Browse Source

Bugfix for heading levels when toggling from list

* org.el (org-toggle-heading): More comments and fix number of stars
when toggling from list items.

TINYCHANGE
Michael Brand 14 years ago
parent
commit
374b70a383
1 changed files with 20 additions and 12 deletions
  1. 20 12
      lisp/org.el

+ 20 - 12
lisp/org.el

@@ -17963,12 +17963,20 @@ stars to add."
 	     (looking-at outline-regexp) (replace-match ""))
 	     (looking-at outline-regexp) (replace-match ""))
 	   (forward-line)))
 	   (forward-line)))
 	;; Case 2. Started at an item: change items into headlines.
 	;; Case 2. Started at an item: change items into headlines.
+	;;         One star will be added by `org-list-to-subtree'.
 	((org-at-item-p)
 	((org-at-item-p)
-	 (let ((stars (make-string
-		       (if nstars
-			   (prefix-numeric-value current-prefix-arg)
-			 (or (org-current-level) 0))
-		       ?*)))
+	 (let* ((stars (make-string
+			(if nstars
+			    ;; subtract the star that will be added again by
+			    ;; `org-list-to-subtree'
+			    (1- (prefix-numeric-value current-prefix-arg))
+			  (or (org-current-level) 0))
+			?*))
+		(add-stars
+		 (cond (nstars "")               ; stars from prefix only
+		       ((equal stars "") "")     ; before first heading
+		       (org-odd-levels-only "*") ; inside heading, odd
+		       (t ""))))                 ; inside heading, oddeven
 	   (while (< (point) end)
 	   (while (< (point) end)
 	     (when (org-at-item-p)
 	     (when (org-at-item-p)
 	       ;; Pay attention to cases when region ends before list.
 	       ;; Pay attention to cases when region ends before list.
@@ -17979,9 +17987,8 @@ stars to add."
 		   (insert
 		   (insert
 		    (org-list-to-subtree
 		    (org-list-to-subtree
 		     (org-list-parse-list t)
 		     (org-list-parse-list t)
-		     '(:istart (concat stars (funcall get-stars depth))
-			       :icount (concat stars
-					       (funcall get-stars depth))))))))
+		     '(:istart (concat stars add-stars (funcall get-stars depth))
+			       :icount (concat stars add-stars (funcall get-stars depth))))))))
 	     (forward-line))))
 	     (forward-line))))
 	;; Case 3. Started at normal text: make every line an heading,
 	;; Case 3. Started at normal text: make every line an heading,
 	;;         skipping headlines and items.
 	;;         skipping headlines and items.
@@ -17990,10 +17997,11 @@ stars to add."
 			      (prefix-numeric-value current-prefix-arg)
 			      (prefix-numeric-value current-prefix-arg)
 			    (or (org-current-level) 0))
 			    (or (org-current-level) 0))
 			  ?*))
 			  ?*))
-		  (add-stars (cond (nstars "")
-				   ((equal stars "") "*")
-				   (org-odd-levels-only "**")
-				   (t "*")))
+		  (add-stars
+		   (cond (nstars "")                ; stars from prefix only
+			 ((equal stars "") "*")     ; before first heading
+			 (org-odd-levels-only "**") ; inside heading, odd
+			 (t "*")))                  ; inside heading, oddeven
 		  (rpl (concat stars add-stars " ")))
 		  (rpl (concat stars add-stars " ")))
 	     (while (< (point) end)
 	     (while (< (point) end)
 	       (when (and (not (org-on-heading-p)) (not (org-at-item-p))
 	       (when (and (not (org-on-heading-p)) (not (org-at-item-p))