]> code.delx.au - gnu-emacs/blobdiff - lisp/bookmark.el
(Abbrevs): A @node line without explicit Prev, Next, and Up links.
[gnu-emacs] / lisp / bookmark.el
index 34a3dc1513be9c5949d6e65e1c4f8ea0a02ad629..104a9c6512fa4d6871940772c09d3c68890a260f 100644 (file)
@@ -1,19 +1,13 @@
-;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later.
+;;; bookmark.el --- set bookmarks, maybe annotate them, jump to them later
 
-;; Copyright (C) 1993, 1994, 1995 Free Software Foundation
+;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003,
+;;   2004, 2005, 2006 Free Software Foundation, Inc.
 
-;; Author: Karl Fogel <kfogel@cyclic.com>
-;; Maintainer: Karl Fogel <kfogel@cyclic.com>
+;; Author: Karl Fogel <kfogel@red-bean.com>
+;; Maintainer: Karl Fogel <kfogel@red-bean.com>
 ;; Created: July, 1993
-;; Version: 2.6.5
 ;; Keywords: bookmarks, placeholders, annotations
 
-;;; Summary:
-;; This package is for setting "bookmarks" in files.  A bookmark
-;; associates a string with a location in a certain file.  Thus, you
-;; can navigate your way to that location by providing the string.
-
-;;; Copyright info:
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; This package is for setting "bookmarks" in files.  A bookmark
+;; associates a string with a location in a certain file.  Thus, you
+;; can navigate your way to that location by providing the string.
+;; See the "User Variables" section for customizations.
 
 ;; Thanks to David Bremner <bremner@cs.sfu.ca> for thinking of and
 ;; then implementing the bookmark-current-bookmark idea.  He even
@@ -46,7 +48,7 @@
 ;; bookmark-bmenu-check-position, and some of the Lucid compatibility
 ;; stuff).
 
-;; Kudos (whatever they are) go to Jim Blandy <jimb@cyclic.com>
+;; Kudos (whatever they are) go to Jim Blandy <jimb@red-bean.com>
 ;; for his eminently sensible suggestion to separate bookmark-jump
 ;; into bookmark-jump and bookmark-jump-noselect, which made many
 ;; other things cleaner as well.
@@ -54,7 +56,7 @@
 ;; Thanks to Roland McGrath for encouragement and help with defining
 ;; autoloads on the menu-bar.
 
-;; Jonathan Stigelman <stig@key.amdahl.com> gave patches for default
+;; Jonathan Stigelman <stig@hackvan.com> gave patches for default
 ;; values in bookmark-jump and bookmark-set.  Everybody please keep
 ;; all the keystrokes they save thereby and send them to him at the
 ;; end of each year :-)  (No, seriously, thanks Jonathan!)
 ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
 ;; <olstad@msc.edu>.
 
-;; LCD Archive Entry:
-;; bookmark|Karl Fogel|kfogel@cyclic.com|
-;; Setting bookmarks in files or directories, jumping to them later.|
-;; 06-March-1995|Version: 2.6.5|~/misc/bookmark.el.Z|
+;; Thanks to Mikio Nakajima <PBC01764@niftyserve.or.jp> for many bugs
+;; reported and fixed.
+
+;; Thank you, Michael Kifer, for contributing the XEmacs support.
 
 ;; Enough with the credits already, get on to the good stuff:
 
-;; FAVORITE CHINESE RESTAURANT: 
+;; FAVORITE CHINESE RESTAURANT:
 ;; Boy, that's a tough one.  Probably Hong Min, or maybe Emperor's
 ;; Choice (both in Chicago's Chinatown).  Well, both.  How about you?
-
 \f
-(require 'pp)
+;;; Code:
 
-\f
-;;;; Code:
+(require 'pp)
 
 ;;; Misc comments:
 ;;
 ;; If variable bookmark-use-annotations is non-nil, an annotation is
-;; queried for when setting a bookmark.  
+;; queried for when setting a bookmark.
 ;;
 ;; The bookmark list is sorted lexically by default, but you can turn
 ;; this off by setting bookmark-sort-flag to nil.  If it is nil, then
 ;; the list will be presented in the order it is recorded
 ;; (chronologically), which is actually fairly useful as well.
 
-;;; Code:
+;;; User Variables
+
+(defgroup bookmark nil
+  "Setting, annotation and jumping to bookmarks."
+  :group 'matching)
+
+
+(defcustom bookmark-use-annotations nil
+  "*If non-nil, saving a bookmark queries for an annotation in a buffer."
+  :type 'boolean
+  :group 'bookmark)
+
+
+(defcustom bookmark-save-flag t
+  "*Controls when Emacs saves bookmarks to a file.
+--> nil means never save bookmarks, except when `bookmark-save' is
+    explicitly called \(\\[bookmark-save]\).
+--> t means save bookmarks when Emacs is killed.
+--> Otherwise, it should be a number that is the frequency with which
+    the bookmark list is saved \(i.e.: the number of times which
+    Emacs' bookmark list may be modified before it is automatically
+    saved.\).  If it is a number, Emacs will also automatically save
+    bookmarks when it is killed.
+
+Therefore, the way to get it to save every time you make or delete a
+bookmark is to set this variable to 1 \(or 0, which produces the same
+behavior.\)
+
+To specify the file in which to save them, modify the variable
+`bookmark-default-file', which is `~/.emacs.bmk' by default."
+  :type '(choice (const nil) integer (other t))
+  :group 'bookmark)
+
+
+(defconst bookmark-old-default-file "~/.emacs-bkmrks"
+  "*The `.emacs.bmk' file used to be called this name.")
+
+
+;; defvarred to avoid a compilation warning:
+(defvar bookmark-file nil
+  "Old name for `bookmark-default-file'.")
+
+(defcustom bookmark-default-file
+  (if bookmark-file
+      ;; In case user set `bookmark-file' in her .emacs:
+      bookmark-file
+    (convert-standard-filename "~/.emacs.bmk"))
+  "*File in which to save bookmarks by default."
+  :type 'file
+  :group 'bookmark)
+
+
+(defcustom bookmark-version-control 'nospecial
+  "*Whether or not to make numbered backups of the bookmark file.
+It can have four values: t, nil, `never', and `nospecial'.
+The first three have the same meaning that they do for the
+variable `version-control', and the final value `nospecial' means just
+use the value of `version-control'."
+  :type '(choice (const nil) (const never) (const nospecial)
+                (other t))
+  :group 'bookmark)
+
+
+(defcustom bookmark-completion-ignore-case t
+  "*Non-nil means bookmark functions ignore case in completion."
+  :type 'boolean
+  :group 'bookmark)
+
+
+(defcustom bookmark-sort-flag t
+  "*Non-nil means that bookmarks will be displayed sorted by bookmark name.
+Otherwise they will be displayed in LIFO order (that is, most
+recently set ones come first, oldest ones come last)."
+  :type 'boolean
+  :group 'bookmark)
+
+
+(defcustom bookmark-automatically-show-annotations t
+  "*Non-nil means show annotations when jumping to a bookmark."
+  :type 'boolean
+  :group 'bookmark)
+
+
+(defcustom bookmark-bmenu-file-column 30
+  "*Column at which to display filenames in a buffer listing bookmarks.
+You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames]."
+  :type 'integer
+  :group 'bookmark)
+
+
+(defcustom bookmark-bmenu-toggle-filenames t
+  "*Non-nil means show filenames when listing bookmarks.
+This may result in truncated bookmark names.  To disable this, put the
+following in your `.emacs' file:
+
+\(setq bookmark-bmenu-toggle-filenames nil\)"
+  :type 'boolean
+  :group 'bookmark)
+
+
+(defcustom bookmark-menu-length 70
+  "*Maximum length of a bookmark name displayed on a popup menu."
+  :type 'integer
+  :group 'bookmark)
+
+
+(defface bookmark-menu-heading
+  '((t (:inherit font-lock-type-face)))
+  "Face used to highlight the heading in bookmark menu buffers."
+  :group 'bookmark
+  :version "22.1")
+
+
+;;; No user-serviceable parts beyond this point.
+
+;; Is it XEmacs?
+(defconst bookmark-xemacsp
+  (string-match "\\(Lucid\\|Xemacs\\)" emacs-version))
+
 
 ;; Added  for lucid emacs  compatibility, db
 (or (fboundp 'defalias)  (fset 'defalias 'fset))
 
 ;; suggested for lucid compatibility by david hughes:
-(or (fboundp 'frame-height)  (fset 'frame-height 'screen-height))
-
+(or (fboundp 'frame-height)  (defalias 'frame-height 'screen-height))
 
 \f
 ;;; Keymap stuff:
-;; some people have C-x r set to rmail or whatever.  We don't want to
-;; assume that C-x r is a prefix map just because it's distributed
-;; that way...
-;; These are the distribution keybindings suggested by RMS, everything
-;; else will be done with M-x or the menubar:
-;;;###autoload
-(if (symbolp (key-binding "\C-xr"))
-    nil
-  (progn (define-key ctl-x-map "rb" 'bookmark-jump)
-         (define-key ctl-x-map "rm" 'bookmark-set)
-         (define-key ctl-x-map "rl" 'bookmark-bmenu-list)))
 
-;; define the map, so it can be bound by those who desire to do so:
+;; Set up these bindings dumping time *only*;
+;; if the user alters them, don't override the user when loading bookmark.el.
+
+;;;###autoload (define-key ctl-x-map "rb" 'bookmark-jump)
+;;;###autoload (define-key ctl-x-map "rm" 'bookmark-set)
+;;;###autoload (define-key ctl-x-map "rl" 'bookmark-bmenu-list)
 
 ;;;###autoload
 (defvar bookmark-map nil
@@ -125,38 +236,21 @@ so that you have a bookmark prefix, just use `global-set-key' and bind a
 key of your choice to `bookmark-map'.  All interactive bookmark
 functions have a binding in this keymap.")
 
-(defvar bookmark-use-annotations nil
-  "*If non-nil, saving a bookmark will query for an annotation in a
-buffer.")
-
-;;;###autoload
-(define-prefix-command 'bookmark-map)
+;;;###autoload (define-prefix-command 'bookmark-map)
 
 ;; Read the help on all of these functions for details...
-;;;###autoload
-(define-key bookmark-map "x" 'bookmark-set)
-;;;###autoload
-(define-key bookmark-map "m" 'bookmark-set) ; "m" for "mark"
-;;;###autoload
-(define-key bookmark-map "j" 'bookmark-jump)
-;;;###autoload
-(define-key bookmark-map "g" 'bookmark-jump) ; "g" for "go"
-;;;###autoload
-(define-key bookmark-map "i" 'bookmark-insert)
-;;;###autoload
-(define-key bookmark-map "e" 'edit-bookmarks)
-;;;###autoload
-(define-key bookmark-map "f" 'bookmark-insert-location) ; "f" for "find"
-;;;###autoload
-(define-key bookmark-map "r" 'bookmark-rename)
-;;;###autoload
-(define-key bookmark-map "d" 'bookmark-delete)
-;;;###autoload
-(define-key bookmark-map "l" 'bookmark-load)
-;;;###autoload
-(define-key bookmark-map "w" 'bookmark-write)
-;;;###autoload
-(define-key bookmark-map "s" 'bookmark-save)
+;;;###autoload (define-key bookmark-map "x" 'bookmark-set)
+;;;###autoload (define-key bookmark-map "m" 'bookmark-set) ; "m" for "mark"
+;;;###autoload (define-key bookmark-map "j" 'bookmark-jump)
+;;;###autoload (define-key bookmark-map "g" 'bookmark-jump) ; "g" for "go"
+;;;###autoload (define-key bookmark-map "i" 'bookmark-insert)
+;;;###autoload (define-key bookmark-map "e" 'edit-bookmarks)
+;;;###autoload (define-key bookmark-map "f" 'bookmark-insert-location) ; "f" for "find"
+;;;###autoload (define-key bookmark-map "r" 'bookmark-rename)
+;;;###autoload (define-key bookmark-map "d" 'bookmark-delete)
+;;;###autoload (define-key bookmark-map "l" 'bookmark-load)
+;;;###autoload (define-key bookmark-map "w" 'bookmark-write)
+;;;###autoload (define-key bookmark-map "s" 'bookmark-save)
 
 
 ;;; The annotation maps.
@@ -172,25 +266,32 @@ buffer.")
 (defvar bookmark-alist ()
   "Association list of bookmarks and their records.
 You probably don't want to change the value of this alist yourself;
-instead, let the various bookmark functions do it for you.")
+instead, let the various bookmark functions do it for you.
 
+The format of the alist is
 
-(defvar bookmarks-already-loaded nil)
+       \(BOOKMARK1 BOOKMARK2 ...\)
 
+where each BOOKMARK is of the form
+
+\(NAME
+  \(filename . FILE\)
+  \(front-context-string . FRONT-STR\)
+  \(rear-context-string  . REAR-STR\)
+  \(position . POS\)
+  \(info-node . POS\)
+  \(annotation . ANNOTATION\)\)
+
+So the cdr of each bookmark is an alist too.
+`info-node' is optional, by the way.")
+
+
+(defvar bookmarks-already-loaded nil)
 
-;; just add the hook to make sure that people don't lose bookmarks
-;; when they kill Emacs, unless they don't want to save them.
-;;;###autoload
-(add-hook 'kill-emacs-hook
-          (function
-           (lambda () (and (featurep 'bookmark)
-                           bookmark-alist
-                           (bookmark-time-to-save-p t)
-                           (bookmark-save)))))
 
 ;; more stuff added by db.
 
-(defvar bookmark-current-bookmark nil 
+(defvar bookmark-current-bookmark nil
   "Name of bookmark most recently used in the current file.
 It is buffer local, used to make moving a bookmark forward
 through a file easier.")
@@ -198,61 +299,10 @@ through a file easier.")
 (make-variable-buffer-local 'bookmark-current-bookmark)
 
 
-(defvar bookmark-save-flag t
-  "*Controls when Emacs saves bookmarks to a file.
---> Nil means never save bookmarks, except when `bookmark-save' is
-    explicitly called \(\\[bookmark-save]\).
---> t means save bookmarks when Emacs is killed.
---> Otherise, it should be a number that is the frequency with which
-    the bookmark list is saved \(i.e.: the number of times which
-    Emacs' bookmark list may be modified before it is automatically
-    saved.\).  If it is a number, Emacs will also automatically save
-    bookmarks when it is killed.
-
-Therefore, the way to get it to save every time you make or delete a
-bookmark is to set this variable to 1 \(or 0, which produces the same
-behavior.\)
-
-To specify the file in which to save them, modify the variable
-bookmark-default-file, which is `~/.emacs.bmk' by default.")
-
-
 (defvar bookmark-alist-modification-count 0
   "Number of modifications to bookmark list since it was last saved.")
 
 
-(defconst bookmark-old-default-file "~/.emacs-bkmrks"
-  "*The .emacs.bmk file used to be called this.")
-
-
-(defvar bookmark-default-file
-  (if (and (boundp 'bookmark-file) bookmark-file)
-      ;; In case user set `bookmark-file' in her .emacs:
-      bookmark-file
-    (if (eq system-type 'ms-dos)
-        "~/emacs.bmk" ; Cannot have initial dot [Yuck!]
-      "~/.emacs.bmk"))
-  "*File in which to save bookmarks by default.")
-
-
-(defvar bookmark-version-control 'nospecial
-  "This variable controls whether or not to make numbered backups of
-the master bookmark file.  It can have four values: t, nil, never, and
-nospecial.  The first three have the same meaning that they do for the
-variable version-control, and the final value nospecial means just use
-the value of version-control.")
-
-
-(defvar bookmark-completion-ignore-case t
-  "*Non-nil means bookmark functions ignore case in completion.")
-
-
-(defvar bookmark-sort-flag t
-  "*Non-nil means that bookmarks will be displayed sorted by bookmark
-name.  Otherwise they will be displayed in LIFO order (that is, most
-recently set ones come first, oldest ones come last).")
-
-
 (defvar bookmark-search-size 16
   "Length of the context strings recorded on either side of a bookmark.")
 
@@ -261,7 +311,8 @@ recently set ones come first, oldest ones come last).")
 (defvar bookmark-yank-point 0)
 (defvar bookmark-current-buffer nil)
 
-
+(defvar Info-current-node)
+(defvar Info-suffix-list)
 \f
 ;; Helper functions.
 
@@ -270,7 +321,7 @@ recently set ones come first, oldest ones come last).")
 ;; Everyone else should go through them.
 
 (defun bookmark-name-from-full-record (full-record)
-  "Return name of BOOKMARK \(an alist element instead of a string\)."
+  "Return name of FULL-RECORD \(an alist element instead of a string\)."
   (car full-record))
 
 
@@ -284,19 +335,23 @@ recently set ones come first, oldest ones come last).")
 
 
 (defun bookmark-get-bookmark (bookmark)
-  "Return the full entry for BOOKMARK in bookmark-alist."
-  (assoc bookmark bookmark-alist))
+  "Return the full entry for BOOKMARK in `bookmark-alist'.
+If BOOKMARK is not a string, return nil."
+  (when (stringp bookmark)
+    (assoc-string bookmark bookmark-alist bookmark-completion-ignore-case)))
 
 
 (defun bookmark-get-bookmark-record (bookmark)
-  "Return the guts of the entry for BOOKMARK in bookmark-alist.
+  "Return the guts of the entry for BOOKMARK in `bookmark-alist'.
 That is, all information but the name."
   (car (cdr (bookmark-get-bookmark bookmark))))
 
 
 (defun bookmark-set-name (bookmark newname)
   "Set BOOKMARK's name to NEWNAME."
-  (setcar (bookmark-get-bookmark bookmark) newname))
+  (setcar
+   (if (stringp bookmark) (bookmark-get-bookmark bookmark) bookmark)
+   newname))
 
 
 (defun bookmark-get-annotation (bookmark)
@@ -305,7 +360,7 @@ That is, all information but the name."
 
 
 (defun bookmark-set-annotation (bookmark ann)
-  "Set the annotation of BOOKMARK."
+  "Set the annotation of BOOKMARK to ANN."
   (let ((cell (assq 'annotation (bookmark-get-bookmark-record bookmark))))
     (if cell
         (setcdr cell ann)
@@ -324,7 +379,11 @@ That is, all information but the name."
     (if cell
         (setcdr cell filename)
       (nconc (bookmark-get-bookmark-record bookmark)
-             (list (cons 'filename filename))))))
+             (list (cons 'filename filename))))
+    (setq bookmark-alist-modification-count
+          (1+ bookmark-alist-modification-count))
+    (if (bookmark-time-to-save-p)
+        (bookmark-save))))
 
 
 (defun bookmark-get-position (bookmark)
@@ -372,8 +431,9 @@ That is, all information but the name."
 
 
 (defun bookmark-get-info-node (bookmark)
+  "Get the info node associated with BOOKMARK."
   (cdr (assq 'info-node (bookmark-get-bookmark-record bookmark))))
-  
+
 
 (defun bookmark-set-info-node (bookmark node)
   "Set the Info node of BOOKMARK to NODE."
@@ -382,8 +442,15 @@ That is, all information but the name."
     (if cell
         (setcdr cell node)
       (nconc (bookmark-get-bookmark-record bookmark)
-             (list (cons 'info-node node))))))
-  
+             (list (cons 'info-node node)))))
+
+  (message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark)))
+  (sit-for 4))
+
+
+(defvar bookmark-history nil
+  "The history list for bookmark functions.")
+
 
 (defun bookmark-completing-read (prompt &optional default)
   "Prompting with PROMPT, read a bookmark name in completion.
@@ -392,76 +459,106 @@ probably don't want to include one yourself.
 Optional second arg DEFAULT is a string to return if the user enters
 the empty string."
   (bookmark-maybe-load-default-file) ; paranoia
-  (let* ((completion-ignore-case bookmark-completion-ignore-case)
-         (default default)
-         (prompt (if default
-                     (concat prompt (format " (%s): " default))
-                   (concat prompt ": ")))
-         (str
-          (completing-read prompt
-                           bookmark-alist
-                           nil
-                           0)))
-    (if (string-equal "" str)
-        (list default)
-      (list str))))
-
-
-(defun bookmark-make (str &optional annotation overwrite)
+  (if (listp last-nonmenu-event)
+      (bookmark-menu-popup-paned-menu t prompt (bookmark-all-names))
+    (let* ((completion-ignore-case bookmark-completion-ignore-case)
+          (default default)
+          (prompt (if default
+                      (concat prompt (format " (%s): " default))
+                    (concat prompt ": ")))
+          (str
+           (completing-read prompt
+                            bookmark-alist
+                            nil
+                            0
+                            nil
+                            'bookmark-history)))
+      (if (string-equal "" str) default str))))
+
+
+(defmacro bookmark-maybe-historicize-string (string)
+  "Put STRING into the bookmark prompt history, if caller non-interactive.
+We need this because sometimes bookmark functions are invoked from
+menus, so `completing-read' never gets a chance to set `bookmark-history'."
+  `(or
+    (interactive-p)
+    (setq bookmark-history (cons ,string bookmark-history))))
+
+
+(defun bookmark-make (name &optional annotation overwrite info-node)
   "Make a bookmark named NAME.
 Optional second arg ANNOTATION gives it an annotation.
 Optional third arg OVERWRITE means replace any existing bookmarks with
-this name."
+this name.
+Optional fourth arg INFO-NODE means this bookmark is at info node
+INFO-NODE, so record this fact in the bookmark's entry."
   (bookmark-maybe-load-default-file)
-  (if (and (bookmark-get-bookmark str) (not overwrite))
-      ;; already existing boookmark under that name and
-      ;; no prefix arg means just overwrite old bookmark
-      (setcdr (bookmark-get-bookmark str)
-              (list (bookmark-make-cell annotation)))
-    
-    ;; otherwise just cons it onto the front (either the bookmark
-    ;; doesn't exist already, or there is no prefix arg.  In either
-    ;; case, we want the new bookmark consed onto the alist...)
-    
-    (setq bookmark-alist
-          (cons
-           (list str 
-                 (bookmark-make-cell annotation))
-           bookmark-alist)))
-
-  ;; Added by db
-  (setq bookmark-current-bookmark str)
-  (setq bookmark-alist-modification-count
-        (1+ bookmark-alist-modification-count))
-  (if (bookmark-time-to-save-p)
-      (bookmark-save)))
-
-
-(defun bookmark-make-cell (annotation)
-  "Return the record part of a bookmark.
+  (let ((stripped-name (copy-sequence name)))
+    (or bookmark-xemacsp
+        ;; XEmacs's `set-text-properties' doesn't work on
+        ;; free-standing strings, apparently.
+        (set-text-properties 0 (length stripped-name) nil stripped-name))
+    (if (and (bookmark-get-bookmark stripped-name) (not overwrite))
+        ;; already existing bookmark under that name and
+        ;; no prefix arg means just overwrite old bookmark
+        (setcdr (bookmark-get-bookmark stripped-name)
+                (list (bookmark-make-cell annotation info-node)))
+
+      ;; otherwise just cons it onto the front (either the bookmark
+      ;; doesn't exist already, or there is no prefix arg.  In either
+      ;; case, we want the new bookmark consed onto the alist...)
+
+      (setq bookmark-alist
+            (cons
+             (list stripped-name
+                   (bookmark-make-cell annotation info-node))
+             bookmark-alist)))
+
+    ;; Added by db
+    (setq bookmark-current-bookmark stripped-name)
+    (setq bookmark-alist-modification-count
+          (1+ bookmark-alist-modification-count))
+    (if (bookmark-time-to-save-p)
+        (bookmark-save))))
+
+
+(defun bookmark-make-cell (annotation &optional info-node)
+  "Return the record part of a new bookmark, given ANNOTATION.
 Must be at the correct position in the buffer in which the bookmark is
-being set.  This will change soon.
-Takes ANNOTATION as an argument."
-  (` ((filename . (, (bookmark-buffer-file-name)))
-      (front-context-string
-       . (, (if (>= (- (point-max) (point)) bookmark-search-size)
-                ;; strip text props via `format':
-                (format "%s"
-                        (buffer-substring 
-                         (point)
-                         (+ (point) bookmark-search-size)))
-              nil)))
-      (rear-context-string
-       . (, (if (>= (- (point) (point-min)) bookmark-search-size)
-                ;; strip text props via `format':
-                (format "%s"
-                        (buffer-substring 
-                         (point)
-                         (- (point) bookmark-search-size)))
-              nil)))
-      (position . (, (point)))
-      (annotation . (, annotation)))))
-  
+being set.  This might change someday.
+Optional second arg INFO-NODE means this bookmark is at info node
+INFO-NODE, so record this fact in the bookmark's entry."
+  (let ((the-record
+         `((filename . ,(bookmark-buffer-file-name))
+           (front-context-string
+            . ,(if (>= (- (point-max) (point)) bookmark-search-size)
+                   (buffer-substring-no-properties
+                    (point)
+                    (+ (point) bookmark-search-size))
+                   nil))
+           (rear-context-string
+            . ,(if (>= (- (point) (point-min)) bookmark-search-size)
+                   (buffer-substring-no-properties
+                    (point)
+                    (- (point) bookmark-search-size))
+                   nil))
+           (position . ,(point)))))
+
+    ;; Now fill in the optional parts:
+
+    ;; Take no chances with text properties
+    (set-text-properties 0 (length annotation) nil annotation)
+    (set-text-properties 0 (length info-node) nil info-node)
+
+    (if annotation
+        (nconc the-record (list (cons 'annotation annotation))))
+    (if info-node
+        (nconc the-record (list (cons 'info-node info-node))))
+
+    ;; Finally, return the completed record.
+    the-record))
+
+
 \f
 ;;; File format stuff
 
@@ -493,25 +590,23 @@ Takes ANNOTATION as an argument."
 ;; risk of interfering with existing ones.
 ;;
 ;; BOOKMARK-NAME is the string the user gives the bookmark and
-;; accesses it by from then on.  
+;; accesses it by from then on.
 ;;
 ;; FILENAME is the location of the file in which the bookmark is set.
 ;;
 ;; STRING-IN-FRONT is a string of `bookmark-search-size' chars of
 ;; context in front of the point at which the bookmark is set.
 ;;
-;; STRING-BEHIND is the same thing, but after the point.  
+;; STRING-BEHIND is the same thing, but after the point.
 ;;
 ;; The context strings exist so that modifications to a file don't
-;; necessarily cause a bookmark's position to be invalidated. 
+;; necessarily cause a bookmark's position to be invalidated.
 ;; bookmark-jump will search for STRING-BEHIND and STRING-IN-FRONT in
 ;; case the file has changed since the bookmark was set.  It will
 ;; attempt to place the user before the changes, if there were any.
-;; annotation is the annotation for the bookmark; it may not exist
+;; ANNOTATION is the annotation for the bookmark; it may not exist
 ;; (for backward compatibility), be nil (no annotation), or be a
 ;; string.
-;;
-;; ANNOTATION is an annotation for the bookmark.
 
 
 (defconst bookmark-file-format-version 1
@@ -525,7 +620,7 @@ You should never need to change this.")
 
 
 (defun bookmark-alist-from-buffer ()
-  "Return a bookmark-alist (in any format) from the current buffer.
+  "Return a `bookmark-alist' (in any format) from the current buffer.
 The buffer must of course contain bookmark format information.
 Does not care from where in the buffer it is called, and does not
 affect point."
@@ -539,11 +634,11 @@ affect point."
             (forward-char -1)
             (read (current-buffer)))
         ;; Else no hope of getting information here.
-        (error "Not bookmark format.")))))
+        (error "Not bookmark format")))))
 
 
 (defun bookmark-upgrade-version-0-alist (old-list)
-  "Upgrade a version 0 alist to the current version."
+  "Upgrade a version 0 alist OLD-LIST to the current version."
   (mapcar
    (lambda (bookmark)
      (let* ((name      (car bookmark))
@@ -555,17 +650,17 @@ affect point."
             (ann       (nth 4 record)))
        (list
         name
-        (` ((filename             .    (, filename))
-            (front-context-string .    (, (or front-str "")))
-            (rear-context-string  .    (, (or rear-str  "")))
-            (position             .    (, position))
-            (annotation           .    (, ann)))))))
+        `((filename             .    ,filename)
+          (front-context-string .    ,(or front-str ""))
+          (rear-context-string  .    ,(or rear-str  ""))
+          (position             .    ,position)
+          (annotation           .    ,ann)))))
    old-list))
 
 
 (defun bookmark-upgrade-file-format-from-0 ()
   "Upgrade a bookmark file of format 0 (the original format) to format 1.
-This expects to be called from point-min in a bookmark file."
+This expects to be called from `point-min' in a bookmark file."
   (message "Upgrading bookmark format from 0 to %d..."
            bookmark-file-format-version)
   (let* ((old-list (bookmark-alist-from-buffer))
@@ -575,14 +670,14 @@ This expects to be called from point-min in a bookmark file."
     (pp new-list (current-buffer))
     (save-buffer))
   (goto-char (point-min))
-  (message "Upgrading bookmark format from 0 to %d... done."
+  (message "Upgrading bookmark format from 0 to %d...done"
            bookmark-file-format-version)
   )
 
 
 (defun bookmark-grok-file-format-version ()
   "Return an integer which is the file-format version of this bookmark file.
-This expects to be called from point-min in a bookmark file."
+This expects to be called from `point-min' in a bookmark file."
   (if (looking-at "^;;;;")
       (save-excursion
         (save-match-data
@@ -597,7 +692,7 @@ This expects to be called from point-min in a bookmark file."
 (defun bookmark-maybe-upgrade-file-format ()
   "Check the file-format version of this bookmark file.
 If the version is not up-to-date, upgrade it automatically.
-This expects to be called from point-min in a bookmark file."
+This expects to be called from `point-min' in a bookmark file."
   (let ((version (bookmark-grok-file-format-version)))
     (cond
      ((= version bookmark-file-format-version)
@@ -605,11 +700,11 @@ This expects to be called from point-min in a bookmark file."
      ((= version 0)
       (bookmark-upgrade-file-format-from-0))
      (t
-      (error "Bookmark file format version strangeness.")))))
+      (error "Bookmark file format version strangeness")))))
 
 
 (defun bookmark-insert-file-format-version-stamp ()
-  "Insert text indicating current version of bookmark file-format."
+  "Insert text indicating current version of bookmark file format."
   (insert
    (format ";;;; Emacs Bookmark Format Version %d ;;;;\n"
            bookmark-file-format-version))
@@ -621,12 +716,21 @@ This expects to be called from point-min in a bookmark file."
 
 ;;; end file-format stuff
 
+\f
+;;; Generic helpers.
+
+(defun bookmark-maybe-message (fmt &rest args)
+  "Apply `message' to FMT and ARGS, but only if the display is fast enough."
+  (if (>= baud-rate 9600)
+      (apply 'message fmt args)))
+
 \f
 ;;; Core code:
 
 ;;;###autoload
-(defun bookmark-set (&optional parg)
-  "Set a bookmark named NAME inside a file.  
+(defun bookmark-set (&optional name parg)
+  "Set a bookmark named NAME inside a file.
+If name is nil, then the user will be prompted.
 With prefix arg, will not overwrite a bookmark that has the same name
 as NAME if such a bookmark already exists, but instead will \"push\"
 the new bookmark onto the bookmark alist.  Thus the most recently set
@@ -638,19 +742,18 @@ To yank words from the text of the buffer and use them as part of the
 bookmark name, type C-w while setting a bookmark.  Successive C-w's
 yank successive words.
 
-Typing C-v inserts the name of the current file being visited. Typing
-C-u inserts the name of the last bookmark used in the buffer \(as an
-aid in using a single bookmark name to track your progress through a
-large file\).  If no bookmark was used, then C-u behaves like C-v and
-inserts the name of the file being visited.
+Typing C-u inserts the name of the last bookmark used in the buffer
+\(as an aid in using a single bookmark name to track your progress
+through a large file\).  If no bookmark was used, then C-u inserts the
+name of the file being visited.
 
 Use \\[bookmark-delete] to remove bookmarks \(you give it a name,
 and it removes only the first instance of a bookmark with that name from
 the list of bookmarks.\)"
-  (interactive "P")
+  (interactive (list nil current-prefix-arg))
   (or
    (bookmark-buffer-file-name)
-   (error "Buffer not visiting a file or directory."))
+   (error "Buffer not visiting a file or directory"))
 
   (bookmark-maybe-load-default-file)
 
@@ -661,55 +764,63 @@ the list of bookmarks.\)"
   (let* ((default (or bookmark-current-bookmark
                       (bookmark-buffer-name)))
         (str
-         (read-from-minibuffer
-           (format "Set bookmark (%s): " default)
-          nil
-          (let ((now-map (copy-keymap minibuffer-local-map)))
-            (progn (define-key now-map  "\C-w" 
-                     'bookmark-yank-word)
-                   (define-key now-map  "\C-v" 
-                     'bookmark-insert-current-file-name)
-                   (define-key now-map  "\C-u" 
-                     'bookmark-insert-current-bookmark))
-            now-map)))
+         (or name
+              (read-from-minibuffer
+               (format "Set bookmark (%s): " default)
+               nil
+               (let ((now-map (copy-keymap minibuffer-local-map)))
+                 (define-key now-map "\C-w" 'bookmark-yank-word)
+                 (define-key now-map "\C-u" 'bookmark-insert-current-bookmark)
+                 now-map))))
         (annotation nil))
     (and (string-equal str "") (setq str default))
-    ;; Ask for an annotation buffer for this bookmark 
+    ;; Ask for an annotation buffer for this bookmark
     (if bookmark-use-annotations
        (bookmark-read-annotation parg str)
-      (progn
-       (bookmark-make str annotation parg)
-        ;; In Info, there's a little more information to record:
-        (if (eq major-mode 'Info-mode)
-            (bookmark-set-info-node str Info-current-node))
-       (setq bookmark-current-bookmark str)
-       (bookmark-bmenu-surreptitiously-rebuild-list)
-       (goto-char bookmark-current-point)))))
+      (bookmark-make str annotation parg (bookmark-info-current-node))
+      (setq bookmark-current-bookmark str)
+      (bookmark-bmenu-surreptitiously-rebuild-list)
+      (goto-char bookmark-current-point))))
+
+
+(defun bookmark-info-current-node ()
+  "If in Info-mode, return current node name (a string), else nil."
+  (if (eq major-mode 'Info-mode)
+      Info-current-node))
 
 
 (defun bookmark-kill-line (&optional newline-too)
   "Kill from point to end of line.
 If optional arg NEWLINE-TOO is non-nil, delete the newline too.
-Does not affect the kill-ring."
+Does not affect the kill ring."
   (let ((eol (save-excursion (end-of-line) (point))))
     (delete-region (point) eol)
     (if (and newline-too (looking-at "\n"))
         (delete-char 1))))
 
 
+;; Defvars to avoid compilation warnings:
+(defvar bookmark-annotation-paragraph nil)
+(defvar bookmark-annotation-name nil)
+(defvar bookmark-annotation-buffer nil)
+(defvar bookmark-annotation-file nil)
+(defvar bookmark-annotation-point nil)
+
+
 (defun bookmark-send-annotation ()
-  "After remove lines beginning with '#', use the contents of this buffer
-as the annotation for a bookmark, and store it in the bookmark list with
+  "Use buffer contents as the annotation for a bookmark.
+Exclude lines that begin with `#'.
+Store the annotation text in the bookmark list with
 the bookmark (and file, and point) specified in buffer local variables."
   (interactive)
   (if (not (eq major-mode 'bookmark-read-annotation-mode))
-      (error "Not in bookmark-read-annotation-mode."))
+      (error "Not in bookmark-read-annotation-mode"))
   (goto-char (point-min))
   (while (< (point) (point-max))
     (if (looking-at "^#")
         (bookmark-kill-line t)
       (forward-line 1)))
-  (let ((annotation (buffer-substring (point-min) (point-max)))
+  (let ((annotation (buffer-string))
        (parg bookmark-annotation-paragraph)
        (bookmark bookmark-annotation-name)
        (pt bookmark-annotation-point)
@@ -719,10 +830,10 @@ the bookmark (and file, and point) specified in buffer local variables."
     ;; Actually, bookmark-make-cell should probably be re-written,
     ;; to avoid this need.  Should I handle the error if a buffer is
     ;; killed between "C-x r m" and a "C-c C-c" in the annotation buffer?
-    (save-excursion 
+    (save-excursion
       (pop-to-buffer buf)
       (goto-char pt)
-      (bookmark-make bookmark annotation parg)
+      (bookmark-make bookmark annotation parg (bookmark-info-current-node))
       (setq bookmark-current-bookmark bookmark))
     (bookmark-bmenu-surreptitiously-rebuild-list)
     (goto-char bookmark-current-point))
@@ -739,13 +850,12 @@ the bookmark (and file, and point) specified in buffer local variables."
 
 
 (defvar bookmark-read-annotation-text-func 'bookmark-default-annotation-text
-  "A variable containing a function which returns the text to insert
-into an annotation compisition buffer.  It takes the name of the bookmark,
-as a string, as an arg.")
-
+  "Function to return default text to use for a bookmark annotation.
+It takes one argument, the name of the bookmark, as a string.")
 
 (defun bookmark-read-annotation-mode (buf point parg bookmark)
   "Mode for composing annotations for a bookmark.
+Wants BUF, POINT, PARG, and BOOKMARK.
 When you have finished composing, type \\[bookmark-send-annotation] to send
 the annotation.
 
@@ -766,12 +876,12 @@ the annotation.
   (use-local-map bookmark-read-annotation-mode-map)
   (setq major-mode 'bookmark-read-annotation-mode)
   (insert (funcall bookmark-read-annotation-text-func bookmark))
-  (run-hooks 'text-mode-hook))
+  (run-mode-hooks 'text-mode-hook))
 
 
 (defun bookmark-read-annotation (parg bookmark)
-  "Pop up a buffer for entering a bookmark annotation.  Text surrounding
-the bookmark is PARG; the bookmark name is BOOKMARK."
+  "Pop up a buffer for entering a bookmark annotation.
+Text surrounding the bookmark is PARG; the bookmark name is BOOKMARK."
   (let ((buf (current-buffer))
        (point (point)))
     (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
@@ -797,27 +907,27 @@ When you have finished composing, type \\[bookmark-send-annotation].
   (make-local-variable 'bookmark-annotation-name)
   (setq bookmark-annotation-name bookmark)
   (use-local-map bookmark-edit-annotation-mode-map)
-  (setq major-mode 'bookmark-edit-annotation-mode)
+  (setq major-mode 'bookmark-edit-annotation-mode
+        mode-name "Edit Bookmark Annotation")
   (insert (funcall bookmark-read-annotation-text-func bookmark))
   (let ((annotation (bookmark-get-annotation bookmark)))
-    (if (and (not (eq annotation nil))
-            (not (string-equal annotation "")))
+    (if (and annotation (not (string-equal annotation "")))
        (insert annotation)))
-  (run-hooks 'text-mode-hook))
+  (run-mode-hooks 'text-mode-hook))
 
 
 (defun bookmark-send-edited-annotation ()
-  "After remove lines beginning with '#', use the contents of this buffer
-as the new annotation for a bookmark."
+  "Use buffer contents as annotation for a bookmark.
+Lines beginning with `#' are ignored."
   (interactive)
   (if (not (eq major-mode 'bookmark-edit-annotation-mode))
-      (error "Not in bookmark-edit-annotation-mode."))
+      (error "Not in bookmark-edit-annotation-mode"))
   (goto-char (point-min))
   (while (< (point) (point-max))
     (if (looking-at "^#")
         (bookmark-kill-line t)
       (forward-line 1)))
-  (let ((annotation (buffer-substring (point-min) (point-max)))
+  (let ((annotation (buffer-string))
        (bookmark bookmark-annotation-name))
     (bookmark-set-annotation bookmark annotation)
     (bookmark-bmenu-surreptitiously-rebuild-list)
@@ -827,34 +937,56 @@ as the new annotation for a bookmark."
 
 (defun bookmark-edit-annotation (bookmark)
   "Pop up a buffer for editing bookmark BOOKMARK's annotation."
-  (let ((buf (current-buffer))
-       (point (point)))
-    (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
-    (bookmark-edit-annotation-mode bookmark)))
+  (pop-to-buffer (generate-new-buffer-name "*Bookmark Annotation Compose*"))
+  (bookmark-edit-annotation-mode bookmark))
 
 
 (defun bookmark-insert-current-bookmark ()
-  ;; insert this buffer's value of bookmark-current-bookmark, default
-  ;; to file name if it's nil.
+  "Insert this buffer's value of `bookmark-current-bookmark'.
+Default to file name if it's nil."
   (interactive)
   (let ((str
         (save-excursion
           (set-buffer bookmark-current-buffer)
           bookmark-current-bookmark)))
-    (if str (insert str) (bookmark-insert-current-file-name))))
+    (if str (insert str) (bookmark-insert-buffer-name))))
 
 
-(defun bookmark-insert-current-file-name ()
-  ;; insert the name (sans path) of the current file into the bookmark
-  ;; name that is being set.
+(defun bookmark-insert-buffer-name ()
+  "Insert the current file name into the bookmark name being set.
+The directory part of the file name is not used."
   (interactive)
   (let ((str
          (save-excursion
            (set-buffer bookmark-current-buffer)
-           (file-name-nondirectory (bookmark-buffer-file-name)))))
+           (bookmark-buffer-name))))
     (insert str)))
 
 
+(defun bookmark-buffer-name ()
+  "Return the name of the current buffer's file, non-directory.
+In Info, return the current node."
+  (cond
+   ;; Are we in Info?
+   ((string-equal mode-name "Info") Info-current-node)
+   ;; Or are we a file?
+   (buffer-file-name (file-name-nondirectory buffer-file-name))
+   ;; Or are we a directory?
+   ((and (boundp 'dired-directory) dired-directory)
+    (let* ((dirname (if (stringp dired-directory)
+                        dired-directory
+                      (car dired-directory)))
+           (idx (1- (length dirname))))
+      ;; Strip the trailing slash.
+      (if (= ?/ (aref dirname idx))
+          (file-name-nondirectory (substring dirname 0 idx))
+        ;; Else return the current-buffer
+        (buffer-name (current-buffer)))))
+   ;; If all else fails, use the buffer's name.
+   (t
+    (buffer-name (current-buffer)))))
+
+
 (defun bookmark-yank-word ()
   (interactive)
   ;; get the next word from the buffer and append it to the name of
@@ -862,14 +994,16 @@ as the new annotation for a bookmark."
   (let ((string (save-excursion
                     (set-buffer bookmark-current-buffer)
                     (goto-char bookmark-yank-point)
-                    (buffer-substring
+                    (buffer-substring-no-properties
                      (point)
-                     (save-excursion
+                     (progn
                        (forward-word 1)
                        (setq bookmark-yank-point (point)))))))
     (insert string)))
 
 
+(defvar Info-current-file)
+
 (defun bookmark-buffer-file-name ()
   "Return the current buffer's file in a way useful for bookmarks.
 For example, if this is a Info buffer, return the Info file's name."
@@ -883,23 +1017,9 @@ For example, if this is a Info buffer, return the Info file's name."
            (car dired-directory))))))
 
 
-(defun bookmark-buffer-name ()
-  "Return the name of the current buffer in a way useful for bookmarks.
-For example, if this is a Info buffer, return the Info node's name."
-  (if (string-equal mode-name "Info")
-      Info-current-node
-    (or
-     buffer-file-name
-     (if (and (boundp 'dired-directory) dired-directory)
-         (if (stringp dired-directory)
-             dired-directory
-           (car dired-directory))))))
-
-
 (defun bookmark-maybe-load-default-file ()
   (and (not bookmarks-already-loaded)
        (null bookmark-alist)
-
        (prog2
            (and
             ;; Possibly the old bookmark file, "~/.emacs-bkmrks", needs
@@ -910,11 +1030,10 @@ For example, if this is a Info buffer, return the Info node's name."
                          (expand-file-name bookmark-default-file)))
            ;; return t so the `and' will continue...
            t)
-       
+
        (file-readable-p (expand-file-name bookmark-default-file))
-       (progn
-         (bookmark-load bookmark-default-file t t)
-         (setq bookmarks-already-loaded t))))
+       (bookmark-load bookmark-default-file t t)
+       (setq bookmarks-already-loaded t)))
 
 
 (defun bookmark-maybe-sort-alist ()
@@ -927,27 +1046,58 @@ For example, if this is a Info buffer, return the Info node's name."
                    (lambda (x y) (string-lessp (car x) (car y))))))))
 
 
+(defvar bookmark-after-jump-hook nil
+  "Hook run after `bookmark-jump' jumps to a bookmark.
+Useful for example to unhide text in `outline-mode'.")
+
 ;;;###autoload
-(defun bookmark-jump (str)
-  "Jump to bookmark BOOKMARK (a point in some file).  
+(defun bookmark-jump (bookmark)
+  "Jump to bookmark BOOKMARK (a point in some file).
 You may have a problem using this function if the value of variable
 `bookmark-alist' is nil.  If that happens, you need to load in some
 bookmarks.  See help on function `bookmark-load' for more about
 this.
 
 If the file pointed to by BOOKMARK no longer exists, you will be asked
-if you wish to give the bookmark a new location, and bookmark-jump
+if you wish to give the bookmark a new location, and `bookmark-jump'
 will then jump to the new location, as well as recording it in place
 of the old one in the permanent bookmark record."
   (interactive
-   (bookmark-completing-read "Jump to bookmark" bookmark-current-bookmark))
-  (let ((cell (bookmark-jump-noselect str)))
+   (list (bookmark-completing-read "Jump to bookmark"
+                                  bookmark-current-bookmark)))
+  (unless bookmark
+    (error "No bookmark specified"))
+  (bookmark-maybe-historicize-string bookmark)
+  (let ((cell (bookmark-jump-noselect bookmark)))
     (and cell
          (switch-to-buffer (car cell))
          (goto-char (cdr cell))
-        ;; if there is an annotation for this bookmark,
-        ;; show it in a buffer.
-        (bookmark-show-annotation str))))
+        (progn (run-hooks 'bookmark-after-jump-hook) t)
+        (if bookmark-automatically-show-annotations
+             ;; if there is an annotation for this bookmark,
+             ;; show it in a buffer.
+             (bookmark-show-annotation bookmark)))))
+
+
+(defun bookmark-file-or-variation-thereof (file)
+  "Return FILE (a string) if it exists, or return a reasonable
+variation of FILE if that exists.  Reasonable variations are checked
+by appending suffixes defined in `Info-suffix-list'.  If cannot find FILE
+nor a reasonable variation thereof, then still return FILE if it can
+be retrieved from a VC backend, else return nil."
+  (if (file-exists-p file)
+      file
+    (or
+     (progn (require 'info)  ; ensure Info-suffix-list is bound
+            (catch 'found
+              (mapc (lambda (elt)
+                      (let ((suffixed-file (concat file (car elt))))
+                        (if (file-exists-p suffixed-file)
+                            (throw 'found suffixed-file))))
+                    Info-suffix-list)
+              nil))
+     ;; Last possibility: try VC
+     (if (vc-backend file) file))))
 
 
 (defun bookmark-jump-noselect (str)
@@ -961,152 +1111,151 @@ of the old one in the permanent bookmark record."
          (info-node              (bookmark-get-info-node str))
          (orig-file              file)
          )
-    (if (or
-         (file-exists-p file)
-         ;; else try some common compression extensions
-         ;; and Emacs better handle it right!
-         ;; Sigh: I think it may *not* be handled at the moment.  What
-         ;; to do about this?
-         (setq file
-               (or
-                (let ((altname (concat file ".Z")))
-                  (and (file-exists-p altname)
-                       altname))
-                (let ((altname (concat file ".gz")))
-                  (and (file-exists-p altname)
-                       altname))
-                (let ((altname (concat file ".z")))
-                  (and (file-exists-p altname)
-                       altname)))))
+    (if (setq file (bookmark-file-or-variation-thereof file))
         (save-excursion
-          (if info-node
-              ;; Info nodes must be visited with care.
-              (progn
-                (require 'info)
-                (Info-find-node file info-node))
-            ;; Else no Info.  Can do an ordinary find-file:
-            (set-buffer (find-file-noselect file))
-            (goto-char place))
-
-          ;; Go searching forward first.  Then, if forward-str exists and
-          ;; was found in the file, we can search backward for behind-str.
-          ;; Rationale is that if text was inserted between the two in the
-          ;; file, it's better to be put before it so you can read it,
-          ;; rather than after and remain perhaps unaware of the changes.
-          (if forward-str
-              (if (search-forward forward-str (point-max) t)
-                  (backward-char (length forward-str))))
-          (if behind-str
-              (if (search-backward behind-str (point-min) t)
-                  (forward-char (length behind-str))))
-          ;; added by db
-          (setq bookmark-current-bookmark str)
-          (cons (current-buffer) (point)))
-      (progn
-        (ding)
-        (if (y-or-n-p (concat (file-name-nondirectory orig-file)
-                              " nonexistent.  Relocate \""
-                              str
-                              "\"? "))
-            (progn
-              (bookmark-relocate str)
-              ;; gasp!  It's a recursive function call in Emacs Lisp!
-              (bookmark-jump-noselect str))
-          (message 
-           "Bookmark not relocated; consider removing it \(%s\)." str)
-          nil)))))
+          (save-window-excursion
+            (if info-node
+                ;; Info nodes must be visited with care.
+                (progn
+                  (require 'info)
+                 (with-no-warnings
+                   (Info-find-node file info-node)))
+              ;; Else no Info.  Can do an ordinary find-file:
+              (set-buffer (find-file-noselect file))
+              (goto-char place))
+
+            ;; Go searching forward first.  Then, if forward-str exists and
+            ;; was found in the file, we can search backward for behind-str.
+            ;; Rationale is that if text was inserted between the two in the
+            ;; file, it's better to be put before it so you can read it,
+            ;; rather than after and remain perhaps unaware of the changes.
+            (if forward-str
+                (if (search-forward forward-str (point-max) t)
+                    (goto-char (match-beginning 0))))
+            (if behind-str
+                (if (search-backward behind-str (point-min) t)
+                    (goto-char (match-end 0))))
+            ;; added by db
+            (setq bookmark-current-bookmark str)
+            (cons (current-buffer) (point))))
+
+      ;; Else unable to find the marked file, so ask if user wants to
+      ;; relocate the bookmark, else remind them to consider deletion.
+      (ding)
+      (if (y-or-n-p (concat (file-name-nondirectory orig-file)
+                            " nonexistent.  Relocate \""
+                            str
+                            "\"? "))
+          (progn
+            (bookmark-relocate str)
+            ;; gasp!  It's a recursive function call in Emacs Lisp!
+            (bookmark-jump-noselect str))
+        (message
+         "Bookmark not relocated; consider removing it \(%s\)." str)
+        nil))))
 
 
 ;;;###autoload
-(defun bookmark-relocate (str)
-  "Relocate BOOKMARK -- prompts for a filename, and makes an already
-existing bookmark point to that file, instead of the one it used to
-point at.  Useful when a file has been renamed after a bookmark was
-set in it."
-  (interactive (bookmark-completing-read "Bookmark to relocate"))
+(defun bookmark-relocate (bookmark)
+  "Relocate BOOKMARK to another file (reading file name with minibuffer).
+This makes an already existing bookmark point to that file, instead of
+the one it used to point at.  Useful when a file has been renamed
+after a bookmark was set in it."
+  (interactive (list (bookmark-completing-read "Bookmark to relocate")))
+  (bookmark-maybe-historicize-string bookmark)
   (bookmark-maybe-load-default-file)
-  (let* ((bmrk-filename (bookmark-get-filename str))
+  (let* ((bmrk-filename (bookmark-get-filename bookmark))
          (newloc (expand-file-name
                   (read-file-name
-                   (format "Relocate %s to: " str)
+                   (format "Relocate %s to: " bookmark)
                    (file-name-directory bmrk-filename)))))
-    (bookmark-set-filename str newloc)))
+    (bookmark-set-filename bookmark newloc)
+    (bookmark-bmenu-surreptitiously-rebuild-list)))
 
 
 ;;;###autoload
-(defun bookmark-insert-location (str)
-  "Insert the name of the file associated with BOOKMARK."
-  (interactive (bookmark-completing-read "Insert bookmark location"))
-  (insert (bookmark-location str)))
+(defun bookmark-insert-location (bookmark &optional no-history)
+  "Insert the name of the file associated with BOOKMARK.
+Optional second arg NO-HISTORY means don't record this in the
+minibuffer history list `bookmark-history'."
+  (interactive (list (bookmark-completing-read "Insert bookmark location")))
+  (or no-history (bookmark-maybe-historicize-string bookmark))
+  (let ((start (point)))
+    (prog1
+       (insert (bookmark-location bookmark)) ; *Return this line*
+      (if (and (display-color-p) (display-mouse-p))
+         (add-text-properties
+          start
+          (save-excursion (re-search-backward
+                           "[^ \t]")
+                                              (1+ (point)))
+          '(mouse-face highlight
+            follow-link t
+            help-echo "mouse-2: go to this bookmark in other window"))))))
 
+;;;###autoload
+(defalias 'bookmark-locate 'bookmark-insert-location)
 
-(defun bookmark-location (str)
+(defun bookmark-location (bookmark)
   "Return the name of the file associated with BOOKMARK."
   (bookmark-maybe-load-default-file)
-  (bookmark-get-filename str))
+  (bookmark-get-filename bookmark))
 
 
 ;;;###autoload
 (defun bookmark-rename (old &optional new)
-  "Change the name of OLD-BOOKMARK to NEWNAME.  
-If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
-If called from menubar, OLD-BOOKMARK is selected from a menu, and
-prompts for NEWNAME. 
-If called from Lisp, prompts for NEWNAME if only OLD-BOOKMARK was
-passed as an argument.  If called with two strings, then no prompting
-is done.  You must pass at least OLD-BOOKMARK when calling from Lisp.
+  "Change the name of OLD bookmark to NEW name.
+If called from keyboard, prompt for OLD and NEW.  If called from
+menubar, select OLD from a menu and prompt for NEW.
+
+If called from Lisp, prompt for NEW if only OLD was passed as an
+argument.  If called with two strings, then no prompting is done.  You
+must pass at least OLD when calling from Lisp.
 
 While you are entering the new name, consecutive C-w's insert
-consectutive words from the text of the buffer into the new bookmark
-name.
-C-v inserts the name of the file.
-C-o inserts the old name of the bookmark; this is helpful when you
-just want to make minor changes to the old name."
-  (interactive (bookmark-completing-read "Old bookmark name"))
+consecutive words from the text of the buffer into the new bookmark
+name."
+  (interactive (list (bookmark-completing-read "Old bookmark name")))
+  (bookmark-maybe-historicize-string old)
   (bookmark-maybe-load-default-file)
-  (progn
-    (setq bookmark-current-point (point))
-    (setq bookmark-yank-point (point))
-    (setq bookmark-current-buffer (current-buffer))
-    (let ((newname
-           (or new   ; use second arg, if non-nil
-               (read-from-minibuffer 
-                "New name: "
-                nil
-                (let ((now-map (copy-keymap minibuffer-local-map)))
-                  (progn (define-key now-map  "\C-w" 
-                           'bookmark-yank-word)
-                         (define-key now-map  "\C-o" 
-                           (lambda ()
-                             (interactive)
-                             (insert old)))
-                         (define-key now-map  "\C-v" 
-                           'bookmark-insert-current-file-name))
-                  now-map)))))
-      (progn
-       (bookmark-set-name old newname)
-       (setq bookmark-current-bookmark newname)
-        (bookmark-bmenu-surreptitiously-rebuild-list)
-       (setq bookmark-alist-modification-count
-             (1+ bookmark-alist-modification-count))
-       (if (bookmark-time-to-save-p)
-           (bookmark-save))))))
+
+  (setq bookmark-current-point (point))
+  (setq bookmark-yank-point (point))
+  (setq bookmark-current-buffer (current-buffer))
+  (let ((newname
+         (or new   ; use second arg, if non-nil
+             (read-from-minibuffer
+              "New name: "
+              nil
+              (let ((now-map (copy-keymap minibuffer-local-map)))
+                (define-key now-map  "\C-w" 'bookmark-yank-word)
+                now-map)
+              nil
+              'bookmark-history))))
+    (bookmark-set-name old newname)
+    (setq bookmark-current-bookmark newname)
+    (bookmark-bmenu-surreptitiously-rebuild-list)
+    (setq bookmark-alist-modification-count
+          (1+ bookmark-alist-modification-count))
+    (if (bookmark-time-to-save-p)
+        (bookmark-save))))
 
 
 ;;;###autoload
-(defun bookmark-insert (str)
-  "Insert the text of the file pointed to by bookmark BOOKMARK.  
+(defun bookmark-insert (bookmark)
+  "Insert the text of the file pointed to by bookmark BOOKMARK.
 You may have a problem using this function if the value of variable
 `bookmark-alist' is nil.  If that happens, you need to load in some
 bookmarks.  See help on function `bookmark-load' for more about
 this."
-  (interactive (bookmark-completing-read "Insert bookmark contents"))
+  (interactive (list (bookmark-completing-read "Insert bookmark contents")))
+  (bookmark-maybe-historicize-string bookmark)
   (bookmark-maybe-load-default-file)
   (let ((orig-point (point))
         (str-to-insert
          (save-excursion
-           (set-buffer (car (bookmark-jump-noselect str)))
-           (buffer-substring (point-min) (point-max)))))
+           (set-buffer (car (bookmark-jump-noselect bookmark)))
+           (buffer-string))))
     (insert str-to-insert)
     (push-mark)
     (goto-char orig-point)))
@@ -1114,7 +1263,7 @@ this."
 
 ;;;###autoload
 (defun bookmark-delete (bookmark &optional batch)
-  "Delete BOOKMARK from the bookmark list.  
+  "Delete BOOKMARK from the bookmark list.
 Removes only the first instance of a bookmark with that name.  If
 there are one or more other bookmarks with the same name, they will
 not be deleted.  Defaults to the \"current\" bookmark \(that is, the
@@ -1122,12 +1271,14 @@ one most recently used in this file, if any\).
 Optional second arg BATCH means don't update the bookmark list buffer,
 probably because we were called from there."
   (interactive
-   (bookmark-completing-read "Delete bookmark" bookmark-current-bookmark))
+   (list (bookmark-completing-read "Delete bookmark"
+                                  bookmark-current-bookmark)))
+  (bookmark-maybe-historicize-string bookmark)
   (bookmark-maybe-load-default-file)
   (let ((will-go (bookmark-get-bookmark bookmark)))
     (setq bookmark-alist (delq will-go bookmark-alist))
     ;; Added by db, nil bookmark-current-bookmark if the last
-    ;; occurence has been deleted
+    ;; occurrence has been deleted
     (or (bookmark-get-bookmark bookmark-current-bookmark)
         (setq bookmark-current-bookmark nil)))
   ;; Don't rebuild the list
@@ -1147,7 +1298,7 @@ probably because we were called from there."
   ;; bookmark-alist-modification-count.  Returns t if they should be
   ;; saved, nil otherwise.  if last-time is non-nil, then this is
   ;; being called when emacs is killed.
-  (cond (last-time 
+  (cond (last-time
         (and (> bookmark-alist-modification-count 0)
              bookmark-save-flag))
        ((numberp bookmark-save-flag)
@@ -1158,22 +1309,22 @@ probably because we were called from there."
 
 ;;;###autoload
 (defun bookmark-write ()
-  "Write bookmarks to a file \(for which the user will be prompted
-interactively\).  Don't use this in Lisp programs; use bookmark-save
-instead."
+  "Write bookmarks to a file (reading the file name with the minibuffer).
+Don't use this in Lisp programs; use `bookmark-save' instead."
   (interactive)
   (bookmark-maybe-load-default-file)
   (bookmark-save t))
 
 
 ;;;###autoload
-(defun bookmark-save (&optional parg file) 
+(defun bookmark-save (&optional parg file)
   "Save currently defined bookmarks.
 Saves by default in the file defined by the variable
-`bookmark-default-file'.  With a prefix arg, save it in file FILE.
+`bookmark-default-file'.  With a prefix arg, save it in file FILE
+\(second argument\).
 
-If you are calling this from Lisp, the two arguments are PREFIX-ARG
-and FILE, and if you just want it to write to the default file, then
+If you are calling this from Lisp, the two arguments are PARG and
+FILE, and if you just want it to write to the default file, then
 pass no arguments.  Or pass in nil and FILE, and it will save in FILE
 instead.  If you pass in one argument, and it is non-nil, then the
 user will be interactively queried for a file to save in.
@@ -1207,33 +1358,66 @@ for a file, defaulting to the file defined by variable
 (defun bookmark-write-file (file)
   (save-excursion
     (save-window-excursion
-      (if (>= baud-rate 9600)
-          (message (format "Saving bookmarks to file %s..." file)))
-      (set-buffer (let ((enable-local-variables nil))
-                    (find-file-noselect file)))
+      (bookmark-maybe-message "Saving bookmarks to file %s..." file)
+      (set-buffer (get-buffer-create " *Bookmarks*"))
       (goto-char (point-min))
       (delete-region (point-min) (point-max))
-      (bookmark-insert-file-format-version-stamp)
-      (pp bookmark-alist (current-buffer))
-      (let ((version-control
-             (cond
-              ((null bookmark-version-control) nil)
-              ((eq 'never bookmark-version-control) 'never)
-              ((eq 'nospecial bookmark-version-control) version-control)
-              (t
-               t))))
-        (write-file file)
-        (kill-buffer (current-buffer))
-        (if (>= baud-rate 9600)
-            (message (format "Saving bookmarks to file %s... done." file)))
-        ))))
+      (let ((print-length nil)
+           (print-level nil))
+       (bookmark-insert-file-format-version-stamp)
+       (pp bookmark-alist (current-buffer))
+       (let ((version-control
+              (cond
+               ((null bookmark-version-control) nil)
+               ((eq 'never bookmark-version-control) 'never)
+               ((eq 'nospecial bookmark-version-control) version-control)
+               (t
+                t))))
+          (condition-case nil
+              (write-region (point-min) (point-max) file)
+            (file-error (message "Can't write %s" file)))
+         (kill-buffer (current-buffer))
+          (bookmark-maybe-message
+           "Saving bookmarks to file %s...done" file))))))
+
+
+(defun bookmark-import-new-list (new-list)
+  ;; Walk over the new list, adding each individual bookmark
+  ;; carefully.  "Carefully" means checking against the existing
+  ;; bookmark-alist and renaming the new bookmarks with <N> extensions
+  ;; as necessary.
+  (let ((lst new-list)
+        (names (bookmark-all-names)))
+    (while lst
+      (let* ((full-record (car lst)))
+        (bookmark-maybe-rename full-record names)
+        (setq bookmark-alist (nconc bookmark-alist (list full-record)))
+        (setq names (cons (bookmark-name-from-full-record full-record) names))
+        (setq lst (cdr lst))))))
+
+
+(defun bookmark-maybe-rename (full-record names)
+  ;; just a helper for bookmark-import-new-list; it is only for
+  ;; readability that this is not inlined.
+  ;;
+  ;; Once this has found a free name, it sets full-record to that
+  ;; name.
+  (let ((found-name (bookmark-name-from-full-record full-record)))
+    (if (member found-name names)
+        ;; We've got a conflict, so generate a new name
+        (let ((count 2)
+              (new-name found-name))
+          (while (member new-name names)
+            (setq new-name (concat found-name (format "<%d>" count)))
+            (setq count (1+ count)))
+          (bookmark-set-name full-record new-name)))))
 
 
 ;;;###autoload
-(defun bookmark-load (file &optional revert no-msg)
+(defun bookmark-load (file &optional overwrite no-msg)
   "Load bookmarks from FILE (which must be in bookmark format).
 Appends loaded bookmarks to the front of the list of bookmarks.  If
-optional second argument REVERT is non-nil, existing bookmarks are
+optional second argument OVERWRITE is non-nil, existing bookmarks are
 destroyed.  Optional third arg NO-MSG means don't display any messages
 while loading.
 
@@ -1242,11 +1426,16 @@ will corrupt Emacs's bookmark list.  Generally, you should only load
 in files that were created with the bookmark functions in the first
 place.  Your own personal bookmark file, `~/.emacs.bmk', is
 maintained automatically by Emacs; you shouldn't need to load it
-explicitly."
+explicitly.
+
+If you load a file containing bookmarks with the same names as
+bookmarks already present in your Emacs, the new bookmarks will get
+unique numeric suffixes \"<2>\", \"<3>\", ... following the same
+method buffers use to resolve name collisions."
   (interactive
    (list (read-file-name
           (format "Load bookmarks from: (%s) "
-                  bookmark-default-file)        
+                  bookmark-default-file)
           ;;Default might not be used often,
           ;;but there's no better default, and
           ;;I guess it's better than none at all.
@@ -1255,8 +1444,8 @@ explicitly."
   (if (file-readable-p file)
       (save-excursion
         (save-window-excursion
-          (if (and (null no-msg) (>= baud-rate 9600))
-              (message (format "Loading bookmarks from %s..." file)))
+          (if (null no-msg)
+              (bookmark-maybe-message "Loading bookmarks from %s..." file))
           (set-buffer (let ((enable-local-variables nil))
                         (find-file-noselect file)))
           (goto-char (point-min))
@@ -1264,18 +1453,24 @@ explicitly."
           (let ((blist (bookmark-alist-from-buffer)))
             (if (listp blist)
                 (progn
-                  (if (not revert)
-                      (setq bookmark-alist-modification-count
-                            (1+ bookmark-alist-modification-count))
-                    (setq bookmark-alist-modification-count 0))
-                  (setq bookmark-alist
-                        (append blist (if (not revert) bookmark-alist)))
-                  (bookmark-bmenu-surreptitiously-rebuild-list)) 
-              (error (format "Invalid bookmark list in %s." file))))
+                  (if overwrite
+                      (progn
+                        (setq bookmark-alist blist)
+                        (setq bookmark-alist-modification-count 0))
+                    ;; else
+                    (bookmark-import-new-list blist)
+                    (setq bookmark-alist-modification-count
+                          (1+ bookmark-alist-modification-count)))
+                  (if (string-equal
+                       (expand-file-name bookmark-default-file)
+                       file)
+                      (setq bookmarks-already-loaded t))
+                  (bookmark-bmenu-surreptitiously-rebuild-list))
+              (error "Invalid bookmark list in %s" file)))
           (kill-buffer (current-buffer)))
-       (if (and (null no-msg) (>= baud-rate 9600))
-            (message (format "Loading bookmarks from %s... done" file))))
-    (error (format "Cannot read bookmark file %s." file))))
+       (if (null no-msg)
+            (bookmark-maybe-message "Loading bookmarks from %s...done" file)))
+    (error "Cannot read bookmark file %s" file)))
 
 
 \f
@@ -1289,19 +1484,6 @@ explicitly."
 (defvar bookmark-bmenu-hidden-bookmarks ())
 
 
-(defvar bookmark-bmenu-file-column 30
-  "*Column at which to display filenames in a buffer listing bookmarks.
-You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames].")
-
-
-(defvar bookmark-bmenu-toggle-filenames t
-  "*Non-nil means show filenames when listing bookmarks.
-This may result in truncated bookmark names.  To disable this, put the
-following in your .emacs:
-
-\(setq bookmark-bmenu-toggle-filenames nil\)")
-
-
 (defvar bookmark-bmenu-mode-map nil)
 
 
@@ -1309,20 +1491,22 @@ following in your .emacs:
     nil
   (setq bookmark-bmenu-mode-map (make-keymap))
   (suppress-keymap bookmark-bmenu-mode-map t)
-  (define-key bookmark-bmenu-mode-map "q" 'bookmark-bmenu-quit)
+  (define-key bookmark-bmenu-mode-map "q" 'quit-window)
   (define-key bookmark-bmenu-mode-map "v" 'bookmark-bmenu-select)
   (define-key bookmark-bmenu-mode-map "w" 'bookmark-bmenu-locate)
   (define-key bookmark-bmenu-mode-map "2" 'bookmark-bmenu-2-window)
   (define-key bookmark-bmenu-mode-map "1" 'bookmark-bmenu-1-window)
   (define-key bookmark-bmenu-mode-map "j" 'bookmark-bmenu-this-window)
+  (define-key bookmark-bmenu-mode-map "\C-c\C-c" 'bookmark-bmenu-this-window)
   (define-key bookmark-bmenu-mode-map "f" 'bookmark-bmenu-this-window)
+  (define-key bookmark-bmenu-mode-map "\C-m" 'bookmark-bmenu-this-window)
   (define-key bookmark-bmenu-mode-map "o" 'bookmark-bmenu-other-window)
-  (define-key bookmark-bmenu-mode-map "\C-o" 'bookmark-bmenu-switch-other-window)
+  (define-key bookmark-bmenu-mode-map "\C-o"
+    'bookmark-bmenu-switch-other-window)
   (define-key bookmark-bmenu-mode-map "s" 'bookmark-bmenu-save)
   (define-key bookmark-bmenu-mode-map "k" 'bookmark-bmenu-delete)
   (define-key bookmark-bmenu-mode-map "\C-d" 'bookmark-bmenu-delete-backwards)
   (define-key bookmark-bmenu-mode-map "x" 'bookmark-bmenu-execute-deletions)
-  (define-key bookmark-bmenu-mode-map "\C-k" 'bookmark-bmenu-delete)
   (define-key bookmark-bmenu-mode-map "d" 'bookmark-bmenu-delete)
   (define-key bookmark-bmenu-mode-map " " 'next-line)
   (define-key bookmark-bmenu-mode-map "n" 'next-line)
@@ -1331,14 +1515,17 @@ following in your .emacs:
   (define-key bookmark-bmenu-mode-map "?" 'describe-mode)
   (define-key bookmark-bmenu-mode-map "u" 'bookmark-bmenu-unmark)
   (define-key bookmark-bmenu-mode-map "m" 'bookmark-bmenu-mark)
-  (define-key bookmark-bmenu-mode-map "l" 'bookmark-bmenu-load) 
+  (define-key bookmark-bmenu-mode-map "l" 'bookmark-bmenu-load)
   (define-key bookmark-bmenu-mode-map "r" 'bookmark-bmenu-rename)
+  (define-key bookmark-bmenu-mode-map "R" 'bookmark-bmenu-relocate)
   (define-key bookmark-bmenu-mode-map "t" 'bookmark-bmenu-toggle-filenames)
   (define-key bookmark-bmenu-mode-map "a" 'bookmark-bmenu-show-annotation)
   (define-key bookmark-bmenu-mode-map "A" 'bookmark-bmenu-show-all-annotations)
-  (define-key bookmark-bmenu-mode-map "e" 'bookmark-bmenu-edit-annotation))
+  (define-key bookmark-bmenu-mode-map "e" 'bookmark-bmenu-edit-annotation)
+  (define-key bookmark-bmenu-mode-map [mouse-2]
+    'bookmark-bmenu-other-window-with-mouse))
+
 
-  
 
 ;; Bookmark Buffer Menu mode is suitable only for specially formatted
 ;; data.
@@ -1346,7 +1533,7 @@ following in your .emacs:
 
 
 ;; todo: need to display whether or not bookmark exists as a buffer in
-;; flag column. 
+;; flag column.
 
 ;; Format:
 ;; FLAGS  BOOKMARK [ LOCATION ]
@@ -1357,7 +1544,7 @@ following in your .emacs:
 Don't affect the buffer ring order."
   (if (get-buffer "*Bookmark List*")
       (save-excursion
-        (save-window-excursion 
+        (save-window-excursion
           (bookmark-bmenu-list)))))
 
 
@@ -1372,22 +1559,34 @@ deletion, or > if it is flagged for displaying."
   (if (interactive-p)
       (switch-to-buffer (get-buffer-create "*Bookmark List*"))
     (set-buffer (get-buffer-create "*Bookmark List*")))
-  (let ((buffer-read-only nil))
-    (delete-region (point-max) (point-min))
-    (goto-char (point-min)) ;sure are playing it safe...
+  (let ((inhibit-read-only t))
+    (erase-buffer)
     (insert "% Bookmark\n- --------\n")
+    (add-text-properties (point-min) (point)
+                        '(font-lock-face bookmark-menu-heading))
     (bookmark-maybe-sort-alist)
     (mapcar
      (lambda (full-record)
-       ;; if a bookmark has an annotation, preceed it with a "*"
+       ;; if a bookmark has an annotation, prepend a "*"
        ;; in the list of bookmarks.
        (let ((annotation (bookmark-get-annotation
                           (bookmark-name-from-full-record full-record))))
-         (if (and (not (eq annotation nil))
-                  (not (string-equal annotation "")))
+         (if (and annotation (not (string-equal annotation "")))
              (insert " *")
            (insert "  "))
-         (insert (concat (bookmark-name-from-full-record full-record) "\n"))))
+        (let ((start (point)))
+          (insert (bookmark-name-from-full-record full-record))
+          (if (and (display-color-p) (display-mouse-p))
+              (add-text-properties
+               start
+               (save-excursion (re-search-backward
+                                "[^ \t]")
+                               (1+ (point)))
+               '(mouse-face highlight
+                 follow-link t
+                 help-echo "mouse-2: go to this bookmark in other window")))
+          (insert "\n")
+          )))
      bookmark-alist))
   (goto-char (point-min))
   (forward-line 2)
@@ -1406,7 +1605,7 @@ deletion, or > if it is flagged for displaying."
   "Major mode for editing a list of bookmarks.
 Each line describes one of the bookmarks in Emacs.
 Letters do not insert themselves; instead, they are commands.
-Bookmark names preceeded by a \"*\" have annotations.
+Bookmark names preceded by a \"*\" have annotations.
 \\<bookmark-bmenu-mode-map>
 \\[bookmark-bmenu-mark] -- mark bookmark to be displayed.
 \\[bookmark-bmenu-select] -- select bookmark of line point is on.
@@ -1420,10 +1619,11 @@ Bookmark names preceeded by a \"*\" have annotations.
 \\[bookmark-bmenu-other-window] -- select this bookmark in another window,
   so the bookmark menu bookmark remains visible in its window.
 \\[bookmark-bmenu-switch-other-window] -- switch the other window to this bookmark.
-\\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).   
+\\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).
+\\[bookmark-bmenu-relocate] -- relocate this bookmark's file \(prompts for new file\).
 \\[bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
-\\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up. 
-\\[bookmark-bmenu-execute-deletions] -- delete marked bookmarks.
+\\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
+\\[bookmark-bmenu-execute-deletions] -- delete bookmarks marked with `\\[bookmark-bmenu-delete]'.
 \\[bookmark-bmenu-save] -- save the current bookmark list in the default file.
   With a prefix arg, prompts for a file to save in.
 \\[bookmark-bmenu-load] -- load in a file of bookmarks (prompts for file.)
@@ -1440,15 +1640,15 @@ Bookmark names preceeded by a \"*\" have annotations.
   (setq buffer-read-only t)
   (setq major-mode 'bookmark-bmenu-mode)
   (setq mode-name "Bookmark Menu")
-  (run-hooks 'bookmark-bmenu-mode-hook))
+  (run-mode-hooks 'bookmark-bmenu-mode-hook))
 
 
-(defun bookmark-bmenu-toggle-filenames (&optional parg)
+(defun bookmark-bmenu-toggle-filenames (&optional show)
   "Toggle whether filenames are shown in the bookmark list.
 Optional argument SHOW means show them unconditionally."
   (interactive)
   (cond
-   (parg
+   (show
     (setq bookmark-bmenu-toggle-filenames nil)
     (bookmark-bmenu-show-filenames)
     (setq bookmark-bmenu-toggle-filenames t))
@@ -1468,15 +1668,21 @@ Optional argument SHOW means show them unconditionally."
         (goto-char (point-min))
         (forward-line 2)
         (setq bookmark-bmenu-hidden-bookmarks ())
-        (let ((buffer-read-only nil))
+        (let ((inhibit-read-only t))
           (while (< (point) (point-max))
             (let ((bmrk (bookmark-bmenu-bookmark)))
               (setq bookmark-bmenu-hidden-bookmarks
                     (cons bmrk bookmark-bmenu-hidden-bookmarks))
-              (move-to-column bookmark-bmenu-file-column t)
-              (delete-region (point) (progn (end-of-line) (point)))
+             (let ((start (save-excursion (end-of-line) (point))))
+               (move-to-column bookmark-bmenu-file-column t)
+               ;; Strip off `mouse-face' from the white spaces region.
+               (if (and (display-color-p) (display-mouse-p))
+                   (remove-text-properties start (point)
+                                           '(mouse-face nil help-echo nil))))
+             (delete-region (point) (progn (end-of-line) (point)))
               (insert "  ")
-              (bookmark-insert-location bmrk)
+              ;; Pass the NO-HISTORY arg:
+              (bookmark-insert-location bmrk t)
               (forward-line 1))))))))
 
 
@@ -1495,32 +1701,40 @@ Optional argument SHOW means show them unconditionally."
             (backward-word 1)
             (setq bookmark-bmenu-bookmark-column (current-column)))
           (save-excursion
-            (let ((buffer-read-only nil))
+            (let ((inhibit-read-only t))
               (while bookmark-bmenu-hidden-bookmarks
                 (move-to-column bookmark-bmenu-bookmark-column t)
                 (bookmark-kill-line)
-                (insert (car bookmark-bmenu-hidden-bookmarks))
+               (let ((start (point)))
+                 (insert (car bookmark-bmenu-hidden-bookmarks))
+                 (if (and (display-color-p) (display-mouse-p))
+                     (add-text-properties
+                      start
+                      (save-excursion (re-search-backward
+                                       "[^ \t]")
+                                      (1+ (point)))
+                      '(mouse-face highlight
+                        follow-link t
+                        help-echo
+                        "mouse-2: go to this bookmark in other window"))))
                 (setq bookmark-bmenu-hidden-bookmarks
                       (cdr bookmark-bmenu-hidden-bookmarks))
                 (forward-line 1))))))))
 
 
-;; if you look at this next function from far away, it resembles a
-;; gun.  But only with this comment above... 
 (defun bookmark-bmenu-check-position ()
-  ;; Returns t if on a line with a bookmark.
-  ;; Otherwise, repositions and returns t.
-  ;; written by David Hughes <djh@harston.cv.com>
-  ;; Mucho thanks, David!  -karl
+  ;; Returns non-nil if on a line with a bookmark.
+  ;; (The actual value returned is bookmark-alist).
+  ;; Else reposition and try again, else return nil.
   (cond ((< (count-lines (point-min) (point)) 2)
          (goto-char (point-min))
          (forward-line 2)
-         t)
+         bookmark-alist)
         ((and (bolp) (eobp))
          (beginning-of-line 0)
-         t)
+         bookmark-alist)
         (t
-         t)))
+         bookmark-alist)))
 
 
 (defun bookmark-bmenu-bookmark ()
@@ -1539,8 +1753,8 @@ Optional argument SHOW means show them unconditionally."
       (beginning-of-line)
       (forward-char bookmark-bmenu-bookmark-column)
       (prog1
-          (buffer-substring (point)
-                            (progn 
+          (buffer-substring-no-properties (point)
+                            (progn
                               (end-of-line)
                               (point)))
         ;; well, this is certainly crystal-clear:
@@ -1552,17 +1766,15 @@ Optional argument SHOW means show them unconditionally."
   "Display the annotation for bookmark named BOOKMARK in a buffer,
 if an annotation exists."
   (let ((annotation (bookmark-get-annotation bookmark)))
-    (if (and (not (eq annotation nil))
-            (not (string-equal annotation "")))
-       (progn
-          (save-excursion
-           (let ((old-buf (current-buffer)))
-             (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
-             (delete-region (point-min) (point-max))
-             ; (insert (concat "Annotation for bookmark '" bookmark "':\n\n"))
-             (insert annotation)
-             (goto-char (point-min))
-             (pop-to-buffer old-buf)))))))
+    (if (and annotation (not (string-equal annotation "")))
+        (save-excursion
+          (let ((old-buf (current-buffer)))
+            (pop-to-buffer (get-buffer-create "*Bookmark Annotation*") t)
+            (delete-region (point-min) (point-max))
+            ;; (insert (concat "Annotation for bookmark '" bookmark "':\n\n"))
+            (insert annotation)
+            (goto-char (point-min))
+            (pop-to-buffer old-buf))))))
 
 
 (defun bookmark-show-all-annotations ()
@@ -1575,7 +1787,7 @@ if an annotation exists."
        (let* ((name (bookmark-name-from-full-record full-record))
               (ann  (bookmark-get-annotation name)))
          (insert (concat name ":\n"))
-         (if (and (not (eq ann nil)) (not (string-equal ann "")))
+         (if (and ann (not (string-equal ann "")))
              ;; insert the annotation, indented by 4 spaces.
              (progn
                (save-excursion (insert ann))
@@ -1590,14 +1802,15 @@ if an annotation exists."
 
 
 (defun bookmark-bmenu-mark ()
-  "Mark bookmark on this line to be displayed by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-select] command."
+  "Mark bookmark on this line to be displayed by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-select]."
   (interactive)
   (beginning-of-line)
   (if (bookmark-bmenu-check-position)
-      (let ((buffer-read-only nil))
+      (let ((inhibit-read-only t))
         (delete-char 1)
         (insert ?>)
-        (forward-line 1))))
+        (forward-line 1)
+        (bookmark-bmenu-check-position))))
 
 
 (defun bookmark-bmenu-select ()
@@ -1606,30 +1819,29 @@ You can mark bookmarks with the \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-mar
   (interactive)
   (if (bookmark-bmenu-check-position)
       (let ((bmrk (bookmark-bmenu-bookmark))
-            (menu (current-buffer))          
+            (menu (current-buffer))
             (others ())
             tem)
         (goto-char (point-min))
         (while (re-search-forward "^>" nil t)
           (setq tem (bookmark-bmenu-bookmark))
-          (let ((buffer-read-only nil))
+          (let ((inhibit-read-only t))
             (delete-char -1)
-            (insert ?\ ))
-          (or (string-equal tem bmrk) 
-              (memq tem others) 
+            (insert ?\s))
+          (or (string-equal tem bmrk)
+              (member tem others)
               (setq others (cons tem others))))
         (setq others (nreverse others)
               tem (/ (1- (frame-height)) (1+ (length others))))
         (delete-other-windows)
         (bookmark-jump bmrk)
         (bury-buffer menu)
-        (if (equal (length others) 0)
-            nil
-          (while others
-            (split-window nil tem)
-            (other-window 1)
-            (bookmark-jump (car others))
-            (setq others (cdr others)))
+        (if others
+            (while others
+              (split-window nil tem)
+              (other-window 1)
+              (bookmark-jump (car others))
+              (setq others (cdr others)))
           (other-window 1)))))
 
 
@@ -1671,8 +1883,11 @@ With a prefix arg, prompts for a file to save them in."
             (pop-up-windows t))
         (delete-other-windows)
         (switch-to-buffer (other-buffer))
-        (let ((buff (car (bookmark-jump-noselect bmrk))))
-          (pop-to-buffer buff))
+       (let* ((pair (bookmark-jump-noselect bmrk))
+               (buff (car pair))
+               (pos  (cdr pair)))
+          (pop-to-buffer buff)
+          (goto-char pos))
         (bury-buffer menu))))
 
 
@@ -1688,11 +1903,46 @@ With a prefix arg, prompts for a file to save them in."
   (interactive)
   (let ((bookmark (bookmark-bmenu-bookmark)))
     (if (bookmark-bmenu-check-position)
-       (let ((buff (car (bookmark-jump-noselect bookmark))))
+       (let* ((pair (bookmark-jump-noselect bookmark))
+               (buff (car pair))
+               (pos  (cdr pair)))
          (switch-to-buffer-other-window buff)
+          (goto-char pos)
+          (set-window-point (get-buffer-window buff) pos)
          (bookmark-show-annotation bookmark)))))
 
 
+(defun bookmark-bmenu-switch-other-window ()
+  "Make the other window select this line's bookmark.
+The current window remains selected."
+  (interactive)
+  (let ((bookmark (bookmark-bmenu-bookmark))
+        (pop-up-windows t)
+        same-window-buffer-names
+        same-window-regexps)
+    (if (bookmark-bmenu-check-position)
+       (let* ((pair (bookmark-jump-noselect bookmark))
+               (buff (car pair))
+               (pos  (cdr pair)))
+         (display-buffer buff)
+          (let ((o-buffer (current-buffer)))
+            ;; save-excursion won't do
+            (set-buffer buff)
+            (goto-char pos)
+            (set-window-point (get-buffer-window buff) pos)
+            (set-buffer o-buffer))
+         (bookmark-show-annotation bookmark)))))
+
+(defun bookmark-bmenu-other-window-with-mouse (event)
+  "Select bookmark at the mouse pointer in other window, leaving bookmark menu visible."
+  (interactive "e")
+  (save-excursion
+    (set-buffer (window-buffer (posn-window (event-end event))))
+    (save-excursion
+      (goto-char (posn-point (event-end event)))
+      (bookmark-bmenu-other-window))))
+
+
 (defun bookmark-bmenu-show-annotation ()
   "Show the annotation for the current bookmark in another window."
   (interactive)
@@ -1715,39 +1965,21 @@ With a prefix arg, prompts for a file to save them in."
        (bookmark-edit-annotation bookmark))))
 
 
-(defun bookmark-bmenu-switch-other-window ()
-  "Make the other window select this line's bookmark.
-The current window remains selected."
-  (interactive)
-  (let ((bookmark (bookmark-bmenu-bookmark)))
-    (if (bookmark-bmenu-check-position)
-       (let ((buff (car (bookmark-jump-noselect bookmark))))
-         (display-buffer buff)
-         (bookmark-show-annotation bookmark)))))
-
-
-(defun bookmark-bmenu-quit ()
-  "Quit the bookmark menu."
-  (interactive)
-  (let ((buffer (current-buffer)))
-    (switch-to-buffer (other-buffer))
-    (bury-buffer buffer)))
-
-
 (defun bookmark-bmenu-unmark (&optional backup)
   "Cancel all requested operations on bookmark on this line and move down.
-Optional ARG means move up."
+Optional BACKUP means move up."
   (interactive "P")
   (beginning-of-line)
   (if (bookmark-bmenu-check-position)
       (progn
-        (let ((buffer-read-only nil))
+        (let ((inhibit-read-only t))
           (delete-char 1)
           ;; any flags to reset according to circumstances?  How about a
           ;; flag indicating whether this bookmark is being visited?
           ;; well, we don't have this now, so maybe later.
           (insert " "))
-        (forward-line (if backup -1 1)))))
+        (forward-line (if backup -1 1))
+        (bookmark-bmenu-check-position))))
 
 
 (defun bookmark-bmenu-backup-unmark ()
@@ -1757,33 +1989,38 @@ Optional ARG means move up."
   (if (bookmark-bmenu-check-position)
       (progn
         (bookmark-bmenu-unmark)
-        (forward-line -1))))
+        (forward-line -1)
+        (bookmark-bmenu-check-position))))
 
 
 (defun bookmark-bmenu-delete ()
-  "Mark bookmark on this line to be deleted by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions] command."
+  "Mark bookmark on this line to be deleted.
+To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions]."
   (interactive)
   (beginning-of-line)
   (if (bookmark-bmenu-check-position)
-      (let ((buffer-read-only nil))
+      (let ((inhibit-read-only t))
         (delete-char 1)
         (insert ?D)
-        (forward-line 1))))
+        (forward-line 1)
+        (bookmark-bmenu-check-position))))
 
 
 (defun bookmark-bmenu-delete-backwards ()
-  "Mark bookmark on this line to be deleted by \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions] command
-and then move up one line"
+  "Mark bookmark on this line to be deleted, then move up one line.
+To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-execute-deletions]."
   (interactive)
   (bookmark-bmenu-delete)
   (forward-line -2)
   (if (bookmark-bmenu-check-position)
-      (forward-line 1)))
+      (forward-line 1))
+  (bookmark-bmenu-check-position))
 
 
 (defun bookmark-bmenu-execute-deletions ()
   "Delete bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
   (interactive)
+  (message "Deleting bookmarks...")
   (let ((hide-em bookmark-bmenu-toggle-filenames)
         (o-point  (point))
         (o-str    (save-excursion
@@ -1815,7 +2052,9 @@ and then move up one line"
     (setq bookmark-alist-modification-count
           (1+ bookmark-alist-modification-count))
     (if (bookmark-time-to-save-p)
-        (bookmark-save))))
+        (bookmark-save))
+    (message "Deleting bookmarks...done")
+    ))
 
 
 (defun bookmark-bmenu-rename ()
@@ -1834,192 +2073,115 @@ and then move up one line"
   (interactive)
   (if (bookmark-bmenu-check-position)
       (let ((bmrk (bookmark-bmenu-bookmark)))
-        (message (bookmark-location bmrk)))))
+        (message "%s" (bookmark-location bmrk)))))
 
+(defun bookmark-bmenu-relocate ()
+  "Change the file path of the bookmark on the current line,
+  prompting with completion for the new path."
+  (interactive)
+  (if (bookmark-bmenu-check-position)
+      (let ((bmrk (bookmark-bmenu-bookmark))
+            (thispoint (point)))
+        (bookmark-relocate bmrk)
+        (goto-char thispoint))))
 
 \f
 ;;; Menu bar stuff.  Prefix is "bookmark-menu".
 
-(defvar bookmark-menu-length 70
-  "*Maximum length of a bookmark name displayed on a popup menu.")
-
-
-(defun bookmark-menu-build-paned-menu (name entries)
-  "Build a multi-paned menu named NAME from the strings in ENTRIES.
-That is, ENTRIES is a list of strings which appear as the choices
-in the menu.  The number of panes depends on the number of entries.
-The visible entries are truncated to `bookmark-menu-length', but the
-strings returned are not."
-  (let* ((f-height (/ (frame-height) 2))
-         (pane-list
-          (let (temp-pane-list
-                (iter 0))
-            (while entries
-              (let (lst
-                    (count 0))
-                (while (and (< count f-height) entries)
-                  (let ((str (car entries)))
-                    (setq lst (cons
-                               (cons
-                                (if (> (length str) bookmark-menu-length)
-                                    (substring str 0 bookmark-menu-length)
-                                  str)
-                                str)
-                               lst))
-                    (setq entries (cdr entries))
-                    (setq count (1+ count))))
-                (setq iter (1+ iter))
-                (setq
-                 temp-pane-list
-                 (cons
-                  (cons
-                   (format "-*- %s (%d) -*-" name iter)
-                   (nreverse lst))
-                  temp-pane-list))))
-            (nreverse temp-pane-list))))
-
-    ;; Return the menu:
-    (cons (concat "-*- " name " -*-") pane-list)))
-
-
 (defun bookmark-menu-popup-paned-menu (event name entries)
   "Pop up multi-paned menu at EVENT, return string chosen from ENTRIES.
 That is, ENTRIES is a list of strings which appear as the choices
 in the menu.
-The number of panes depends on the number of entries."
-  (interactive "e")
-  (x-popup-menu event (bookmark-menu-build-paned-menu name entries)))
-
-
-(defun bookmark-menu-popup-paned-bookmark-menu (event name)
-  "Pop up menu of bookmarks, return chosen bookmark.
-Pop up at EVENT, menu's name is NAME.
-The number of panes depends on the number of bookmarks."
-  (bookmark-menu-popup-paned-menu event name (bookmark-all-names)))
-
-
-(defun bookmark-popup-menu-and-apply-function (func-sym menu-label event)
-  ;; help function for making menus that need to apply a bookmark
-  ;; function to a string.
-  (let* ((choice (bookmark-menu-popup-paned-bookmark-menu
-                  event menu-label)))
-    (if choice (apply func-sym (list choice)))))
-
-
-(defun bookmark-menu-insert (event)
-  "Insert the text of the file pointed to by bookmark BOOKMARK.  
-You may have a problem using this function if the value of variable
-`bookmark-alist' is nil.  If that happens, you need to load in some
-bookmarks.  See help on function `bookmark-load' for more about
-this."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-insert "Insert Bookmark Contents" event))
-
-
-(defun bookmark-menu-jump (event)
-  "Jump to bookmark BOOKMARK (a point in some file).  
-You may have a problem using this function if the value of variable
-`bookmark-alist' is nil.  If that happens, you need to load in some
-bookmarks.  See help on function `bookmark-load' for more about
-this."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-jump "Jump to Bookmark" event))
-
-
-(defun bookmark-menu-locate (event)
-  "Insert the name of the file associated with BOOKMARK. 
-\(This is not the same as the contents of that file\)."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-insert-location "Insert Bookmark Location" event))
-
-
-(defun bookmark-menu-rename (event)
-  "Change the name of OLD-BOOKMARK to NEWNAME.  
-If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
-If called from menubar, OLD-BOOKMARK is selected from a menu, and
-prompts for NEWNAME. 
-If called from Lisp, prompts for NEWNAME if only OLD-BOOKMARK was
-passed as an argument.  If called with two strings, then no prompting
-is done.  You must pass at least OLD-BOOKMARK when calling from Lisp.
-
-While you are entering the new name, consecutive C-w's insert
-consectutive words from the text of the buffer into the new bookmark
-name, and C-v inserts the name of the file."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-rename "Rename Bookmark" event))
-
-
-(defun bookmark-menu-delete (event)
-  "Delete the bookmark named NAME from the bookmark list.  
-Removes only the first instance of a bookmark with that name.  If
-there are one or more other bookmarks with the same name, they will
-not be deleted.  Defaults to the \"current\" bookmark \(that is, the
-one most recently used in this file, if any\)."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-delete "Delete Bookmark" event))
+The number of panes depends on the number of entries.
+The visible entries are truncated to `bookmark-menu-length', but the
+strings returned are not."
+  (let ((f-height (/ (frame-height) 2))
+       (pane-list nil)
+       (iter 0))
+    (while entries
+      (let (lst
+           (count 0))
+       (while (and (< count f-height) entries)
+         (let ((str (car entries)))
+           (push (cons
+                  (if (> (length str) bookmark-menu-length)
+                      (substring str 0 bookmark-menu-length)
+                    str)
+                  str)
+                 lst)
+           (setq entries (cdr entries))
+           (setq count (1+ count))))
+       (setq iter (1+ iter))
+       (push (cons
+              (format "-*- %s (%d) -*-" name iter)
+              (nreverse lst))
+             pane-list)))
+
+    ;; Popup the menu and return the string.
+    (x-popup-menu event (cons (concat "-*- " name " -*-")
+                             (nreverse pane-list)))))
 
 
 ;; Thanks to Roland McGrath for fixing menubar.el so that the
 ;; following works, and for explaining what to do to make it work.
 
-(defvar menu-bar-bookmark-map (make-sparse-keymap "Bookmark functions."))
+;; We MUST autoload EACH form used to set up this variable's value, so
+;; that the whole job is done in loaddefs.el.
 
+;; Emacs menubar stuff.
+
+;;;###autoload
+(defvar menu-bar-bookmark-map
+  (let ((map (make-sparse-keymap "Bookmark functions")))
+    (define-key map [load]     '("Load a Bookmark File..." . bookmark-load))
+    (define-key map [write]    '("Save Bookmarks As..." . bookmark-write))
+    (define-key map [save]     '("Save Bookmarks" . bookmark-save))
+    (define-key map [edit]     '("Edit Bookmark List" . bookmark-bmenu-list))
+    (define-key map [delete]   '("Delete Bookmark..." . bookmark-delete))
+    (define-key map [rename]   '("Rename Bookmark..." . bookmark-rename))
+    (define-key map [locate]   '("Insert Location..." . bookmark-locate))
+    (define-key map [insert]   '("Insert Contents..." . bookmark-insert))
+    (define-key map [set]      '("Set Bookmark..." . bookmark-set))
+    (define-key map [jump]     '("Jump to Bookmark..." . bookmark-jump))
+    map))
+
+;;;###autoload
+(defalias 'menu-bar-bookmark-map menu-bar-bookmark-map)
 
 ;; make bookmarks appear toward the right side of the menu.
 (if (boundp 'menu-bar-final-items)
-    (if menu-bar-final-items 
+    (if menu-bar-final-items
         (setq menu-bar-final-items
               (cons 'bookmark menu-bar-final-items)))
   (setq menu-bar-final-items '(bookmark)))
 
-(define-key menu-bar-bookmark-map [load]
-  '("Load a bookmark file" . bookmark-load))
-
-(define-key menu-bar-bookmark-map [write]
-  '("Write \(to another file\)" . bookmark-write))
-
-(define-key menu-bar-bookmark-map [save]
-  '("Save  \(in default file\)" . bookmark-save))
-
-(define-key menu-bar-bookmark-map [edit]
-  '("Edit Bookmark List" . bookmark-bmenu-list))
-
-(define-key menu-bar-bookmark-map [delete]
-  '("Delete bookmark" . bookmark-menu-delete))
-
-(define-key menu-bar-bookmark-map [rename]
-  '("Rename bookmark" . bookmark-menu-rename))
-
-(define-key menu-bar-bookmark-map [locate]
-  '("Insert location" . bookmark-menu-locate))
+;;;; end bookmark menu stuff ;;;;
 
-(define-key menu-bar-bookmark-map [insert]
-  '("Insert contents" . bookmark-menu-insert))
+\f
+;;; Load Hook
+(defvar bookmark-load-hook nil
+  "Hook run at the end of loading bookmark.")
 
-(define-key menu-bar-bookmark-map [set]
-  '("Set bookmark" . bookmark-set))
+;;; Exit Hook, called from kill-emacs-hook
+(defvar bookmark-exit-hook nil
+  "Hook run when Emacs exits.")
 
-(define-key menu-bar-bookmark-map [jump] 
-  '("Jump to bookmark" . bookmark-menu-jump))
-;;;###autoload (autoload 'menu-bar-bookmark-map "bookmark" nil t 'keymap)
+(define-obsolete-variable-alias 'bookmark-exit-hooks 'bookmark-exit-hook "22.1")
 
-(fset 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
+(defun bookmark-exit-hook-internal ()
+  "Save bookmark state, if necessary, at Emacs exit time.
+This also runs `bookmark-exit-hook'."
+  (run-hooks 'bookmark-exit-hook)
+  (and bookmark-alist
+       (bookmark-time-to-save-p t)
+       (bookmark-save)))
 
-;;;; end bookmark menu stuff ;;;;
+(add-hook 'kill-emacs-hook 'bookmark-exit-hook-internal)
 
-\f
-;;; Load Hook
-(defvar bookmark-load-hook nil
-  "Hook to run at the end of loading bookmark.")
 
 (run-hooks 'bookmark-load-hook)
 
 (provide 'bookmark)
-      
+
+;;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6
 ;;; bookmark.el ends here