]> code.delx.au - gnu-emacs/commitdiff
Fix todo-mode bug involving archived items (bug#23447)
authorStephen Berman <stephen.berman@gmx.net>
Wed, 4 May 2016 19:52:32 +0000 (21:52 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Wed, 4 May 2016 19:52:32 +0000 (21:52 +0200)
* lisp/calendar/todo-mode.el (todo-jump-to-category): When jumping
from Todo Categories mode to a category with only archived items
and todo-skip-archived-categories is non-nil, make sure the
archive file buffer is in Todo Archive mode to prevent
todo-category-select from raising an error, and don't set
todo-current-todo-file, since that makes todo-show display the
archived category.  Remove a no-op call to kill-buffer, which is
already called in todo-insert-category-line.

lisp/calendar/todo-mode.el

index 0529e97033398f46904f35287ff49f33dc4677b4..8e7525860530f3d6f9bb743f147ba610e692f84b 100644 (file)
@@ -902,17 +902,19 @@ Categories mode."
       (todo-show)
     (let* ((archive (eq where 'archive))
           (cat (unless archive where))
+           (goto-archive (and cat
+                              todo-skip-archived-categories
+                              (zerop (todo-get-count 'todo cat))
+                              (zerop (todo-get-count 'done cat))
+                              (not (zerop (todo-get-count 'archived cat)))))
           (file0 (when cat             ; We're in Todo Categories mode.
-                   ;; With non-nil `todo-skip-archived-categories'
-                   ;; jump to archive file of a category with only
-                   ;; archived items.
-                   (if (and todo-skip-archived-categories
-                            (zerop (todo-get-count 'todo cat))
-                            (zerop (todo-get-count 'done cat))
-                            (not (zerop (todo-get-count 'archived cat))))
+                   (if goto-archive
+                       ;; If the category has only archived items and
+                       ;; `todo-skip-archived-categories' is non-nil, jump to
+                       ;; the archive category.
                        (concat (file-name-sans-extension
                                 todo-current-todo-file) ".toda")
-                     ;; Otherwise, jump to current todo file.
+                     ;; Otherwise, jump to the category in the todo file.
                      todo-current-todo-file)))
           (len (length todo-categories))
           (cat+file (unless cat
@@ -923,18 +925,15 @@ Categories mode."
           (category (or cat (car cat+file))))
       (unless cat (setq file0 (cdr cat+file)))
       (with-current-buffer (find-file-noselect file0 'nowarn)
-       (setq todo-current-todo-file file0)
-       ;; If called from Todo Categories mode, clean up before jumping.
-       (if (string= (buffer-name) todo-categories-buffer)
-           (kill-buffer))
-       (set-window-buffer (selected-window)
-                          (set-buffer (find-buffer-visiting file0)))
-       (unless todo-global-current-todo-file
-         (setq todo-global-current-todo-file todo-current-todo-file))
-       (todo-category-number category)
-       (todo-category-select)
-       (goto-char (point-min))
-       (when add-item (todo-insert-item--basic))))))
+        (when goto-archive (todo-archive-mode))
+        (set-window-buffer (selected-window)
+                           (set-buffer (find-buffer-visiting file0)))
+        (unless todo-global-current-todo-file
+          (setq todo-global-current-todo-file todo-current-todo-file))
+        (todo-category-number category)
+        (todo-category-select)
+        (goto-char (point-min))
+        (when add-item (todo-insert-item--basic))))))
 
 (defun todo-next-item (&optional count)
   "Move point down to the beginning of the next item.