emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Suggestion to add hook to be run when org-indent completes a buffer's initialization
@ 2023-12-30  5:24 dark.key8799
  2023-12-31 14:42 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: dark.key8799 @ 2023-12-30  5:24 UTC (permalink / raw)
  To: emacs-orgmode

The org-modern-indent package relies on org-indent having finished preparing a buffer to add its own customizations. Currently it relies on a timer mechanism to watch org-indent-agentized-buffers and execute once a buffer has been prepped by org-indent.

That leads to some downstream issues in particular use-cases (https://github.com/jdtsmith/org-modern-indent/issues/11)

Although there are some workarounds for the particular issue above, a cleaner solution would be org-indent calling some hook at the end of the preparation. As per link above, jdtsmith proposes to add such call in org-indent-initialize-buffer:

         ;; Job is complete: un-agentize buffer.
	 (unless interruptp
	   (setq org-indent-agentized-buffers
		 (delq buffer org-indent-agentized-buffers))
           (run-hook-with-args 'org-indent-buffer-init-finished buffer)) ;; <-- added

-- 
Alexandre Avanian


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization
  2023-12-30  5:24 Suggestion to add hook to be run when org-indent completes a buffer's initialization dark.key8799
@ 2023-12-31 14:42 ` Ihor Radchenko
  2024-01-02 10:56   ` [PATCH] " dark.key8799
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2023-12-31 14:42 UTC (permalink / raw)
  To: dark.key8799; +Cc: emacs-orgmode

dark.key8799@151e.ai writes:

> Although there are some workarounds for the particular issue above, a cleaner solution would be org-indent calling some hook at the end of the preparation. As per link above, jdtsmith proposes to add such call in org-indent-initialize-buffer:
>
>          ;; Job is complete: un-agentize buffer.
> 	 (unless interruptp
> 	   (setq org-indent-agentized-buffers
> 		 (delq buffer org-indent-agentized-buffers))
>            (run-hook-with-args 'org-indent-buffer-init-finished buffer)) ;; <-- added

I do not see why we shouldn't add such a hook. Patches welcome!

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization
  2023-12-31 14:42 ` Ihor Radchenko
@ 2024-01-02 10:56   ` dark.key8799
  2024-01-02 11:15     ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: dark.key8799 @ 2024-01-02 10:56 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 161 bytes --]

On Sun, Dec 31, 2023, at 22:42, Ihor Radchenko wrote:

> I do not see why we shouldn't add such a hook. Patches welcome!

Would this work?

-- 
Alexandre Avanian

[-- Attachment #2: 0001-lisp-org-indent.el-Add-hook-to-run-after-it-initiali.patch --]
[-- Type: application/octet-stream, Size: 1711 bytes --]

From d11dc9bfdb3a659ca56884a98a7a0bf703f2a4ce Mon Sep 17 00:00:00 2001
From: Alexandre Avanian <git@alexandre.avanian.net>
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.

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
---
 lisp/org-indent.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/org-indent.el b/lisp/org-indent.el
index 62ebd6be0..4dc883c01 100644
--- a/lisp/org-indent.el
+++ b/lisp/org-indent.el
@@ -103,6 +103,13 @@
   :group 'org-indent
   :type 'integer)
 
+(defcustom org-indent-post-buffer-init-hook 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
+  :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 +297,8 @@
 	 ;; 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-hook buffer)))))))
 
 (defun org-indent-set-line-properties (level indentation &optional heading)
   "Set prefix properties on current line an move to next one.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization
  2024-01-02 10:56   ` [PATCH] " dark.key8799
@ 2024-01-02 11:15     ` Ihor Radchenko
  2024-01-02 15:53       ` dark.key8799
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-02 11:15 UTC (permalink / raw)
  To: dark.key8799; +Cc: emacs-orgmode

dark.key8799@151e.ai writes:

>> I do not see why we shouldn't add such a hook. Patches welcome!
>
> Would this work?

Yes, but please address some minor comments.

> +(defcustom org-indent-post-buffer-init-hook 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
> +  :type 'hook)

By convention, abnormal hooks (hooks that require arguments) are named
as *-functions, not *-hook.

Also, when adding new customizations, we generally announce them in
etc/ORG-NEWS.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization
  2024-01-02 11:15     ` Ihor Radchenko
@ 2024-01-02 15:53       ` dark.key8799
  2024-01-03 15:38         ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: dark.key8799 @ 2024-01-02 15:53 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

On Tue, Jan 2, 2024, at 19:15, Ihor Radchenko wrote:
> By convention, abnormal hooks (hooks that require arguments) are named
> as *-functions, not *-hook.
>
> Also, when adding new customizations, we generally announce them in
> etc/ORG-NEWS.

Understood. Please find amended patch.

-- 
Alexandre Avanian

[-- Attachment #2: 0001-lisp-org-indent.el-Add-hook-to-run-after-it-initiali.patch --]
[-- Type: application/octet-stream, Size: 2322 bytes --]

From 12edb4205a87be187900a55de5c37b9264a7a27c Mon Sep 17 00:00:00 2001
From: Alexandre Avanian <git@alexandre.avanian.net>
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 | 10 +++++++++-
 2 files changed, 14 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..aebd95743 100644
--- a/lisp/org-indent.el
+++ b/lisp/org-indent.el
@@ -103,6 +103,13 @@
   :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
+  :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 +297,8 @@
 	 ;; 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.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Re: Suggestion to add hook to be run when org-indent completes a buffer's initialization
  2024-01-02 15:53       ` dark.key8799
@ 2024-01-03 15:38         ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-03 15:38 UTC (permalink / raw)
  To: dark.key8799; +Cc: emacs-orgmode

dark.key8799@151e.ai writes:

> Understood. Please find amended patch.

Applied, onto main, with minor amendments.
I capitalized all the sentences in commit message and added
:package-version keyword to the `defcustom' definition.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3aac00e45

Thanks for your contribution!

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-01-03 15:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-30  5:24 Suggestion to add hook to be run when org-indent completes a buffer's initialization dark.key8799
2023-12-31 14:42 ` Ihor Radchenko
2024-01-02 10:56   ` [PATCH] " dark.key8799
2024-01-02 11:15     ` Ihor Radchenko
2024-01-02 15:53       ` dark.key8799
2024-01-03 15:38         ` Ihor Radchenko

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).