]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug in 'todo-jump-to-category' (bug#78608)
authorStephen Berman <stephen.berman@gmx.net>
Wed, 28 May 2025 15:17:23 +0000 (17:17 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 7 Jun 2025 19:53:00 +0000 (21:53 +0200)
* lisp/calendar/todo-mode.el (todo-jump-to-category): Eliminate
comparison of the number of Todo categories before and after
specifying the category to jump to and replace it by a check of
whether there are any items in the category, since an existing
category should always have at least one item (perhaps done or
archived).

(cherry picked from commit 4507b6a9c7587c2b3caa241982db13e999197b1c)

lisp/calendar/todo-mode.el

index 5b9bf2d8e165eff8761d0afe24807aa694a1323e..1430eda5b03adea1c373cd9db8c79bab331f6de4 100644 (file)
@@ -950,12 +950,9 @@ Categories mode."
                                 todo-current-todo-file) ".toda")
                      ;; Otherwise, jump to the category in the todo file.
                      todo-current-todo-file)))
-          (len (length todo-categories))
           (cat+file (unless cat
                       (todo-read-category "Jump to category: "
                                            (if archive 'archive) file)))
-          (add-item (and todo-add-item-if-new-category
-                         (> (length todo-categories) len)))
           (category (or cat (car cat+file))))
       (unless cat (setq file0 (cdr cat+file)))
       (with-current-buffer (find-file-noselect file0 'nowarn)
@@ -969,7 +966,10 @@ Categories mode."
         (todo-category-select)
         (goto-char (point-min))
        (if (bound-and-true-p hl-line-mode) (hl-line-highlight))
-        (when add-item (todo-insert-item--basic))))))
+        (when (and todo-add-item-if-new-category
+                   ;; A new category is empty on creation.
+                   (seq-every-p #'zerop (cdr (assoc category todo-categories))))
+          (todo-insert-item--basic))))))
 
 (defun todo-next-item (&optional count)
   "Move point down to the beginning of the next item.