org-fold-core-save-visibility: Fix macro expansion

* lisp/org-fold-core.el (org-fold-core-save-visibility): Calculate
folds on runtime, not during macro expansion.

* testing/lisp/test-org.el (test-org/org-ctrl-c-ctrl-c): Add test
ensuring that outline visibility is preserved upon refreshing Org
setup.

Reported-by: Matt Lundin <mdl@imapmail.org>
Link: https://orgmode.org/list/87wn70tlcn.fsf@fastmail.fm
This commit is contained in:
Ihor Radchenko 2022-12-10 11:54:47 +03:00
parent 76a725317e
commit aba51fb584
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 16 additions and 1 deletions

View File

@ -1063,7 +1063,7 @@ means that the buffer should stay alive during the operation,
because otherwise all these markers will point to nowhere."
(declare (debug (form body)) (indent 1))
(org-with-gensyms (regions)
`(let* ((,regions ,(org-fold-core-get-regions :with-markers use-markers)))
`(let* ((,regions (org-fold-core-get-regions :with-markers ,use-markers)))
(unwind-protect (progn ,@body)
(org-fold-core-regions ,regions :override t :clean-markers t)))))

View File

@ -3581,6 +3581,21 @@ SCHEDULED: <2017-05-06 Sat>
(kill-buffer buffer))
t)))
(ert-deftest test-org/org-ctrl-c-ctrl-c ()
"Test `org-ctrl-c-ctrl-c' specifications."
;; FIXME: Improve coverage.
;; Preserve visibility after refreshing Org setup.
(org-test-with-temp-text
"#+TITLE: Test
* Heading<point>
text"
(org-overview)
(should (org-fold-folded-p (point) 'outline))
(save-excursion
(goto-char (point-min))
(org-ctrl-c-ctrl-c))
(should (org-fold-folded-p (point) 'outline))))
;;; Navigation