From: Stephen Berman Date: Tue, 14 Aug 2018 22:14:41 +0000 (+0200) Subject: Fix last todo-edit-mode change X-Git-Tag: emacs-27.0.90~4565 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6d24402d6358b2e6ccf78a6cb909723a5d18dd27;p=emacs.git Fix last todo-edit-mode change * 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. --- diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 1623c6e2ec8..08da75dbd60 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -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)) diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el index 90282045062..6cd2bfe35b3 100644 --- a/test/lisp/calendar/todo-mode-tests.el +++ b/test/lisp/calendar/todo-mode-tests.el @@ -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