summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2019-02-03 14:09:57 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2019-02-03 14:23:44 +0100
commit70c90c2cb5dc44a32ffff67a8c88b7957bbf77fb (patch)
treec3192a0de06fc74a6b84b87d7752e6f39421ae82
parent4761fab2ff6a2f893c21c404a4ef48eae5eb3078 (diff)
downloadorg-mode-70c90c2cb5dc44a32ffff67a8c88b7957bbf77fb.tar.gz
Fix nested VISIBILITY property
* lisp/org.el (org-set-visibility-according-to-property): Fix nested VISIBILITY property. Small refactoring. * testing/lisp/test-org.el (test-org/set-visibility-according-to-property): Add test. Reported-by: Michael Maurer <maurer.michael@gmail.com> <http://lists.gnu.org/r/emacs-orgmode/2019-01/msg00402.html>
-rw-r--r--lisp/org.el48
-rw-r--r--testing/lisp/test-org.el16
2 files changed, 40 insertions, 24 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 001923d..54eded5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7286,30 +7286,32 @@ With a numeric prefix, show all headlines up to that level."
(org-cycle-show-empty-lines t)))
(defun org-set-visibility-according-to-property ()
- "Switch subtree visibilities according to :VISIBILITY: property."
+ "Switch subtree visibility according to VISIBILITY property."
(interactive)
- (org-with-wide-buffer
- (goto-char (point-min))
- (while (re-search-forward "^[ \t]*:VISIBILITY:" nil t)
- (if (not (org-at-property-p)) (outline-next-heading)
- (let ((state (match-string 3)))
- (save-excursion
- (org-back-to-heading t)
- (outline-hide-subtree)
- (org-reveal)
- (cond
- ((equal state "folded")
- (outline-hide-subtree))
- ((equal state "children")
- (org-show-hidden-entry)
- (org-show-children))
- ((equal state "content")
- (save-excursion
- (save-restriction
- (org-narrow-to-subtree)
- (org-content))))
- ((member state '("all" "showall"))
- (outline-show-subtree)))))))))
+ (let ((regexp (org-re-property "VISIBILITY")))
+ (org-with-point-at 1
+ (while (re-search-forward regexp nil t)
+ (let ((state (match-string 3)))
+ (if (not (org-at-property-p)) (outline-next-heading)
+ (save-excursion
+ (org-back-to-heading t)
+ (outline-hide-subtree)
+ (org-reveal)
+ (pcase state
+ ("folded"
+ (outline-hide-subtree))
+ ("children"
+ (org-show-hidden-entry)
+ (org-show-children))
+ ("content"
+ (save-excursion
+ (save-restriction
+ (org-narrow-to-subtree)
+ (org-content))))
+ ((or "all" "showall")
+ (outline-show-subtree))
+ (_ nil)))
+ (org-end-of-subtree)))))))
(defun org-overview ()
"Switch to overview mode, showing only top-level headlines.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index a6ef491..37740e2 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -7489,7 +7489,21 @@ Contents
Contents
*** <point>c"
(org-set-visibility-according-to-property)
- (not (invisible-p (point))))))
+ (not (invisible-p (point)))))
+ ;; When VISIBILITY properties are nested, ignore inner ones.
+ (should
+ (org-test-with-temp-text
+ "
+* A
+:PROPERTIES:
+:VISIBILITY: folded
+:END:
+** <point>B
+:PROPERTIES:
+:VISIBILITY: folded
+:END:"
+ (org-set-visibility-according-to-property)
+ (invisible-p (point)))))
;;; Yank and Kill