]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix last todo-edit-mode change
authorStephen Berman <stephen.berman@gmx.net>
Tue, 14 Aug 2018 22:14:41 +0000 (00:14 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Tue, 14 Aug 2018 22:14:41 +0000 (00:14 +0200)
* lisp/calendar/todo-mode.el (todo-edit-mode): For editing an item
instead of the whole file, the current todo-file must be set from
todo-global-current-todo-file.

* test/lisp/calendar/todo-mode-tests.el (todo-test-current-file-in-edit-mode):
New test.

lisp/calendar/todo-mode.el
test/lisp/calendar/todo-mode-tests.el

index 1623c6e2ec82371c3ffac50b9f28b8de0de14f46..08da75dbd60e6a2dd706e0cb4be366a6d1737707 100644 (file)
@@ -6726,9 +6726,13 @@ Added to `window-configuration-change-hook' in Todo mode."
 
 \\{todo-edit-mode-map}"
   (todo-modes-set-1)
-  (setq-local todo-current-todo-file (file-truename (buffer-file-name)))
-  (when (= (buffer-size) (- (point-max) (point-min)))
-    ;; Only need this when editing the whole file not just an item.
+  (if (> (buffer-size) (- (point-max) (point-min)))
+      ;; Editing one item in an indirect buffer, so buffer-file-name is nil.
+      (setq-local todo-current-todo-file todo-global-current-todo-file)
+    ;; When editing archive file, make sure it is current todo file.
+    (setq-local todo-current-todo-file (file-truename (buffer-file-name)))
+    ;; Need this when editing the whole file to return to the category
+    ;; editing was invoked from.
     (setq-local todo-categories (todo-set-categories)))
   (setq buffer-read-only nil))
 
index 902820450628bbb123b95cf445fda28ac26619b5..6cd2bfe35b3374d159326a9b9751ddb3d465924b 100644 (file)
@@ -763,6 +763,29 @@ The highlighting should remain enabled."
    (ert-simulate-command '(forward-line)) ; Now on first done item.
    (should (eq 'hl-line (get-char-property (point) 'face)))))
 
+(ert-deftest todo-test-current-file-in-edit-mode ()
+  "Test the value of todo-current-todo-file in todo-edit-mode."
+  (with-todo-test
+   (todo-test--show 1)
+   ;; The preceding call todo-mode but does not run pre-command-hook
+   ;; in the test environment, thus failing to set
+   ;; todo-global-current-todo-file, which is needed for the test
+   ;; after todo-edit-item--text.  So force the hook function to run.
+   (ert-simulate-command '(todo-mode))
+   (let ((curfile todo-current-todo-file))
+     (should (equal curfile todo-test-file-1))
+     (todo-edit-item--text 'multiline)
+     (should (equal todo-current-todo-file curfile))
+     (todo-edit-quit)
+     (todo-edit-file)
+     (should (equal todo-current-todo-file curfile))
+     (todo-edit-quit))
+   (todo-find-archive)
+   (let ((curfile todo-current-todo-file))
+     (should (equal curfile todo-test-archive-1))
+     (todo-edit-file)
+     (should (equal todo-current-todo-file curfile)))))
+
 (ert-deftest todo-test-edit-quit ()
   "Test result of exiting todo-edit-mode on a whole file.
 Exiting should return to the same todo-mode or todo-archive-mode