Browse Source

Visibility Cycling: Allow to show all empty lines after a headline

`org-cycle-separator-lines' can now get a negative value, to indicate
that, if the number of empty lines before a visible entry is greater
than the specified number, then *all* empty lines should be shown.
Carsten Dominik 15 years ago
parent
commit
9eaab0b5cf
2 changed files with 19 additions and 6 deletions
  1. 4 0
      lisp/ChangeLog
  2. 15 6
      lisp/org.el

+ 4 - 0
lisp/ChangeLog

@@ -1,5 +1,9 @@
 2009-08-24  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-08-24  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org.el (org-cycle-separator-lines): Update docstring.
+	(org-cycle-show-empty-lines): Handle negative values for
+	`org-cycle-show-empty-lines'.
+
 	* org-remember.el (org-remember-escaped-%): New function.
 	* org-remember.el (org-remember-escaped-%): New function.
 	(org-remember-apply-template): Use `org-remember-escaped-%' to
 	(org-remember-apply-template): Use `org-remember-escaped-%' to
 	detect escaped % signs.
 	detect escaped % signs.

+ 15 - 6
lisp/org.el

@@ -673,6 +673,9 @@ So the default 2 means, at least 2 empty lines after the end of a subtree
 are needed to produce free space between a collapsed subtree and the
 are needed to produce free space between a collapsed subtree and the
 following headline.
 following headline.
 
 
+If the number is negative, and the number of empty lines is at least -N,
+all empty lines are shown.
+
 Special case: when 0, never leave empty lines in collapsed view."
 Special case: when 0, never leave empty lines in collapsed view."
   :group 'org-cycle
   :group 'org-cycle
   :type 'integer)
   :type 'integer)
@@ -5231,16 +5234,16 @@ 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 (> org-cycle-separator-lines 0)
+  (when (not (= org-cycle-separator-lines 0))
     (save-excursion
     (save-excursion
-      (let* ((n org-cycle-separator-lines)
+      (let* ((n (abs org-cycle-separator-lines))
 	     (re (cond
 	     (re (cond
 		  ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
 		  ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
 		  ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
 		  ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
 		  (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)
+	     beg end b e)
 	(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)))
@@ -5251,9 +5254,15 @@ are at least `org-cycle-separator-lines' empty lines before the headline."
 	(when beg
 	(when beg
 	  (goto-char beg)
 	  (goto-char beg)
 	  (while (re-search-forward re end t)
 	  (while (re-search-forward re end t)
-	    (if (not (get-char-property (match-end 1) 'invisible))
-		(outline-flag-region
-		 (match-beginning 1) (match-end 1) nil)))))))
+	    (unless (get-char-property (match-end 1) 'invisible)
+	      (setq e (match-end 1))
+	      (if (< org-cycle-separator-lines 0)
+		  (setq b (save-excursion
+			    (goto-char (match-beginning 0))
+			    (org-back-over-empty-lines)
+			    (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))