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