diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-11-27 23:21:06 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-11-27 23:21:06 +0100 |
commit | b16feed40c7f519ada0cd9315251dcc257be31d2 (patch) | |
tree | a161f2f586b4e9df5bf7f848e39995e4b29be194 | |
parent | d6e20dbcff3c9fd0870d5550fb8c06750b95c4c3 (diff) | |
download | org-mode-b16feed40c7f519ada0cd9315251dcc257be31d2.tar.gz |
Normalize blank lines with <C-RET>
* lisp/org.el (org-insert-heading): Make C-RET more predictable. In
particular, it should not eat all the blank lines at the end of the
tree.
Reported-by: David Masterson <dsmasterson@outlook.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-11/msg00275.html>
-rw-r--r-- | lisp/org.el | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lisp/org.el b/lisp/org.el index 0da0007..3d239c8 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7640,22 +7640,25 @@ unconditionally." (member arg '((4) (16))) (and (not invisible-ok) (invisible-p (max (1- (point)) (point-min))))) - ;; Position point at the location of insertion. - (if (not level) ;before first headline - (org-with-limited-levels (outline-next-heading)) - ;; Make sure we end up on a visible headline if INVISIBLE-OK - ;; is nil. - (org-with-limited-levels (org-back-to-heading invisible-ok)) - (cond ((equal arg '(16)) - (org-up-heading-safe) - (org-end-of-subtree t t)) - (t - (org-end-of-subtree t t)))) - (unless (bolp) (insert "\n")) ;ensure final newline + ;; Position point at the location of insertion. Make sure we + ;; end up on a visible headline if INVISIBLE-OK is nil. + (org-with-limited-levels + (if (not level) (outline-next-heading) ;before first headline + (org-back-to-heading invisible-ok) + (when (equal arg '(16)) (org-up-heading-safe)) + (org-end-of-subtree))) + (unless (bolp) (insert "\n")) (unless (and blank? (org-previous-line-empty-p)) (org-N-empty-lines-before-current (if blank? 1 0))) - (insert stars " \n") - (forward-char -1)) + (insert stars " ") + (when (eobp) (save-excursion (insert "\n"))) + ;; When INVISIBLE-OK is non-nil, ensure newly created headline + ;; is visible. + (unless invisible-ok + (pcase (get-char-property-and-overlay (point) 'invisible) + (`(outline . ,o) + (move-overlay o (overlay-start o) (line-end-position 0))) + (_ nil)))) ;; At a headline... ((org-at-heading-p) (cond ((bolp) |