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