summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2013-09-01 14:04:48 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2013-09-01 14:04:48 +0200
commitb8c85a13bbfaa369874ee618bfaf218fb21f56f6 (patch)
tree4dc4b9b279b70743c69f85d86f2b76309ece9d76
parent2c38c3acc0b5d1cb3bb26f45829d711bb6f4009c (diff)
downloadorg-mode-b8c85a13bbfaa369874ee618bfaf218fb21f56f6.tar.gz
Improve the empty line insertion behavior of `org-insert-heading'.
* lisp/org.el (org-insert-heading): Improve the empty line insertion behavior. Basically, never remove empty lines, only add them. This was a request by Nicolas Goaziou.
-rw-r--r--lisp/org.el29
1 files changed, 19 insertions, 10 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 97b5365..a3e9f3e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7564,7 +7564,7 @@ This is important for non-interactive uses of the command."
(or arg (not itemp))))
;; At beginning of buffer or so hight up that only a heading makes sense.
(insert
- (if (org-previous-line-empty-p) "" "\n")
+ (if (or (bobp) (org-previous-line-empty-p)) "" "\n")
(if (org-in-src-block-p) ",* " "* "))
(run-hooks 'org-insert-heading-hook))
@@ -7576,13 +7576,17 @@ This is important for non-interactive uses of the command."
;; Insert a heading
(save-restriction
(widen)
- (let* ((empty-line-p nil)
- (level nil)
+ (let* ((level nil)
(on-heading (org-at-heading-p))
- ;; Get a level to fall back on
+ (empty-line-p (if on-heading
+ (org-previous-line-empty-p)
+ ;; We will decide later
+ nil))
+ ;; Get a level string to fall back on
(fix-level
(save-excursion
(org-back-to-heading t)
+ (if (org-previous-line-empty-p) (setq empty-line-p t))
(looking-at org-outline-regexp)
(make-string (1- (length (match-string 0))) ?*)))
(stars
@@ -7603,10 +7607,12 @@ This is important for non-interactive uses of the command."
(error "This should not happen")))
(unless (and (save-excursion
(save-match-data
- (org-backward-heading-same-level 1 invisible-ok))
+ (org-backward-heading-same-level
+ 1 invisible-ok))
(= (point) (match-beginning 0)))
(not (org-previous-line-empty-p t)))
- (setq empty-line-p (org-previous-line-empty-p)))
+ (setq empty-line-p (or empty-line-p
+ (org-previous-line-empty-p))))
(match-string 0))
(error (or fix-level "* ")))))
(blank-a (cdr (assq 'heading org-blank-before-new-entry)))
@@ -7640,9 +7646,10 @@ This is important for non-interactive uses of the command."
(setq initial-content (org-trim initial-content)))
(goto-char pos))
;; a normal line
- (setq initial-content (buffer-substring (point) (point-at-eol)))
- (delete-region (point) (point-at-eol))
- (setq initial-content (org-trim initial-content))))
+ (unless (bolp)
+ (setq initial-content (buffer-substring (point) (point-at-eol)))
+ (delete-region (point) (point-at-eol))
+ (setq initial-content (org-trim initial-content)))))
;; If we are at the beginning of the line, insert before it. Else after
(cond
@@ -7657,7 +7664,9 @@ This is important for non-interactive uses of the command."
(insert stars)
(just-one-space)
(insert initial-content)
- (if adjust-empty-lines (org-N-empty-lines-before-current (if empty-line-p 1 0)))
+ (if adjust-empty-lines
+ (if (and blank (not (org-previous-line-empty-p)))
+ (org-N-empty-lines-before-current (if blank 1 0))))
(run-hooks 'org-insert-heading-hook)))))))
(defun org-N-empty-lines-before-current (N)