Commit b894c439 authored by Karl Fogel's avatar Karl Fogel

* 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.
parent 3a69db53
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> 2010-01-02 Karl Fogel <kfogel@red-bean.com>
* bookmark.el (bookmark-bmenu-select, bookmark-bmenu-1-window, * bookmark.el (bookmark-bmenu-select, bookmark-bmenu-1-window,
......
...@@ -289,13 +289,20 @@ This point is in `bookmark-current-buffer'.") ...@@ -289,13 +289,20 @@ This point is in `bookmark-current-buffer'.")
(defvar bookmark-quit-flag nil (defvar bookmark-quit-flag nil
"Non nil make `bookmark-bmenu-search' quit immediately.") "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 (defmacro with-buffer-modified-unmodified (&rest body)
;; know anything about the format of bookmark-alist entries. "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. ;; Everyone else should go through them.
(defun bookmark-name-from-full-record (full-record) (defun bookmark-name-from-full-record (full-record)
"Return name of FULL-RECORD (an alist element instead of a string)." "Return name of FULL-RECORD (an alist element instead of a string)."
(car full-record)) (car full-record))
...@@ -866,6 +873,8 @@ Lines beginning with `#' are ignored." ...@@ -866,6 +873,8 @@ Lines beginning with `#' are ignored."
(let ((annotation (buffer-substring-no-properties (point-min) (point-max))) (let ((annotation (buffer-substring-no-properties (point-min) (point-max)))
(bookmark bookmark-annotation-name)) (bookmark bookmark-annotation-name))
(bookmark-set-annotation bookmark annotation) (bookmark-set-annotation bookmark annotation)
(setq bookmark-alist-modification-count
(1+ bookmark-alist-modification-count))
(bookmark-bmenu-surreptitiously-rebuild-list)) (bookmark-bmenu-surreptitiously-rebuild-list))
(kill-buffer (current-buffer))) (kill-buffer (current-buffer)))
...@@ -1526,6 +1535,7 @@ deletion, or > if it is flagged for displaying." ...@@ -1526,6 +1535,7 @@ deletion, or > if it is flagged for displaying."
(interactive) (interactive)
(bookmark-maybe-load-default-file) (bookmark-maybe-load-default-file)
(let ((buf (get-buffer-create "*Bookmark List*"))) (let ((buf (get-buffer-create "*Bookmark List*")))
;; fooo
(if (called-interactively-p 'interactive) (if (called-interactively-p 'interactive)
(if (or (window-dedicated-p) (window-minibuffer-p)) (if (or (window-dedicated-p) (window-minibuffer-p))
(pop-to-buffer buf) (pop-to-buffer buf)
...@@ -1557,6 +1567,7 @@ deletion, or > if it is flagged for displaying." ...@@ -1557,6 +1567,7 @@ deletion, or > if it is flagged for displaying."
follow-link t follow-link t
help-echo "mouse-2: go to this bookmark in other window"))) help-echo "mouse-2: go to this bookmark in other window")))
(insert "\n"))) (insert "\n")))
(set-buffer-modified-p (not (= bookmark-alist-modification-count 0)))
(goto-char (point-min)) (goto-char (point-min))
(forward-line 2) (forward-line 2)
(bookmark-bmenu-mode) (bookmark-bmenu-mode)
...@@ -1635,26 +1646,27 @@ Non-nil FORCE forces a redisplay showing the filenames. FORCE is used ...@@ -1635,26 +1646,27 @@ Non-nil FORCE forces a redisplay showing the filenames. FORCE is used
mainly for debugging, and should not be necessary in normal use." mainly for debugging, and should not be necessary in normal use."
(if (and (not force) bookmark-bmenu-toggle-filenames) (if (and (not force) bookmark-bmenu-toggle-filenames)
nil ;already shown, so do nothing nil ;already shown, so do nothing
(save-excursion (with-buffer-modified-unmodified
(save-window-excursion (save-excursion
(goto-char (point-min)) (save-window-excursion
(forward-line 2) (goto-char (point-min))
(setq bookmark-bmenu-hidden-bookmarks ()) (forward-line 2)
(let ((inhibit-read-only t)) (setq bookmark-bmenu-hidden-bookmarks ())
(while (< (point) (point-max)) (let ((inhibit-read-only t))
(let ((bmrk (bookmark-bmenu-bookmark))) (while (< (point) (point-max))
(push bmrk bookmark-bmenu-hidden-bookmarks) (let ((bmrk (bookmark-bmenu-bookmark)))
(let ((start (save-excursion (end-of-line) (point)))) (push bmrk bookmark-bmenu-hidden-bookmarks)
(move-to-column bookmark-bmenu-file-column t) (let ((start (save-excursion (end-of-line) (point))))
;; Strip off `mouse-face' from the white spaces region. (move-to-column bookmark-bmenu-file-column t)
(if (display-mouse-p) ;; Strip off `mouse-face' from the white spaces region.
(remove-text-properties start (point) (if (display-mouse-p)
'(mouse-face nil help-echo nil)))) (remove-text-properties start (point)
(delete-region (point) (progn (end-of-line) (point))) '(mouse-face nil help-echo nil))))
(insert " ") (delete-region (point) (progn (end-of-line) (point)))
;; Pass the NO-HISTORY arg: (insert " ")
(bookmark-insert-location bmrk t) ;; Pass the NO-HISTORY arg:
(forward-line 1)))))))) (bookmark-insert-location bmrk t)
(forward-line 1)))))))))
(defun bookmark-bmenu-hide-filenames (&optional force) (defun bookmark-bmenu-hide-filenames (&optional force)
...@@ -1663,31 +1675,26 @@ Non-nil FORCE forces a redisplay showing the filenames. FORCE is used ...@@ -1663,31 +1675,26 @@ Non-nil FORCE forces a redisplay showing the filenames. FORCE is used
mainly for debugging, and should not be necessary in normal use." mainly for debugging, and should not be necessary in normal use."
(when (and (not force) bookmark-bmenu-toggle-filenames) (when (and (not force) bookmark-bmenu-toggle-filenames)
;; nothing to hide if above is nil ;; nothing to hide if above is nil
(save-excursion (with-buffer-modified-unmodified
(goto-char (point-min)) (save-excursion
(forward-line 2) (goto-char (point-min))
(setq bookmark-bmenu-hidden-bookmarks (forward-line 2)
(nreverse bookmark-bmenu-hidden-bookmarks)) (setq bookmark-bmenu-hidden-bookmarks
(let ((inhibit-read-only t) (nreverse bookmark-bmenu-hidden-bookmarks))
(column (save-excursion (let ((inhibit-read-only t))
(goto-char (point-min)) (while bookmark-bmenu-hidden-bookmarks
(search-forward "Bookmark") (move-to-column (1+ bookmark-bmenu-marks-width) t)
(backward-word 1) (bookmark-kill-line)
(current-column)))) (let ((name (pop bookmark-bmenu-hidden-bookmarks))
(while bookmark-bmenu-hidden-bookmarks (start (point)))
(move-to-column column t) (insert name)
(bookmark-kill-line) (if (display-mouse-p)
(let ((name (pop bookmark-bmenu-hidden-bookmarks)) (add-text-properties
(start (point))) start (point)
(insert name) '(mouse-face
(if (display-mouse-p) highlight follow-link t help-echo
(add-text-properties "mouse-2: go to this bookmark in other window"))))
start (point) (forward-line 1)))))))
'(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 () (defun bookmark-bmenu-ensure-position ()
...@@ -1752,11 +1759,12 @@ if an annotation exists." ...@@ -1752,11 +1759,12 @@ if an annotation exists."
(interactive) (interactive)
(beginning-of-line) (beginning-of-line)
(bookmark-bmenu-ensure-position) (bookmark-bmenu-ensure-position)
(let ((inhibit-read-only t)) (with-buffer-modified-unmodified
(delete-char 1) (let ((inhibit-read-only t))
(insert ?>) (delete-char 1)
(forward-line 1) (insert ?>)
(bookmark-bmenu-ensure-position))) (forward-line 1)
(bookmark-bmenu-ensure-position))))
(defun bookmark-bmenu-select () (defun bookmark-bmenu-select ()
...@@ -1917,14 +1925,15 @@ Optional BACKUP means move up." ...@@ -1917,14 +1925,15 @@ Optional BACKUP means move up."
(interactive "P") (interactive "P")
(beginning-of-line) (beginning-of-line)
(bookmark-bmenu-ensure-position) (bookmark-bmenu-ensure-position)
(let ((inhibit-read-only t)) (with-buffer-modified-unmodified
(delete-char 1) (let ((inhibit-read-only t))
;; any flags to reset according to circumstances? How about a (delete-char 1)
;; flag indicating whether this bookmark is being visited? ;; any flags to reset according to circumstances? How about a
;; well, we don't have this now, so maybe later. ;; flag indicating whether this bookmark is being visited?
(insert " ")) ;; well, we don't have this now, so maybe later.
(forward-line (if backup -1 1)) (insert " "))
(bookmark-bmenu-ensure-position)) (forward-line (if backup -1 1))
(bookmark-bmenu-ensure-position)))
(defun bookmark-bmenu-backup-unmark () (defun bookmark-bmenu-backup-unmark ()
...@@ -1943,11 +1952,12 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\ ...@@ -1943,11 +1952,12 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
(interactive) (interactive)
(beginning-of-line) (beginning-of-line)
(bookmark-bmenu-ensure-position) (bookmark-bmenu-ensure-position)
(let ((inhibit-read-only t)) (with-buffer-modified-unmodified
(delete-char 1) (let ((inhibit-read-only t))
(insert ?D) (delete-char 1)
(forward-line 1) (insert ?D)
(bookmark-bmenu-ensure-position))) (forward-line 1)
(bookmark-bmenu-ensure-position))))
(defun bookmark-bmenu-delete-backwards () (defun bookmark-bmenu-delete-backwards ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment