annotate lisp/bookmark.el @ 4705:bbeec82f0416

(lib-src/Makefile, src/Makefile, oldXMenu/Makefile): Depend on vpath.sed. Replace sed comand for VPATH with @vpath_sed@.
author Roland McGrath <roland@gnu.org>
date Sun, 12 Sep 1993 10:49:30 +0000
parents cd8eef9ec0c4
children 511c83aee4ae
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
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
85 (defvar bookmark-map nil
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
86 "Keymap containing bindings to bookmark functions.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
87 It is not bound to any key by default: to bind it
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
88 so that you have a bookmark prefix, just use `global-set-key' and bind a
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
89 key of your choice to `bookmark-map'. All interactive bookmark
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 functions have a binding in this keymap.")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (define-prefix-command 'bookmark-map)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; Read the help on all of these functions for details...
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; "x" marks the spot!
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (define-key bookmark-map "x" 'bookmark-set)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (define-key bookmark-map "j" 'bookmark-jump)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (define-key bookmark-map "i" 'bookmark-insert)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (define-key bookmark-map "f" 'bookmark-locate) ; "f" for "find"
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
100 (define-key bookmark-map "r" 'bookmark-rename)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; deletes bookmarks
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (define-key bookmark-map "d" 'bookmark-delete)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; loads new file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (define-key bookmark-map "l" 'bookmark-load)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;; saves them in file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (define-key bookmark-map "w" 'bookmark-write)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (define-key bookmark-map "s" 'bookmark-save)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
4634
cd8eef9ec0c4 (bookmark-alist): Move defvar before first use.
Richard M. Stallman <rms@gnu.org>
parents: 4633
diff changeset
109 (defvar bookmark-alist ()
cd8eef9ec0c4 (bookmark-alist): Move defvar before first use.
Richard M. Stallman <rms@gnu.org>
parents: 4633
diff changeset
110 "Association list of bookmarks.
cd8eef9ec0c4 (bookmark-alist): Move defvar before first use.
Richard M. Stallman <rms@gnu.org>
parents: 4633
diff changeset
111 You probably don't want to change the value of this alist yourself;
cd8eef9ec0c4 (bookmark-alist): Move defvar before first use.
Richard M. Stallman <rms@gnu.org>
parents: 4633
diff changeset
112 instead, let the various bookmark functions do it for you.")
cd8eef9ec0c4 (bookmark-alist): Move defvar before first use.
Richard M. Stallman <rms@gnu.org>
parents: 4633
diff changeset
113
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; 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
115 ;; 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
116
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (add-hook 'kill-emacs-hook
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (function
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (lambda ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (and (featurep 'bookmark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (bookmark-time-to-save-p t)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (bookmark-save)))))
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 ;; more stuff added by db.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defvar bookmark-current-bookmark nil
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
127 "Name of bookmark most recently used in the current file.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
128 It is buffer local, used to make moving a bookmark forward
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
129 through a file easier.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (make-variable-buffer-local 'bookmark-current-bookmark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (defvar bookmark-save-flag t
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
134 "*Controls when Emacs saves bookmarks to a file.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
135 --> Nil means never save bookmarks, except when `bookmark-save' is
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
136 explicitly called \(\\[bookmark-save]\).
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
137 --> t means save bookmarks when Emacs is killed.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
138 --> Otherise, it should be a number that is the frequency with which
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
139 the bookmark list is saved \(i.e.: the number of times which
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
140 Emacs' bookmark list may be modified before it is automatically
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
141 saved.\). If it is a number, Emacs will also automatically save
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
142 bookmarks when it is killed.
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 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
145 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
146 behavior.\)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 To specify the file in which to save them, modify the variable
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
149 bookmark-file, which is `~/.emacs-bkmrks' by default.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defvar bookmark-alist-modification-count 0
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
152 "Number of modifications to bookmark list since it was last saved.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defvar bookmark-file "~/.emacs-bkmrks"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "*File in which to save bookmarks by default.")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (defvar bookmark-completion-ignore-case t
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
158 "*Non-nil means bookmark functions ignore case in completion.")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
160 (defvar bookmark-search-size 500
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
161 "Length of the 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-current-point 0)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defvar bookmark-yank-point 0)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defvar bookmark-current-buffer nil)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (defun bookmark-set (&optional parg)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
168
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
169 "Set a bookmark named NAME inside a file.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
170 With prefix arg, will not overwrite a bookmark that has the same name
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
171 as NAME if such a bookmark already exists, but instead will \"push\"
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
172 the new bookmark onto the bookmark alist. Thus the most recently set
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
173 bookmark with name NAME would be the one in effect at any given time,
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
174 but the others are still there, should you decide to delete the most
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
175 recent one.
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 To yank words from the text of the buffer and use them as part of the
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
178 bookmark name, type C-w while setting a bookmark. Successive C-w's
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 yank successive words.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 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
182 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
183 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
184 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
185 inserts the name of the file being visited.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 Use \\[bookmark-delete] to remove bookmarks \(you give it a name,
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 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
189 the list of bookmarks.\)"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (interactive "P")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (if (not (bookmark-buffer-file-name))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (error "Buffer not visiting a file or directory."))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (setq bookmark-current-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (setq bookmark-yank-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (setq bookmark-current-buffer (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (let ((str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (read-from-minibuffer
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 "Set bookmark: "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 nil
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (let ((now-map (copy-keymap minibuffer-local-map)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (progn (define-key now-map "\C-w"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 'bookmark-yank-word)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (define-key now-map "\C-v"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 'bookmark-insert-current-file-name)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (define-key now-map "\C-u"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 'bookmark-insert-current-bookmark))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 now-map))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (bookmark-make parg str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (setq bookmark-current-bookmark str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (goto-char bookmark-current-point))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun bookmark-insert-current-bookmark ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;; insert this buffer's value of bookmark-current-bookmark, default
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 ;; to file name if it's nil.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (let ((str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (set-buffer bookmark-current-buffer)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 bookmark-current-bookmark)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (if str (insert str) (bookmark-insert-current-file-name))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (defun bookmark-insert-current-file-name ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; 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
225 ;; name that is being set.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (let ((str (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (set-buffer bookmark-current-buffer)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (bookmark-buffer-file-name))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (insert (substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (1+ (string-match
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 "\\(/[^/]*\\)/*$"
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
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (defun bookmark-yank-word ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ;; 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
239 ;; the bookmark currently being set.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (let ((string (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (set-buffer bookmark-current-buffer)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (goto-char bookmark-yank-point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (buffer-substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (forward-word 1)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (setq bookmark-yank-point (point)))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (insert string)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (defun bookmark-make (parg str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (if (and (assoc str bookmark-alist) (not parg))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 ;; already existing boookmark under that name and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ;; no prefix arg means just overwrite old bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (setcdr (assoc str bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (list (bookmark-make-cell)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ;; otherwise just cons it onto the front (either the bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;; 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
259 ;; case, we want the new bookmark consed onto the alist...)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (setq bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (cons
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (list str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (bookmark-make-cell))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 bookmark-alist)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; Added by db
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (setq bookmark-current-bookmark str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (setq bookmark-alist-modification-count
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (1+ bookmark-alist-modification-count))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (if (bookmark-time-to-save-p)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (bookmark-save)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (defun bookmark-make-cell ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 ;; 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
275 ;; looks like this:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 ;; (filename search-forward-str search-back-str point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (list
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (bookmark-buffer-file-name)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (if (>= (- (point-max) (point)) bookmark-search-size)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (buffer-substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (+ (point) bookmark-search-size))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 nil)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (if (>= (- (point) (point-min)) bookmark-search-size)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (buffer-substring
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (point)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (- (point) bookmark-search-size))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 nil)
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
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (defun bookmark-buffer-file-name ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (or
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 buffer-file-name
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (if (and (boundp 'dired-directory) dired-directory)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (if (stringp dired-directory)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 dired-directory
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (car dired-directory)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (defun bookmark-try-default-file ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (if (and (null bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (file-readable-p (expand-file-name bookmark-file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (bookmark-load bookmark-file)))
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
303
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (defun bookmark-jump (str)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
305 "Jump to bookmark BOOKMARK (a point in some file).
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
306 You may have a problem using this function if the value of variable
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
307 `bookmark-alist' is nil. If that happens, you need to load in some
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
308 bookmarks. See help on function `bookmark-load' for more about
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
309 this."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
310 (interactive (let ((completion-ignore-case
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 bookmark-completion-ignore-case))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (list (completing-read
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 "Jump to bookmark: "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 nil
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
316 0))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
317 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
318 (let ((file (car whereto-list))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
319 (forward-str (car (cdr whereto-list)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
320 (behind-str (car (cdr (cdr whereto-list))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
321 (place (car (cdr (cdr (cdr whereto-list))))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
322 (if (file-exists-p (expand-file-name file))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
323 (progn
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
324 (find-file (expand-file-name file))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
325 (goto-char place)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
326 ;; 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
327 ;; 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
328 ;; 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
329 ;; 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
330 ;; 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
331 (if forward-str
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
332 (if (search-forward forward-str (point-max) t)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
333 (backward-char bookmark-search-size)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
334 (if behind-str
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
335 (if (search-backward behind-str (point-min) t)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
336 (forward-char bookmark-search-size)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
337 ;; added by db
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
338 (setq bookmark-current-bookmark str))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
339 (error
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
340 (concat "File "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
341 file
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
342 " does not exist. Suggest deleting bookmark \""
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
343 str
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
344 "\""))))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (defun bookmark-locate (str)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
347 "Insert the name of the file associated with BOOKMARK.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
348 \(This is not the same as the contents of that file\)."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
349 (interactive (let ((completion-ignore-case
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
350 bookmark-completion-ignore-case))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
351 (list (completing-read
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
352 "Insert bookmark location: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
353 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
354 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
355 0))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (insert (car (car (cdr (assoc str bookmark-alist))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
358 (defun bookmark-rename (old &optional new)
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
359 "Change the name of BOOKMARK to NEWNAME.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
360 If called from keyboard, prompts for OLD and NEWNAME.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
361 If called from menubar, prompts for NEWNAME.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
362 If called from Lisp, prompts for NEWNAME if only BOOKMARK was passed
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
363 as an argument. If called with two strings, then no prompting is
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
364 done. You must pass at least BOOKMARK when calling from Lisp.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
365
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
366 While you are entering the new name, consecutive C-w's insert
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
367 consectutive words from the text of the buffer into the new bookmark
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
368 name, and C-v inserts the name of the file."
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
369
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
370 (interactive (let ((completion-ignore-case
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
371 bookmark-completion-ignore-case))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
372 (list (completing-read "Old bookmark name: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
373 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
374 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
375 0))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (setq bookmark-current-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (setq bookmark-yank-point (point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (setq bookmark-current-buffer (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (let ((cell (assoc old bookmark-alist))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (str
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
382 (or new ; use second arg, if non-nil
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
383 (read-from-minibuffer
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
384 "New name: "
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
385 nil
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
386 (let ((now-map (copy-keymap minibuffer-local-map)))
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
387 (progn (define-key now-map "\C-w"
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
388 'bookmark-yank-word)
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
389 (define-key now-map "\C-v"
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
390 'bookmark-insert-current-file-name))
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
391 now-map)))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (setcar cell str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (setq bookmark-current-bookmark str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (setq bookmark-alist-modification-count
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (1+ bookmark-alist-modification-count))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (if (bookmark-time-to-save-p)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (bookmark-save))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (defun bookmark-insert (str)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
401 "Insert the text of the file pointed to by bookmark BOOKMARK.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
402 You may have a problem using this function if the value of variable
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
403 `bookmark-alist' is nil. If that happens, you need to load in some
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
404 bookmarks. See help on function `bookmark-load' for more about
4631
fc781d29fd48 New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4595
diff changeset
405 this."
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
406 (interactive (let ((completion-ignore-case
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
407 bookmark-completion-ignore-case))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
408 (list (completing-read
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
409 "Insert bookmark contents: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
410 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
411 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
412 0))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (let ((whereto-list (car (cdr (assoc str bookmark-alist)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (let ((file (car whereto-list)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (if (file-readable-p (expand-file-name file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (let ((str-to-insert
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (find-file (expand-file-name file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (prog1
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (buffer-substring (point-min) (point-max))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (bury-buffer))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (orig-point (point)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (insert str-to-insert)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (push-mark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (goto-char orig-point))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (error
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (concat "File "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 " does not exist. Suggest deleting bookmark \""
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 "\""))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (defun bookmark-delete (str)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
434 "Delete the bookmark named NAME from the bookmark list.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
435 Removes only the first instance of a bookmark with that name. If
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
436 there are one or more other bookmarks with the same name, they will
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
437 not be deleted. Defaults to the \"current\" bookmark \(that is, the
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
438 one most recently used in this file, if any\)."
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
439
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (interactive (let ((completion-ignore-case
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 bookmark-completion-ignore-case))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (list
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
443 (completing-read
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
444 "Delete bookmark: "
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
445 bookmark-alist
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
446 nil
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
447 0
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
448 bookmark-current-bookmark))))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
449 (let ((will-go (assoc str bookmark-alist)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
450 (setq bookmark-alist (delq will-go bookmark-alist))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
451 ;; 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
452 ;; occurence has been deleted
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (or (assoc bookmark-current-bookmark bookmark-alist)
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
454 (setq bookmark-current-bookmark nil)))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
455 (setq bookmark-alist-modification-count
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
456 (1+ bookmark-alist-modification-count))
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
457 (if (bookmark-time-to-save-p)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
458 (bookmark-save)))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (defun bookmark-time-to-save-p (&optional last-time)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 ;; By Gregory M. Saunders <saunders@cis.ohio-state.edu>
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 ;; 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
463 ;; examining the value of variable bookmark-save-flag, and maybe
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 ;; bookmark-alist-modification-count. Returns t if they should be
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 ;; 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
466 ;; being called when emacs is killed.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (cond (last-time
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (and (> bookmark-alist-modification-count 0)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 bookmark-save-flag))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 ((numberp bookmark-save-flag)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (>= bookmark-alist-modification-count bookmark-save-flag))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (t
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 nil)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (defun bookmark-write ()
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (interactive)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (bookmark-save t))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
479 (defun bookmark-save (&optional parg file)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
480 "Save currently defined bookmarks.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
481 Saves by default in the file defined by the variable
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
482 `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
483
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 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
485 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
486 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
487 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
488 user will be interactively queried for a file to save in.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
490 When you want to load in the bookmarks from a file, use
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
491 \`bookmark-load\', \\[bookmark-load]. That function will prompt you
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
492 for a file, defaulting to the file defined by variable
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
493 `bookmark-file'."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (interactive "P")
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (cond
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 ((and (null parg) (null file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 ;;whether interactive or not, write to default file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (bookmark-write-file bookmark-file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 ((and (null parg) file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 ;;whether interactive or not, write to given file
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (bookmark-write-file file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 ((and parg (not file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 ;;have been called interactively w/ prefix arg
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (let ((file (read-file-name "File to save bookmarks in: ")))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (bookmark-write-file file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (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
507 (bookmark-write-file file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 ;; 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
509 ;; 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
510 ;; set, which is what we want.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (setq bookmark-alist-modification-count 0))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (defun bookmark-write-file (file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (message (format "Saving bookmarks to file %s." file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (set-buffer (find-file-noselect file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (goto-char (point-min))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (delete-region (point-min) (point-max))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (print bookmark-alist (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (write-file file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (kill-buffer (current-buffer))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (defun bookmark-load (file &optional revert no-msg)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
524 "Load bookmarks from FILE (which must be in bookmark format).
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
525 Appends loaded bookmarks to the front of the list of bookmarks. If
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
526 optional second argument REVERT is non-nil, existing bookmarks are
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
527 destroyed. Optional third arg NO-MSG means don't display any messages
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
528 while loading.
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 If you load a file that doesn't contain a proper bookmark alist, you
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
531 will corrupt Emacs's bookmark list. Generally, you should only load
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 in files that were created with the bookmark functions in the first
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
533 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
534 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
535 explicitly."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (interactive
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (list (read-file-name
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (format "Load bookmarks from: (%s) "
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 ;;Default might not be used often,
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 ;;but there's no better default, and
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 ;;I guess it's better than none at all.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 "~/" bookmark-file 'confirm)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (setq file (expand-file-name file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (if (file-readable-p file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (save-excursion
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (if (null no-msg)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (message (format "Loading bookmarks from %s..." file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (set-buffer (find-file-noselect file))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (goto-char (point-min))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (let ((blist (car (read-from-string
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (buffer-substring (point-min) (point-max))))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (if (listp blist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (if (not revert)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (setq bookmark-alist-modification-count
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (1+ bookmark-alist-modification-count))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (setq bookmark-alist-modification-count 0))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (setq bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (append blist (if (not revert) bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (error (format "Invalid bookmark list in %s." file))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (kill-buffer (current-buffer))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (if (null no-msg)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (message (format "Loading bookmarks from %s... done" file))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (error (format "Cannot read bookmark file %s." file))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
567 ;;;; bookmark menu bar stuff ;;;;
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
569 (defvar bookmark-menu-bar-length 70
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
570 "*Maximum length of a bookmark name displayed on a popup menu.")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
571
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
572 (defvar bookmark-enable-menu-bar t
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
573 "*Non-nil means put a bookmark menu on the menu bar.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
574 \(Assuming that you are running Emacs under a windowing system, such
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
575 as X.\)")
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
577 (defun bookmark-make-menu-bar-alist ()
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (if (not bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (if (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (bookmark-load bookmark-file)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (if bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (mapcar (lambda (cell)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (let ((str (car cell)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (cons
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
585 (if (> (length str) bookmark-menu-bar-length)
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
586 (substring str 0 bookmark-menu-bar-length)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 str)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 str)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 bookmark-alist)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (error "No bookmarks currently set.")))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
592 (defun bookmark-make-menu-bar-with-function (func-sym
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
593 menu-label
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
594 menu-str event)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 ;; help function for making menus that need to apply a bookmark
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 ;; function to a string.
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
597 (let* ((menu (bookmark-make-menu-bar-alist))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (str (x-popup-menu event
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (list menu-label
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (cons menu-str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 menu)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (if str
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (apply func-sym (list str)))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
605 (defun bookmark-menu-bar-insert (event)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
606 "Insert the text of the file pointed to by bookmark BOOKMARK.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
607 You may have a problem using this function if the value of variable
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
608 `bookmark-alist' is nil. If that happens, you need to load in some
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
609 bookmarks. See help on function `bookmark-load' for more about
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
610 this."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
612 (bookmark-make-menu-bar-with-function 'bookmark-insert
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 "Bookmark Insert Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 "--- Insert Contents ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
617 (defun bookmark-menu-bar-jump (event)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
618 "Jump to bookmark BOOKMARK (a point in some file).
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
619 You may have a problem using this function if the value of variable
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
620 `bookmark-alist' is nil. If that happens, you need to load in some
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
621 bookmarks. See help on function `bookmark-load' for more about
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
622 this."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
624 (bookmark-make-menu-bar-with-function 'bookmark-jump
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 "Bookmark Jump Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 "--- Jump to Bookmark ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
629 (defun bookmark-menu-bar-locate (event)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
630 "Insert the name of the file associated with BOOKMARK.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
631 \(This is not the same as the contents of that file\)."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
633 (bookmark-make-menu-bar-with-function 'bookmark-locate
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 "Bookmark Locate Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 "--- Insert Location ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
638 (defun bookmark-menu-bar-rename (event)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
639 "Change the name of BOOKMARK to NEWNAME.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
640 If called from keyboard, prompts for OLD and NEWNAME.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
641 If called from menubar, prompts for NEWNAME.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
642 If called from Lisp, prompts for NEWNAME if only BOOKMARK was passed
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
643 as an argument. If called with two strings, then no prompting is
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
644 done. You must pass at least BOOKMARK when calling from Lisp.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
645
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
646 While you are entering the new name, consecutive C-w's insert
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
647 consectutive words from the text of the buffer into the new bookmark
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
648 name, and C-v inserts the name of the file."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
650 (bookmark-make-menu-bar-with-function 'bookmark-rename
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 "Bookmark Rename Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 "--- Rename Bookmark ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
655 (defun bookmark-menu-bar-delete (event)
4633
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
656 "Delete the bookmark named NAME from the bookmark list.
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
657 Removes only the first instance of a bookmark with that name. If
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
658 there are one or more other bookmarks with the same name, they will
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
659 not be deleted. Defaults to the \"current\" bookmark \(that is, the
738840d8e627 Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 4631
diff changeset
660 one most recently used in this file, if any\)."
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (interactive "e")
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
662 (bookmark-make-menu-bar-with-function 'bookmark-delete
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 "Bookmark Delete Menu"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 "--- Delete Bookmark ---"
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 event))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
667 (if (and bookmark-enable-menu-bar window-system)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (progn
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (defvar menu-bar-bookmark-map
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (make-sparse-keymap "Bookmark functions"))
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 ;; make bookmarks appear toward the right side of the menu.
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (if (boundp 'menu-bar-final-items)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (if menu-bar-final-items
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (setq menu-bar-final-items
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (cons 'bookmark menu-bar-final-items)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (setq menu-bar-final-items '(bookmark)))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (define-key global-map [menu-bar bookmark]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (cons "Bookmarks" menu-bar-bookmark-map))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (define-key menu-bar-bookmark-map [load]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 '(" Load a bookmark file" . bookmark-load))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (define-key menu-bar-bookmark-map [write]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 '("Write \(to another file\)" . bookmark-write))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (define-key menu-bar-bookmark-map [save]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
689 '("Save \(in default file\)" . bookmark-save))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (define-key menu-bar-bookmark-map [delete]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
692 '(" Delete a bookmark" . bookmark-menu-bar-delete))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (define-key menu-bar-bookmark-map [rename]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
695 '(" Rename bookmark" . bookmark-menu-bar-rename))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (define-key menu-bar-bookmark-map [locate]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
698 '(" Insert location" . bookmark-menu-bar-locate))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (define-key menu-bar-bookmark-map [insert]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
701 '(" Insert contents" . bookmark-menu-bar-insert))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (define-key menu-bar-bookmark-map [set]
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 '(" Set bookmark" . bookmark-set))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (define-key menu-bar-bookmark-map [jump]
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
707 '(" Go to bookmark" . bookmark-menu-bar-jump))))
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 ;; not using properties because they make the menu sluggish in coming
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 ;; up -- too many tests to make. Instead, choosing a useless menu
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 ;; item just gets you an error now (see
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
712 ;; bookmark-make-menu-bar-with-function)
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
714 ;; (put 'bookmark-menu-bar-jump 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
720 ;; (put 'bookmark-menu-bar-insert 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
726 ;; (put 'bookmark-menu-bar-locate 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
732 ;; (put 'bookmark-menu-bar-rename 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
738 ;; (put 'bookmark-menu-bar-delete 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
744 ;; (put 'bookmark-menu-bar-save 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 ;;
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
750 ;; (put 'bookmark-menu-bar-write 'menu-enable
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 ;; '(or bookmark-alist
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 ;; (and (file-readable-p bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 ;; (progn (bookmark-load bookmark-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 ;; bookmark-alist))))
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
756 ;;;; end bookmark menu-bar stuff ;;;;
4537
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 ;; load the default bookmark file, if it exists, and the
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 ;; bookmark-alist is nil:
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (bookmark-try-default-file)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (provide 'bookmark)
14f38c0332a4 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763
4595
2507541ef88d New version from Fogel.
Richard M. Stallman <rms@gnu.org>
parents: 4537
diff changeset
764 ;;; bookmark.el ends here