(occur): If no matches, just display in echo area.
[bpt/emacs.git] / lisp / bookmark.el
index 645a556..bdb9ef4 100644 (file)
@@ -1,19 +1,13 @@
 ;;; 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 Free Software Foundation
 
-;; 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
-;; Author's Update Number: 2.6.10
+;; Author's Update Number: see variable `bookmark-version'.
 ;; 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., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, 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>.
 
+;; 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: 
 ;; 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:
+
 (require 'pp)
 
-\f
-;;;; Code:
+(defconst bookmark-version "2.6.20"
+  "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:
 ;;
 ;; the list will be presented in the order it is recorded
 ;; (chronologically), which is actually fairly useful as well.
 
-;;; Code:
+;;; User Variables
+
+(defvar bookmark-use-annotations nil
+  "*If non-nil, saving a bookmark will query for an annotation in a
+buffer.")
+
+
+(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.
+--> 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.")
+
+
+(defconst bookmark-old-default-file "~/.emacs-bkmrks"
+  "*The .emacs.bmk file used to be called this.")
+
+
+;; defvarred to avoid a compilation warning:
+(defvar bookmark-file nil
+  "Old name for `bookmark-default-file'.")
+
+(defvar 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.")
+
+
+(defvar 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'.")
+
+
+(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-automatically-show-annotations t
+  "*Nil means don't show annotations when jumping to a bookmark.")
+
+
+(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-menu-length 70
+  "*Maximum length of a bookmark name displayed on a popup menu.")
+
+
+;;; 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))
 
+;; This variable is probably obsolete now...
+(or (boundp 'baud-rate)
+    ;; 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:
@@ -120,10 +230,6 @@ 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)
 
@@ -167,7 +273,24 @@ 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
+
+       \(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)
@@ -193,69 +316,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.")
-
-
-;; defvarred to avoid a compilation warning:
-(defvar bookmark-file nil
-  "Old name for `bookmark-default-file'.")
-
-(defvar 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.")
-
-
-(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-automatically-show-annotations t
-  "*Nil means don't show annotations when jumping to a bookmark.")
-
-
 (defvar bookmark-search-size 16
   "Length of the context strings recorded on either side of a bookmark.")
 
@@ -273,7 +337,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))
 
 
@@ -308,7 +372,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)
@@ -375,6 +439,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))))
   
 
@@ -425,61 +490,57 @@ menus, so `completing-read' never gets a chance to set `bookmark-history'."
       (setq bookmark-history (cons (, string) bookmark-history)))))
 
 
-(defun bookmark-make (str &optional annotation overwrite)
+(defun bookmark-make (name &optional annotation overwrite)
   "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."
   (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...)
+  (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)))
+      
+      ;; 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))
+             bookmark-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)))
+    ;; 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)
-  "Return the record part of a bookmark.
+  "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."
+being set.  This will change soon."
   (` ((filename . (, (bookmark-buffer-file-name)))
       (front-context-string
        . (, (if (>= (- (point-max) (point)) bookmark-search-size)
-                ;; strip text props via `format':
-               (let ((string
-                        (buffer-substring 
-                         (point)
-                         (+ (point) bookmark-search-size))))
-                  (set-text-properties 0 (length string) nil string)
-                  string)
+                (buffer-substring-no-properties
+                 (point)
+                 (+ (point) bookmark-search-size))
               nil)))
       (rear-context-string
        . (, (if (>= (- (point) (point-min)) bookmark-search-size)
-                ;; strip text props via `format':
-               (let ((string
-                        (buffer-substring 
-                         (point)
-                         (- (point) bookmark-search-size))))
-                  (set-text-properties 0 (length string) nil string)
-                  string)
+                (buffer-substring-no-properties
+                 (point)
+                 (- (point) bookmark-search-size))
               nil)))
       (position . (, (point)))
       (annotation . (, annotation)))))
@@ -561,11 +622,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))
@@ -597,7 +658,7 @@ 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)
   )
 
@@ -627,7 +688,7 @@ 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 ()
@@ -647,8 +708,9 @@ This expects to be called from point-min in a bookmark file."
 ;;; 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
@@ -668,10 +730,10 @@ 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)
 
@@ -682,15 +744,16 @@ 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-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)))
+                 (progn (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 
@@ -730,7 +793,7 @@ as the annotation for a bookmark, and store it 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 "^#")
@@ -767,12 +830,13 @@ 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,
+into an annotation composition buffer.  It takes the name of the bookmark,
 as a string, as an arg.")
 
 
 (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.
 
@@ -838,7 +902,7 @@ When you have finished composing, type \\[bookmark-send-annotation].
 as the new annotation for a bookmark."
   (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 "^#")
@@ -861,8 +925,8 @@ as the new annotation for a 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
@@ -872,8 +936,8 @@ as the new annotation for a bookmark."
 
 
 (defun bookmark-insert-buffer-name ()
-  ;; insert the name (sans path) of the current file into the bookmark
-  ;; name that is being set.
+  "Insert the name (sans path) of the current file into the bookmark
+name that is being set."
   (interactive)
   (let ((str
          (save-excursion
@@ -913,7 +977,7 @@ In Info, return the current node."
   (let ((string (save-excursion
                     (set-buffer bookmark-current-buffer)
                     (goto-char bookmark-yank-point)
-                    (buffer-substring
+                    (buffer-substring-no-properties
                      (point)
                      (save-excursion
                        (forward-word 1)
@@ -966,7 +1030,7 @@ For example, if this is a Info buffer, return the Info file's name."
 
 
 ;;;###autoload
-(defun bookmark-jump (str)
+(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
@@ -979,15 +1043,15 @@ 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))
-  (bookmark-maybe-historicize-string str)
-  (let ((cell (bookmark-jump-noselect str)))
+  (bookmark-maybe-historicize-string bookmark)
+  (let ((cell (bookmark-jump-noselect bookmark)))
     (and cell
          (switch-to-buffer (car cell))
          (goto-char (cdr cell))
         (if bookmark-automatically-show-annotations
              ;; if there is an annotation for this bookmark,
              ;; show it in a buffer.
-             (bookmark-show-annotation str)))))
+             (bookmark-show-annotation bookmark)))))
 
 
 (defun bookmark-jump-noselect (str)
@@ -1058,50 +1122,50 @@ of the old one in the permanent bookmark record."
 
 
 ;;;###autoload
-(defun bookmark-relocate (str)
+(defun bookmark-relocate (bookmark)
   "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"))
-  (bookmark-maybe-historicize-string str)
+  (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)))
 
 
 ;;;###autoload
-(defun bookmark-insert-location (str &optional no-history)
+(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 (bookmark-completing-read "Insert bookmark location"))
-  (or no-history (bookmark-maybe-historicize-string str))
-  (insert (bookmark-location str)))
+  (or no-history (bookmark-maybe-historicize-string bookmark))
+  (insert (bookmark-location bookmark)))
 
 
-(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, prompts for OLD and NEW.  If called from menubar, OLD is
+selected from a menu, and prompts for NEW.
+
+If called from Lisp, prompts 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
+consecutive words from the text of the buffer into the new bookmark
 name."
   (interactive (bookmark-completing-read "Old bookmark name"))
   (bookmark-maybe-historicize-string old)
@@ -1131,19 +1195,19 @@ name."
 
 
 ;;;###autoload
-(defun bookmark-insert (str)
+(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"))
-  (bookmark-maybe-historicize-string str)
+  (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)))
+           (set-buffer (car (bookmark-jump-noselect bookmark)))
            (buffer-substring (point-min) (point-max)))))
     (insert str-to-insert)
     (push-mark)
@@ -1166,7 +1230,7 @@ probably because we were called from there."
   (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
@@ -1209,7 +1273,8 @@ instead."
 (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
@@ -1247,7 +1312,7 @@ for a file, defaulting to the file defined by variable
   (save-excursion
     (save-window-excursion
       (if (>= baud-rate 9600)
-          (message (format "Saving bookmarks to file %s..." file)))
+          (message "Saving bookmarks to file %s..." file))
       (set-buffer (let ((enable-local-variables nil))
                     (find-file-noselect file)))
       (goto-char (point-min))
@@ -1264,7 +1329,7 @@ for a file, defaulting to the file defined by variable
         (write-file file)
         (kill-buffer (current-buffer))
         (if (>= baud-rate 9600)
-            (message (format "Saving bookmarks to file %s... done." file)))
+            (message "Saving bookmarks to file %s...done" file))
         ))))
 
 
@@ -1295,7 +1360,7 @@ explicitly."
       (save-excursion
         (save-window-excursion
           (if (and (null no-msg) (>= baud-rate 9600))
-              (message (format "Loading bookmarks from %s..." file)))
+              (message "Loading bookmarks from %s..." file))
           (set-buffer (let ((enable-local-variables nil))
                         (find-file-noselect file)))
           (goto-char (point-min))
@@ -1310,11 +1375,11 @@ explicitly."
                   (setq bookmark-alist
                         (append blist (if (not revert) bookmark-alist)))
                   (bookmark-bmenu-surreptitiously-rebuild-list)) 
-              (error (format "Invalid bookmark list in %s." file))))
+              (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))))
+            (message "Loading bookmarks from %s...done" file)))
+    (error "Cannot read bookmark file %s" file)))
 
 
 \f
@@ -1328,19 +1393,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)
 
 
@@ -1361,7 +1413,6 @@ following in your .emacs:
   (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)
@@ -1418,7 +1469,7 @@ deletion, or > if it is flagged for displaying."
     (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))))
@@ -1445,7 +1496,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.
@@ -1462,7 +1513,7 @@ Bookmark names preceeded by a \"*\" have annotations.
 \\[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-execute-deletions] -- delete marked bookmarks.
+\\[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.)
@@ -1482,12 +1533,12 @@ Bookmark names preceeded by a \"*\" have annotations.
   (run-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))
@@ -1656,20 +1707,19 @@ You can mark bookmarks with the \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-mar
             (delete-char -1)
             (insert ?\ ))
           (or (string-equal tem bmrk) 
-              (memq tem others) 
+              (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)))))
 
 
@@ -1791,7 +1841,7 @@ The current window remains selected."
 
 (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)
@@ -1839,6 +1889,7 @@ and then move up one line"
 (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
@@ -1870,7 +1921,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 ()
@@ -1895,10 +1948,6 @@ and then move up one line"
 \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
@@ -1937,6 +1986,33 @@ strings returned are not."
     (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
@@ -1961,36 +2037,52 @@ The number of panes depends on the number of bookmarks."
     (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."
+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."
+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\)."
+\(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.
@@ -2001,19 +2093,28 @@ 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."
+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\)."
+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))
@@ -2022,8 +2123,18 @@ one most recently used in this file, if any\)."
 ;; 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.
 
+;; FSF Emacs menubar stuff
+;; The odd conditional structure is due to the limitations of autoload
+;; cookies.
+
+;;;###autoload
+(defvar menu-bar-bookmark-map (make-sparse-keymap "Bookmark functions"))
+
+;;;###autoload
+(defalias 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
 
 ;; make bookmarks appear toward the right side of the menu.
 (if (boundp 'menu-bar-final-items)
@@ -2032,39 +2143,45 @@ one most recently used in this file, if any\)."
               (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))
+  '("Load a Bookmark File..." . bookmark-load))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [write]
-  '("Write \(to another file\)" . bookmark-write))
+  '("Save Bookmarks As..." . bookmark-write))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [save]
-  '("Save  \(in default file\)" . bookmark-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))
+  '("Delete Bookmark" . bookmark-menu-delete))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [rename]
-  '("Rename bookmark" . bookmark-menu-rename))
+  '("Rename Bookmark" . bookmark-menu-rename))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [locate]
-  '("Insert location" . bookmark-menu-locate))
+  '("Insert Location" . bookmark-menu-locate))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [insert]
-  '("Insert contents" . bookmark-menu-insert))
+  '("Insert Contents" . bookmark-menu-insert))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [set]
-  '("Set bookmark" . bookmark-set))
+  '("Set Bookmark" . bookmark-set))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [jump] 
-  '("Jump to bookmark" . bookmark-menu-jump))
-;;;###autoload (autoload 'menu-bar-bookmark-map "bookmark" nil t 'keymap)
-
-(fset 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
+  '("Jump to Bookmark" . bookmark-menu-jump))
 
 ;;;; end bookmark menu stuff ;;;;