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