emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Fabio Leimgruber <fabio.leimgruber@posteo.eu>
To: Fabio Leimgruber <fabio.leimgruber@posteo.eu>
Cc: emacs-orgmode@gnu.org
Subject: Re: org-trigger-hook and org-babel-execute-subtree
Date: Fri, 09 Sep 2016 01:07:24 +0200	[thread overview]
Message-ID: <m2mvjing7n.fsf@nirvana.fritz.box> (raw)
In-Reply-To: <m260qc0w7o.fsf@nirvana.fritz.box> (Fabio Leimgruber's message of "Sun, 04 Sep 2016 12:56:43 +0200")

[-- 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 --]

      reply	other threads:[~2016-09-08 23:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-04 10:56 org-trigger-hook and org-babel-execute-subtree Fabio Leimgruber
2016-09-08 23:07 ` Fabio Leimgruber [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2mvjing7n.fsf@nirvana.fritz.box \
    --to=fabio.leimgruber@posteo.eu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).