From bca4034ae7e87d10ea7def3e1dc7e24231298bc4 Mon Sep 17 00:00:00 2001 From: Chris Barrett Date: Thu, 1 Sep 2022 10:40:03 +1200 Subject: [PATCH] Generalise way we detect whether we're in archives --- lisp/org-format.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/org-format.el b/lisp/org-format.el index f9410b4..372e053 100644 --- a/lisp/org-format.el +++ b/lisp/org-format.el @@ -51,6 +51,8 @@ Only applies to level-1 headings in the document." :group 'org-format :type 'integer) + + (defun org-format--ensure-empty-lines (n) (save-excursion (goto-char (line-beginning-position)) @@ -62,10 +64,21 @@ Only applies to level-1 headings in the document." (delete-region (point) start))) (insert (make-string n ?\n))))) +(defun org-format--in-archived-heading-p () + (save-excursion + (when (org-before-first-heading-p) + (org-forward-heading-same-level 1)) + (let ((tags (org-get-tags))) + (seq-contains-p tags org-archive-tag)))) + (defun org-format-all-headings () "Ensure that blank lines exist between headings and their contents." (interactive) - (let ((scope (if (equal (buffer-name) "archive.org") 'tree 'file)) + (let ((scope (if (org-format--in-archived-heading-p) + ;; archive files can be enormous--just format the heading at + ;; point after archiving. + 'tree + 'file)) (seen-first-heading-p)) (org-map-entries (lambda () ;; Widen so we can see space preceding the current