[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-trigger-hook and org-babel-execute-subtree

From: Fabio Leimgruber
Subject: Re: [O] org-trigger-hook and org-babel-execute-subtree
Date: Fri, 09 Sep 2016 01:07:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin)

Fabio Leimgruber <address@hidden> writes:

> #+BEGIN_SRC emacs-lisp
> (defun my-run-babel-on-todo (plist)
>   "When TODO state changes, run all source blocks below heading"
>   (let* ((element (org-element-at-point))
>          (babel-p (org-element-property :TRIGGER_BABEL element)))
>     (when babel-p
>       (princ "This gets run alright, but not the next one")
>       (org-babel-execute-subtree))))
> #+BEGIN_SRC emacs-lisp
> (add-hook 'org-trigger-hook 'my-run-babel-on-todo)
> * TODO test
> :END:
> #+BEGIN_SRC calc
>   1 + 1

FWIW, the following does work.  Comments would be appreciated.

#+BEGIN_SRC emacs-lisp :results silent
(defun my-org-invoke-babel-named (name)
    (org-babel-goto-named-src-block name)

#+BEGIN_SRC emacs-lisp :results silent
  (defun my-run-babel-on-todo (plist)
    "When state changes, run defined source blocks"
    (let* ((to (plist-get plist :to))
           (element (org-element-at-point))
           (babel-snippet (org-element-property :TRIGGER_BABEL element)))
      (when (string= "DONE" to)
        (my-org-invoke-babel-named babel-snippet))))

#+BEGIN_SRC emacs-lisp
(add-hook 'org-trigger-hook 'my-run-babel-on-todo)

* TODO test
:TRIGGER_BABEL: trigger_name

#+name: trigger_name
#+BEGIN_SRC calc
  1 + 1


Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]