diff options
| author | Roland Winkler | 2019-06-18 00:59:11 -0500 |
|---|---|---|
| committer | Roland Winkler | 2019-06-18 00:59:11 -0500 |
| commit | 0f4d368f3500fe8e3ac8f9a0d5ab1ca95f1ef2d0 (patch) | |
| tree | 4b849209d622531ff0f49140b0a8c787ba3609ab | |
| parent | 64767008f70af88d193d36eb6d2c27e4bc95ea8e (diff) | |
| download | emacs-0f4d368f3500fe8e3ac8f9a0d5ab1ca95f1ef2d0.tar.gz emacs-0f4d368f3500fe8e3ac8f9a0d5ab1ca95f1ef2d0.zip | |
* bookmark.el: Watch bookmark file. Use lexical binding.
(bookmark-watch-bookmark-file): New user variable.
(bookmark-alist): Fix docstring.
(bookmark-bookmarks-timestamp): Renamed from bookmarks-already-loaded.
(bookmark-maybe-load-default-file, bookmark-save, bookmark-load):
Use bookmark-bookmarks-timestamp.
(bookmark-bmenu-mode-map): Define menu bar menu.
(bookmark-show-annotation, bookmark-show-all-annotations):
Make bookmarks buffer read-only.
(bookmark-bmenu-save): Use call-interactively.
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/bookmark.el | 323 |
2 files changed, 201 insertions, 125 deletions
| @@ -1526,6 +1526,9 @@ buffer periodically when 'auto-revert-avoid-polling' is non-nil. | |||
| 1526 | *** 'bookmark-file' and 'bookmark-old-default-file' are now obsolete | 1526 | *** 'bookmark-file' and 'bookmark-old-default-file' are now obsolete |
| 1527 | aliases of 'bookmark-default-file'. | 1527 | aliases of 'bookmark-default-file'. |
| 1528 | 1528 | ||
| 1529 | *** New user option 'bookmark-watch-bookmark-file'. | ||
| 1530 | When non-nil, watch whether the bookmark file has changed on disk. | ||
| 1531 | |||
| 1529 | 1532 | ||
| 1530 | * New Modes and Packages in Emacs 27.1 | 1533 | * New Modes and Packages in Emacs 27.1 |
| 1531 | 1534 | ||
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 49abc9e6550..a800525b49d 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later | 1 | ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1993-1997, 2001-2019 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1993-1997, 2001-2019 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -86,9 +86,21 @@ To specify the file in which to save them, modify the variable | |||
| 86 | (defcustom bookmark-default-file | 86 | (defcustom bookmark-default-file |
| 87 | (locate-user-emacs-file "bookmarks" ".emacs.bmk") | 87 | (locate-user-emacs-file "bookmarks" ".emacs.bmk") |
| 88 | "File in which to save bookmarks by default." | 88 | "File in which to save bookmarks by default." |
| 89 | ;; The current default file is defined via the internal variable | ||
| 90 | ;; `bookmark-bookmarks-timestamp'. This does not affect the value | ||
| 91 | ;; of `bookmark-default-file'. | ||
| 89 | :type 'file | 92 | :type 'file |
| 90 | :group 'bookmark) | 93 | :group 'bookmark) |
| 91 | 94 | ||
| 95 | (defcustom bookmark-watch-bookmark-file t | ||
| 96 | "If non-nil watch the default bookmark file. | ||
| 97 | If this file has changed on disk since it was last loaded, query the user | ||
| 98 | whether to load it again. If the value is `silent' reload without querying. | ||
| 99 | This file defaults to `bookmark-default-file'. But during an Emacs session, | ||
| 100 | `bookmark-load' and `bookmark-save' can redefine the current default file." | ||
| 101 | :version "27.1" | ||
| 102 | :type 'boolean | ||
| 103 | :group 'bookmark) | ||
| 92 | 104 | ||
| 93 | (defcustom bookmark-version-control 'nospecial | 105 | (defcustom bookmark-version-control 'nospecial |
| 94 | "Whether or not to make numbered backups of the bookmark file. | 106 | "Whether or not to make numbered backups of the bookmark file. |
| @@ -222,39 +234,50 @@ functions have a binding in this keymap.") | |||
| 222 | Bookmark functions update the value automatically. | 234 | Bookmark functions update the value automatically. |
| 223 | You probably do NOT want to change the value yourself. | 235 | You probably do NOT want to change the value yourself. |
| 224 | 236 | ||
| 225 | The value is an alist with entries of the form | 237 | The value is an alist with bookmarks of the form |
| 226 | 238 | ||
| 227 | (BOOKMARK-NAME . PARAM-ALIST) | 239 | (BOOKMARK-NAME . PARAM-ALIST) |
| 228 | 240 | ||
| 229 | or the deprecated form (BOOKMARK-NAME PARAM-ALIST). | 241 | or the deprecated form (BOOKMARK-NAME PARAM-ALIST). |
| 230 | 242 | ||
| 231 | BOOKMARK-NAME is the name you gave to the bookmark when creating it. | 243 | BOOKMARK-NAME is the name you gave to the bookmark when creating it. |
| 232 | 244 | ||
| 233 | PARAM-ALIST is an alist of bookmark information. The order of the | 245 | PARAM-ALIST is an alist of bookmark information. The order of the |
| 234 | entries in PARAM-ALIST is not important. The possible entries are | 246 | entries in PARAM-ALIST is not important. The default entries are |
| 235 | described below. An entry with a key but null value means the entry | 247 | described below. An entry with a key but null value means the entry |
| 236 | is not used. | 248 | is not used. |
| 237 | 249 | ||
| 238 | (filename . FILENAME) | 250 | (filename . FILENAME) |
| 239 | (position . POS) | 251 | (buf . BUFFER-OR-NAME) |
| 240 | (front-context-string . STR-AFTER-POS) | 252 | (position . POS) |
| 241 | (rear-context-string . STR-BEFORE-POS) | 253 | (front-context-string . STR-AFTER-POS) |
| 242 | (handler . HANDLER) | 254 | (rear-context-string . STR-BEFORE-POS) |
| 243 | (annotation . ANNOTATION) | 255 | (handler . HANDLER) |
| 244 | 256 | (annotation . ANNOTATION) | |
| 245 | FILENAME names the bookmarked file. | 257 | |
| 246 | POS is the bookmarked buffer position. | 258 | FILENAME names the bookmarked file. |
| 247 | STR-AFTER-POS is buffer text that immediately follows POS. | 259 | BUFFER-OR-NAME is a buffer or the name of a buffer that is used |
| 248 | STR-BEFORE-POS is buffer text that immediately precedes POS. | 260 | if FILENAME is not defined or it refers to a non-existent file. |
| 249 | ANNOTATION is a string that describes the bookmark. | 261 | POS is the bookmarked buffer position. |
| 250 | See options `bookmark-use-annotations' and | 262 | STR-AFTER-POS is buffer text that immediately follows POS. |
| 251 | `bookmark-automatically-show-annotations'. | 263 | STR-BEFORE-POS is buffer text that immediately precedes POS. |
| 252 | HANDLER is a function that provides the bookmark-jump behavior for a | 264 | ANNOTATION is a string that describes the bookmark. |
| 253 | specific kind of bookmark. This is the case for Info bookmarks, | 265 | See options `bookmark-use-annotations' and |
| 254 | for instance. HANDLER must accept a bookmark as its single argument.") | 266 | `bookmark-automatically-show-annotations'. |
| 255 | 267 | HANDLER is a function that provides the bookmark-jump behavior for a | |
| 256 | (defvar bookmarks-already-loaded nil | 268 | specific kind of bookmark instead of the default `bookmark-default-handler'. |
| 257 | "Non-nil if and only if bookmarks have been loaded from `bookmark-default-file'.") | 269 | This is the case for Info bookmarks, for instance. HANDLER must accept |
| 270 | a bookmark as its single argument. | ||
| 271 | |||
| 272 | A function `bookmark-make-record-function' may define additional entries | ||
| 273 | in PARAM-LIST that can be used by HANDLER.") | ||
| 274 | |||
| 275 | (defvar bookmark-bookmarks-timestamp nil | ||
| 276 | "Timestamp of current default bookmark file. | ||
| 277 | The value is actually (FILE . MODTIME), where FILE is a bookmark file that | ||
| 278 | defaults to `bookmark-default-file' and MODTIME is its modification time.") | ||
| 279 | (define-obsolete-variable-alias 'bookmarks-already-loaded | ||
| 280 | 'bookmark-bookmarks-timestamp "27.1") | ||
| 258 | 281 | ||
| 259 | (defvar bookmark-file-coding-system nil | 282 | (defvar bookmark-file-coding-system nil |
| 260 | "The coding-system of the last loaded or saved bookmark file.") | 283 | "The coding-system of the last loaded or saved bookmark file.") |
| @@ -1013,12 +1036,19 @@ it to the name of the bookmark currently being set, advancing | |||
| 1013 | 1036 | ||
| 1014 | (defun bookmark-maybe-load-default-file () | 1037 | (defun bookmark-maybe-load-default-file () |
| 1015 | "If bookmarks have not been loaded from the default place, load them." | 1038 | "If bookmarks have not been loaded from the default place, load them." |
| 1016 | (and (not bookmarks-already-loaded) | 1039 | (cond ((and (not bookmark-bookmarks-timestamp) |
| 1017 | (null bookmark-alist) | 1040 | (null bookmark-alist) |
| 1018 | (file-readable-p bookmark-default-file) | 1041 | (file-readable-p bookmark-default-file) |
| 1019 | (bookmark-load bookmark-default-file t t) | 1042 | (bookmark-load bookmark-default-file t t))) |
| 1020 | (setq bookmarks-already-loaded t))) | 1043 | ((and bookmark-watch-bookmark-file |
| 1021 | 1044 | (not (equal (nth 5 (file-attributes | |
| 1045 | (car bookmark-bookmarks-timestamp))) | ||
| 1046 | (cdr bookmark-bookmarks-timestamp))) | ||
| 1047 | (or (eq 'silent bookmark-watch-bookmark-file) | ||
| 1048 | (yes-or-no-p | ||
| 1049 | (format "Bookmarks %s changed on disk. Reload? " | ||
| 1050 | (car bookmark-bookmarks-timestamp))))) | ||
| 1051 | (bookmark-load (car bookmark-bookmarks-timestamp) t t)))) | ||
| 1022 | 1052 | ||
| 1023 | (defun bookmark-maybe-sort-alist () | 1053 | (defun bookmark-maybe-sort-alist () |
| 1024 | "Return `bookmark-alist' for display. | 1054 | "Return `bookmark-alist' for display. |
| @@ -1181,7 +1211,7 @@ Changes current buffer and point and returns nil, or signals a `file-error'." | |||
| 1181 | (cond | 1211 | (cond |
| 1182 | ((and file (file-readable-p file) (not (buffer-live-p buf))) | 1212 | ((and file (file-readable-p file) (not (buffer-live-p buf))) |
| 1183 | (find-file-noselect file)) | 1213 | (find-file-noselect file)) |
| 1184 | ;; No file found. See if buffer BUF have been created. | 1214 | ;; No file found. See if buffer BUF has been created. |
| 1185 | ((and buf (get-buffer buf))) | 1215 | ((and buf (get-buffer buf))) |
| 1186 | (t ;; If not, raise error. | 1216 | (t ;; If not, raise error. |
| 1187 | (signal 'bookmark-error-no-filename (list 'stringp file))))) | 1217 | (signal 'bookmark-error-no-filename (list 'stringp file))))) |
| @@ -1360,42 +1390,44 @@ is greater than `bookmark-alist-modification-count'." | |||
| 1360 | 1390 | ||
| 1361 | 1391 | ||
| 1362 | ;;;###autoload | 1392 | ;;;###autoload |
| 1363 | (defun bookmark-save (&optional parg file) | 1393 | (defun bookmark-save (&optional parg file make-default) |
| 1364 | "Save currently defined bookmarks. | 1394 | "Save currently defined bookmarks in FILE. |
| 1365 | Saves by default in the file defined by the variable | 1395 | FILE defaults to `bookmark-default-file'. |
| 1366 | `bookmark-default-file'. With a prefix arg, save it in file FILE | 1396 | With prefix PARG, query user for a file to save in. |
| 1367 | \(second argument). | 1397 | If MAKE-DEFAULT is non-nil (interactively with prefix C-u C-u) |
| 1368 | 1398 | the file we save in becomes the new default in the current Emacs | |
| 1369 | If you are calling this from Lisp, the two arguments are PARG and | 1399 | session (without affecting the value of `bookmark-default-file'.). |
| 1370 | FILE, and if you just want it to write to the default file, then | ||
| 1371 | pass no arguments. Or pass in nil and FILE, and it will save in FILE | ||
| 1372 | instead. If you pass in one argument, and it is non-nil, then the | ||
| 1373 | user will be interactively queried for a file to save in. | ||
| 1374 | 1400 | ||
| 1375 | When you want to load in the bookmarks from a file, use | 1401 | When you want to load in the bookmarks from a file, use |
| 1376 | `bookmark-load', \\[bookmark-load]. That function will prompt you | 1402 | `bookmark-load', \\[bookmark-load]. That function will prompt you |
| 1377 | for a file, defaulting to the file defined by variable | 1403 | for a file, defaulting to the file defined by variable |
| 1378 | `bookmark-default-file'." | 1404 | `bookmark-default-file'." |
| 1379 | (interactive "P") | 1405 | (interactive |
| 1406 | (list current-prefix-arg nil (equal '(16) current-prefix-arg))) | ||
| 1380 | (bookmark-maybe-load-default-file) | 1407 | (bookmark-maybe-load-default-file) |
| 1381 | (cond | 1408 | (unless file |
| 1382 | ((and (null parg) (null file)) | 1409 | (setq file |
| 1383 | ;;whether interactive or not, write to default file | 1410 | (let ((default (or (car bookmark-bookmarks-timestamp) |
| 1384 | (bookmark-write-file bookmark-default-file)) | 1411 | bookmark-default-file))) |
| 1385 | ((and (null parg) file) | 1412 | (if parg |
| 1386 | ;;whether interactive or not, write to given file | 1413 | ;; This should be part of the `interactive' spec. |
| 1387 | (bookmark-write-file file)) | 1414 | (read-file-name (format "File to save bookmarks in: (%s) " |
| 1388 | ((and parg (not file)) | 1415 | default) |
| 1389 | ;;have been called interactively w/ prefix arg | 1416 | (file-name-directory default) default) |
| 1390 | (let ((file (read-file-name "File to save bookmarks in: "))) | 1417 | default)))) |
| 1391 | (bookmark-write-file file))) | 1418 | (bookmark-write-file file) |
| 1392 | (t ; someone called us with prefix-arg *and* a file, so just write to file | 1419 | ;; Signal that we have synced the bookmark file by setting this to 0. |
| 1393 | (bookmark-write-file file))) | 1420 | ;; If there was an error at any point before, it will not get set, |
| 1394 | ;; signal that we have synced the bookmark file by setting this to | 1421 | ;; which is what we want. |
| 1395 | ;; 0. If there was an error at any point before, it will not get | 1422 | (setq bookmark-alist-modification-count 0) |
| 1396 | ;; set, which is what we want. | 1423 | (if make-default |
| 1397 | (setq bookmark-alist-modification-count 0)) | 1424 | (let ((default (expand-file-name file))) |
| 1398 | 1425 | (setq bookmark-bookmarks-timestamp | |
| 1426 | (cons default (nth 5 (file-attributes default))))) | ||
| 1427 | (let ((default (car bookmark-bookmarks-timestamp))) | ||
| 1428 | (if (string= default (expand-file-name file)) | ||
| 1429 | (setq bookmark-bookmarks-timestamp | ||
| 1430 | (cons default (nth 5 (file-attributes default)))))))) | ||
| 1399 | 1431 | ||
| 1400 | 1432 | ||
| 1401 | (defun bookmark-write-file (file) | 1433 | (defun bookmark-write-file (file) |
| @@ -1469,12 +1501,13 @@ This is a helper for `bookmark-import-new-list'." | |||
| 1469 | 1501 | ||
| 1470 | 1502 | ||
| 1471 | ;;;###autoload | 1503 | ;;;###autoload |
| 1472 | (defun bookmark-load (file &optional overwrite no-msg) | 1504 | (defun bookmark-load (file &optional overwrite no-msg default) |
| 1473 | "Load bookmarks from FILE (which must be in bookmark format). | 1505 | "Load bookmarks from FILE (which must be in bookmark format). |
| 1474 | Appends loaded bookmarks to the front of the list of bookmarks. If | 1506 | Appends loaded bookmarks to the front of the list of bookmarks. |
| 1475 | optional second argument OVERWRITE is non-nil, existing bookmarks are | 1507 | If argument OVERWRITE is non-nil, existing bookmarks are destroyed. |
| 1476 | destroyed. Optional third arg NO-MSG means don't display any messages | 1508 | Optional third arg NO-MSG means don't display any messages while loading. |
| 1477 | while loading. | 1509 | If DEFAULT is non-nil make FILE the new bookmark file to watch. |
| 1510 | Interactively, a prefix arg makes OVERWRITE and DEFAULT non-nil. | ||
| 1478 | 1511 | ||
| 1479 | If you load a file that doesn't contain a proper bookmark alist, you | 1512 | If you load a file that doesn't contain a proper bookmark alist, you |
| 1480 | will corrupt Emacs's bookmark list. Generally, you should only load | 1513 | will corrupt Emacs's bookmark list. Generally, you should only load |
| @@ -1487,48 +1520,51 @@ If you load a file containing bookmarks with the same names as | |||
| 1487 | bookmarks already present in your Emacs, the new bookmarks will get | 1520 | bookmarks already present in your Emacs, the new bookmarks will get |
| 1488 | unique numeric suffixes \"<2>\", \"<3>\", etc." | 1521 | unique numeric suffixes \"<2>\", \"<3>\", etc." |
| 1489 | (interactive | 1522 | (interactive |
| 1490 | (list (read-file-name | 1523 | (let ((default (abbreviate-file-name |
| 1491 | (format "Load bookmarks from: (%s) " | 1524 | (or (car bookmark-bookmarks-timestamp) |
| 1492 | bookmark-default-file) | 1525 | (expand-file-name bookmark-default-file)))) |
| 1493 | ;;Default might not be used often, | 1526 | (prefix current-prefix-arg)) |
| 1494 | ;;but there's no better default, and | 1527 | (list (read-file-name (format "Load bookmarks from: (%s) " default) |
| 1495 | ;;I guess it's better than none at all. | 1528 | (file-name-directory default) default 'confirm) |
| 1496 | "~/" bookmark-default-file 'confirm))) | 1529 | prefix nil prefix))) |
| 1497 | (setq file (abbreviate-file-name (expand-file-name file))) | 1530 | (let* ((file (expand-file-name file)) |
| 1498 | (if (not (file-readable-p file)) | 1531 | (afile (abbreviate-file-name file))) |
| 1499 | (error "Cannot read bookmark file %s" file) | 1532 | (unless (file-readable-p file) |
| 1533 | (user-error "Cannot read bookmark file %s" afile)) | ||
| 1500 | (let ((reporter | 1534 | (let ((reporter |
| 1501 | (when (null no-msg) | 1535 | (unless no-msg |
| 1502 | (make-progress-reporter | 1536 | (make-progress-reporter |
| 1503 | (format "Loading bookmarks from %s..." file))))) | 1537 | (format "Loading bookmarks from %s..." file))))) |
| 1504 | (with-current-buffer (let ((enable-local-variables nil)) | 1538 | (with-current-buffer (let (enable-local-variables) |
| 1505 | (find-file-noselect file)) | 1539 | (find-file-noselect file)) |
| 1506 | (goto-char (point-min)) | 1540 | (goto-char (point-min)) |
| 1507 | (bookmark-maybe-upgrade-file-format) | 1541 | (bookmark-maybe-upgrade-file-format) |
| 1508 | (let ((blist (bookmark-alist-from-buffer))) | 1542 | (let ((blist (bookmark-alist-from-buffer))) |
| 1509 | (if (listp blist) | 1543 | (unless (listp blist) |
| 1510 | (progn | 1544 | (error "Invalid bookmark list in %s" file)) |
| 1511 | (if overwrite | 1545 | ;; RW: Upon loading the bookmarks, we could add to each bookmark |
| 1512 | (progn | 1546 | ;; in `bookmark-alist' an extra key `bookmark-file', so that |
| 1513 | (setq bookmark-alist blist) | 1547 | ;; upon reloading the bookmarks with OVERWRITE non-nil, |
| 1514 | (setq bookmark-alist-modification-count 0)) | 1548 | ;; we overwrite only those bookmarks for which the key `bookmark-file' |
| 1515 | ;; else | 1549 | ;; matches FILE. `bookmark-save' can ignore this key. |
| 1516 | (bookmark-import-new-list blist) | 1550 | ;; Would this be a useful option? |
| 1517 | (setq bookmark-alist-modification-count | 1551 | (if overwrite |
| 1518 | (1+ bookmark-alist-modification-count))) | 1552 | (setq bookmark-alist blist |
| 1519 | (if (string-equal | 1553 | bookmark-alist-modification-count 0) |
| 1520 | (abbreviate-file-name | 1554 | (bookmark-import-new-list blist) |
| 1521 | (expand-file-name bookmark-default-file)) | 1555 | (setq bookmark-alist-modification-count |
| 1522 | file) | 1556 | (1+ bookmark-alist-modification-count))) |
| 1523 | (setq bookmarks-already-loaded t)) | 1557 | (if (or default |
| 1524 | (bookmark-bmenu-surreptitiously-rebuild-list) | 1558 | (string= file (or (car bookmark-bookmarks-timestamp) |
| 1525 | (setq bookmark-file-coding-system buffer-file-coding-system)) | 1559 | (expand-file-name bookmark-default-file)))) |
| 1526 | (error "Invalid bookmark list in %s" file))) | 1560 | (setq bookmark-bookmarks-timestamp |
| 1561 | (cons file (nth 5 (file-attributes file))))) | ||
| 1562 | (bookmark-bmenu-surreptitiously-rebuild-list) | ||
| 1563 | (setq bookmark-file-coding-system buffer-file-coding-system)) | ||
| 1527 | (kill-buffer (current-buffer))) | 1564 | (kill-buffer (current-buffer))) |
| 1528 | (when (null no-msg) | 1565 | (unless no-msg |
| 1529 | (progress-reporter-done reporter))))) | 1566 | (progress-reporter-done reporter))))) |
| 1530 | 1567 | ||
| 1531 | |||
| 1532 | 1568 | ||
| 1533 | ;;; Code supporting the dired-like bookmark menu. | 1569 | ;;; Code supporting the dired-like bookmark menu. |
| 1534 | ;; Prefix is "bookmark-bmenu" for "buffer-menu": | 1570 | ;; Prefix is "bookmark-bmenu" for "buffer-menu": |
| @@ -1552,6 +1588,7 @@ unique numeric suffixes \"<2>\", \"<3>\", etc." | |||
| 1552 | (define-key map "o" 'bookmark-bmenu-other-window) | 1588 | (define-key map "o" 'bookmark-bmenu-other-window) |
| 1553 | (define-key map "\C-o" 'bookmark-bmenu-switch-other-window) | 1589 | (define-key map "\C-o" 'bookmark-bmenu-switch-other-window) |
| 1554 | (define-key map "s" 'bookmark-bmenu-save) | 1590 | (define-key map "s" 'bookmark-bmenu-save) |
| 1591 | (define-key map "\C-x\C-s" 'bookmark-bmenu-save) | ||
| 1555 | (define-key map "k" 'bookmark-bmenu-delete) | 1592 | (define-key map "k" 'bookmark-bmenu-delete) |
| 1556 | (define-key map "\C-d" 'bookmark-bmenu-delete-backwards) | 1593 | (define-key map "\C-d" 'bookmark-bmenu-delete-backwards) |
| 1557 | (define-key map "x" 'bookmark-bmenu-execute-deletions) | 1594 | (define-key map "x" 'bookmark-bmenu-execute-deletions) |
| @@ -1573,6 +1610,34 @@ unique numeric suffixes \"<2>\", \"<3>\", etc." | |||
| 1573 | (define-key map [mouse-2] 'bookmark-bmenu-other-window-with-mouse) | 1610 | (define-key map [mouse-2] 'bookmark-bmenu-other-window-with-mouse) |
| 1574 | map)) | 1611 | map)) |
| 1575 | 1612 | ||
| 1613 | (easy-menu-define | ||
| 1614 | bookmark-menu bookmark-bmenu-mode-map "Bookmark Menu" | ||
| 1615 | '("Bookmark" | ||
| 1616 | ["Select Bookmark in This Window" bookmark-bmenu-this-window t] | ||
| 1617 | ["Select Bookmark in Full-Frame Window" bookmark-bmenu-1-window t] | ||
| 1618 | ["Select Bookmark in Other Window" bookmark-bmenu-other-window t] | ||
| 1619 | ["Select Bookmark in Other Frame" bookmark-bmenu-other-frame t] | ||
| 1620 | ["Select Marked Bookmarks" bookmark-bmenu-select t] | ||
| 1621 | "---" | ||
| 1622 | ["Mark Bookmark" bookmark-bmenu-mark t] | ||
| 1623 | ["Unmark Bookmark" bookmark-bmenu-unmark t] | ||
| 1624 | ["Unmark Backwards" bookmark-bmenu-backup-unmark t] | ||
| 1625 | ["Toggle Display of Filenames" bookmark-bmenu-toggle-filenames t] | ||
| 1626 | ["Display Location of Bookmark" bookmark-bmenu-locate t] | ||
| 1627 | "---" | ||
| 1628 | ("Edit Bookmarks" | ||
| 1629 | ["Rename Bookmark" bookmark-bmenu-rename t] | ||
| 1630 | ["Relocate Bookmark's File" bookmark-bmenu-relocate t] | ||
| 1631 | ["Mark Bookmark for Deletion" bookmark-bmenu-delete t] | ||
| 1632 | ["Delete Marked Bookmarks" bookmark-bmenu-execute-deletions t]) | ||
| 1633 | ("Annotations" | ||
| 1634 | ["Show Annotation for Current Bookmark" bookmark-bmenu-show-annotation t] | ||
| 1635 | ["Show Annotations for All Bookmarks" bookmark-bmenu-show-all-annotations t] | ||
| 1636 | ["Edit Annotation for Current Bookmark." bookmark-bmenu-edit-annotation t]) | ||
| 1637 | "---" | ||
| 1638 | ["Save Bookmarks" bookmark-bmenu-save t] | ||
| 1639 | ["Load Bookmarks" bookmark-bmenu-load t])) | ||
| 1640 | |||
| 1576 | ;; Bookmark Buffer Menu mode is suitable only for specially formatted | 1641 | ;; Bookmark Buffer Menu mode is suitable only for specially formatted |
| 1577 | ;; data. | 1642 | ;; data. |
| 1578 | (put 'bookmark-bmenu-mode 'mode-class 'special) | 1643 | (put 'bookmark-bmenu-mode 'mode-class 'special) |
| @@ -1647,6 +1712,8 @@ deletion, or > if it is flagged for displaying." | |||
| 1647 | ;;;###autoload | 1712 | ;;;###autoload |
| 1648 | (defalias 'edit-bookmarks 'bookmark-bmenu-list) | 1713 | (defalias 'edit-bookmarks 'bookmark-bmenu-list) |
| 1649 | 1714 | ||
| 1715 | ;; FIXME: This could also display the current default bookmark file | ||
| 1716 | ;; according to `bookmark-bookmarks-timestamp'. | ||
| 1650 | (defun bookmark-bmenu-set-header () | 1717 | (defun bookmark-bmenu-set-header () |
| 1651 | "Set the immutable header line." | 1718 | "Set the immutable header line." |
| 1652 | (let ((header (concat "%% " "Bookmark"))) | 1719 | (let ((header (concat "%% " "Bookmark"))) |
| @@ -1815,9 +1882,12 @@ If the annotation does not exist, do nothing." | |||
| 1815 | (save-excursion | 1882 | (save-excursion |
| 1816 | (let ((old-buf (current-buffer))) | 1883 | (let ((old-buf (current-buffer))) |
| 1817 | (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t) | 1884 | (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t) |
| 1818 | (delete-region (point-min) (point-max)) | 1885 | (let (buffer-read-only) |
| 1819 | (insert annotation) | 1886 | (erase-buffer) |
| 1820 | (goto-char (point-min)) | 1887 | (insert annotation) |
| 1888 | (goto-char (point-min)) | ||
| 1889 | (set-buffer-modified-p nil)) | ||
| 1890 | (setq buffer-read-only t) | ||
| 1821 | (switch-to-buffer-other-window old-buf)))))) | 1891 | (switch-to-buffer-other-window old-buf)))))) |
| 1822 | 1892 | ||
| 1823 | 1893 | ||
| @@ -1825,22 +1895,25 @@ If the annotation does not exist, do nothing." | |||
| 1825 | "Display the annotations for all bookmarks in a buffer." | 1895 | "Display the annotations for all bookmarks in a buffer." |
| 1826 | (save-selected-window | 1896 | (save-selected-window |
| 1827 | (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t) | 1897 | (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t) |
| 1828 | (delete-region (point-min) (point-max)) | 1898 | (let (buffer-read-only) |
| 1829 | (dolist (full-record (bookmark-maybe-sort-alist)) | 1899 | (erase-buffer) |
| 1830 | (let* ((name (bookmark-name-from-full-record full-record)) | 1900 | (dolist (full-record (bookmark-maybe-sort-alist)) |
| 1831 | (ann (bookmark-get-annotation full-record))) | 1901 | (let* ((name (bookmark-name-from-full-record full-record)) |
| 1832 | (insert (concat name ":\n")) | 1902 | (ann (bookmark-get-annotation full-record))) |
| 1833 | (if (and ann (not (string-equal ann ""))) | 1903 | (insert (concat name ":\n")) |
| 1834 | ;; insert the annotation, indented by 4 spaces. | 1904 | (if (and ann (not (string-equal ann ""))) |
| 1835 | (progn | 1905 | ;; insert the annotation, indented by 4 spaces. |
| 1836 | (save-excursion (insert ann) (unless (bolp) | 1906 | (progn |
| 1837 | (insert "\n"))) | 1907 | (save-excursion (insert ann) (unless (bolp) |
| 1838 | (while (< (point) (point-max)) | 1908 | (insert "\n"))) |
| 1839 | (beginning-of-line) ; paranoia | 1909 | (while (< (point) (point-max)) |
| 1840 | (insert " ") | 1910 | (beginning-of-line) ; paranoia |
| 1841 | (forward-line) | 1911 | (insert " ") |
| 1842 | (end-of-line)))))) | 1912 | (forward-line) |
| 1843 | (goto-char (point-min)))) | 1913 | (end-of-line)))))) |
| 1914 | (goto-char (point-min)) | ||
| 1915 | (set-buffer-modified-p nil)) | ||
| 1916 | (setq buffer-read-only t))) | ||
| 1844 | 1917 | ||
| 1845 | 1918 | ||
| 1846 | (defun bookmark-bmenu-mark () | 1919 | (defun bookmark-bmenu-mark () |
| @@ -1901,13 +1974,13 @@ You can mark bookmarks with the \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-mar | |||
| 1901 | nil))) | 1974 | nil))) |
| 1902 | 1975 | ||
| 1903 | 1976 | ||
| 1904 | (defun bookmark-bmenu-save (parg) | 1977 | (defun bookmark-bmenu-save () |
| 1905 | "Save the current list into a bookmark file. | 1978 | "Save the current list into a bookmark file. |
| 1906 | With a prefix arg, prompts for a file to save them in." | 1979 | With a prefix arg, prompts for a file to save them in." |
| 1907 | (interactive "P") | 1980 | (interactive) |
| 1908 | (save-excursion | 1981 | (save-excursion |
| 1909 | (save-window-excursion | 1982 | (save-window-excursion |
| 1910 | (bookmark-save parg) | 1983 | (call-interactively 'bookmark-save) |
| 1911 | (set-buffer-modified-p nil)))) | 1984 | (set-buffer-modified-p nil)))) |
| 1912 | 1985 | ||
| 1913 | 1986 | ||