]> code.delx.au - gnu-emacs/blobdiff - lisp/bookmark.el
Make sure shell-cd sets list-buffers-directory to a directory ending with `/'.
[gnu-emacs] / lisp / bookmark.el
index 620b4ab603280be6ca69ac860988736118876bcf..e8bbd30b9b0df8cec1fd094158e3e4f19f6e8fc7 100644 (file)
@@ -1,11 +1,11 @@
 ;;; bookmark.el --- set bookmarks, jump to them later.
 
-;; Copyright (C) 1993 Free Software Foundation
+;; Copyright (C) 1993, 1994 Free Software Foundation
 
 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu>
 ;; Maintainer: Karl Fogel <kfogel@cs.oberlin.edu>
 ;; Created: July, 1993
-;; Version: 2.4
+;; Version: 2.5
 ;; Keywords: bookmarks, placeholders
 
 ;; This file is part of GNU Emacs.
 
 ;; Thanks to David Bremner <bremner@cs.sfu.ca> for thinking of and
 ;; then implementing the bookmark-current-bookmark idea.  He even
-;; sent *patches*, bless his soul... 
+;; sent *patches*, bless his soul...
 
 ;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for
 ;; fixing and improving bookmark-time-to-save-p.
 
+;; Thanks go to Andrew V. Klein <avk@rtsg.mot.com> for the code that
+;; sorts the alist before presenting it to the user (in list-bookmarks
+;; and the menu-bar).
+
 ;; And much thanks to David Hughes <djh@harston.cv.com> for many small
 ;; suggestions and the code to implement them (like
 ;; Bookmark-menu-check-position, and some of the Lucid compatibility
 ;; stuff).
 
+;; Kudos (whatever they are) go to Jim Blandy <jimb@cs.oberlin.edu>
+;; for his eminently sensible suggestion to separate bookmark-jump
+;; into bookmark-jump and bookmark-jump-noselect, which made many
+;; other things cleaner as well.
+
 ;; 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
+;; values in bookmark-jump and bookmark-set.  Everybody please keep
+;; all the keystrokes they save thereby and send them to him at the
+;; end of each year :-)  (No, seriously, thanks Jonathan!)
+
 ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
 ;; <olstad@msc.edu>.
 
 ;; LCD Archive Entry:
 ;; bookmark|Karl Fogel|kfogel@cs.oberlin.edu|
 ;; Setting bookmarks in files or directories, jumping to them later.|
-;; 16-July-93|Version: 2.4|~/misc/bookmark.el.Z|
+;; 16-July-93|Version: 2.5|~/misc/bookmark.el.Z|
 
 ;; Enough with the credits already, get on to the good stuff:
 
@@ -53,7 +67,7 @@
 ;; Boy, that's a tough one.  Probably Hong Min, or maybe Emperor's
 ;; Choice (both in Chicago's Chinatown).  Well, both.  How about you?
 
-;;; Commentary on code:
+;;; Commentary:
 
 ;; bookmark alist format:
 ;;               (...
 ;; 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"))
+(if (or (symbolp (key-binding "\C-xr"))
+       (fboundp 'bookmark-set))
     nil
   (progn (define-key ctl-x-map "rb" 'bookmark-jump)
          (define-key ctl-x-map "rm" 'bookmark-set)
@@ -146,7 +161,6 @@ instead, let the various bookmark functions do it for you.")
 
 ;; 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)
@@ -165,7 +179,7 @@ through a file easier.")
 
 (defvar 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.
 --> Otherise, it should be a number that is the frequency with which
@@ -184,22 +198,25 @@ bookmark-file, which is `~/.emacs-bkmrks' by default.")
 (defvar bookmark-alist-modification-count 0
   "Number of modifications to bookmark list since it was last saved.")
 
-(defvar bookmark-file "~/.emacs-bkmrks" 
+(defvar bookmark-file
+  (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
+      "~/emacs.bmk" ; Cannot have initial dot [Yuck!]
+    "~/.emacs-bkmrks") 
   "*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.")
+  "Control whether to make numbered backups of the master bookmark file.
+This variable can have four values: t, nil, `never', and `nospecial'.
+The first three have the same meaning that they do for the
+variable `version-control'.
+The 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
+  "*Non-nil means display bookmarks sorted by name.
+Otherwise they are  displayed in LIFO order (that is, most
 recently set ones come first, oldest ones come last).")
 
 (defvar bookmark-search-size 500 
@@ -211,7 +228,7 @@ recently set ones come first, oldest ones come last).")
 
 ;;;###autoload
 (defun bookmark-set (&optional parg)
-  "Set a bookmark named NAME inside a file.  
+  "Set a bookmark named NAME inside the visited file.  
 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
@@ -223,7 +240,7 @@ To yank words from the text of the buffer and use them as part of the
 bookmark name, type C-w while setting a bookmark.  Successive C-w's
 yank successive words.
 
-Typing C-v inserts the name of the current file being visited. Typing
+Typing C-v inserts the name of the current file being visited.  Typing
 C-u inserts the name of the last bookmark used in the buffer \(as an
 aid in using a single bookmark name to track your progress through a
 large file\).  If no bookmark was used, then C-u behaves like C-v and
@@ -374,10 +391,9 @@ You may have a problem using this function if the value of variable
 bookmarks.  See help on function `bookmark-load' for more about
 this.
 
-If the file pointed to by BOOKMARK no longer exists, you will be asked
-if you wish to give the bookmark a new location, and bookmark-jump
-will then jump to the new location, as well as recording it in place
-of the old one in the permanent bookmark record."
+If the file pointed to by BOOKMARK no longer exists, `bookmark-jump'
+asks you to specify a different file to use instead.  If you specify
+one, it also updates BOOKMARK to refer to that file."
   (interactive (progn (bookmark-try-default-file)
                       (let* ((completion-ignore-case
                               bookmark-completion-ignore-case)
@@ -462,11 +478,11 @@ of the old one in the permanent bookmark record."
             nil))))))
 
 ;;;###autoload
-(defun bookmark-relocate (str)
-  "Relocate BOOKMARK -- prompts for a filename, and makes an already
-existing bookmark point to that file, instead of the one it used to
-point at.  Useful when a file has been renamed after a bookmark was
-set in it."
+(defun bookmark-relocate (bookmark)
+  "Relocate bookmark BOOKMARK.
+Prompt for a filename, and makes the bookmark 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 (let ((completion-ignore-case
                       bookmark-completion-ignore-case))
                  (progn (bookmark-try-default-file)
@@ -475,11 +491,11 @@ set in it."
                                bookmark-alist
                                nil
                                0)))))
-  (let* ((bmrk (assoc str bookmark-alist))
+  (let* ((bmrk (assoc bookmark bookmark-alist))
          (bmrk-filename (car (car (cdr bmrk))))
          (newloc (expand-file-name
                  (read-file-name
-                  (format "Relocate %s to: " str)
+                  (format "Relocate %s to: " bookmark)
                   (file-name-directory bmrk-filename)))))
     (setcar (car (cdr bmrk)) newloc)))
 
@@ -618,9 +634,8 @@ one most recently used in this file, if any\)."
 
 ;;;###autoload
 (defun bookmark-write ()
-  "Write bookmarks to a file \(for which the user will be prompted
-interactively\).  Don't use this in Lisp programs; use bookmark-save
-instead."
+  "Write bookmarks to a specified file.
+Don't use this in Lisp programs; use `bookmark-save' instead."
   (interactive)
   (bookmark-try-default-file)
   (bookmark-save t))
@@ -666,7 +681,8 @@ for a file, defaulting to the file defined by variable
     (save-window-excursion
       (if (>= baud-rate 9600)
           (message (format "Saving bookmarks to file %s." file)))
-      (set-buffer (find-file-noselect file))
+      (set-buffer (let ((enable-local-variables nil))
+                    (find-file-noselect file)))
       (goto-char (point-min))
       (delete-region (point-min) (point-max))
       (print bookmark-alist (current-buffer))
@@ -709,7 +725,8 @@ explicitly."
         (save-window-excursion
           (if (and (null no-msg) (>= baud-rate 9600))
               (message (format "Loading bookmarks from %s..." file)))
-          (set-buffer (find-file-noselect file))
+          (set-buffer (let ((enable-local-variables nil))
+                        (find-file-noselect file)))
           (goto-char (point-min))
           (let ((blist (car (read-from-string
                              (buffer-substring (point-min) (point-max))))))
@@ -795,8 +812,8 @@ following in your .emacs:
 (defun list-bookmarks ()
   "Display a list of existing bookmarks.
 The list is displayed in a buffer named `*Bookmark List*'.
-The leftmost column displays a D if the bookmark is flagged for
-deletion, or > if it is flagged for displaying."
+The leftmost column displays a `D' if the bookmark is flagged for
+deletion, or `>' if it is flagged for displaying."
   (interactive)
   (bookmark-try-default-file)
   (switch-to-buffer (get-buffer-create "*Bookmark List*"))
@@ -823,7 +840,7 @@ Letters do not insert themselves; instead, they are commands.
 \\<Bookmark-menu-mode-map>
 \\[Bookmark-menu-mark] -- mark bookmark to be displayed.
 \\[Bookmark-menu-select] -- select bookmark of line point is on.
-  Also show bookmarks marked using m in other windows.
+  Also show bookmarks marked using `m' in other windows.
 \\[Bookmark-menu-toggle-filenames] -- toggle displaying of filenames (they may obscure long bookmark names).
 \\[Bookmark-menu-locate] -- display (in minibuffer) location of this bookmark.
 \\[Bookmark-menu-1-window] -- select this bookmark in full-frame window.
@@ -1094,8 +1111,8 @@ Optional ARG means move up."
         (forward-line 1))))
 
 (defun Bookmark-menu-delete-backwards ()
-  "Mark bookmark on this line to be deleted by \\<Bookmark-menu-mode-map>\\[Bookmark-menu-execute] command
-and then move up one line"
+  "Mark bookmark on this line to be deleted by \\<Bookmark-menu-mode-map>\\[Bookmark-menu-execute] command.
+Then move up one line"
   (interactive)
   (Bookmark-menu-delete)
   (forward-line -2)
@@ -1171,6 +1188,7 @@ and then move up one line"
                                   (cons menu-str menu)))))
     (if str (apply func-sym (list str)))))
 
+;;;###autoload
 (defun bookmark-menu-bar-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
@@ -1183,6 +1201,7 @@ this."
                                         "--- Insert Contents ---"
                                         event))
 
+;;;###autoload
 (defun bookmark-menu-bar-jump (event)
   "Jump to bookmark BOOKMARK (a point in some file).  
 You may have a problem using this function if the value of variable
@@ -1195,8 +1214,9 @@ this."
                                         "--- Jump to Bookmark ---"
                                         event))
 
+;;;###autoload
 (defun bookmark-menu-bar-locate (event)
-  "Insert the name of the  file associated with BOOKMARK. 
+  "Insert the name of the file associated with BOOKMARK. 
 \(This is not the same as the contents of that file\)."
   (interactive "e")
   (bookmark-make-menu-bar-with-function 'bookmark-locate
@@ -1204,6 +1224,7 @@ this."
                                         "--- Insert Location ---"
                                         event))
 
+;;;###autoload
 (defun bookmark-menu-bar-rename (event)
   "Change the name of OLD-BOOKMARK to NEWNAME.  
 If called from keyboard, prompts for OLD-BOOKMARK and NEWNAME.
@@ -1222,6 +1243,7 @@ name, and C-v inserts the name of the file."
                                         "--- Rename Bookmark ---"
                                         event))
 
+;;;###autoload
 (defun bookmark-menu-bar-delete (event)
   "Delete the bookmark named NAME from the bookmark list.  
 Removes only the first instance of a bookmark with that name.  If
@@ -1237,50 +1259,51 @@ 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.
 
-;;;###autoload 
-(define-key global-map [menu-bar bookmark]
-  '("Bookmarks" . menu-bar-bookmark-map))
-
+;;;###autoload
 (defvar menu-bar-bookmark-map (make-sparse-keymap "Bookmark functions."))
 
-;; make bookmarks appear toward the right side of the menu.
-(if (boundp '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
+(fset 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [load]
   '("Load a bookmark file" . bookmark-load))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [write]
   '("Write \(to another file\)" . bookmark-write))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [save]
   '("Save  \(in default file\)" . bookmark-save))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [edit]
   '("Edit Bookmark List" . list-bookmarks))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [delete]
   '("Delete bookmark" . bookmark-menu-bar-delete))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [rename]
   '("Rename bookmark" . bookmark-menu-bar-rename))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [locate]
   '("Insert location" . bookmark-menu-bar-locate))
 
+;;;###autoload
 (define-key menu-bar-bookmark-map [insert]
   '("Insert contents" . bookmark-menu-bar-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-bar-jump))
-;;;###autoload (autoload 'menu-bar-bookmark-map "bookmark" nil t 'keymap)
 
 (fset 'menu-bar-bookmark-map (symbol-value 'menu-bar-bookmark-map))
 
@@ -1289,4 +1312,3 @@ one most recently used in this file, if any\)."
 (provide 'bookmark)
       
 ;;; bookmark.el ends here
-