diff options
| author | Karl Fogel | 2009-10-25 02:07:45 +0000 |
|---|---|---|
| committer | Karl Fogel | 2009-10-25 02:07:45 +0000 |
| commit | 7c85c02b812e427c3f5e41761ae5f44b18c34ea6 (patch) | |
| tree | ffbc8f06b5867eaf7c701ac71caf8c5f44e2c20c | |
| parent | 18060980dd40351e12ecb29186c11ab749a9d77f (diff) | |
| download | emacs-7c85c02b812e427c3f5e41761ae5f44b18c34ea6.tar.gz emacs-7c85c02b812e427c3f5e41761ae5f44b18c34ea6.zip | |
* bookmark.el: Update documentation, especially documentation
of `bookmark-alist' and of the bookmark file format.
Patch by Drew Adams, with minor tweaks from me. (Bug#4195)
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/bookmark.el | 193 |
2 files changed, 117 insertions, 82 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7edfa9c4144..8021b71f656 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2009-10-24 Karl Fogel <kfogel@red-bean.com> | ||
| 2 | |||
| 3 | * bookmark.el: Update documentation, especially documentation | ||
| 4 | of `bookmark-alist' and of the bookmark file format. | ||
| 5 | Patch by Drew Adams, with minor tweaks from me. (Bug#4195) | ||
| 6 | |||
| 1 | 2009-10-24 Chong Yidong <cyd@stupidchicken.com> | 7 | 2009-10-24 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 8 | ||
| 3 | * mail/emacsbug.el (report-emacs-bug): Clarify that the | 9 | * mail/emacsbug.el (report-emacs-bug): Clarify that the |
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 331e392a9c7..ad715d8a21e 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -252,31 +252,39 @@ functions have a binding in this keymap.") | |||
| 252 | ;;; Core variables and data structures: | 252 | ;;; Core variables and data structures: |
| 253 | (defvar bookmark-alist () | 253 | (defvar bookmark-alist () |
| 254 | "Association list of bookmarks and their records. | 254 | "Association list of bookmarks and their records. |
| 255 | You probably don't want to change the value of this alist yourself; | 255 | Bookmark functions update the value automatically. |
| 256 | instead, let the various bookmark functions do it for you. | 256 | You probably do NOT want to change the value yourself. |
| 257 | 257 | ||
| 258 | The format of the alist is | 258 | The value is an alist with entries of the form |
| 259 | 259 | ||
| 260 | \(BOOKMARK1 BOOKMARK2 ...\) | 260 | (BOOKMARK-NAME . PARAM-ALIST) |
| 261 | 261 | ||
| 262 | where each BOOKMARK is of the form | 262 | or the deprecated form (BOOKMARK-NAME PARAM-ALIST). |
| 263 | 263 | ||
| 264 | (NAME PARAM-ALIST) or (NAME . PARAM-ALIST) | 264 | BOOKMARK-NAME is the name you gave to the bookmark when creating it. |
| 265 | 265 | ||
| 266 | where the first form is the old deprecated one and the second is | 266 | PARAM-ALIST is an alist of bookmark information. The order of the |
| 267 | the new favored one. PARAM-ALIST is typically of the form: | 267 | entries in PARAM-ALIST is not important. The possible entries are |
| 268 | described below. An entry with a key but null value means the entry | ||
| 269 | is not used. | ||
| 268 | 270 | ||
| 269 | ((filename . FILE) | 271 | (filename . FILENAME) |
| 270 | (front-context-string . FRONT-STR) | ||
| 271 | (rear-context-string . REAR-STR) | ||
| 272 | (position . POS) | 272 | (position . POS) |
| 273 | (handler . HANDLER-FUNC) | 273 | (front-context-string . STR-AFTER-POS) |
| 274 | (annotation . ANNOTATION)) | 274 | (rear-context-string . STR-BEFORE-POS) |
| 275 | 275 | (handler . HANDLER) | |
| 276 | If the element `(handler . HANDLER-FUNC)' is present, HANDLER-FUNC | 276 | (annotation . ANNOTATION) |
| 277 | will be used to open this bookmark instead of `bookmark-default-handler', | 277 | |
| 278 | whose calling discipline HANDLER-FUNC should of course match.") | 278 | FILENAME names the bookmarked file. |
| 279 | 279 | POS is the bookmarked buffer position (position in the file). | |
| 280 | STR-AFTER-POS is buffer text that immediately follows POS. | ||
| 281 | STR-BEFORE-POS is buffer text that immediately precedes POS. | ||
| 282 | ANNOTATION is a string that describes the bookmark. | ||
| 283 | See options `bookmark-use-annotations' and | ||
| 284 | `bookmark-automatically-show-annotations'. | ||
| 285 | HANDLER is a function that provides the bookmark-jump behavior for a | ||
| 286 | specific kind of bookmark. This is the case for Info bookmarks, | ||
| 287 | for instance. HANDLER must accept a bookmark as argument.") | ||
| 280 | 288 | ||
| 281 | (defvar bookmarks-already-loaded nil | 289 | (defvar bookmarks-already-loaded nil |
| 282 | "Non-nil iff bookmarks have been loaded from `bookmark-default-file'.") | 290 | "Non-nil iff bookmarks have been loaded from `bookmark-default-file'.") |
| @@ -564,51 +572,71 @@ record that pertains to the location within the buffer." | |||
| 564 | 572 | ||
| 565 | ;;; File format stuff | 573 | ;;; File format stuff |
| 566 | 574 | ||
| 567 | ;; The OLD format of the bookmark-alist was: | 575 | ;; *IMPORTANT NOTICE* If you are thinking about modifying (redefining) |
| 576 | ;; the bookmark file format -- please don't. The current format | ||
| 577 | ;; should be extensible enough. If you feel the need to change it, | ||
| 578 | ;; please discuss it with other Emacs developers first. | ||
| 579 | ;; | ||
| 580 | ;; The format of `bookmark-alist' has changed twice in its lifetime. | ||
| 581 | ;; This comment describes the three formats, FIRST, SECOND, and | ||
| 582 | ;; CURRENT. | ||
| 583 | ;; | ||
| 584 | ;; The FIRST format was used prior to Emacs 20: | ||
| 568 | ;; | 585 | ;; |
| 569 | ;; ((BOOKMARK-NAME . (FILENAME | 586 | ;; ((BOOKMARK-NAME (FILENAME |
| 570 | ;; STRING-IN-FRONT | 587 | ;; STRING-IN-FRONT |
| 571 | ;; STRING-BEHIND | 588 | ;; STRING-BEHIND |
| 572 | ;; POINT)) | 589 | ;; POINT)) |
| 573 | ;; ...) | 590 | ;; ...) |
| 574 | ;; | 591 | ;; |
| 575 | ;; The NEW format of the bookmark-alist is: | 592 | ;; The SECOND format was introduced in Emacs 20: |
| 593 | ;; | ||
| 594 | ;; ((BOOKMARK-NAME ((filename . FILENAME) | ||
| 595 | ;; (position . POS) | ||
| 596 | ;; (front-context-string . STR-AFTER-POS) | ||
| 597 | ;; (rear-context-string . STR-BEFORE-POS) | ||
| 598 | ;; (annotation . ANNOTATION) | ||
| 599 | ;; (whatever . VALUE) | ||
| 600 | ;; ... | ||
| 601 | ;; )) | ||
| 602 | ;; ...) | ||
| 603 | ;; | ||
| 604 | ;; The CURRENT format was introduced in Emacs 22: | ||
| 576 | ;; | 605 | ;; |
| 577 | ;; ((BOOKMARK-NAME (filename . FILENAME) | 606 | ;; ((BOOKMARK-NAME (filename . FILENAME) |
| 578 | ;; (front-context-string . STRING-IN-FRONT) | 607 | ;; (position . POS) |
| 579 | ;; (rear-context-string . STRING-BEHIND) | 608 | ;; (front-context-string . STR-AFTER-POS) |
| 580 | ;; (position . POINT) | 609 | ;; (rear-context-string . STR-BEFORE-POS) |
| 581 | ;; (annotation . ANNOTATION) | 610 | ;; (annotation . ANNOTATION) |
| 582 | ;; (whatever . VALUE) | 611 | ;; (whatever . VALUE) |
| 583 | ;; ... | 612 | ;; ... |
| 584 | ;; )) | 613 | ;; ) |
| 585 | ;; ...) | 614 | ;; ...) |
| 586 | ;; | 615 | ;; |
| 616 | ;; Both FIRST and SECOND have the same level of nesting: the cadr of a | ||
| 617 | ;; bookmark record is a list of entry information. FIRST and SECOND | ||
| 618 | ;; differ in the form of the record information: FIRST uses a list of | ||
| 619 | ;; atoms, and SECOND uses an alist. In the FIRST format, the order of | ||
| 620 | ;; the list elements matters. In the SECOND format, the order of the | ||
| 621 | ;; alist elements is unimportant. The SECOND format facilitates the | ||
| 622 | ;; addition of new kinds of elements, to support new kinds of | ||
| 623 | ;; bookmarks or code evolution. | ||
| 587 | ;; | 624 | ;; |
| 588 | ;; I switched to using an internal as well as external alist because I | 625 | ;; The CURRENT format removes a level of nesting wrt FIRST and SECOND, |
| 589 | ;; felt that would be a more flexible framework in which to add | 626 | ;; saving one cons cell per bookmark: the cadr of a bookmark record is |
| 590 | ;; features. It means that the order in which values appear doesn't | 627 | ;; no longer a cons. Why that change was made remains a mystery -- |
| 591 | ;; matter, and it means that arbitrary values can be added without | 628 | ;; just be aware of it. (Be aware too that this explanatory comment |
| 592 | ;; risk of interfering with existing ones. | 629 | ;; was incorrect in Emacs 22 and Emacs 23.1.) |
| 593 | ;; | ||
| 594 | ;; BOOKMARK-NAME is the string the user gives the bookmark and | ||
| 595 | ;; accesses it by from then on. | ||
| 596 | ;; | 630 | ;; |
| 597 | ;; FILENAME is the location of the file in which the bookmark is set. | 631 | ;; To deal with the change from FIRST format to SECOND, conversion |
| 632 | ;; code was added, and it is still in use. See | ||
| 633 | ;; `bookmark-maybe-upgrade-file-format'. | ||
| 598 | ;; | 634 | ;; |
| 599 | ;; STRING-IN-FRONT is a string of `bookmark-search-size' chars of | 635 | ;; No conversion from SECOND to CURRENT is done. Instead, the code |
| 600 | ;; context in front of the point at which the bookmark is set. | 636 | ;; handles both formats OK. It must continue to do so. |
| 601 | ;; | 637 | ;; |
| 602 | ;; STRING-BEHIND is the same thing, but after the point. | 638 | ;; See the doc string of `bookmark-alist' for information about the |
| 603 | ;; | 639 | ;; elements that define a bookmark (e.g. `filename'). |
| 604 | ;; The context strings exist so that modifications to a file don't | ||
| 605 | ;; necessarily cause a bookmark's position to be invalidated. | ||
| 606 | ;; bookmark-jump will search for STRING-BEHIND and STRING-IN-FRONT in | ||
| 607 | ;; case the file has changed since the bookmark was set. It will | ||
| 608 | ;; attempt to place the user before the changes, if there were any. | ||
| 609 | ;; ANNOTATION is the annotation for the bookmark; it may not exist | ||
| 610 | ;; (for backward compatibility), be nil (no annotation), or be a | ||
| 611 | ;; string. | ||
| 612 | 640 | ||
| 613 | 641 | ||
| 614 | (defconst bookmark-file-format-version 1 | 642 | (defconst bookmark-file-format-version 1 |
| @@ -744,25 +772,25 @@ This expects to be called from `point-min' in a bookmark file." | |||
| 744 | "Set a bookmark named NAME at the current location. | 772 | "Set a bookmark named NAME at the current location. |
| 745 | If name is nil, then prompt the user. | 773 | If name is nil, then prompt the user. |
| 746 | 774 | ||
| 747 | With prefix arg (NO-OVERWRITE), do not overwrite a bookmark that | 775 | With a prefix arg (non-nil NO-OVERWRITE), do not overwrite any |
| 748 | has the same name as NAME if such a bookmark already exists, but | 776 | existing bookmark that has the same name as NAME, but instead push the |
| 749 | instead push the new bookmark onto the bookmark alist. Thus the | 777 | new bookmark onto the bookmark alist. The most recently set bookmark |
| 750 | most recently set bookmark with name NAME would be the one in | 778 | with name NAME is thus the one in effect at any given time, but the |
| 751 | effect at any given time, but the others are still there, should | 779 | others are still there, should the user decide to delete the most |
| 752 | the user decide to delete the most recent one. | 780 | recent one. |
| 753 | 781 | ||
| 754 | To yank words from the text of the buffer and use them as part of the | 782 | To yank words from the text of the buffer and use them as part of the |
| 755 | bookmark name, type C-w while setting a bookmark. Successive C-w's | 783 | bookmark name, type C-w while setting a bookmark. Successive C-w's |
| 756 | yank successive words. | 784 | yank successive words. |
| 757 | 785 | ||
| 758 | Typing C-u will insert (at the bookmark name prompt) the name of the | 786 | Typing C-u inserts (at the bookmark name prompt) the name of the last |
| 759 | last bookmark used in the document where the new bookmark is being set; | 787 | bookmark used in the document where the new bookmark is being set; |
| 760 | this helps one use a single bookmark name to track progress through | 788 | this helps you use a single bookmark name to track progress through a |
| 761 | a large document. If there is no prior bookmark for this document, | 789 | large document. If there is no prior bookmark for this document, then |
| 762 | then C-u inserts an appropriate name based on the buffer or file. | 790 | C-u inserts an appropriate name based on the buffer or file. |
| 763 | 791 | ||
| 764 | Use \\[bookmark-delete] to remove bookmarks \(give it a name and it | 792 | Use \\[bookmark-delete] to remove bookmarks \(you give it a name and |
| 765 | removes only the first instance of a bookmark with that name from | 793 | it removes only the first instance of a bookmark with that name from |
| 766 | the list of bookmarks.\)" | 794 | the list of bookmarks.\)" |
| 767 | (interactive (list nil current-prefix-arg)) | 795 | (interactive (list nil current-prefix-arg)) |
| 768 | (let* ((record (bookmark-make-record)) | 796 | (let* ((record (bookmark-make-record)) |
| @@ -890,8 +918,8 @@ to the buffer's file name if `bookmark-current-bookmark' is nil." | |||
| 890 | 918 | ||
| 891 | 919 | ||
| 892 | (defun bookmark-buffer-name () | 920 | (defun bookmark-buffer-name () |
| 893 | "Return the name of the current buffer (or its file, if any) in a | 921 | "Return the name of the current buffer in a form usable as a bookmark name. |
| 894 | way that is suitable as a bookmark name." | 922 | If the buffer is associated with a file or directory, use that name." |
| 895 | (cond | 923 | (cond |
| 896 | ;; Or are we a file? | 924 | ;; Or are we a file? |
| 897 | (buffer-file-name (file-name-nondirectory buffer-file-name)) | 925 | (buffer-file-name (file-name-nondirectory buffer-file-name)) |
| @@ -1012,8 +1040,8 @@ BOOKMARK may be a bookmark name (a string) or a bookmark record, but | |||
| 1012 | the latter is usually only used by programmatic callers. | 1040 | the latter is usually only used by programmatic callers. |
| 1013 | 1041 | ||
| 1014 | If DISPLAY-FUNC is non-nil, it is a function to invoke to display the | 1042 | If DISPLAY-FUNC is non-nil, it is a function to invoke to display the |
| 1015 | bookmark. It defaults to `switch-to-buffer'; a typical other value | 1043 | bookmark. It defaults to `switch-to-buffer'. A typical value for |
| 1016 | would be, e.g., `switch-to-buffer-other-window'." | 1044 | DISPLAY-FUNC would be `switch-to-buffer-other-window'." |
| 1017 | (interactive | 1045 | (interactive |
| 1018 | (list (bookmark-completing-read "Jump to bookmark" | 1046 | (list (bookmark-completing-read "Jump to bookmark" |
| 1019 | bookmark-current-bookmark))) | 1047 | bookmark-current-bookmark))) |
| @@ -1053,8 +1081,7 @@ BOOKMARK may be a bookmark name (a string) or a bookmark record. | |||
| 1053 | Changes current buffer and point and returns nil, or signals a `file-error'. | 1081 | Changes current buffer and point and returns nil, or signals a `file-error'. |
| 1054 | 1082 | ||
| 1055 | If BOOKMARK has no file, this is a no-op. If BOOKMARK has a file, but | 1083 | If BOOKMARK has no file, this is a no-op. If BOOKMARK has a file, but |
| 1056 | that file no longer exists, then offer interactively to relocate BOOKMARK. | 1084 | that file no longer exists, then offer interactively to relocate BOOKMARK." |
| 1057 | " | ||
| 1058 | (condition-case err | 1085 | (condition-case err |
| 1059 | (funcall (or (bookmark-get-handler bookmark) | 1086 | (funcall (or (bookmark-get-handler bookmark) |
| 1060 | 'bookmark-default-handler) | 1087 | 'bookmark-default-handler) |
| @@ -1368,8 +1395,9 @@ for a file, defaulting to the file defined by variable | |||
| 1368 | 1395 | ||
| 1369 | 1396 | ||
| 1370 | (defun bookmark-import-new-list (new-list) | 1397 | (defun bookmark-import-new-list (new-list) |
| 1371 | "Add NEW-LIST of bookmarks to `bookmark-alist', rename new bookmarks | 1398 | "Add NEW-LIST of bookmarks to `bookmark-alist'. |
| 1372 | with \"<N>\" extensions where they collide with existing bookmark names." | 1399 | Rename new bookmarks as needed using suffix \"<N>\" (N=1,2,3...), when |
| 1400 | they conflict with existing bookmark names." | ||
| 1373 | (let ((lst new-list) | 1401 | (let ((lst new-list) |
| 1374 | (names (bookmark-all-names))) | 1402 | (names (bookmark-all-names))) |
| 1375 | (while lst | 1403 | (while lst |
| @@ -1381,8 +1409,8 @@ with \"<N>\" extensions where they collide with existing bookmark names." | |||
| 1381 | 1409 | ||
| 1382 | 1410 | ||
| 1383 | (defun bookmark-maybe-rename (full-record names) | 1411 | (defun bookmark-maybe-rename (full-record names) |
| 1384 | "If bookmark record FULL-RECORD collides with anything in NAMES, give | 1412 | "Rename bookmark FULL-RECORD if its current name is already used. |
| 1385 | FULL-RECORD a new name. This is a helper for `bookmark-import-new-list'." | 1413 | This is a helper for `bookmark-import-new-list'." |
| 1386 | (let ((found-name (bookmark-name-from-full-record full-record))) | 1414 | (let ((found-name (bookmark-name-from-full-record full-record))) |
| 1387 | (if (member found-name names) | 1415 | (if (member found-name names) |
| 1388 | ;; We've got a conflict, so generate a new name | 1416 | ;; We've got a conflict, so generate a new name |
| @@ -1640,9 +1668,8 @@ Optional argument SHOW means show them unconditionally." | |||
| 1640 | 1668 | ||
| 1641 | (defun bookmark-bmenu-show-filenames (&optional force) | 1669 | (defun bookmark-bmenu-show-filenames (&optional force) |
| 1642 | "In an interactive bookmark list, show filenames along with bookmarks. | 1670 | "In an interactive bookmark list, show filenames along with bookmarks. |
| 1643 | 1671 | Non-nil FORCE forces a redisplay showing the filenames. FORCE is used | |
| 1644 | If FORCE is non-nil, force a redisplay showing the filenames; this is | 1672 | mainly for debugging, and should not be necessary in normal use." |
| 1645 | used mainly for debugging, and should not be necessary in normal usage." | ||
| 1646 | (if (and (not force) bookmark-bmenu-toggle-filenames) | 1673 | (if (and (not force) bookmark-bmenu-toggle-filenames) |
| 1647 | nil ;already shown, so do nothing | 1674 | nil ;already shown, so do nothing |
| 1648 | (save-excursion | 1675 | (save-excursion |
| @@ -1670,9 +1697,8 @@ used mainly for debugging, and should not be necessary in normal usage." | |||
| 1670 | 1697 | ||
| 1671 | (defun bookmark-bmenu-hide-filenames (&optional force) | 1698 | (defun bookmark-bmenu-hide-filenames (&optional force) |
| 1672 | "In an interactive bookmark list, hide the filenames of the bookmarks. | 1699 | "In an interactive bookmark list, hide the filenames of the bookmarks. |
| 1673 | 1700 | Non-nil FORCE forces a redisplay showing the filenames. FORCE is used | |
| 1674 | If FORCE is non-nil, force a redisplay hiding the filenames; this is | 1701 | mainly for debugging, and should not be necessary in normal use." |
| 1675 | used mainly for debugging, and should not be necessary in normal usage." | ||
| 1676 | (if (and (not force) bookmark-bmenu-toggle-filenames) | 1702 | (if (and (not force) bookmark-bmenu-toggle-filenames) |
| 1677 | ;; nothing to hide if above is nil | 1703 | ;; nothing to hide if above is nil |
| 1678 | (save-excursion | 1704 | (save-excursion |
| @@ -1709,12 +1735,16 @@ used mainly for debugging, and should not be necessary in normal usage." | |||
| 1709 | 1735 | ||
| 1710 | 1736 | ||
| 1711 | (defun bookmark-bmenu-check-position () | 1737 | (defun bookmark-bmenu-check-position () |
| 1712 | "Return non-nil if on a line with a bookmark (the actual value | 1738 | "If point is not on a bookmark line, move it to one. |
| 1713 | returned is `bookmark-alist'). Else reposition and try again; else if | 1739 | If before the first bookmark line, move it to the first. |
| 1714 | still no bookmark, return nil." | 1740 | If after the last, move it to the last. |
| 1715 | ;; FIXME: I don't believe this doc string. As far as I can tell, | 1741 | Return `bookmark-alist'" |
| 1716 | ;; this function always just returns bookmark-alist. So what is | 1742 | ;; FIXME: The doc string originally implied that this returns nil if |
| 1717 | ;; it for, really? -kfogel, 2009-10-04 | 1743 | ;; not on a bookmark, which is false. Is there any real reason to |
| 1744 | ;; return `bookmark-alist'? This seems to be called in a few places | ||
| 1745 | ;; as a check of whether point is on a bookmark line. Those | ||
| 1746 | ;; "checks" are in fact no-ops, since this never returns nil. | ||
| 1747 | ;; -dadams, 2009-10-10 | ||
| 1718 | (cond ((< (count-lines (point-min) (point)) 2) | 1748 | (cond ((< (count-lines (point-min) (point)) 2) |
| 1719 | (goto-char (point-min)) | 1749 | (goto-char (point-min)) |
| 1720 | (forward-line 2) | 1750 | (forward-line 2) |
| @@ -1728,7 +1758,6 @@ still no bookmark, return nil." | |||
| 1728 | 1758 | ||
| 1729 | (defun bookmark-bmenu-bookmark () | 1759 | (defun bookmark-bmenu-bookmark () |
| 1730 | "Return the bookmark for this line in an interactive bookmark list buffer." | 1760 | "Return the bookmark for this line in an interactive bookmark list buffer." |
| 1731 | ;; return a string which is bookmark of this line. | ||
| 1732 | (if (bookmark-bmenu-check-position) | 1761 | (if (bookmark-bmenu-check-position) |
| 1733 | (save-excursion | 1762 | (save-excursion |
| 1734 | (save-window-excursion | 1763 | (save-window-excursion |