emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Bugfix for heading levels when toggling from list
@ 2011-06-09  7:07 Michael Brand
  2011-06-09  7:54 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Brand @ 2011-06-09  7:07 UTC (permalink / raw)
  To: Nicolas Goaziou, Org Mode

[-- Attachment #1: Type: text/plain, Size: 392 bytes --]

Hi Nicolas, hi all

The help provided from this thread about the function outline-level
and "Match Data"
http://thread.gmane.org/gmane.emacs.orgmode/42611
allowed me to make the attached patch. It resolves two or so buglets,
the one I found first was introduced by
http://orgmode.org/w/?p=org-mode.git;a=commitdiff;h=ddc24673877da5f7d82375fb10b8cc238e2ff6a7
according to git bisect.

Michael

[-- Attachment #2: 0001-Bugfix-for-heading-levels-when-toggling-from-list.patch --]
[-- Type: application/octet-stream, Size: 2743 bytes --]

From ffcbe6207484ec08fc1bdd2b911459326cb338b5 Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Thu, 9 Jun 2011 08:59:09 +0200
Subject: [PATCH] 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.
---
 lisp/org.el |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index bb00573..f9745c1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17963,12 +17963,20 @@ stars to add."
 	     (looking-at outline-regexp) (replace-match ""))
 	   (forward-line)))
 	;; Case 2. Started at an item: change items into headlines.
+	;;         One star will be added by `org-list-to-subtree'.
 	((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)
 	     (when (org-at-item-p)
 	       ;; Pay attention to cases when region ends before list.
@@ -17979,9 +17987,8 @@ stars to add."
 		   (insert
 		    (org-list-to-subtree
 		     (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))))
 	;; Case 3. Started at normal text: make every line an heading,
 	;;         skipping headlines and items.
@@ -17990,10 +17997,11 @@ stars to add."
 			      (prefix-numeric-value current-prefix-arg)
 			    (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 " ")))
 	     (while (< (point) end)
 	       (when (and (not (org-on-heading-p)) (not (org-at-item-p))
-- 
1.7.4.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-10  5:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-09  7:07 [PATCH] Bugfix for heading levels when toggling from list Michael Brand
2011-06-09  7:54 ` Nicolas Goaziou
2011-06-09 11:13   ` Michael Brand
2011-06-10  5:25     ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).