Add arch taglines
[bpt/emacs.git] / lisp / bookmark.el
index 4340048..762de73 100644 (file)
@@ -1,11 +1,10 @@
-;;; 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, 1996 Free Software Foundation
+;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001, 2003 Free Software Foundation
 
 ;; Author: Karl Fogel <kfogel@red-bean.com>
 ;; Maintainer: Karl Fogel <kfogel@red-bean.com>
 ;; Created: July, 1993
-;; Author's Update Number: see variable `bookmark-version'.
 ;; Keywords: bookmarks, placeholders, annotations
 
 ;; This file is part of GNU Emacs.
 
 ;; 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
-;;;; Code:
+;;; Code:
 
 (require 'pp)
 
-(defconst bookmark-version "2.6.4"
-  "Version number of bookmark.el.  This is not related to the version
-of Emacs bookmark comes with; it is used solely by bookmark's
-maintainers to avoid version confusion.")
-
 ;;; 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
@@ -99,14 +93,20 @@ maintainers to avoid version confusion.")
 
 ;;; User Variables
 
-(defvar bookmark-use-annotations nil
-  "*If non-nil, saving a bookmark will query for an annotation in a
-buffer.")
+(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)
 
 
-(defvar bookmark-save-flag t
+(defcustom bookmark-save-flag t
   "*Controls when Emacs saves bookmarks to a file.
---> Nil means never save bookmarks, except when `bookmark-save' is
+--> 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
@@ -120,64 +120,81 @@ 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.")
+`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.")
+  "*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'.")
 
-(defvar bookmark-default-file
+(defcustom bookmark-default-file
   (if 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.")
+    (convert-standard-filename "~/.emacs.bmk"))
+  "*File in which to save bookmarks by default."
+  :type 'file
+  :group 'bookmark)
 
 
-(defvar bookmark-version-control 'nospecial
+(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'.")
+use the value of `version-control'."
+  :type '(choice (const nil) (const never) (const nospecial)
+                (other t))
+  :group 'bookmark)
 
 
-(defvar bookmark-completion-ignore-case t
-  "*Non-nil means bookmark functions ignore case in completion.")
+(defcustom bookmark-completion-ignore-case t
+  "*Non-nil means bookmark functions ignore case in completion."
+  :type 'boolean
+  :group 'bookmark)
 
 
-(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).")
+(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)
 
 
-(defvar bookmark-automatically-show-annotations t
-  "*Nil means don't show annotations when jumping to a bookmark.")
+(defcustom bookmark-automatically-show-annotations t
+  "*nil means don't show annotations when jumping to a bookmark."
+  :type 'boolean
+  :group 'bookmark)
 
 
-(defvar bookmark-bmenu-file-column 30
+(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].")
+You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames]."
+  :type 'integer
+  :group 'bookmark)
 
 
-(defvar bookmark-bmenu-toggle-filenames t
+(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:
+following in your `.emacs' file:
 
-\(setq bookmark-bmenu-toggle-filenames nil\)")
+\(setq bookmark-bmenu-toggle-filenames nil\)"
+  :type 'boolean
+  :group 'bookmark)
 
 
-(defvar bookmark-menu-length 70
-  "*Maximum length of a bookmark name displayed on a popup menu.")
+(defcustom bookmark-menu-length 70
+  "*Maximum length of a bookmark name displayed on a popup menu."
+  :type 'integer
+  :group 'bookmark)
 
 
 ;;; No user-serviceable parts beyond this point.
@@ -195,32 +212,19 @@ following in your .emacs:
 
 ;; This variable is probably obsolete now...
 (or (boundp 'baud-rate)
-    ;; some random value higher than 9600    
+    ;; some random value higher than 9600
     (setq baud-rate 19200))
 
-;; XEmacs apparently call this `buffer-substring-without-properties',
-;; sigh.
-(or (fboundp 'buffer-substring-no-properties)
-    (if (fboundp 'buffer-substring-without-properties)
-        (fset 'buffer-substring-no-properties
-              'buffer-substring-without-properties)
-      (fset 'buffer-substring-no-properties 'buffer-substring)))
 
 \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
@@ -230,34 +234,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.")
 
-;;;###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.
@@ -296,19 +287,9 @@ So the cdr of each bookmark is an alist too.
 (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.")
@@ -351,8 +332,13 @@ through a file easier.")
 
 
 (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)
+    (apply (if bookmark-completion-ignore-case
+              #'assoc-ignore-case
+            #'assoc)
+          (list bookmark bookmark-alist))))
 
 
 (defun bookmark-get-bookmark-record (bookmark)
@@ -363,7 +349,9 @@ That is, all information but the name."
 
 (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)
@@ -441,7 +429,7 @@ 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."
@@ -455,7 +443,7 @@ That is, all information but the name."
   (message "%S" (assq 'info-node (bookmark-get-bookmark-record bookmark)))
   (sit-for 4)
   )
-  
+
 
 (defvar bookmark-history nil
   "The history list for bookmark functions.")
@@ -468,30 +456,30 @@ 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
-                           nil
-                           'bookmark-history)))
-    (if (string-equal "" str)
-        (list default)
-      (list str))))
+  (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)))))
+  `(or
+    (interactive-p)
+    (setq bookmark-history (cons ,string bookmark-history))))
 
 
 (defun bookmark-make (name &optional annotation overwrite info-node)
@@ -512,17 +500,17 @@ INFO-NODE, so record this fact in the bookmark's entry."
         ;; 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 
+             (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
@@ -538,23 +526,27 @@ 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)))
-             ))))
+         `((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
@@ -562,8 +554,8 @@ INFO-NODE, so record this fact in the bookmark's entry."
 
     ;; Finally, return the completed record.
     the-record))
-    
-  
+
+
 \f
 ;;; File format stuff
 
@@ -595,17 +587,17 @@ INFO-NODE, so record this fact in the bookmark's entry."
 ;; 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.
@@ -655,11 +647,11 @@ 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))
 
 
@@ -766,21 +758,18 @@ the list of bookmarks.\)"
                (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-u" 
-                          'bookmark-insert-current-bookmark))
+                 (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 (bookmark-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 ()
@@ -820,7 +809,7 @@ the bookmark (and file, and point) specified in buffer local variables."
     (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)
@@ -830,7 +819,7 @@ 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-info-current-node))
@@ -910,8 +899,7 @@ When you have finished composing, type \\[bookmark-send-annotation].
   (setq major-mode 'bookmark-edit-annotation-mode)
   (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))
 
@@ -926,7 +914,7 @@ When you have finished composing, type \\[bookmark-send-annotation].
     (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)
@@ -936,10 +924,8 @@ When you have finished composing, type \\[bookmark-send-annotation].
 
 (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 ()
@@ -997,7 +983,7 @@ In Info, return the current node."
                     (goto-char bookmark-yank-point)
                     (buffer-substring-no-properties
                      (point)
-                     (save-excursion
+                     (progn
                        (forward-word 1)
                        (setq bookmark-yank-point (point)))))))
     (insert string)))
@@ -1029,11 +1015,10 @@ For example, if this is a Info buffer, return the Info file'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 ()
@@ -1048,7 +1033,7 @@ For example, if this is a Info buffer, return the Info file's name."
 
 ;;;###autoload
 (defun bookmark-jump (bookmark)
-  "Jump to bookmark BOOKMARK (a point in some file).  
+  "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
@@ -1059,7 +1044,8 @@ 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))
+   (list (bookmark-completing-read "Jump to bookmark"
+                                  bookmark-current-bookmark)))
   (bookmark-maybe-historicize-string bookmark)
   (let ((cell (bookmark-jump-noselect bookmark)))
     (and cell
@@ -1071,6 +1057,27 @@ of the old one in the permanent bookmark record."
              (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)
   ;; a leetle helper for bookmark-jump :-)
   ;; returns (BUFFER . POINT)
@@ -1082,60 +1089,47 @@ 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)
+                  (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
@@ -1144,7 +1138,7 @@ of the old one in the permanent bookmark record."
 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 (bookmark-completing-read "Bookmark to relocate"))
+  (interactive (list (bookmark-completing-read "Bookmark to relocate")))
   (bookmark-maybe-historicize-string bookmark)
   (bookmark-maybe-load-default-file)
   (let* ((bmrk-filename (bookmark-get-filename bookmark))
@@ -1152,7 +1146,8 @@ after a bookmark was set in it."
                   (read-file-name
                    (format "Relocate %s to: " bookmark)
                    (file-name-directory bmrk-filename)))))
-    (bookmark-set-filename bookmark newloc)))
+    (bookmark-set-filename bookmark newloc)
+    (bookmark-bmenu-surreptitiously-rebuild-list)))
 
 
 ;;;###autoload
@@ -1160,9 +1155,18 @@ after a bookmark was set in it."
   "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 (bookmark-completing-read "Insert bookmark location"))
+  (interactive (list (bookmark-completing-read "Insert bookmark location")))
   (or no-history (bookmark-maybe-historicize-string bookmark))
-  (insert (bookmark-location 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
+                                help-echo "mouse-2: go to this bookmark"))))))
 
 ;;;###autoload
 (defalias 'bookmark-locate 'bookmark-insert-location)
@@ -1186,48 +1190,47 @@ must pass at least OLD when calling from Lisp.
 While you are entering the new name, consecutive C-w's insert
 consecutive words from the text of the buffer into the new bookmark
 name."
-  (interactive (bookmark-completing-read "Old 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)))
-                  (define-key now-map  "\C-w" 'bookmark-yank-word)
-                  now-map)
-                nil
-                'bookmark-history))))
-      (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 (bookmark)
-  "Insert the text of the file pointed to by bookmark 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 bookmark)))
-           (buffer-substring (point-min) (point-max)))))
+           (buffer-string))))
     (insert str-to-insert)
     (push-mark)
     (goto-char orig-point)))
@@ -1235,7 +1238,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
@@ -1243,7 +1246,8 @@ 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)))
@@ -1269,7 +1273,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)
@@ -1288,7 +1292,7 @@ Don't use this in Lisp programs; use `bookmark-save' instead."
 
 
 ;;;###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
@@ -1334,28 +1338,61 @@ for a file, defaulting to the file defined by variable
       (set-buffer (let ((enable-local-variables nil))
                     (find-file-noselect file)))
       (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 "Saving bookmarks to file %s...done" file))
-        ))))
+      (let ((print-length nil)
+           (print-level nil))
+       (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 "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.
 
@@ -1364,11 +1401,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.
@@ -1386,13 +1428,19 @@ 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)) 
+                  (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))
@@ -1418,7 +1466,7 @@ explicitly."
     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)
@@ -1426,6 +1474,7 @@ explicitly."
   (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)
@@ -1441,14 +1490,16 @@ explicitly."
   (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 "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.
@@ -1456,7 +1507,7 @@ explicitly."
 
 
 ;; todo: need to display whether or not bookmark exists as a buffer in
-;; flag column. 
+;; flag column.
 
 ;; Format:
 ;; FLAGS  BOOKMARK [ LOCATION ]
@@ -1467,7 +1518,7 @@ explicitly."
 Don't affect the buffer ring order."
   (if (get-buffer "*Bookmark List*")
       (save-excursion
-        (save-window-excursion 
+        (save-window-excursion
           (bookmark-bmenu-list)))))
 
 
@@ -1482,9 +1533,8 @@ 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")
     (bookmark-maybe-sort-alist)
     (mapcar
@@ -1493,11 +1543,20 @@ deletion, or > if it is flagged for displaying."
        ;; 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
+                                     help-echo "mouse-2: go to this bookmark")))
+          (insert "\n")
+          )))
      bookmark-alist))
   (goto-char (point-min))
   (forward-line 2)
@@ -1530,9 +1589,9 @@ Bookmark names preceded 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-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-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.
@@ -1578,13 +1637,18 @@ 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 "  ")
               ;; Pass the NO-HISTORY arg:
               (bookmark-insert-location bmrk t)
@@ -1606,32 +1670,38 @@ 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
+                                            help-echo
+                                            "mouse-2: go to this bookmark"))))
                 (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 ()
@@ -1650,8 +1720,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:
@@ -1663,17 +1733,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 ()
@@ -1686,7 +1754,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))
@@ -1705,10 +1773,11 @@ if an annotation exists."
   (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 ()
@@ -1717,17 +1786,17 @@ 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) 
-              (member tem others) 
+          (or (string-equal tem bmrk)
+              (member tem others)
               (setq others (cons tem others))))
         (setq others (nreverse others)
               tem (/ (1- (frame-height)) (1+ (length others))))
@@ -1814,7 +1883,10 @@ With a prefix arg, prompts for a file to save them in."
   "Make the other window select this line's bookmark.
 The current window remains selected."
   (interactive)
-  (let ((bookmark (bookmark-bmenu-bookmark)))
+  (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))
@@ -1828,6 +1900,15 @@ The current window remains selected."
             (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."
@@ -1851,14 +1932,6 @@ The current window remains selected."
        (bookmark-edit-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 BACKUP means move up."
@@ -1866,13 +1939,14 @@ Optional BACKUP means move up."
   (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 ()
@@ -1882,7 +1956,8 @@ Optional BACKUP 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 ()
@@ -1891,10 +1966,11 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
   (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 ()
@@ -1904,7 +1980,8 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
   (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 ()
@@ -1969,176 +2046,38 @@ To carry out the deletions that you've marked, use \\<bookmark-bmenu-mode-map>\\
 \f
 ;;; Menu bar stuff.  Prefix is "bookmark-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-build-xemacs-menu (name entries function)
-  "Build a menu named NAME from the strings in ENTRIES.
-That is, ENTRIES is a list of strings that appear as the choices
-in the menu.
-The visible entries are truncated to `bookmark-menu-length', but the
-strings returned are not."
-  (let* (lst 
-        (pane-list
-         (progn
-           (while entries
-             (let ((str (car entries)))
-               (setq lst (cons
-                          (vector
-                           (if (> (length str) bookmark-menu-length)
-                               (substring str 0 bookmark-menu-length)
-                             str)
-                           (list function str)
-                           t)
-                          lst))
-               (setq entries (cdr entries))))
-           (nreverse lst))))
-
-    ;; Return the menu:
-    (append (if popup-menu-titles (list (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)))))
-
-
-;;;###autoload
-(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.
-
-Warning: this function only takes an EVENT as argument.  Use the
-corresponding bookmark function from Lisp \(the one without the
-\"-menu-\" in its name\)."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-insert "Insert Bookmark Contents" event))
-
-
-;;;###autoload
-(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.
-
-Warning: this function only takes an EVENT as argument.  Use the
-corresponding bookmark function from Lisp \(the one without the
-\"-menu-\" in its name\)."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-jump "Jump to Bookmark" event))
-
-
-;;;###autoload
-(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\).
-
-Warning: this function only takes an EVENT as argument.  Use the
-corresponding bookmark function from Lisp \(the one without the
-\"-menu-\" in its name\)."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-insert-location "Insert Bookmark Location" event))
-
-
-;;;###autoload
-(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
-consecutive words from the text of the buffer into the new bookmark
-name.
-
-Warning: this function only takes an EVENT as argument.  Use the
-corresponding bookmark function from Lisp \(the one without the
-\"-menu-\" in its name\)."
-  (interactive "e")
-  (bookmark-popup-menu-and-apply-function
-   'bookmark-rename "Rename Bookmark" event))
-
-
-;;;###autoload
-(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\).
-
-Warning: this function only takes an EVENT as argument.  Use the
-corresponding bookmark function from Lisp \(the one without the
-\"-menu-\" in its name\)."
-  (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
@@ -2150,67 +2089,55 @@ corresponding bookmark function from Lisp \(the one without the
 ;; Emacs menubar stuff.
 
 ;;;###autoload
-(defvar menu-bar-bookmark-map (make-sparse-keymap "Bookmark functions"))
+(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 (symbol-value 'menu-bar-bookmark-map))
+(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)))
 
-;;;###autoload
-(define-key menu-bar-bookmark-map [load]
-  '("Load a Bookmark File..." . bookmark-load))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [write]
-  '("Save Bookmarks As..." . bookmark-write))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [save]
-  '("Save Bookmarks" . bookmark-save))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [edit]
-  '("Edit Bookmark List" . bookmark-bmenu-list))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [delete]
-  '("Delete Bookmark" . bookmark-menu-delete))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [rename]
-  '("Rename Bookmark" . bookmark-menu-rename))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [locate]
-  '("Insert Location" . bookmark-menu-locate))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [insert]
-  '("Insert Contents" . bookmark-menu-insert))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [set]
-  '("Set Bookmark" . bookmark-set))
-
-;;;###autoload
-(define-key menu-bar-bookmark-map [jump] 
-  '("Jump to Bookmark" . bookmark-menu-jump))
-
 ;;;; end bookmark menu stuff ;;;;
 
 \f
 ;;; Load Hook
 (defvar bookmark-load-hook nil
-  "Hook to run at the end of loading bookmark.")
+  "Hook run at the end of loading bookmark.")
+
+;;; Exit Hook, called from kill-emacs-hook
+(defvar bookmark-exit-hook nil
+  "Hook run when emacs exits.")
+
+(defun bookmark-exit-hook-internal ()
+  "Save bookmark state, if necessary, at Emacs exit time.
+This also runs `bookmark-exit-hooks'."
+  (run-hooks 'bookmark-exit-hooks)
+  (and bookmark-alist
+       (bookmark-time-to-save-p t)
+       (bookmark-save)))
+
+(add-hook 'kill-emacs-hook 'bookmark-exit-hook-internal)
+
 
 (run-hooks 'bookmark-load-hook)
 
 (provide 'bookmark)
-      
+
+;;; arch-tag: 139f519a-dd0c-4b8d-8b5d-f9fcf53ca8f6
 ;;; bookmark.el ends here