aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-10-13 05:59:54 +0000
committerRichard M. Stallman1993-10-13 05:59:54 +0000
commitd22d6453de00a5fb2628f16c56777e2af2e31cd4 (patch)
tree2d4c8c6da8d65f3d0bfa125c4817d4c2b9194300
parent292297c66e228c4e87b8491b55ef6094a4167500 (diff)
downloademacs-d22d6453de00a5fb2628f16c56777e2af2e31cd4.tar.gz
emacs-d22d6453de00a5fb2628f16c56777e2af2e31cd4.zip
(bookmark-write): Add numbered backups for bookmark file.
(bookmark-version-control): New variable. (bookmark-jump): bookmark-jump now gives a default value if no bookmark is entered manually. (bookmark-set): Default to bookmark-current-bookmark or buffer-name the way bookmark-jump does. (ctl-x-map): Check if C-x r is a prefix before using it as one. Include string "Bookmarks" in defining [menu-bar bookmark] in global-map in the menu-bar code. (menu-bar-bookmark-map): Supply t as 4th arg of autoload. (bookmark-jump-noselect): New subroutine taken from bookmark-jump. Support compressed files. (bookmark-jump): Call bookmark-jump-noselect. Offer to relocate if necessary, but change default dir to that of the old bookmark in read-file-name. (bookmark-set, bookmark-rename, bookmark-delete, bookmark-write-file, bookmark-load, Bookmark-menu-show-filenames, Bookmark-menu-hide-filenames, Bookmark-menu-bookmark, Bookmark-menu-save, Bookmark-menu-load): Fixed the save-excursion bugs by wrapping things in save-window-excursion as well. (bookmark-make-menu-bar-alist): Added sorting. (bookmark-map): Added new keybindings. (bookmark-try-default-file): Set bookmarks-already-loaded to t after the load. (list-bookmarks): Added bookmark menu stuff. (Bookmark-menu-*): New functions.
-rw-r--r--lisp/bookmark.el1120
1 files changed, 824 insertions, 296 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 21a9243736c..620b4ab6032 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1,11 +1,11 @@
1;;; bookmark.el --- set bookmarks, jump to them later. 1;;; bookmark.el --- set bookmarks, jump to them later.
2 2
3;; Copyright (C) 1993 Free Software Foundation, Inc. 3;; Copyright (C) 1993 Free Software Foundation
4 4
5;; Author: Karl Fogel <kfogel@cs.oberlin.edu> 5;; Author: Karl Fogel <kfogel@cs.oberlin.edu>
6;; Maintainer: Karl Fogel <kfogel@cs.oberlin.edu> 6;; Maintainer: Karl Fogel <kfogel@cs.oberlin.edu>
7;; Created: July, 1993 7;; Created: July, 1993
8;; Version: 1.7.3 (interim) 8;; Version: 2.4
9;; Keywords: bookmarks, placeholders 9;; Keywords: bookmarks, placeholders
10 10
11;; This file is part of GNU Emacs. 11;; This file is part of GNU Emacs.
@@ -31,13 +31,23 @@
31;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for 31;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for
32;; fixing and improving bookmark-time-to-save-p. 32;; fixing and improving bookmark-time-to-save-p.
33 33
34;; And much thanks to David Hughes <djh@harston.cv.com> for many small
35;; suggestions and the code to implement them (like
36;; Bookmark-menu-check-position, and some of the Lucid compatibility
37;; stuff).
38
39;; Thanks to Roland McGrath for encouragement and help with defining
40;; autoloads on the menu-bar.
41
34;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad 42;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
35;; <olstad@msc.edu>. 43;; <olstad@msc.edu>.
36 44
37;; LCD Archive Entry: 45;; LCD Archive Entry:
38;; bookmark|Karl Fogel|kfogel@cs.oberlin.edu| 46;; bookmark|Karl Fogel|kfogel@cs.oberlin.edu|
39;; Setting bookmarks in files or directories, jumping to them later.| 47;; Setting bookmarks in files or directories, jumping to them later.|
40;; 16-July-93|Version: 1.7.2|~/misc/bookmark.el.Z| 48;; 16-July-93|Version: 2.4|~/misc/bookmark.el.Z|
49
50;; Enough with the credits already, get on to the good stuff:
41 51
42;; FAVORITE CHINESE RESTAURANT: 52;; FAVORITE CHINESE RESTAURANT:
43;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's 53;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's
@@ -63,25 +73,34 @@
63;; set. It will attempt to place the user before the changes, if 73;; set. It will attempt to place the user before the changes, if
64;; there were any. 74;; there were any.
65;; 75;;
66;; It is not advisable to sort the bookmark list when it is presented 76;; The bookmark list is sorted lexically by default, but you can turn
67;; to the user, because it is already sorted in what is probably the 77;; this off by setting bookmark-sort-flag to nil. If it is nil, then
68;; most useful way: order of creation, with most recently created 78;; the list will be presented in the order it is recorded
69;; bookmarks coming first and older ones toward the end (renaming does 79;; (chronologically), which is actually fairly useful as well.
70;; not count as creating) -- which is what we want, most of the time.
71 80
72;;; Code: 81;;; Code:
73 82
74;; Added for lucid emacs compatibility, db 83;; Added for lucid emacs compatibility, db
75(or (fboundp 'defalias) (fset 'defalias 'fset)) 84(or (fboundp 'defalias) (fset 'defalias 'fset))
76 85
77;; these are the distribution keybindings suggested by RMS, everything 86;; suggested for lucid compatibility by david hughes:
87(or (fboundp 'frame-height) (fset 'frame-height 'screen-height))
88
89;; some people have C-x r set to rmail or whatever. We don't want to
90;; assume that C-x r is a prefix map just because it's distributed
91;; that way...
92;; These are the distribution keybindings suggested by RMS, everything
78;; else will be done with M-x or the menubar: 93;; else will be done with M-x or the menubar:
79(define-key ctl-x-map "rb" 'bookmark-jump) 94;;;###autoload
80(define-key ctl-x-map "rm" 'bookmark-set) 95(if (symbolp (key-binding "\C-xr"))
81(define-key ctl-x-map "rl" 'bookmark-locate) 96 nil
97 (progn (define-key ctl-x-map "rb" 'bookmark-jump)
98 (define-key ctl-x-map "rm" 'bookmark-set)
99 (define-key ctl-x-map "rl" 'list-bookmarks)))
82 100
83;; define the map, so it can be bound by those who desire to do so: 101;; define the map, so it can be bound by those who desire to do so:
84 102
103;;;###autoload
85(defvar bookmark-map nil 104(defvar bookmark-map nil
86 "Keymap containing bindings to bookmark functions. 105 "Keymap containing bindings to bookmark functions.
87It is not bound to any key by default: to bind it 106It is not bound to any key by default: to bind it
@@ -89,21 +108,33 @@ so that you have a bookmark prefix, just use `global-set-key' and bind a
89key of your choice to `bookmark-map'. All interactive bookmark 108key of your choice to `bookmark-map'. All interactive bookmark
90functions have a binding in this keymap.") 109functions have a binding in this keymap.")
91 110
111;;;###autoload
92(define-prefix-command 'bookmark-map) 112(define-prefix-command 'bookmark-map)
93 113
94;; Read the help on all of these functions for details... 114;; Read the help on all of these functions for details...
95;; "x" marks the spot! 115;;;###autoload
96(define-key bookmark-map "x" 'bookmark-set) 116(define-key bookmark-map "x" 'bookmark-set)
117;;;###autoload
118(define-key bookmark-map "m" 'bookmark-set) ; "m" for "mark"
119;;;###autoload
97(define-key bookmark-map "j" 'bookmark-jump) 120(define-key bookmark-map "j" 'bookmark-jump)
121;;;###autoload
122(define-key bookmark-map "g" 'bookmark-jump) ; "g" for "go"
123;;;###autoload
98(define-key bookmark-map "i" 'bookmark-insert) 124(define-key bookmark-map "i" 'bookmark-insert)
125;;;###autoload
126(define-key bookmark-map "e" 'edit-bookmarks)
127;;;###autoload
99(define-key bookmark-map "f" 'bookmark-locate) ; "f" for "find" 128(define-key bookmark-map "f" 'bookmark-locate) ; "f" for "find"
129;;;###autoload
100(define-key bookmark-map "r" 'bookmark-rename) 130(define-key bookmark-map "r" 'bookmark-rename)
101;; deletes bookmarks 131;;;###autoload
102(define-key bookmark-map "d" 'bookmark-delete) 132(define-key bookmark-map "d" 'bookmark-delete)
103;; loads new file 133;;;###autoload
104(define-key bookmark-map "l" 'bookmark-load) 134(define-key bookmark-map "l" 'bookmark-load)
105;; saves them in file 135;;;###autoload
106(define-key bookmark-map "w" 'bookmark-write) 136(define-key bookmark-map "w" 'bookmark-write)
137;;;###autoload
107(define-key bookmark-map "s" 'bookmark-save) 138(define-key bookmark-map "s" 'bookmark-save)
108 139
109(defvar bookmark-alist () 140(defvar bookmark-alist ()
@@ -111,18 +142,20 @@ functions have a binding in this keymap.")
111You probably don't want to change the value of this alist yourself; 142You probably don't want to change the value of this alist yourself;
112instead, let the various bookmark functions do it for you.") 143instead, let the various bookmark functions do it for you.")
113 144
145(defvar bookmarks-already-loaded nil)
146
114;; just add the hook to make sure that people don't lose bookmarks 147;; just add the hook to make sure that people don't lose bookmarks
115;; when they kill Emacs, unless they don't want to save them. 148;; when they kill Emacs, unless they don't want to save them.
116 149;;;###autoload
117(add-hook 'kill-emacs-hook 150(add-hook 'kill-emacs-hook
118 (function 151 (function
119 (lambda () 152 (lambda () (and (featurep 'bookmark)
120 (and (featurep 'bookmark) 153 bookmark-alist
121 bookmark-alist 154 (bookmark-time-to-save-p t)
122 (bookmark-time-to-save-p t) 155 (bookmark-save)))))
123 (bookmark-save)))))
124 156
125;; more stuff added by db. 157;; more stuff added by db.
158
126(defvar bookmark-current-bookmark nil 159(defvar bookmark-current-bookmark nil
127 "Name of bookmark most recently used in the current file. 160 "Name of bookmark most recently used in the current file.
128It is buffer local, used to make moving a bookmark forward 161It is buffer local, used to make moving a bookmark forward
@@ -154,9 +187,21 @@ bookmark-file, which is `~/.emacs-bkmrks' by default.")
154(defvar bookmark-file "~/.emacs-bkmrks" 187(defvar bookmark-file "~/.emacs-bkmrks"
155 "*File in which to save bookmarks by default.") 188 "*File in which to save bookmarks by default.")
156 189
190(defvar bookmark-version-control 'nospecial
191 "This variable controls whether or not to make numbered backups of
192the master bookmark file. It can have four values: t, nil, never, and
193nospecial. The first three have the same meaning that they do for the
194variable version-control, and the final value nospecial means just use
195the value of version-control.")
196
157(defvar bookmark-completion-ignore-case t 197(defvar bookmark-completion-ignore-case t
158 "*Non-nil means bookmark functions ignore case in completion.") 198 "*Non-nil means bookmark functions ignore case in completion.")
159 199
200(defvar bookmark-sort-flag t
201 "*Non-nil means that bookmarks will be displayed sorted by bookmark
202name. Otherwise they will be displayed in LIFO order (that is, most
203recently set ones come first, oldest ones come last).")
204
160(defvar bookmark-search-size 500 205(defvar bookmark-search-size 500
161 "Length of the context strings recorded on either side of a bookmark.") 206 "Length of the context strings recorded on either side of a bookmark.")
162 207
@@ -164,8 +209,8 @@ bookmark-file, which is `~/.emacs-bkmrks' by default.")
164(defvar bookmark-yank-point 0) 209(defvar bookmark-yank-point 0)
165(defvar bookmark-current-buffer nil) 210(defvar bookmark-current-buffer nil)
166 211
212;;;###autoload
167(defun bookmark-set (&optional parg) 213(defun bookmark-set (&optional parg)
168
169 "Set a bookmark named NAME inside a file. 214 "Set a bookmark named NAME inside a file.
170With prefix arg, will not overwrite a bookmark that has the same name 215With prefix arg, will not overwrite a bookmark that has the same name
171as NAME if such a bookmark already exists, but instead will \"push\" 216as NAME if such a bookmark already exists, but instead will \"push\"
@@ -190,24 +235,32 @@ the list of bookmarks.\)"
190 (interactive "P") 235 (interactive "P")
191 (if (not (bookmark-buffer-file-name)) 236 (if (not (bookmark-buffer-file-name))
192 (error "Buffer not visiting a file or directory.")) 237 (error "Buffer not visiting a file or directory."))
238 (bookmark-try-default-file)
193 (setq bookmark-current-point (point)) 239 (setq bookmark-current-point (point))
194 (setq bookmark-yank-point (point)) 240 (setq bookmark-yank-point (point))
195 (setq bookmark-current-buffer (current-buffer)) 241 (setq bookmark-current-buffer (current-buffer))
196 (let ((str 242 (let* ((default (or bookmark-current-bookmark
197 (read-from-minibuffer 243 (buffer-name (current-buffer))))
198 "Set bookmark: " 244 (str
199 nil 245 (read-from-minibuffer
200 (let ((now-map (copy-keymap minibuffer-local-map))) 246 (format "Set bookmark (%s): " default)
201 (progn (define-key now-map "\C-w" 247 nil
202 'bookmark-yank-word) 248 (let ((now-map (copy-keymap minibuffer-local-map)))
203 (define-key now-map "\C-v" 249 (progn (define-key now-map "\C-w"
204 'bookmark-insert-current-file-name) 250 'bookmark-yank-word)
205 (define-key now-map "\C-u" 251 (define-key now-map "\C-v"
206 'bookmark-insert-current-bookmark)) 252 'bookmark-insert-current-file-name)
207 now-map)))) 253 (define-key now-map "\C-u"
254 'bookmark-insert-current-bookmark))
255 now-map))))
256 (and (string-equal str "") (setq str default))
208 (progn 257 (progn
209 (bookmark-make parg str) 258 (bookmark-make parg str)
210 (setq bookmark-current-bookmark str) 259 (setq bookmark-current-bookmark str)
260 (if (get-buffer "*Bookmark List*") ;rebuild the bookmark list
261 (save-excursion
262 (save-window-excursion
263 (list-bookmarks))))
211 (goto-char bookmark-current-point)))) 264 (goto-char bookmark-current-point))))
212 265
213(defun bookmark-insert-current-bookmark () 266(defun bookmark-insert-current-bookmark ()
@@ -225,8 +278,8 @@ the list of bookmarks.\)"
225 ;; name that is being set. 278 ;; name that is being set.
226 (interactive) 279 (interactive)
227 (let ((str (save-excursion 280 (let ((str (save-excursion
228 (set-buffer bookmark-current-buffer) 281 (set-buffer bookmark-current-buffer)
229 (bookmark-buffer-file-name)))) 282 (bookmark-buffer-file-name))))
230 (insert (substring 283 (insert (substring
231 str 284 str
232 (1+ (string-match 285 (1+ (string-match
@@ -238,13 +291,13 @@ the list of bookmarks.\)"
238 ;; get the next word from the buffer and append it to the name of 291 ;; get the next word from the buffer and append it to the name of
239 ;; the bookmark currently being set. 292 ;; the bookmark currently being set.
240 (let ((string (save-excursion 293 (let ((string (save-excursion
241 (set-buffer bookmark-current-buffer) 294 (set-buffer bookmark-current-buffer)
242 (goto-char bookmark-yank-point) 295 (goto-char bookmark-yank-point)
243 (buffer-substring 296 (buffer-substring
244 (point) 297 (point)
245 (save-excursion 298 (save-excursion
246 (forward-word 1) 299 (forward-word 1)
247 (setq bookmark-yank-point (point))))))) 300 (setq bookmark-yank-point (point)))))))
248 (insert string))) 301 (insert string)))
249 302
250(defun bookmark-make (parg str) 303(defun bookmark-make (parg str)
@@ -297,82 +350,177 @@ the list of bookmarks.\)"
297 (car dired-directory))))) 350 (car dired-directory)))))
298 351
299(defun bookmark-try-default-file () 352(defun bookmark-try-default-file ()
300 (if (and (null bookmark-alist) 353 (and (not bookmarks-already-loaded)
301 (file-readable-p (expand-file-name bookmark-file))) 354 (null bookmark-alist)
302 (bookmark-load bookmark-file))) 355 (file-readable-p (expand-file-name bookmark-file))
303 356 (progn
357 (bookmark-load bookmark-file t t)
358 (setq bookmarks-already-loaded t))))
359
360(defun bookmark-maybe-sort-alist ()
361 ;;Return the bookmark-alist for display. If the bookmark-sort-flag
362 ;;is non-nil, then return a sorted copy of the alist.
363 (if bookmark-sort-flag
364 (setq bookmark-alist
365 (sort (copy-alist bookmark-alist)
366 (function
367 (lambda (x y) (string-lessp (car x) (car y))))))))
368
369;;;###autoload
304(defun bookmark-jump (str) 370(defun bookmark-jump (str)
305 "Jump to bookmark BOOKMARK (a point in some file). 371 "Jump to bookmark BOOKMARK (a point in some file).
306You may have a problem using this function if the value of variable 372You may have a problem using this function if the value of variable
307`bookmark-alist' is nil. If that happens, you need to load in some 373`bookmark-alist' is nil. If that happens, you need to load in some
308bookmarks. See help on function `bookmark-load' for more about 374bookmarks. See help on function `bookmark-load' for more about
309this." 375this.
310 (interactive (let ((completion-ignore-case 376
311 bookmark-completion-ignore-case)) 377If the file pointed to by BOOKMARK no longer exists, you will be asked
312 (list (completing-read 378if you wish to give the bookmark a new location, and bookmark-jump
313 "Jump to bookmark: " 379will then jump to the new location, as well as recording it in place
314 bookmark-alist 380of the old one in the permanent bookmark record."
315 nil 381 (interactive (progn (bookmark-try-default-file)
316 0)))) 382 (let* ((completion-ignore-case
317 (let ((whereto-list (car (cdr (assoc str bookmark-alist))))) 383 bookmark-completion-ignore-case)
318 (let ((file (car whereto-list)) 384 (default
319 (forward-str (car (cdr whereto-list))) 385 (or (and
320 (behind-str (car (cdr (cdr whereto-list)))) 386 (assoc bookmark-current-bookmark
321 (place (car (cdr (cdr (cdr whereto-list)))))) 387 bookmark-alist)
322 (if (file-exists-p (expand-file-name file)) 388 bookmark-current-bookmark)
323 (progn 389 (and (assoc (buffer-name (current-buffer))
324 (find-file (expand-file-name file)) 390 bookmark-alist)
325 (goto-char place) 391 (buffer-name (current-buffer)))))
326 ;; Go searching forward first. Then, if forward-str exists and 392 (str
327 ;; was found in the file, we can search backward for behind-str. 393 (completing-read
328 ;; Rationale is that if text was inserted between the two in the 394 (if default
329 ;; file, it's better to be put before it so you can read it, 395 (format "Jump to bookmark (%s): "
330 ;; rather than after and remain perhaps unaware of the changes. 396 default)
331 (if forward-str 397 "Jump to bookmark: ")
332 (if (search-forward forward-str (point-max) t) 398 bookmark-alist
333 (backward-char bookmark-search-size))) 399 nil
334 (if behind-str 400 0)))
335 (if (search-backward behind-str (point-min) t) 401 (and (string-equal "" str)
336 (forward-char bookmark-search-size))) 402 (setq str default))
337 ;; added by db 403 (list str))))
338 (setq bookmark-current-bookmark str)) 404 (let ((cell (bookmark-jump-noselect str)))
339 (error 405 (and cell
340 (concat "File " 406 (switch-to-buffer (car cell))
341 file 407 (goto-char (cdr cell)))))
342 " does not exist. Suggest deleting bookmark \"" 408
343 str 409(defun bookmark-jump-noselect (str)
344 "\"")))))) 410 ;; a leetle helper for bookmark-jump :-)
345 411 ;; returns (BUFFER . POINT)
346(defun bookmark-locate (str) 412 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
347 "Insert the name of the file associated with BOOKMARK. 413 (let* ((file (expand-file-name (car whereto-list)))
348\(This is not the same as the contents of that file\)." 414 (orig-file file)
415 (forward-str (car (cdr whereto-list)))
416 (behind-str (car (cdr (cdr whereto-list))))
417 (place (car (cdr (cdr (cdr whereto-list))))))
418 (if (or
419 (file-exists-p file)
420 ;; else try some common compression extensions
421 ;; and Emacs better handle it right!
422 (setq file
423 (or
424 (let ((altname (concat file ".Z")))
425 (and (file-exists-p altname)
426 altname))
427 (let ((altname (concat file ".gz")))
428 (and (file-exists-p altname)
429 altname))
430 (let ((altname (concat file ".z")))
431 (and (file-exists-p altname)
432 altname)))))
433 (save-excursion
434 (set-buffer (find-file-noselect file))
435 (goto-char place)
436 ;; Go searching forward first. Then, if forward-str exists and
437 ;; was found in the file, we can search backward for behind-str.
438 ;; Rationale is that if text was inserted between the two in the
439 ;; file, it's better to be put before it so you can read it,
440 ;; rather than after and remain perhaps unaware of the changes.
441 (if forward-str
442 (if (search-forward forward-str (point-max) t)
443 (backward-char bookmark-search-size)))
444 (if behind-str
445 (if (search-backward behind-str (point-min) t)
446 (forward-char bookmark-search-size)))
447 ;; added by db
448 (setq bookmark-current-bookmark str)
449 (cons (current-buffer) (point)))
450 (progn
451 (ding)
452 (if (y-or-n-p (concat (file-name-nondirectory orig-file)
453 " nonexistent. Relocate \""
454 str
455 "\"? "))
456 (progn
457 (bookmark-relocate str)
458 ;; gasp! It's a recursive function call in Emacs Lisp!
459 (bookmark-jump-noselect str))
460 (message
461 "Bookmark not relocated, but deleting it would be a good idea.")
462 nil))))))
463
464;;;###autoload
465(defun bookmark-relocate (str)
466 "Relocate BOOKMARK -- prompts for a filename, and makes an already
467existing bookmark point to that file, instead of the one it used to
468point at. Useful when a file has been renamed after a bookmark was
469set in it."
349 (interactive (let ((completion-ignore-case 470 (interactive (let ((completion-ignore-case
350 bookmark-completion-ignore-case)) 471 bookmark-completion-ignore-case))
351 (list (completing-read 472 (progn (bookmark-try-default-file)
352 "Insert bookmark location: " 473 (list (completing-read
353 bookmark-alist 474 "Bookmark to relocate: "
354 nil 475 bookmark-alist
355 0)))) 476 nil
356 (insert (car (car (cdr (assoc str bookmark-alist)))))) 477 0)))))
357 478 (let* ((bmrk (assoc str bookmark-alist))
479 (bmrk-filename (car (car (cdr bmrk))))
480 (newloc (expand-file-name
481 (read-file-name
482 (format "Relocate %s to: " str)
483 (file-name-directory bmrk-filename)))))
484 (setcar (car (cdr bmrk)) newloc)))
485
486;;;###autoload
487(defun bookmark-locate (str &optional no-insertion)
488 "Insert the name of the file associated with BOOKMARK.
489Optional second arg NO-INSERTION means merely return the filename as a
490string."
491 (interactive (let ((completion-ignore-case
492 bookmark-completion-ignore-case))
493 (progn (bookmark-try-default-file)
494 (list (completing-read
495 "Insert bookmark location: "
496 bookmark-alist
497 nil
498 0)))))
499 (let ((where (car (car (cdr (assoc str bookmark-alist))))))
500 (if no-insertion
501 where
502 (insert where))))
503
504;;;###autoload
358(defun bookmark-rename (old &optional new) 505(defun bookmark-rename (old &optional new)
359 "Change the name of BOOKMARK to NEWNAME. 506 "Change the name of OLD-BOOKMARK to NEWNAME.
360If called from keyboard, prompts for OLD and NEWNAME. 507If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
361If called from menubar, prompts for NEWNAME. 508If called from menubar, OLD-BOOKMARK is selected from a menu, and
362If called from Lisp, prompts for NEWNAME if only BOOKMARK was passed 509prompts for NEWNAME.
363as an argument. If called with two strings, then no prompting is 510If called from Lisp, prompts for NEWNAME if only OLD-BOOKMARK was
364done. You must pass at least BOOKMARK when calling from Lisp. 511passed as an argument. If called with two strings, then no prompting
512is done. You must pass at least OLD-BOOKMARK when calling from Lisp.
365 513
366While you are entering the new name, consecutive C-w's insert 514While you are entering the new name, consecutive C-w's insert
367consectutive words from the text of the buffer into the new bookmark 515consectutive words from the text of the buffer into the new bookmark
368name, and C-v inserts the name of the file." 516name, and C-v inserts the name of the file."
369
370 (interactive (let ((completion-ignore-case 517 (interactive (let ((completion-ignore-case
371 bookmark-completion-ignore-case)) 518 bookmark-completion-ignore-case))
372 (list (completing-read "Old bookmark name: " 519 (progn (bookmark-try-default-file)
373 bookmark-alist 520 (list (completing-read "Old bookmark name: "
374 nil 521 bookmark-alist
375 0)))) 522 nil
523 0)))))
376 (progn 524 (progn
377 (setq bookmark-current-point (point)) 525 (setq bookmark-current-point (point))
378 (setq bookmark-yank-point (point)) 526 (setq bookmark-yank-point (point))
@@ -392,11 +540,14 @@ name, and C-v inserts the name of the file."
392 (progn 540 (progn
393 (setcar cell str) 541 (setcar cell str)
394 (setq bookmark-current-bookmark str) 542 (setq bookmark-current-bookmark str)
543 (if (get-buffer "*Bookmark List*")
544 (save-excursion (save-window-excursion (list-bookmarks))))
395 (setq bookmark-alist-modification-count 545 (setq bookmark-alist-modification-count
396 (1+ bookmark-alist-modification-count)) 546 (1+ bookmark-alist-modification-count))
397 (if (bookmark-time-to-save-p) 547 (if (bookmark-time-to-save-p)
398 (bookmark-save)))))) 548 (bookmark-save))))))
399 549
550;;;###autoload
400(defun bookmark-insert (str) 551(defun bookmark-insert (str)
401 "Insert the text of the file pointed to by bookmark BOOKMARK. 552 "Insert the text of the file pointed to by bookmark BOOKMARK.
402You may have a problem using this function if the value of variable 553You may have a problem using this function if the value of variable
@@ -405,53 +556,46 @@ bookmarks. See help on function `bookmark-load' for more about
405this." 556this."
406 (interactive (let ((completion-ignore-case 557 (interactive (let ((completion-ignore-case
407 bookmark-completion-ignore-case)) 558 bookmark-completion-ignore-case))
408 (list (completing-read 559 (progn (bookmark-try-default-file)
409 "Insert bookmark contents: " 560 (list (completing-read
410 bookmark-alist 561 "Insert bookmark contents: "
411 nil 562 bookmark-alist
412 0)))) 563 nil
413 (let ((whereto-list (car (cdr (assoc str bookmark-alist))))) 564 0)))))
414 (let ((file (car whereto-list))) 565 (let ((orig-point (point))
415 (if (file-readable-p (expand-file-name file)) 566 (str-to-insert
416 (let ((str-to-insert 567 (save-excursion
417 (save-excursion 568 (set-buffer (car (bookmark-jump-noselect str)))
418 (find-file (expand-file-name file)) 569 (buffer-substring (point-min) (point-max)))))
419 (prog1 570 (insert str-to-insert)
420 (buffer-substring (point-min) (point-max)) 571 (push-mark)
421 (bury-buffer)))) 572 (goto-char orig-point)))
422 (orig-point (point))) 573
423 (insert str-to-insert) 574;;;###autoload
424 (push-mark)
425 (goto-char orig-point))
426 (error
427 (concat "File "
428 file
429 " does not exist. Suggest deleting bookmark \""
430 str
431 "\""))))))
432
433(defun bookmark-delete (str) 575(defun bookmark-delete (str)
434 "Delete the bookmark named NAME from the bookmark list. 576 "Delete the bookmark named NAME from the bookmark list.
435Removes only the first instance of a bookmark with that name. If 577Removes only the first instance of a bookmark with that name. If
436there are one or more other bookmarks with the same name, they will 578there are one or more other bookmarks with the same name, they will
437not be deleted. Defaults to the \"current\" bookmark \(that is, the 579not be deleted. Defaults to the \"current\" bookmark \(that is, the
438one most recently used in this file, if any\)." 580one most recently used in this file, if any\)."
439
440 (interactive (let ((completion-ignore-case 581 (interactive (let ((completion-ignore-case
441 bookmark-completion-ignore-case)) 582 bookmark-completion-ignore-case))
442 (list 583 (progn (bookmark-try-default-file)
443 (completing-read 584 (list
444 "Delete bookmark: " 585 (completing-read
445 bookmark-alist 586 "Delete bookmark: "
446 nil 587 bookmark-alist
447 0 588 nil
448 bookmark-current-bookmark)))) 589 0
590 bookmark-current-bookmark)))))
449 (let ((will-go (assoc str bookmark-alist))) 591 (let ((will-go (assoc str bookmark-alist)))
450 (setq bookmark-alist (delq will-go bookmark-alist)) 592 (setq bookmark-alist (delq will-go bookmark-alist))
451 ;; Added by db, nil bookmark-current-bookmark if the last 593 ;; Added by db, nil bookmark-current-bookmark if the last
452 ;; occurence has been deleted 594 ;; occurence has been deleted
453 (or (assoc bookmark-current-bookmark bookmark-alist) 595 (or (assoc bookmark-current-bookmark bookmark-alist)
454 (setq bookmark-current-bookmark nil))) 596 (setq bookmark-current-bookmark nil)))
597 (if (get-buffer "*Bookmark List*")
598 (save-excursion (save-window-excursion (list-bookmarks))))
455 (setq bookmark-alist-modification-count 599 (setq bookmark-alist-modification-count
456 (1+ bookmark-alist-modification-count)) 600 (1+ bookmark-alist-modification-count))
457 (if (bookmark-time-to-save-p) 601 (if (bookmark-time-to-save-p)
@@ -472,10 +616,16 @@ one most recently used in this file, if any\)."
472 (t 616 (t
473 nil))) 617 nil)))
474 618
619;;;###autoload
475(defun bookmark-write () 620(defun bookmark-write ()
621 "Write bookmarks to a file \(for which the user will be prompted
622interactively\). Don't use this in Lisp programs; use bookmark-save
623instead."
476 (interactive) 624 (interactive)
625 (bookmark-try-default-file)
477 (bookmark-save t)) 626 (bookmark-save t))
478 627
628;;;###autoload
479(defun bookmark-save (&optional parg file) 629(defun bookmark-save (&optional parg file)
480 "Save currently defined bookmarks. 630 "Save currently defined bookmarks.
481Saves by default in the file defined by the variable 631Saves by default in the file defined by the variable
@@ -492,6 +642,7 @@ When you want to load in the bookmarks from a file, use
492for a file, defaulting to the file defined by variable 642for a file, defaulting to the file defined by variable
493`bookmark-file'." 643`bookmark-file'."
494 (interactive "P") 644 (interactive "P")
645 (bookmark-try-default-file)
495 (cond 646 (cond
496 ((and (null parg) (null file)) 647 ((and (null parg) (null file))
497 ;;whether interactive or not, write to default file 648 ;;whether interactive or not, write to default file
@@ -512,14 +663,24 @@ for a file, defaulting to the file defined by variable
512 663
513(defun bookmark-write-file (file) 664(defun bookmark-write-file (file)
514 (save-excursion 665 (save-excursion
515 (message (format "Saving bookmarks to file %s." file)) 666 (save-window-excursion
516 (set-buffer (find-file-noselect file)) 667 (if (>= baud-rate 9600)
517 (goto-char (point-min)) 668 (message (format "Saving bookmarks to file %s." file)))
518 (delete-region (point-min) (point-max)) 669 (set-buffer (find-file-noselect file))
519 (print bookmark-alist (current-buffer)) 670 (goto-char (point-min))
520 (write-file file) 671 (delete-region (point-min) (point-max))
521 (kill-buffer (current-buffer)))) 672 (print bookmark-alist (current-buffer))
522 673 (let ((version-control
674 (cond
675 ((null bookmark-version-control) nil)
676 ((eq 'never bookmark-version-control) 'never)
677 ((eq 'nospecial bookmark-version-control) version-control)
678 (t
679 t))))
680 (write-file file)
681 (kill-buffer (current-buffer))))))
682
683;;;###autoload
523(defun bookmark-load (file &optional revert no-msg) 684(defun bookmark-load (file &optional revert no-msg)
524 "Load bookmarks from FILE (which must be in bookmark format). 685 "Load bookmarks from FILE (which must be in bookmark format).
525Appends loaded bookmarks to the front of the list of bookmarks. If 686Appends loaded bookmarks to the front of the list of bookmarks. If
@@ -534,50 +695,460 @@ place. Your own personal bookmark file, `~/.emacs-bkmrks', is
534maintained automatically by Emacs; you shouldn't need to load it 695maintained automatically by Emacs; you shouldn't need to load it
535explicitly." 696explicitly."
536 (interactive 697 (interactive
537 (list (read-file-name 698 (progn (bookmark-try-default-file)
538 (format "Load bookmarks from: (%s) " 699 (list (read-file-name
539 bookmark-file) 700 (format "Load bookmarks from: (%s) "
540 ;;Default might not be used often, 701 bookmark-file)
541 ;;but there's no better default, and 702 ;;Default might not be used often,
542 ;;I guess it's better than none at all. 703 ;;but there's no better default, and
543 "~/" bookmark-file 'confirm))) 704 ;;I guess it's better than none at all.
705 "~/" bookmark-file 'confirm))))
544 (setq file (expand-file-name file)) 706 (setq file (expand-file-name file))
545 (if (file-readable-p file) 707 (if (file-readable-p file)
546 (save-excursion 708 (save-excursion
547 (if (null no-msg) 709 (save-window-excursion
548 (message (format "Loading bookmarks from %s..." file))) 710 (if (and (null no-msg) (>= baud-rate 9600))
549 (set-buffer (find-file-noselect file)) 711 (message (format "Loading bookmarks from %s..." file)))
550 (goto-char (point-min)) 712 (set-buffer (find-file-noselect file))
551 (let ((blist (car (read-from-string 713 (goto-char (point-min))
552 (buffer-substring (point-min) (point-max)))))) 714 (let ((blist (car (read-from-string
553 (if (listp blist) 715 (buffer-substring (point-min) (point-max))))))
554 (progn 716 (if (listp blist)
555 (if (not revert) 717 (progn
556 (setq bookmark-alist-modification-count 718 (if (not revert)
557 (1+ bookmark-alist-modification-count)) 719 (setq bookmark-alist-modification-count
558 (setq bookmark-alist-modification-count 0)) 720 (1+ bookmark-alist-modification-count))
559 (setq bookmark-alist 721 (setq bookmark-alist-modification-count 0))
560 (append blist (if (not revert) bookmark-alist)))) 722 (setq bookmark-alist
561 (error (format "Invalid bookmark list in %s." file)))) 723 (append blist (if (not revert) bookmark-alist)))
562 (kill-buffer (current-buffer)) 724 (if (get-buffer "*Bookmark List*")
563 (if (null no-msg) 725 (save-excursion (list-bookmarks))))
564 (message (format "Loading bookmarks from %s... done" file)))) 726 (error (format "Invalid bookmark list in %s." file))))
727 (kill-buffer (current-buffer)))
728 (if (and (null no-msg) (>= baud-rate 9600))
729 (message (format "Loading bookmarks from %s... done" file))))
565 (error (format "Cannot read bookmark file %s." file)))) 730 (error (format "Cannot read bookmark file %s." file))))
566 731
732;;;; bookmark-menu-mode stuff ;;;;
733
734(defvar Bookmark-menu-bookmark-column nil)
735
736(defvar Bookmark-menu-hidden-bookmarks ())
737
738(defvar Bookmark-menu-file-column 30
739 "*Column at which to display filenames in a buffer listing bookmarks.
740You can toggle whether files are shown with \\<Bookmark-menu-mode-map>\\[Bookmark-menu-toggle-filenames].")
741
742(defvar Bookmark-menu-toggle-filenames t
743 "*Non-nil means show filenames when listing bookmarks.
744This may result in truncated bookmark names. To disable this, put the
745following in your .emacs:
746
747\(setq Bookmark-menu-toggle-filenames nil\)")
748
749(defvar Bookmark-menu-mode-map nil)
750
751(if Bookmark-menu-mode-map
752 nil
753 (setq Bookmark-menu-mode-map (make-keymap))
754 (suppress-keymap Bookmark-menu-mode-map t)
755 (define-key Bookmark-menu-mode-map "q" 'Bookmark-menu-quit)
756 (define-key Bookmark-menu-mode-map "v" 'Bookmark-menu-select)
757 (define-key Bookmark-menu-mode-map "w" 'Bookmark-menu-locate)
758 (define-key Bookmark-menu-mode-map "2" 'Bookmark-menu-2-window)
759 (define-key Bookmark-menu-mode-map "1" 'Bookmark-menu-1-window)
760 (define-key Bookmark-menu-mode-map "j" 'Bookmark-menu-this-window)
761 (define-key Bookmark-menu-mode-map "f" 'Bookmark-menu-this-window)
762 (define-key Bookmark-menu-mode-map "o" 'Bookmark-menu-other-window)
763 (define-key Bookmark-menu-mode-map "\C-o" 'Bookmark-menu-switch-other-window)
764 (define-key Bookmark-menu-mode-map "s" 'Bookmark-menu-save)
765 (define-key Bookmark-menu-mode-map "k" 'Bookmark-menu-delete)
766 (define-key Bookmark-menu-mode-map "\C-d" 'Bookmark-menu-delete-backwards)
767 (define-key Bookmark-menu-mode-map "x" 'Bookmark-menu-execute)
768 (define-key Bookmark-menu-mode-map "\C-k" 'Bookmark-menu-delete)
769 (define-key Bookmark-menu-mode-map "d" 'Bookmark-menu-delete)
770 (define-key Bookmark-menu-mode-map " " 'next-line)
771 (define-key Bookmark-menu-mode-map "n" 'next-line)
772 (define-key Bookmark-menu-mode-map "p" 'previous-line)
773 (define-key Bookmark-menu-mode-map "\177" 'Bookmark-menu-backup-unmark)
774 (define-key Bookmark-menu-mode-map "?" 'describe-mode)
775 (define-key Bookmark-menu-mode-map "u" 'Bookmark-menu-unmark)
776 (define-key Bookmark-menu-mode-map "m" 'Bookmark-menu-mark)
777 (define-key Bookmark-menu-mode-map "l" 'Bookmark-menu-load)
778 (define-key Bookmark-menu-mode-map "r" 'Bookmark-menu-rename)
779 (define-key Bookmark-menu-mode-map "t" 'Bookmark-menu-toggle-filenames))
780
781;; Bookmark Menu mode is suitable only for specially formatted data.
782(put 'Bookmark-menu-mode 'mode-class 'special)
783
784;; need to display whether or not bookmark exists as a buffer in flag
785;; column.
786
787;; Format:
788;; FLAGS BOOKMARK (/FILE/NAME/HERE/WHAT/REGEXP/TO/USE?)
789;; goto bookmark-column and then search till "(/[^)]*)$" or "(/.*)$" ?
790
791;;;###autoload
792(defalias 'edit-bookmarks 'list-bookmarks)
793
794;;;###autoload
795(defun list-bookmarks ()
796 "Display a list of existing bookmarks.
797The list is displayed in a buffer named `*Bookmark List*'.
798The leftmost column displays a D if the bookmark is flagged for
799deletion, or > if it is flagged for displaying."
800 (interactive)
801 (bookmark-try-default-file)
802 (switch-to-buffer (get-buffer-create "*Bookmark List*"))
803 (let ((buffer-read-only nil))
804 (delete-region (point-max) (point-min))
805 (goto-char (point-min)) ;sure are playing it safe...
806 (insert "% Bookmark\n- --------\n")
807 (bookmark-maybe-sort-alist)
808 (let ((lst bookmark-alist))
809 (while lst
810 (insert
811 (concat " " (car (car lst)) "\n"))
812 (setq lst (cdr lst)))))
813 (goto-char (point-min))
814 (forward-line 2)
815 (bookmark-menu-mode)
816 (if Bookmark-menu-toggle-filenames
817 (Bookmark-menu-toggle-filenames t)))
818
819(defun bookmark-menu-mode ()
820 "Major mode for editing a list of bookmarks.
821Each line describes one of the bookmarks in Emacs.
822Letters do not insert themselves; instead, they are commands.
823\\<Bookmark-menu-mode-map>
824\\[Bookmark-menu-mark] -- mark bookmark to be displayed.
825\\[Bookmark-menu-select] -- select bookmark of line point is on.
826 Also show bookmarks marked using m in other windows.
827\\[Bookmark-menu-toggle-filenames] -- toggle displaying of filenames (they may obscure long bookmark names).
828\\[Bookmark-menu-locate] -- display (in minibuffer) location of this bookmark.
829\\[Bookmark-menu-1-window] -- select this bookmark in full-frame window.
830\\[Bookmark-menu-2-window] -- select this bookmark in one window,
831 together with bookmark selected before this one in another window.
832\\[Bookmark-menu-this-window] -- select this bookmark in place of the bookmark menu buffer.
833\\[Bookmark-menu-other-window] -- select this bookmark in another window,
834 so the bookmark menu bookmark remains visible in its window.
835\\[Bookmark-menu-switch-other-window] -- switch the other window to this bookmark.
836\\[Bookmark-menu-rename] -- rename this bookmark \(prompts for new name\).
837\\[Bookmark-menu-delete] -- mark this bookmark to be deleted, and move down.
838\\[Bookmark-menu-delete-backwards] -- mark this bookmark to be deleted, and move up.
839\\[Bookmark-menu-execute] -- delete marked bookmarks.
840\\[Bookmark-menu-save] -- save the current bookmark list in the default file.
841 With a prefix arg, prompts for a file to save in.
842\\[Bookmark-menu-load] -- load in a file of bookmarks (prompts for file.)
843\\[Bookmark-menu-unmark] -- remove all kinds of marks from current line.
844 With prefix argument, also move up one line.
845\\[Bookmark-menu-backup-unmark] -- back up a line and remove marks."
846 (kill-all-local-variables)
847 (use-local-map Bookmark-menu-mode-map)
848 (setq truncate-lines t)
849 (setq buffer-read-only t)
850 (setq major-mode 'bookmark-menu-mode)
851 (setq mode-name "Bookmark Menu")
852 (run-hooks 'bookmark-menu-mode-hook))
853
854(defun Bookmark-menu-toggle-filenames (&optional parg)
855 "Toggle whether filenames are shown in the bookmark list.
856Optional argument SHOW means show them unconditionally."
857 (interactive)
858 (cond
859 (parg
860 (setq Bookmark-menu-toggle-filenames nil)
861 (Bookmark-menu-show-filenames)
862 (setq Bookmark-menu-toggle-filenames t))
863 (Bookmark-menu-toggle-filenames
864 (Bookmark-menu-hide-filenames)
865 (setq Bookmark-menu-toggle-filenames nil))
866 (t
867 (Bookmark-menu-show-filenames)
868 (setq Bookmark-menu-toggle-filenames t))))
869
870(defun Bookmark-menu-show-filenames (&optional force)
871 (if (and (not force) Bookmark-menu-toggle-filenames)
872 nil ;already shown, so do nothing
873 (save-excursion
874 (save-window-excursion
875 (goto-char (point-min))
876 (forward-line 2)
877 (setq Bookmark-menu-hidden-bookmarks ())
878 (let ((buffer-read-only nil))
879 (while (< (point) (point-max))
880 (let ((bmrk (Bookmark-menu-bookmark)))
881 (setq Bookmark-menu-hidden-bookmarks
882 (cons bmrk Bookmark-menu-hidden-bookmarks))
883 (move-to-column Bookmark-menu-file-column t)
884 (delete-region (point) (progn (end-of-line) (point)))
885 (insert " ")
886 (bookmark-locate bmrk)
887 (forward-line 1))))))))
888
889(defun Bookmark-menu-hide-filenames (&optional force)
890 (if (and (not force) Bookmark-menu-toggle-filenames)
891 ;; nothing to hide if above is nil
892 (save-excursion
893 (save-window-excursion
894 (goto-char (point-min))
895 (forward-line 2)
896 (setq Bookmark-menu-hidden-bookmarks
897 (nreverse Bookmark-menu-hidden-bookmarks))
898 (save-excursion
899 (goto-char (point-min))
900 (search-forward "Bookmark")
901 (backward-word 1)
902 (setq Bookmark-menu-bookmark-column (current-column)))
903 (save-excursion
904 (let ((buffer-read-only nil))
905 (while Bookmark-menu-hidden-bookmarks
906 (move-to-column Bookmark-menu-bookmark-column t)
907 (kill-line)
908 (insert (car Bookmark-menu-hidden-bookmarks))
909 (setq Bookmark-menu-hidden-bookmarks
910 (cdr Bookmark-menu-hidden-bookmarks))
911 (forward-line 1))))))))
912
913;; if you look at this next function from far away, it resembles a
914;; gun. But only with this comment above...
915(defun Bookmark-menu-check-position ()
916 ;; Returns t if on a line with a bookmark.
917 ;; Otherwise, repositions and returns t.
918 ;; written by David Hughes <djh@harston.cv.com>
919 ;; Mucho thanks, David! -karl
920 (cond ((< (count-lines (point-min) (point)) 2)
921 (goto-char (point-min))
922 (forward-line 2)
923 t)
924 ((and (bolp) (eobp))
925 (beginning-of-line 0)
926 t)
927 (t
928 t)))
929
930(defun Bookmark-menu-bookmark ()
931 ;; return a string which is bookmark of this line.
932 (if (Bookmark-menu-check-position)
933 (save-excursion
934 (save-window-excursion
935 (goto-char (point-min))
936 (search-forward "Bookmark")
937 (backward-word 1)
938 (setq Bookmark-menu-bookmark-column (current-column)))))
939 (if Bookmark-menu-toggle-filenames
940 (Bookmark-menu-hide-filenames))
941 (save-excursion
942 (save-window-excursion
943 (beginning-of-line)
944 (forward-char Bookmark-menu-bookmark-column)
945 (prog1
946 (buffer-substring (point)
947 (progn
948 (end-of-line)
949 (point)))
950 ;; well, this is certainly crystal-clear:
951 (if Bookmark-menu-toggle-filenames
952 (Bookmark-menu-toggle-filenames t))))))
953
954(defun Bookmark-menu-mark ()
955 "Mark bookmark on this line to be displayed by \\<Bookmark-menu-mode-map>\\[Bookmark-menu-select] command."
956 (interactive)
957 (beginning-of-line)
958 (if (Bookmark-menu-check-position)
959 (let ((buffer-read-only nil))
960 (delete-char 1)
961 (insert ?>)
962 (forward-line 1))))
963
964(defun Bookmark-menu-select ()
965 "Select this line's bookmark; also display bookmarks marked with `>'.
966You can mark bookmarks with the \\<Bookmark-menu-mode-map>\\[Bookmark-menu-mark] command."
967 (interactive)
968 (if (Bookmark-menu-check-position)
969 (let ((bmrk (Bookmark-menu-bookmark))
970 (menu (current-buffer))
971 (others ())
972 tem)
973 (goto-char (point-min))
974 (while (re-search-forward "^>" nil t)
975 (setq tem (Bookmark-menu-bookmark))
976 (let ((buffer-read-only nil))
977 (delete-char -1)
978 (insert ?\ ))
979 (or (string-equal tem bmrk)
980 (memq tem others)
981 (setq others (cons tem others))))
982 (setq others (nreverse others)
983 tem (/ (1- (frame-height)) (1+ (length others))))
984 (delete-other-windows)
985 (bookmark-jump bmrk)
986 (bury-buffer menu)
987 (if (equal (length others) 0)
988 nil
989 (while others
990 (split-window nil tem)
991 (other-window 1)
992 (bookmark-jump (car others))
993 (setq others (cdr others)))
994 (other-window 1)))))
995
996(defun Bookmark-menu-save (parg)
997 "Save the current list into a bookmark file.
998With a prefix arg, prompts for a file to save them in."
999 (interactive "P")
1000 (save-excursion
1001 (save-window-excursion
1002 (bookmark-save parg))))
1003
1004(defun Bookmark-menu-load ()
1005 "Load a bookmark file and rebuild list."
1006 (interactive)
1007 (if (Bookmark-menu-check-position)
1008 (save-excursion
1009 (save-window-excursion
1010 (call-interactively 'bookmark-load)))))
1011
1012(defun Bookmark-menu-1-window ()
1013 "Select this line's bookmark, alone, in full frame."
1014 (interactive)
1015 (if (Bookmark-menu-check-position)
1016 (progn
1017 (bookmark-jump (Bookmark-menu-bookmark))
1018 (bury-buffer (other-buffer))
1019 (delete-other-windows))))
1020
1021(defun Bookmark-menu-2-window ()
1022 "Select this line's bookmark, with previous buffer in second window."
1023 (interactive)
1024 (if (Bookmark-menu-check-position)
1025 (let ((bmrk (Bookmark-menu-bookmark))
1026 (menu (current-buffer))
1027 (pop-up-windows t))
1028 (delete-other-windows)
1029 (switch-to-buffer (other-buffer))
1030 (let ((buff (car (bookmark-jump-noselect bmrk))))
1031 (pop-to-buffer buff))
1032 (bury-buffer menu))))
1033
1034(defun Bookmark-menu-this-window ()
1035 "Select this line's bookmark in this window."
1036 (interactive)
1037 (if (Bookmark-menu-check-position)
1038 (bookmark-jump (Bookmark-menu-bookmark))))
1039
1040(defun Bookmark-menu-other-window ()
1041 "Select this line's bookmark in other window, leaving bookmark menu visible."
1042 (interactive)
1043 (if (Bookmark-menu-check-position)
1044 (let ((buff (car (bookmark-jump-noselect (Bookmark-menu-bookmark)))))
1045 (switch-to-buffer-other-window buff))))
1046
1047(defun Bookmark-menu-switch-other-window ()
1048 "Make the other window select this line's bookmark.
1049The current window remains selected."
1050 (interactive)
1051 (if (Bookmark-menu-check-position)
1052 (let ((buff (car (bookmark-jump-noselect (Bookmark-menu-bookmark)))))
1053 (display-buffer buff))))
1054
1055(defun Bookmark-menu-quit ()
1056 "Quit the bookmark menu."
1057 (interactive)
1058 (let ((buffer (current-buffer)))
1059 (switch-to-buffer (other-buffer))
1060 (bury-buffer buffer)))
1061
1062(defun Bookmark-menu-unmark (&optional backup)
1063 "Cancel all requested operations on bookmark on this line and move down.
1064Optional ARG means move up."
1065 (interactive "P")
1066 (beginning-of-line)
1067 (if (Bookmark-menu-check-position)
1068 (progn
1069 (let ((buffer-read-only nil))
1070 (delete-char 1)
1071 ;; any flags to reset according to circumstances? How about a
1072 ;; flag indicating whether this bookmark is being visited?
1073 ;; well, we don't have this now, so maybe later.
1074 (insert " "))
1075 (forward-line (if backup -1 1)))))
1076
1077(defun Bookmark-menu-backup-unmark ()
1078 "Move up and cancel all requested operations on bookmark on line above."
1079 (interactive)
1080 (forward-line -1)
1081 (if (Bookmark-menu-check-position)
1082 (progn
1083 (Bookmark-menu-unmark)
1084 (forward-line -1))))
1085
1086(defun Bookmark-menu-delete ()
1087 "Mark bookmark on this line to be deleted by \\<Bookmark-menu-mode-map>\\[Bookmark-menu-execute] command."
1088 (interactive)
1089 (beginning-of-line)
1090 (if (Bookmark-menu-check-position)
1091 (let ((buffer-read-only nil))
1092 (delete-char 1)
1093 (insert ?D)
1094 (forward-line 1))))
1095
1096(defun Bookmark-menu-delete-backwards ()
1097 "Mark bookmark on this line to be deleted by \\<Bookmark-menu-mode-map>\\[Bookmark-menu-execute] command
1098and then move up one line"
1099 (interactive)
1100 (Bookmark-menu-delete)
1101 (forward-line -2)
1102 (if (Bookmark-menu-check-position)
1103 (forward-line 1)))
1104
1105(defun Bookmark-menu-execute ()
1106 "Delete bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
1107 (interactive)
1108 (let ((hide-em Bookmark-menu-toggle-filenames))
1109 (if hide-em (Bookmark-menu-hide-filenames))
1110 (setq Bookmark-menu-toggle-filenames nil)
1111 (goto-char (point-min))
1112 (forward-line 1)
1113 (let ((deaders ()))
1114 (while (re-search-forward "^D" (point-max) t)
1115 (setq deaders (cons (Bookmark-menu-bookmark) deaders)))
1116 (mapcar (lambda (str)
1117 (setq bookmark-alist
1118 (delq (assoc str bookmark-alist) bookmark-alist)))
1119 deaders))
1120 (list-bookmarks)
1121 (goto-char (point-min))
1122 (forward-line 2)
1123 (setq Bookmark-menu-toggle-filenames hide-em)
1124 (if Bookmark-menu-toggle-filenames
1125 (Bookmark-menu-toggle-filenames t))))
1126
1127(defun Bookmark-menu-rename ()
1128 "Rename bookmark on current line. Prompts for a new name."
1129 (interactive)
1130 (if (Bookmark-menu-check-position)
1131 (let ((bmrk (Bookmark-menu-bookmark))
1132 (thispoint (point)))
1133 (bookmark-rename bmrk)
1134 (list-bookmarks)
1135 (goto-char thispoint))))
1136
1137(defun Bookmark-menu-locate ()
1138 "Display location of this bookmark. Displays in the minibuffer."
1139 (interactive)
1140 (if (Bookmark-menu-check-position)
1141 (let ((bmrk (Bookmark-menu-bookmark)))
1142 (message (bookmark-locate bmrk t)))))
1143
567;;;; bookmark menu bar stuff ;;;; 1144;;;; bookmark menu bar stuff ;;;;
568 1145
569(defvar bookmark-menu-bar-length 70 1146(defvar bookmark-menu-bar-length 70
570 "*Maximum length of a bookmark name displayed on a popup menu.") 1147 "*Maximum length of a bookmark name displayed on a popup menu.")
571 1148
572(defvar bookmark-enable-menu-bar t
573 "*Non-nil means put a bookmark menu on the menu bar.
574\(Assuming that you are running Emacs under a windowing system, such
575as X.\)")
576
577(defun bookmark-make-menu-bar-alist () 1149(defun bookmark-make-menu-bar-alist ()
578 (if (not bookmark-alist) 1150 (bookmark-try-default-file)
579 (if (file-readable-p bookmark-file) 1151 (bookmark-maybe-sort-alist)
580 (bookmark-load bookmark-file)))
581 (if bookmark-alist 1152 (if bookmark-alist
582 (mapcar (lambda (cell) 1153 (mapcar (lambda (cell)
583 (let ((str (car cell))) 1154 (let ((str (car cell)))
@@ -597,10 +1168,8 @@ as X.\)")
597 (let* ((menu (bookmark-make-menu-bar-alist)) 1168 (let* ((menu (bookmark-make-menu-bar-alist))
598 (str (x-popup-menu event 1169 (str (x-popup-menu event
599 (list menu-label 1170 (list menu-label
600 (cons menu-str 1171 (cons menu-str menu)))))
601 menu))))) 1172 (if str (apply func-sym (list str)))))
602 (if str
603 (apply func-sym (list str)))))
604 1173
605(defun bookmark-menu-bar-insert (event) 1174(defun bookmark-menu-bar-insert (event)
606 "Insert the text of the file pointed to by bookmark BOOKMARK. 1175 "Insert the text of the file pointed to by bookmark BOOKMARK.
@@ -610,9 +1179,9 @@ bookmarks. See help on function `bookmark-load' for more about
610this." 1179this."
611 (interactive "e") 1180 (interactive "e")
612 (bookmark-make-menu-bar-with-function 'bookmark-insert 1181 (bookmark-make-menu-bar-with-function 'bookmark-insert
613 "Bookmark Insert Menu" 1182 "Bookmark Insert Menu"
614 "--- Insert Contents ---" 1183 "--- Insert Contents ---"
615 event)) 1184 event))
616 1185
617(defun bookmark-menu-bar-jump (event) 1186(defun bookmark-menu-bar-jump (event)
618 "Jump to bookmark BOOKMARK (a point in some file). 1187 "Jump to bookmark BOOKMARK (a point in some file).
@@ -622,35 +1191,36 @@ bookmarks. See help on function `bookmark-load' for more about
622this." 1191this."
623 (interactive "e") 1192 (interactive "e")
624 (bookmark-make-menu-bar-with-function 'bookmark-jump 1193 (bookmark-make-menu-bar-with-function 'bookmark-jump
625 "Bookmark Jump Menu" 1194 "Bookmark Jump Menu"
626 "--- Jump to Bookmark ---" 1195 "--- Jump to Bookmark ---"
627 event)) 1196 event))
628 1197
629(defun bookmark-menu-bar-locate (event) 1198(defun bookmark-menu-bar-locate (event)
630 "Insert the name of the file associated with BOOKMARK. 1199 "Insert the name of the file associated with BOOKMARK.
631\(This is not the same as the contents of that file\)." 1200\(This is not the same as the contents of that file\)."
632 (interactive "e") 1201 (interactive "e")
633 (bookmark-make-menu-bar-with-function 'bookmark-locate 1202 (bookmark-make-menu-bar-with-function 'bookmark-locate
634 "Bookmark Locate Menu" 1203 "Bookmark Locate Menu"
635 "--- Insert Location ---" 1204 "--- Insert Location ---"
636 event)) 1205 event))
637 1206
638(defun bookmark-menu-bar-rename (event) 1207(defun bookmark-menu-bar-rename (event)
639 "Change the name of BOOKMARK to NEWNAME. 1208 "Change the name of OLD-BOOKMARK to NEWNAME.
640If called from keyboard, prompts for OLD and NEWNAME. 1209If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
641If called from menubar, prompts for NEWNAME. 1210If called from menubar, OLD-BOOKMARK is selected from a menu, and
642If called from Lisp, prompts for NEWNAME if only BOOKMARK was passed 1211prompts for NEWNAME.
643as an argument. If called with two strings, then no prompting is 1212If called from Lisp, prompts for NEWNAME if only OLD-BOOKMARK was
644done. You must pass at least BOOKMARK when calling from Lisp. 1213passed as an argument. If called with two strings, then no prompting
1214is done. You must pass at least OLD-BOOKMARK when calling from Lisp.
645 1215
646While you are entering the new name, consecutive C-w's insert 1216While you are entering the new name, consecutive C-w's insert
647consectutive words from the text of the buffer into the new bookmark 1217consectutive words from the text of the buffer into the new bookmark
648name, and C-v inserts the name of the file." 1218name, and C-v inserts the name of the file."
649 (interactive "e") 1219 (interactive "e")
650 (bookmark-make-menu-bar-with-function 'bookmark-rename 1220 (bookmark-make-menu-bar-with-function 'bookmark-rename
651 "Bookmark Rename Menu" 1221 "Bookmark Rename Menu"
652 "--- Rename Bookmark ---" 1222 "--- Rename Bookmark ---"
653 event)) 1223 event))
654 1224
655(defun bookmark-menu-bar-delete (event) 1225(defun bookmark-menu-bar-delete (event)
656 "Delete the bookmark named NAME from the bookmark list. 1226 "Delete the bookmark named NAME from the bookmark list.
@@ -660,105 +1230,63 @@ not be deleted. Defaults to the \"current\" bookmark \(that is, the
660one most recently used in this file, if any\)." 1230one most recently used in this file, if any\)."
661 (interactive "e") 1231 (interactive "e")
662 (bookmark-make-menu-bar-with-function 'bookmark-delete 1232 (bookmark-make-menu-bar-with-function 'bookmark-delete
663 "Bookmark Delete Menu" 1233 "Bookmark Delete Menu"
664 "--- Delete Bookmark ---" 1234 "--- Delete Bookmark ---"
665 event)) 1235 event))
666 1236
667(if (and bookmark-enable-menu-bar window-system) 1237;; Thanks to Roland McGrath for fixing menubar.el so that the
668 (progn 1238;; following works, and for explaining what to do to make it work.
669 (defvar menu-bar-bookmark-map
670 (make-sparse-keymap "Bookmark functions"))
671
672 ;; make bookmarks appear toward the right side of the menu.
673 (if (boundp 'menu-bar-final-items)
674 (if menu-bar-final-items
675 (setq menu-bar-final-items
676 (cons 'bookmark menu-bar-final-items)))
677 (setq menu-bar-final-items '(bookmark)))
678 1239
679 (define-key global-map [menu-bar bookmark] 1240;;;###autoload
680 (cons "Bookmarks" menu-bar-bookmark-map)) 1241(define-key global-map [menu-bar bookmark]
1242 '("Bookmarks" . menu-bar-bookmark-map))
681 1243
682 (define-key menu-bar-bookmark-map [load] 1244(defvar menu-bar-bookmark-map (make-sparse-keymap "Bookmark functions."))
683 '(" Load a bookmark file" . bookmark-load))
684 1245
685 (define-key menu-bar-bookmark-map [write] 1246;; make bookmarks appear toward the right side of the menu.
686 '("Write \(to another file\)" . bookmark-write)) 1247(if (boundp 'menu-bar-final-items)
1248 (if menu-bar-final-items
1249 (setq menu-bar-final-items
1250 (cons 'bookmark menu-bar-final-items)))
1251 (setq menu-bar-final-items '(bookmark)))
687 1252
688 (define-key menu-bar-bookmark-map [save] 1253(define-key menu-bar-bookmark-map [load]
689 '("Save \(in default file\)" . bookmark-save)) 1254 '("Load a bookmark file" . bookmark-load))
690
691 (define-key menu-bar-bookmark-map [delete]
692 '(" Delete a bookmark" . bookmark-menu-bar-delete))
693
694 (define-key menu-bar-bookmark-map [rename]
695 '(" Rename bookmark" . bookmark-menu-bar-rename))
696
697 (define-key menu-bar-bookmark-map [locate]
698 '(" Insert location" . bookmark-menu-bar-locate))
699
700 (define-key menu-bar-bookmark-map [insert]
701 '(" Insert contents" . bookmark-menu-bar-insert))
702
703 (define-key menu-bar-bookmark-map [set]
704 '(" Set bookmark" . bookmark-set))
705
706 (define-key menu-bar-bookmark-map [jump]
707 '(" Go to bookmark" . bookmark-menu-bar-jump))))
708
709;; not using properties because they make the menu sluggish in coming
710;; up -- too many tests to make. Instead, choosing a useless menu
711;; item just gets you an error now (see
712;; bookmark-make-menu-bar-with-function)
713;;
714;; (put 'bookmark-menu-bar-jump 'menu-enable
715;; '(or bookmark-alist
716;; (and (file-readable-p bookmark-file)
717;; (progn (bookmark-load bookmark-file)
718;; bookmark-alist))))
719;;
720;; (put 'bookmark-menu-bar-insert 'menu-enable
721;; '(or bookmark-alist
722;; (and (file-readable-p bookmark-file)
723;; (progn (bookmark-load bookmark-file)
724;; bookmark-alist))))
725;;
726;; (put 'bookmark-menu-bar-locate 'menu-enable
727;; '(or bookmark-alist
728;; (and (file-readable-p bookmark-file)
729;; (progn (bookmark-load bookmark-file)
730;; bookmark-alist))))
731;;
732;; (put 'bookmark-menu-bar-rename 'menu-enable
733;; '(or bookmark-alist
734;; (and (file-readable-p bookmark-file)
735;; (progn (bookmark-load bookmark-file)
736;; bookmark-alist))))
737;;
738;; (put 'bookmark-menu-bar-delete 'menu-enable
739;; '(or bookmark-alist
740;; (and (file-readable-p bookmark-file)
741;; (progn (bookmark-load bookmark-file)
742;; bookmark-alist))))
743;;
744;; (put 'bookmark-menu-bar-save 'menu-enable
745;; '(or bookmark-alist
746;; (and (file-readable-p bookmark-file)
747;; (progn (bookmark-load bookmark-file)
748;; bookmark-alist))))
749;;
750;; (put 'bookmark-menu-bar-write 'menu-enable
751;; '(or bookmark-alist
752;; (and (file-readable-p bookmark-file)
753;; (progn (bookmark-load bookmark-file)
754;; bookmark-alist))))
755 1255
756;;;; end bookmark menu-bar stuff ;;;; 1256(define-key menu-bar-bookmark-map [write]
1257 '("Write \(to another file\)" . bookmark-write))
1258
1259(define-key menu-bar-bookmark-map [save]
1260 '("Save \(in default file\)" . bookmark-save))
1261
1262(define-key menu-bar-bookmark-map [edit]
1263 '("Edit Bookmark List" . list-bookmarks))
1264
1265(define-key menu-bar-bookmark-map [delete]
1266 '("Delete bookmark" . bookmark-menu-bar-delete))
1267
1268(define-key menu-bar-bookmark-map [rename]
1269 '("Rename bookmark" . bookmark-menu-bar-rename))
1270
1271(define-key menu-bar-bookmark-map [locate]
1272 '("Insert location" . bookmark-menu-bar-locate))
757 1273
758;; load the default bookmark file, if it exists, and the 1274(define-key menu-bar-bookmark-map [insert]
759;; bookmark-alist is nil: 1275 '("Insert contents" . bookmark-menu-bar-insert))
760(bookmark-try-default-file) 1276
1277(define-key menu-bar-bookmark-map [set]
1278 '("Set bookmark" . bookmark-set))
1279
1280(define-key menu-bar-bookmark-map [jump]
1281 '("Jump to bookmark" . bookmark-menu-bar-jump))
1282
1283;;;###autoload (autoload 'menu-bar-bookmark-map "bookmark" nil t 'keymap)
1284
1285(fset 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
1286
1287;;;; end bookmark menu-bar stuff ;;;;
761 1288
762(provide 'bookmark) 1289(provide 'bookmark)
763 1290
764;;; bookmark.el ends here 1291;;; bookmark.el ends here
1292