Browse Source

Fix visibility with `org-cycle-separator-lines' at -1

* lisp/org.el (org-cycle-show-empty-lines): Fix visibility cycling
  with `org-cycle-separator-lines' set to -1.

Reported-by: Michael Crouch <creidieki@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/97879>
Nicolas Goaziou 10 years ago
parent
commit
a714c3a118
1 changed files with 13 additions and 17 deletions
  1. 13 17
      lisp/org.el

+ 13 - 17
lisp/org.el

@@ -7123,7 +7123,7 @@ The region to be covered depends on STATE when called through
 `org-cycle-hook'.  Lisp program can use t for STATE to get the
 `org-cycle-hook'.  Lisp program can use t for STATE to get the
 entire buffer covered.  Note that an empty line is only shown if there
 entire buffer covered.  Note that an empty line is only shown if there
 are at least `org-cycle-separator-lines' empty lines before the headline."
 are at least `org-cycle-separator-lines' empty lines before the headline."
-  (when (not (= org-cycle-separator-lines 0))
+  (when (/= org-cycle-separator-lines 0)
     (save-excursion
     (save-excursion
       (let* ((n (abs org-cycle-separator-lines))
       (let* ((n (abs org-cycle-separator-lines))
 	     (re (cond
 	     (re (cond
@@ -7132,30 +7132,26 @@ are at least `org-cycle-separator-lines' empty lines before the headline."
 		  (t (let ((ns (number-to-string (- n 2))))
 		  (t (let ((ns (number-to-string (- n 2))))
 		       (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
 		       (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
 			       "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
 			       "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
-	     beg end b e)
+	     beg end)
 	(cond
 	(cond
 	 ((memq state '(overview contents t))
 	 ((memq state '(overview contents t))
 	  (setq beg (point-min) end (point-max)))
 	  (setq beg (point-min) end (point-max)))
 	 ((memq state '(children folded))
 	 ((memq state '(children folded))
-	  (setq beg (point) end (progn (org-end-of-subtree t t)
+	  (setq beg (point)
-				       (beginning-of-line 2)
+		end (progn (org-end-of-subtree t t)
-				       (point)))))
+			   (line-beginning-position 2)))))
 	(when beg
 	(when beg
 	  (goto-char beg)
 	  (goto-char beg)
 	  (while (re-search-forward re end t)
 	  (while (re-search-forward re end t)
 	    (unless (get-char-property (match-end 1) 'invisible)
 	    (unless (get-char-property (match-end 1) 'invisible)
-	      (setq e (match-end 1))
+	      (let ((e (match-end 1))
-	      (if (< org-cycle-separator-lines 0)
+		    (b (if (>= org-cycle-separator-lines 0)
-		  (setq b (save-excursion
+			   (match-beginning 1)
-			    (goto-char (match-beginning 0))
+			 (save-excursion
-			    (org-back-over-empty-lines)
+			   (goto-char (match-beginning 0))
-			    (if (save-excursion
+			   (skip-chars-backward " \t\n")
-				  (goto-char (max (point-min) (1- (point))))
+			   (line-end-position)))))
-				  (org-at-heading-p))
+		(outline-flag-region b e nil))))))))
-				(1- (point))
-			      (point))))
-		(setq b (match-beginning 1)))
-	      (outline-flag-region b e nil)))))))
   ;; Never hide empty lines at the end of the file.
   ;; Never hide empty lines at the end of the file.
   (save-excursion
   (save-excursion
     (goto-char (point-max))
     (goto-char (point-max))