From: Stephen Berman Date: Sun, 2 Jul 2023 09:49:08 +0000 (+0200) Subject: Fix todo-mode commands to move items and categories (bug#64298) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a2ccab18ca247c5ba99499aa65470e15e33adcda;p=emacs.git Fix todo-mode commands to move items and categories (bug#64298) * lisp/calendar/todo-mode.el (todo-move-category): Restore display of selected category in source file, so internal file structure is not visible if user is prompted to choose a new category name in target file, and widen again to delete moved category from source file. (todo-move-item): Don't use todo-forward-item when moving done items, to avoid mislocation if done items sections of the the target category was empty before moving. (todo-forward-item): Remove commented out code meant to have the effect of the above change in todo-move-item, but it did not work. --- diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index ad18e8f035e..56b0943d303 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -1463,6 +1463,10 @@ the archive of the file moved to, creating it if it does not exist." (point-max))) (content (buffer-substring-no-properties beg end)) (counts (cdr (assoc cat todo-categories)))) + ;; Restore display of selected category, so internal file + ;; structure is not visible if user is prompted to choose a new + ;; category name in target file. + (todo-category-select) ;; Move the category to the new file. Also update or create ;; archive file if necessary. (with-current-buffer @@ -1525,7 +1529,8 @@ the archive of the file moved to, creating it if it does not exist." ;; last category, delete the file. Also handle archive file ;; if necessary. (let ((buffer-read-only nil)) - (remove-overlays beg end) + (widen) + (remove-overlays beg end) (delete-region beg end) (goto-char (point-min)) ;; Put point after todo-categories sexp. @@ -2856,7 +2861,8 @@ section in the category moved to." (while done-items (let ((buffer-read-only nil)) (todo-insert-with-overlays (pop done-items))) - (todo-forward-item))) + (todo-item-end) + (forward-line))) ;; If only done items were moved, move point to the top ;; one, otherwise, move point to the top moved todo item. (goto-char here) @@ -5296,21 +5302,7 @@ changes you have made in the order of the categories. ;; legitimate place to insert an item. But skip this space if ;; count > 1, since that should only stop on an item. (when (and not-done (todo-done-item-p) (not count)) - ;; (if (or (not count) (= count 1)) - (re-search-backward "^$" start t))));) - ;; The preceding sexp is insufficient when buffer is not narrowed, - ;; since there could be no done items in this category, so the - ;; search puts us on first todo item of next category. Does this - ;; ever happen? If so: - ;; (let ((opoint) (point)) - ;; (forward-line -1) - ;; (when (or (not count) (= count 1)) - ;; (cond ((looking-at (concat "^" (regexp-quote todo-category-beg))) - ;; (forward-line -2)) - ;; ((looking-at (concat "^" (regexp-quote todo-category-done))) - ;; (forward-line -1)) - ;; (t - ;; (goto-char opoint))))))) + (re-search-backward "^$" start t)))) (defun todo-backward-item (&optional count) "Move point up to start of item with next higher priority.