aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2018-08-14 21:39:24 +0200
committerStephen Berman2018-08-14 21:39:24 +0200
commita2ec595e5d7cf95715312a9cd0a6f4ef0f6e370f (patch)
tree75f7d6ebf424945177cc972b3b15f3bf86d822b2
parent11c7c2f758f8f07e7b917fbc93267cee236a80e5 (diff)
downloademacs-a2ec595e5d7cf95715312a9cd0a6f4ef0f6e370f.tar.gz
emacs-a2ec595e5d7cf95715312a9cd0a6f4ef0f6e370f.zip
Fix exiting from editing todo archive file (bug#32437)
* lisp/calendar/todo-mode.el (todo-edit-file): Make the warning also suitable for Todo Archive mode, and add more space to it. (todo-edit-quit): On quitting editing an archive file, return to the Todo Archive mode buffer editing was invoked in. (todo-check-format): Display a warning instead of a message when the categories sexp isn't as expected. (todo-mode-external-set): Remove. (todo-edit-mode): Set buffer local values of todo-current-todo-file and todo-categories from the todo or archive file being edited. (todo-categories-mode): Set buffer local values of todo-current-todo-file and todo-categories as before but directly instead of using superfluous todo-mode-external-set function. * test/lisp/calendar/todo-mode-tests.el (todo-test-edit-quit): New test.
-rw-r--r--lisp/calendar/todo-mode.el87
-rw-r--r--test/lisp/calendar/todo-mode-tests.el18
2 files changed, 73 insertions, 32 deletions
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el
index 9c770f17fb1..f7af65c36b8 100644
--- a/lisp/calendar/todo-mode.el
+++ b/lisp/calendar/todo-mode.el
@@ -1242,9 +1242,10 @@ this command should be used with caution."
1242 (widen) 1242 (widen)
1243 (todo-edit-mode) 1243 (todo-edit-mode)
1244 (remove-overlays) 1244 (remove-overlays)
1245 (display-warning 'todo (format "\ 1245 (display-warning
1246 'todo (format "\
1246 1247
1247Type %s to return to Todo mode. 1248Type %s to return to Todo%s mode.
1248 1249
1249This also runs a file format check and signals an error if 1250This also runs a file format check and signals an error if
1250the format has become invalid. However, this check cannot 1251the format has become invalid. However, this check cannot
@@ -1254,7 +1255,12 @@ You can repair this inconsistency by invoking the command
1254`todo-repair-categories-sexp', but this will revert any 1255`todo-repair-categories-sexp', but this will revert any
1255renumbering of the categories you have made, so you will 1256renumbering of the categories you have made, so you will
1256have to renumber them again (see `(todo-mode) Reordering 1257have to renumber them again (see `(todo-mode) Reordering
1257Categories')." (substitute-command-keys "\\[todo-edit-quit]")))) 1258Categories').
1259"
1260 (substitute-command-keys "\\[todo-edit-quit]")
1261 (if (equal "toda" (file-name-extension
1262 (buffer-file-name)))
1263 " Archive" ""))))
1258 1264
1259(defun todo-add-category (&optional file cat) 1265(defun todo-add-category (&optional file cat)
1260 "Add a new category to a todo file. 1266 "Add a new category to a todo file.
@@ -2240,7 +2246,9 @@ made in the number or names of categories."
2240 ;; (todo-repair-categories-sexp) 2246 ;; (todo-repair-categories-sexp)
2241 ;; Compare (todo-make-categories-list t) with sexp and if 2247 ;; Compare (todo-make-categories-list t) with sexp and if
2242 ;; different ask (todo-update-categories-sexp) ? 2248 ;; different ask (todo-update-categories-sexp) ?
2243 (todo-mode) 2249 (if (equal (file-name-extension (buffer-file-name)) "toda")
2250 (todo-archive-mode)
2251 (todo-mode))
2244 (let* ((cat-beg (concat "^" (regexp-quote todo-category-beg) 2252 (let* ((cat-beg (concat "^" (regexp-quote todo-category-beg)
2245 "\\(.*\\)$")) 2253 "\\(.*\\)$"))
2246 (curline (buffer-substring-no-properties 2254 (curline (buffer-substring-no-properties
@@ -5094,7 +5102,7 @@ again."
5094 5102
5095(defun todo-check-format () 5103(defun todo-check-format ()
5096 "Signal an error if the current todo file is ill-formatted. 5104 "Signal an error if the current todo file is ill-formatted.
5097Otherwise return t. Display a message if the file is well-formed 5105Otherwise return t. Display a warning if the file is well-formed
5098but the categories sexp differs from the current value of 5106but the categories sexp differs from the current value of
5099`todo-categories'." 5107`todo-categories'."
5100 (save-excursion 5108 (save-excursion
@@ -5128,12 +5136,14 @@ but the categories sexp differs from the current value of
5128 (forward-line))) 5136 (forward-line)))
5129 ;; Warn user if categories sexp has changed. 5137 ;; Warn user if categories sexp has changed.
5130 (unless (string= ssexp cats) 5138 (unless (string= ssexp cats)
5131 (message (concat "The sexp at the beginning of the file differs " 5139 (display-warning 'todo "\
5132 "from the value of `todo-categories'.\n" 5140
5133 "If the sexp is wrong, you can fix it with " 5141The sexp at the beginning of the file differs from the value of
5134 "M-x todo-repair-categories-sexp,\n" 5142`todo-categories'. If the sexp is wrong, you can fix it with
5135 "but note this reverts any changes you have " 5143M-x todo-repair-categories-sexp, but note this reverts any
5136 "made in the order of the categories.")))))) 5144changes you have made in the order of the categories.
5145"
5146 )))))
5137 t) 5147 t)
5138 5148
5139(defun todo-item-start () 5149(defun todo-item-start ()
@@ -6711,32 +6721,36 @@ Added to `window-configuration-change-hook' in Todo mode."
6711 (setq-local todo-current-todo-file (file-truename (buffer-file-name))) 6721 (setq-local todo-current-todo-file (file-truename (buffer-file-name)))
6712 (setq-local todo-show-done-only t)) 6722 (setq-local todo-show-done-only t))
6713 6723
6714(defun todo-mode-external-set () 6724;; (defun todo-mode-external-set ()
6715 "Set `todo-categories' externally to `todo-current-todo-file'." 6725;; "Set `todo-categories' externally to `todo-current-todo-file'."
6716 (setq-local todo-current-todo-file todo-global-current-todo-file) 6726;; (setq-local todo-current-todo-file todo-global-current-todo-file)
6717 (let ((cats (with-current-buffer 6727;; (let ((cats (with-current-buffer
6718 ;; Can't use find-buffer-visiting when 6728;; ;; Can't use find-buffer-visiting when
6719 ;; `todo-show-categories-table' is called on first 6729;; ;; `todo-show-categories-table' is called on first
6720 ;; invocation of `todo-show', since there is then 6730;; ;; invocation of `todo-show', since there is then
6721 ;; no buffer visiting the current file. 6731;; ;; no buffer visiting the current file.
6722 (find-file-noselect todo-current-todo-file 'nowarn) 6732;; (find-file-noselect todo-current-todo-file 'nowarn)
6723 (or todo-categories 6733;; (or todo-categories
6724 ;; In Todo Edit mode todo-categories is now nil 6734;; ;; In Todo Edit mode todo-categories is now nil
6725 ;; since it uses same buffer as Todo mode but 6735;; ;; since it uses same buffer as Todo mode but
6726 ;; doesn't have the latter's local variables. 6736;; ;; doesn't have the latter's local variables.
6727 (save-excursion 6737;; (save-excursion
6728 (goto-char (point-min)) 6738;; (goto-char (point-min))
6729 (read (buffer-substring-no-properties 6739;; (read (buffer-substring-no-properties
6730 (line-beginning-position) 6740;; (line-beginning-position)
6731 (line-end-position)))))))) 6741;; (line-end-position))))))))
6732 (setq-local todo-categories cats))) 6742;; (setq-local todo-categories cats)))
6733 6743
6734(define-derived-mode todo-edit-mode text-mode "Todo-Ed" 6744(define-derived-mode todo-edit-mode text-mode "Todo-Ed"
6735 "Major mode for editing multiline todo items. 6745 "Major mode for editing multiline todo items.
6736 6746
6737\\{todo-edit-mode-map}" 6747\\{todo-edit-mode-map}"
6738 (todo-modes-set-1) 6748 (todo-modes-set-1)
6739 (todo-mode-external-set) 6749 ;; (todo-mode-external-set)
6750 (setq-local todo-current-todo-file (file-truename (buffer-file-name)))
6751 (when (= (buffer-size) (- (point-max) (point-min)))
6752 ;; Only need this when editing the whole file not just an item.
6753 (setq-local todo-categories (todo-set-categories)))
6740 (setq buffer-read-only nil)) 6754 (setq buffer-read-only nil))
6741 6755
6742(put 'todo-categories-mode 'mode-class 'special) 6756(put 'todo-categories-mode 'mode-class 'special)
@@ -6745,7 +6759,16 @@ Added to `window-configuration-change-hook' in Todo mode."
6745 "Major mode for displaying and editing todo categories. 6759 "Major mode for displaying and editing todo categories.
6746 6760
6747\\{todo-categories-mode-map}" 6761\\{todo-categories-mode-map}"
6748 (todo-mode-external-set)) 6762 ;; (todo-mode-external-set)
6763 (setq-local todo-current-todo-file todo-global-current-todo-file)
6764 (setq-local todo-categories
6765 ;; Can't use find-buffer-visiting when
6766 ;; `todo-show-categories-table' is called on first
6767 ;; invocation of `todo-show', since there is then no
6768 ;; buffer visiting the current file.
6769 (with-current-buffer (find-file-noselect
6770 todo-current-todo-file 'nowarn)
6771 todo-categories)))
6749 6772
6750(put 'todo-filtered-items-mode 'mode-class 'special) 6773(put 'todo-filtered-items-mode 'mode-class 'special)
6751 6774
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el
index 325faeff514..90282045062 100644
--- a/test/lisp/calendar/todo-mode-tests.el
+++ b/test/lisp/calendar/todo-mode-tests.el
@@ -763,6 +763,24 @@ The highlighting should remain enabled."
763 (ert-simulate-command '(forward-line)) ; Now on first done item. 763 (ert-simulate-command '(forward-line)) ; Now on first done item.
764 (should (eq 'hl-line (get-char-property (point) 'face))))) 764 (should (eq 'hl-line (get-char-property (point) 'face)))))
765 765
766(ert-deftest todo-test-edit-quit ()
767 "Test result of exiting todo-edit-mode on a whole file.
768Exiting should return to the same todo-mode or todo-archive-mode
769buffer from which the editing command was invoked."
770 (with-todo-test
771 (todo-test--show 1)
772 (let ((buf (current-buffer)))
773 (todo-edit-file)
774 (todo-edit-quit)
775 (should (eq (current-buffer) buf))
776 (should (eq major-mode 'todo-mode))
777 (todo-find-archive)
778 (let ((buf (current-buffer)))
779 (todo-edit-file)
780 (todo-edit-quit)
781 (should (eq (current-buffer) buf))
782 (should (eq major-mode 'todo-archive-mode))))))
783
766 784
767(provide 'todo-mode-tests) 785(provide 'todo-mode-tests)
768;;; todo-mode-tests.el ends here 786;;; todo-mode-tests.el ends here