emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org f64c8a5a5b: org-insert-heading: Prevent 0-blanks af


From: ELPA Syncer
Subject: [elpa] externals/org f64c8a5a5b: org-insert-heading: Prevent 0-blanks after heading when there is blank before
Date: Fri, 10 May 2024 06:58:32 -0400 (EDT)

branch: externals/org
commit f64c8a5a5b91657ae3985bda199a2fc475180f12
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-insert-heading: Prevent 0-blanks after heading when there is blank 
before
    
    * lisp/org.el (org-insert-heading): When creating a new heading with
    blank lines before results in the _next_ heading to have no blank
    lines, add them.
    
    Reported-by: gusbrs <gusbrs.2016@gmail.com>
    Link: https://orgmode.org/list/877cjl67z6.fsf@localhost
---
 lisp/org.el | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 09541ea0b9..92fa575ca9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6409,7 +6409,17 @@ but not a number, insert a level-1 heading."
                      current-level
                      ;; This `1' is for when before first headline
                      1))
-         (stars (make-string num-stars ?*)))
+         (stars (make-string num-stars ?*))
+         (maybe-add-blank-after
+          (lambda (blank?)
+            "Add a blank line before next heading when BLANK? is non-nil.
+Assume that point is on the inserted heading."
+            (save-excursion
+              (end-of-line)
+              (unless (eobp)
+                (forward-char)
+                (when (and blank? (org-at-heading-p))
+                  (insert "\n")))))))
     (cond
      ((or org-insert-heading-respect-content
          (member arg '((4) (16)))
@@ -6439,6 +6449,8 @@ but not a number, insert a level-1 heading."
       (insert stars " " "\n")
       ;; Move point after stars.
       (backward-char)
+      ;; Retain blank lines before next heading.
+      (funcall maybe-add-blank-after blank?)
       ;; When INVISIBLE-OK is non-nil, ensure newly created headline
       ;; is visible.
       (unless invisible-ok
@@ -6473,23 +6485,31 @@ but not a number, insert a level-1 heading."
               (end-of-line)
               (when blank? (insert "\n"))
               (insert "\n" stars " ")
+               ;; Retain blank lines before next heading.
+               (funcall maybe-add-blank-after blank?)
               (when (org-string-nw-p split) (insert split))))
            (t
             (end-of-line)
             (when blank? (insert "\n"))
-            (insert "\n" stars " "))))
+            (insert "\n" stars " ")
+             ;; Retain blank lines before next heading.
+             (funcall maybe-add-blank-after blank?))))
      ;; On regular text, turn line into a headline or split, if
      ;; appropriate.
      ((bolp)
       (insert stars " ")
       (unless (and blank? (org-previous-line-empty-p))
-        (org-N-empty-lines-before-current (if blank? 1 0))))
+        (org-N-empty-lines-before-current (if blank? 1 0)))
+      ;; Retain blank lines before next heading.
+      (funcall maybe-add-blank-after blank?))
      (t
       (unless (org-get-alist-option org-M-RET-may-split-line 'headline)
         (end-of-line))
       (insert "\n" stars " ")
       (unless (and blank? (org-previous-line-empty-p))
-        (org-N-empty-lines-before-current (if blank? 1 0))))))
+        (org-N-empty-lines-before-current (if blank? 1 0)))
+      ;; Retain blank lines before next heading.
+      (funcall maybe-add-blank-after blank?))))
   (run-hooks 'org-insert-heading-hook))
 
 (defun org-N-empty-lines-before-current (n)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]