1 ;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later.
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation
5 ;; Author: Karl Fogel <kfogel@cyclic.com>
6 ;; Maintainer: Karl Fogel <kfogel@cyclic.com>
8 ;; Author's Update Number: 2.6.13
9 ;; Keywords: bookmarks, placeholders, annotations
12 ;; This package is for setting "bookmarks" in files. A bookmark
13 ;; associates a string with a location in a certain file. Thus, you
14 ;; can navigate your way to that location by providing the string.
15 ;; See the "User Variables" section for customizations.
18 ;; This file is part of GNU Emacs.
20 ;; GNU Emacs is free software; you can redistribute it and/or modify
21 ;; it under the terms of the GNU General Public License as published by
22 ;; the Free Software Foundation; either version 2, or (at your option)
25 ;; GNU Emacs is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs; see the file COPYING. If not, write to
32 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
34 ;; Thanks to David Bremner <bremner@cs.sfu.ca> for thinking of and
35 ;; then implementing the bookmark-current-bookmark idea. He even
36 ;; sent *patches*, bless his soul...
38 ;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for
39 ;; fixing and improving bookmark-time-to-save-p.
41 ;; Thanks go to Andrew V. Klein <avk@cig.mot.com> for the code that
42 ;; sorts the alist before presenting it to the user (in bookmark-bmenu-list
45 ;; And much thanks to David Hughes <djh@harston.cv.com> for many small
46 ;; suggestions and the code to implement them (like
47 ;; bookmark-bmenu-check-position, and some of the Lucid compatibility
50 ;; Kudos (whatever they are) go to Jim Blandy <jimb@cyclic.com>
51 ;; for his eminently sensible suggestion to separate bookmark-jump
52 ;; into bookmark-jump and bookmark-jump-noselect, which made many
53 ;; other things cleaner as well.
55 ;; Thanks to Roland McGrath for encouragement and help with defining
56 ;; autoloads on the menu-bar.
58 ;; Jonathan Stigelman <stig@key.amdahl.com> gave patches for default
59 ;; values in bookmark-jump and bookmark-set. Everybody please keep
60 ;; all the keystrokes they save thereby and send them to him at the
61 ;; end of each year :-) (No, seriously, thanks Jonathan!)
63 ;; Buckets of gratitude to John Grabowski <johng@media.mit.edu> for
64 ;; thinking up the annotations feature and implementing it so well.
66 ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
69 ;; Thanks to Mikio Nakajima <PBC01764@niftyserve.or.jp> for many bugs
70 ;; reported and fixed.
72 ;; Enough with the credits already, get on to the good stuff:
74 ;; FAVORITE CHINESE RESTAURANT:
75 ;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's
76 ;; Choice (both in Chicago's Chinatown). Well, both. How about you?
86 ;; If variable bookmark-use-annotations is non-nil, an annotation is
87 ;; queried for when setting a bookmark.
89 ;; The bookmark list is sorted lexically by default, but you can turn
90 ;; this off by setting bookmark-sort-flag to nil. If it is nil, then
91 ;; the list will be presented in the order it is recorded
92 ;; (chronologically), which is actually fairly useful as well.
96 (defvar bookmark-use-annotations nil
97 "*If non-nil, saving a bookmark will query for an annotation in a
101 (defvar bookmark-save-flag t
102 "*Controls when Emacs saves bookmarks to a file.
103 --> Nil means never save bookmarks, except when `bookmark-save' is
104 explicitly called \(\\[bookmark-save]\).
105 --> t means save bookmarks when Emacs is killed.
106 --> Otherise, it should be a number that is the frequency with which
107 the bookmark list is saved \(i.e.: the number of times which
108 Emacs' bookmark list may be modified before it is automatically
109 saved.\). If it is a number, Emacs will also automatically save
110 bookmarks when it is killed.
112 Therefore, the way to get it to save every time you make or delete a
113 bookmark is to set this variable to 1 \(or 0, which produces the same
116 To specify the file in which to save them, modify the variable
117 bookmark-default-file, which is `~/.emacs.bmk' by default.")
120 (defconst bookmark-old-default-file
"~/.emacs-bkmrks"
121 "*The .emacs.bmk file used to be called this.")
124 ;; defvarred to avoid a compilation warning:
125 (defvar bookmark-file nil
126 "Old name for `bookmark-default-file'.")
128 (defvar bookmark-default-file
130 ;; In case user set `bookmark-file' in her .emacs:
132 (if (eq system-type
'ms-dos
)
133 "~/emacs.bmk" ; Cannot have initial dot [Yuck!]
135 "*File in which to save bookmarks by default.")
138 (defvar bookmark-version-control
'nospecial
139 "*Whether or not to make numbered backups of the bookmark file.
140 It can have four values: t, nil, `never', and `nospecial'.
141 The first three have the same meaning that they do for the
142 variable `version-control', and the final value `nospecial' means just
143 use the value of `version-control'.")
146 (defvar bookmark-completion-ignore-case t
147 "*Non-nil means bookmark functions ignore case in completion.")
150 (defvar bookmark-sort-flag t
151 "*Non-nil means that bookmarks will be displayed sorted by bookmark
152 name. Otherwise they will be displayed in LIFO order (that is, most
153 recently set ones come first, oldest ones come last).")
156 (defvar bookmark-automatically-show-annotations t
157 "*Nil means don't show annotations when jumping to a bookmark.")
160 (defvar bookmark-bmenu-file-column
30
161 "*Column at which to display filenames in a buffer listing bookmarks.
162 You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames].")
165 (defvar bookmark-bmenu-toggle-filenames t
166 "*Non-nil means show filenames when listing bookmarks.
167 This may result in truncated bookmark names. To disable this, put the
168 following in your .emacs:
170 \(setq bookmark-bmenu-toggle-filenames nil\)")
173 (defvar bookmark-menu-length
70
174 "*Maximum length of a bookmark name displayed on a popup menu.")
177 ;;; No user-serviceable parts beyond this point.
179 ;; Added for lucid emacs compatibility, db
180 (or (fboundp 'defalias
) (fset 'defalias
'fset
))
182 ;; suggested for lucid compatibility by david hughes:
183 (or (fboundp 'frame-height
) (defalias 'frame-height
'screen-height
))
188 ;; some people have C-x r set to rmail or whatever. We don't want to
189 ;; assume that C-x r is a prefix map just because it's distributed
191 ;; These are the distribution keybindings suggested by RMS, everything
192 ;; else will be done with M-x or the menubar:
194 (if (symbolp (key-binding "\C-xr"))
196 (progn (define-key ctl-x-map
"rb" 'bookmark-jump
)
197 (define-key ctl-x-map
"rm" 'bookmark-set
)
198 (define-key ctl-x-map
"rl" 'bookmark-bmenu-list
)))
200 ;; define the map, so it can be bound by those who desire to do so:
203 (defvar bookmark-map nil
204 "Keymap containing bindings to bookmark functions.
205 It is not bound to any key by default: to bind it
206 so that you have a bookmark prefix, just use `global-set-key' and bind a
207 key of your choice to `bookmark-map'. All interactive bookmark
208 functions have a binding in this keymap.")
211 (define-prefix-command 'bookmark-map
)
213 ;; Read the help on all of these functions for details...
215 (define-key bookmark-map
"x" 'bookmark-set
)
217 (define-key bookmark-map
"m" 'bookmark-set
) ; "m" for "mark"
219 (define-key bookmark-map
"j" 'bookmark-jump
)
221 (define-key bookmark-map
"g" 'bookmark-jump
) ; "g" for "go"
223 (define-key bookmark-map
"i" 'bookmark-insert
)
225 (define-key bookmark-map
"e" 'edit-bookmarks
)
227 (define-key bookmark-map
"f" 'bookmark-insert-location
) ; "f" for "find"
229 (define-key bookmark-map
"r" 'bookmark-rename
)
231 (define-key bookmark-map
"d" 'bookmark-delete
)
233 (define-key bookmark-map
"l" 'bookmark-load
)
235 (define-key bookmark-map
"w" 'bookmark-write
)
237 (define-key bookmark-map
"s" 'bookmark-save
)
240 ;;; The annotation maps.
241 (defvar bookmark-read-annotation-mode-map
(copy-keymap text-mode-map
)
242 "Keymap for composing an annotation for a bookmark.")
244 (define-key bookmark-read-annotation-mode-map
"\C-c\C-c"
245 'bookmark-send-annotation
)
249 ;;; Core variables and data structures:
250 (defvar bookmark-alist
()
251 "Association list of bookmarks and their records.
252 You probably don't want to change the value of this alist yourself;
253 instead, let the various bookmark functions do it for you.
255 The format of the alist is
257 \(BOOKMARK1 BOOKMARK2 ...\)
259 where each BOOKMARK is of the form
263 \(front-context-string . FRONT-STR\)
264 \(rear-context-string . REAR-STR\)
267 \(annotation . ANNOTATION\)\)
269 So the cdr of each bookmark is an alist too.
270 `info-node' is optional, by the way.")
273 (defvar bookmarks-already-loaded nil
)
276 ;; just add the hook to make sure that people don't lose bookmarks
277 ;; when they kill Emacs, unless they don't want to save them.
279 (add-hook 'kill-emacs-hook
281 (lambda () (and (featurep 'bookmark
)
283 (bookmark-time-to-save-p t
)
286 ;; more stuff added by db.
288 (defvar bookmark-current-bookmark nil
289 "Name of bookmark most recently used in the current file.
290 It is buffer local, used to make moving a bookmark forward
291 through a file easier.")
293 (make-variable-buffer-local 'bookmark-current-bookmark
)
296 (defvar bookmark-alist-modification-count
0
297 "Number of modifications to bookmark list since it was last saved.")
300 (defvar bookmark-search-size
16
301 "Length of the context strings recorded on either side of a bookmark.")
304 (defvar bookmark-current-point
0)
305 (defvar bookmark-yank-point
0)
306 (defvar bookmark-current-buffer nil
)
312 ;; Only functions on this page and the next one (file formats) need to
313 ;; know anything about the format of bookmark-alist entries.
314 ;; Everyone else should go through them.
316 (defun bookmark-name-from-full-record (full-record)
317 "Return name of FULL-RECORD \(an alist element instead of a string\)."
321 (defun bookmark-all-names ()
322 "Return a list of all current bookmark names."
323 (bookmark-maybe-load-default-file)
325 (lambda (full-record)
326 (bookmark-name-from-full-record full-record
))
330 (defun bookmark-get-bookmark (bookmark)
331 "Return the full entry for BOOKMARK in bookmark-alist."
332 (assoc bookmark bookmark-alist
))
335 (defun bookmark-get-bookmark-record (bookmark)
336 "Return the guts of the entry for BOOKMARK in bookmark-alist.
337 That is, all information but the name."
338 (car (cdr (bookmark-get-bookmark bookmark
))))
341 (defun bookmark-set-name (bookmark newname
)
342 "Set BOOKMARK's name to NEWNAME."
343 (setcar (bookmark-get-bookmark bookmark
) newname
))
346 (defun bookmark-get-annotation (bookmark)
347 "Return the annotation of BOOKMARK, or nil if none."
348 (cdr (assq 'annotation
(bookmark-get-bookmark-record bookmark
))))
351 (defun bookmark-set-annotation (bookmark ann
)
352 "Set the annotation of BOOKMARK to ANN."
353 (let ((cell (assq 'annotation
(bookmark-get-bookmark-record bookmark
))))
356 (nconc (bookmark-get-bookmark-record bookmark
)
357 (list (cons 'annotation ann
))))))
360 (defun bookmark-get-filename (bookmark)
361 "Return the full filename of BOOKMARK."
362 (cdr (assq 'filename
(bookmark-get-bookmark-record bookmark
))))
365 (defun bookmark-set-filename (bookmark filename
)
366 "Set the full filename of BOOKMARK to FILENAME."
367 (let ((cell (assq 'filename
(bookmark-get-bookmark-record bookmark
))))
369 (setcdr cell filename
)
370 (nconc (bookmark-get-bookmark-record bookmark
)
371 (list (cons 'filename filename
))))))
374 (defun bookmark-get-position (bookmark)
375 "Return the position \(i.e.: point\) of BOOKMARK."
376 (cdr (assq 'position
(bookmark-get-bookmark-record bookmark
))))
379 (defun bookmark-set-position (bookmark position
)
380 "Set the position \(i.e.: point\) of BOOKMARK to POSITION."
381 (let ((cell (assq 'position
(bookmark-get-bookmark-record bookmark
))))
383 (setcdr cell position
)
384 (nconc (bookmark-get-bookmark-record bookmark
)
385 (list (cons 'position position
))))))
388 (defun bookmark-get-front-context-string (bookmark)
389 "Return the front-context-string of BOOKMARK."
390 (cdr (assq 'front-context-string
(bookmark-get-bookmark-record bookmark
))))
393 (defun bookmark-set-front-context-string (bookmark string
)
394 "Set the front-context-string of BOOKMARK to STRING."
395 (let ((cell (assq 'front-context-string
396 (bookmark-get-bookmark-record bookmark
))))
399 (nconc (bookmark-get-bookmark-record bookmark
)
400 (list (cons 'front-context-string string
))))))
403 (defun bookmark-get-rear-context-string (bookmark)
404 "Return the rear-context-string of BOOKMARK."
405 (cdr (assq 'rear-context-string
(bookmark-get-bookmark-record bookmark
))))
408 (defun bookmark-set-rear-context-string (bookmark string
)
409 "Set the rear-context-string of BOOKMARK to STRING."
410 (let ((cell (assq 'rear-context-string
411 (bookmark-get-bookmark-record bookmark
))))
414 (nconc (bookmark-get-bookmark-record bookmark
)
415 (list (cons 'rear-context-string string
))))))
418 (defun bookmark-get-info-node (bookmark)
419 "Get the info node associated with BOOKMARK."
420 (cdr (assq 'info-node
(bookmark-get-bookmark-record bookmark
))))
423 (defun bookmark-set-info-node (bookmark node
)
424 "Set the Info node of BOOKMARK to NODE."
425 (let ((cell (assq 'info-node
426 (bookmark-get-bookmark-record bookmark
))))
429 (nconc (bookmark-get-bookmark-record bookmark
)
430 (list (cons 'info-node node
))))))
433 (defvar bookmark-history nil
434 "The history list for bookmark functions.")
437 (defun bookmark-completing-read (prompt &optional default
)
438 "Prompting with PROMPT, read a bookmark name in completion.
439 PROMPT will get a \": \" stuck on the end no matter what, so you
440 probably don't want to include one yourself.
441 Optional second arg DEFAULT is a string to return if the user enters
443 (bookmark-maybe-load-default-file) ; paranoia
444 (let* ((completion-ignore-case bookmark-completion-ignore-case
)
447 (concat prompt
(format " (%s): " default
))
448 (concat prompt
": ")))
450 (completing-read prompt
456 (if (string-equal "" str
)
461 (defmacro bookmark-maybe-historicize-string
(string)
462 "Put STRING into the bookmark prompt history, if caller non-interactive.
463 We need this because sometimes bookmark functions are invoked from
464 menus, so `completing-read' never gets a chance to set `bookmark-history'."
467 (setq bookmark-history
(cons (, string
) bookmark-history
)))))
470 (defun bookmark-make (name &optional annotation overwrite
)
471 "Make a bookmark named NAME.
472 Optional second arg ANNOTATION gives it an annotation.
473 Optional third arg OVERWRITE means replace any existing bookmarks with
475 (bookmark-maybe-load-default-file)
476 (if (and (bookmark-get-bookmark name
) (not overwrite
))
477 ;; already existing boookmark under that name and
478 ;; no prefix arg means just overwrite old bookmark
479 (setcdr (bookmark-get-bookmark name
)
480 (list (bookmark-make-cell annotation
)))
482 ;; otherwise just cons it onto the front (either the bookmark
483 ;; doesn't exist already, or there is no prefix arg. In either
484 ;; case, we want the new bookmark consed onto the alist...)
489 (bookmark-make-cell annotation
))
493 (setq bookmark-current-bookmark name
)
494 (setq bookmark-alist-modification-count
495 (1+ bookmark-alist-modification-count
))
496 (if (bookmark-time-to-save-p)
500 (defun bookmark-make-cell (annotation)
501 "Return the record part of a new bookmark, given ANNOTATION.
502 Must be at the correct position in the buffer in which the bookmark is
503 being set. This will change soon."
504 (` ((filename .
(, (bookmark-buffer-file-name)))
505 (front-context-string
506 .
(, (if (>= (- (point-max) (point)) bookmark-search-size
)
507 ;; strip text props via `format':
511 (+ (point) bookmark-search-size
))))
512 (set-text-properties 0 (length string
) nil string
)
516 .
(, (if (>= (- (point) (point-min)) bookmark-search-size
)
517 ;; strip text props via `format':
521 (- (point) bookmark-search-size
))))
522 (set-text-properties 0 (length string
) nil string
)
525 (position .
(, (point)))
526 (annotation .
(, annotation
)))))
529 ;;; File format stuff
531 ;; The OLD format of the bookmark-alist was:
533 ;; ((bookmark-name (filename
539 ;; The NEW format of the bookmark-alist is:
541 ;; ((bookmark-name ((filename . FILENAME)
542 ;; (front-context-string . string-in-front)
543 ;; (rear-context-string . string-behind)
544 ;; (position . POINT)
545 ;; (annotation . annotation)
546 ;; (whatever . VALUE)
552 ;; I switched to using an internal as well as external alist because I
553 ;; felt that would be a more flexible framework in which to add
554 ;; features. It means that the order in which values appear doesn't
555 ;; matter, and it means that arbitrary values can be added without
556 ;; risk of interfering with existing ones.
558 ;; BOOKMARK-NAME is the string the user gives the bookmark and
559 ;; accesses it by from then on.
561 ;; FILENAME is the location of the file in which the bookmark is set.
563 ;; STRING-IN-FRONT is a string of `bookmark-search-size' chars of
564 ;; context in front of the point at which the bookmark is set.
566 ;; STRING-BEHIND is the same thing, but after the point.
568 ;; The context strings exist so that modifications to a file don't
569 ;; necessarily cause a bookmark's position to be invalidated.
570 ;; bookmark-jump will search for STRING-BEHIND and STRING-IN-FRONT in
571 ;; case the file has changed since the bookmark was set. It will
572 ;; attempt to place the user before the changes, if there were any.
573 ;; annotation is the annotation for the bookmark; it may not exist
574 ;; (for backward compatibility), be nil (no annotation), or be a
577 ;; ANNOTATION is an annotation for the bookmark.
580 (defconst bookmark-file-format-version
1
581 "The current version of the format used by bookmark files.
582 You should never need to change this.")
585 (defconst bookmark-end-of-version-stamp-marker
586 "-*- End Of Bookmark File Format Version Stamp -*-\n"
587 "This string marks the end of the version stamp in a bookmark file.")
590 (defun bookmark-alist-from-buffer ()
591 "Return a bookmark-alist (in any format) from the current buffer.
592 The buffer must of course contain bookmark format information.
593 Does not care from where in the buffer it is called, and does not
596 (goto-char (point-min))
597 (if (search-forward bookmark-end-of-version-stamp-marker nil t
)
598 (read (current-buffer))
599 ;; Else we're dealing with format version 0
600 (if (search-forward "(" nil t
)
603 (read (current-buffer)))
604 ;; Else no hope of getting information here.
605 (error "Not bookmark format.")))))
608 (defun bookmark-upgrade-version-0-alist (old-list)
609 "Upgrade a version 0 alist OLD-LIST to the current version."
612 (let* ((name (car bookmark
))
613 (record (car (cdr bookmark
)))
614 (filename (nth 0 record
))
615 (front-str (nth 1 record
))
616 (rear-str (nth 2 record
))
617 (position (nth 3 record
))
618 (ann (nth 4 record
)))
621 (` ((filename .
(, filename
))
622 (front-context-string .
(, (or front-str
"")))
623 (rear-context-string .
(, (or rear-str
"")))
624 (position .
(, position
))
625 (annotation .
(, ann
)))))))
629 (defun bookmark-upgrade-file-format-from-0 ()
630 "Upgrade a bookmark file of format 0 (the original format) to format 1.
631 This expects to be called from point-min in a bookmark file."
632 (message "Upgrading bookmark format from 0 to %d..."
633 bookmark-file-format-version
)
634 (let* ((old-list (bookmark-alist-from-buffer))
635 (new-list (bookmark-upgrade-version-0-alist old-list
)))
636 (delete-region (point-min) (point-max))
637 (bookmark-insert-file-format-version-stamp)
638 (pp new-list
(current-buffer))
640 (goto-char (point-min))
641 (message "Upgrading bookmark format from 0 to %d... done."
642 bookmark-file-format-version
)
646 (defun bookmark-grok-file-format-version ()
647 "Return an integer which is the file-format version of this bookmark file.
648 This expects to be called from point-min in a bookmark file."
649 (if (looking-at "^;;;;")
652 (re-search-forward "[0-9]")
654 (read (current-buffer))))
655 ;; Else this is format version 0, the original one, which didn't
656 ;; even have version stamps.
660 (defun bookmark-maybe-upgrade-file-format ()
661 "Check the file-format version of this bookmark file.
662 If the version is not up-to-date, upgrade it automatically.
663 This expects to be called from point-min in a bookmark file."
664 (let ((version (bookmark-grok-file-format-version)))
666 ((= version bookmark-file-format-version
)
667 ) ; home free -- version is current
669 (bookmark-upgrade-file-format-from-0))
671 (error "Bookmark file format version strangeness.")))))
674 (defun bookmark-insert-file-format-version-stamp ()
675 "Insert text indicating current version of bookmark file-format."
677 (format ";;;; Emacs Bookmark Format Version %d ;;;;\n"
678 bookmark-file-format-version
))
679 (insert ";;; This format is meant to be slightly human-readable;\n"
680 ";;; nevertheless, you probably don't want to edit it.\n"
682 bookmark-end-of-version-stamp-marker
))
685 ;;; end file-format stuff
691 (defun bookmark-set (&optional name parg
)
692 "Set a bookmark named NAME inside a file.
693 If name is nil, then the user will be prompted.
694 With prefix arg, will not overwrite a bookmark that has the same name
695 as NAME if such a bookmark already exists, but instead will \"push\"
696 the new bookmark onto the bookmark alist. Thus the most recently set
697 bookmark with name NAME would be the one in effect at any given time,
698 but the others are still there, should you decide to delete the most
701 To yank words from the text of the buffer and use them as part of the
702 bookmark name, type C-w while setting a bookmark. Successive C-w's
703 yank successive words.
705 Typing C-u inserts the name of the last bookmark used in the buffer
706 \(as an aid in using a single bookmark name to track your progress
707 through a large file\). If no bookmark was used, then C-u inserts the
708 name of the file being visited.
710 Use \\[bookmark-delete] to remove bookmarks \(you give it a name,
711 and it removes only the first instance of a bookmark with that name from
712 the list of bookmarks.\)"
713 (interactive (list nil current-prefix-arg
))
715 (bookmark-buffer-file-name)
716 (error "Buffer not visiting a file or directory."))
718 (bookmark-maybe-load-default-file)
720 (setq bookmark-current-point
(point))
721 (setq bookmark-yank-point
(point))
722 (setq bookmark-current-buffer
(current-buffer))
724 (let* ((default (or bookmark-current-bookmark
725 (bookmark-buffer-name)))
728 (read-from-minibuffer
729 (format "Set bookmark (%s): " default
)
731 (let ((now-map (copy-keymap minibuffer-local-map
)))
732 (progn (define-key now-map
"\C-w"
734 (define-key now-map
"\C-u"
735 'bookmark-insert-current-bookmark
))
738 (and (string-equal str
"") (setq str default
))
739 ;; Ask for an annotation buffer for this bookmark
740 (if bookmark-use-annotations
741 (bookmark-read-annotation parg str
)
743 (bookmark-make str annotation parg
)
744 ;; In Info, there's a little more information to record:
745 (if (eq major-mode
'Info-mode
)
746 (bookmark-set-info-node str Info-current-node
))
747 (setq bookmark-current-bookmark str
)
748 (bookmark-bmenu-surreptitiously-rebuild-list)
749 (goto-char bookmark-current-point
)))))
752 (defun bookmark-kill-line (&optional newline-too
)
753 "Kill from point to end of line.
754 If optional arg NEWLINE-TOO is non-nil, delete the newline too.
755 Does not affect the kill-ring."
756 (let ((eol (save-excursion (end-of-line) (point))))
757 (delete-region (point) eol
)
758 (if (and newline-too
(looking-at "\n"))
762 ;; Defvars to avoid compilation warnings:
763 (defvar bookmark-annotation-paragraph nil
)
764 (defvar bookmark-annotation-name nil
)
765 (defvar bookmark-annotation-buffer nil
)
766 (defvar bookmark-annotation-file nil
)
767 (defvar bookmark-annotation-point nil
)
770 (defun bookmark-send-annotation ()
771 "After remove lines beginning with '#', use the contents of this buffer
772 as the annotation for a bookmark, and store it in the bookmark list with
773 the bookmark (and file, and point) specified in buffer local variables."
775 (if (not (eq major-mode
'bookmark-read-annotation-mode
))
776 (error "Not in bookmark-read-annotation-mode."))
777 (goto-char (point-min))
778 (while (< (point) (point-max))
779 (if (looking-at "^#")
780 (bookmark-kill-line t
)
782 (let ((annotation (buffer-substring (point-min) (point-max)))
783 (parg bookmark-annotation-paragraph
)
784 (bookmark bookmark-annotation-name
)
785 (pt bookmark-annotation-point
)
786 (buf bookmark-annotation-buffer
))
787 ;; for bookmark-make-cell to work, we need to be
788 ;; in the relevant buffer, at the relevant point.
789 ;; Actually, bookmark-make-cell should probably be re-written,
790 ;; to avoid this need. Should I handle the error if a buffer is
791 ;; killed between "C-x r m" and a "C-c C-c" in the annotation buffer?
795 (bookmark-make bookmark annotation parg
)
796 (setq bookmark-current-bookmark bookmark
))
797 (bookmark-bmenu-surreptitiously-rebuild-list)
798 (goto-char bookmark-current-point
))
799 (kill-buffer (current-buffer)))
802 (defun bookmark-default-annotation-text (bookmark)
803 (concat "# Type the annotation for bookmark '" bookmark
"' here.\n"
804 "# All lines which start with a '#' will be deleted.\n"
805 "# Type C-c C-c when done.\n#\n"
806 "# Author: " (user-full-name) " <" (user-login-name) "@"
808 "# Date: " (current-time-string) "\n"))
811 (defvar bookmark-read-annotation-text-func
'bookmark-default-annotation-text
812 "A variable containing a function which returns the text to insert
813 into an annotation compisition buffer. It takes the name of the bookmark,
814 as a string, as an arg.")
817 (defun bookmark-read-annotation-mode (buf point parg bookmark
)
818 "Mode for composing annotations for a bookmark.
819 Wants BUF POINT PARG and BOOKMARK.
820 When you have finished composing, type \\[bookmark-send-annotation] to send
823 \\{bookmark-read-annotation-mode-map}
826 (kill-all-local-variables)
827 (make-local-variable 'bookmark-annotation-paragraph
)
828 (make-local-variable 'bookmark-annotation-name
)
829 (make-local-variable 'bookmark-annotation-buffer
)
830 (make-local-variable 'bookmark-annotation-file
)
831 (make-local-variable 'bookmark-annotation-point
)
832 (setq bookmark-annotation-paragraph parg
)
833 (setq bookmark-annotation-name bookmark
)
834 (setq bookmark-annotation-buffer buf
)
835 (setq bookmark-annotation-file
(buffer-file-name buf
))
836 (setq bookmark-annotation-point point
)
837 (use-local-map bookmark-read-annotation-mode-map
)
838 (setq major-mode
'bookmark-read-annotation-mode
)
839 (insert (funcall bookmark-read-annotation-text-func bookmark
))
840 (run-hooks 'text-mode-hook
))
843 (defun bookmark-read-annotation (parg bookmark
)
844 "Pop up a buffer for entering a bookmark annotation. Text surrounding
845 the bookmark is PARG; the bookmark name is BOOKMARK."
846 (let ((buf (current-buffer))
848 (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
849 (bookmark-read-annotation-mode buf point parg bookmark
)))
852 (defvar bookmark-edit-annotation-mode-map
(copy-keymap text-mode-map
)
853 "Keymap for editing an annotation of a bookmark.")
856 (define-key bookmark-edit-annotation-mode-map
"\C-c\C-c"
857 'bookmark-send-edited-annotation
)
860 (defun bookmark-edit-annotation-mode (bookmark)
861 "Mode for editing the annotation of bookmark BOOKMARK.
862 When you have finished composing, type \\[bookmark-send-annotation].
864 \\{bookmark-edit-annotation-mode-map}
867 (kill-all-local-variables)
868 (make-local-variable 'bookmark-annotation-name
)
869 (setq bookmark-annotation-name bookmark
)
870 (use-local-map bookmark-edit-annotation-mode-map
)
871 (setq major-mode
'bookmark-edit-annotation-mode
)
872 (insert (funcall bookmark-read-annotation-text-func bookmark
))
873 (let ((annotation (bookmark-get-annotation bookmark
)))
874 (if (and (not (eq annotation nil
))
875 (not (string-equal annotation
"")))
876 (insert annotation
)))
877 (run-hooks 'text-mode-hook
))
880 (defun bookmark-send-edited-annotation ()
881 "After remove lines beginning with '#', use the contents of this buffer
882 as the new annotation for a bookmark."
884 (if (not (eq major-mode
'bookmark-edit-annotation-mode
))
885 (error "Not in bookmark-edit-annotation-mode."))
886 (goto-char (point-min))
887 (while (< (point) (point-max))
888 (if (looking-at "^#")
889 (bookmark-kill-line t
)
891 (let ((annotation (buffer-substring (point-min) (point-max)))
892 (bookmark bookmark-annotation-name
))
893 (bookmark-set-annotation bookmark annotation
)
894 (bookmark-bmenu-surreptitiously-rebuild-list)
895 (goto-char bookmark-current-point
))
896 (kill-buffer (current-buffer)))
899 (defun bookmark-edit-annotation (bookmark)
900 "Pop up a buffer for editing bookmark BOOKMARK's annotation."
901 (let ((buf (current-buffer))
903 (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
904 (bookmark-edit-annotation-mode bookmark
)))
907 (defun bookmark-insert-current-bookmark ()
908 "Insert this buffer's value of bookmark-current-bookmark, default
909 to file name if it's nil."
913 (set-buffer bookmark-current-buffer
)
914 bookmark-current-bookmark
)))
915 (if str
(insert str
) (bookmark-insert-buffer-name))))
918 (defun bookmark-insert-buffer-name ()
919 "Insert the name (sans path) of the current file into the bookmark
920 name that is being set."
924 (set-buffer bookmark-current-buffer
)
925 (bookmark-buffer-name))))
929 (defun bookmark-buffer-name ()
930 "Return the name of the current buffer's file, non-directory.
931 In Info, return the current node."
934 ((string-equal mode-name
"Info") Info-current-node
)
936 (buffer-file-name (file-name-nondirectory buffer-file-name
))
937 ;; Or are we a directory?
938 ((and (boundp 'dired-directory
) dired-directory
)
939 (let* ((dirname (if (stringp dired-directory
)
941 (car dired-directory
)))
942 (idx (1- (length dirname
))))
943 ;; Strip the trailing slash.
944 (if (= ?
/ (aref dirname idx
))
945 (file-name-nondirectory (substring dirname
0 idx
))
946 ;; Else return the current-buffer
947 (buffer-name (current-buffer)))))
948 ;; If all else fails, use the buffer's name.
950 (buffer-name (current-buffer)))))
953 (defun bookmark-yank-word ()
955 ;; get the next word from the buffer and append it to the name of
956 ;; the bookmark currently being set.
957 (let ((string (save-excursion
958 (set-buffer bookmark-current-buffer
)
959 (goto-char bookmark-yank-point
)
964 (setq bookmark-yank-point
(point)))))))
968 (defun bookmark-buffer-file-name ()
969 "Return the current buffer's file in a way useful for bookmarks.
970 For example, if this is a Info buffer, return the Info file's name."
971 (if (eq major-mode
'Info-mode
)
975 (if (and (boundp 'dired-directory
) dired-directory
)
976 (if (stringp dired-directory
)
978 (car dired-directory
))))))
981 (defun bookmark-maybe-load-default-file ()
982 (and (not bookmarks-already-loaded
)
983 (null bookmark-alist
)
987 ;; Possibly the old bookmark file, "~/.emacs-bkmrks", needs
989 (file-exists-p (expand-file-name bookmark-old-default-file
))
990 (not (file-exists-p (expand-file-name bookmark-default-file
)))
991 (rename-file (expand-file-name bookmark-old-default-file
)
992 (expand-file-name bookmark-default-file
)))
993 ;; return t so the `and' will continue...
996 (file-readable-p (expand-file-name bookmark-default-file
))
998 (bookmark-load bookmark-default-file t t
)
999 (setq bookmarks-already-loaded t
))))
1002 (defun bookmark-maybe-sort-alist ()
1003 ;;Return the bookmark-alist for display. If the bookmark-sort-flag
1004 ;;is non-nil, then return a sorted copy of the alist.
1005 (if bookmark-sort-flag
1006 (setq bookmark-alist
1007 (sort (copy-alist bookmark-alist
)
1009 (lambda (x y
) (string-lessp (car x
) (car y
))))))))
1013 (defun bookmark-jump (bookmark)
1014 "Jump to bookmark BOOKMARK (a point in some file).
1015 You may have a problem using this function if the value of variable
1016 `bookmark-alist' is nil. If that happens, you need to load in some
1017 bookmarks. See help on function `bookmark-load' for more about
1020 If the file pointed to by BOOKMARK no longer exists, you will be asked
1021 if you wish to give the bookmark a new location, and bookmark-jump
1022 will then jump to the new location, as well as recording it in place
1023 of the old one in the permanent bookmark record."
1025 (bookmark-completing-read "Jump to bookmark" bookmark-current-bookmark
))
1026 (bookmark-maybe-historicize-string bookmark
)
1027 (let ((cell (bookmark-jump-noselect bookmark
)))
1029 (switch-to-buffer (car cell
))
1030 (goto-char (cdr cell
))
1031 (if bookmark-automatically-show-annotations
1032 ;; if there is an annotation for this bookmark,
1033 ;; show it in a buffer.
1034 (bookmark-show-annotation bookmark
)))))
1037 (defun bookmark-jump-noselect (str)
1038 ;; a leetle helper for bookmark-jump :-)
1039 ;; returns (BUFFER . POINT)
1040 (bookmark-maybe-load-default-file)
1041 (let* ((file (expand-file-name (bookmark-get-filename str
)))
1042 (forward-str (bookmark-get-front-context-string str
))
1043 (behind-str (bookmark-get-rear-context-string str
))
1044 (place (bookmark-get-position str
))
1045 (info-node (bookmark-get-info-node str
))
1049 (file-exists-p file
)
1050 ;; else try some common compression extensions
1051 ;; and Emacs better handle it right!
1052 ;; Sigh: I think it may *not* be handled at the moment. What
1053 ;; to do about this?
1056 (let ((altname (concat file
".Z")))
1057 (and (file-exists-p altname
)
1059 (let ((altname (concat file
".gz")))
1060 (and (file-exists-p altname
)
1062 (let ((altname (concat file
".z")))
1063 (and (file-exists-p altname
)
1067 ;; Info nodes must be visited with care.
1070 (Info-find-node file info-node
))
1071 ;; Else no Info. Can do an ordinary find-file:
1072 (set-buffer (find-file-noselect file
))
1075 ;; Go searching forward first. Then, if forward-str exists and
1076 ;; was found in the file, we can search backward for behind-str.
1077 ;; Rationale is that if text was inserted between the two in the
1078 ;; file, it's better to be put before it so you can read it,
1079 ;; rather than after and remain perhaps unaware of the changes.
1081 (if (search-forward forward-str
(point-max) t
)
1082 (backward-char (length forward-str
))))
1084 (if (search-backward behind-str
(point-min) t
)
1085 (forward-char (length behind-str
))))
1087 (setq bookmark-current-bookmark str
)
1088 (cons (current-buffer) (point)))
1091 (if (y-or-n-p (concat (file-name-nondirectory orig-file
)
1092 " nonexistent. Relocate \""
1096 (bookmark-relocate str
)
1097 ;; gasp! It's a recursive function call in Emacs Lisp!
1098 (bookmark-jump-noselect str
))
1100 "Bookmark not relocated; consider removing it \(%s\)." str
)
1105 (defun bookmark-relocate (bookmark)
1106 "Relocate BOOKMARK -- prompts for a filename, and makes an already
1107 existing bookmark point to that file, instead of the one it used to
1108 point at. Useful when a file has been renamed after a bookmark was
1110 (interactive (bookmark-completing-read "Bookmark to relocate"))
1111 (bookmark-maybe-historicize-string bookmark
)
1112 (bookmark-maybe-load-default-file)
1113 (let* ((bmrk-filename (bookmark-get-filename bookmark
))
1114 (newloc (expand-file-name
1116 (format "Relocate %s to: " bookmark
)
1117 (file-name-directory bmrk-filename
)))))
1118 (bookmark-set-filename bookmark newloc
)))
1122 (defun bookmark-insert-location (bookmark &optional no-history
)
1123 "Insert the name of the file associated with BOOKMARK.
1124 Optional second arg NO-HISTORY means don't record this in the
1125 minibuffer history list `bookmark-history'."
1126 (interactive (bookmark-completing-read "Insert bookmark location"))
1127 (or no-history
(bookmark-maybe-historicize-string bookmark
))
1128 (insert (bookmark-location bookmark
)))
1131 (defun bookmark-location (bookmark)
1132 "Return the name of the file associated with BOOKMARK."
1133 (bookmark-maybe-load-default-file)
1134 (bookmark-get-filename bookmark
))
1138 (defun bookmark-rename (old &optional new
)
1139 "Change the name of OLD bookmark to NEW name. If called from
1140 keyboard, prompts for OLD and NEW. If called from menubar, OLD is
1141 selected from a menu, and prompts for NEW.
1143 If called from Lisp, prompts for NEW if only OLD was passed as an
1144 argument. If called with two strings, then no prompting is done. You
1145 must pass at least OLD when calling from Lisp.
1147 While you are entering the new name, consecutive C-w's insert
1148 consectutive words from the text of the buffer into the new bookmark
1150 (interactive (bookmark-completing-read "Old bookmark name"))
1151 (bookmark-maybe-historicize-string old
)
1152 (bookmark-maybe-load-default-file)
1154 (setq bookmark-current-point
(point))
1155 (setq bookmark-yank-point
(point))
1156 (setq bookmark-current-buffer
(current-buffer))
1158 (or new
; use second arg, if non-nil
1159 (read-from-minibuffer
1162 (let ((now-map (copy-keymap minibuffer-local-map
)))
1163 (define-key now-map
"\C-w" 'bookmark-yank-word
)
1166 'bookmark-history
))))
1168 (bookmark-set-name old newname
)
1169 (setq bookmark-current-bookmark newname
)
1170 (bookmark-bmenu-surreptitiously-rebuild-list)
1171 (setq bookmark-alist-modification-count
1172 (1+ bookmark-alist-modification-count
))
1173 (if (bookmark-time-to-save-p)
1174 (bookmark-save))))))
1178 (defun bookmark-insert (bookmark)
1179 "Insert the text of the file pointed to by bookmark BOOKMARK.
1180 You may have a problem using this function if the value of variable
1181 `bookmark-alist' is nil. If that happens, you need to load in some
1182 bookmarks. See help on function `bookmark-load' for more about
1184 (interactive (bookmark-completing-read "Insert bookmark contents"))
1185 (bookmark-maybe-historicize-string bookmark
)
1186 (bookmark-maybe-load-default-file)
1187 (let ((orig-point (point))
1190 (set-buffer (car (bookmark-jump-noselect bookmark
)))
1191 (buffer-substring (point-min) (point-max)))))
1192 (insert str-to-insert
)
1194 (goto-char orig-point
)))
1198 (defun bookmark-delete (bookmark &optional batch
)
1199 "Delete BOOKMARK from the bookmark list.
1200 Removes only the first instance of a bookmark with that name. If
1201 there are one or more other bookmarks with the same name, they will
1202 not be deleted. Defaults to the \"current\" bookmark \(that is, the
1203 one most recently used in this file, if any\).
1204 Optional second arg BATCH means don't update the bookmark list buffer,
1205 probably because we were called from there."
1207 (bookmark-completing-read "Delete bookmark" bookmark-current-bookmark
))
1208 (bookmark-maybe-historicize-string bookmark
)
1209 (bookmark-maybe-load-default-file)
1210 (let ((will-go (bookmark-get-bookmark bookmark
)))
1211 (setq bookmark-alist
(delq will-go bookmark-alist
))
1212 ;; Added by db, nil bookmark-current-bookmark if the last
1213 ;; occurence has been deleted
1214 (or (bookmark-get-bookmark bookmark-current-bookmark
)
1215 (setq bookmark-current-bookmark nil
)))
1216 ;; Don't rebuild the list
1219 (bookmark-bmenu-surreptitiously-rebuild-list)
1220 (setq bookmark-alist-modification-count
1221 (1+ bookmark-alist-modification-count
))
1222 (if (bookmark-time-to-save-p)
1226 (defun bookmark-time-to-save-p (&optional last-time
)
1227 ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu>
1228 ;; finds out whether it's time to save bookmarks to a file, by
1229 ;; examining the value of variable bookmark-save-flag, and maybe
1230 ;; bookmark-alist-modification-count. Returns t if they should be
1231 ;; saved, nil otherwise. if last-time is non-nil, then this is
1232 ;; being called when emacs is killed.
1234 (and (> bookmark-alist-modification-count
0)
1235 bookmark-save-flag
))
1236 ((numberp bookmark-save-flag
)
1237 (>= bookmark-alist-modification-count bookmark-save-flag
))
1243 (defun bookmark-write ()
1244 "Write bookmarks to a file \(for which the user will be prompted
1245 interactively\). Don't use this in Lisp programs; use bookmark-save
1248 (bookmark-maybe-load-default-file)
1253 (defun bookmark-save (&optional parg file
)
1254 "Save currently defined bookmarks.
1255 Saves by default in the file defined by the variable
1256 `bookmark-default-file'. With a prefix arg, save it in file FILE
1257 \(second argument\).
1259 If you are calling this from Lisp, the two arguments are PREFIX-ARG
1260 and FILE, and if you just want it to write to the default file, then
1261 pass no arguments. Or pass in nil and FILE, and it will save in FILE
1262 instead. If you pass in one argument, and it is non-nil, then the
1263 user will be interactively queried for a file to save in.
1265 When you want to load in the bookmarks from a file, use
1266 \`bookmark-load\', \\[bookmark-load]. That function will prompt you
1267 for a file, defaulting to the file defined by variable
1268 `bookmark-default-file'."
1270 (bookmark-maybe-load-default-file)
1272 ((and (null parg
) (null file
))
1273 ;;whether interactive or not, write to default file
1274 (bookmark-write-file bookmark-default-file
))
1275 ((and (null parg
) file
)
1276 ;;whether interactive or not, write to given file
1277 (bookmark-write-file file
))
1278 ((and parg
(not file
))
1279 ;;have been called interactively w/ prefix arg
1280 (let ((file (read-file-name "File to save bookmarks in: ")))
1281 (bookmark-write-file file
)))
1282 (t ; someone called us with prefix-arg *and* a file, so just write to file
1283 (bookmark-write-file file
)))
1284 ;; signal that we have synced the bookmark file by setting this to
1285 ;; 0. If there was an error at any point before, it will not get
1286 ;; set, which is what we want.
1287 (setq bookmark-alist-modification-count
0))
1291 (defun bookmark-write-file (file)
1293 (save-window-excursion
1294 (if (>= baud-rate
9600)
1295 (message (format "Saving bookmarks to file %s..." file
)))
1296 (set-buffer (let ((enable-local-variables nil
))
1297 (find-file-noselect file
)))
1298 (goto-char (point-min))
1299 (delete-region (point-min) (point-max))
1300 (bookmark-insert-file-format-version-stamp)
1301 (pp bookmark-alist
(current-buffer))
1302 (let ((version-control
1304 ((null bookmark-version-control
) nil
)
1305 ((eq 'never bookmark-version-control
) 'never
)
1306 ((eq 'nospecial bookmark-version-control
) version-control
)
1310 (kill-buffer (current-buffer))
1311 (if (>= baud-rate
9600)
1312 (message (format "Saving bookmarks to file %s... done." file
)))
1317 (defun bookmark-load (file &optional revert no-msg
)
1318 "Load bookmarks from FILE (which must be in bookmark format).
1319 Appends loaded bookmarks to the front of the list of bookmarks. If
1320 optional second argument REVERT is non-nil, existing bookmarks are
1321 destroyed. Optional third arg NO-MSG means don't display any messages
1324 If you load a file that doesn't contain a proper bookmark alist, you
1325 will corrupt Emacs's bookmark list. Generally, you should only load
1326 in files that were created with the bookmark functions in the first
1327 place. Your own personal bookmark file, `~/.emacs.bmk', is
1328 maintained automatically by Emacs; you shouldn't need to load it
1331 (list (read-file-name
1332 (format "Load bookmarks from: (%s) "
1333 bookmark-default-file
)
1334 ;;Default might not be used often,
1335 ;;but there's no better default, and
1336 ;;I guess it's better than none at all.
1337 "~/" bookmark-default-file
'confirm
)))
1338 (setq file
(expand-file-name file
))
1339 (if (file-readable-p file
)
1341 (save-window-excursion
1342 (if (and (null no-msg
) (>= baud-rate
9600))
1343 (message (format "Loading bookmarks from %s..." file
)))
1344 (set-buffer (let ((enable-local-variables nil
))
1345 (find-file-noselect file
)))
1346 (goto-char (point-min))
1347 (bookmark-maybe-upgrade-file-format)
1348 (let ((blist (bookmark-alist-from-buffer)))
1352 (setq bookmark-alist-modification-count
1353 (1+ bookmark-alist-modification-count
))
1354 (setq bookmark-alist-modification-count
0))
1355 (setq bookmark-alist
1356 (append blist
(if (not revert
) bookmark-alist
)))
1357 (bookmark-bmenu-surreptitiously-rebuild-list))
1358 (error (format "Invalid bookmark list in %s." file
))))
1359 (kill-buffer (current-buffer)))
1360 (if (and (null no-msg
) (>= baud-rate
9600))
1361 (message (format "Loading bookmarks from %s... done" file
))))
1362 (error (format "Cannot read bookmark file %s." file
))))
1366 ;;; Code supporting the dired-like bookmark menu. Prefix is
1367 ;;; "bookmark-bmenu" for "buffer-menu":
1370 (defvar bookmark-bmenu-bookmark-column nil
)
1373 (defvar bookmark-bmenu-hidden-bookmarks
())
1376 (defvar bookmark-bmenu-mode-map nil
)
1379 (if bookmark-bmenu-mode-map
1381 (setq bookmark-bmenu-mode-map
(make-keymap))
1382 (suppress-keymap bookmark-bmenu-mode-map t
)
1383 (define-key bookmark-bmenu-mode-map
"q" 'bookmark-bmenu-quit
)
1384 (define-key bookmark-bmenu-mode-map
"v" 'bookmark-bmenu-select
)
1385 (define-key bookmark-bmenu-mode-map
"w" 'bookmark-bmenu-locate
)
1386 (define-key bookmark-bmenu-mode-map
"2" 'bookmark-bmenu-2-window
)
1387 (define-key bookmark-bmenu-mode-map
"1" 'bookmark-bmenu-1-window
)
1388 (define-key bookmark-bmenu-mode-map
"j" 'bookmark-bmenu-this-window
)
1389 (define-key bookmark-bmenu-mode-map
"f" 'bookmark-bmenu-this-window
)
1390 (define-key bookmark-bmenu-mode-map
"o" 'bookmark-bmenu-other-window
)
1391 (define-key bookmark-bmenu-mode-map
"\C-o" 'bookmark-bmenu-switch-other-window
)
1392 (define-key bookmark-bmenu-mode-map
"s" 'bookmark-bmenu-save
)
1393 (define-key bookmark-bmenu-mode-map
"k" 'bookmark-bmenu-delete
)
1394 (define-key bookmark-bmenu-mode-map
"\C-d" 'bookmark-bmenu-delete-backwards
)
1395 (define-key bookmark-bmenu-mode-map
"x" 'bookmark-bmenu-execute-deletions
)
1396 (define-key bookmark-bmenu-mode-map
"\C-k" 'bookmark-bmenu-delete
)
1397 (define-key bookmark-bmenu-mode-map
"d" 'bookmark-bmenu-delete
)
1398 (define-key bookmark-bmenu-mode-map
" " 'next-line
)
1399 (define-key bookmark-bmenu-mode-map
"n" 'next-line
)
1400 (define-key bookmark-bmenu-mode-map
"p" 'previous-line
)
1401 (define-key bookmark-bmenu-mode-map
"\177" 'bookmark-bmenu-backup-unmark
)
1402 (define-key bookmark-bmenu-mode-map
"?" 'describe-mode
)
1403 (define-key bookmark-bmenu-mode-map
"u" 'bookmark-bmenu-unmark
)
1404 (define-key bookmark-bmenu-mode-map
"m" 'bookmark-bmenu-mark
)
1405 (define-key bookmark-bmenu-mode-map
"l" 'bookmark-bmenu-load
)
1406 (define-key bookmark-bmenu-mode-map
"r" 'bookmark-bmenu-rename
)
1407 (define-key bookmark-bmenu-mode-map
"t" 'bookmark-bmenu-toggle-filenames
)
1408 (define-key bookmark-bmenu-mode-map
"a" 'bookmark-bmenu-show-annotation
)
1409 (define-key bookmark-bmenu-mode-map
"A" 'bookmark-bmenu-show-all-annotations
)
1410 (define-key bookmark-bmenu-mode-map
"e" 'bookmark-bmenu-edit-annotation
))
1414 ;; Bookmark Buffer Menu mode is suitable only for specially formatted
1416 (put 'bookmark-bmenu-mode
'mode-class
'special
)
1419 ;; todo: need to display whether or not bookmark exists as a buffer in
1423 ;; FLAGS BOOKMARK [ LOCATION ]
1426 (defun bookmark-bmenu-surreptitiously-rebuild-list ()
1427 "Rebuild the Bookmark List if it exists.
1428 Don't affect the buffer ring order."
1429 (if (get-buffer "*Bookmark List*")
1431 (save-window-excursion
1432 (bookmark-bmenu-list)))))
1436 (defun bookmark-bmenu-list ()
1437 "Display a list of existing bookmarks.
1438 The list is displayed in a buffer named `*Bookmark List*'.
1439 The leftmost column displays a D if the bookmark is flagged for
1440 deletion, or > if it is flagged for displaying."
1442 (bookmark-maybe-load-default-file)
1444 (switch-to-buffer (get-buffer-create "*Bookmark List*"))
1445 (set-buffer (get-buffer-create "*Bookmark List*")))
1446 (let ((buffer-read-only nil
))
1447 (delete-region (point-max) (point-min))
1448 (goto-char (point-min)) ;sure are playing it safe...
1449 (insert "% Bookmark\n- --------\n")
1450 (bookmark-maybe-sort-alist)
1452 (lambda (full-record)
1453 ;; if a bookmark has an annotation, preceed it with a "*"
1454 ;; in the list of bookmarks.
1455 (let ((annotation (bookmark-get-annotation
1456 (bookmark-name-from-full-record full-record
))))
1457 (if (and (not (eq annotation nil
))
1458 (not (string-equal annotation
"")))
1461 (insert (concat (bookmark-name-from-full-record full-record
) "\n"))))
1463 (goto-char (point-min))
1465 (bookmark-bmenu-mode)
1466 (if bookmark-bmenu-toggle-filenames
1467 (bookmark-bmenu-toggle-filenames t
)))
1470 (defalias 'list-bookmarks
'bookmark-bmenu-list
)
1472 (defalias 'edit-bookmarks
'bookmark-bmenu-list
)
1476 (defun bookmark-bmenu-mode ()
1477 "Major mode for editing a list of bookmarks.
1478 Each line describes one of the bookmarks in Emacs.
1479 Letters do not insert themselves; instead, they are commands.
1480 Bookmark names preceeded by a \"*\" have annotations.
1481 \\<bookmark-bmenu-mode-map>
1482 \\[bookmark-bmenu-mark] -- mark bookmark to be displayed.
1483 \\[bookmark-bmenu-select] -- select bookmark of line point is on.
1484 Also show bookmarks marked using m in other windows.
1485 \\[bookmark-bmenu-toggle-filenames] -- toggle displaying of filenames (they may obscure long bookmark names).
1486 \\[bookmark-bmenu-locate] -- display (in minibuffer) location of this bookmark.
1487 \\[bookmark-bmenu-1-window] -- select this bookmark in full-frame window.
1488 \\[bookmark-bmenu-2-window] -- select this bookmark in one window,
1489 together with bookmark selected before this one in another window.
1490 \\[bookmark-bmenu-this-window] -- select this bookmark in place of the bookmark menu buffer.
1491 \\[bookmark-bmenu-other-window] -- select this bookmark in another window,
1492 so the bookmark menu bookmark remains visible in its window.
1493 \\[bookmark-bmenu-switch-other-window] -- switch the other window to this bookmark.
1494 \\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).
1495 \\[bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
1496 \\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
1497 \\[bookmark-bmenu-execute-deletions] -- delete marked bookmarks.
1498 \\[bookmark-bmenu-save] -- save the current bookmark list in the default file.
1499 With a prefix arg, prompts for a file to save in.
1500 \\[bookmark-bmenu-load] -- load in a file of bookmarks (prompts for file.)
1501 \\[bookmark-bmenu-unmark] -- remove all kinds of marks from current line.
1502 With prefix argument, also move up one line.
1503 \\[bookmark-bmenu-backup-unmark] -- back up a line and remove marks.
1504 \\[bookmark-bmenu-show-annotation] -- show the annotation, if it exists, for the current bookmark
1506 \\[bookmark-bmenu-show-all-annotations] -- show the annotations of all bookmarks in another buffer.
1507 \\[bookmark-bmenu-edit-annotation] -- edit the annotation for the current bookmark."
1508 (kill-all-local-variables)
1509 (use-local-map bookmark-bmenu-mode-map
)
1510 (setq truncate-lines t
)
1511 (setq buffer-read-only t
)
1512 (setq major-mode
'bookmark-bmenu-mode
)
1513 (setq mode-name
"Bookmark Menu")
1514 (run-hooks 'bookmark-bmenu-mode-hook
))
1517 (defun bookmark-bmenu-toggle-filenames (&optional show
)
1518 "Toggle whether filenames are shown in the bookmark list.
1519 Optional argument SHOW means show them unconditionally."
1523 (setq bookmark-bmenu-toggle-filenames nil
)
1524 (bookmark-bmenu-show-filenames)
1525 (setq bookmark-bmenu-toggle-filenames t
))
1526 (bookmark-bmenu-toggle-filenames
1527 (bookmark-bmenu-hide-filenames)
1528 (setq bookmark-bmenu-toggle-filenames nil
))
1530 (bookmark-bmenu-show-filenames)
1531 (setq bookmark-bmenu-toggle-filenames t
))))
1534 (defun bookmark-bmenu-show-filenames (&optional force
)
1535 (if (and (not force
) bookmark-bmenu-toggle-filenames
)
1536 nil
;already shown, so do nothing
1538 (save-window-excursion
1539 (goto-char (point-min))
1541 (setq bookmark-bmenu-hidden-bookmarks
())
1542 (let ((buffer-read-only nil
))
1543 (while (< (point) (point-max))
1544 (let ((bmrk (bookmark-bmenu-bookmark)))
1545 (setq bookmark-bmenu-hidden-bookmarks
1546 (cons bmrk bookmark-bmenu-hidden-bookmarks
))
1547 (move-to-column bookmark-bmenu-file-column t
)
1548 (delete-region (point) (progn (end-of-line) (point)))
1550 ;; Pass the NO-HISTORY arg:
1551 (bookmark-insert-location bmrk t
)
1552 (forward-line 1))))))))
1555 (defun bookmark-bmenu-hide-filenames (&optional force
)
1556 (if (and (not force
) bookmark-bmenu-toggle-filenames
)
1557 ;; nothing to hide if above is nil
1559 (save-window-excursion
1560 (goto-char (point-min))
1562 (setq bookmark-bmenu-hidden-bookmarks
1563 (nreverse bookmark-bmenu-hidden-bookmarks
))
1565 (goto-char (point-min))
1566 (search-forward "Bookmark")
1568 (setq bookmark-bmenu-bookmark-column
(current-column)))
1570 (let ((buffer-read-only nil
))
1571 (while bookmark-bmenu-hidden-bookmarks
1572 (move-to-column bookmark-bmenu-bookmark-column t
)
1573 (bookmark-kill-line)
1574 (insert (car bookmark-bmenu-hidden-bookmarks
))
1575 (setq bookmark-bmenu-hidden-bookmarks
1576 (cdr bookmark-bmenu-hidden-bookmarks
))
1577 (forward-line 1))))))))
1580 ;; if you look at this next function from far away, it resembles a
1581 ;; gun. But only with this comment above...
1582 (defun bookmark-bmenu-check-position ()
1583 ;; Returns t if on a line with a bookmark.
1584 ;; Otherwise, repositions and returns t.
1585 ;; written by David Hughes <djh@harston.cv.com>
1586 ;; Mucho thanks, David! -karl
1587 (cond ((< (count-lines (point-min) (point)) 2)
1588 (goto-char (point-min))
1591 ((and (bolp) (eobp))
1592 (beginning-of-line 0)
1598 (defun bookmark-bmenu-bookmark ()
1599 ;; return a string which is bookmark of this line.
1600 (if (bookmark-bmenu-check-position)
1602 (save-window-excursion
1603 (goto-char (point-min))
1604 (search-forward "Bookmark")
1606 (setq bookmark-bmenu-bookmark-column
(current-column)))))
1607 (if bookmark-bmenu-toggle-filenames
1608 (bookmark-bmenu-hide-filenames))
1610 (save-window-excursion
1612 (forward-char bookmark-bmenu-bookmark-column
)
1614 (buffer-substring (point)
1618 ;; well, this is certainly crystal-clear:
1619 (if bookmark-bmenu-toggle-filenames
1620 (bookmark-bmenu-toggle-filenames t
))))))
1623 (defun bookmark-show-annotation (bookmark)
1624 "Display the annotation for bookmark named BOOKMARK in a buffer,
1625 if an annotation exists."
1626 (let ((annotation (bookmark-get-annotation bookmark
)))
1627 (if (and (not (eq annotation nil
))
1628 (not (string-equal annotation
"")))
1631 (let ((old-buf (current-buffer)))
1632 (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t
)
1633 (delete-region (point-min) (point-max))
1634 ; (insert (concat "Annotation for bookmark '" bookmark "':\n\n"))
1636 (goto-char (point-min))
1637 (pop-to-buffer old-buf
)))))))
1640 (defun bookmark-show-all-annotations ()
1641 "Display the annotations for all bookmarks in a buffer."
1642 (let ((old-buf (current-buffer)))
1643 (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t
)
1644 (delete-region (point-min) (point-max))
1646 (lambda (full-record)
1647 (let* ((name (bookmark-name-from-full-record full-record
))
1648 (ann (bookmark-get-annotation name
)))
1649 (insert (concat name
":\n"))
1650 (if (and (not (eq ann nil
)) (not (string-equal ann
"")))
1651 ;; insert the annotation, indented by 4 spaces.
1653 (save-excursion (insert ann
))
1654 (while (< (point) (point-max))
1655 (beginning-of-line) ; paranoia
1660 (goto-char (point-min))
1661 (pop-to-buffer old-buf
)))
1664 (defun bookmark-bmenu-mark ()
1665 "Mark bookmark on this line to be displayed by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-select] command."
1668 (if (bookmark-bmenu-check-position)
1669 (let ((buffer-read-only nil
))
1675 (defun bookmark-bmenu-select ()
1676 "Select this line's bookmark; also display bookmarks marked with `>'.
1677 You can mark bookmarks with the \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-mark] command."
1679 (if (bookmark-bmenu-check-position)
1680 (let ((bmrk (bookmark-bmenu-bookmark))
1681 (menu (current-buffer))
1684 (goto-char (point-min))
1685 (while (re-search-forward "^>" nil t
)
1686 (setq tem
(bookmark-bmenu-bookmark))
1687 (let ((buffer-read-only nil
))
1690 (or (string-equal tem bmrk
)
1692 (setq others
(cons tem others
))))
1693 (setq others
(nreverse others
)
1694 tem
(/ (1- (frame-height)) (1+ (length others
))))
1695 (delete-other-windows)
1696 (bookmark-jump bmrk
)
1700 (split-window nil tem
)
1702 (bookmark-jump (car others
))
1703 (setq others
(cdr others
)))
1704 (other-window 1)))))
1707 (defun bookmark-bmenu-save (parg)
1708 "Save the current list into a bookmark file.
1709 With a prefix arg, prompts for a file to save them in."
1712 (save-window-excursion
1713 (bookmark-save parg
))))
1716 (defun bookmark-bmenu-load ()
1717 "Load the bookmark file and rebuild the bookmark menu-buffer."
1719 (if (bookmark-bmenu-check-position)
1721 (save-window-excursion
1722 ;; This will call `bookmark-bmenu-list'
1723 (call-interactively 'bookmark-load
)))))
1726 (defun bookmark-bmenu-1-window ()
1727 "Select this line's bookmark, alone, in full frame."
1729 (if (bookmark-bmenu-check-position)
1731 (bookmark-jump (bookmark-bmenu-bookmark))
1732 (bury-buffer (other-buffer))
1733 (delete-other-windows))))
1736 (defun bookmark-bmenu-2-window ()
1737 "Select this line's bookmark, with previous buffer in second window."
1739 (if (bookmark-bmenu-check-position)
1740 (let ((bmrk (bookmark-bmenu-bookmark))
1741 (menu (current-buffer))
1743 (delete-other-windows)
1744 (switch-to-buffer (other-buffer))
1745 (let* ((pair (bookmark-jump-noselect bmrk
))
1748 (pop-to-buffer buff
)
1750 (bury-buffer menu
))))
1753 (defun bookmark-bmenu-this-window ()
1754 "Select this line's bookmark in this window."
1756 (if (bookmark-bmenu-check-position)
1757 (bookmark-jump (bookmark-bmenu-bookmark))))
1760 (defun bookmark-bmenu-other-window ()
1761 "Select this line's bookmark in other window, leaving bookmark menu visible."
1763 (let ((bookmark (bookmark-bmenu-bookmark)))
1764 (if (bookmark-bmenu-check-position)
1765 (let* ((pair (bookmark-jump-noselect bookmark
))
1768 (switch-to-buffer-other-window buff
)
1770 (set-window-point (get-buffer-window buff
) pos
)
1771 (bookmark-show-annotation bookmark
)))))
1774 (defun bookmark-bmenu-switch-other-window ()
1775 "Make the other window select this line's bookmark.
1776 The current window remains selected."
1778 (let ((bookmark (bookmark-bmenu-bookmark)))
1779 (if (bookmark-bmenu-check-position)
1780 (let* ((pair (bookmark-jump-noselect bookmark
))
1783 (display-buffer buff
)
1784 (let ((o-buffer (current-buffer)))
1785 ;; save-excursion won't do
1788 (set-window-point (get-buffer-window buff
) pos
)
1789 (set-buffer o-buffer
))
1790 (bookmark-show-annotation bookmark
)))))
1793 (defun bookmark-bmenu-show-annotation ()
1794 "Show the annotation for the current bookmark in another window."
1796 (let ((bookmark (bookmark-bmenu-bookmark)))
1797 (if (bookmark-bmenu-check-position)
1798 (bookmark-show-annotation bookmark
))))
1801 (defun bookmark-bmenu-show-all-annotations ()
1802 "Show the annotation for all bookmarks in another window."
1804 (bookmark-show-all-annotations))
1807 (defun bookmark-bmenu-edit-annotation ()
1808 "Edit the annotation for the current bookmark in another window."
1810 (let ((bookmark (bookmark-bmenu-bookmark)))
1811 (if (bookmark-bmenu-check-position)
1812 (bookmark-edit-annotation bookmark
))))
1815 (defun bookmark-bmenu-quit ()
1816 "Quit the bookmark menu."
1818 (let ((buffer (current-buffer)))
1819 (switch-to-buffer (other-buffer))
1820 (bury-buffer buffer
)))
1823 (defun bookmark-bmenu-unmark (&optional backup
)
1824 "Cancel all requested operations on bookmark on this line and move down.
1825 Optional BACKUP means move up."
1828 (if (bookmark-bmenu-check-position)
1830 (let ((buffer-read-only nil
))
1832 ;; any flags to reset according to circumstances? How about a
1833 ;; flag indicating whether this bookmark is being visited?
1834 ;; well, we don't have this now, so maybe later.
1836 (forward-line (if backup -
1 1)))))
1839 (defun bookmark-bmenu-backup-unmark ()
1840 "Move up and cancel all requested operations on bookmark on line above."
1843 (if (bookmark-bmenu-check-position)
1845 (bookmark-bmenu-unmark)
1846 (forward-line -
1))))
1849 (defun bookmark-bmenu-delete ()
1850 "Mark bookmark on this line to be deleted by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions] command."
1853 (if (bookmark-bmenu-check-position)
1854 (let ((buffer-read-only nil
))
1860 (defun bookmark-bmenu-delete-backwards ()
1861 "Mark bookmark on this line to be deleted by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions] command
1862 and then move up one line"
1864 (bookmark-bmenu-delete)
1866 (if (bookmark-bmenu-check-position)
1870 (defun bookmark-bmenu-execute-deletions ()
1871 "Delete bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
1873 (let ((hide-em bookmark-bmenu-toggle-filenames
)
1875 (o-str (save-excursion
1877 (if (looking-at "^D")
1881 (progn (end-of-line) (point))))))
1882 (o-col (current-column)))
1883 (if hide-em
(bookmark-bmenu-hide-filenames))
1884 (setq bookmark-bmenu-toggle-filenames nil
)
1885 (goto-char (point-min))
1887 (while (re-search-forward "^D" (point-max) t
)
1888 (bookmark-delete (bookmark-bmenu-bookmark) t
)) ; pass BATCH arg
1889 (bookmark-bmenu-list)
1890 (setq bookmark-bmenu-toggle-filenames hide-em
)
1891 (if bookmark-bmenu-toggle-filenames
1892 (bookmark-bmenu-toggle-filenames t
))
1895 (goto-char (point-min))
1896 (search-forward o-str
)
1898 (forward-char o-col
))
1899 (goto-char o-point
))
1901 (setq bookmark-alist-modification-count
1902 (1+ bookmark-alist-modification-count
))
1903 (if (bookmark-time-to-save-p)
1907 (defun bookmark-bmenu-rename ()
1908 "Rename bookmark on current line. Prompts for a new name."
1910 (if (bookmark-bmenu-check-position)
1911 (let ((bmrk (bookmark-bmenu-bookmark))
1912 (thispoint (point)))
1913 (bookmark-rename bmrk
)
1914 (bookmark-bmenu-list)
1915 (goto-char thispoint
))))
1918 (defun bookmark-bmenu-locate ()
1919 "Display location of this bookmark. Displays in the minibuffer."
1921 (if (bookmark-bmenu-check-position)
1922 (let ((bmrk (bookmark-bmenu-bookmark)))
1923 (message (bookmark-location bmrk
)))))
1927 ;;; Menu bar stuff. Prefix is "bookmark-menu".
1929 (defun bookmark-menu-build-paned-menu (name entries
)
1930 "Build a multi-paned menu named NAME from the strings in ENTRIES.
1931 That is, ENTRIES is a list of strings which appear as the choices
1932 in the menu. The number of panes depends on the number of entries.
1933 The visible entries are truncated to `bookmark-menu-length', but the
1934 strings returned are not."
1935 (let* ((f-height (/ (frame-height) 2))
1937 (let (temp-pane-list
1942 (while (and (< count f-height
) entries
)
1943 (let ((str (car entries
)))
1946 (if (> (length str
) bookmark-menu-length
)
1947 (substring str
0 bookmark-menu-length
)
1951 (setq entries
(cdr entries
))
1952 (setq count
(1+ count
))))
1953 (setq iter
(1+ iter
))
1958 (format "-*- %s (%d) -*-" name iter
)
1961 (nreverse temp-pane-list
))))
1964 (cons (concat "-*- " name
" -*-") pane-list
)))
1967 (defun bookmark-menu-popup-paned-menu (event name entries
)
1968 "Pop up multi-paned menu at EVENT, return string chosen from ENTRIES.
1969 That is, ENTRIES is a list of strings which appear as the choices
1971 The number of panes depends on the number of entries."
1973 (x-popup-menu event
(bookmark-menu-build-paned-menu name entries
)))
1976 (defun bookmark-menu-popup-paned-bookmark-menu (event name
)
1977 "Pop up menu of bookmarks, return chosen bookmark.
1978 Pop up at EVENT, menu's name is NAME.
1979 The number of panes depends on the number of bookmarks."
1980 (bookmark-menu-popup-paned-menu event name
(bookmark-all-names)))
1983 (defun bookmark-popup-menu-and-apply-function (func-sym menu-label event
)
1984 ;; help function for making menus that need to apply a bookmark
1985 ;; function to a string.
1986 (let* ((choice (bookmark-menu-popup-paned-bookmark-menu
1988 (if choice
(apply func-sym
(list choice
)))))
1992 (defun bookmark-menu-insert (event)
1993 "Insert the text of the file pointed to by bookmark BOOKMARK.
1994 You may have a problem using this function if the value of variable
1995 `bookmark-alist' is nil. If that happens, you need to load in some
1996 bookmarks. See help on function `bookmark-load' for more about
1999 Warning: this function only takes an EVENT as argument. Use the
2000 corresponding bookmark function from Lisp \(the one without the
2001 \"-menu-\" in its name\)."
2003 (bookmark-popup-menu-and-apply-function
2004 'bookmark-insert
"Insert Bookmark Contents" event
))
2008 (defun bookmark-menu-jump (event)
2009 "Jump to bookmark BOOKMARK (a point in some file).
2010 You may have a problem using this function if the value of variable
2011 `bookmark-alist' is nil. If that happens, you need to load in some
2012 bookmarks. See help on function `bookmark-load' for more about
2015 Warning: this function only takes an EVENT as argument. Use the
2016 corresponding bookmark function from Lisp \(the one without the
2017 \"-menu-\" in its name\)."
2019 (bookmark-popup-menu-and-apply-function
2020 'bookmark-jump
"Jump to Bookmark" event
))
2024 (defun bookmark-menu-locate (event)
2025 "Insert the name of the file associated with BOOKMARK.
2026 \(This is not the same as the contents of that file\).
2028 Warning: this function only takes an EVENT as argument. Use the
2029 corresponding bookmark function from Lisp \(the one without the
2030 \"-menu-\" in its name\)."
2032 (bookmark-popup-menu-and-apply-function
2033 'bookmark-insert-location
"Insert Bookmark Location" event
))
2037 (defun bookmark-menu-rename (event)
2038 "Change the name of OLD-BOOKMARK to NEWNAME.
2039 If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
2040 If called from menubar, OLD-BOOKMARK is selected from a menu, and
2041 prompts for NEWNAME.
2042 If called from Lisp, prompts for NEWNAME if only OLD-BOOKMARK was
2043 passed as an argument. If called with two strings, then no prompting
2044 is done. You must pass at least OLD-BOOKMARK when calling from Lisp.
2046 While you are entering the new name, consecutive C-w's insert
2047 consectutive words from the text of the buffer into the new bookmark
2050 Warning: this function only takes an EVENT as argument. Use the
2051 corresponding bookmark function from Lisp \(the one without the
2052 \"-menu-\" in its name\)."
2054 (bookmark-popup-menu-and-apply-function
2055 'bookmark-rename
"Rename Bookmark" event
))
2059 (defun bookmark-menu-delete (event)
2060 "Delete the bookmark named NAME from the bookmark list.
2061 Removes only the first instance of a bookmark with that name. If
2062 there are one or more other bookmarks with the same name, they will
2063 not be deleted. Defaults to the \"current\" bookmark \(that is, the
2064 one most recently used in this file, if any\).
2066 Warning: this function only takes an EVENT as argument. Use the
2067 corresponding bookmark function from Lisp \(the one without the
2068 \"-menu-\" in its name\)."
2070 (bookmark-popup-menu-and-apply-function
2071 'bookmark-delete
"Delete Bookmark" event
))
2074 ;; Thanks to Roland McGrath for fixing menubar.el so that the
2075 ;; following works, and for explaining what to do to make it work.
2077 ;; We MUST autoload EACH form used to set up this variable's value, so
2078 ;; that the whole job is done in loaddefs.el.
2081 (defvar menu-bar-bookmark-map
(make-sparse-keymap "Bookmark functions"))
2084 (defalias 'menu-bar-bookmark-map
(symbol-value 'menu-bar-bookmark-map
))
2087 (define-key menu-bar-bookmark-map
[load]
2088 '("Load a Bookmark File" . bookmark-load))
2091 (define-key menu-bar-bookmark-map [write]
2092 '("Write \(to another file\)" . bookmark-write))
2095 (define-key menu-bar-bookmark-map [save]
2096 '("Save \(in default file\)" . bookmark-save))
2099 (define-key menu-bar-bookmark-map [edit]
2100 '("Edit Bookmark List" . bookmark-bmenu-list))
2103 (define-key menu-bar-bookmark-map [delete]
2104 '("Delete Bookmark" . bookmark-menu-delete))
2107 (define-key menu-bar-bookmark-map [rename]
2108 '("Rename Bookmark" . bookmark-menu-rename))
2111 (define-key menu-bar-bookmark-map [locate]
2112 '("Insert Location" . bookmark-menu-locate))
2115 (define-key menu-bar-bookmark-map [insert]
2116 '("Insert Contents" . bookmark-menu-insert))
2119 (define-key menu-bar-bookmark-map [set]
2120 '("Set Bookmark" . bookmark-set))
2123 (define-key menu-bar-bookmark-map [jump]
2124 '("Jump to Bookmark" . bookmark-menu-jump))
2126 ;;;; end bookmark menu stuff ;;;;
2130 (defvar bookmark-load-hook nil
2131 "Hook to run at the end of loading bookmark.")
2133 (run-hooks 'bookmark-load-hook)
2137 ;;; bookmark.el ends here