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