fix(org): update +org--more-startup-folded-options-a

With the introduction of org-fold, this advice (which adds support for a
special family of visibility #+startup options) needed to be updated.
This commit is contained in:
Henrik Lissner 2022-07-26 00:54:25 +02:00
parent 9cb4c8b637
commit dd83c455ba
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -696,15 +696,19 @@ mutating hooks on exported output, like formatters."
(defadvice! +org--more-startup-folded-options-a () (defadvice! +org--more-startup-folded-options-a ()
"Adds support for 'showNlevels*' startup options. "Adds support for 'showNlevels*' startup options.
Unlike showNlevels, this will also unfold parent trees." Unlike showNlevels, this will also unfold parent trees."
:before #'org-set-startup-visibility :before-until #'org-cycle-set-startup-visibility
(when-let (n (pcase org-startup-folded (when-let (n (pcase org-startup-folded
(`show2levels* 2) (`show2levels* 2)
(`show3levels* 3) (`show3levels* 3)
(`show4levels* 4) (`show4levels* 4)
(`show5levels* 5))) (`show5levels* 5)))
(org-show-all '(headings drawers)) (org-fold-show-all '(headings))
(save-excursion (save-excursion
(goto-char (point-max)) (goto-char (point-max))
(save-restriction
(narrow-to-region (point-min) (or (re-search-forward org-outline-regexp-bol nil t) (point-max)))
(org-fold-hide-drawer-all))
(goto-char (point-max))
(let ((regexp (if (and (wholenump n) (> n 0)) (let ((regexp (if (and (wholenump n) (> n 0))
(format "^\\*\\{%d,%d\\} " (1- n) n) (format "^\\*\\{%d,%d\\} " (1- n) n)
"^\\*+ ")) "^\\*+ "))
@ -712,8 +716,9 @@ Unlike showNlevels, this will also unfold parent trees."
(while (re-search-backward regexp nil t) (while (re-search-backward regexp nil t)
(when (or (not (wholenump n)) (when (or (not (wholenump n))
(= (org-current-level) n)) (= (org-current-level) n))
(org-flag-region (line-end-position) last t 'outline)) (org-fold-core-region (line-end-position) last t 'outline))
(setq last (line-end-position 0))))))) (setq last (line-end-position 0)))))
t))
;; Some uses of `org-fix-tags-on-the-fly' occur without a check on ;; Some uses of `org-fix-tags-on-the-fly' occur without a check on
;; `org-auto-align-tags', such as in `org-self-insert-command' and ;; `org-auto-align-tags', such as in `org-self-insert-command' and