(w32_menu_display_help): Suppress tooltip when navigating menus with
[bpt/emacs.git] / lisp / bookmark.el
CommitLineData
e8af40ee 1;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later
b3bf02fa 2
a1ff29b9 3;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2003 Free Software Foundation
b3bf02fa 4
60d0378e
KF
5;; Author: Karl Fogel <kfogel@red-bean.com>
6;; Maintainer: Karl Fogel <kfogel@red-bean.com>
b3bf02fa 7;; Created: July, 1993
e3437989 8;; Keywords: bookmarks, placeholders, annotations
b3bf02fa
RS
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
b578f267 23;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
b578f267
EN
26
27;;; Commentary:
28
29;; This package is for setting "bookmarks" in files. A bookmark
30;; associates a string with a location in a certain file. Thus, you
31;; can navigate your way to that location by providing the string.
32;; See the "User Variables" section for customizations.
b3bf02fa
RS
33
34;; Thanks to David Bremner <bremner@cs.sfu.ca> for thinking of and
35;; then implementing the bookmark-current-bookmark idea. He even
d23e2c3f 36;; sent *patches*, bless his soul...
b3bf02fa
RS
37
38;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for
39;; fixing and improving bookmark-time-to-save-p.
40
e3437989
RS
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
d23e2c3f
KF
43;; and the menu-bar).
44
d22d6453
RS
45;; And much thanks to David Hughes <djh@harston.cv.com> for many small
46;; suggestions and the code to implement them (like
e3437989 47;; bookmark-bmenu-check-position, and some of the Lucid compatibility
d22d6453
RS
48;; stuff).
49
60d0378e 50;; Kudos (whatever they are) go to Jim Blandy <jimb@red-bean.com>
d23e2c3f
KF
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.
54
d22d6453
RS
55;; Thanks to Roland McGrath for encouragement and help with defining
56;; autoloads on the menu-bar.
57
2b911848 58;; Jonathan Stigelman <stig@hackvan.com> gave patches for default
d23e2c3f
KF
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!)
62
e3437989
RS
63;; Buckets of gratitude to John Grabowski <johng@media.mit.edu> for
64;; thinking up the annotations feature and implementing it so well.
65
b3bf02fa
RS
66;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
67;; <olstad@msc.edu>.
68
4eadcdf8
RS
69;; Thanks to Mikio Nakajima <PBC01764@niftyserve.or.jp> for many bugs
70;; reported and fixed.
71
09fd6588
KF
72;; Thank you, Michael Kifer, for contributing the XEmacs support.
73
d22d6453 74;; Enough with the credits already, get on to the good stuff:
b3bf02fa 75
dbe99ae9 76;; FAVORITE CHINESE RESTAURANT:
b3bf02fa
RS
77;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's
78;; Choice (both in Chicago's Chinatown). Well, both. How about you?
e3437989 79\f
e8af40ee 80;;; Code:
b3bf02fa 81
b578f267
EN
82(require 'pp)
83
e3437989 84;;; Misc comments:
b3bf02fa 85;;
e3437989 86;; If variable bookmark-use-annotations is non-nil, an annotation is
dbe99ae9 87;; queried for when setting a bookmark.
11eb4275 88;;
d22d6453
RS
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.
b3bf02fa 93
4eadcdf8
RS
94;;; User Variables
95
bbf5eb28 96(defgroup bookmark nil
9848f0ca 97 "Setting, annotation and jumping to bookmarks."
bbf5eb28
RS
98 :group 'matching)
99
100
101(defcustom bookmark-use-annotations nil
9848f0ca 102 "*If non-nil, saving a bookmark queries for an annotation in a buffer."
bbf5eb28
RS
103 :type 'boolean
104 :group 'bookmark)
4eadcdf8
RS
105
106
bbf5eb28 107(defcustom bookmark-save-flag t
4eadcdf8 108 "*Controls when Emacs saves bookmarks to a file.
9848f0ca 109--> nil means never save bookmarks, except when `bookmark-save' is
4eadcdf8
RS
110 explicitly called \(\\[bookmark-save]\).
111--> t means save bookmarks when Emacs is killed.
3b526bae 112--> Otherwise, it should be a number that is the frequency with which
4eadcdf8
RS
113 the bookmark list is saved \(i.e.: the number of times which
114 Emacs' bookmark list may be modified before it is automatically
115 saved.\). If it is a number, Emacs will also automatically save
116 bookmarks when it is killed.
117
118Therefore, the way to get it to save every time you make or delete a
119bookmark is to set this variable to 1 \(or 0, which produces the same
120behavior.\)
121
122To specify the file in which to save them, modify the variable
9848f0ca 123`bookmark-default-file', which is `~/.emacs.bmk' by default."
31fa1bd1 124 :type '(choice (const nil) integer (other t))
bbf5eb28 125 :group 'bookmark)
4eadcdf8
RS
126
127
128(defconst bookmark-old-default-file "~/.emacs-bkmrks"
9848f0ca 129 "*The `.emacs.bmk' file used to be called this name.")
4eadcdf8
RS
130
131
132;; defvarred to avoid a compilation warning:
133(defvar bookmark-file nil
134 "Old name for `bookmark-default-file'.")
135
bbf5eb28 136(defcustom bookmark-default-file
4eadcdf8
RS
137 (if bookmark-file
138 ;; In case user set `bookmark-file' in her .emacs:
139 bookmark-file
88fb0aaa 140 (convert-standard-filename "~/.emacs.bmk"))
bbf5eb28
RS
141 "*File in which to save bookmarks by default."
142 :type 'file
143 :group 'bookmark)
4eadcdf8
RS
144
145
bbf5eb28 146(defcustom bookmark-version-control 'nospecial
4eadcdf8
RS
147 "*Whether or not to make numbered backups of the bookmark file.
148It can have four values: t, nil, `never', and `nospecial'.
149The first three have the same meaning that they do for the
150variable `version-control', and the final value `nospecial' means just
bbf5eb28 151use the value of `version-control'."
31fa1bd1
AS
152 :type '(choice (const nil) (const never) (const nospecial)
153 (other t))
bbf5eb28 154 :group 'bookmark)
4eadcdf8
RS
155
156
bbf5eb28
RS
157(defcustom bookmark-completion-ignore-case t
158 "*Non-nil means bookmark functions ignore case in completion."
159 :type 'boolean
160 :group 'bookmark)
4eadcdf8
RS
161
162
bbf5eb28 163(defcustom bookmark-sort-flag t
9848f0ca
RS
164 "*Non-nil means that bookmarks will be displayed sorted by bookmark name.
165Otherwise they will be displayed in LIFO order (that is, most
bbf5eb28
RS
166recently set ones come first, oldest ones come last)."
167 :type 'boolean
168 :group 'bookmark)
4eadcdf8
RS
169
170
bbf5eb28 171(defcustom bookmark-automatically-show-annotations t
f0529b5b 172 "*nil means don't show annotations when jumping to a bookmark."
bbf5eb28
RS
173 :type 'boolean
174 :group 'bookmark)
4eadcdf8
RS
175
176
bbf5eb28 177(defcustom bookmark-bmenu-file-column 30
4eadcdf8 178 "*Column at which to display filenames in a buffer listing bookmarks.
bbf5eb28
RS
179You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames]."
180 :type 'integer
181 :group 'bookmark)
4eadcdf8
RS
182
183
bbf5eb28 184(defcustom bookmark-bmenu-toggle-filenames t
4eadcdf8
RS
185 "*Non-nil means show filenames when listing bookmarks.
186This may result in truncated bookmark names. To disable this, put the
9848f0ca 187following in your `.emacs' file:
4eadcdf8 188
bbf5eb28
RS
189\(setq bookmark-bmenu-toggle-filenames nil\)"
190 :type 'boolean
191 :group 'bookmark)
4eadcdf8
RS
192
193
bbf5eb28
RS
194(defcustom bookmark-menu-length 70
195 "*Maximum length of a bookmark name displayed on a popup menu."
196 :type 'integer
85d457c6 197 :group 'bookmark)
4eadcdf8
RS
198
199
200;;; No user-serviceable parts beyond this point.
b3bf02fa 201
09fd6588
KF
202;; Is it XEmacs?
203(defconst bookmark-xemacsp
204 (string-match "\\(Lucid\\|Xemacs\\)" emacs-version))
205
206
b3bf02fa
RS
207;; Added for lucid emacs compatibility, db
208(or (fboundp 'defalias) (fset 'defalias 'fset))
209
d22d6453 210;; suggested for lucid compatibility by david hughes:
4eadcdf8 211(or (fboundp 'frame-height) (defalias 'frame-height 'screen-height))
d22d6453 212
09fd6588
KF
213;; This variable is probably obsolete now...
214(or (boundp 'baud-rate)
dbe99ae9 215 ;; some random value higher than 9600
09fd6588
KF
216 (setq baud-rate 19200))
217
e3437989
RS
218
219\f
220;;; Keymap stuff:
b3bf02fa 221
77bc05c7
RS
222;; Set up these bindings dumping time *only*;
223;; if the user alters them, don't override the user when loading bookmark.el.
224
225;;;###autoload (define-key ctl-x-map "rb" 'bookmark-jump)
226;;;###autoload (define-key ctl-x-map "rm" 'bookmark-set)
227;;;###autoload (define-key ctl-x-map "rl" 'bookmark-bmenu-list)
b3bf02fa 228
d22d6453 229;;;###autoload
9aef3b21
RS
230(defvar bookmark-map nil
231 "Keymap containing bindings to bookmark functions.
232It is not bound to any key by default: to bind it
233so that you have a bookmark prefix, just use `global-set-key' and bind a
234key of your choice to `bookmark-map'. All interactive bookmark
b3bf02fa
RS
235functions have a binding in this keymap.")
236
a1ff29b9 237;;;###autoload (define-prefix-command 'bookmark-map)
b3bf02fa
RS
238
239;; Read the help on all of these functions for details...
a1ff29b9
AS
240;;;###autoload (define-key bookmark-map "x" 'bookmark-set)
241;;;###autoload (define-key bookmark-map "m" 'bookmark-set) ; "m" for "mark"
242;;;###autoload (define-key bookmark-map "j" 'bookmark-jump)
243;;;###autoload (define-key bookmark-map "g" 'bookmark-jump) ; "g" for "go"
244;;;###autoload (define-key bookmark-map "i" 'bookmark-insert)
245;;;###autoload (define-key bookmark-map "e" 'edit-bookmarks)
246;;;###autoload (define-key bookmark-map "f" 'bookmark-insert-location) ; "f" for "find"
247;;;###autoload (define-key bookmark-map "r" 'bookmark-rename)
248;;;###autoload (define-key bookmark-map "d" 'bookmark-delete)
249;;;###autoload (define-key bookmark-map "l" 'bookmark-load)
250;;;###autoload (define-key bookmark-map "w" 'bookmark-write)
251;;;###autoload (define-key bookmark-map "s" 'bookmark-save)
b3bf02fa 252
e3437989
RS
253
254;;; The annotation maps.
255(defvar bookmark-read-annotation-mode-map (copy-keymap text-mode-map)
256 "Keymap for composing an annotation for a bookmark.")
257
258(define-key bookmark-read-annotation-mode-map "\C-c\C-c"
259 'bookmark-send-annotation)
260
261
262\f
263;;; Core variables and data structures:
7e2d009d 264(defvar bookmark-alist ()
e3437989 265 "Association list of bookmarks and their records.
7e2d009d 266You probably don't want to change the value of this alist yourself;
4eadcdf8
RS
267instead, let the various bookmark functions do it for you.
268
269The format of the alist is
270
271 \(BOOKMARK1 BOOKMARK2 ...\)
272
273where each BOOKMARK is of the form
274
275\(NAME
276 \(filename . FILE\)
277 \(front-context-string . FRONT-STR\)
278 \(rear-context-string . REAR-STR\)
279 \(position . POS\)
280 \(info-node . POS\)
281 \(annotation . ANNOTATION\)\)
282
283So the cdr of each bookmark is an alist too.
284`info-node' is optional, by the way.")
7e2d009d 285
e3437989 286
d22d6453
RS
287(defvar bookmarks-already-loaded nil)
288
e3437989 289
b3bf02fa 290;; more stuff added by db.
d22d6453 291
dbe99ae9 292(defvar bookmark-current-bookmark nil
9aef3b21
RS
293 "Name of bookmark most recently used in the current file.
294It is buffer local, used to make moving a bookmark forward
8027e2ad 295through a file easier.")
b3bf02fa
RS
296
297(make-variable-buffer-local 'bookmark-current-bookmark)
298
e3437989 299
b3bf02fa 300(defvar bookmark-alist-modification-count 0
9aef3b21 301 "Number of modifications to bookmark list since it was last saved.")
b3bf02fa 302
e3437989 303
e3437989 304(defvar bookmark-search-size 16
9aef3b21 305 "Length of the context strings recorded on either side of a bookmark.")
b3bf02fa 306
e3437989 307
b3bf02fa
RS
308(defvar bookmark-current-point 0)
309(defvar bookmark-yank-point 0)
310(defvar bookmark-current-buffer nil)
311
f8e1f213
RS
312(defvar Info-current-node)
313(defvar Info-suffix-list)
e3437989
RS
314\f
315;; Helper functions.
316
317;; Only functions on this page and the next one (file formats) need to
318;; know anything about the format of bookmark-alist entries.
319;; Everyone else should go through them.
320
321(defun bookmark-name-from-full-record (full-record)
4eadcdf8 322 "Return name of FULL-RECORD \(an alist element instead of a string\)."
e3437989
RS
323 (car full-record))
324
325
326(defun bookmark-all-names ()
327 "Return a list of all current bookmark names."
328 (bookmark-maybe-load-default-file)
329 (mapcar
330 (lambda (full-record)
331 (bookmark-name-from-full-record full-record))
332 bookmark-alist))
333
334
335(defun bookmark-get-bookmark (bookmark)
28d80dea
GM
336 "Return the full entry for BOOKMARK in bookmark-alist.
337If BOOKMARK is not a string, return nil."
338 (when (stringp bookmark)
d0959626 339 (assoc-string bookmark bookmark-alist bookmark-completion-ignore-case)))
e3437989
RS
340
341
342(defun bookmark-get-bookmark-record (bookmark)
343 "Return the guts of the entry for BOOKMARK in bookmark-alist.
344That is, all information but the name."
345 (car (cdr (bookmark-get-bookmark bookmark))))
346
347
348(defun bookmark-set-name (bookmark newname)
349 "Set BOOKMARK's name to NEWNAME."
91169ba7
RS
350 (setcar
351 (if (stringp bookmark) (bookmark-get-bookmark bookmark) bookmark)
352 newname))
e3437989
RS
353
354
355(defun bookmark-get-annotation (bookmark)
356 "Return the annotation of BOOKMARK, or nil if none."
357 (cdr (assq 'annotation (bookmark-get-bookmark-record bookmark))))
358
359
360(defun bookmark-set-annotation (bookmark ann)
4eadcdf8 361 "Set the annotation of BOOKMARK to ANN."
e3437989
RS
362 (let ((cell (assq 'annotation (bookmark-get-bookmark-record bookmark))))
363 (if cell
364 (setcdr cell ann)
365 (nconc (bookmark-get-bookmark-record bookmark)
366 (list (cons 'annotation ann))))))
367
368
369(defun bookmark-get-filename (bookmark)
370 "Return the full filename of BOOKMARK."
371 (cdr (assq 'filename (bookmark-get-bookmark-record bookmark))))
372
373
374(defun bookmark-set-filename (bookmark filename)
375 "Set the full filename of BOOKMARK to FILENAME."
376 (let ((cell (assq 'filename (bookmark-get-bookmark-record bookmark))))
377 (if cell
378 (setcdr cell filename)
379 (nconc (bookmark-get-bookmark-record bookmark)
037b0a87
KF
380 (list (cons 'filename filename))))
381 (setq bookmark-alist-modification-count
382 (1+ bookmark-alist-modification-count))
383 (if (bookmark-time-to-save-p)
384 (bookmark-save))))
e3437989
RS
385
386
387(defun bookmark-get-position (bookmark)
388 "Return the position \(i.e.: point\) of BOOKMARK."
389 (cdr (assq 'position (bookmark-get-bookmark-record bookmark))))
390
391
392(defun bookmark-set-position (bookmark position)
393 "Set the position \(i.e.: point\) of BOOKMARK to POSITION."
394 (let ((cell (assq 'position (bookmark-get-bookmark-record bookmark))))
395 (if cell
396 (setcdr cell position)
397 (nconc (bookmark-get-bookmark-record bookmark)
398 (list (cons 'position position))))))
399
400
401(defun bookmark-get-front-context-string (bookmark)
402 "Return the front-context-string of BOOKMARK."
403 (cdr (assq 'front-context-string (bookmark-get-bookmark-record bookmark))))
404
405
406(defun bookmark-set-front-context-string (bookmark string)
407 "Set the front-context-string of BOOKMARK to STRING."
408 (let ((cell (assq 'front-context-string
409 (bookmark-get-bookmark-record bookmark))))
410 (if cell
411 (setcdr cell string)
412 (nconc (bookmark-get-bookmark-record bookmark)
413 (list (cons 'front-context-string string))))))
414
415
416(defun bookmark-get-rear-context-string (bookmark)
417 "Return the rear-context-string of BOOKMARK."
418 (cdr (assq 'rear-context-string (bookmark-get-bookmark-record bookmark))))
419
420
421(defun bookmark-set-rear-context-string (bookmark string)
422 "Set the rear-context-string of BOOKMARK to STRING."
423 (let ((cell (assq 'rear-context-string
424 (bookmark-get-bookmark-record bookmark))))
425 (if cell
426 (setcdr cell string)
427 (nconc (bookmark-get-bookmark-record bookmark)
428 (list (cons 'rear-context-string string))))))
429
430
431(defun bookmark-get-info-node (bookmark)
4eadcdf8 432 "Get the info node associated with BOOKMARK."
e3437989 433 (cdr (assq 'info-node (bookmark-get-bookmark-record bookmark))))
dbe99ae9 434
e3437989
RS
435
436(defun bookmark-set-info-node (bookmark node)
437 "Set the Info node of BOOKMARK to NODE."
438 (let ((cell (assq 'info-node
439 (bookmark-get-bookmark-record bookmark))))
440 (if cell
441 (setcdr cell node)
442 (nconc (bookmark-get-bookmark-record bookmark)
a15269c0
KF
443 (list (cons 'info-node node)))))
444
445 (message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark)))
446 (sit-for 4)
447 )
dbe99ae9 448
e3437989 449
4c0b5ad1
KF
450(defvar bookmark-history nil
451 "The history list for bookmark functions.")
452
453
e3437989
RS
454(defun bookmark-completing-read (prompt &optional default)
455 "Prompting with PROMPT, read a bookmark name in completion.
456PROMPT will get a \": \" stuck on the end no matter what, so you
457probably don't want to include one yourself.
458Optional second arg DEFAULT is a string to return if the user enters
459the empty string."
460 (bookmark-maybe-load-default-file) ; paranoia
175d0960
SM
461 (if (listp last-nonmenu-event)
462 (bookmark-menu-popup-paned-menu t prompt (bookmark-all-names))
463 (let* ((completion-ignore-case bookmark-completion-ignore-case)
464 (default default)
465 (prompt (if default
466 (concat prompt (format " (%s): " default))
467 (concat prompt ": ")))
468 (str
469 (completing-read prompt
470 bookmark-alist
471 nil
472 0
473 nil
474 'bookmark-history)))
475 (if (string-equal "" str) default str))))
e3437989
RS
476
477
4c0b5ad1
KF
478(defmacro bookmark-maybe-historicize-string (string)
479 "Put STRING into the bookmark prompt history, if caller non-interactive.
480We need this because sometimes bookmark functions are invoked from
481menus, so `completing-read' never gets a chance to set `bookmark-history'."
dbe99ae9
SS
482 `(or
483 (interactive-p)
484 (setq bookmark-history (cons ,string bookmark-history))))
4c0b5ad1
KF
485
486
a15269c0 487(defun bookmark-make (name &optional annotation overwrite info-node)
e3437989
RS
488 "Make a bookmark named NAME.
489Optional second arg ANNOTATION gives it an annotation.
490Optional third arg OVERWRITE means replace any existing bookmarks with
a15269c0
KF
491this name.
492Optional fourth arg INFO-NODE means this bookmark is at info node
493INFO-NODE, so record this fact in the bookmark's entry."
e3437989 494 (bookmark-maybe-load-default-file)
88415bfc 495 (let ((stripped-name (copy-sequence name)))
09fd6588
KF
496 (or bookmark-xemacsp
497 ;; XEmacs's `set-text-properties' doesn't work on
498 ;; free-standing strings, apparently.
499 (set-text-properties 0 (length stripped-name) nil stripped-name))
88415bfc 500 (if (and (bookmark-get-bookmark stripped-name) (not overwrite))
3b526bae 501 ;; already existing bookmark under that name and
88415bfc
KH
502 ;; no prefix arg means just overwrite old bookmark
503 (setcdr (bookmark-get-bookmark stripped-name)
a15269c0 504 (list (bookmark-make-cell annotation info-node)))
dbe99ae9 505
88415bfc
KH
506 ;; otherwise just cons it onto the front (either the bookmark
507 ;; doesn't exist already, or there is no prefix arg. In either
508 ;; case, we want the new bookmark consed onto the alist...)
dbe99ae9 509
88415bfc
KH
510 (setq bookmark-alist
511 (cons
dbe99ae9 512 (list stripped-name
a15269c0 513 (bookmark-make-cell annotation info-node))
88415bfc 514 bookmark-alist)))
dbe99ae9 515
88415bfc
KH
516 ;; Added by db
517 (setq bookmark-current-bookmark stripped-name)
518 (setq bookmark-alist-modification-count
519 (1+ bookmark-alist-modification-count))
520 (if (bookmark-time-to-save-p)
521 (bookmark-save))))
e3437989
RS
522
523
a15269c0 524(defun bookmark-make-cell (annotation &optional info-node)
4eadcdf8 525 "Return the record part of a new bookmark, given ANNOTATION.
e3437989 526Must be at the correct position in the buffer in which the bookmark is
a15269c0
KF
527being set. This might change someday.
528Optional second arg INFO-NODE means this bookmark is at info node
529INFO-NODE, so record this fact in the bookmark's entry."
530 (let ((the-record
8a946354
SS
531 `((filename . ,(bookmark-buffer-file-name))
532 (front-context-string
533 . ,(if (>= (- (point-max) (point)) bookmark-search-size)
534 (buffer-substring-no-properties
535 (point)
536 (+ (point) bookmark-search-size))
537 nil))
538 (rear-context-string
539 . ,(if (>= (- (point) (point-min)) bookmark-search-size)
540 (buffer-substring-no-properties
541 (point)
542 (- (point) bookmark-search-size))
543 nil))
544 (position . ,(point)))))
a15269c0
KF
545
546 ;; Now fill in the optional parts:
91169ba7
RS
547
548 ;; Take no chances with text properties
549 (set-text-properties 0 (length annotation) nil annotation)
550 (set-text-properties 0 (length info-node) nil info-node)
551
a15269c0
KF
552 (if annotation
553 (nconc the-record (list (cons 'annotation annotation))))
554 (if info-node
555 (nconc the-record (list (cons 'info-node info-node))))
556
557 ;; Finally, return the completed record.
558 the-record))
dbe99ae9
SS
559
560
e3437989
RS
561\f
562;;; File format stuff
563
564;; The OLD format of the bookmark-alist was:
565;;
566;; ((bookmark-name (filename
567;; string-in-front
568;; string-behind
569;; point))
570;; ...)
571;;
572;; The NEW format of the bookmark-alist is:
573;;
574;; ((bookmark-name ((filename . FILENAME)
575;; (front-context-string . string-in-front)
576;; (rear-context-string . string-behind)
577;; (position . POINT)
578;; (annotation . annotation)
579;; (whatever . VALUE)
580;; ...
581;; ))
582;; ...)
583;;
584;;
585;; I switched to using an internal as well as external alist because I
586;; felt that would be a more flexible framework in which to add
587;; features. It means that the order in which values appear doesn't
588;; matter, and it means that arbitrary values can be added without
589;; risk of interfering with existing ones.
590;;
591;; BOOKMARK-NAME is the string the user gives the bookmark and
dbe99ae9 592;; accesses it by from then on.
e3437989
RS
593;;
594;; FILENAME is the location of the file in which the bookmark is set.
595;;
596;; STRING-IN-FRONT is a string of `bookmark-search-size' chars of
597;; context in front of the point at which the bookmark is set.
598;;
dbe99ae9 599;; STRING-BEHIND is the same thing, but after the point.
e3437989
RS
600;;
601;; The context strings exist so that modifications to a file don't
dbe99ae9 602;; necessarily cause a bookmark's position to be invalidated.
e3437989
RS
603;; bookmark-jump will search for STRING-BEHIND and STRING-IN-FRONT in
604;; case the file has changed since the bookmark was set. It will
605;; attempt to place the user before the changes, if there were any.
a15269c0 606;; ANNOTATION is the annotation for the bookmark; it may not exist
e3437989
RS
607;; (for backward compatibility), be nil (no annotation), or be a
608;; string.
e3437989
RS
609
610
611(defconst bookmark-file-format-version 1
612 "The current version of the format used by bookmark files.
613You should never need to change this.")
614
615
616(defconst bookmark-end-of-version-stamp-marker
617 "-*- End Of Bookmark File Format Version Stamp -*-\n"
618 "This string marks the end of the version stamp in a bookmark file.")
619
620
621(defun bookmark-alist-from-buffer ()
622 "Return a bookmark-alist (in any format) from the current buffer.
623The buffer must of course contain bookmark format information.
624Does not care from where in the buffer it is called, and does not
625affect point."
626 (save-excursion
627 (goto-char (point-min))
628 (if (search-forward bookmark-end-of-version-stamp-marker nil t)
629 (read (current-buffer))
630 ;; Else we're dealing with format version 0
631 (if (search-forward "(" nil t)
632 (progn
633 (forward-char -1)
634 (read (current-buffer)))
635 ;; Else no hope of getting information here.
a3ad20c2 636 (error "Not bookmark format")))))
e3437989
RS
637
638
639(defun bookmark-upgrade-version-0-alist (old-list)
4eadcdf8 640 "Upgrade a version 0 alist OLD-LIST to the current version."
e3437989
RS
641 (mapcar
642 (lambda (bookmark)
643 (let* ((name (car bookmark))
644 (record (car (cdr bookmark)))
645 (filename (nth 0 record))
646 (front-str (nth 1 record))
647 (rear-str (nth 2 record))
648 (position (nth 3 record))
649 (ann (nth 4 record)))
650 (list
651 name
8a946354
SS
652 `((filename . ,filename)
653 (front-context-string . ,(or front-str ""))
654 (rear-context-string . ,(or rear-str ""))
655 (position . ,position)
656 (annotation . ,ann)))))
e3437989
RS
657 old-list))
658
659
660(defun bookmark-upgrade-file-format-from-0 ()
661 "Upgrade a bookmark file of format 0 (the original format) to format 1.
662This expects to be called from point-min in a bookmark file."
663 (message "Upgrading bookmark format from 0 to %d..."
664 bookmark-file-format-version)
665 (let* ((old-list (bookmark-alist-from-buffer))
666 (new-list (bookmark-upgrade-version-0-alist old-list)))
667 (delete-region (point-min) (point-max))
668 (bookmark-insert-file-format-version-stamp)
669 (pp new-list (current-buffer))
670 (save-buffer))
671 (goto-char (point-min))
60d0378e 672 (message "Upgrading bookmark format from 0 to %d...done"
e3437989
RS
673 bookmark-file-format-version)
674 )
675
676
677(defun bookmark-grok-file-format-version ()
678 "Return an integer which is the file-format version of this bookmark file.
679This expects to be called from point-min in a bookmark file."
680 (if (looking-at "^;;;;")
681 (save-excursion
682 (save-match-data
683 (re-search-forward "[0-9]")
684 (forward-char -1)
685 (read (current-buffer))))
686 ;; Else this is format version 0, the original one, which didn't
687 ;; even have version stamps.
688 0))
689
690
691(defun bookmark-maybe-upgrade-file-format ()
692 "Check the file-format version of this bookmark file.
693If the version is not up-to-date, upgrade it automatically.
694This expects to be called from point-min in a bookmark file."
695 (let ((version (bookmark-grok-file-format-version)))
696 (cond
697 ((= version bookmark-file-format-version)
698 ) ; home free -- version is current
699 ((= version 0)
700 (bookmark-upgrade-file-format-from-0))
701 (t
a3ad20c2 702 (error "Bookmark file format version strangeness")))))
e3437989
RS
703
704
705(defun bookmark-insert-file-format-version-stamp ()
5e0e5feb 706 "Insert text indicating current version of bookmark file format."
e3437989
RS
707 (insert
708 (format ";;;; Emacs Bookmark Format Version %d ;;;;\n"
709 bookmark-file-format-version))
710 (insert ";;; This format is meant to be slightly human-readable;\n"
711 ";;; nevertheless, you probably don't want to edit it.\n"
712 ";;; "
713 bookmark-end-of-version-stamp-marker))
714
715
716;;; end file-format stuff
717
718\f
719;;; Core code:
720
d22d6453 721;;;###autoload
4eadcdf8
RS
722(defun bookmark-set (&optional name parg)
723 "Set a bookmark named NAME inside a file.
724If name is nil, then the user will be prompted.
9aef3b21
RS
725With prefix arg, will not overwrite a bookmark that has the same name
726as NAME if such a bookmark already exists, but instead will \"push\"
727the new bookmark onto the bookmark alist. Thus the most recently set
728bookmark with name NAME would be the one in effect at any given time,
729but the others are still there, should you decide to delete the most
730recent one.
b3bf02fa
RS
731
732To yank words from the text of the buffer and use them as part of the
9aef3b21 733bookmark name, type C-w while setting a bookmark. Successive C-w's
b3bf02fa
RS
734yank successive words.
735
4c0b5ad1
KF
736Typing C-u inserts the name of the last bookmark used in the buffer
737\(as an aid in using a single bookmark name to track your progress
738through a large file\). If no bookmark was used, then C-u inserts the
739name of the file being visited.
b3bf02fa
RS
740
741Use \\[bookmark-delete] to remove bookmarks \(you give it a name,
742and it removes only the first instance of a bookmark with that name from
743the list of bookmarks.\)"
4eadcdf8 744 (interactive (list nil current-prefix-arg))
e3437989
RS
745 (or
746 (bookmark-buffer-file-name)
a3ad20c2 747 (error "Buffer not visiting a file or directory"))
e3437989
RS
748
749 (bookmark-maybe-load-default-file)
750
b3bf02fa
RS
751 (setq bookmark-current-point (point))
752 (setq bookmark-yank-point (point))
753 (setq bookmark-current-buffer (current-buffer))
e3437989 754
d22d6453 755 (let* ((default (or bookmark-current-bookmark
e3437989 756 (bookmark-buffer-name)))
d22d6453 757 (str
4eadcdf8
RS
758 (or name
759 (read-from-minibuffer
760 (format "Set bookmark (%s): " default)
761 nil
762 (let ((now-map (copy-keymap minibuffer-local-map)))
91169ba7
RS
763 (define-key now-map "\C-w" 'bookmark-yank-word)
764 (define-key now-map "\C-u" 'bookmark-insert-current-bookmark)
4eadcdf8 765 now-map))))
e3437989
RS
766 (annotation nil))
767 (and (string-equal str "") (setq str default))
dbe99ae9 768 ;; Ask for an annotation buffer for this bookmark
e3437989
RS
769 (if bookmark-use-annotations
770 (bookmark-read-annotation parg str)
91169ba7
RS
771 (bookmark-make str annotation parg (bookmark-info-current-node))
772 (setq bookmark-current-bookmark str)
773 (bookmark-bmenu-surreptitiously-rebuild-list)
774 (goto-char bookmark-current-point))))
e3437989
RS
775
776
a15269c0
KF
777(defun bookmark-info-current-node ()
778 "If in Info-mode, return current node name (a string), else nil."
779 (if (eq major-mode 'Info-mode)
780 Info-current-node))
781
782
e3437989
RS
783(defun bookmark-kill-line (&optional newline-too)
784 "Kill from point to end of line.
785If optional arg NEWLINE-TOO is non-nil, delete the newline too.
786Does not affect the kill-ring."
787 (let ((eol (save-excursion (end-of-line) (point))))
788 (delete-region (point) eol)
789 (if (and newline-too (looking-at "\n"))
790 (delete-char 1))))
791
792
4c0b5ad1
KF
793;; Defvars to avoid compilation warnings:
794(defvar bookmark-annotation-paragraph nil)
795(defvar bookmark-annotation-name nil)
796(defvar bookmark-annotation-buffer nil)
797(defvar bookmark-annotation-file nil)
798(defvar bookmark-annotation-point nil)
799
800
e3437989 801(defun bookmark-send-annotation ()
5e0e5feb
RS
802 "Use buffer contents as the annotation for a bookmark.
803Exclude lines that begin with `#'.
804Store the annotation text in the bookmark list with
e3437989
RS
805the bookmark (and file, and point) specified in buffer local variables."
806 (interactive)
807 (if (not (eq major-mode 'bookmark-read-annotation-mode))
a3ad20c2 808 (error "Not in bookmark-read-annotation-mode"))
e3437989
RS
809 (goto-char (point-min))
810 (while (< (point) (point-max))
811 (if (looking-at "^#")
812 (bookmark-kill-line t)
813 (forward-line 1)))
91169ba7 814 (let ((annotation (buffer-string))
e3437989
RS
815 (parg bookmark-annotation-paragraph)
816 (bookmark bookmark-annotation-name)
817 (pt bookmark-annotation-point)
818 (buf bookmark-annotation-buffer))
819 ;; for bookmark-make-cell to work, we need to be
820 ;; in the relevant buffer, at the relevant point.
821 ;; Actually, bookmark-make-cell should probably be re-written,
822 ;; to avoid this need. Should I handle the error if a buffer is
823 ;; killed between "C-x r m" and a "C-c C-c" in the annotation buffer?
dbe99ae9 824 (save-excursion
e3437989
RS
825 (pop-to-buffer buf)
826 (goto-char pt)
a15269c0 827 (bookmark-make bookmark annotation parg (bookmark-info-current-node))
e3437989
RS
828 (setq bookmark-current-bookmark bookmark))
829 (bookmark-bmenu-surreptitiously-rebuild-list)
830 (goto-char bookmark-current-point))
831 (kill-buffer (current-buffer)))
832
833
834(defun bookmark-default-annotation-text (bookmark)
835 (concat "# Type the annotation for bookmark '" bookmark "' here.\n"
836 "# All lines which start with a '#' will be deleted.\n"
837 "# Type C-c C-c when done.\n#\n"
838 "# Author: " (user-full-name) " <" (user-login-name) "@"
839 (system-name) ">\n"
840 "# Date: " (current-time-string) "\n"))
841
842
843(defvar bookmark-read-annotation-text-func 'bookmark-default-annotation-text
5e0e5feb
RS
844 "Function to return default text to use for a bookmark annotation.
845It takes the name of the bookmark, as a string, as an arg.")
e3437989
RS
846
847(defun bookmark-read-annotation-mode (buf point parg bookmark)
848 "Mode for composing annotations for a bookmark.
4eadcdf8 849Wants BUF POINT PARG and BOOKMARK.
e3437989
RS
850When you have finished composing, type \\[bookmark-send-annotation] to send
851the annotation.
852
853\\{bookmark-read-annotation-mode-map}
854"
855 (interactive)
856 (kill-all-local-variables)
857 (make-local-variable 'bookmark-annotation-paragraph)
858 (make-local-variable 'bookmark-annotation-name)
859 (make-local-variable 'bookmark-annotation-buffer)
860 (make-local-variable 'bookmark-annotation-file)
861 (make-local-variable 'bookmark-annotation-point)
862 (setq bookmark-annotation-paragraph parg)
863 (setq bookmark-annotation-name bookmark)
864 (setq bookmark-annotation-buffer buf)
865 (setq bookmark-annotation-file (buffer-file-name buf))
866 (setq bookmark-annotation-point point)
867 (use-local-map bookmark-read-annotation-mode-map)
868 (setq major-mode 'bookmark-read-annotation-mode)
869 (insert (funcall bookmark-read-annotation-text-func bookmark))
f33cee85 870 (run-mode-hooks 'text-mode-hook))
e3437989
RS
871
872
873(defun bookmark-read-annotation (parg bookmark)
5e0e5feb
RS
874 "Pop up a buffer for entering a bookmark annotation.
875Text surrounding the bookmark is PARG; the bookmark name is BOOKMARK."
e3437989
RS
876 (let ((buf (current-buffer))
877 (point (point)))
878 (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
879 (bookmark-read-annotation-mode buf point parg bookmark)))
880
881
882(defvar bookmark-edit-annotation-mode-map (copy-keymap text-mode-map)
883 "Keymap for editing an annotation of a bookmark.")
884
885
886(define-key bookmark-edit-annotation-mode-map "\C-c\C-c"
887 'bookmark-send-edited-annotation)
888
889
890(defun bookmark-edit-annotation-mode (bookmark)
891 "Mode for editing the annotation of bookmark BOOKMARK.
892When you have finished composing, type \\[bookmark-send-annotation].
893
894\\{bookmark-edit-annotation-mode-map}
895"
896 (interactive)
897 (kill-all-local-variables)
898 (make-local-variable 'bookmark-annotation-name)
899 (setq bookmark-annotation-name bookmark)
900 (use-local-map bookmark-edit-annotation-mode-map)
dc5dcc00
JB
901 (setq major-mode 'bookmark-edit-annotation-mode
902 mode-name "Edit Bookmark Annotation")
e3437989
RS
903 (insert (funcall bookmark-read-annotation-text-func bookmark))
904 (let ((annotation (bookmark-get-annotation bookmark)))
91169ba7 905 (if (and annotation (not (string-equal annotation "")))
e3437989 906 (insert annotation)))
f33cee85 907 (run-mode-hooks 'text-mode-hook))
e3437989
RS
908
909
910(defun bookmark-send-edited-annotation ()
dc5dcc00
JB
911 "Use buffer contents as annotation for a bookmark.
912Lines beginning with `#' are ignored."
e3437989
RS
913 (interactive)
914 (if (not (eq major-mode 'bookmark-edit-annotation-mode))
a3ad20c2 915 (error "Not in bookmark-edit-annotation-mode"))
e3437989
RS
916 (goto-char (point-min))
917 (while (< (point) (point-max))
918 (if (looking-at "^#")
919 (bookmark-kill-line t)
920 (forward-line 1)))
91169ba7 921 (let ((annotation (buffer-string))
e3437989
RS
922 (bookmark bookmark-annotation-name))
923 (bookmark-set-annotation bookmark annotation)
924 (bookmark-bmenu-surreptitiously-rebuild-list)
925 (goto-char bookmark-current-point))
926 (kill-buffer (current-buffer)))
927
928
929(defun bookmark-edit-annotation (bookmark)
930 "Pop up a buffer for editing bookmark BOOKMARK's annotation."
175d0960
SM
931 (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
932 (bookmark-edit-annotation-mode bookmark))
e3437989 933
b3bf02fa
RS
934
935(defun bookmark-insert-current-bookmark ()
5e0e5feb
RS
936 "Insert this buffer's value of bookmark-current-bookmark.
937Default to file name if it's nil."
b3bf02fa
RS
938 (interactive)
939 (let ((str
940 (save-excursion
941 (set-buffer bookmark-current-buffer)
942 bookmark-current-bookmark)))
4cd51172 943 (if str (insert str) (bookmark-insert-buffer-name))))
b3bf02fa 944
e3437989 945
4cd51172 946(defun bookmark-insert-buffer-name ()
5e0e5feb
RS
947 "Insert the current file name into the bookmark name being set.
948The directory part of the file name is not used."
b3bf02fa 949 (interactive)
e3437989
RS
950 (let ((str
951 (save-excursion
952 (set-buffer bookmark-current-buffer)
4cd51172 953 (bookmark-buffer-name))))
e3437989
RS
954 (insert str)))
955
b3bf02fa 956
4cd51172
RS
957(defun bookmark-buffer-name ()
958 "Return the name of the current buffer's file, non-directory.
959In Info, return the current node."
960 (cond
961 ;; Are we in Info?
962 ((string-equal mode-name "Info") Info-current-node)
963 ;; Or are we a file?
964 (buffer-file-name (file-name-nondirectory buffer-file-name))
965 ;; Or are we a directory?
966 ((and (boundp 'dired-directory) dired-directory)
967 (let* ((dirname (if (stringp dired-directory)
968 dired-directory
969 (car dired-directory)))
970 (idx (1- (length dirname))))
971 ;; Strip the trailing slash.
972 (if (= ?/ (aref dirname idx))
973 (file-name-nondirectory (substring dirname 0 idx))
974 ;; Else return the current-buffer
975 (buffer-name (current-buffer)))))
976 ;; If all else fails, use the buffer's name.
977 (t
978 (buffer-name (current-buffer)))))
979
980
b3bf02fa
RS
981(defun bookmark-yank-word ()
982 (interactive)
983 ;; get the next word from the buffer and append it to the name of
984 ;; the bookmark currently being set.
985 (let ((string (save-excursion
d22d6453
RS
986 (set-buffer bookmark-current-buffer)
987 (goto-char bookmark-yank-point)
88415bfc 988 (buffer-substring-no-properties
d22d6453 989 (point)
91169ba7 990 (progn
d22d6453
RS
991 (forward-word 1)
992 (setq bookmark-yank-point (point)))))))
b3bf02fa
RS
993 (insert string)))
994
b3bf02fa
RS
995
996(defun bookmark-buffer-file-name ()
e3437989
RS
997 "Return the current buffer's file in a way useful for bookmarks.
998For example, if this is a Info buffer, return the Info file's name."
999 (if (eq major-mode 'Info-mode)
1000 Info-current-file
1001 (or
1002 buffer-file-name
1003 (if (and (boundp 'dired-directory) dired-directory)
1004 (if (stringp dired-directory)
1005 dired-directory
1006 (car dired-directory))))))
1007
1008
e3437989 1009(defun bookmark-maybe-load-default-file ()
d22d6453
RS
1010 (and (not bookmarks-already-loaded)
1011 (null bookmark-alist)
e3437989
RS
1012 (prog2
1013 (and
1014 ;; Possibly the old bookmark file, "~/.emacs-bkmrks", needs
1015 ;; to be renamed.
1016 (file-exists-p (expand-file-name bookmark-old-default-file))
1017 (not (file-exists-p (expand-file-name bookmark-default-file)))
1018 (rename-file (expand-file-name bookmark-old-default-file)
1019 (expand-file-name bookmark-default-file)))
1020 ;; return t so the `and' will continue...
1021 t)
dbe99ae9 1022
e3437989 1023 (file-readable-p (expand-file-name bookmark-default-file))
91169ba7
RS
1024 (bookmark-load bookmark-default-file t t)
1025 (setq bookmarks-already-loaded t)))
d22d6453 1026
e3437989 1027
d22d6453
RS
1028(defun bookmark-maybe-sort-alist ()
1029 ;;Return the bookmark-alist for display. If the bookmark-sort-flag
1030 ;;is non-nil, then return a sorted copy of the alist.
1031 (if bookmark-sort-flag
1032 (setq bookmark-alist
1033 (sort (copy-alist bookmark-alist)
1034 (function
1035 (lambda (x y) (string-lessp (car x) (car y))))))))
1036
e3437989 1037
d22d6453 1038;;;###autoload
4eadcdf8 1039(defun bookmark-jump (bookmark)
dbe99ae9 1040 "Jump to bookmark BOOKMARK (a point in some file).
9aef3b21
RS
1041You may have a problem using this function if the value of variable
1042`bookmark-alist' is nil. If that happens, you need to load in some
1043bookmarks. See help on function `bookmark-load' for more about
d22d6453
RS
1044this.
1045
e3437989
RS
1046If the file pointed to by BOOKMARK no longer exists, you will be asked
1047if you wish to give the bookmark a new location, and bookmark-jump
1048will then jump to the new location, as well as recording it in place
1049of the old one in the permanent bookmark record."
1050 (interactive
175d0960
SM
1051 (list (bookmark-completing-read "Jump to bookmark"
1052 bookmark-current-bookmark)))
5d8d3a34
RS
1053 (unless bookmark
1054 (error "No bookmark specified"))
4eadcdf8
RS
1055 (bookmark-maybe-historicize-string bookmark)
1056 (let ((cell (bookmark-jump-noselect bookmark)))
d22d6453
RS
1057 (and cell
1058 (switch-to-buffer (car cell))
e3437989 1059 (goto-char (cdr cell))
2c9ad69f
KF
1060 (if bookmark-automatically-show-annotations
1061 ;; if there is an annotation for this bookmark,
1062 ;; show it in a buffer.
4eadcdf8 1063 (bookmark-show-annotation bookmark)))))
e3437989 1064
d22d6453 1065
8d56596c 1066(defun bookmark-file-or-variation-thereof (file)
76bc6ee3
KF
1067 "Return FILE (a string) if it exists, or return a reasonable
1068variation of FILE if that exists. Reasonable variations are checked
1069by appending suffixes defined in `Info-suffix-list'. If cannot find FILE
1070nor a reasonable variation thereof, then still return FILE if it can
1071be retrieved from a VC backend, else return nil."
dd33e6e9
KF
1072 (if (file-exists-p file)
1073 file
76bc6ee3
KF
1074 (or
1075 (progn (require 'info) ; ensure Info-suffix-list is bound
1076 (catch 'found
1077 (mapc (lambda (elt)
1078 (let ((suffixed-file (concat file (car elt))))
1079 (if (file-exists-p suffixed-file)
1080 (throw 'found suffixed-file))))
1081 Info-suffix-list)
1082 nil))
1083 ;; Last possibility: try VC
1084 (if (vc-backend file) file))))
1085
8d56596c 1086
d22d6453
RS
1087(defun bookmark-jump-noselect (str)
1088 ;; a leetle helper for bookmark-jump :-)
1089 ;; returns (BUFFER . POINT)
e3437989
RS
1090 (bookmark-maybe-load-default-file)
1091 (let* ((file (expand-file-name (bookmark-get-filename str)))
1092 (forward-str (bookmark-get-front-context-string str))
1093 (behind-str (bookmark-get-rear-context-string str))
1094 (place (bookmark-get-position str))
1095 (info-node (bookmark-get-info-node str))
1096 (orig-file file)
1097 )
8d56596c 1098 (if (setq file (bookmark-file-or-variation-thereof file))
e3437989 1099 (save-excursion
e197b151
RS
1100 (save-window-excursion
1101 (if info-node
1102 ;; Info nodes must be visited with care.
1103 (progn
1104 (require 'info)
1105 (Info-find-node file info-node))
1106 ;; Else no Info. Can do an ordinary find-file:
1107 (set-buffer (find-file-noselect file))
1108 (goto-char place))
1109
1110 ;; Go searching forward first. Then, if forward-str exists and
1111 ;; was found in the file, we can search backward for behind-str.
1112 ;; Rationale is that if text was inserted between the two in the
1113 ;; file, it's better to be put before it so you can read it,
1114 ;; rather than after and remain perhaps unaware of the changes.
1115 (if forward-str
1116 (if (search-forward forward-str (point-max) t)
1117 (goto-char (match-beginning 0))))
1118 (if behind-str
1119 (if (search-backward behind-str (point-min) t)
1120 (goto-char (match-end 0))))
1121 ;; added by db
1122 (setq bookmark-current-bookmark str)
1123 (cons (current-buffer) (point))))
1124
91169ba7
RS
1125 ;; Else unable to find the marked file, so ask if user wants to
1126 ;; relocate the bookmark, else remind them to consider deletion.
1127 (ding)
1128 (if (y-or-n-p (concat (file-name-nondirectory orig-file)
1129 " nonexistent. Relocate \""
1130 str
1131 "\"? "))
1132 (progn
1133 (bookmark-relocate str)
1134 ;; gasp! It's a recursive function call in Emacs Lisp!
1135 (bookmark-jump-noselect str))
dbe99ae9 1136 (message
91169ba7
RS
1137 "Bookmark not relocated; consider removing it \(%s\)." str)
1138 nil))))
e3437989 1139
d22d6453
RS
1140
1141;;;###autoload
4eadcdf8 1142(defun bookmark-relocate (bookmark)
5e0e5feb
RS
1143 "Relocate BOOKMARK to another file (reading file name with minibuffer).
1144This makes an already existing bookmark point to that file, instead of
1145the one it used to point at. Useful when a file has been renamed
1146after a bookmark was set in it."
175d0960 1147 (interactive (list (bookmark-completing-read "Bookmark to relocate")))
4eadcdf8 1148 (bookmark-maybe-historicize-string bookmark)
e3437989 1149 (bookmark-maybe-load-default-file)
4eadcdf8 1150 (let* ((bmrk-filename (bookmark-get-filename bookmark))
d22d6453 1151 (newloc (expand-file-name
e3437989 1152 (read-file-name
4eadcdf8 1153 (format "Relocate %s to: " bookmark)
e3437989 1154 (file-name-directory bmrk-filename)))))
91169ba7
RS
1155 (bookmark-set-filename bookmark newloc)
1156 (bookmark-bmenu-surreptitiously-rebuild-list)))
e3437989 1157
d22d6453
RS
1158
1159;;;###autoload
4eadcdf8 1160(defun bookmark-insert-location (bookmark &optional no-history)
4c0b5ad1
KF
1161 "Insert the name of the file associated with BOOKMARK.
1162Optional second arg NO-HISTORY means don't record this in the
1163minibuffer history list `bookmark-history'."
175d0960 1164 (interactive (list (bookmark-completing-read "Insert bookmark location")))
4eadcdf8 1165 (or no-history (bookmark-maybe-historicize-string bookmark))
7e510a5e
RS
1166 (let ((start (point)))
1167 (prog1
1168 (insert (bookmark-location bookmark)) ; *Return this line*
59cfe8b9 1169 (if (and (display-color-p) (display-mouse-p))
2fbb6576
EZ
1170 (add-text-properties start
1171 (save-excursion (re-search-backward
1172 "[^ \t]")
1173 (1+ (point)))
1174 '(mouse-face highlight
1175 help-echo "mouse-2: go to this bookmark"))))))
e3437989 1176
fbd98d61 1177;;;###autoload
a15269c0 1178(defalias 'bookmark-locate 'bookmark-insert-location)
e3437989 1179
4eadcdf8 1180(defun bookmark-location (bookmark)
e3437989
RS
1181 "Return the name of the file associated with BOOKMARK."
1182 (bookmark-maybe-load-default-file)
4eadcdf8 1183 (bookmark-get-filename bookmark))
e3437989 1184
d22d6453
RS
1185
1186;;;###autoload
9aef3b21 1187(defun bookmark-rename (old &optional new)
5e0e5feb
RS
1188 "Change the name of OLD bookmark to NEW name.
1189If called from keyboard, prompt for OLD and NEW. If called from
1190menubar, select OLD from a menu and prompt for NEW.
4eadcdf8 1191
5e0e5feb 1192If called from Lisp, prompt for NEW if only OLD was passed as an
4eadcdf8
RS
1193argument. If called with two strings, then no prompting is done. You
1194must pass at least OLD when calling from Lisp.
9aef3b21
RS
1195
1196While you are entering the new name, consecutive C-w's insert
3b526bae 1197consecutive words from the text of the buffer into the new bookmark
4c0b5ad1 1198name."
175d0960 1199 (interactive (list (bookmark-completing-read "Old bookmark name")))
4c0b5ad1 1200 (bookmark-maybe-historicize-string old)
e3437989 1201 (bookmark-maybe-load-default-file)
91169ba7
RS
1202
1203 (setq bookmark-current-point (point))
1204 (setq bookmark-yank-point (point))
1205 (setq bookmark-current-buffer (current-buffer))
1206 (let ((newname
1207 (or new ; use second arg, if non-nil
1208 (read-from-minibuffer
1209 "New name: "
1210 nil
1211 (let ((now-map (copy-keymap minibuffer-local-map)))
1212 (define-key now-map "\C-w" 'bookmark-yank-word)
1213 now-map)
1214 nil
1215 'bookmark-history))))
1216 (bookmark-set-name old newname)
1217 (setq bookmark-current-bookmark newname)
1218 (bookmark-bmenu-surreptitiously-rebuild-list)
1219 (setq bookmark-alist-modification-count
1220 (1+ bookmark-alist-modification-count))
1221 (if (bookmark-time-to-save-p)
1222 (bookmark-save))))
b3bf02fa 1223
e3437989 1224
d22d6453 1225;;;###autoload
4eadcdf8 1226(defun bookmark-insert (bookmark)
dbe99ae9 1227 "Insert the text of the file pointed to by bookmark BOOKMARK.
9aef3b21
RS
1228You may have a problem using this function if the value of variable
1229`bookmark-alist' is nil. If that happens, you need to load in some
1230bookmarks. See help on function `bookmark-load' for more about
8027e2ad 1231this."
175d0960 1232 (interactive (list (bookmark-completing-read "Insert bookmark contents")))
4eadcdf8 1233 (bookmark-maybe-historicize-string bookmark)
e3437989 1234 (bookmark-maybe-load-default-file)
d22d6453
RS
1235 (let ((orig-point (point))
1236 (str-to-insert
1237 (save-excursion
4eadcdf8 1238 (set-buffer (car (bookmark-jump-noselect bookmark)))
91169ba7 1239 (buffer-string))))
d22d6453
RS
1240 (insert str-to-insert)
1241 (push-mark)
1242 (goto-char orig-point)))
1243
e3437989 1244
d22d6453 1245;;;###autoload
e3437989 1246(defun bookmark-delete (bookmark &optional batch)
dbe99ae9 1247 "Delete BOOKMARK from the bookmark list.
9aef3b21
RS
1248Removes only the first instance of a bookmark with that name. If
1249there are one or more other bookmarks with the same name, they will
1250not be deleted. Defaults to the \"current\" bookmark \(that is, the
e3437989
RS
1251one most recently used in this file, if any\).
1252Optional second arg BATCH means don't update the bookmark list buffer,
1253probably because we were called from there."
1254 (interactive
175d0960
SM
1255 (list (bookmark-completing-read "Delete bookmark"
1256 bookmark-current-bookmark)))
4c0b5ad1 1257 (bookmark-maybe-historicize-string bookmark)
e3437989
RS
1258 (bookmark-maybe-load-default-file)
1259 (let ((will-go (bookmark-get-bookmark bookmark)))
11eb4275
RS
1260 (setq bookmark-alist (delq will-go bookmark-alist))
1261 ;; Added by db, nil bookmark-current-bookmark if the last
3b526bae 1262 ;; occurrence has been deleted
e3437989 1263 (or (bookmark-get-bookmark bookmark-current-bookmark)
11eb4275 1264 (setq bookmark-current-bookmark nil)))
e3437989
RS
1265 ;; Don't rebuild the list
1266 (if batch
1267 nil
1268 (bookmark-bmenu-surreptitiously-rebuild-list)
1269 (setq bookmark-alist-modification-count
1270 (1+ bookmark-alist-modification-count))
1271 (if (bookmark-time-to-save-p)
1272 (bookmark-save))))
1273
b3bf02fa
RS
1274
1275(defun bookmark-time-to-save-p (&optional last-time)
1276 ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu>
1277 ;; finds out whether it's time to save bookmarks to a file, by
1278 ;; examining the value of variable bookmark-save-flag, and maybe
1279 ;; bookmark-alist-modification-count. Returns t if they should be
1280 ;; saved, nil otherwise. if last-time is non-nil, then this is
1281 ;; being called when emacs is killed.
dbe99ae9 1282 (cond (last-time
b3bf02fa
RS
1283 (and (> bookmark-alist-modification-count 0)
1284 bookmark-save-flag))
1285 ((numberp bookmark-save-flag)
1286 (>= bookmark-alist-modification-count bookmark-save-flag))
1287 (t
1288 nil)))
1289
e3437989 1290
d22d6453 1291;;;###autoload
b3bf02fa 1292(defun bookmark-write ()
5e0e5feb
RS
1293 "Write bookmarks to a file (reading the file name with the minibuffer).
1294Don't use this in Lisp programs; use `bookmark-save' instead."
b3bf02fa 1295 (interactive)
e3437989 1296 (bookmark-maybe-load-default-file)
b3bf02fa
RS
1297 (bookmark-save t))
1298
e3437989 1299
d22d6453 1300;;;###autoload
dbe99ae9 1301(defun bookmark-save (&optional parg file)
9aef3b21
RS
1302 "Save currently defined bookmarks.
1303Saves by default in the file defined by the variable
4eadcdf8
RS
1304`bookmark-default-file'. With a prefix arg, save it in file FILE
1305\(second argument\).
b3bf02fa
RS
1306
1307If you are calling this from Lisp, the two arguments are PREFIX-ARG
1308and FILE, and if you just want it to write to the default file, then
1309pass no arguments. Or pass in nil and FILE, and it will save in FILE
1310instead. If you pass in one argument, and it is non-nil, then the
1311user will be interactively queried for a file to save in.
1312
11eb4275 1313When you want to load in the bookmarks from a file, use
9aef3b21 1314\`bookmark-load\', \\[bookmark-load]. That function will prompt you
11eb4275 1315for a file, defaulting to the file defined by variable
e3437989 1316`bookmark-default-file'."
b3bf02fa 1317 (interactive "P")
e3437989 1318 (bookmark-maybe-load-default-file)
b3bf02fa
RS
1319 (cond
1320 ((and (null parg) (null file))
1321 ;;whether interactive or not, write to default file
e3437989 1322 (bookmark-write-file bookmark-default-file))
b3bf02fa
RS
1323 ((and (null parg) file)
1324 ;;whether interactive or not, write to given file
1325 (bookmark-write-file file))
1326 ((and parg (not file))
1327 ;;have been called interactively w/ prefix arg
1328 (let ((file (read-file-name "File to save bookmarks in: ")))
1329 (bookmark-write-file file)))
1330 (t ; someone called us with prefix-arg *and* a file, so just write to file
1331 (bookmark-write-file file)))
1332 ;; signal that we have synced the bookmark file by setting this to
1333 ;; 0. If there was an error at any point before, it will not get
1334 ;; set, which is what we want.
1335 (setq bookmark-alist-modification-count 0))
1336
e3437989
RS
1337
1338\f
b3bf02fa
RS
1339(defun bookmark-write-file (file)
1340 (save-excursion
d22d6453
RS
1341 (save-window-excursion
1342 (if (>= baud-rate 9600)
bd0e5b36 1343 (message "Saving bookmarks to file %s..." file))
186a7127 1344 (set-buffer (let ((enable-local-variables nil))
d23e2c3f 1345 (find-file-noselect file)))
d22d6453 1346 (goto-char (point-min))
8a946354 1347 (let ((print-length nil)
1672462f
GM
1348 (print-level nil))
1349 (delete-region (point-min) (point-max))
1350 (bookmark-insert-file-format-version-stamp)
1351 (pp bookmark-alist (current-buffer))
1352 (let ((version-control
1353 (cond
1354 ((null bookmark-version-control) nil)
1355 ((eq 'never bookmark-version-control) 'never)
1356 ((eq 'nospecial bookmark-version-control) version-control)
1357 (t
1358 t))))
9552bee8
KF
1359 (condition-case nil
1360 (write-file file)
1361 (file-error (message "Can't write %s" file)))
1672462f
GM
1362 (kill-buffer (current-buffer))
1363 (if (>= baud-rate 9600)
1364 (message "Saving bookmarks to file %s...done" file)))))))
e3437989 1365
d22d6453 1366
91169ba7
RS
1367(defun bookmark-import-new-list (new-list)
1368 ;; Walk over the new list, adding each individual bookmark
1369 ;; carefully. "Carefully" means checking against the existing
1370 ;; bookmark-alist and renaming the new bookmarks with <N> extensions
1371 ;; as necessary.
1372 (let ((lst new-list)
1373 (names (bookmark-all-names)))
1374 (while lst
1375 (let* ((full-record (car lst)))
1376 (bookmark-maybe-rename full-record names)
1377 (setq bookmark-alist (nconc bookmark-alist (list full-record)))
1378 (setq names (cons (bookmark-name-from-full-record full-record) names))
1379 (setq lst (cdr lst))))))
1380
1381
1382(defun bookmark-maybe-rename (full-record names)
1383 ;; just a helper for bookmark-import-new-list; it is only for
1384 ;; readability that this is not inlined.
1385 ;;
1386 ;; Once this has found a free name, it sets full-record to that
1387 ;; name.
1388 (let ((found-name (bookmark-name-from-full-record full-record)))
1389 (if (member found-name names)
1390 ;; We've got a conflict, so generate a new name
1391 (let ((count 2)
1392 (new-name found-name))
1393 (while (member new-name names)
1394 (setq new-name (concat found-name (format "<%d>" count)))
1395 (setq count (1+ count)))
1396 (bookmark-set-name full-record new-name)))))
1397
1398
d22d6453 1399;;;###autoload
91169ba7 1400(defun bookmark-load (file &optional overwrite no-msg)
9aef3b21
RS
1401 "Load bookmarks from FILE (which must be in bookmark format).
1402Appends loaded bookmarks to the front of the list of bookmarks. If
91169ba7 1403optional second argument OVERWRITE is non-nil, existing bookmarks are
9aef3b21
RS
1404destroyed. Optional third arg NO-MSG means don't display any messages
1405while loading.
b3bf02fa
RS
1406
1407If you load a file that doesn't contain a proper bookmark alist, you
9aef3b21 1408will corrupt Emacs's bookmark list. Generally, you should only load
b3bf02fa 1409in files that were created with the bookmark functions in the first
e3437989 1410place. Your own personal bookmark file, `~/.emacs.bmk', is
8027e2ad 1411maintained automatically by Emacs; you shouldn't need to load it
91169ba7
RS
1412explicitly.
1413
1414If you load a file containing bookmarks with the same names as
1415bookmarks already present in your Emacs, the new bookmarks will get
1416unique numeric suffixes \"<2>\", \"<3>\", ... following the same
1417method buffers use to resolve name collisions."
b3bf02fa 1418 (interactive
e3437989
RS
1419 (list (read-file-name
1420 (format "Load bookmarks from: (%s) "
dbe99ae9 1421 bookmark-default-file)
e3437989
RS
1422 ;;Default might not be used often,
1423 ;;but there's no better default, and
1424 ;;I guess it's better than none at all.
1425 "~/" bookmark-default-file 'confirm)))
b3bf02fa
RS
1426 (setq file (expand-file-name file))
1427 (if (file-readable-p file)
1428 (save-excursion
d22d6453
RS
1429 (save-window-excursion
1430 (if (and (null no-msg) (>= baud-rate 9600))
bd0e5b36 1431 (message "Loading bookmarks from %s..." file))
186a7127 1432 (set-buffer (let ((enable-local-variables nil))
d23e2c3f 1433 (find-file-noselect file)))
d22d6453 1434 (goto-char (point-min))
e3437989
RS
1435 (bookmark-maybe-upgrade-file-format)
1436 (let ((blist (bookmark-alist-from-buffer)))
d22d6453
RS
1437 (if (listp blist)
1438 (progn
91169ba7
RS
1439 (if overwrite
1440 (progn
1441 (setq bookmark-alist blist)
1442 (setq bookmark-alist-modification-count 0))
1443 ;; else
1444 (bookmark-import-new-list blist)
1445 (setq bookmark-alist-modification-count
1446 (1+ bookmark-alist-modification-count)))
1447 (if (string-equal
1448 (expand-file-name bookmark-default-file)
1449 file)
1450 (setq bookmarks-already-loaded t))
dbe99ae9 1451 (bookmark-bmenu-surreptitiously-rebuild-list))
a3ad20c2 1452 (error "Invalid bookmark list in %s" file)))
d22d6453
RS
1453 (kill-buffer (current-buffer)))
1454 (if (and (null no-msg) (>= baud-rate 9600))
bd0e5b36 1455 (message "Loading bookmarks from %s...done" file)))
a3ad20c2 1456 (error "Cannot read bookmark file %s" file)))
b3bf02fa 1457
d22d6453 1458
e3437989
RS
1459\f
1460;;; Code supporting the dired-like bookmark menu. Prefix is
1461;;; "bookmark-bmenu" for "buffer-menu":
1462
1463
1464(defvar bookmark-bmenu-bookmark-column nil)
d22d6453 1465
d22d6453 1466
e3437989
RS
1467(defvar bookmark-bmenu-hidden-bookmarks ())
1468
1469
e3437989 1470(defvar bookmark-bmenu-mode-map nil)
d22d6453 1471
d22d6453 1472
e3437989 1473(if bookmark-bmenu-mode-map
d22d6453 1474 nil
e3437989
RS
1475 (setq bookmark-bmenu-mode-map (make-keymap))
1476 (suppress-keymap bookmark-bmenu-mode-map t)
31cd9611 1477 (define-key bookmark-bmenu-mode-map "q" 'quit-window)
e3437989
RS
1478 (define-key bookmark-bmenu-mode-map "v" 'bookmark-bmenu-select)
1479 (define-key bookmark-bmenu-mode-map "w" 'bookmark-bmenu-locate)
1480 (define-key bookmark-bmenu-mode-map "2" 'bookmark-bmenu-2-window)
1481 (define-key bookmark-bmenu-mode-map "1" 'bookmark-bmenu-1-window)
1482 (define-key bookmark-bmenu-mode-map "j" 'bookmark-bmenu-this-window)
fbd98d61 1483 (define-key bookmark-bmenu-mode-map "\C-c\C-c" 'bookmark-bmenu-this-window)
e3437989 1484 (define-key bookmark-bmenu-mode-map "f" 'bookmark-bmenu-this-window)
74002bdf 1485 (define-key bookmark-bmenu-mode-map "\C-m" 'bookmark-bmenu-this-window)
e3437989 1486 (define-key bookmark-bmenu-mode-map "o" 'bookmark-bmenu-other-window)
fbd98d61
KF
1487 (define-key bookmark-bmenu-mode-map "\C-o"
1488 'bookmark-bmenu-switch-other-window)
e3437989
RS
1489 (define-key bookmark-bmenu-mode-map "s" 'bookmark-bmenu-save)
1490 (define-key bookmark-bmenu-mode-map "k" 'bookmark-bmenu-delete)
1491 (define-key bookmark-bmenu-mode-map "\C-d" 'bookmark-bmenu-delete-backwards)
1492 (define-key bookmark-bmenu-mode-map "x" 'bookmark-bmenu-execute-deletions)
e3437989
RS
1493 (define-key bookmark-bmenu-mode-map "d" 'bookmark-bmenu-delete)
1494 (define-key bookmark-bmenu-mode-map " " 'next-line)
1495 (define-key bookmark-bmenu-mode-map "n" 'next-line)
1496 (define-key bookmark-bmenu-mode-map "p" 'previous-line)
1497 (define-key bookmark-bmenu-mode-map "\177" 'bookmark-bmenu-backup-unmark)
1498 (define-key bookmark-bmenu-mode-map "?" 'describe-mode)
1499 (define-key bookmark-bmenu-mode-map "u" 'bookmark-bmenu-unmark)
1500 (define-key bookmark-bmenu-mode-map "m" 'bookmark-bmenu-mark)
dbe99ae9 1501 (define-key bookmark-bmenu-mode-map "l" 'bookmark-bmenu-load)
e3437989 1502 (define-key bookmark-bmenu-mode-map "r" 'bookmark-bmenu-rename)
037b0a87 1503 (define-key bookmark-bmenu-mode-map "R" 'bookmark-bmenu-relocate)
e3437989
RS
1504 (define-key bookmark-bmenu-mode-map "t" 'bookmark-bmenu-toggle-filenames)
1505 (define-key bookmark-bmenu-mode-map "a" 'bookmark-bmenu-show-annotation)
1506 (define-key bookmark-bmenu-mode-map "A" 'bookmark-bmenu-show-all-annotations)
7e510a5e
RS
1507 (define-key bookmark-bmenu-mode-map "e" 'bookmark-bmenu-edit-annotation)
1508 (define-key bookmark-bmenu-mode-map [mouse-2]
1509 'bookmark-bmenu-other-window-with-mouse))
e3437989 1510
dbe99ae9 1511
e3437989
RS
1512
1513;; Bookmark Buffer Menu mode is suitable only for specially formatted
1514;; data.
1515(put 'bookmark-bmenu-mode 'mode-class 'special)
1516
1517
1518;; todo: need to display whether or not bookmark exists as a buffer in
dbe99ae9 1519;; flag column.
d22d6453
RS
1520
1521;; Format:
e3437989
RS
1522;; FLAGS BOOKMARK [ LOCATION ]
1523
1524
1525(defun bookmark-bmenu-surreptitiously-rebuild-list ()
1526 "Rebuild the Bookmark List if it exists.
1527Don't affect the buffer ring order."
1528 (if (get-buffer "*Bookmark List*")
1529 (save-excursion
dbe99ae9 1530 (save-window-excursion
e3437989 1531 (bookmark-bmenu-list)))))
d22d6453 1532
d22d6453
RS
1533
1534;;;###autoload
e3437989 1535(defun bookmark-bmenu-list ()
d22d6453
RS
1536 "Display a list of existing bookmarks.
1537The list is displayed in a buffer named `*Bookmark List*'.
e3437989
RS
1538The leftmost column displays a D if the bookmark is flagged for
1539deletion, or > if it is flagged for displaying."
d22d6453 1540 (interactive)
e3437989
RS
1541 (bookmark-maybe-load-default-file)
1542 (if (interactive-p)
1543 (switch-to-buffer (get-buffer-create "*Bookmark List*"))
1544 (set-buffer (get-buffer-create "*Bookmark List*")))
175d0960
SM
1545 (let ((inhibit-read-only t))
1546 (erase-buffer)
d22d6453
RS
1547 (insert "% Bookmark\n- --------\n")
1548 (bookmark-maybe-sort-alist)
e3437989
RS
1549 (mapcar
1550 (lambda (full-record)
3b526bae 1551 ;; if a bookmark has an annotation, prepend a "*"
e3437989
RS
1552 ;; in the list of bookmarks.
1553 (let ((annotation (bookmark-get-annotation
1554 (bookmark-name-from-full-record full-record))))
91169ba7 1555 (if (and annotation (not (string-equal annotation "")))
e3437989
RS
1556 (insert " *")
1557 (insert " "))
7e510a5e
RS
1558 (let ((start (point)))
1559 (insert (bookmark-name-from-full-record full-record))
59cfe8b9 1560 (if (and (display-color-p) (display-mouse-p))
2fbb6576
EZ
1561 (add-text-properties start
1562 (save-excursion (re-search-backward
1563 "[^ \t]")
1564 (1+ (point)))
1565 '(mouse-face highlight
1566 help-echo "mouse-2: go to this bookmark")))
7e510a5e
RS
1567 (insert "\n")
1568 )))
e3437989 1569 bookmark-alist))
d22d6453
RS
1570 (goto-char (point-min))
1571 (forward-line 2)
e3437989
RS
1572 (bookmark-bmenu-mode)
1573 (if bookmark-bmenu-toggle-filenames
1574 (bookmark-bmenu-toggle-filenames t)))
1575
1576;;;###autoload
1577(defalias 'list-bookmarks 'bookmark-bmenu-list)
1578;;;###autoload
1579(defalias 'edit-bookmarks 'bookmark-bmenu-list)
d22d6453 1580
e3437989
RS
1581
1582
1583(defun bookmark-bmenu-mode ()
d22d6453
RS
1584 "Major mode for editing a list of bookmarks.
1585Each line describes one of the bookmarks in Emacs.
1586Letters do not insert themselves; instead, they are commands.
3b526bae 1587Bookmark names preceded by a \"*\" have annotations.
e3437989
RS
1588\\<bookmark-bmenu-mode-map>
1589\\[bookmark-bmenu-mark] -- mark bookmark to be displayed.
1590\\[bookmark-bmenu-select] -- select bookmark of line point is on.
1591 Also show bookmarks marked using m in other windows.
1592\\[bookmark-bmenu-toggle-filenames] -- toggle displaying of filenames (they may obscure long bookmark names).
1593\\[bookmark-bmenu-locate] -- display (in minibuffer) location of this bookmark.
1594\\[bookmark-bmenu-1-window] -- select this bookmark in full-frame window.
1595\\[bookmark-bmenu-2-window] -- select this bookmark in one window,
d22d6453 1596 together with bookmark selected before this one in another window.
e3437989
RS
1597\\[bookmark-bmenu-this-window] -- select this bookmark in place of the bookmark menu buffer.
1598\\[bookmark-bmenu-other-window] -- select this bookmark in another window,
d22d6453 1599 so the bookmark menu bookmark remains visible in its window.
e3437989 1600\\[bookmark-bmenu-switch-other-window] -- switch the other window to this bookmark.
dbe99ae9 1601\\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).
037b0a87 1602\\[bookmark-bmenu-relocate] -- relocate this bookmark's file \(prompts for new file\).
e3437989 1603\\[bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
dbe99ae9 1604\\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
60d0378e 1605\\[bookmark-bmenu-execute-deletions] -- delete bookmarks marked with `\\[bookmark-bmenu-delete]'.
e3437989 1606\\[bookmark-bmenu-save] -- save the current bookmark list in the default file.
d22d6453 1607 With a prefix arg, prompts for a file to save in.
e3437989
RS
1608\\[bookmark-bmenu-load] -- load in a file of bookmarks (prompts for file.)
1609\\[bookmark-bmenu-unmark] -- remove all kinds of marks from current line.
d22d6453 1610 With prefix argument, also move up one line.
e3437989
RS
1611\\[bookmark-bmenu-backup-unmark] -- back up a line and remove marks.
1612\\[bookmark-bmenu-show-annotation] -- show the annotation, if it exists, for the current bookmark
1613 in another buffer.
1614\\[bookmark-bmenu-show-all-annotations] -- show the annotations of all bookmarks in another buffer.
1615\\[bookmark-bmenu-edit-annotation] -- edit the annotation for the current bookmark."
d22d6453 1616 (kill-all-local-variables)
e3437989 1617 (use-local-map bookmark-bmenu-mode-map)
d22d6453
RS
1618 (setq truncate-lines t)
1619 (setq buffer-read-only t)
e3437989 1620 (setq major-mode 'bookmark-bmenu-mode)
d22d6453 1621 (setq mode-name "Bookmark Menu")
f33cee85 1622 (run-mode-hooks 'bookmark-bmenu-mode-hook))
d22d6453 1623
e3437989 1624
4eadcdf8 1625(defun bookmark-bmenu-toggle-filenames (&optional show)
d22d6453
RS
1626 "Toggle whether filenames are shown in the bookmark list.
1627Optional argument SHOW means show them unconditionally."
1628 (interactive)
1629 (cond
4eadcdf8 1630 (show
e3437989
RS
1631 (setq bookmark-bmenu-toggle-filenames nil)
1632 (bookmark-bmenu-show-filenames)
1633 (setq bookmark-bmenu-toggle-filenames t))
1634 (bookmark-bmenu-toggle-filenames
1635 (bookmark-bmenu-hide-filenames)
1636 (setq bookmark-bmenu-toggle-filenames nil))
d22d6453 1637 (t
e3437989
RS
1638 (bookmark-bmenu-show-filenames)
1639 (setq bookmark-bmenu-toggle-filenames t))))
1640
d22d6453 1641
e3437989
RS
1642(defun bookmark-bmenu-show-filenames (&optional force)
1643 (if (and (not force) bookmark-bmenu-toggle-filenames)
d22d6453
RS
1644 nil ;already shown, so do nothing
1645 (save-excursion
1646 (save-window-excursion
1647 (goto-char (point-min))
1648 (forward-line 2)
e3437989 1649 (setq bookmark-bmenu-hidden-bookmarks ())
175d0960 1650 (let ((inhibit-read-only t))
d22d6453 1651 (while (< (point) (point-max))
e3437989
RS
1652 (let ((bmrk (bookmark-bmenu-bookmark)))
1653 (setq bookmark-bmenu-hidden-bookmarks
1654 (cons bmrk bookmark-bmenu-hidden-bookmarks))
7e510a5e
RS
1655 (let ((start (save-excursion (end-of-line) (point))))
1656 (move-to-column bookmark-bmenu-file-column t)
1657 ;; Strip off `mouse-face' from the white spaces region.
59cfe8b9 1658 (if (and (display-color-p) (display-mouse-p))
7e510a5e 1659 (remove-text-properties start (point)
2fbb6576 1660 '(mouse-face nil help-echo nil))))
7e510a5e 1661 (delete-region (point) (progn (end-of-line) (point)))
d22d6453 1662 (insert " ")
4c0b5ad1
KF
1663 ;; Pass the NO-HISTORY arg:
1664 (bookmark-insert-location bmrk t)
d22d6453
RS
1665 (forward-line 1))))))))
1666
e3437989
RS
1667
1668(defun bookmark-bmenu-hide-filenames (&optional force)
1669 (if (and (not force) bookmark-bmenu-toggle-filenames)
d22d6453
RS
1670 ;; nothing to hide if above is nil
1671 (save-excursion
1672 (save-window-excursion
1673 (goto-char (point-min))
1674 (forward-line 2)
e3437989
RS
1675 (setq bookmark-bmenu-hidden-bookmarks
1676 (nreverse bookmark-bmenu-hidden-bookmarks))
d22d6453
RS
1677 (save-excursion
1678 (goto-char (point-min))
1679 (search-forward "Bookmark")
1680 (backward-word 1)
e3437989 1681 (setq bookmark-bmenu-bookmark-column (current-column)))
d22d6453 1682 (save-excursion
175d0960 1683 (let ((inhibit-read-only t))
e3437989
RS
1684 (while bookmark-bmenu-hidden-bookmarks
1685 (move-to-column bookmark-bmenu-bookmark-column t)
1686 (bookmark-kill-line)
7e510a5e
RS
1687 (let ((start (point)))
1688 (insert (car bookmark-bmenu-hidden-bookmarks))
59cfe8b9 1689 (if (and (display-color-p) (display-mouse-p))
2fbb6576
EZ
1690 (add-text-properties start
1691 (save-excursion (re-search-backward
1692 "[^ \t]")
1693 (1+ (point)))
1694 '(mouse-face highlight
1695 help-echo
1696 "mouse-2: go to this bookmark"))))
e3437989
RS
1697 (setq bookmark-bmenu-hidden-bookmarks
1698 (cdr bookmark-bmenu-hidden-bookmarks))
d22d6453
RS
1699 (forward-line 1))))))))
1700
e3437989 1701
e3437989 1702(defun bookmark-bmenu-check-position ()
91169ba7
RS
1703 ;; Returns non-nil if on a line with a bookmark.
1704 ;; (The actual value returned is bookmark-alist).
1705 ;; Else reposition and try again, else return nil.
d22d6453
RS
1706 (cond ((< (count-lines (point-min) (point)) 2)
1707 (goto-char (point-min))
1708 (forward-line 2)
91169ba7 1709 bookmark-alist)
d22d6453
RS
1710 ((and (bolp) (eobp))
1711 (beginning-of-line 0)
91169ba7 1712 bookmark-alist)
d22d6453 1713 (t
91169ba7 1714 bookmark-alist)))
d22d6453 1715
e3437989
RS
1716
1717(defun bookmark-bmenu-bookmark ()
d22d6453 1718 ;; return a string which is bookmark of this line.
e3437989 1719 (if (bookmark-bmenu-check-position)
d22d6453
RS
1720 (save-excursion
1721 (save-window-excursion
1722 (goto-char (point-min))
1723 (search-forward "Bookmark")
1724 (backward-word 1)
e3437989
RS
1725 (setq bookmark-bmenu-bookmark-column (current-column)))))
1726 (if bookmark-bmenu-toggle-filenames
1727 (bookmark-bmenu-hide-filenames))
d22d6453
RS
1728 (save-excursion
1729 (save-window-excursion
1730 (beginning-of-line)
e3437989 1731 (forward-char bookmark-bmenu-bookmark-column)
d22d6453 1732 (prog1
dbe99ae9
SS
1733 (buffer-substring-no-properties (point)
1734 (progn
d22d6453
RS
1735 (end-of-line)
1736 (point)))
1737 ;; well, this is certainly crystal-clear:
e3437989
RS
1738 (if bookmark-bmenu-toggle-filenames
1739 (bookmark-bmenu-toggle-filenames t))))))
d22d6453 1740
e3437989
RS
1741
1742(defun bookmark-show-annotation (bookmark)
1743 "Display the annotation for bookmark named BOOKMARK in a buffer,
1744if an annotation exists."
1745 (let ((annotation (bookmark-get-annotation bookmark)))
91169ba7
RS
1746 (if (and annotation (not (string-equal annotation "")))
1747 (save-excursion
1748 (let ((old-buf (current-buffer)))
1749 (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
1750 (delete-region (point-min) (point-max))
1751 ;; (insert (concat "Annotation for bookmark '" bookmark "':\n\n"))
1752 (insert annotation)
1753 (goto-char (point-min))
1754 (pop-to-buffer old-buf))))))
e3437989
RS
1755
1756
1757(defun bookmark-show-all-annotations ()
1758 "Display the annotations for all bookmarks in a buffer."
1759 (let ((old-buf (current-buffer)))
1760 (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
1761 (delete-region (point-min) (point-max))
1762 (mapcar
1763 (lambda (full-record)
1764 (let* ((name (bookmark-name-from-full-record full-record))
1765 (ann (bookmark-get-annotation name)))
1766 (insert (concat name ":\n"))
91169ba7 1767 (if (and ann (not (string-equal ann "")))
e3437989
RS
1768 ;; insert the annotation, indented by 4 spaces.
1769 (progn
1770 (save-excursion (insert ann))
1771 (while (< (point) (point-max))
1772 (beginning-of-line) ; paranoia
1773 (insert " ")
1774 (forward-line)
1775 (end-of-line))))))
1776 bookmark-alist)
1777 (goto-char (point-min))
1778 (pop-to-buffer old-buf)))
1779
1780
1781(defun bookmark-bmenu-mark ()
5e0e5feb 1782 "Mark bookmark on this line to be displayed by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-select]."
d22d6453
RS
1783 (interactive)
1784 (beginning-of-line)
e3437989 1785 (if (bookmark-bmenu-check-position)
175d0960 1786 (let ((inhibit-read-only t))
d22d6453
RS
1787 (delete-char 1)
1788 (insert ?>)
91169ba7
RS
1789 (forward-line 1)
1790 (bookmark-bmenu-check-position))))
d22d6453 1791
e3437989
RS
1792
1793(defun bookmark-bmenu-select ()
d22d6453 1794 "Select this line's bookmark; also display bookmarks marked with `>'.
e3437989 1795You can mark bookmarks with the \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-mark] command."
d22d6453 1796 (interactive)
e3437989
RS
1797 (if (bookmark-bmenu-check-position)
1798 (let ((bmrk (bookmark-bmenu-bookmark))
dbe99ae9 1799 (menu (current-buffer))
d22d6453
RS
1800 (others ())
1801 tem)
1802 (goto-char (point-min))
1803 (while (re-search-forward "^>" nil t)
e3437989 1804 (setq tem (bookmark-bmenu-bookmark))
175d0960 1805 (let ((inhibit-read-only t))
d22d6453
RS
1806 (delete-char -1)
1807 (insert ?\ ))
dbe99ae9
SS
1808 (or (string-equal tem bmrk)
1809 (member tem others)
d22d6453
RS
1810 (setq others (cons tem others))))
1811 (setq others (nreverse others)
1812 tem (/ (1- (frame-height)) (1+ (length others))))
1813 (delete-other-windows)
1814 (bookmark-jump bmrk)
1815 (bury-buffer menu)
4eadcdf8
RS
1816 (if others
1817 (while others
1818 (split-window nil tem)
1819 (other-window 1)
1820 (bookmark-jump (car others))
1821 (setq others (cdr others)))
d22d6453
RS
1822 (other-window 1)))))
1823
e3437989
RS
1824
1825(defun bookmark-bmenu-save (parg)
d22d6453
RS
1826 "Save the current list into a bookmark file.
1827With a prefix arg, prompts for a file to save them in."
1828 (interactive "P")
1829 (save-excursion
1830 (save-window-excursion
1831 (bookmark-save parg))))
1832
e3437989
RS
1833
1834(defun bookmark-bmenu-load ()
1835 "Load the bookmark file and rebuild the bookmark menu-buffer."
d22d6453 1836 (interactive)
e3437989 1837 (if (bookmark-bmenu-check-position)
d22d6453
RS
1838 (save-excursion
1839 (save-window-excursion
e3437989 1840 ;; This will call `bookmark-bmenu-list'
d22d6453
RS
1841 (call-interactively 'bookmark-load)))))
1842
e3437989
RS
1843
1844(defun bookmark-bmenu-1-window ()
d22d6453
RS
1845 "Select this line's bookmark, alone, in full frame."
1846 (interactive)
e3437989 1847 (if (bookmark-bmenu-check-position)
d22d6453 1848 (progn
e3437989 1849 (bookmark-jump (bookmark-bmenu-bookmark))
d22d6453
RS
1850 (bury-buffer (other-buffer))
1851 (delete-other-windows))))
1852
e3437989
RS
1853
1854(defun bookmark-bmenu-2-window ()
d22d6453
RS
1855 "Select this line's bookmark, with previous buffer in second window."
1856 (interactive)
e3437989
RS
1857 (if (bookmark-bmenu-check-position)
1858 (let ((bmrk (bookmark-bmenu-bookmark))
d22d6453
RS
1859 (menu (current-buffer))
1860 (pop-up-windows t))
1861 (delete-other-windows)
1862 (switch-to-buffer (other-buffer))
e40e3151
KF
1863 (let* ((pair (bookmark-jump-noselect bmrk))
1864 (buff (car pair))
1865 (pos (cdr pair)))
1866 (pop-to-buffer buff)
1867 (goto-char pos))
d22d6453
RS
1868 (bury-buffer menu))))
1869
e3437989
RS
1870
1871(defun bookmark-bmenu-this-window ()
d22d6453
RS
1872 "Select this line's bookmark in this window."
1873 (interactive)
e3437989
RS
1874 (if (bookmark-bmenu-check-position)
1875 (bookmark-jump (bookmark-bmenu-bookmark))))
d22d6453 1876
e3437989
RS
1877
1878(defun bookmark-bmenu-other-window ()
d22d6453
RS
1879 "Select this line's bookmark in other window, leaving bookmark menu visible."
1880 (interactive)
e3437989
RS
1881 (let ((bookmark (bookmark-bmenu-bookmark)))
1882 (if (bookmark-bmenu-check-position)
e40e3151
KF
1883 (let* ((pair (bookmark-jump-noselect bookmark))
1884 (buff (car pair))
1885 (pos (cdr pair)))
e3437989 1886 (switch-to-buffer-other-window buff)
e40e3151
KF
1887 (goto-char pos)
1888 (set-window-point (get-buffer-window buff) pos)
1889 (bookmark-show-annotation bookmark)))))
1890
1891
1892(defun bookmark-bmenu-switch-other-window ()
1893 "Make the other window select this line's bookmark.
1894The current window remains selected."
1895 (interactive)
e197b151
RS
1896 (let ((bookmark (bookmark-bmenu-bookmark))
1897 (pop-up-windows t)
dbe99ae9 1898 same-window-buffer-names
e197b151 1899 same-window-regexps)
e40e3151
KF
1900 (if (bookmark-bmenu-check-position)
1901 (let* ((pair (bookmark-jump-noselect bookmark))
1902 (buff (car pair))
1903 (pos (cdr pair)))
1904 (display-buffer buff)
1905 (let ((o-buffer (current-buffer)))
1906 ;; save-excursion won't do
1907 (set-buffer buff)
1908 (goto-char pos)
1909 (set-window-point (get-buffer-window buff) pos)
1910 (set-buffer o-buffer))
e3437989
RS
1911 (bookmark-show-annotation bookmark)))))
1912
7e510a5e
RS
1913(defun bookmark-bmenu-other-window-with-mouse (event)
1914 "Select bookmark at the mouse pointer in other window, leaving bookmark menu visible."
1915 (interactive "e")
1916 (save-excursion
1917 (set-buffer (window-buffer (posn-window (event-end event))))
1918 (save-excursion
1919 (goto-char (posn-point (event-end event)))
1920 (bookmark-bmenu-other-window))))
1921
e3437989
RS
1922
1923(defun bookmark-bmenu-show-annotation ()
1924 "Show the annotation for the current bookmark in another window."
1925 (interactive)
1926 (let ((bookmark (bookmark-bmenu-bookmark)))
1927 (if (bookmark-bmenu-check-position)
1928 (bookmark-show-annotation bookmark))))
d22d6453 1929
e3437989
RS
1930
1931(defun bookmark-bmenu-show-all-annotations ()
1932 "Show the annotation for all bookmarks in another window."
1933 (interactive)
1934 (bookmark-show-all-annotations))
1935
1936
1937(defun bookmark-bmenu-edit-annotation ()
1938 "Edit the annotation for the current bookmark in another window."
1939 (interactive)
1940 (let ((bookmark (bookmark-bmenu-bookmark)))
1941 (if (bookmark-bmenu-check-position)
1942 (bookmark-edit-annotation bookmark))))
1943
1944
e3437989 1945(defun bookmark-bmenu-unmark (&optional backup)
d22d6453 1946 "Cancel all requested operations on bookmark on this line and move down.
4eadcdf8 1947Optional BACKUP means move up."
d22d6453
RS
1948 (interactive "P")
1949 (beginning-of-line)
e3437989 1950 (if (bookmark-bmenu-check-position)
d22d6453 1951 (progn
175d0960 1952 (let ((inhibit-read-only t))
d22d6453
RS
1953 (delete-char 1)
1954 ;; any flags to reset according to circumstances? How about a
1955 ;; flag indicating whether this bookmark is being visited?
1956 ;; well, we don't have this now, so maybe later.
1957 (insert " "))
91169ba7
RS
1958 (forward-line (if backup -1 1))
1959 (bookmark-bmenu-check-position))))
d22d6453 1960
e3437989
RS
1961
1962(defun bookmark-bmenu-backup-unmark ()
d22d6453
RS
1963 "Move up and cancel all requested operations on bookmark on line above."
1964 (interactive)
1965 (forward-line -1)
e3437989 1966 (if (bookmark-bmenu-check-position)
d22d6453 1967 (progn
e3437989 1968 (bookmark-bmenu-unmark)
91169ba7
RS
1969 (forward-line -1)
1970 (bookmark-bmenu-check-position))))
d22d6453 1971
e3437989
RS
1972
1973(defun bookmark-bmenu-delete ()
5e0e5feb
RS
1974 "Mark bookmark on this line to be deleted.
1975To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions]."
d22d6453
RS
1976 (interactive)
1977 (beginning-of-line)
e3437989 1978 (if (bookmark-bmenu-check-position)
175d0960 1979 (let ((inhibit-read-only t))
d22d6453
RS
1980 (delete-char 1)
1981 (insert ?D)
91169ba7
RS
1982 (forward-line 1)
1983 (bookmark-bmenu-check-position))))
d22d6453 1984
e3437989
RS
1985
1986(defun bookmark-bmenu-delete-backwards ()
5e0e5feb
RS
1987 "Mark bookmark on this line to be deleted, then move up one line.
1988To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions]."
d22d6453 1989 (interactive)
e3437989 1990 (bookmark-bmenu-delete)
d22d6453 1991 (forward-line -2)
e3437989 1992 (if (bookmark-bmenu-check-position)
91169ba7
RS
1993 (forward-line 1))
1994 (bookmark-bmenu-check-position))
d22d6453 1995
e3437989
RS
1996
1997(defun bookmark-bmenu-execute-deletions ()
d22d6453
RS
1998 "Delete bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
1999 (interactive)
60d0378e 2000 (message "Deleting bookmarks...")
e3437989
RS
2001 (let ((hide-em bookmark-bmenu-toggle-filenames)
2002 (o-point (point))
2003 (o-str (save-excursion
2004 (beginning-of-line)
2005 (if (looking-at "^D")
2006 nil
2007 (buffer-substring
2008 (point)
2009 (progn (end-of-line) (point))))))
2010 (o-col (current-column)))
2011 (if hide-em (bookmark-bmenu-hide-filenames))
2012 (setq bookmark-bmenu-toggle-filenames nil)
d22d6453
RS
2013 (goto-char (point-min))
2014 (forward-line 1)
e3437989
RS
2015 (while (re-search-forward "^D" (point-max) t)
2016 (bookmark-delete (bookmark-bmenu-bookmark) t)) ; pass BATCH arg
2017 (bookmark-bmenu-list)
2018 (setq bookmark-bmenu-toggle-filenames hide-em)
2019 (if bookmark-bmenu-toggle-filenames
2020 (bookmark-bmenu-toggle-filenames t))
2021 (if o-str
2022 (progn
2023 (goto-char (point-min))
2024 (search-forward o-str)
2025 (beginning-of-line)
2026 (forward-char o-col))
2027 (goto-char o-point))
2028 (beginning-of-line)
2029 (setq bookmark-alist-modification-count
2030 (1+ bookmark-alist-modification-count))
2031 (if (bookmark-time-to-save-p)
60d0378e
KF
2032 (bookmark-save))
2033 (message "Deleting bookmarks...done")
2034 ))
e3437989
RS
2035
2036
2037(defun bookmark-bmenu-rename ()
d22d6453
RS
2038 "Rename bookmark on current line. Prompts for a new name."
2039 (interactive)
e3437989
RS
2040 (if (bookmark-bmenu-check-position)
2041 (let ((bmrk (bookmark-bmenu-bookmark))
d22d6453
RS
2042 (thispoint (point)))
2043 (bookmark-rename bmrk)
e3437989 2044 (bookmark-bmenu-list)
d22d6453
RS
2045 (goto-char thispoint))))
2046
e3437989
RS
2047
2048(defun bookmark-bmenu-locate ()
d22d6453
RS
2049 "Display location of this bookmark. Displays in the minibuffer."
2050 (interactive)
e3437989
RS
2051 (if (bookmark-bmenu-check-position)
2052 (let ((bmrk (bookmark-bmenu-bookmark)))
2053 (message (bookmark-location bmrk)))))
2054
037b0a87
KF
2055(defun bookmark-bmenu-relocate ()
2056 "Change the file path of the bookmark on the current line,
2057 prompting with completion for the new path."
2058 (interactive)
2059 (if (bookmark-bmenu-check-position)
2060 (let ((bmrk (bookmark-bmenu-bookmark))
2061 (thispoint (point)))
2062 (bookmark-relocate bmrk)
2063 (goto-char thispoint))))
d22d6453 2064
e3437989
RS
2065\f
2066;;; Menu bar stuff. Prefix is "bookmark-menu".
11eb4275 2067
e3437989
RS
2068(defun bookmark-menu-popup-paned-menu (event name entries)
2069 "Pop up multi-paned menu at EVENT, return string chosen from ENTRIES.
2070That is, ENTRIES is a list of strings which appear as the choices
2071in the menu.
175d0960
SM
2072The number of panes depends on the number of entries.
2073The visible entries are truncated to `bookmark-menu-length', but the
2074strings returned are not."
2075 (let ((f-height (/ (frame-height) 2))
2076 (pane-list nil)
2077 (iter 0))
2078 (while entries
2079 (let (lst
2080 (count 0))
2081 (while (and (< count f-height) entries)
2082 (let ((str (car entries)))
2083 (push (cons
2084 (if (> (length str) bookmark-menu-length)
2085 (substring str 0 bookmark-menu-length)
2086 str)
2087 str)
2088 lst)
2089 (setq entries (cdr entries))
2090 (setq count (1+ count))))
2091 (setq iter (1+ iter))
2092 (push (cons
2093 (format "-*- %s (%d) -*-" name iter)
2094 (nreverse lst))
2095 pane-list)))
2096
2097 ;; Popup the menu and return the string.
2098 (x-popup-menu event (cons (concat "-*- " name " -*-")
2099 (nreverse pane-list)))))
e3437989 2100
b3bf02fa 2101
d22d6453
RS
2102;; Thanks to Roland McGrath for fixing menubar.el so that the
2103;; following works, and for explaining what to do to make it work.
b3bf02fa 2104
7af04c89
RS
2105;; We MUST autoload EACH form used to set up this variable's value, so
2106;; that the whole job is done in loaddefs.el.
b3bf02fa 2107
5e0e5feb 2108;; Emacs menubar stuff.
09fd6588 2109
7af04c89 2110;;;###autoload
175d0960
SM
2111(defvar menu-bar-bookmark-map
2112 (let ((map (make-sparse-keymap "Bookmark functions")))
2113 (define-key map [load] '("Load a Bookmark File..." . bookmark-load))
2114 (define-key map [write] '("Save Bookmarks As..." . bookmark-write))
2115 (define-key map [save] '("Save Bookmarks" . bookmark-save))
2116 (define-key map [edit] '("Edit Bookmark List" . bookmark-bmenu-list))
b2a664c0
JL
2117 (define-key map [delete] '("Delete Bookmark..." . bookmark-delete))
2118 (define-key map [rename] '("Rename Bookmark..." . bookmark-rename))
2119 (define-key map [locate] '("Insert Location..." . bookmark-locate))
2120 (define-key map [insert] '("Insert Contents..." . bookmark-insert))
2121 (define-key map [set] '("Set Bookmark..." . bookmark-set))
2122 (define-key map [jump] '("Jump to Bookmark..." . bookmark-jump))
175d0960 2123 map))
09fd6588 2124
7af04c89 2125;;;###autoload
175d0960 2126(defalias 'menu-bar-bookmark-map menu-bar-bookmark-map)
e3437989 2127
09fd6588
KF
2128;; make bookmarks appear toward the right side of the menu.
2129(if (boundp 'menu-bar-final-items)
dbe99ae9 2130 (if menu-bar-final-items
09fd6588
KF
2131 (setq menu-bar-final-items
2132 (cons 'bookmark menu-bar-final-items)))
2133 (setq menu-bar-final-items '(bookmark)))
2134
e3437989
RS
2135;;;; end bookmark menu stuff ;;;;
2136
2137\f
2138;;; Load Hook
2139(defvar bookmark-load-hook nil
175d0960 2140 "Hook run at the end of loading bookmark.")
e3437989 2141
6192b604
KF
2142;;; Exit Hook, called from kill-emacs-hook
2143(defvar bookmark-exit-hook nil
175d0960 2144 "Hook run when emacs exits.")
dbe99ae9 2145
6192b604
KF
2146(defun bookmark-exit-hook-internal ()
2147 "Save bookmark state, if necessary, at Emacs exit time.
2148This also runs `bookmark-exit-hooks'."
175d0960
SM
2149 (run-hooks 'bookmark-exit-hooks)
2150 (and bookmark-alist
2151 (bookmark-time-to-save-p t)
2152 (bookmark-save)))
6192b604
KF
2153
2154(add-hook 'kill-emacs-hook 'bookmark-exit-hook-internal)
2155
2156
e3437989 2157(run-hooks 'bookmark-load-hook)
b3bf02fa 2158
b3bf02fa 2159(provide 'bookmark)
dbe99ae9 2160
ab5796a9 2161;;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6
11eb4275 2162;;; bookmark.el ends here