annotate lisp/bookmark.el @ 4631:fc781d29fd48

New version from Fogel.
author Richard M. Stallman <rms@gnu.org>
date Sat, 14 Aug 1993 11:04:06 +0000
parents 2507541ef88d
children 738840d8e627
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; bookmark.el --- set bookmarks, jump to them later.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Karl Fogel <kfogel@cs.oberlin.edu>
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
6 ;; Maintainer: Karl Fogel <kfogel@cs.oberlin.edu>
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: July, 1993
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
8 ;; Version: 1.7.3 (interim)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Keywords: bookmarks, placeholders
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Thanks to David Bremner <bremner@cs.sfu.ca> for thinking of and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; then implementing the bookmark-current-bookmark idea. He even
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; sent *patches*, bless his soul...
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; Thanks to Gregory M. Saunders <saunders@cis.ohio-state.edu> for
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; fixing and improving bookmark-time-to-save-p.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Based on info-bookmark.el, by Karl Fogel and Ken Olstad
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; <olstad@msc.edu>.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; LCD Archive Entry:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; bookmark|Karl Fogel|kfogel@cs.oberlin.edu|
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; Setting bookmarks in files or directories, jumping to them later.|
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; 16-July-93|Version: 1.7.2|~/misc/bookmark.el.Z|
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; FAVORITE CHINESE RESTAURANT:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; Boy, that's a tough one. Probably Hong Min, or maybe Emperor's
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; Choice (both in Chicago's Chinatown). Well, both. How about you?
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; Commentary on code:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; bookmark alist format:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; (...
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; (bookmark-name (filename
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; string-in-front
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; string-behind
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; ...)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; bookmark-name is the string the user gives the bookmark and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; accesses it by from then on. filename is the location of the file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; in which the bookmark is set. string-in-front is a string of
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; `bookmark-search-size' chars of context in front of the point the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; bookmark is set at, string-behind is the same thing after the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; point. bookmark-jump will search for string-behind and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; string-in-front in case the file has changed since the bookmark was
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; set. It will attempt to place the user before the changes, if
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; there were any.
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
65 ;;
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
66 ;; It is not advisable to sort the bookmark list when it is presented
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
67 ;; to the user, because it is already sorted in what is probably the
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
68 ;; most useful way: order of creation, with most recently created
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
69 ;; bookmarks coming first and older ones toward the end (renaming does
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
70 ;; not count as creating) -- which is what we want, most of the time.
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; Code:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; Added for lucid emacs compatibility, db
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (or (fboundp 'defalias) (fset 'defalias 'fset))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; these are the distribution keybindings suggested by RMS, everything
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; else will be done with M-x or the menubar:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (define-key ctl-x-map "rb" 'bookmark-jump)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (define-key ctl-x-map "rm" 'bookmark-set)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (define-key ctl-x-map "rl" 'bookmark-locate)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; define the map, so it can be bound by those who desire to do so:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defvar bookmark-map nil "This is a keymap containing bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 functions. It is not bound to any key by default: to bind it so
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 that you have a bookmark prefix, just use global-set-key and bind a
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
88 key of your choice to \`bookmark-map\'. All interactive bookmark
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 functions have a binding in this keymap.")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (define-prefix-command 'bookmark-map)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; Read the help on all of these functions for details...
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; "x" marks the spot!
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (define-key bookmark-map "x" 'bookmark-set)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (define-key bookmark-map "j" 'bookmark-jump)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (define-key bookmark-map "i" 'bookmark-insert)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (define-key bookmark-map "f" 'bookmark-locate) ; "f" for "find"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (define-key bookmark-map "n" 'bookmark-rename) ; "n" for "new name"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; deletes bookmarks
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (define-key bookmark-map "d" 'bookmark-delete)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; loads new file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (define-key bookmark-map "l" 'bookmark-load)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; saves them in file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (define-key bookmark-map "w" 'bookmark-write)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (define-key bookmark-map "s" 'bookmark-save)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 ;; just add the hook to make sure that people don't lose bookmarks
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; when they kill Emacs, unless they don't want to save them.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (add-hook 'kill-emacs-hook
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (function
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (lambda ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (and (featurep 'bookmark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (bookmark-time-to-save-p t)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (bookmark-save)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 ;; more stuff added by db.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (defvar bookmark-current-bookmark nil
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
121 "This variable stores the bookmark most recently set, jumped to, or
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
122 renamed. It is buffer local, used to make moving a bookmark forward
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
123 through a file easier.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (make-variable-buffer-local 'bookmark-current-bookmark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defvar bookmark-save-flag t
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
128 "*This variable determines when Emacs\' internal bookmark list will
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
129 be saved to a file:
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
130
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
131 Nil means never save bookmarks, except when \`bookmark-save\' is
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 explicitly called \(\\[bookmark-save]\).
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 t means save bookmarks when Emacs is killed.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 Otherise, it should be a number that is the frequency with which the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 bookmark list is saved \(i.e.: the number of times which Emacs\'
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 bookmark list may be modified before it is automatically saved.\). If
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 it is a number, Emacs will also automatically save bookmarks when it
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 is killed.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 Therefore, the way to get it to save every time you make or delete a
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 bookmark is to set this variable to 1 \(or 0, which produces the same
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 behavior.\)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 To specify the file in which to save them, modify the variable
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
147 bookmark-file, which is \`~/.emacs-bkmrks\' by default.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (defvar bookmark-alist-modification-count 0
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 "Number of times the bookmark list has been modified since last
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 saved.")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (defvar bookmark-file "~/.emacs-bkmrks"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 "*File in which to save bookmarks by default.")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defvar bookmark-completion-ignore-case t
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
157 "*Non-nil means those bookmark functions which use completion will
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
158 be case-insensitive in completion.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
160 (defvar bookmark-search-size 500 "Length, in characters, of the
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
161 context strings recorded on either side of a bookmark.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (defvar bookmark-alist ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 "Association list of bookmarks.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 You probably don't want to change the value of this alist yourself;
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 instead, let the various bookmark functions do it for you.")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (defvar bookmark-current-point 0)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (defvar bookmark-yank-point 0)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defvar bookmark-current-buffer nil)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defun bookmark-set (&optional parg)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 "Set a bookmark named NAME inside a file. With prefix arg, will not
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 overwrite a bookmark that has the same name as NAME if such a bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 already exists, but instead will \"push\" the new bookmark onto the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 bookmark alist. Thus the most recently set bookmark with name NAME would
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 be the one in effect at any given time, but the others are still there,
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 should you decide to delete the most recent one.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 To yank words from the text of the buffer and use them as part of the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 bookmark name, type C-w while setting a bookmark. Successive C-w\'s
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 yank successive words.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 Typing C-v inserts the name of the current file being visited. Typing
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 C-u inserts the name of the last bookmark used in the buffer \(as an
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 aid in using a single bookmark name to track your progress through a
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 large file\). If no bookmark was used, then C-u behaves like C-v and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 inserts the name of the file being visited.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 Use \\[bookmark-delete] to remove bookmarks \(you give it a name,
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 and it removes only the first instance of a bookmark with that name from
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 the list of bookmarks.\)"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (interactive "P")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (if (not (bookmark-buffer-file-name))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (error "Buffer not visiting a file or directory."))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (setq bookmark-current-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (setq bookmark-yank-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (setq bookmark-current-buffer (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (let ((str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (read-from-minibuffer
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 "Set bookmark: "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 nil
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (let ((now-map (copy-keymap minibuffer-local-map)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (progn (define-key now-map "\C-w"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 'bookmark-yank-word)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (define-key now-map "\C-v"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 'bookmark-insert-current-file-name)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (define-key now-map "\C-u"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 'bookmark-insert-current-bookmark))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 now-map))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (bookmark-make parg str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (setq bookmark-current-bookmark str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (goto-char bookmark-current-point))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defun bookmark-insert-current-bookmark ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; insert this buffer's value of bookmark-current-bookmark, default
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; to file name if it's nil.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (let ((str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (set-buffer bookmark-current-buffer)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 bookmark-current-bookmark)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (if str (insert str) (bookmark-insert-current-file-name))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (defun bookmark-insert-current-file-name ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;; insert the name (sans path) of the current file into the bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ;; name that is being set.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (let ((str (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (set-buffer bookmark-current-buffer)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (bookmark-buffer-file-name))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (insert (substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (1+ (string-match
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 "\\(/[^/]*\\)/*$"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 str))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (defun bookmark-yank-word ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;; get the next word from the buffer and append it to the name of
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;; the bookmark currently being set.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (let ((string (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (set-buffer bookmark-current-buffer)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (goto-char bookmark-yank-point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (buffer-substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (forward-word 1)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (setq bookmark-yank-point (point)))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (insert string)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (defun bookmark-make (parg str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (if (and (assoc str bookmark-alist) (not parg))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ;; already existing boookmark under that name and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; no prefix arg means just overwrite old bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (setcdr (assoc str bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (list (bookmark-make-cell)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ;; otherwise just cons it onto the front (either the bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;; doesn't exist already, or there is no prefix arg. In either
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 ;; case, we want the new bookmark consed onto the alist...)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (setq bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (cons
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (list str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (bookmark-make-cell))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 bookmark-alist)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 ;; Added by db
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (setq bookmark-current-bookmark str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (setq bookmark-alist-modification-count
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (1+ bookmark-alist-modification-count))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (if (bookmark-time-to-save-p)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (bookmark-save)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (defun bookmark-make-cell ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ;; make the cell that is the cdr of a bookmark alist element. It
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;; looks like this:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 ;; (filename search-forward-str search-back-str point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (list
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (bookmark-buffer-file-name)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (if (>= (- (point-max) (point)) bookmark-search-size)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (buffer-substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (+ (point) bookmark-search-size))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 nil)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (if (>= (- (point) (point-min)) bookmark-search-size)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (buffer-substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (- (point) bookmark-search-size))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 nil)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (point)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (defun bookmark-buffer-file-name ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (or
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 buffer-file-name
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (if (and (boundp 'dired-directory) dired-directory)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (if (stringp dired-directory)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 dired-directory
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (car dired-directory)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (defun bookmark-try-default-file ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (if (and (null bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (file-readable-p (expand-file-name bookmark-file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (bookmark-load bookmark-file)))
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
306
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (defun bookmark-jump (str)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
308 "Jump to bookmark BOOKMARK (a point in some file). You may have a
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
309 problem using this function if the value of variable
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
310 \`bookmark-alist\' is nil. If that happens, you need to load in some
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
311 bookmarks. See help on function \`bookmark-load\' for more about
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
312 this."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
313 (interactive (let ((completion-ignore-case
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 bookmark-completion-ignore-case))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (list (completing-read
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 "Jump to bookmark: "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 nil
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
319 0))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
320 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
321 (let ((file (car whereto-list))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
322 (forward-str (car (cdr whereto-list)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
323 (behind-str (car (cdr (cdr whereto-list))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
324 (place (car (cdr (cdr (cdr whereto-list))))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
325 (if (file-exists-p (expand-file-name file))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
326 (progn
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
327 (find-file (expand-file-name file))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
328 (goto-char place)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
329 ;; Go searching forward first. Then, if forward-str exists and
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
330 ;; was found in the file, we can search backward for behind-str.
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
331 ;; Rationale is that if text was inserted between the two in the
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
332 ;; file, it's better to be put before it so you can read it,
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
333 ;; rather than after and remain perhaps unaware of the changes.
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
334 (if forward-str
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
335 (if (search-forward forward-str (point-max) t)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
336 (backward-char bookmark-search-size)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
337 (if behind-str
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
338 (if (search-backward behind-str (point-min) t)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
339 (forward-char bookmark-search-size)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
340 ;; added by db
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
341 (setq bookmark-current-bookmark str))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
342 (error
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
343 (concat "File "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
344 file
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
345 " does not exist. Suggest deleting bookmark \""
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
346 str
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
347 "\""))))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (defun bookmark-locate (str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 "Insert the name of the file associated with BOOKMARK \(as opposed
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 to the contents of that file\)."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
352 (interactive (let ((completion-ignore-case
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
353 bookmark-completion-ignore-case))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
354 (list (completing-read
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
355 "Insert bookmark location: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
356 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
357 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
358 0))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (insert (car (car (cdr (assoc str bookmark-alist))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (defun bookmark-rename (old)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 "Change the name of BOOKMARK to NEWNAME. While you are entering
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 the new name, consecutive C-w\'s will insert consectutive words from
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 the text of the buffer into the new bookmark name, and C-v will insert
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 the name of the file."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
366 (interactive (let ((completion-ignore-case
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
367 bookmark-completion-ignore-case))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
368 (list (completing-read "Old bookmark name: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
369 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
370 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
371 0))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (setq bookmark-current-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (setq bookmark-yank-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq bookmark-current-buffer (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (let ((cell (assoc old bookmark-alist))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (read-from-minibuffer
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 "New name: "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 nil
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (let ((now-map (copy-keymap minibuffer-local-map)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (progn (define-key now-map "\C-w"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 'bookmark-yank-word)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (define-key now-map "\C-v"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 'bookmark-insert-current-file-name))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 now-map))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (setcar cell str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (setq bookmark-current-bookmark str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (setq bookmark-alist-modification-count
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (1+ bookmark-alist-modification-count))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (if (bookmark-time-to-save-p)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (bookmark-save))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (defun bookmark-insert (str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 "Insert the text of the file pointed to by bookmark BOOKMARK. You
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 may have a problem using this function if the value of variable
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
398 \`bookmark-alist\' is nil. If that happens, you need to load in some
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
399 bookmarks. See help on function \`bookmark-load\' for more about
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
400 this."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
401 (interactive (let ((completion-ignore-case
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
402 bookmark-completion-ignore-case))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
403 (list (completing-read
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
404 "Insert bookmark contents: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
405 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
406 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
407 0))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (let ((file (car whereto-list)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (if (file-readable-p (expand-file-name file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (let ((str-to-insert
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (find-file (expand-file-name file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (prog1
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (buffer-substring (point-min) (point-max))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (bury-buffer))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (orig-point (point)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (insert str-to-insert)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (push-mark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (goto-char orig-point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (error
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (concat "File "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 " does not exist. Suggest deleting bookmark \""
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 "\""))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (defun bookmark-delete (str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 "Delete the bookmark named NAME from the bookmark list. Removes
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
430 only the first instance of a bookmark with that name. If there are
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
431 one or more other bookmarks with the same name, they will not be
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
432 deleted. Defaults to the \"current\" bookmark \(that is, the one most
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
433 recently used in this file, if any\)."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (interactive (let ((completion-ignore-case
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 bookmark-completion-ignore-case))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (list
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
437 (completing-read
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
438 "Delete bookmark: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
439 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
440 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
441 0
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
442 bookmark-current-bookmark))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
443 (let ((will-go (assoc str bookmark-alist)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
444 (setq bookmark-alist (delq will-go bookmark-alist))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
445 ;; Added by db, nil bookmark-current-bookmark if the last
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
446 ;; occurence has been deleted
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (or (assoc bookmark-current-bookmark bookmark-alist)
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
448 (setq bookmark-current-bookmark nil)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
449 (setq bookmark-alist-modification-count
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
450 (1+ bookmark-alist-modification-count))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
451 (if (bookmark-time-to-save-p)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
452 (bookmark-save)))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (defun bookmark-time-to-save-p (&optional last-time)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu>
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 ;; finds out whether it's time to save bookmarks to a file, by
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 ;; examining the value of variable bookmark-save-flag, and maybe
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 ;; bookmark-alist-modification-count. Returns t if they should be
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ;; saved, nil otherwise. if last-time is non-nil, then this is
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 ;; being called when emacs is killed.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (cond (last-time
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (and (> bookmark-alist-modification-count 0)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 bookmark-save-flag))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 ((numberp bookmark-save-flag)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (>= bookmark-alist-modification-count bookmark-save-flag))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (t
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 nil)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (defun bookmark-write ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (bookmark-save t))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
473 (defun bookmark-save (&optional parg file)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
474 "Save currently defined bookmarks in the file defined by the
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
475 variable \`bookmark-file\'. With a prefix arg, save it in file FILE.
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 If you are calling this from Lisp, the two arguments are PREFIX-ARG
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 and FILE, and if you just want it to write to the default file, then
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 pass no arguments. Or pass in nil and FILE, and it will save in FILE
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 instead. If you pass in one argument, and it is non-nil, then the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 user will be interactively queried for a file to save in.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
483 When you want to load in the bookmarks from a file, use
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
484 \\`bookmark-load\\', \\[bookmark-load]. That function will prompt you
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
485 for a file, defaulting to the file defined by variable
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
486 \`bookmark-file\'."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (interactive "P")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (cond
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 ((and (null parg) (null file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 ;;whether interactive or not, write to default file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (bookmark-write-file bookmark-file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 ((and (null parg) file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 ;;whether interactive or not, write to given file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (bookmark-write-file file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 ((and parg (not file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 ;;have been called interactively w/ prefix arg
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (let ((file (read-file-name "File to save bookmarks in: ")))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (bookmark-write-file file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (t ; someone called us with prefix-arg *and* a file, so just write to file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (bookmark-write-file file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 ;; signal that we have synced the bookmark file by setting this to
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 ;; 0. If there was an error at any point before, it will not get
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 ;; set, which is what we want.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (setq bookmark-alist-modification-count 0))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (defun bookmark-write-file (file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (message (format "Saving bookmarks to file %s." file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (set-buffer (find-file-noselect file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (goto-char (point-min))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (delete-region (point-min) (point-max))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (print bookmark-alist (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (write-file file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (kill-buffer (current-buffer))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (defun bookmark-load (file &optional revert no-msg)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 "Loads bookmarks from FILE, appending loaded bookmarks to the front
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 of the list of bookmarks. If optional second argument REVERT is
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 non-nil, existing bookmarks are destroyed. Optional third arg NO-MSG
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 means don't display any messages while loading.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 If you load a file that doesn't contain a proper bookmark alist, you
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 will corrupt Emacs\' bookmark list. Generally, you should only load
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 in files that were created with the bookmark functions in the first
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
525 place. Your own personal bookmark file, \`~/.emacs-bkmrks\', is
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
526 maintained automatically by Emacs; you shouldn't need to load it
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
527 explicitly."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (interactive
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (list (read-file-name
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (format "Load bookmarks from: (%s) "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 ;;Default might not be used often,
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 ;;but there's no better default, and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 ;;I guess it's better than none at all.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 "~/" bookmark-file 'confirm)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (setq file (expand-file-name file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (if (file-readable-p file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (if (null no-msg)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (message (format "Loading bookmarks from %s..." file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (set-buffer (find-file-noselect file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (goto-char (point-min))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (let ((blist (car (read-from-string
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (buffer-substring (point-min) (point-max))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (if (listp blist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (if (not revert)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (setq bookmark-alist-modification-count
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (1+ bookmark-alist-modification-count))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (setq bookmark-alist-modification-count 0))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (setq bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (append blist (if (not revert) bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (error (format "Invalid bookmark list in %s." file))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (kill-buffer (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (if (null no-msg)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (message (format "Loading bookmarks from %s... done" file))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (error (format "Cannot read bookmark file %s." file))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
559 ;;;; bookmark menu bar stuff ;;;;
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
561 (defvar bookmark-menu-bar-length 70 "*Maximum length of a bookmark name
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
562 displayed on a popup menu.")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
563
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
564 (defvar bookmark-enable-menu-bar t
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 "*Non-nil means put a bookmark menu on the menu bar \(assuming that
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 you are running Emacs under a windowing system, such as X\).")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
568 (defun bookmark-make-menu-bar-alist ()
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 (if (not bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (if (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (bookmark-load bookmark-file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (if bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (mapcar (lambda (cell)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (let ((str (car cell)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (cons
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
576 (if (> (length str) bookmark-menu-bar-length)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
577 (substring str 0 bookmark-menu-bar-length)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 str)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (error "No bookmarks currently set.")))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
583 (defun bookmark-make-menu-bar-with-function (func-sym
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
584 menu-label
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
585 menu-str event)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 ;; help function for making menus that need to apply a bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 ;; function to a string.
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
588 (let* ((menu (bookmark-make-menu-bar-alist))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (str (x-popup-menu event
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (list menu-label
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (cons menu-str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 menu)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (if str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (apply func-sym (list str)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
596 (defun bookmark-menu-bar-insert (event)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
597 ;; see bookmark-insert
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
599 (bookmark-make-menu-bar-with-function 'bookmark-insert
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 "Bookmark Insert Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 "--- Insert Contents ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
604 (defun bookmark-menu-bar-jump (event)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
605 ;; see bookmark-jump
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
607 (bookmark-make-menu-bar-with-function 'bookmark-jump
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 "Bookmark Jump Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 "--- Jump to Bookmark ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
612 (defun bookmark-menu-bar-locate (event)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
613 ;; see bookmark-locate
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
615 (bookmark-make-menu-bar-with-function 'bookmark-locate
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 "Bookmark Locate Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 "--- Insert Location ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
620 (defun bookmark-menu-bar-rename (event)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
621 ;; see bookmark-rename
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
623 (bookmark-make-menu-bar-with-function 'bookmark-rename
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 "Bookmark Rename Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 "--- Rename Bookmark ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
628 (defun bookmark-menu-bar-delete (event)
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
629 ;; see bookmark-delete
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
631 (bookmark-make-menu-bar-with-function 'bookmark-delete
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 "Bookmark Delete Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 "--- Delete Bookmark ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
636 (if (and bookmark-enable-menu-bar window-system)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (defvar menu-bar-bookmark-map
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 (make-sparse-keymap "Bookmark functions"))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 ;; make bookmarks appear toward the right side of the menu.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (if (boundp 'menu-bar-final-items)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 (if menu-bar-final-items
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (setq menu-bar-final-items
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 (cons 'bookmark menu-bar-final-items)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 (setq menu-bar-final-items '(bookmark)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (define-key global-map [menu-bar bookmark]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (cons "Bookmarks" menu-bar-bookmark-map))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (define-key menu-bar-bookmark-map [load]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 '(" Load a bookmark file" . bookmark-load))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (define-key menu-bar-bookmark-map [write]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 '("Write \(to another file\)" . bookmark-write))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (define-key menu-bar-bookmark-map [save]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
658 '("Save \(in default file\)" . bookmark-save))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (define-key menu-bar-bookmark-map [delete]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
661 '(" Delete a bookmark" . bookmark-menu-bar-delete))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 (define-key menu-bar-bookmark-map [rename]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
664 '(" Rename bookmark" . bookmark-menu-bar-rename))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 (define-key menu-bar-bookmark-map [locate]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
667 '(" Insert location" . bookmark-menu-bar-locate))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (define-key menu-bar-bookmark-map [insert]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
670 '(" Insert contents" . bookmark-menu-bar-insert))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (define-key menu-bar-bookmark-map [set]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 '(" Set bookmark" . bookmark-set))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (define-key menu-bar-bookmark-map [jump]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
676 '(" Go to bookmark" . bookmark-menu-bar-jump))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 ;; not using properties because they make the menu sluggish in coming
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 ;; up -- too many tests to make. Instead, choosing a useless menu
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 ;; item just gets you an error now (see
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
681 ;; bookmark-make-menu-bar-with-function)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
683 ;; (put 'bookmark-menu-bar-jump 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
689 ;; (put 'bookmark-menu-bar-insert 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
695 ;; (put 'bookmark-menu-bar-locate 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
701 ;; (put 'bookmark-menu-bar-rename 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
707 ;; (put 'bookmark-menu-bar-delete 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
713 ;; (put 'bookmark-menu-bar-save 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
719 ;; (put 'bookmark-menu-bar-write 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
725 ;;;; end bookmark menu-bar stuff ;;;;
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 ;; load the default bookmark file, if it exists, and the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 ;; bookmark-alist is nil:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 (bookmark-try-default-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (provide 'bookmark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
733 ;;; bookmark.el ends here