branch: externals/org-modern commit 8702acf29107ae3b9eb4d75c79b6dc968221d16b Author: JD Smith <93749+jdtsm...@users.noreply.github.com> Commit: JD Smith <93749+jdtsm...@users.noreply.github.com>
use org-indent-post-buffer-init-functions to init, if available --- org-modern-indent.el | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/org-modern-indent.el b/org-modern-indent.el index 61a5ed4dc2..c19771a080 100644 --- a/org-modern-indent.el +++ b/org-modern-indent.el @@ -164,10 +164,7 @@ returned." "Wait for org-indent to finish initializing BUF, then refresh." (if (or (not (bound-and-true-p org-indent-agentized-buffers)) (not (memq buf org-indent-agentized-buffers))) - (when (buffer-live-p buf) ; org-capture buffers vanish fast - (with-current-buffer buf - (font-lock-add-keywords nil org-modern-indent--font-lock-keywords t) - (font-lock-flush))) + (org-modern-indent--add-keywords buf) ;; still waiting (with-current-buffer buf (if org-modern-indent--init @@ -182,6 +179,14 @@ returned." (list (run-at-time 0.1 nil #'org-modern-indent--wait-and-refresh buf) 1)))))) +(defun org-modern-indent--add-keywords (buf) + "Add keywords to buffer BUF and refresh. +To be added to `org-indent-post-buffer-init-functions'." + (when (buffer-live-p buf) ; org-capture buffers vanish fast + (with-current-buffer buf + (font-lock-add-keywords nil org-modern-indent--font-lock-keywords t) + (font-lock-flush)))) + (defun org-modern-indent--refresh () "Unfontify entire buffer and refresh line prefix." (with-silent-modifications @@ -229,20 +234,25 @@ END, and R are its arguments." "Org-modern-like block brackets within org-indent." :global nil :group 'org-modern-indent - (if org-modern-indent-mode (progn (advice-add 'org-indent-refresh-maybe :around #'org-modern-indent--refresh-watch) (advice-add 'org-indent-add-properties :filter-args #'org-modern-indent--store-refresh-args) - (org-modern-indent--wait-and-refresh (current-buffer))) + (if (boundp 'org-indent-post-buffer-init-functions) + (add-hook 'org-indent-post-buffer-init-functions + #'org-modern-indent--add-keywords) + (org-modern-indent--wait-and-refresh (current-buffer)))) ;; Disabling (advice-remove 'org-indent-refresh-maybe #'org-modern-indent--refresh-watch) (advice-remove 'org-indent-add-properties #'org-modern-indent--store-refresh-args) (font-lock-remove-keywords nil org-modern-indent--font-lock-keywords) + (if (boundp 'org-indent-post-buffer-init-functions) + (remove-hook 'org-indent-post-buffer-init-functions + #'org-modern-indent--add-keywords)) (org-modern-indent--refresh))) (provide 'org-modern-indent)