mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2025-01-05 11:45:52 +00:00
Editing: Automatic empty lines before new entries.
The variable `org-blank-before-new-entry' regulates if Org should insert a blank line before a new entry, when making a new headline or plain list item. Up to now, the possible values in each case where t or nil, i.e. unconditionally do or don't insert a blank line. Now each setting can also be `auto'. If this is the case, Org will look if the current entry, of which the command creates a sibling, does have a blank line before it. If yes, it will also make a blank line. If not, it will not. This seems so useful that I have made this behavior the default.
This commit is contained in:
parent
e245f4c8d0
commit
15ad97ac3c
@ -1,3 +1,14 @@
|
||||
2009-01-08 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org.el (org-insert-heading): Handle new value `auto' for
|
||||
`org-blank-before-new-entry'.
|
||||
|
||||
* org-list.el (org-insert-item): Handle new value `auto' for
|
||||
`org-blank-before-new-entry'.
|
||||
|
||||
* org.el (org-blank-before-new-entry): New value `auto', made
|
||||
default.
|
||||
|
||||
2009-01-07 Carsten Dominik <carsten.dominik@gmail.com>
|
||||
|
||||
* org-exp.el (org-export-normalize-links): If the link is also
|
||||
|
@ -189,13 +189,20 @@ Return t when things worked, nil when we are not in an item."
|
||||
(save-match-data
|
||||
(and (looking-at "[ \t]*\\(.*?\\) ::")
|
||||
(match-string 1)))))
|
||||
(empty-line-p (save-excursion
|
||||
(goto-char (match-beginning 0))
|
||||
(and (not (bobp))
|
||||
(or (beginning-of-line 0) t)
|
||||
(save-match-data
|
||||
(looking-at "[ \t]*$")))))
|
||||
(timerp (and descp
|
||||
(save-match-data
|
||||
(string-match "^[-+*][ \t]+[0-9]+:[0-9]+:[0-9]+$"
|
||||
descp))))
|
||||
(eow (save-excursion (beginning-of-line 1) (looking-at "[ \t]*")
|
||||
(match-end 0)))
|
||||
(blank (cdr (assq 'plain-list-item org-blank-before-new-entry)))
|
||||
(blank-a (cdr (assq 'plain-list-item org-blank-before-new-entry)))
|
||||
(blank (if (eq blank-a 'auto) empty-line-p blank-a))
|
||||
pos)
|
||||
(if descp (setq checkbox nil))
|
||||
(if timerp
|
||||
|
30
lisp/org.el
30
lisp/org.el
@ -689,15 +689,21 @@ for the duration of the command."
|
||||
:group 'org-structure
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom org-blank-before-new-entry '((heading . nil)
|
||||
(plain-list-item . nil))
|
||||
(defcustom org-blank-before-new-entry '((heading . auto)
|
||||
(plain-list-item . auto))
|
||||
"Should `org-insert-heading' leave a blank line before new heading/item?
|
||||
The value is an alist, with `heading' and `plain-list-item' as car,
|
||||
and a boolean flag as cdr."
|
||||
:group 'org-edit-structure
|
||||
:type '(list
|
||||
(cons (const heading) (boolean))
|
||||
(cons (const plain-list-item) (boolean))))
|
||||
(cons (const heading)
|
||||
(choice (const :tag "Never" nil)
|
||||
(const :tag "Always" t)
|
||||
(const :tag "Auto" auto)))
|
||||
(cons (const plain-list-item)
|
||||
(choice (const :tag "Never" nil)
|
||||
(const :tag "Always" t)
|
||||
(const :tag "Auto" auto)))))
|
||||
|
||||
(defcustom org-insert-heading-hook nil
|
||||
"Hook being run after inserting a new heading."
|
||||
@ -4831,6 +4837,13 @@ frame is not changed."
|
||||
|
||||
;;; Inserting headlines
|
||||
|
||||
(defun org-previous-line-empty-p ()
|
||||
(save-excursion
|
||||
(and (not (bobp))
|
||||
(or (beginning-of-line 0) t)
|
||||
(save-match-data
|
||||
(looking-at "[ \t]*$")))))
|
||||
|
||||
(defun org-insert-heading (&optional force-heading)
|
||||
"Insert a new heading or item with same depth at point.
|
||||
If point is in a plain list and FORCE-HEADING is nil, create a new list item.
|
||||
@ -4841,13 +4854,16 @@ but create the new headline after the current line."
|
||||
(if (= (buffer-size) 0)
|
||||
(insert "\n* ")
|
||||
(when (or force-heading (not (org-insert-item)))
|
||||
(let* ((head (save-excursion
|
||||
(let* ((empty-line-p nil)
|
||||
(head (save-excursion
|
||||
(condition-case nil
|
||||
(progn
|
||||
(org-back-to-heading)
|
||||
(setq empty-line-p (org-previous-line-empty-p))
|
||||
(match-string 0))
|
||||
(error "*"))))
|
||||
(blank (cdr (assq 'heading org-blank-before-new-entry)))
|
||||
(blank-a (cdr (assq 'heading org-blank-before-new-entry)))
|
||||
(blank (if (eq blank-a 'auto) empty-line-p blank-a))
|
||||
pos hide-previous previous-pos)
|
||||
(cond
|
||||
((and (org-on-heading-p) (bolp)
|
||||
@ -4880,6 +4896,8 @@ but create the new headline after the current line."
|
||||
(org-insert-heading-respect-content
|
||||
(org-end-of-subtree nil t)
|
||||
(or (bolp) (newline))
|
||||
(or (org-previous-line-empty-p)
|
||||
(and blank (newline)))
|
||||
(open-line 1))
|
||||
((org-on-heading-p)
|
||||
(when hide-previous
|
||||
|
Loading…
Reference in New Issue
Block a user