* org-trigger-hook and org-babel-execute-subtree
@ 2016-09-04 10:56 Fabio Leimgruber
2016-09-08 23:07 ` Fabio Leimgruber
0 siblings, 1 reply; 2+ messages in thread
From: Fabio Leimgruber @ 2016-09-04 10:56 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 801 bytes --]
Hello all,
I am trying to evaluate source blocks under certain heading when their
TODO state changes. This is what I have so far to test it:
#+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
As hinted at in the (princ ...), org-babel-execute-subtree is not run.
Am I missing something?
Best Regards,
Fabio Leimgruber
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: org-trigger-hook and org-babel-execute-subtree
2016-09-04 10:56 org-trigger-hook and org-babel-execute-subtree Fabio Leimgruber
@ 2016-09-08 23:07 ` Fabio Leimgruber
0 siblings, 0 replies; 2+ messages in thread
From: Fabio Leimgruber @ 2016-09-08 23:07 UTC (permalink / raw)
To: Fabio Leimgruber; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1501 bytes --]
Fabio Leimgruber <fabio.leimgruber@posteo.eu> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 180 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-08 23:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-04 10:56 org-trigger-hook and org-babel-execute-subtree Fabio Leimgruber
2016-09-08 23:07 ` Fabio Leimgruber
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).