branch: externals-release/org commit c670379adfbdc4883d3cfa230289fd2829993265 Author: Bastien <b...@gnu.org> Commit: Bastien <b...@gnu.org>
Fix `org-agenda-todo' undo behavior when logging (not adding note) * lisp/org.el (org-log-setup): New variable. (org-auto-repeat-maybe): Check against `org-log-setup' if we are currently logging. (org-add-log-setup): Only use `post-command-hook' when logging a note, otherwise use `org-log-setup'. (org-add-log-note): Reset `org-log-setup' to nil. (org-store-log-note): Remove useless code. * lisp/org-agenda.el (org-agenda-bulk-action): Check `org-log-setup' instead of `post-command-hook'. This is a more correct fix that supersedes the previous attempt with 08a47b09 for the same problem. Reported-by: Warren Lynn <wrn.l...@gmail.com> Link: https://orgmode.org/list/87v98a8mes....@gnu.org/ --- lisp/org-agenda.el | 4 +--- lisp/org.el | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index c99ee2a..3bcfde2 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -10512,9 +10512,7 @@ The prefix arg is passed through to the command if possible." (let (org-loop-over-headlines-in-active-region) (funcall cmd)) ;; `post-command-hook' is not run yet. We make sure any ;; pending log note is processed. - (when (or (memq 'org-add-log-note (default-value 'post-command-hook)) - (memq 'org-add-log-note post-command-hook)) - (org-add-log-note)) + (when org-log-setup (org-add-log-note)) (cl-incf processed)))) (when redo-at-end (org-agenda-redo)) (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all)) diff --git a/lisp/org.el b/lisp/org.el index dc433c0..5fe48f6 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -10392,8 +10392,7 @@ This function is run automatically after each state change to a DONE state." (org-entry-put nil "LAST_REPEAT" (format-time-string (org-time-stamp-format t t)))) (when org-log-repeat - (if (or (memq 'org-add-log-note (default-value 'post-command-hook)) - (memq 'org-add-log-note post-command-hook)) + (if org-log-setup ;; We are already setup for some record. (when (eq org-log-repeat 'note) ;; Make sure we take a note, not only a time stamp. @@ -10842,6 +10841,7 @@ narrowing." (forward-line))))) (if (bolp) (point) (line-beginning-position 2)))) +(defvar org-log-setup nil) (defun org-add-log-setup (&optional purpose state prev-state how extra) "Set up the post command hook to take a note. If this is about to TODO state change, the new state is expected in STATE. @@ -10853,8 +10853,11 @@ EXTRA is additional text that will be inserted into the notes buffer." org-log-note-previous-state prev-state org-log-note-how how org-log-note-extra extra - org-log-note-effective-time (org-current-effective-time)) - (add-hook 'post-command-hook 'org-add-log-note 'append)) + org-log-note-effective-time (org-current-effective-time) + org-log-setup t) + (if (eq how 'note) + (add-hook 'post-command-hook 'org-add-log-note 'append) + (org-add-log-note purpose))) (defun org-skip-over-state-notes () "Skip past the list of State notes in an entry." @@ -10882,6 +10885,7 @@ EXTRA is additional text that will be inserted into the notes buffer." (defun org-add-log-note (&optional _purpose) "Pop up a window for taking a note, and add this note later." (remove-hook 'post-command-hook 'org-add-log-note) + (setq org-log-setup nil) (setq org-log-note-window-configuration (current-window-configuration)) (delete-other-windows) (move-marker org-log-note-return-to (point)) @@ -10990,19 +10994,13 @@ EXTRA is additional text that will be inserted into the notes buffer." (indent-line-to ind) (insert line))) (message "Note stored") - (org-back-to-heading t)) - ;; Fix `buffer-undo-list' when `org-store-log-note' is called - ;; from within `org-add-log-note' because `buffer-undo-list' - ;; is then modified outside of `org-with-remote-undo'. - (when (eq this-command 'org-agenda-todo) - (setcdr buffer-undo-list (cddr buffer-undo-list)))))) + (org-back-to-heading t))))) ;; Don't add undo information when called from `org-agenda-todo'. - (let ((buffer-undo-list (eq this-command 'org-agenda-todo))) - (set-window-configuration org-log-note-window-configuration) - (with-current-buffer (marker-buffer org-log-note-return-to) - (goto-char org-log-note-return-to)) - (move-marker org-log-note-return-to nil) - (when org-log-post-message (message "%s" org-log-post-message)))) + (set-window-configuration org-log-note-window-configuration) + (with-current-buffer (marker-buffer org-log-note-return-to) + (goto-char org-log-note-return-to)) + (move-marker org-log-note-return-to nil) + (when org-log-post-message (message "%s" org-log-post-message))) (defun org-remove-empty-drawer-at (pos) "Remove an empty drawer at position POS.