changeset 106710:a96887ed3368

* lisp/bookmark.el: Show modified state of bookmark buffer more accurately. (bookmark-bmenu-list): Initialize buffer-modified-p properly. (bookmark-send-edited-annotation): Mark bookmark-alist as modified. (with-buffer-modified-unmodified): New macro. (bookmark-bmenu-show-filenames, bookmark-bmenu-hide-filenames, bookmark-bmenu-mark, bookmark-bmenu-unmark, bookmark-bmenu-delete): Use new macro to preserve the buffer-modified state.
author Karl Fogel <kfogel@red-bean.com>
date Sat, 02 Jan 2010 13:52:32 -0500
parents f497db0aba00
children b87d77f96245
files lisp/ChangeLog lisp/bookmark.el
diffstat 2 files changed, 87 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Jan 02 13:13:28 2010 -0500
+++ b/lisp/ChangeLog	Sat Jan 02 13:52:32 2010 -0500
@@ -1,3 +1,13 @@
+2010-01-02  Karl Fogel  <kfogel@red-bean.com>
+
+	* bookmark.el: Show modified state of bookmark buffer more accurately.
+	(bookmark-bmenu-list): Initialize buffer-modified-p properly.
+	(bookmark-send-edited-annotation): Mark bookmark-alist as modified.
+	(with-buffer-modified-unmodified): New macro.
+	(bookmark-bmenu-show-filenames, bookmark-bmenu-hide-filenames)
+	(bookmark-bmenu-mark, bookmark-bmenu-unmark, bookmark-bmenu-delete):
+	Use new macro to preserve the buffer-modified state.
+
 2010-01-02  Karl Fogel  <kfogel@red-bean.com>
 
 	* bookmark.el (bookmark-bmenu-select, bookmark-bmenu-1-window,
--- a/lisp/bookmark.el	Sat Jan 02 13:13:28 2010 -0500
+++ b/lisp/bookmark.el	Sat Jan 02 13:52:32 2010 -0500
@@ -289,13 +289,20 @@
 (defvar bookmark-quit-flag nil
   "Non nil make `bookmark-bmenu-search' quit immediately.")
 
-;; Helper functions.
+;; Helper functions and macros.
 
-;; Only functions on this page and the next one (file formats) need to
-;; know anything about the format of bookmark-alist entries.
+(defmacro with-buffer-modified-unmodified (&rest body)
+  "Run BODY while preserving the buffer's `buffer-modified-p' state."
+  (let ((was-modified (make-symbol "was-modified")))
+    `(let ((,was-modified (buffer-modified-p)))
+       (unwind-protect
+           (progn ,@body)
+         (set-buffer-modified-p ,was-modified)))))
+
+;; Only functions below, in this page and the next one (file formats),
+;; need to know anything about the format of bookmark-alist entries.
 ;; Everyone else should go through them.
 
-
 (defun bookmark-name-from-full-record (full-record)
   "Return name of FULL-RECORD (an alist element instead of a string)."
   (car full-record))
@@ -866,6 +873,8 @@
   (let ((annotation (buffer-substring-no-properties (point-min) (point-max)))
 	(bookmark bookmark-annotation-name))
     (bookmark-set-annotation bookmark annotation)
+    (setq bookmark-alist-modification-count
+          (1+ bookmark-alist-modification-count))
     (bookmark-bmenu-surreptitiously-rebuild-list))
   (kill-buffer (current-buffer)))
 
@@ -1526,6 +1535,7 @@
   (interactive)
   (bookmark-maybe-load-default-file)
   (let ((buf (get-buffer-create "*Bookmark List*")))
+    ;; fooo
     (if (called-interactively-p 'interactive)
         (if (or (window-dedicated-p) (window-minibuffer-p))
             (pop-to-buffer buf)
@@ -1557,6 +1567,7 @@
              follow-link t
              help-echo "mouse-2: go to this bookmark in other window")))
         (insert "\n")))
+    (set-buffer-modified-p (not (= bookmark-alist-modification-count 0)))
     (goto-char (point-min))
     (forward-line 2)
     (bookmark-bmenu-mode)
@@ -1635,26 +1646,27 @@
 mainly for debugging, and should not be necessary in normal use."
   (if (and (not force) bookmark-bmenu-toggle-filenames)
       nil ;already shown, so do nothing
-    (save-excursion
-      (save-window-excursion
-        (goto-char (point-min))
-        (forward-line 2)
-        (setq bookmark-bmenu-hidden-bookmarks ())
-        (let ((inhibit-read-only t))
-          (while (< (point) (point-max))
-            (let ((bmrk (bookmark-bmenu-bookmark)))
-              (push bmrk bookmark-bmenu-hidden-bookmarks)
-	      (let ((start (save-excursion (end-of-line) (point))))
-		(move-to-column bookmark-bmenu-file-column t)
-		;; Strip off `mouse-face' from the white spaces region.
-		(if (display-mouse-p)
-		    (remove-text-properties start (point)
-					    '(mouse-face nil help-echo nil))))
-	      (delete-region (point) (progn (end-of-line) (point)))
-              (insert "  ")
-              ;; Pass the NO-HISTORY arg:
-              (bookmark-insert-location bmrk t)
-              (forward-line 1))))))))
+    (with-buffer-modified-unmodified
+     (save-excursion
+       (save-window-excursion
+         (goto-char (point-min))
+         (forward-line 2)
+         (setq bookmark-bmenu-hidden-bookmarks ())
+         (let ((inhibit-read-only t))
+           (while (< (point) (point-max))
+             (let ((bmrk (bookmark-bmenu-bookmark)))
+               (push bmrk bookmark-bmenu-hidden-bookmarks)
+               (let ((start (save-excursion (end-of-line) (point))))
+                 (move-to-column bookmark-bmenu-file-column t)
+                 ;; Strip off `mouse-face' from the white spaces region.
+                 (if (display-mouse-p)
+                     (remove-text-properties start (point)
+                                             '(mouse-face nil help-echo nil))))
+               (delete-region (point) (progn (end-of-line) (point)))
+               (insert "  ")
+               ;; Pass the NO-HISTORY arg:
+               (bookmark-insert-location bmrk t)
+               (forward-line 1)))))))))
 
 
 (defun bookmark-bmenu-hide-filenames (&optional force)
@@ -1663,31 +1675,26 @@
 mainly for debugging, and should not be necessary in normal use."
   (when (and (not force) bookmark-bmenu-toggle-filenames)
     ;; nothing to hide if above is nil
-    (save-excursion
-      (goto-char (point-min))
-      (forward-line 2)
-      (setq bookmark-bmenu-hidden-bookmarks
-            (nreverse bookmark-bmenu-hidden-bookmarks))
-      (let ((inhibit-read-only t)
-            (column (save-excursion
-                      (goto-char (point-min))
-                      (search-forward "Bookmark")
-                      (backward-word 1)
-                      (current-column))))
-        (while bookmark-bmenu-hidden-bookmarks
-          (move-to-column column t)
-          (bookmark-kill-line)
-          (let ((name  (pop bookmark-bmenu-hidden-bookmarks))
-                (start (point)))
-            (insert name)
-            (if (display-mouse-p)
-                (add-text-properties
-                 start (point)
-                 '(mouse-face highlight
-                   follow-link t
-                   help-echo
-                   "mouse-2: go to this bookmark in other window"))))
-          (forward-line 1))))))
+    (with-buffer-modified-unmodified
+     (save-excursion
+       (goto-char (point-min))
+       (forward-line 2)
+       (setq bookmark-bmenu-hidden-bookmarks
+             (nreverse bookmark-bmenu-hidden-bookmarks))
+       (let ((inhibit-read-only t))
+         (while bookmark-bmenu-hidden-bookmarks
+           (move-to-column (1+ bookmark-bmenu-marks-width) t)
+           (bookmark-kill-line)
+           (let ((name  (pop bookmark-bmenu-hidden-bookmarks))
+                 (start (point)))
+             (insert name)
+             (if (display-mouse-p)
+                 (add-text-properties
+                  start (point)
+                  '(mouse-face
+                    highlight follow-link t help-echo
+                    "mouse-2: go to this bookmark in other window"))))
+           (forward-line 1)))))))
 
 
 (defun bookmark-bmenu-ensure-position ()
@@ -1752,11 +1759,12 @@
   (interactive)
   (beginning-of-line)
   (bookmark-bmenu-ensure-position)
-  (let ((inhibit-read-only t))
-    (delete-char 1)
-    (insert ?>)
-    (forward-line 1)
-    (bookmark-bmenu-ensure-position)))
+  (with-buffer-modified-unmodified
+   (let ((inhibit-read-only t))
+     (delete-char 1)
+     (insert ?>)
+     (forward-line 1)
+     (bookmark-bmenu-ensure-position))))
 
 
 (defun bookmark-bmenu-select ()
@@ -1917,14 +1925,15 @@
   (interactive "P")
   (beginning-of-line)
   (bookmark-bmenu-ensure-position)
-  (let ((inhibit-read-only t))
-    (delete-char 1)
-    ;; any flags to reset according to circumstances?  How about a
-    ;; flag indicating whether this bookmark is being visited?
-    ;; well, we don't have this now, so maybe later.
-    (insert " "))
-  (forward-line (if backup -1 1))
-  (bookmark-bmenu-ensure-position))
+  (with-buffer-modified-unmodified
+   (let ((inhibit-read-only t))
+     (delete-char 1)
+     ;; any flags to reset according to circumstances?  How about a
+     ;; flag indicating whether this bookmark is being visited?
+     ;; well, we don't have this now, so maybe later.
+     (insert " "))
+   (forward-line (if backup -1 1))
+   (bookmark-bmenu-ensure-position)))
 
 
 (defun bookmark-bmenu-backup-unmark ()
@@ -1943,11 +1952,12 @@
   (interactive)
   (beginning-of-line)
   (bookmark-bmenu-ensure-position)
-  (let ((inhibit-read-only t))
-    (delete-char 1)
-    (insert ?D)
-    (forward-line 1)
-    (bookmark-bmenu-ensure-position)))
+  (with-buffer-modified-unmodified
+   (let ((inhibit-read-only t))
+     (delete-char 1)
+     (insert ?D)
+     (forward-line 1)
+     (bookmark-bmenu-ensure-position))))
 
 
 (defun bookmark-bmenu-delete-backwards ()