Jelajahi Sumber

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>
Nicolas Goaziou 6 tahun lalu
induk
melakukan
70c90c2cb5
2 mengubah file dengan 40 tambahan dan 24 penghapusan
  1. 25 23
      lisp/org.el
  2. 15 1
      testing/lisp/test-org.el

+ 25 - 23
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.

+ 15 - 1
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