Browse Source

Improve consistency for inserting new headlines.

Carsten Dominik 17 years ago
parent
commit
238d0d1880
4 changed files with 55 additions and 20 deletions
  1. 7 2
      doc/org.texi
  2. 1 0
      doc/orgcard.tex
  3. 5 0
      lisp/ChangeLog
  4. 42 18
      lisp/org.el

+ 7 - 2
doc/org.texi

@@ -890,11 +890,16 @@ of a headline), then a headline like the current one will be inserted
 after the end of the subtree.
 after the end of the subtree.
 @kindex C-@key{RET}
 @kindex C-@key{RET}
 @item C-@key{RET}
 @item C-@key{RET}
-Insert a new heading after the current subtree, same level as the
-current headline.  This command works from anywhere in the entry.
+Just like @kbd{M-@key{RET}, but if the heading is inserted after the current,
+insert it actually after the entire subtree.
 @kindex M-S-@key{RET}
 @kindex M-S-@key{RET}
 @item M-S-@key{RET}
 @item M-S-@key{RET}
 Insert new TODO entry with same level as current heading.
 Insert new TODO entry with same level as current heading.
+@kindex C-S-@key{RET}
+@item C-S-@key{RET}
+Insert new TODO entry with same level as current heading.  Like
+@kbd{C-@key{RET}}, the new headline will be inserted after the current
+subtree.
 @kindex M-@key{left}
 @kindex M-@key{left}
 @item M-@key{left}
 @item M-@key{left}
 Promote current heading by one level.
 Promote current heading by one level.

+ 1 - 0
doc/orgcard.tex

@@ -308,6 +308,7 @@ are preserved on all copies.
 \key{insert new heading/item at current level}{M-RET}
 \key{insert new heading/item at current level}{M-RET}
 \key{insert new heading after subtree}{C-RET}
 \key{insert new heading after subtree}{C-RET}
 \key{insert new TODO entry/checkbox item}{M-S-RET}
 \key{insert new TODO entry/checkbox item}{M-S-RET}
+\key{insert TODO entry/ckbx after subtree}{C-S-RET}
 
 
 \key{promote/demote heading}{M-LEFT/RIGHT}
 \key{promote/demote heading}{M-LEFT/RIGHT}
 \metax{promote/demote current subtree}{M-S-LEFT/RIGHT}
 \metax{promote/demote current subtree}{M-S-LEFT/RIGHT}

+ 5 - 0
lisp/ChangeLog

@@ -1,5 +1,10 @@
 2008-09-13  Carsten Dominik  <dominik@science.uva.nl>
 2008-09-13  Carsten Dominik  <dominik@science.uva.nl>
 
 
+	* org.el (org-insert-heading-respect-content)
+	(org-insert-todo-heading-respect-content): New commands.
+	(org-insert-heading-respect-content): New option.
+	(org-insert-heading): Respect `org-insert-heading-respect-content'.
+
 	* org-clock.el (org-clock-find-position): Make sure the note after
 	* org-clock.el (org-clock-find-position): Make sure the note after
 	the clock line gets moved into the new clock drawer.
 	the clock line gets moved into the new clock drawer.
 
 

+ 42 - 18
lisp/org.el

@@ -659,6 +659,15 @@ default   the value to be used for all contexts not explicitly
 		   (boolean)))))
 		   (boolean)))))
 
 
 
 
+(defcustom org-insert-heading-respect-content nil
+  "Non-nil means, insert new headings after the current subtree.
+When nil, the new heading is created directly after the current line.
+The commands \\[org-insert-heading-respect-content] and
+\\[org-insert-todo-heading-respect-content] turn this variable on
+for the duration of the command."
+  :group 'org-structure
+  :type 'boolean)
+
 (defcustom org-blank-before-new-entry '((heading . nil)
 (defcustom org-blank-before-new-entry '((heading . nil)
 					(plain-list-item . nil))
 					(plain-list-item . nil))
   "Should `org-insert-heading' leave a blank line before new heading/item?
   "Should `org-insert-heading' leave a blank line before new heading/item?
@@ -4599,24 +4608,28 @@ but create the new hedline after the current line."
 	  (let ((split
 	  (let ((split
 		 (org-get-alist-option org-M-RET-may-split-line 'headline))
 		 (org-get-alist-option org-M-RET-may-split-line 'headline))
 		tags pos)
 		tags pos)
-	    (if (org-on-heading-p)
-		(progn
-		  (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
-		  (setq tags (and (match-end 2) (match-string 2)))
-		  (and (match-end 1)
-		       (delete-region (match-beginning 1) (match-end 1)))
-		  (setq pos (point-at-bol))
-		  (or split (end-of-line 1))
-		  (delete-horizontal-space)
-		  (newline (if blank 2 1))
-		  (when tags
-		    (save-excursion
-		      (goto-char pos)
-		      (end-of-line 1)
-		      (insert " " tags)
-		      (org-set-tags nil 'align))))
+	    (cond
+	     (org-insert-heading-respect-content
+	      (org-end-of-subtree nil t)
+	      (open-line 1))
+	     ((org-on-heading-p)
+	      (looking-at ".*?\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)?[ \t]*$")
+	      (setq tags (and (match-end 2) (match-string 2)))
+	      (and (match-end 1)
+		   (delete-region (match-beginning 1) (match-end 1)))
+	      (setq pos (point-at-bol))
+	      (or split (end-of-line 1))
+	      (delete-horizontal-space)
+	      (newline (if blank 2 1))
+	      (when tags
+		(save-excursion
+		  (goto-char pos)
+		  (end-of-line 1)
+		  (insert " " tags)
+		  (org-set-tags nil 'align))))
+	     (t
 	      (or split (end-of-line 1))
 	      (or split (end-of-line 1))
-	      (newline (if blank 2 1))))))
+	      (newline (if blank 2 1)))))))
 	(insert head) (just-one-space)
 	(insert head) (just-one-space)
 	(setq pos (point))
 	(setq pos (point))
 	(end-of-line 1)
 	(end-of-line 1)
@@ -4641,6 +4654,16 @@ but create the new hedline after the current line."
   (org-move-subtree-down)
   (org-move-subtree-down)
   (end-of-line 1))
   (end-of-line 1))
 
 
+(defun org-insert-heading-respect-content ()
+  (interactive)
+  (let ((org-insert-heading-respect-content t))
+    (call-interactively 'org-insert-heading)))
+
+(defun org-insert-todo-heading-respect-content ()
+  (interactive)
+  (let ((org-insert-heading-respect-content t))
+    (call-interactively 'org-insert-todo-todo-heading)))
+
 (defun org-insert-todo-heading (arg)
 (defun org-insert-todo-heading (arg)
   "Insert a new heading with the same level and TODO state as current heading.
   "Insert a new heading with the same level and TODO state as current heading.
 If the heading has no TODO state, or if the state is DONE, use the first
 If the heading has no TODO state, or if the state is DONE, use the first
@@ -12662,7 +12685,8 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 (org-defkey org-mode-map "\C-c\\"   'org-tags-sparse-tree) ; Minor-mode res.
 (org-defkey org-mode-map "\C-c\\"   'org-tags-sparse-tree) ; Minor-mode res.
 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
 (org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)
 (org-defkey org-mode-map "\M-\C-m"  'org-insert-heading)
 (org-defkey org-mode-map "\M-\C-m"  'org-insert-heading)
-(org-defkey org-mode-map [(control return)] 'org-insert-heading-after-current)
+(org-defkey org-mode-map [(control return)] 'org-insert-heading-respect-content)
+(org-defkey org-mode-map [(shift control return)] 'org-insert-todo-heading-respect-content)
 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
 (org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
 (org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
 (org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)