org-log-beginning: Fix regression in c0b66bf
* lisp/org.el (org-log-beginning): Re-implement the bugfix attempted
in c0b66bf
differently to avoid slurping blank lines when creating a
new logbook drawer. Add more commentary to the function.
Reported-by: Christopher M. Miles <numbchild@gmail.com>
The reproducer:
* headline1
(point here)
* headline 2
(setq org-log-into-drawer t)
Press [C-c C-z] become bellowing content:
* headline1
:LOGBOOK:
- Note taken on [2024-06-05 Wed 12:49] \\
kkk
:END:(point here)
* headline 2
This commit is contained in:
parent
589e1f38c1
commit
223cc31ec7
55
lisp/org.el
55
lisp/org.el
|
@ -10674,6 +10674,9 @@ narrowing."
|
|||
(let ((drawer (org-log-into-drawer)))
|
||||
(cond
|
||||
(drawer
|
||||
;; This either moves past planning and property drawer, to
|
||||
;; first line below heading, or to `eob' (if heading is the
|
||||
;; last heading in buffer without contents).
|
||||
(org-end-of-meta-data)
|
||||
(let ((regexp (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$"))
|
||||
(end (if (org-at-heading-p) (point)
|
||||
|
@ -10690,24 +10693,54 @@ narrowing."
|
|||
(throw 'exit nil))))
|
||||
;; No drawer found. Create one, if permitted.
|
||||
(when create
|
||||
;; `org-end-of-meta-data' ended up at next heading
|
||||
;; * Heading to insert darawer<maybe folded>
|
||||
;; * Another heading
|
||||
;;
|
||||
;; Unless current heading is the last heading in buffer
|
||||
;; and does not have a newline, `org-end-of-meta-data'
|
||||
;; should move us somewhere below the heading.
|
||||
;; can move us to the next heading.
|
||||
;; Avoid situation when we insert drawer right before
|
||||
;; first "*". Otherwise, if the previous heading is
|
||||
;; folded, we are inserting after visible newline at
|
||||
;; the end of the fold, thus breaking the fold
|
||||
;; continuity.
|
||||
;; first "*". Otherwise, if the heading is folded, we
|
||||
;; are inserting after visible newline at the end of the
|
||||
;; fold, thus breaking the fold continuity.
|
||||
(unless (eobp)
|
||||
(when (org-at-heading-p) (backward-char)))
|
||||
(org-fold-core-ignore-modifications
|
||||
(unless (bolp) (insert-and-inherit "\n"))
|
||||
(let ((beg (point)))
|
||||
(insert-and-inherit ":" drawer ":\n:END:")
|
||||
(if (eolp) (forward-char) (insert "\n"))
|
||||
(let (;; Heading
|
||||
;; <point>
|
||||
;; Text
|
||||
(at-blank-line? (looking-at-p "^[ \t]*$"))
|
||||
;; Heading
|
||||
;; <point>Text
|
||||
(at-beginning-of-non-blank-line?
|
||||
(and (bolp) (not (eolp)))))
|
||||
(unless (bolp)
|
||||
;; Heading<point> (see `backward-char' branch above)
|
||||
(insert-and-inherit "\n"))
|
||||
(let ((beg (point)) cbeg)
|
||||
(insert-and-inherit ":" drawer ":")
|
||||
(setq cbeg (point))
|
||||
(insert-and-inherit "\n:END:")
|
||||
(cond
|
||||
(at-blank-line?
|
||||
;; Heading
|
||||
;; :LOGBOOK:
|
||||
;; :END:
|
||||
;;
|
||||
;; Text
|
||||
(insert "\n")
|
||||
(backward-char))
|
||||
(at-beginning-of-non-blank-line?
|
||||
;; Heading
|
||||
;; :LOGBOOK:
|
||||
;; :END:
|
||||
;; Text
|
||||
(insert "\n")
|
||||
(backward-char)))
|
||||
(org-indent-region beg (point))
|
||||
(org-fold-region (line-end-position -1) (1- (point)) t 'drawer))))
|
||||
(end-of-line -1))))
|
||||
(org-fold-region cbeg (point) t 'drawer)))))
|
||||
(end-of-line 0))))
|
||||
(t
|
||||
(org-end-of-meta-data org-log-state-notes-insert-after-drawers)
|
||||
(let ((endpos (point)))
|
||||
|
|
Loading…
Reference in New Issue