aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2018-09-03 22:40:24 +0200
committerStephen Berman2018-09-03 22:40:24 +0200
commit40f8ade7c81ab6f99537691ae00d2d42069bdb20 (patch)
tree470239326b29b7b0aef70878b455e8920eff5bac
parent7e24039a9747cc1117b17631511e42cb3576362b (diff)
downloademacs-40f8ade7c81ab6f99537691ae00d2d42069bdb20.tar.gz
emacs-40f8ade7c81ab6f99537691ae00d2d42069bdb20.zip
Make todo-show work when adding and deleting a new todo file
* lisp/calendar/todo-mode.el (todo-add-file): Since todo-current-todo-file must be set before calling todo-show, but the buffer is not yet in todo-mode, which makes it buffer local, explicitly set it buffer locally (bug#32627). * test/lisp/calendar/todo-mode-tests.el (todo-test--add-file) (todo-test--delete-file): New functions. (todo-test-add-and-delete-file): New test.
-rw-r--r--lisp/calendar/todo-mode.el4
-rw-r--r--test/lisp/calendar/todo-mode-tests.el76
2 files changed, 63 insertions, 17 deletions
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el
index 08da75dbd60..7d01fe31fb2 100644
--- a/lisp/calendar/todo-mode.el
+++ b/lisp/calendar/todo-mode.el
@@ -1106,7 +1106,9 @@ Noninteractively, return the name of the new file."
1106 (progn 1106 (progn
1107 (set-window-buffer (selected-window) 1107 (set-window-buffer (selected-window)
1108 (set-buffer (find-file-noselect file))) 1108 (set-buffer (find-file-noselect file)))
1109 (setq todo-current-todo-file file) 1109 ;; Since buffer is not yet in todo-mode, we need to
1110 ;; explicitly make todo-current-todo-file buffer local.
1111 (setq-local todo-current-todo-file file)
1110 (todo-show)) 1112 (todo-show))
1111 file))) 1113 file)))
1112 1114
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el
index 6cd2bfe35b3..015fbaccf4d 100644
--- a/test/lisp/calendar/todo-mode-tests.el
+++ b/test/lisp/calendar/todo-mode-tests.el
@@ -603,7 +603,7 @@ separator, otherwise, return the position at the beginning."
603 (forward-line -1)) 603 (forward-line -1))
604 (if eol (forward-char))) 604 (if eol (forward-char)))
605 605
606(ert-deftest todo-test-done-items-separator01-bol () 606(ert-deftest todo-test-done-items-separator01-bol () ; bug#32343
607 "Test item copying and here insertion at BOL of separator. 607 "Test item copying and here insertion at BOL of separator.
608Both should be user errors." 608Both should be user errors."
609 (with-todo-test 609 (with-todo-test
@@ -616,7 +616,7 @@ Both should be user errors."
616 (should (string= copy-err (cadr (funcall insert-item-test 'copy)))) 616 (should (string= copy-err (cadr (funcall insert-item-test 'copy))))
617 (should (string= here-err (cadr (funcall insert-item-test 'here))))))) 617 (should (string= here-err (cadr (funcall insert-item-test 'here)))))))
618 618
619(ert-deftest todo-test-done-items-separator01-eol () 619(ert-deftest todo-test-done-items-separator01-eol () ; bug#32343
620 "Test item copying and here insertion at EOL of separator. 620 "Test item copying and here insertion at EOL of separator.
621Both should be user errors." 621Both should be user errors."
622 (with-todo-test 622 (with-todo-test
@@ -629,7 +629,7 @@ Both should be user errors."
629 (should (string= copy-err (cadr (funcall insert-item-test 'copy)))) 629 (should (string= copy-err (cadr (funcall insert-item-test 'copy))))
630 (should (string= here-err (cadr (funcall insert-item-test 'here))))))) 630 (should (string= here-err (cadr (funcall insert-item-test 'here)))))))
631 631
632(ert-deftest todo-test-done-items-separator02-bol () 632(ert-deftest todo-test-done-items-separator02-bol () ; bug#32343
633 "Test item editing commands at BOL of done items separator. 633 "Test item editing commands at BOL of done items separator.
634They should all be noops." 634They should all be noops."
635 (with-todo-test 635 (with-todo-test
@@ -642,7 +642,7 @@ They should all be noops."
642 (should-not (called-interactively-p #'todo-delete-item)) 642 (should-not (called-interactively-p #'todo-delete-item))
643 (should-not (called-interactively-p #'todo-edit-item)))) 643 (should-not (called-interactively-p #'todo-edit-item))))
644 644
645(ert-deftest todo-test-done-items-separator02-eol () 645(ert-deftest todo-test-done-items-separator02-eol () ; bug#32343
646 "Test item editing command at EOL of done items separator. 646 "Test item editing command at EOL of done items separator.
647They should all be noops." 647They should all be noops."
648 (with-todo-test 648 (with-todo-test
@@ -655,7 +655,7 @@ They should all be noops."
655 (should-not (called-interactively-p #'todo-delete-item)) 655 (should-not (called-interactively-p #'todo-delete-item))
656 (should-not (called-interactively-p #'todo-edit-item)))) 656 (should-not (called-interactively-p #'todo-edit-item))))
657 657
658(ert-deftest todo-test-done-items-separator03-bol () 658(ert-deftest todo-test-done-items-separator03-bol () ; bug#32343
659 "Test item marking at BOL of done items separator. 659 "Test item marking at BOL of done items separator.
660This should be a noop, adding no marks to the category." 660This should be a noop, adding no marks to the category."
661 (with-todo-test 661 (with-todo-test
@@ -663,7 +663,7 @@ This should be a noop, adding no marks to the category."
663 (call-interactively #'todo-toggle-mark-item) 663 (call-interactively #'todo-toggle-mark-item)
664 (should-not (assoc (todo-current-category) todo-categories-with-marks)))) 664 (should-not (assoc (todo-current-category) todo-categories-with-marks))))
665 665
666(ert-deftest todo-test-done-items-separator03-eol () 666(ert-deftest todo-test-done-items-separator03-eol () ; bug#32343
667 "Test item marking at EOL of done items separator. 667 "Test item marking at EOL of done items separator.
668This should be a noop, adding no marks to the category." 668This should be a noop, adding no marks to the category."
669 (with-todo-test 669 (with-todo-test
@@ -671,7 +671,7 @@ This should be a noop, adding no marks to the category."
671 (call-interactively #'todo-toggle-mark-item) 671 (call-interactively #'todo-toggle-mark-item)
672 (should-not (assoc (todo-current-category) todo-categories-with-marks)))) 672 (should-not (assoc (todo-current-category) todo-categories-with-marks))))
673 673
674(ert-deftest todo-test-done-items-separator04-bol () 674(ert-deftest todo-test-done-items-separator04-bol () ; bug#32343
675 "Test moving to previous item from BOL of done items separator. 675 "Test moving to previous item from BOL of done items separator.
676This should move point to the last not done todo item." 676This should move point to the last not done todo item."
677 (with-todo-test 677 (with-todo-test
@@ -685,7 +685,7 @@ This should move point to the last not done todo item."
685 (todo-previous-item) 685 (todo-previous-item)
686 (todo-item-string))))))) 686 (todo-item-string)))))))
687 687
688(ert-deftest todo-test-done-items-separator04-eol () 688(ert-deftest todo-test-done-items-separator04-eol () ; bug#32343
689 "Test moving to previous item from EOL of done items separator. 689 "Test moving to previous item from EOL of done items separator.
690This should move point to the last not done todo item." 690This should move point to the last not done todo item."
691 (with-todo-test 691 (with-todo-test
@@ -699,7 +699,7 @@ This should move point to the last not done todo item."
699 (todo-previous-item) 699 (todo-previous-item)
700 (todo-item-string))))))) 700 (todo-item-string)))))))
701 701
702(ert-deftest todo-test-done-items-separator05-bol () 702(ert-deftest todo-test-done-items-separator05-bol () ; bug#32343
703 "Test moving to next item from BOL of done items separator. 703 "Test moving to next item from BOL of done items separator.
704This should move point to the first done todo item." 704This should move point to the first done todo item."
705 (with-todo-test 705 (with-todo-test
@@ -713,7 +713,7 @@ This should move point to the first done todo item."
713 (todo-next-item) 713 (todo-next-item)
714 (todo-item-string))))))) 714 (todo-item-string)))))))
715 715
716(ert-deftest todo-test-done-items-separator05-eol () 716(ert-deftest todo-test-done-items-separator05-eol () ; bug#32343
717 "Test moving to next item from EOL of done items separator. 717 "Test moving to next item from EOL of done items separator.
718This should move point to the first done todo item." 718This should move point to the first done todo item."
719 (with-todo-test 719 (with-todo-test
@@ -732,7 +732,7 @@ This should move point to the first done todo item."
732;; hook function is not automatically run, so after enabling item 732;; hook function is not automatically run, so after enabling item
733;; highlighting, use ert-simulate-command around the next command, 733;; highlighting, use ert-simulate-command around the next command,
734;; which explicitly runs the hook function. 734;; which explicitly runs the hook function.
735(ert-deftest todo-test-done-items-separator06-bol () 735(ert-deftest todo-test-done-items-separator06-bol () ; bug#32343
736 "Test enabling item highlighting at BOL of done items separator. 736 "Test enabling item highlighting at BOL of done items separator.
737Subsequently moving to an item should show it highlighted." 737Subsequently moving to an item should show it highlighted."
738 (with-todo-test 738 (with-todo-test
@@ -741,7 +741,7 @@ Subsequently moving to an item should show it highlighted."
741 (ert-simulate-command '(todo-previous-item)) 741 (ert-simulate-command '(todo-previous-item))
742 (should (eq 'hl-line (get-char-property (point) 'face))))) 742 (should (eq 'hl-line (get-char-property (point) 'face)))))
743 743
744(ert-deftest todo-test-done-items-separator06-eol () 744(ert-deftest todo-test-done-items-separator06-eol () ; bug#32343
745 "Test enabling item highlighting at EOL of done items separator. 745 "Test enabling item highlighting at EOL of done items separator.
746Subsequently moving to an item should show it highlighted." 746Subsequently moving to an item should show it highlighted."
747 (with-todo-test 747 (with-todo-test
@@ -751,7 +751,7 @@ Subsequently moving to an item should show it highlighted."
751 (ert-simulate-command '(todo-previous-item)) 751 (ert-simulate-command '(todo-previous-item))
752 (should (eq 'hl-line (get-char-property (point) 'face))))) 752 (should (eq 'hl-line (get-char-property (point) 'face)))))
753 753
754(ert-deftest todo-test-done-items-separator07 () 754(ert-deftest todo-test-done-items-separator07 () ; bug#32343
755 "Test item highlighting when crossing done items separator. 755 "Test item highlighting when crossing done items separator.
756The highlighting should remain enabled." 756The highlighting should remain enabled."
757 (with-todo-test 757 (with-todo-test
@@ -763,11 +763,11 @@ 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-current-file-in-edit-mode () 766(ert-deftest todo-test-current-file-in-edit-mode () ; bug#32437
767 "Test the value of todo-current-todo-file in todo-edit-mode." 767 "Test the value of todo-current-todo-file in todo-edit-mode."
768 (with-todo-test 768 (with-todo-test
769 (todo-test--show 1) 769 (todo-test--show 1)
770 ;; The preceding call todo-mode but does not run pre-command-hook 770 ;; The preceding calls todo-mode but does not run pre-command-hook
771 ;; in the test environment, thus failing to set 771 ;; in the test environment, thus failing to set
772 ;; todo-global-current-todo-file, which is needed for the test 772 ;; todo-global-current-todo-file, which is needed for the test
773 ;; after todo-edit-item--text. So force the hook function to run. 773 ;; after todo-edit-item--text. So force the hook function to run.
@@ -786,7 +786,7 @@ The highlighting should remain enabled."
786 (todo-edit-file) 786 (todo-edit-file)
787 (should (equal todo-current-todo-file curfile))))) 787 (should (equal todo-current-todo-file curfile)))))
788 788
789(ert-deftest todo-test-edit-quit () 789(ert-deftest todo-test-edit-quit () ; bug#32437
790 "Test result of exiting todo-edit-mode on a whole file. 790 "Test result of exiting todo-edit-mode on a whole file.
791Exiting should return to the same todo-mode or todo-archive-mode 791Exiting should return to the same todo-mode or todo-archive-mode
792buffer from which the editing command was invoked." 792buffer from which the editing command was invoked."
@@ -804,6 +804,50 @@ buffer from which the editing command was invoked."
804 (should (eq (current-buffer) buf)) 804 (should (eq (current-buffer) buf))
805 (should (eq major-mode 'todo-archive-mode)))))) 805 (should (eq major-mode 'todo-archive-mode))))))
806 806
807(defun todo-test--add-file (file cat)
808 "Add file FILE with category CAT to todo-files and show it.
809This provides a noninteractive API for todo-add-file for use in
810automatic testing."
811 (let ((file0 (file-truename (concat todo-test-data-dir file ".todo")))
812 todo-add-item-if-new-category) ; Don't need an item in cat.
813 (cl-letf (((symbol-function 'todo-read-file-name)
814 (lambda (_prompt) file0))
815 ((symbol-function 'todo-read-category)
816 (lambda (_prompt &optional _match-type _file) (cons cat file0))))
817 (call-interactively 'todo-add-file) ; Interactive to call todo-show.
818 (todo-add-category file0 cat))))
819
820(defun todo-test--delete-file ()
821 "Delete current todo file without prompting."
822 (cl-letf (((symbol-function 'yes-or-no-p)
823 (lambda (_prompt) t)))
824 (todo-delete-file)))
825
826(ert-deftest todo-test-add-and-delete-file () ; bug#32627
827 "Test adding a new todo file and then deleting it.
828Calling todo-show should display the last current todo file, not
829necessarily the new file. After deleting the new file, todo-show
830should display the previously current (or default) todo file."
831 (with-todo-test
832 (todo-show)
833 (should (equal todo-current-todo-file todo-test-file-1))
834 (let* ((file (concat todo-directory "todo-test-2.todo"))
835 (file-nb (file-name-base file))
836 (cat "cat21"))
837 (todo-test--add-file file-nb cat) ; Add new file and show it.
838 (should (equal todo-current-todo-file file))
839 (todo-quit) ; Quitting todo-mode displays previous buffer.
840 (should (equal todo-current-todo-file todo-test-file-1))
841 (switch-to-buffer "*scratch*")
842 (todo-show) ; Show the last current todo-file (not the new one).
843 (should (equal todo-current-todo-file todo-test-file-1))
844 (switch-to-buffer (get-file-buffer file)) ; Back to new file.
845 (should (equal todo-current-todo-file file))
846 (todo-test--delete-file)
847 (todo-show) ; Back to old file.
848 (should (equal todo-current-todo-file todo-test-file-1))
849 (delete-file (concat file "~")))))
850
807 851
808(provide 'todo-mode-tests) 852(provide 'todo-mode-tests)
809;;; todo-mode-tests.el ends here 853;;; todo-mode-tests.el ends here