From 83575624abe3e32c5463b98b319c9c8e7c67c283 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 2 Aug 2023 15:23:06 +0300 Subject: [PATCH] Ensure that clocking drawer is inserted before point * lisp/org-clock.el (org-clock-find-position): Insert before point when creating drawers. This makes sure that newly inserted drawer do not interfere with user typing. See f993ecd67. * lisp/org-clock.el (org-clock-in): Add commentary. --- lisp/org-clock.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index c12142d81..da19acef6 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -1418,6 +1418,9 @@ the default behavior." (sit-for 2) (throw 'abort nil)) (t + ;; Make sure that point moves after clock line upon + ;; inserting it. Then, users can continue typing even if + ;; point was right where the clock is inserted. (insert-before-markers-and-inherit "\n") (backward-char 1) (when (and (save-excursion @@ -1629,13 +1632,16 @@ line and position cursor in that line." (org-fold-core-ignore-modifications ;; Skip planning line and property drawer, if any. (org-end-of-meta-data) - (unless (bolp) (insert-and-inherit "\n")) + (unless (bolp) (insert-before-markers-and-inherit "\n")) ;; Create a new drawer if necessary. (when (and org-clock-into-drawer (or (not (wholenump org-clock-into-drawer)) (< org-clock-into-drawer 2))) (let ((beg (point))) - (insert-and-inherit ":" drawer ":\n:END:\n") + ;; Make sure that point moves after drawer upon + ;; inserting it. Then, users can continue typing even + ;; if point was right where the clock is inserted. + (insert-before-markers-and-inherit ":" drawer ":\n:END:\n") (org-indent-region beg (point)) (if (eq org-fold-core-style 'text-properties) (org-fold-region @@ -1666,7 +1672,7 @@ line and position cursor in that line." "\n:END:\n") (let ((end (point-marker))) (goto-char beg) - (save-excursion (insert-and-inherit ":" drawer ":\n")) + (save-excursion (insert-before-markers-and-inherit ":" drawer ":\n")) (org-fold-region (line-end-position) (1- end) t 'outline) (org-indent-region (point) end) (forward-line)