From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex =?utf-8?Q?Benn=C3=A9e?= Subject: Hooking document specific src blocks into default actions Date: Mon, 26 Feb 2018 12:28:16 +0000 Message-ID: <87tvu46ilb.fsf@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqHtH-0007Mq-EP for emacs-orgmode@gnu.org; Mon, 26 Feb 2018 07:28:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqHtE-0008Id-9h for emacs-orgmode@gnu.org; Mon, 26 Feb 2018 07:28:23 -0500 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:38639) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eqHtE-0008IQ-1g for emacs-orgmode@gnu.org; Mon, 26 Feb 2018 07:28:20 -0500 Received: by mail-wr0-x22b.google.com with SMTP id n7so21018813wrn.5 for ; Mon, 26 Feb 2018 04:28:19 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z73sm10516101wmc.3.2018.02.26.04.28.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 04:28:17 -0800 (PST) Received: from zen (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTPS id D5EE13E00B4 for ; Mon, 26 Feb 2018 12:28:16 +0000 (GMT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Hi, I've been using these for a while but I recently wanted to add a function at the head of the ctrl-c-ctrl-c processing: (defvar my-org-default-action nil "Default action for this document to run on `org-ctrl-c-ctrl-c'. \\ This will run via `org-ctrl-c-ctrl-c-hook' and should return a non-nil result if it processed something. As such it can override default `org-mode' behaviour for \\[org-ctrl-c-ctrl-c]. If you want something to run at the end then you need to use `my-org-default-code-block'") (make-variable-buffer-local 'my-org-default-action) (defun my-org--do-action (func-or-string) "Evaluate a code block or call a function `FUNC-OR-STRING' from org-fil= e." (let ((current-point (point))) (cond ((stringp func-or-string) (save-excursion (org-babel-goto-named-src-block func-or-string) (org-babel-when-in-src-block (org-babel-eval-wipe-error-buffer) (org-babel-execute-src-block current-prefix-arg nil '((:called-from . current-point))))= )) ((functionp func-or-string) (funcall func-or-string)) (t (error "What to do with: %s" func-or-string))))) (defun my-org-run-default-action () "Execute default action for this org file." (interactive) (when my-org-default-action (my-org--do-action my-org-default-action))) (add-to-list 'org-ctrl-c-ctrl-c-hook 'my-org-run-default-action) However I've run into a small problem that when I execute the source block I end up with 't every time as we successfully executed the block even if it didn't end up doing anything at the time. Is there a better way to invoke source blocks from the current org-document than this? One where the eventual result can be returned into the calling lisp so org-ctrl-c-ctrl-c-hook can move on if we didn't do anything? -- Alex Benn=C3=A9e