[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))))
> #+END_SRC
>
> #+BEGIN_SRC emacs-lisp
> (add-hook 'org-trigger-hook 'my-run-babel-on-todo)
> #+END_SRC
>
>
> * TODO test
> :PROPERTIES:
> :TRIGGER_BABEL: t
> :END:
>
> #+BEGIN_SRC calc
> 1 + 1
> #+END_SRC
>
FWIW, the following does work. Comments would be appreciated.
#+BEGIN_SRC emacs-lisp :results silent
(defun my-org-invoke-babel-named (name)
(interactive)
(save-excursion
(org-babel-goto-named-src-block name)
(org-babel-execute-src-block-maybe)))
#+END_SRC
#+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))))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(add-hook 'org-trigger-hook 'my-run-babel-on-todo)
#+END_SRC
* TODO test
:PROPERTIES:
:TRIGGER_BABEL: trigger_name
:END:
#+name: trigger_name
#+BEGIN_SRC calc
1 + 1
#+END_SRC
Regards,
Fabio
signature.asc
Description: PGP signature