From: Stephen Berman Date: Sun, 17 Mar 2013 23:09:13 +0000 (+0100) Subject: * calendar/todos.el (todos-insert-item): Fix mistake in logic of X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2065 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=40012197ec0773a9d42abf0c4c1052636f7c94ea;p=emacs.git * calendar/todos.el (todos-insert-item): Fix mistake in logic of here insertion from last change, and ensure category is set when command is called from outside Todos buffer. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bf1658d6f7c..bb42d10aad2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-03-17 Stephen Berman + + * calendar/todos.el (todos-insert-item): Fix mistake in logic of + here insertion from last change, and ensure category is set when + command is called from outside Todos buffer. + 2013-03-15 Stephen Berman * calendar/todos.el: Item unarchiving fixes and improvements. diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 0527579a051..350a957c6e4 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -4629,14 +4629,19 @@ the priority is not given by HERE but by prompting." (setq todos-date-from-calendar nil) (find-file-noselect file 'nowarn) (set-window-buffer (selected-window) - ;; If current category was nil till now, on - ;; entering Todos mode here it will be set to - ;; file's first category. (set-buffer (find-buffer-visiting file))) + ;; If this command was invoked outside of a Todos buffer, the + ;; call to todos-current-category above returned nil. If we + ;; just entered Todos mode now, then cat was set to the file's + ;; first category, but if todos-mode was already enabled, cat + ;; did not get set, so we have to set it explicitly. + (unless cat + (setq cat (todos-current-category))) (setq todos-current-todos-file file) (unless todos-global-current-todos-file (setq todos-global-current-todos-file todos-current-todos-file)) (let ((buffer-read-only nil) + (called-from-outside (not (and todos-mm (equal cat ocat)))) done-only item-added) (setq new-item ;; Add date, time and diary marking as required. @@ -4657,6 +4662,16 @@ the priority is not given by HERE but by prompting." new-item nil nil 1)) (unwind-protect (progn + ;; Make sure the correct category is selected. There + ;; are two cases: (i) we just visited the file, so no + ;; category is selected yet, or (ii) we invoked + ;; insertion "here" from outside the category we want + ;; to insert in (with priority insertion, category + ;; selection is done by todos-set-item-priority). + (when (or (= (- (point-max) (point-min)) (buffer-size)) + (and here called-from-outside)) + (todos-category-number cat) + (todos-category-select)) ;; If only done items are displayed in category, ;; toggle to todo items before inserting new item. (when (save-excursion @@ -4671,9 +4686,7 @@ the priority is not given by HERE but by prompting." ;; category, can't insert "here", so to be ;; useful give new item top priority. (when (or (todos-done-item-section-p) - (prog1 (not (and todos-mm (equal cat ocat))) - (todos-category-number cat) - (todos-category-select)) + called-from-outside done-only) (goto-char (point-min))) (todos-insert-with-overlays new-item))