]> git.eshelyaron.com Git - emacs.git/commitdiff
* calendar/todos.el (todos-move-item): If user quits before
authorStephen Berman <stephen.berman@gmx.net>
Mon, 8 Oct 2012 12:50:40 +0000 (14:50 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Mon, 8 Oct 2012 12:50:40 +0000 (14:50 +0200)
completing movement, restore display of initial category; If item
is moved to end of target category, make sure the items above it
are displayed in the window.

lisp/ChangeLog
lisp/calendar/todos.el

index 377b1883be659a335f4c71651bd58fd45f24dfb7..ae920322f8ab6bdd483e6ca88c3cc6a6be511ca1 100644 (file)
@@ -1,3 +1,10 @@
+2012-10-08  Stephen Berman  <Stephen.Berman@rub.de>
+
+       * calendar/todos.el (todos-move-item): If user quits before
+       completing movement, restore display of initial category; If item
+       is moved to end of target category, make sure the items above it
+       are displayed in the window.
+
 2012-10-08  Stephen Berman  <stephen.berman@gmx.net>
 
        * calendar/todos.el: Fixes to todos-move-item and some of its
index b6dff87348a60f48b3d2aa5879ddda6b14822437..977d74501a9f3b491769e9a1d5207e22c3746eba 100644 (file)
@@ -4762,7 +4762,7 @@ entry/entries in that category."
                      file1))
             (count 0)
             (count-diary 0)
-            ov cat2 nmark)
+            ov cat2 moved nmark)
        (set-buffer (find-file-noselect file2))
        (unwind-protect
            (progn
@@ -4802,46 +4802,62 @@ entry/entries in that category."
          (when (todos-diary-item-p) (setq count-diary 1)))
        (set-window-buffer (selected-window)
                           (set-buffer (find-file-noselect file2)))
-       (todos-set-item-priority item cat2 t)
-       (setq nmark (point-marker))
-       (todos-update-count 'todo count)
-       (todos-update-count 'diary count-diary)
-       (todos-update-categories-sexp)
-       (with-current-buffer (find-buffer-visiting file1)
-         (save-excursion
-           (save-restriction
-             (widen)
-             (goto-char omark)
-             (if marked
-                 (let (beg end)
-                   (setq item nil)
-                   (re-search-backward
-                    (concat "^" (regexp-quote todos-category-beg)) nil t)
-                   (forward-line)
-                   (setq beg (point))
-                   (re-search-forward
-                    (concat "^" (regexp-quote todos-category-done)) nil t)
-                   (setq end (match-beginning 0))
-                   (goto-char beg)
-                   (while (< (point) end)
-                     (if (todos-marked-item-p)
-                         (todos-remove-item)
-                       (todos-forward-item)))
-                   ;; FIXME: does this work?
-                   (remove-overlays (point-min) (point-max)
-                                    'before-string todos-item-mark)
-                   (setq todos-categories-with-marks
-                         (assq-delete-all cat1 todos-categories-with-marks)))
-               (if ov (delete-overlay ov))
-               (todos-remove-item))))
-         (todos-update-count 'todo (- count) cat1)
-         (todos-update-count 'diary (- count-diary) cat1)
-         (todos-update-categories-sexp))
-       (set-window-buffer (selected-window)
-                          (set-buffer (find-file-noselect file2)))
-       (setq todos-category-number (todos-category-number cat2))
-       (todos-category-select)
-       (goto-char nmark)))))
+       (unwind-protect
+           (progn
+             (todos-set-item-priority item cat2 t)
+             (setq moved t))
+         (cond
+          ;; Move succeeded, so remove item from starting category,
+          ;; update item counts and display the category containing
+          ;; the moved item.
+          (moved
+           (setq nmark (point-marker))
+           (todos-update-count 'todo count)
+           (todos-update-count 'diary count-diary)
+           (todos-update-categories-sexp)
+           (with-current-buffer (find-buffer-visiting file1)
+             (save-excursion
+               (save-restriction
+                 (widen)
+                 (goto-char omark)
+                 (if marked
+                     (let (beg end)
+                       (setq item nil)
+                       (re-search-backward
+                        (concat "^" (regexp-quote todos-category-beg)) nil t)
+                       (forward-line)
+                       (setq beg (point))
+                       (re-search-forward
+                        (concat "^" (regexp-quote todos-category-done)) nil t)
+                       (setq end (match-beginning 0))
+                       (goto-char beg)
+                       (while (< (point) end)
+                         (if (todos-marked-item-p)
+                             (todos-remove-item)
+                           (todos-forward-item)))
+                       ;; FIXME: does this work?
+                       (remove-overlays (point-min) (point-max)
+                                        'before-string todos-item-mark)
+                       (setq todos-categories-with-marks
+                             (assq-delete-all cat1 todos-categories-with-marks)))
+                   (if ov (delete-overlay ov))
+                   (todos-remove-item))))
+             (todos-update-count 'todo (- count) cat1)
+             (todos-update-count 'diary (- count-diary) cat1)
+             (todos-update-categories-sexp))
+           (set-window-buffer (selected-window)
+                              (set-buffer (find-file-noselect file2)))
+           (setq todos-category-number (todos-category-number cat2))
+           (todos-category-select)
+           (goto-char nmark)
+           ;; If item is moved to end of category, make sure the
+           ;; items above it are displayed in the window.
+           (recenter))
+          ;; User quit before moving, so return to starting category.
+          (t
+           (todos-category-number cat1)
+           (todos-category-select)
+           (goto-char omark))))))))
 
 (defun todos-move-item-to-file ()
   "Move the current todo item to a category in another Todos file."