comparison lisp/bookmark.el @ 4595:2507541ef88d

New version from Fogel.
author Richard M. Stallman <rms@gnu.org>
date Fri, 13 Aug 1993 00:59:51 +0000
parents 14f38c0332a4
children fc781d29fd48
comparison
equal deleted inserted replaced
4594:dc7eabff318b 4595:2507541ef88d
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
4 4
5 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu> 5 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu>
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Created: July, 1993 7 ;; Created: July, 1993
8 ;; Version: 1.7.2 8 ;; Version: 1.7.3 (interim)
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.
12 12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify 13 ;; GNU Emacs is free software; you can redistribute it and/or modify
60 ;; bookmark is set at, string-behind is the same thing after the 60 ;; bookmark is set at, string-behind is the same thing after the
61 ;; point. bookmark-jump will search for string-behind and 61 ;; point. bookmark-jump will search for string-behind and
62 ;; string-in-front in case the file has changed since the bookmark was 62 ;; string-in-front in case the file has changed since the bookmark was
63 ;; set. It will attempt to place the user before the changes, if 63 ;; set. It will attempt to place the user before the changes, if
64 ;; there were any. 64 ;; there were any.
65 ;;
66 ;; It is not advisable to sort the bookmark list when it is presented
67 ;; to the user, because it is already sorted in what is probably the
68 ;; most useful way: order of creation, with most recently created
69 ;; bookmarks coming first and older ones toward the end (renaming does
70 ;; not count as creating) -- which is what we want, most of the time.
65 71
66 ;;; Code: 72 ;;; Code:
67 73
68 ;; Added for lucid emacs compatibility, db 74 ;; Added for lucid emacs compatibility, db
69 (or (fboundp 'defalias) (fset 'defalias 'fset)) 75 (or (fboundp 'defalias) (fset 'defalias 'fset))
77 ;; define the map, so it can be bound by those who desire to do so: 83 ;; define the map, so it can be bound by those who desire to do so:
78 84
79 (defvar bookmark-map nil "This is a keymap containing bookmark 85 (defvar bookmark-map nil "This is a keymap containing bookmark
80 functions. It is not bound to any key by default: to bind it so 86 functions. It is not bound to any key by default: to bind it so
81 that you have a bookmark prefix, just use global-set-key and bind a 87 that you have a bookmark prefix, just use global-set-key and bind a
82 key of your choice to \'bookmark-map. All interactive bookmark 88 key of your choice to \`bookmark-map\'. All interactive bookmark
83 functions have a binding in this keymap.") 89 functions have a binding in this keymap.")
84 90
85 (define-prefix-command 'bookmark-map) 91 (define-prefix-command 'bookmark-map)
86 92
87 ;; Read the help on all of these functions for details... 93 ;; Read the help on all of these functions for details...
117 file easier.") 123 file easier.")
118 124
119 (make-variable-buffer-local 'bookmark-current-bookmark) 125 (make-variable-buffer-local 'bookmark-current-bookmark)
120 126
121 (defvar bookmark-save-flag t 127 (defvar bookmark-save-flag t
122 "*Nil means never save bookmarks, except when bookmark-save is 128 "*Nil means never save bookmarks, except when \`bookmark-save\' is
123 explicitly called \(\\[bookmark-save]\). 129 explicitly called \(\\[bookmark-save]\).
124 130
125 t means save bookmarks when Emacs is killed. 131 t means save bookmarks when Emacs is killed.
126 132
127 Otherise, it should be a number that is the frequency with which the 133 Otherise, it should be a number that is the frequency with which the
133 Therefore, the way to get it to save every time you make or delete a 139 Therefore, the way to get it to save every time you make or delete a
134 bookmark is to set this variable to 1 \(or 0, which produces the same 140 bookmark is to set this variable to 1 \(or 0, which produces the same
135 behavior.\) 141 behavior.\)
136 142
137 To specify the file in which to save them, modify the variable 143 To specify the file in which to save them, modify the variable
138 bookmark-file, which is \"~/.emacs-bkmrks\" by default.") 144 bookmark-file, which is \`~/.emacs-bkmrks\' by default.")
139 145
140 (defvar bookmark-alist-modification-count 0 146 (defvar bookmark-alist-modification-count 0
141 "Number of times the bookmark list has been modified since last 147 "Number of times the bookmark list has been modified since last
142 saved.") 148 saved.")
143 149
299 (file-readable-p (expand-file-name bookmark-file))) 305 (file-readable-p (expand-file-name bookmark-file)))
300 (bookmark-load bookmark-file))) 306 (bookmark-load bookmark-file)))
301 307
302 (defun bookmark-jump (str) 308 (defun bookmark-jump (str)
303 "Go to the location saved in the bookmark BOOKMARK. You may have a 309 "Go to the location saved in the bookmark BOOKMARK. You may have a
304 problem using this function if the value of variable bookmark-alist 310 problem using this function if the value of variable \`bookmark-alist\'
305 is nil. If that happens, you need to load in some bookmarks. See 311 is nil. If that happens, you need to load in some bookmarks. See
306 help on function bookmark-load for more about this." 312 help on function \`bookmark-load\' for more about this."
307 (interactive (progn 313 (interactive (let ((completion-ignore-case
308 (bookmark-try-default-file)
309 (let ((completion-ignore-case
310 bookmark-completion-ignore-case)) 314 bookmark-completion-ignore-case))
311 (list (completing-read 315 (list (completing-read
312 "Jump to bookmark: " 316 "Jump to bookmark: "
313 bookmark-alist 317 bookmark-alist
314 nil 318 nil
315 0))))) 319 0))))
316 (let ((whereto-list (car (cdr (assoc str bookmark-alist))))) 320 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
317 (let ((file (car whereto-list)) 321 (let ((file (car whereto-list))
318 (forward-str (car (cdr whereto-list))) 322 (forward-str (car (cdr whereto-list)))
319 (behind-str (car (cdr (cdr whereto-list)))) 323 (behind-str (car (cdr (cdr whereto-list))))
320 (place (car (cdr (cdr (cdr whereto-list)))))) 324 (place (car (cdr (cdr (cdr whereto-list))))))
321 (if (file-exists-p (expand-file-name file)) 325 (if (file-exists-p (expand-file-name file))
322 (progn 326 (progn
323 (find-file (expand-file-name file)) 327 (find-file (expand-file-name file))
324 (goto-char place) 328 (goto-char place)
325 ;; Go searching forward first. Then, if forward-str exists and 329 ;; Go searching forward first. Then, if forward-str exists and
326 ;; was found in the file, we can search backward for behind-str. 330 ;; was found in the file, we can search backward for behind-str.
327 ;; Rationale is that if text was inserted between the two in the 331 ;; Rationale is that if text was inserted between the two in the
328 ;; file, it's better to be put before it so you can read it, 332 ;; file, it's better to be put before it so you can read it,
329 ;; rather than after and remain perhaps unaware of the changes. 333 ;; rather than after and remain perhaps unaware of the changes.
330 (if forward-str 334 (if forward-str
331 (if (search-forward forward-str (point-max) t) 335 (if (search-forward forward-str (point-max) t)
332 (backward-char bookmark-search-size))) 336 (backward-char bookmark-search-size)))
333 (if behind-str 337 (if behind-str
334 (if (search-backward behind-str (point-min) t) 338 (if (search-backward behind-str (point-min) t)
335 (forward-char bookmark-search-size))) 339 (forward-char bookmark-search-size)))
336 ;; added by db 340 ;; added by db
337 (setq bookmark-current-bookmark str)) 341 (setq bookmark-current-bookmark str))
338 (error 342 (error
339 (concat "File " 343 (concat "File "
340 file 344 file
341 " does not exist. Suggest deleting bookmark \"" 345 " does not exist. Suggest deleting bookmark \""
342 str 346 str
343 "\"")))))) 347 "\""))))))
344 348
345 (defun bookmark-locate (str) 349 (defun bookmark-locate (str)
346 "Insert the name of the file associated with BOOKMARK \(as opposed 350 "Insert the name of the file associated with BOOKMARK \(as opposed
347 to the contents of that file\)." 351 to the contents of that file\)."
348 (interactive (progn 352 (interactive (let ((completion-ignore-case
349 (bookmark-try-default-file) 353 bookmark-completion-ignore-case))
350 (let ((completion-ignore-case 354 (list (completing-read
351 bookmark-completion-ignore-case)) 355 "Insert bookmark location: "
352 (list (completing-read 356 bookmark-alist
353 "Insert bookmark location: " 357 nil
354 bookmark-alist 358 0))))
355 nil
356 0)))))
357 (insert (car (car (cdr (assoc str bookmark-alist)))))) 359 (insert (car (car (cdr (assoc str bookmark-alist))))))
358 360
359 (defun bookmark-rename (old) 361 (defun bookmark-rename (old)
360 "Change the name of BOOKMARK to NEWNAME. While you are entering 362 "Change the name of BOOKMARK to NEWNAME. While you are entering
361 the new name, consecutive C-w\'s will insert consectutive words from 363 the new name, consecutive C-w\'s will insert consectutive words from
362 the text of the buffer into the new bookmark name, and C-v will insert 364 the text of the buffer into the new bookmark name, and C-v will insert
363 the name of the file." 365 the name of the file."
364 (interactive (progn 366 (interactive (let ((completion-ignore-case
365 (bookmark-try-default-file) 367 bookmark-completion-ignore-case))
366 (let ((completion-ignore-case 368 (list (completing-read "Old bookmark name: "
367 bookmark-completion-ignore-case)) 369 bookmark-alist
368 (list (completing-read "Old bookmark name: " 370 nil
369 bookmark-alist 371 0))))
370 nil
371 0)))))
372 (progn 372 (progn
373 (setq bookmark-current-point (point)) 373 (setq bookmark-current-point (point))
374 (setq bookmark-yank-point (point)) 374 (setq bookmark-yank-point (point))
375 (setq bookmark-current-buffer (current-buffer)) 375 (setq bookmark-current-buffer (current-buffer))
376 (let ((cell (assoc old bookmark-alist)) 376 (let ((cell (assoc old bookmark-alist))
393 (bookmark-save)))))) 393 (bookmark-save))))))
394 394
395 (defun bookmark-insert (str) 395 (defun bookmark-insert (str)
396 "Insert the text of the file pointed to by bookmark BOOKMARK. You 396 "Insert the text of the file pointed to by bookmark BOOKMARK. You
397 may have a problem using this function if the value of variable 397 may have a problem using this function if the value of variable
398 bookmark-alist is nil. If that happens, you need to load in some 398 \`bookmark-alist is nil\'. If that happens, you need to load in some
399 bookmarks. See help on function bookmark-load for more about this." 399 bookmarks. See help on function \`bookmark-load\' for more about this."
400 (interactive (progn 400 (interactive (let ((completion-ignore-case
401 (bookmark-try-default-file) 401 bookmark-completion-ignore-case))
402 (let ((completion-ignore-case 402 (list (completing-read
403 bookmark-completion-ignore-case)) 403 "Insert bookmark contents: "
404 (list (completing-read 404 bookmark-alist
405 "Insert bookmark contents: " 405 nil
406 bookmark-alist 406 0))))
407 nil
408 0)))))
409 (let ((whereto-list (car (cdr (assoc str bookmark-alist))))) 407 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
410 (let ((file (car whereto-list))) 408 (let ((file (car whereto-list)))
411 (if (file-readable-p (expand-file-name file)) 409 (if (file-readable-p (expand-file-name file))
412 (let ((str-to-insert 410 (let ((str-to-insert
413 (save-excursion 411 (save-excursion
427 "\"")))))) 425 "\""))))))
428 426
429 (defun bookmark-delete (str) 427 (defun bookmark-delete (str)
430 "Delete the bookmark named NAME from the bookmark list. Removes 428 "Delete the bookmark named NAME from the bookmark list. Removes
431 only the first instance of a bookmark with that name. If there is 429 only the first instance of a bookmark with that name. If there is
432 another bookmark with the same name, it will become \"current\" as 430 another bookmark with the same name, it will take effect as soon as
433 soon as the old one is removed from the bookmark list. Defaults to 431 the old one is removed from the bookmark list. Defaults to the
434 the \"current\" bookmark \(that is, the one most recently set or 432 \"current\" bookmark \(that is, the one most recently used in this
435 jumped to in this file\). 433 file, if any\)."
436
437 With a prefix argument, deletes all bookmarks \(will prompt for
438 confirmation before such a drastic step, however.\) If you then save
439 the empty bookmark list, they will truly be deleted; otherwise you
440 will revert to the bookmarks saved in the default bookmark file
441 automatically the next time you jump to a bookmark, insert one, rename
442 one, or kill Emacs."
443 (interactive (let ((completion-ignore-case 434 (interactive (let ((completion-ignore-case
444 bookmark-completion-ignore-case)) 435 bookmark-completion-ignore-case))
445 (list 436 (list
446 (if current-prefix-arg 437 (completing-read
447 nil 438 "Delete bookmark: "
448 (completing-read 439 bookmark-alist
449 "Delete bookmark: " 440 nil
450 bookmark-alist 441 0
451 nil 442 bookmark-current-bookmark))))
452 0 443 (let ((will-go (assoc str bookmark-alist)))
453 bookmark-current-bookmark))))) 444 (setq bookmark-alist (delq will-go bookmark-alist))
454 (if (null str) 445 ;; Added by db, nil bookmark-current-bookmark if the last
455 (if (y-or-n-p "Delete all bookmarks? ") 446 ;; occurence has been deleted
456 (progn
457 (setq bookmark-alist nil)
458 (message
459 (if (file-readable-p (expand-file-name bookmark-file))
460 (format
461 "Will revert to bookmarks in %s, unless you save now."
462 bookmark-file)
463 "All bookmarks deleted.")))
464 (message "No bookmarks deleted."))
465 (let ((will-go (assoc str bookmark-alist)))
466 (setq bookmark-alist (delq will-go bookmark-alist)))
467 ;; Added by db, nil bookmark-current-bookmark if the last
468 ;; occurence has been deleted
469 (or (assoc bookmark-current-bookmark bookmark-alist) 447 (or (assoc bookmark-current-bookmark bookmark-alist)
470 (setq bookmark-current-bookmark nil))) 448 (setq bookmark-current-bookmark nil)))
471 (setq bookmark-alist-modification-count 449 (setq bookmark-alist-modification-count
472 (1+ bookmark-alist-modification-count)) 450 (1+ bookmark-alist-modification-count))
473 (if (bookmark-time-to-save-p) 451 (if (bookmark-time-to-save-p)
474 (bookmark-save))) 452 (bookmark-save)))
475 453
476 (defun bookmark-time-to-save-p (&optional last-time) 454 (defun bookmark-time-to-save-p (&optional last-time)
477 ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu> 455 ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu>
478 ;; finds out whether it's time to save bookmarks to a file, by 456 ;; finds out whether it's time to save bookmarks to a file, by
479 ;; examining the value of variable bookmark-save-flag, and maybe 457 ;; examining the value of variable bookmark-save-flag, and maybe
490 468
491 (defun bookmark-write () 469 (defun bookmark-write ()
492 (interactive) 470 (interactive)
493 (bookmark-save t)) 471 (bookmark-save t))
494 472
495 (defun bookmark-save (&optional parg file) 473 (defun bookmark-save (&optional parg file)
496 "Saves currently defined bookmarks in the file defined by 474 "Saves currently defined bookmarks in the file defined by the
497 the variable bookmark-file. With a prefix arg, save it in file 475 variable \`bookmark-file\'. With a prefix arg, save it in file FILE.
498 FILE.
499 476
500 If you are calling this from Lisp, the two arguments are PREFIX-ARG 477 If you are calling this from Lisp, the two arguments are PREFIX-ARG
501 and FILE, and if you just want it to write to the default file, then 478 and FILE, and if you just want it to write to the default file, then
502 pass no arguments. Or pass in nil and FILE, and it will save in FILE 479 pass no arguments. Or pass in nil and FILE, and it will save in FILE
503 instead. If you pass in one argument, and it is non-nil, then the 480 instead. If you pass in one argument, and it is non-nil, then the
504 user will be interactively queried for a file to save in. 481 user will be interactively queried for a file to save in.
505 482
506 When you want to load in the bookmarks from a file, use bookmark-load, 483 When you want to load in the bookmarks from a file, use
507 \\[bookmark-load]. That function will prompt you for a file, 484 \\`bookmark-load\\', \\[bookmark-load]. That function will prompt you
508 defaulting to the file defined by variable bookmark-file." 485 for a file, defaulting to the file defined by variable
486 \`bookmark-file\'."
509 (interactive "P") 487 (interactive "P")
510 (cond 488 (cond
511 ((and (null parg) (null file)) 489 ((and (null parg) (null file))
512 ;;whether interactive or not, write to default file 490 ;;whether interactive or not, write to default file
513 (bookmark-write-file bookmark-file)) 491 (bookmark-write-file bookmark-file))
542 means don't display any messages while loading. 520 means don't display any messages while loading.
543 521
544 If you load a file that doesn't contain a proper bookmark alist, you 522 If you load a file that doesn't contain a proper bookmark alist, you
545 will corrupt Emacs\' bookmark list. Generally, you should only load 523 will corrupt Emacs\' bookmark list. Generally, you should only load
546 in files that were created with the bookmark functions in the first 524 in files that were created with the bookmark functions in the first
547 place. If the bookmark alist does become corrupted, just delete all 525 place. Your own personal bookmark file, \`~/.emacs-bkmrks\', is
548 bookmarks and your master bookmark-file will be automatically loaded 526 maintained automatically by Emacs; you should never need to load it
549 next time you try to go to a bookmark \(assuming that your bookmark 527 explicitly."
550 file itself is not corrupt, this will solve the problem\)."
551 (interactive 528 (interactive
552 (list (read-file-name 529 (list (read-file-name
553 (format "Load bookmarks from: (%s) " 530 (format "Load bookmarks from: (%s) "
554 bookmark-file) 531 bookmark-file)
555 ;;Default might not be used often, 532 ;;Default might not be used often,
577 (kill-buffer (current-buffer)) 554 (kill-buffer (current-buffer))
578 (if (null no-msg) 555 (if (null no-msg)
579 (message (format "Loading bookmarks from %s... done" file)))) 556 (message (format "Loading bookmarks from %s... done" file))))
580 (error (format "Cannot read bookmark file %s." file)))) 557 (error (format "Cannot read bookmark file %s." file))))
581 558
582 ;;;; bookmark menu stuff ;;;; 559 ;;;; bookmark menu bar stuff ;;;;
583 560
584 (defvar bookmark-enable-menus t 561 (defvar bookmark-menu-bar-length 70 "*Maximum length of a bookmark name
562 displayed on a menu.")
563
564 (defvar bookmark-enable-menu-bar t
585 "*Non-nil means put a bookmark menu on the menu bar \(assuming that 565 "*Non-nil means put a bookmark menu on the menu bar \(assuming that
586 you are running Emacs under a windowing system, such as X\).") 566 you are running Emacs under a windowing system, such as X\).")
587 567
588 (defvar bookmark-menu-length 70 "*Maximum length of a bookmark name 568 (defun bookmark-make-menu-bar-alist ()
589 displayed on a menu.")
590
591 (defun bookmark-make-menu-alist ()
592 (if (not bookmark-alist) 569 (if (not bookmark-alist)
593 (if (file-readable-p bookmark-file) 570 (if (file-readable-p bookmark-file)
594 (bookmark-load bookmark-file))) 571 (bookmark-load bookmark-file)))
595 (if bookmark-alist 572 (if bookmark-alist
596 (mapcar (lambda (cell) 573 (mapcar (lambda (cell)
597 (let ((str (car cell))) 574 (let ((str (car cell)))
598 (cons 575 (cons
599 (if (> (length str) bookmark-menu-length) 576 (if (> (length str) bookmark-menu-bar-length)
600 (substring str 0 bookmark-menu-length) 577 (substring str 0 bookmark-menu-bar-length)
601 str) 578 str)
602 str))) 579 str)))
603 bookmark-alist) 580 bookmark-alist)
604 (error "No bookmarks currently set."))) 581 (error "No bookmarks currently set.")))
605 582
606 (defun bookmark-make-menu-with-function (func-sym menu-label menu-str event) 583 (defun bookmark-make-menu-bar-with-function (func-sym
584 menu-label
585 menu-str event)
607 ;; help function for making menus that need to apply a bookmark 586 ;; help function for making menus that need to apply a bookmark
608 ;; function to a string. 587 ;; function to a string.
609 (let* ((menu (bookmark-make-menu-alist)) 588 (let* ((menu (bookmark-make-menu-bar-alist))
610 (str (x-popup-menu event 589 (str (x-popup-menu event
611 (list menu-label 590 (list menu-label
612 (cons menu-str 591 (cons menu-str
613 menu))))) 592 menu)))))
614 (if str 593 (if str
615 (apply func-sym (list str))))) 594 (apply func-sym (list str)))))
616 595
617 (defun bookmark-menu-insert (event) 596 (defun bookmark-menu-bar-insert (event)
618 "Insert the text of the file pointed to by bookmark BOOKMARK. You 597 "Insert the text of the file pointed to by bookmark BOOKMARK. You
619 may have a problem using this function if the value of variable 598 may have a problem using this function if the value of variable
620 bookmark-alist is nil. If that happens, you need to load in some 599 \`bookmark-alist\' is nil. If that happens, you need to load in some
621 bookmarks. See help on function bookmark-load for more about this." 600 bookmarks. See help on function \`bookmark-load\' for more about this."
622 (interactive "e") 601 (interactive "e")
623 (bookmark-make-menu-with-function 'bookmark-insert 602 (bookmark-make-menu-bar-with-function 'bookmark-insert
624 "Bookmark Insert Menu" 603 "Bookmark Insert Menu"
625 "--- Insert Contents ---" 604 "--- Insert Contents ---"
626 event)) 605 event))
627 606
628 (defun bookmark-menu-jump (event) 607 (defun bookmark-menu-bar-jump (event)
629 "Go to the location saved in the bookmark BOOKMARK. You may have a 608 "Go to the location saved in the bookmark BOOKMARK. You may have a
630 problem using this function if the value of variable bookmark-alist 609 problem using this function if the value of variable \`bookmark-alist\'
631 is nil. If that happens, you need to load in some bookmarks. See 610 is nil. If that happens, you need to load in some bookmarks. See
632 help on function bookmark-load for more about this." 611 help on function \`bookmark-load\' for more about this."
633 (interactive "e") 612 (interactive "e")
634 (bookmark-make-menu-with-function 'bookmark-jump 613 (bookmark-make-menu-bar-with-function 'bookmark-jump
635 "Bookmark Jump Menu" 614 "Bookmark Jump Menu"
636 "--- Jump to Bookmark ---" 615 "--- Jump to Bookmark ---"
637 event)) 616 event))
638 617
639 (defun bookmark-menu-locate (event) 618 (defun bookmark-menu-bar-locate (event)
640 "Insert the name of the file associated with BOOKMARK \(as opposed 619 "Insert the name of the file associated with BOOKMARK \(as opposed
641 to the contents of that file\)." 620 to the contents of that file\)."
642 (interactive "e") 621 (interactive "e")
643 (bookmark-make-menu-with-function 'bookmark-locate 622 (bookmark-make-menu-bar-with-function 'bookmark-locate
644 "Bookmark Locate Menu" 623 "Bookmark Locate Menu"
645 "--- Insert Location ---" 624 "--- Insert Location ---"
646 event)) 625 event))
647 626
648 (defun bookmark-menu-rename (event) 627 (defun bookmark-menu-bar-rename (event)
649 "Change the name of BOOKMARK to NEWNAME. While you are entering 628 "Change the name of BOOKMARK to NEWNAME. While you are entering
650 the new name, consecutive C-w\'s will insert consectutive words from 629 the new name, consecutive C-w\'s will insert consectutive words from
651 the text of the buffer into the new bookmark name, and C-v will insert 630 the text of the buffer into the new bookmark name, and C-v will insert
652 the name of the file." 631 the name of the file."
653 (interactive "e") 632 (interactive "e")
654 (bookmark-make-menu-with-function 'bookmark-rename 633 (bookmark-make-menu-bar-with-function 'bookmark-rename
655 "Bookmark Rename Menu" 634 "Bookmark Rename Menu"
656 "--- Rename Bookmark ---" 635 "--- Rename Bookmark ---"
657 event)) 636 event))
658 637
659 (defun bookmark-menu-delete (event) 638 (defun bookmark-menu-bar-delete (event)
660 "Delete the bookmark named NAME from the bookmark list. Removes only 639 "Delete the bookmark named NAME from the bookmark list. Removes
661 the first instance of a bookmark with that name. If there is another 640 only the first instance of a bookmark with that name. If there is
662 bookmark with the same name, it will become \"current\" as soon as the 641 another bookmark with the same name, it will take effect as soon as
663 old one is removed from the bookmark list." 642 the old one is removed from the bookmark list."
664 (interactive "e") 643 (interactive "e")
665 (bookmark-make-menu-with-function 'bookmark-delete 644 (bookmark-make-menu-bar-with-function 'bookmark-delete
666 "Bookmark Delete Menu" 645 "Bookmark Delete Menu"
667 "--- Delete Bookmark ---" 646 "--- Delete Bookmark ---"
668 event)) 647 event))
669 648
670 (defun bookmark-menu-delete-all () 649 (if (and bookmark-enable-menu-bar window-system)
671 (interactive)
672 (let ((current-prefix-arg t))
673 (bookmark-delete nil)))
674
675 (if (and bookmark-enable-menus window-system)
676 (progn 650 (progn
677 (defvar menu-bar-bookmark-map 651 (defvar menu-bar-bookmark-map
678 (make-sparse-keymap "Bookmark functions")) 652 (make-sparse-keymap "Bookmark functions"))
679 653
680 ;; make bookmarks appear toward the right side of the menu. 654 ;; make bookmarks appear toward the right side of the menu.
692 666
693 (define-key menu-bar-bookmark-map [write] 667 (define-key menu-bar-bookmark-map [write]
694 '("Write \(to another file\)" . bookmark-write)) 668 '("Write \(to another file\)" . bookmark-write))
695 669
696 (define-key menu-bar-bookmark-map [save] 670 (define-key menu-bar-bookmark-map [save]
697 '("Save \(in default file\)" . bookmark-save)) 671 '("Save \(in default file\)" . bookmark-save))
698 672
699 (define-key menu-bar-bookmark-map [delete-all]
700 '(" Delete all bookmarks" . bookmark-menu-delete-all))
701
702 (define-key menu-bar-bookmark-map [delete] 673 (define-key menu-bar-bookmark-map [delete]
703 '(" Delete a bookmark" . bookmark-menu-delete)) 674 '(" Delete a bookmark" . bookmark-menu-bar-delete))
704 675
705 (define-key menu-bar-bookmark-map [rename] 676 (define-key menu-bar-bookmark-map [rename]
706 '(" Rename bookmark" . bookmark-menu-rename)) 677 '(" Rename bookmark" . bookmark-menu-bar-rename))
707 678
708 (define-key menu-bar-bookmark-map [locate] 679 (define-key menu-bar-bookmark-map [locate]
709 '(" Insert location" . bookmark-menu-locate)) 680 '(" Insert location" . bookmark-menu-bar-locate))
710 681
711 (define-key menu-bar-bookmark-map [insert] 682 (define-key menu-bar-bookmark-map [insert]
712 '(" Insert contents" . bookmark-menu-insert)) 683 '(" Insert contents" . bookmark-menu-bar-insert))
713 684
714 (define-key menu-bar-bookmark-map [set] 685 (define-key menu-bar-bookmark-map [set]
715 '(" Set bookmark" . bookmark-set)) 686 '(" Set bookmark" . bookmark-set))
716 687
717 (define-key menu-bar-bookmark-map [jump] 688 (define-key menu-bar-bookmark-map [jump]
718 '(" Go to bookmark" . bookmark-menu-jump)))) 689 '(" Go to bookmark" . bookmark-menu-bar-jump))))
719 690
720 ;; not using properties because they make the menu sluggish in coming 691 ;; not using properties because they make the menu sluggish in coming
721 ;; up -- too many tests to make. Instead, choosing a useless menu 692 ;; up -- too many tests to make. Instead, choosing a useless menu
722 ;; item just gets you an error now (see 693 ;; item just gets you an error now (see
723 ;; bookmark-make-menu-with-function) 694 ;; bookmark-make-menu-bar-with-function)
724 ;; 695 ;;
725 ;; (put 'bookmark-menu-jump 'menu-enable 696 ;; (put 'bookmark-menu-bar-jump 'menu-enable
726 ;; '(or bookmark-alist 697 ;; '(or bookmark-alist
727 ;; (and (file-readable-p bookmark-file) 698 ;; (and (file-readable-p bookmark-file)
728 ;; (progn (bookmark-load bookmark-file) 699 ;; (progn (bookmark-load bookmark-file)
729 ;; bookmark-alist)))) 700 ;; bookmark-alist))))
730 ;; 701 ;;
731 ;; (put 'bookmark-menu-insert 'menu-enable 702 ;; (put 'bookmark-menu-bar-insert 'menu-enable
732 ;; '(or bookmark-alist 703 ;; '(or bookmark-alist
733 ;; (and (file-readable-p bookmark-file) 704 ;; (and (file-readable-p bookmark-file)
734 ;; (progn (bookmark-load bookmark-file) 705 ;; (progn (bookmark-load bookmark-file)
735 ;; bookmark-alist)))) 706 ;; bookmark-alist))))
736 ;; 707 ;;
737 ;; (put 'bookmark-menu-locate 'menu-enable 708 ;; (put 'bookmark-menu-bar-locate 'menu-enable
738 ;; '(or bookmark-alist 709 ;; '(or bookmark-alist
739 ;; (and (file-readable-p bookmark-file) 710 ;; (and (file-readable-p bookmark-file)
740 ;; (progn (bookmark-load bookmark-file) 711 ;; (progn (bookmark-load bookmark-file)
741 ;; bookmark-alist)))) 712 ;; bookmark-alist))))
742 ;; 713 ;;
743 ;; (put 'bookmark-menu-rename 'menu-enable 714 ;; (put 'bookmark-menu-bar-rename 'menu-enable
744 ;; '(or bookmark-alist 715 ;; '(or bookmark-alist
745 ;; (and (file-readable-p bookmark-file) 716 ;; (and (file-readable-p bookmark-file)
746 ;; (progn (bookmark-load bookmark-file) 717 ;; (progn (bookmark-load bookmark-file)
747 ;; bookmark-alist)))) 718 ;; bookmark-alist))))
748 ;; 719 ;;
749 ;; (put 'bookmark-menu-delete 'menu-enable 720 ;; (put 'bookmark-menu-bar-delete 'menu-enable
750 ;; '(or bookmark-alist 721 ;; '(or bookmark-alist
751 ;; (and (file-readable-p bookmark-file) 722 ;; (and (file-readable-p bookmark-file)
752 ;; (progn (bookmark-load bookmark-file) 723 ;; (progn (bookmark-load bookmark-file)
753 ;; bookmark-alist)))) 724 ;; bookmark-alist))))
754 ;; 725 ;;
755 ;; (put 'bookmark-menu-save 'menu-enable 726 ;; (put 'bookmark-menu-bar-save 'menu-enable
756 ;; '(or bookmark-alist 727 ;; '(or bookmark-alist
757 ;; (and (file-readable-p bookmark-file) 728 ;; (and (file-readable-p bookmark-file)
758 ;; (progn (bookmark-load bookmark-file) 729 ;; (progn (bookmark-load bookmark-file)
759 ;; bookmark-alist)))) 730 ;; bookmark-alist))))
760 ;; 731 ;;
761 ;; (put 'bookmark-menu-write 'menu-enable 732 ;; (put 'bookmark-menu-bar-write 'menu-enable
762 ;; '(or bookmark-alist 733 ;; '(or bookmark-alist
763 ;; (and (file-readable-p bookmark-file) 734 ;; (and (file-readable-p bookmark-file)
764 ;; (progn (bookmark-load bookmark-file) 735 ;; (progn (bookmark-load bookmark-file)
765 ;; bookmark-alist)))) 736 ;; bookmark-alist))))
766 737
767 ;;;; end bookmark menu stuff ;;;; 738 ;;;; end bookmark menu-bar stuff ;;;;
768 739
769 ;; load the default bookmark file, if it exists, and the 740 ;; load the default bookmark file, if it exists, and the
770 ;; bookmark-alist is nil: 741 ;; bookmark-alist is nil:
771 (bookmark-try-default-file) 742 (bookmark-try-default-file)
772 743
773
774 (provide 'bookmark) 744 (provide 'bookmark)
775 745
776 ;;; bookmark.el ends here ;;; 746 ;;; bookmark.el ends here