(read_minibuf): New arg disable_multibyte.
[bpt/emacs.git] / lisp / bookmark.el
index 5d4b86c..b41d9fc 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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 Free Software Foundation
 
 ;; Author: Karl Fogel <kfogel@red-bean.com>
 ;; Maintainer: Karl Fogel <kfogel@red-bean.com>
@@ -99,14 +99,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)
 
 
-(defvar bookmark-save-flag t
+(defcustom bookmark-use-annotations nil
+  "*If non-nil, saving a bookmark queries for an annotation in a buffer."
+  :type 'boolean
+  :group 'bookmark)
+
+
+(defcustom bookmark-save-flag t
   "*Controls when Emacs saves bookmarks to a file.
---> Nil means never save bookmarks, except when `bookmark-save' is
+--> 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,62 +126,80 @@ 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) (const t) integer)
+  :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
     (convert-standard-filename "~/.emacs.bmk"))
-  "*File in which to save bookmarks by default.")
+  "*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 t) (const nil) (const never) (const nospecial))
+  :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 'boolean)
 
 
 ;;; No user-serviceable parts beyond this point.
@@ -206,19 +230,13 @@ following in your .emacs:
 
 \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
@@ -1160,7 +1178,15 @@ 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 bookmark))
-  (insert (bookmark-location bookmark)))
+  (let ((start (point)))
+    (prog1
+       (insert (bookmark-location bookmark)) ; *Return this line*
+      (if window-system
+         (put-text-property start 
+                            (save-excursion (re-search-backward
+                                             "[^ \t]")
+                                            (1+ (point)))
+                            'mouse-face 'highlight)))))
 
 ;;;###autoload
 (defalias 'bookmark-locate 'bookmark-insert-location)
@@ -1444,7 +1470,9 @@ explicitly."
   (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))
 
   
 
@@ -1495,7 +1523,16 @@ deletion, or > if it is flagged for displaying."
                   (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 window-system
+              (put-text-property start 
+                                 (save-excursion (re-search-backward
+                                                  "[^ \t]")
+                                                 (1+ (point)))
+                                 'mouse-face 'highlight))
+          (insert "\n")
+          )))
      bookmark-alist))
   (goto-char (point-min))
   (forward-line 2)
@@ -1581,8 +1618,13 @@ Optional argument SHOW means show them unconditionally."
             (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 window-system
+                   (remove-text-properties start (point)
+                                           '(mouse-face))))
+             (delete-region (point) (progn (end-of-line) (point)))
               (insert "  ")
               ;; Pass the NO-HISTORY arg:
               (bookmark-insert-location bmrk t)
@@ -1608,7 +1650,14 @@ Optional argument SHOW means show them unconditionally."
               (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 window-system
+                     (put-text-property start 
+                                        (save-excursion (re-search-backward
+                                                         "[^ \t]")
+                                                        (1+ (point)))
+                                        'mouse-face 'highlight)))
                 (setq bookmark-bmenu-hidden-bookmarks
                       (cdr bookmark-bmenu-hidden-bookmarks))
                 (forward-line 1))))))))
@@ -1648,7 +1697,7 @@ Optional argument SHOW means show them unconditionally."
       (beginning-of-line)
       (forward-char bookmark-bmenu-bookmark-column)
       (prog1
-          (buffer-substring (point)
+          (buffer-substring-no-properties (point) 
                             (progn 
                               (end-of-line)
                               (point)))
@@ -1826,6 +1875,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."