diff options
| author | Karl Fogel | 2010-01-02 13:52:32 -0500 |
|---|---|---|
| committer | Karl Fogel | 2010-01-02 13:52:32 -0500 |
| commit | b894c439536a226d8524941bcc3d0117e26da11b (patch) | |
| tree | b63d4fdfdae3c778e106685c8943bc17b0b0dad5 | |
| parent | 3a69db535c8346f3444b942de45fbed3d5be6b62 (diff) | |
| download | emacs-b894c439536a226d8524941bcc3d0117e26da11b.tar.gz emacs-b894c439536a226d8524941bcc3d0117e26da11b.zip | |
* 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.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/bookmark.el | 146 |
2 files changed, 88 insertions, 68 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a180291abfc..b4282bdf22d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,15 @@ | |||
| 1 | 2010-01-02 Karl Fogel <kfogel@red-bean.com> | 1 | 2010-01-02 Karl Fogel <kfogel@red-bean.com> |
| 2 | 2 | ||
| 3 | * bookmark.el: Show modified state of bookmark buffer more accurately. | ||
| 4 | (bookmark-bmenu-list): Initialize buffer-modified-p properly. | ||
| 5 | (bookmark-send-edited-annotation): Mark bookmark-alist as modified. | ||
| 6 | (with-buffer-modified-unmodified): New macro. | ||
| 7 | (bookmark-bmenu-show-filenames, bookmark-bmenu-hide-filenames) | ||
| 8 | (bookmark-bmenu-mark, bookmark-bmenu-unmark, bookmark-bmenu-delete): | ||
| 9 | Use new macro to preserve the buffer-modified state. | ||
| 10 | |||
| 11 | 2010-01-02 Karl Fogel <kfogel@red-bean.com> | ||
| 12 | |||
| 3 | * bookmark.el (bookmark-bmenu-select, bookmark-bmenu-1-window, | 13 | * bookmark.el (bookmark-bmenu-select, bookmark-bmenu-1-window, |
| 4 | (bookmark-bmenu-2-window, bookmark-bmenu-this-window) | 14 | (bookmark-bmenu-2-window, bookmark-bmenu-this-window) |
| 5 | (bookmark-bmenu-other-window, bookmark-bmenu-switch-other-window) | 15 | (bookmark-bmenu-other-window, bookmark-bmenu-switch-other-window) |
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 98e700ae97f..5326c292685 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -289,13 +289,20 @@ This point is in `bookmark-current-buffer'.") | |||
| 289 | (defvar bookmark-quit-flag nil | 289 | (defvar bookmark-quit-flag nil |
| 290 | "Non nil make `bookmark-bmenu-search' quit immediately.") | 290 | "Non nil make `bookmark-bmenu-search' quit immediately.") |
| 291 | 291 | ||
| 292 | ;; Helper functions. | 292 | ;; Helper functions and macros. |
| 293 | 293 | ||
| 294 | ;; Only functions on this page and the next one (file formats) need to | 294 | (defmacro with-buffer-modified-unmodified (&rest body) |
| 295 | ;; know anything about the format of bookmark-alist entries. | 295 | "Run BODY while preserving the buffer's `buffer-modified-p' state." |
| 296 | (let ((was-modified (make-symbol "was-modified"))) | ||
| 297 | `(let ((,was-modified (buffer-modified-p))) | ||
| 298 | (unwind-protect | ||
| 299 | (progn ,@body) | ||
| 300 | (set-buffer-modified-p ,was-modified))))) | ||
| 301 | |||
| 302 | ;; Only functions below, in this page and the next one (file formats), | ||
| 303 | ;; need to know anything about the format of bookmark-alist entries. | ||
| 296 | ;; Everyone else should go through them. | 304 | ;; Everyone else should go through them. |
| 297 | 305 | ||
| 298 | |||
| 299 | (defun bookmark-name-from-full-record (full-record) | 306 | (defun bookmark-name-from-full-record (full-record) |
| 300 | "Return name of FULL-RECORD (an alist element instead of a string)." | 307 | "Return name of FULL-RECORD (an alist element instead of a string)." |
| 301 | (car full-record)) | 308 | (car full-record)) |
| @@ -866,6 +873,8 @@ Lines beginning with `#' are ignored." | |||
| 866 | (let ((annotation (buffer-substring-no-properties (point-min) (point-max))) | 873 | (let ((annotation (buffer-substring-no-properties (point-min) (point-max))) |
| 867 | (bookmark bookmark-annotation-name)) | 874 | (bookmark bookmark-annotation-name)) |
| 868 | (bookmark-set-annotation bookmark annotation) | 875 | (bookmark-set-annotation bookmark annotation) |
| 876 | (setq bookmark-alist-modification-count | ||
| 877 | (1+ bookmark-alist-modification-count)) | ||
| 869 | (bookmark-bmenu-surreptitiously-rebuild-list)) | 878 | (bookmark-bmenu-surreptitiously-rebuild-list)) |
| 870 | (kill-buffer (current-buffer))) | 879 | (kill-buffer (current-buffer))) |
| 871 | 880 | ||
| @@ -1526,6 +1535,7 @@ deletion, or > if it is flagged for displaying." | |||
| 1526 | (interactive) | 1535 | (interactive) |
| 1527 | (bookmark-maybe-load-default-file) | 1536 | (bookmark-maybe-load-default-file) |
| 1528 | (let ((buf (get-buffer-create "*Bookmark List*"))) | 1537 | (let ((buf (get-buffer-create "*Bookmark List*"))) |
| 1538 | ;; fooo | ||
| 1529 | (if (called-interactively-p 'interactive) | 1539 | (if (called-interactively-p 'interactive) |
| 1530 | (if (or (window-dedicated-p) (window-minibuffer-p)) | 1540 | (if (or (window-dedicated-p) (window-minibuffer-p)) |
| 1531 | (pop-to-buffer buf) | 1541 | (pop-to-buffer buf) |
| @@ -1557,6 +1567,7 @@ deletion, or > if it is flagged for displaying." | |||
| 1557 | follow-link t | 1567 | follow-link t |
| 1558 | help-echo "mouse-2: go to this bookmark in other window"))) | 1568 | help-echo "mouse-2: go to this bookmark in other window"))) |
| 1559 | (insert "\n"))) | 1569 | (insert "\n"))) |
| 1570 | (set-buffer-modified-p (not (= bookmark-alist-modification-count 0))) | ||
| 1560 | (goto-char (point-min)) | 1571 | (goto-char (point-min)) |
| 1561 | (forward-line 2) | 1572 | (forward-line 2) |
| 1562 | (bookmark-bmenu-mode) | 1573 | (bookmark-bmenu-mode) |
| @@ -1635,26 +1646,27 @@ Non-nil FORCE forces a redisplay showing the filenames. FORCE is used | |||
| 1635 | mainly for debugging, and should not be necessary in normal use." | 1646 | mainly for debugging, and should not be necessary in normal use." |
| 1636 | (if (and (not force) bookmark-bmenu-toggle-filenames) | 1647 | (if (and (not force) bookmark-bmenu-toggle-filenames) |
| 1637 | nil ;already shown, so do nothing | 1648 | nil ;already shown, so do nothing |
| 1638 | (save-excursion | 1649 | (with-buffer-modified-unmodified |
| 1639 | (save-window-excursion | 1650 | (save-excursion |
| 1640 | (goto-char (point-min)) | 1651 | (save-window-excursion |
| 1641 | (forward-line 2) | 1652 | (goto-char (point-min)) |
| 1642 | (setq bookmark-bmenu-hidden-bookmarks ()) | 1653 | (forward-line 2) |
| 1643 | (let ((inhibit-read-only t)) | 1654 | (setq bookmark-bmenu-hidden-bookmarks ()) |
| 1644 | (while (< (point) (point-max)) | 1655 | (let ((inhibit-read-only t)) |
| 1645 | (let ((bmrk (bookmark-bmenu-bookmark))) | 1656 | (while (< (point) (point-max)) |
| 1646 | (push bmrk bookmark-bmenu-hidden-bookmarks) | 1657 | (let ((bmrk (bookmark-bmenu-bookmark))) |
| 1647 | (let ((start (save-excursion (end-of-line) (point)))) | 1658 | (push bmrk bookmark-bmenu-hidden-bookmarks) |
| 1648 | (move-to-column bookmark-bmenu-file-column t) | 1659 | (let ((start (save-excursion (end-of-line) (point)))) |
| 1649 | ;; Strip off `mouse-face' from the white spaces region. | 1660 | (move-to-column bookmark-bmenu-file-column t) |
| 1650 | (if (display-mouse-p) | 1661 | ;; Strip off `mouse-face' from the white spaces region. |
| 1651 | (remove-text-properties start (point) | 1662 | (if (display-mouse-p) |
| 1652 | '(mouse-face nil help-echo nil)))) | 1663 | (remove-text-properties start (point) |
| 1653 | (delete-region (point) (progn (end-of-line) (point))) | 1664 | '(mouse-face nil help-echo nil)))) |
| 1654 | (insert " ") | 1665 | (delete-region (point) (progn (end-of-line) (point))) |
| 1655 | ;; Pass the NO-HISTORY arg: | 1666 | (insert " ") |
| 1656 | (bookmark-insert-location bmrk t) | 1667 | ;; Pass the NO-HISTORY arg: |
| 1657 | (forward-line 1)))))))) | 1668 | (bookmark-insert-location bmrk t) |
| 1669 | (forward-line 1))))))))) | ||
| 1658 | 1670 | ||
| 1659 | 1671 | ||
| 1660 | (defun bookmark-bmenu-hide-filenames (&optional force) | 1672 | (defun bookmark-bmenu-hide-filenames (&optional force) |
| @@ -1663,31 +1675,26 @@ Non-nil FORCE forces a redisplay showing the filenames. FORCE is used | |||
| 1663 | mainly for debugging, and should not be necessary in normal use." | 1675 | mainly for debugging, and should not be necessary in normal use." |
| 1664 | (when (and (not force) bookmark-bmenu-toggle-filenames) | 1676 | (when (and (not force) bookmark-bmenu-toggle-filenames) |
| 1665 | ;; nothing to hide if above is nil | 1677 | ;; nothing to hide if above is nil |
| 1666 | (save-excursion | 1678 | (with-buffer-modified-unmodified |
| 1667 | (goto-char (point-min)) | 1679 | (save-excursion |
| 1668 | (forward-line 2) | 1680 | (goto-char (point-min)) |
| 1669 | (setq bookmark-bmenu-hidden-bookmarks | 1681 | (forward-line 2) |
| 1670 | (nreverse bookmark-bmenu-hidden-bookmarks)) | 1682 | (setq bookmark-bmenu-hidden-bookmarks |
| 1671 | (let ((inhibit-read-only t) | 1683 | (nreverse bookmark-bmenu-hidden-bookmarks)) |
| 1672 | (column (save-excursion | 1684 | (let ((inhibit-read-only t)) |
| 1673 | (goto-char (point-min)) | 1685 | (while bookmark-bmenu-hidden-bookmarks |
| 1674 | (search-forward "Bookmark") | 1686 | (move-to-column (1+ bookmark-bmenu-marks-width) t) |
| 1675 | (backward-word 1) | 1687 | (bookmark-kill-line) |
| 1676 | (current-column)))) | 1688 | (let ((name (pop bookmark-bmenu-hidden-bookmarks)) |
| 1677 | (while bookmark-bmenu-hidden-bookmarks | 1689 | (start (point))) |
| 1678 | (move-to-column column t) | 1690 | (insert name) |
| 1679 | (bookmark-kill-line) | 1691 | (if (display-mouse-p) |
| 1680 | (let ((name (pop bookmark-bmenu-hidden-bookmarks)) | 1692 | (add-text-properties |
| 1681 | (start (point))) | 1693 | start (point) |
| 1682 | (insert name) | 1694 | '(mouse-face |
| 1683 | (if (display-mouse-p) | 1695 | highlight follow-link t help-echo |
| 1684 | (add-text-properties | 1696 | "mouse-2: go to this bookmark in other window")))) |
| 1685 | start (point) | 1697 | (forward-line 1))))))) |
| 1686 | '(mouse-face highlight | ||
| 1687 | follow-link t | ||
| 1688 | help-echo | ||
| 1689 | "mouse-2: go to this bookmark in other window")))) | ||
| 1690 | (forward-line 1)))))) | ||
| 1691 | 1698 | ||
| 1692 | 1699 | ||
| 1693 | (defun bookmark-bmenu-ensure-position () | 1700 | (defun bookmark-bmenu-ensure-position () |
| @@ -1752,11 +1759,12 @@ if an annotation exists." | |||
| 1752 | (interactive) | 1759 | (interactive) |
| 1753 | (beginning-of-line) | 1760 | (beginning-of-line) |
| 1754 | (bookmark-bmenu-ensure-position) | 1761 | (bookmark-bmenu-ensure-position) |
| 1755 | (let ((inhibit-read-only t)) | 1762 | (with-buffer-modified-unmodified |
| 1756 | (delete-char 1) | 1763 | (let ((inhibit-read-only t)) |
| 1757 | (insert ?>) | 1764 | (delete-char 1) |
| 1758 | (forward-line 1) | 1765 | (insert ?>) |
| 1759 | (bookmark-bmenu-ensure-position))) | 1766 | (forward-line 1) |
| 1767 | (bookmark-bmenu-ensure-position)))) | ||
| 1760 | 1768 | ||
| 1761 | 1769 | ||
| 1762 | (defun bookmark-bmenu-select () | 1770 | (defun bookmark-bmenu-select () |
| @@ -1917,14 +1925,15 @@ Optional BACKUP means move up." | |||
| 1917 | (interactive "P") | 1925 | (interactive "P") |
| 1918 | (beginning-of-line) | 1926 | (beginning-of-line) |
| 1919 | (bookmark-bmenu-ensure-position) | 1927 | (bookmark-bmenu-ensure-position) |
| 1920 | (let ((inhibit-read-only t)) | 1928 | (with-buffer-modified-unmodified |
| 1921 | (delete-char 1) | 1929 | (let ((inhibit-read-only t)) |
| 1922 | ;; any flags to reset according to circumstances? How about a | 1930 | (delete-char 1) |
| 1923 | ;; flag indicating whether this bookmark is being visited? | 1931 | ;; any flags to reset according to circumstances? How about a |
| 1924 | ;; well, we don't have this now, so maybe later. | 1932 | ;; flag indicating whether this bookmark is being visited? |
| 1925 | (insert " ")) | 1933 | ;; well, we don't have this now, so maybe later. |
| 1926 | (forward-line (if backup -1 1)) | 1934 | (insert " ")) |
| 1927 | (bookmark-bmenu-ensure-position)) | 1935 | (forward-line (if backup -1 1)) |
| 1936 | (bookmark-bmenu-ensure-position))) | ||
| 1928 | 1937 | ||
| 1929 | 1938 | ||
| 1930 | (defun bookmark-bmenu-backup-unmark () | 1939 | (defun bookmark-bmenu-backup-unmark () |
| @@ -1943,11 +1952,12 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\ | |||
| 1943 | (interactive) | 1952 | (interactive) |
| 1944 | (beginning-of-line) | 1953 | (beginning-of-line) |
| 1945 | (bookmark-bmenu-ensure-position) | 1954 | (bookmark-bmenu-ensure-position) |
| 1946 | (let ((inhibit-read-only t)) | 1955 | (with-buffer-modified-unmodified |
| 1947 | (delete-char 1) | 1956 | (let ((inhibit-read-only t)) |
| 1948 | (insert ?D) | 1957 | (delete-char 1) |
| 1949 | (forward-line 1) | 1958 | (insert ?D) |
| 1950 | (bookmark-bmenu-ensure-position))) | 1959 | (forward-line 1) |
| 1960 | (bookmark-bmenu-ensure-position)))) | ||
| 1951 | 1961 | ||
| 1952 | 1962 | ||
| 1953 | (defun bookmark-bmenu-delete-backwards () | 1963 | (defun bookmark-bmenu-delete-backwards () |