From 61cf8cd7ac5a35799a78fab3b0474692d4ddb683 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 22 Oct 2008 07:53:22 +0200 Subject: [PATCH] Modify behavior at headling insertion. C-RET now always inserts a heading, never an item. The folding state of the heading before the newly inserted one is preserved. Patch by Peter Jones. --- doc/org.texi | 5 +++-- lisp/ChangeLog | 7 +++++++ lisp/org.el | 21 ++++++++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index e342aab76..afd68a6fd 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -897,8 +897,9 @@ of a headline), then a headline like the current one will be inserted after the end of the subtree. @kindex C-@key{RET} @item C-@key{RET} -Just like @kbd{M-@key{RET}}, but if the heading is inserted after the current, -insert it actually after the entire subtree. +Just like @kbd{M-@key{RET}}, except when adding a new heading below the +current heading, the new heading is placed after the body instead of before +it. This command works from anywhere in the entry. @kindex M-S-@key{RET} @item M-S-@key{RET} Insert new TODO entry with same level as current heading. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e6841cd64..65062fc25 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2008-10-22 Carsten Dominik + + * org.el (org-insert-heading-respect-content): Force heading + creation. + (org-insert-heading): keep the folding state of the heading before + the inserted one. + 2008-10-21 Carsten Dominik * org-archive.el (org-archive-to-archive-sibling): Handle top diff --git a/lisp/org.el b/lisp/org.el index d9cf394e7..cd0b7e98a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4607,7 +4607,7 @@ but create the new hedline after the current line." (match-string 0)) (error "*")))) (blank (cdr (assq 'heading org-blank-before-new-entry))) - pos) + pos hide-previous) (cond ((and (org-on-heading-p) (bolp) (or (bobp) @@ -4622,6 +4622,9 @@ but create the new hedline after the current line." nil) (t ;; in the middle of the line + (save-excursion + (end-of-line) + (setq hide-previous (org-invisible-p))) (org-show-entry) (let ((split (org-get-alist-option org-M-RET-may-split-line 'headline)) @@ -4652,6 +4655,10 @@ but create the new hedline after the current line." (setq pos (point)) (end-of-line 1) (unless (= (point) pos) (just-one-space) (backward-delete-char 1)) + (when (and org-insert-heading-respect-content hide-previous) + (save-excursion + (outline-previous-visible-heading 1) + (hide-entry))) (run-hooks 'org-insert-heading-hook))))) (defun org-get-heading (&optional no-tags) @@ -4675,20 +4682,20 @@ but create the new hedline after the current line." (defun org-insert-heading-respect-content () (interactive) (let ((org-insert-heading-respect-content t)) - (call-interactively 'org-insert-heading))) + (org-insert-heading t))) -(defun org-insert-todo-heading-respect-content () - (interactive) +(defun org-insert-todo-heading-respect-content (&optional force-state) + (interactive "P") (let ((org-insert-heading-respect-content t)) - (call-interactively 'org-insert-todo-heading))) + (org-insert-todo-heading force-state t))) -(defun org-insert-todo-heading (arg) +(defun org-insert-todo-heading (arg &optional force-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 state (TODO by default). Also with prefix arg, force first state." (interactive "P") (when (not (org-insert-item 'checkbox)) - (org-insert-heading) + (org-insert-heading force-heading) (save-excursion (org-back-to-heading) (outline-previous-heading) -- 2.11.4.GIT