From 3aac00e45dc917c9174d1ecb1a80ffa41a3d2199 Mon Sep 17 00:00:00 2001 From: Alexandre Avanian Date: Tue, 2 Jan 2024 18:08:09 +0800 Subject: [PATCH] lisp/org-indent.el: Add hook to run after it initializes a buffer * lisp/org-indent.el (org-indent-initialize-buffer): Define and call hook after it initializes a buffer. * etc/ORG-NEWS: Announce new custom option. This will allow to enrich org-indent properties without requiring hacks to detect initialization. See https://list.orgmode.org/orgmode/5f4cdb77-8f43-4f2d-91a7-bc4ce57df8ad@app.fastmail.com/#r TINYCHANGE --- etc/ORG-NEWS | 5 +++++ lisp/org-indent.el | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 7d0822faf..a906d116f 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -581,6 +581,11 @@ The main change will be for users who did not configure ~ob-python~ will now start interactive sessions in a more consistent manner with ~run-python~. +*** New hook option ~org-indent-post-buffer-init-functions~ + +This allows to run functions after ~org-indent~ intializes a buffer to +enrich its properties. + ** New features *** =ob-plantuml.el=: Support tikz file format output diff --git a/lisp/org-indent.el b/lisp/org-indent.el index 62ebd6be0..c402aec72 100644 --- a/lisp/org-indent.el +++ b/lisp/org-indent.el @@ -103,6 +103,14 @@ For details see the variable `org-adapt-indentation'." :group 'org-indent :type 'integer) +(defcustom org-indent-post-buffer-init-functions nil + "Hook run after org-indent finishes initializing a buffer. +The function(s) in in this hook must accept a single argument representing +the initialized buffer." + :group 'org-indent + :package-version '(Org . "9.7") + :type 'hook) + (defface org-indent '((t (:inherit org-hide))) "Face for outline indentation. The default is to make it look like whitespace. But you may find it @@ -290,7 +298,8 @@ a time value." ;; Job is complete: un-agentize buffer. (unless interruptp (setq org-indent-agentized-buffers - (delq buffer org-indent-agentized-buffers)))))))) + (delq buffer org-indent-agentized-buffers)) + (run-hook-with-args 'org-indent-post-buffer-init-functions buffer))))))) (defun org-indent-set-line-properties (level indentation &optional heading) "Set prefix properties on current line an move to next one.