\\{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))
(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