Hi All, I recently noticed that there was no entry point for running actions at the conclusion of tangling. We have `org-babel-pre-tangle-hook' which runs at the start of the tangle, and `org-babel-post-tangle-hook' which is run in each tangled file in turn, but nothing to run at the very end once.
So, I’ve got a little patch to introduce a new hook `org-babel-pre-tangle-finished' to fill this gap. If there are no objections, I’ll merge this in a few days. All the best, Timothy
>From 1a90aa41ecc0f94a95d422a3ce9981df933b171d Mon Sep 17 00:00:00 2001 From: TEC <g...@tecosaur.net> Date: Sat, 27 Aug 2022 11:15:23 +0800 Subject: [PATCH 1/3] ob-tangle: New tangle-finished hook * lisp/ob-tangle.el (org-babel-tangle, org-babel-tangle-finished-hook): Create a new hook, `org-babel-tangle-finished-hook', and run it at the end of `org-babel-tangle'. --- lisp/ob-tangle.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 29c764ecb..94ef242ff 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -89,6 +89,13 @@ (defcustom org-babel-tangle-body-hook nil :version "24.1" :type 'hook) +(defcustom org-babel-tangle-finished-hook nil + "Hook run at the very end of `org-babel-tangle'. +In this way, it is the counterpart to `org-babel-pre-tangle-hook'." + :group 'org-babel + :package-version '(Org . "9.6") + :type 'hook) + (defcustom org-babel-tangle-comment-format-beg "[[%link][%source-name]]" "Format of inserted comments in tangled code files. The following format strings can be used to insert special @@ -322,6 +329,7 @@ (defun org-babel-tangle (&optional arg target-file lang-re) (org-babel-with-temp-filebuffer file (run-hooks 'org-babel-post-tangle-hook))) path-collector)) + (run-hooks 'org-babel-tangle-finished-hook) path-collector)))) (defun org-babel-interpret-file-mode (mode) -- 2.37.1
>From 167d548bf0e3434aab7af40826f7f31b8174ea27 Mon Sep 17 00:00:00 2001 From: TEC <g...@tecosaur.net> Date: Sun, 28 Aug 2022 01:29:56 +0800 Subject: [PATCH 2/3] manual: Document org-babel-tangle-finished-hook * etc/ORG-NEWS: Mention new hook, `org-babel-tangle-finished-hook'. * doc/org-manual.org (Tangle hooks): Mention new hook, `org-babel-tangle-finished-hook'. --- doc/org-manual.org | 4 ++++ etc/ORG-NEWS | 35 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index a37b8390c..2481d81e9 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -18592,6 +18592,10 @@ *** Tangle hooks ~org-babel-tangle~, making it suitable for post-processing, compilation, and evaluation of code in the tangled files. +- ~org-babel-tangle-finished-hook~ :: + #+vindex: org-babel-tangle-finished-hook +This hook is run after post-tangle hooks, in the original buffer. + *** Jumping between code and Org :PROPERTIES: :UNNUMBERED: notoc diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a7f32671e..d6f77ced8 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -297,6 +297,13 @@ Use the header argument =:var x=code-block[]= or : #+CALL: fn(x=code-block[]) to pass the contents of a named code block as a string argument. +*** New ~org-babel-tangle-finished-hook~ hook run at the very end of ~org-babel-tangle~ + +This provides a proper counterpart to ~org-babel-pre-tangle-hook~, as +~org-babel-post-tangle-hook~ is run +per-tangle-destination. ~org-babel-tangle-finished-hook~ is just run +once after the post tangle hooks. + ** New options *** New custom settings =org-icalendar-scheduled-summary-prefix= and =org-icalendar-deadline-summary-prefix= @@ -5407,21 +5414,21 @@ See https://orgmode.org/elpa/ ** Overview of the new keybindings - | Keybinding | Speedy | Command | - |-----------------+--------+-----------------------------| - | =C-c C-x C-z= | | [[doc::org-clock-resolve][org-clock-resolve]] | - | =C-c C-x C-q= | | [[doc::org-clock-cancel][org-clock-cancel]] | - | =C-c C-x C-x= | | [[doc::org-clock-in-last][org-clock-in-last]] | - | =M-h= | | [[doc::org-mark-element][org-mark-element]] | - | =*= | | [[doc::org-agenda-bulk-mark-all][org-agenda-bulk-mark-all]] | - | =C-c C-M-l= | | [[doc::org-insert-all-links][org-insert-all-links]] | + | Keybinding | Speedy | Command | + |-----------------+--------+-------------------------------------------------------------------| + | =C-c C-x C-z= | | [[doc::org-clock-resolve][org-clock-resolve]] | + | =C-c C-x C-q= | | [[doc::org-clock-cancel][org-clock-cancel]] | + | =C-c C-x C-x= | | [[doc::org-clock-in-last][org-clock-in-last]] | + | =M-h= | | [[doc::org-mark-element][org-mark-element]] | + | =*= | | [[doc::org-agenda-bulk-mark-all][org-agenda-bulk-mark-all]] | + | =C-c C-M-l= | | [[doc::org-insert-all-links][org-insert-all-links]] | | =C-c C-x C-M-v= | | [[doc::org-redisplay-inline-images][org-redisplay-inline-images]] | - | =C-c C-x E= | =E= | [[doc::org-inc-effort][org-inc-effort]] | - | | =#= | [[doc::org-toggle-comment][org-toggle-comment]] | - | | =:= | [[doc::org-columns][org-columns]] | - | | =W= | Set =APPT_WARNTIME= | - | =k= | | [[doc::org-agenda-capture][org-agenda-capture]] | - | C-c , | , | [[doc::org-priority][org-priority]] | + | =C-c C-x E= | =E= | [[doc::org-inc-effort][org-inc-effort]] | + | | =#= | [[doc::org-toggle-comment][org-toggle-comment]] | + | | =:= | [[doc::org-columns][org-columns]] | + | | =W= | Set =APPT_WARNTIME= | + | =k= | | [[doc::org-agenda-capture][org-agenda-capture]] | + | C-c , | , | [[doc::org-priority][org-priority]] | ** New package and Babel language -- 2.37.1
>From e64db8ee8e888fa266331d1b36e5765d6d7d880f Mon Sep 17 00:00:00 2001 From: TEC <g...@tecosaur.net> Date: Sat, 17 Sep 2022 17:59:59 +0800 Subject: [PATCH 3/3] manual: Note undocumented tangle hooks * doc/org-manual.org (Tangle hooks): Note that the pre-tangle and tangle-body hooks are undocumented. --- doc/org-manual.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/org-manual.org b/doc/org-manual.org index 2481d81e9..aafc92d1d 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -18585,6 +18585,8 @@ *** Tangle hooks :UNNUMBERED: notoc :END: +# FIXME missing pre-tangle and tangle-body hooks + - ~org-babel-post-tangle-hook~ :: #+vindex: org-babel-post-tangle-hook -- 2.37.1