summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2013-04-11 00:35:31 +0200
committerBastien Guerry <bzg@altern.org>2013-04-11 00:35:31 +0200
commit3449c6d001b8d261b104bc9dd42bf1290d74bc0b (patch)
tree130532fc33a470cc18dd090d4192f87410c5d40d
parent9ac7fabb461242efb4e898787dd3df51842ea5fd (diff)
downloadorg-mode-3449c6d001b8d261b104bc9dd42bf1290d74bc0b.tar.gz
org.el (org-insert-heading): Convert the current line into a headline
* org.el (org-insert-heading-respect-content): Fix docstring. (org-insert-heading): When in a non-empty non-headline line, convert the current line into a headline. Thanks to Bernt Hansen for reporting this issue.
-rw-r--r--lisp/org.el13
1 files changed, 9 insertions, 4 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 2cbab66..997d0f5 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1340,9 +1340,8 @@ default the value to be used for all contexts not explicitly
(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."
+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)
@@ -7536,6 +7535,8 @@ This is important for non-interactive uses of the command."
(or (not (null arg)) org-insert-heading-respect-content))
(level nil)
(on-heading (org-at-heading-p))
+ (on-empty-line
+ (save-excursion (beginning-of-line 1) (looking-at "^\\s-*$")))
(head (save-excursion
(condition-case nil
(progn
@@ -7588,6 +7589,8 @@ This is important for non-interactive uses of the command."
tags pos)
(cond
;; Insert a new line, possibly at end of parent subtree
+ ((and (not arg) (not on-heading) (not on-empty-line))
+ (beginning-of-line 1))
(org-insert-heading-respect-content
(if (not eops)
(progn
@@ -7637,7 +7640,9 @@ This is important for non-interactive uses of the command."
(org-set-tags nil 'align))))
(t
(or split (end-of-line 1))
- (newline (if blank 2 1))))))
+ (newline (cond ((and blank (not on-empty-line)) 2)
+ (blank 1)
+ (on-empty-line 0) (t 1)))))))
(insert head) (just-one-space)
(setq pos (point))
(end-of-line 1)