changeset 105812:68937a278ce7

Stephen Berman <stephen.berman at gmx.net> (todo-edit-item): Signal an error if there is no item to edit. (Bug#4820) (todo-top-priorities): Restore point and restore narrowing in Todo buffer. (Bug#4820)
author Glenn Morris <rgm@gnu.org>
date Sat, 31 Oct 2009 02:22:30 +0000
parents 18865054beee
children df4934f25eef
files lisp/ChangeLog lisp/calendar/todo-mode.el
diffstat 2 files changed, 44 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Oct 31 02:19:41 2009 +0000
+++ b/lisp/ChangeLog	Sat Oct 31 02:22:30 2009 +0000
@@ -1,3 +1,10 @@
+2009-10-31  Stephen Berman  <stephen.berman@gmx.net>
+
+	* calendar/todo-mode.el (todo-edit-item): Signal an error if there
+	is no item to edit. (Bug#4820)
+	(todo-top-priorities): Restore point and restore narrowing in Todo
+	buffer. (Bug#4820)
+
 2009-10-31  Glenn Morris  <rgm@gnu.org>
 
 	* net/ange-ftp.el (top-level): Don't require dired when compiling.
--- a/lisp/calendar/todo-mode.el	Sat Oct 31 02:19:41 2009 +0000
+++ b/lisp/calendar/todo-mode.el	Sat Oct 31 02:22:30 2009 +0000
@@ -505,14 +505,16 @@
 (defun todo-edit-item ()
   "Edit current TODO list entry."
   (interactive)
-  (let ((item (todo-item-string)))
-    (if (todo-string-multiline-p item)
-        (todo-edit-multiline)
-      (let ((new (read-from-minibuffer "Edit: " item)))
-        (todo-remove-item)
-        (insert new "\n")
-        (todo-backward-item)
-        (message "")))))
+  (if (< (point-min) (point-max))
+      (let ((item (todo-item-string)))
+	(if (todo-string-multiline-p item)
+	    (todo-edit-multiline)
+	  (let ((new (read-from-minibuffer "Edit: " item)))
+	    (todo-remove-item)
+	    (insert new "\n")
+	    (todo-backward-item)
+	    (message ""))))
+    (error "No TODO list entry to edit")))
 (defalias 'todo-cmd-edit 'todo-edit-item)
 
 (defun todo-edit-multiline ()
@@ -745,34 +747,35 @@
                       (regexp-quote todo-prefix) " " todo-category-sep "\n")
             (concat todo-category-end "\n"))))
         beg end)
-    (todo-show)
     (save-excursion
+      (todo-show)
       (save-restriction
-        (widen)
-        (copy-to-buffer todo-print-buffer-name (point-min) (point-max))
-        (set-buffer todo-print-buffer-name)
-        (goto-char (point-min))
-        (when (re-search-forward (regexp-quote todo-header) nil t)
-	  (beginning-of-line 1)
-	  (delete-region (point) (line-end-position)))
-        (while (re-search-forward       ;Find category start
-                (regexp-quote (concat todo-prefix todo-category-beg))
-                nil t)
-          (setq beg (+ (line-end-position) 1)) ;Start of first entry.
-          (re-search-forward cat-end nil t)
-          (setq end (match-beginning 0))
-          (replace-match todo-category-break)
-          (narrow-to-region beg end)    ;In case we have too few entries.
-          (goto-char (point-min))
-          (if (zerop nof-priorities)      ;Traverse entries.
-              (goto-char end)            ;All entries
-            (todo-forward-item nof-priorities))
-          (setq beg (point))
-          (delete-region beg end)
-          (widen))
-        (and (looking-at "") (replace-match "")) ;Remove trailing form-feed.
-        (goto-char (point-min))         ;Due to display buffer
-        ))
+	(save-current-buffer
+	  (widen)
+	  (copy-to-buffer todo-print-buffer-name (point-min) (point-max))
+	  (set-buffer todo-print-buffer-name)
+	  (goto-char (point-min))
+	  (when (re-search-forward (regexp-quote todo-header) nil t)
+	    (beginning-of-line 1)
+	    (delete-region (point) (line-end-position)))
+	  (while (re-search-forward       ;Find category start
+		  (regexp-quote (concat todo-prefix todo-category-beg))
+		  nil t)
+	    (setq beg (+ (line-end-position) 1)) ;Start of first entry.
+	    (re-search-forward cat-end nil t)
+	    (setq end (match-beginning 0))
+	    (replace-match todo-category-break)
+	    (narrow-to-region beg end)    ;In case we have too few entries.
+	    (goto-char (point-min))
+	    (if (zerop nof-priorities)      ;Traverse entries.
+		(goto-char end)            ;All entries
+	      (todo-forward-item nof-priorities))
+	    (setq beg (point))
+	    (delete-region beg end)
+	    (widen))
+	  (and (looking-at "") (replace-match "")) ;Remove trailing form-feed.
+	  (goto-char (point-min))         ;Due to display buffer
+	  )))
     ;; Could have used switch-to-buffer as it has a norecord argument,
     ;; which is nice when we are called from e.g. todo-print.
     ;; Else we could have used pop-to-buffer.