annotate lisp/subr.el @ 406:b8cc9ab3f761 r21-2-33

Import from CVS: tag r21-2-33
author cvs
date Mon, 13 Aug 2007 11:17:09 +0200
parents 2f8bb876ab1d
children 697ef44129c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; subr.el --- basic lisp subroutines for XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1992, 1994-5, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Copyright (C) 1995 Sun Microsystems.
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
6 ;; Copyright (C) 2000 Ben Wing.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; Keywords: extensions, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Synched up with: FSF 19.34.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;; There's not a whole lot in common now with the FSF version,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 ;; be wary when applying differences. I've left in a number of lines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;; of commentary just to give diff(1) something to synch itself with to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 ;; provide useful context diffs. -sb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 ;;;; Lisp language features.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 (defmacro lambda (&rest cdr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 "Return a lambda expression.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 self-quoting; the result of evaluating the lambda expression is the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 expression itself. The lambda expression may then be treated as a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 function, i.e., stored as the function value of a symbol, passed to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 funcall or mapcar, etc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 ARGS should take the same form as an argument list for a `defun'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 DOCSTRING is an optional documentation string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 If present, it should describe how to call the function.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 But documentation strings are usually not useful in nameless functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 INTERACTIVE should be a call to the function `interactive', which see.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 It may also be omitted.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 BODY should be a list of lisp expressions."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 `(function (lambda ,@cdr)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (defmacro defun-when-void (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 "Define a function, just like `defun', unless it's already defined.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 Used for compatibility among different emacs variants."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 `(if (fboundp ',(car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 (defun ,@args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 (defmacro define-function-when-void (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 "Define a function, just like `define-function', unless it's already defined.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 Used for compatibility among different emacs variants."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 `(if (fboundp ,(car args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 (define-function ,@args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 ;;;; Keymap support.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 ;; XEmacs: removed to keymap.el
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
79 ;;;; The global keymap tree.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 ;;; global-map, esc-map, and ctl-x-map have their values set up in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 ;;; keymap.c; we just give them docstrings here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 ;;;; Event manipulation functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 ;; XEmacs: This stuff is done in C Code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 ;;;; Obsolescent names for functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 ;; XEmacs: not used.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 ;; XEmacs:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (defun local-variable-if-set-p (sym buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 "Return t if SYM would be local to BUFFER after it is set.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 A nil value for BUFFER is *not* the same as (current-buffer), but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 can be used to determine whether `make-variable-buffer-local' has been
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 called on SYM."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 (local-variable-p sym buffer t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 ;;;; Hook manipulation functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 ;; (defconst run-hooks 'run-hooks ...)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (defun make-local-hook (hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 "Make the hook HOOK local to the current buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 When a hook is local, its local and global values
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 work in concert: running the hook actually runs all the hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 functions listed in *either* the local value *or* the global value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 of the hook variable.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 This function works by making `t' a member of the buffer-local value,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 which acts as a flag to run the hook functions in the default value as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 well. This works for all normal hooks, but does not work for most
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 non-normal hooks yet. We will be changing the callers of non-normal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 hooks so that they can handle localness; this has to be done one by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 This function does nothing if HOOK is already local in the current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
121 Do not use `make-local-variable' to make a hook variable buffer-local.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
122
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
123 See also `add-local-hook' and `remove-local-hook'."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 (if (local-variable-p hook (current-buffer)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 (or (boundp hook) (set hook nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (make-local-variable hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 (set hook (list t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 (defun add-hook (hook function &optional append local)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 "Add to the value of HOOK the function FUNCTION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 FUNCTION is not added if already present.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 FUNCTION is added (if necessary) at the beginning of the hook list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 unless the optional argument APPEND is non-nil, in which case
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 FUNCTION is added at the end.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 The optional fourth argument, LOCAL, if non-nil, says to modify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 the hook's buffer-local value rather than its default value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 This makes no difference if the hook is not buffer-local.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 To make a hook variable buffer-local, always use
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 `make-local-hook', not `make-local-variable'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 HOOK should be a symbol, and FUNCTION may be any valid function. If
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 HOOK is void, it is first set to nil. If HOOK's value is a single
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
145 function, it is changed to a list of functions.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
146
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
147 You can remove this hook yourself using `remove-hook'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
148
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
149 See also `add-local-hook' and `add-one-shot-hook'."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (or (boundp hook) (set hook nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (or (default-boundp hook) (set-default hook nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 ;; If the hook value is a single function, turn it into a list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (let ((old (symbol-value hook)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (if (or (not (listp old)) (eq (car old) 'lambda))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 (set hook (list old))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 (if (or local
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 ;; Detect the case where make-local-variable was used on a hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 ;; and do what we used to do.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (and (local-variable-if-set-p hook (current-buffer)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (not (memq t (symbol-value hook)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 ;; Alter the local value only.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (or (if (consp function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (member function (symbol-value hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (memq function (symbol-value hook)))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
165 (set hook
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (if append
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 (append (symbol-value hook) (list function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 (cons function (symbol-value hook)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 ;; Alter the global value (which is also the only value,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 ;; if the hook doesn't have a local value).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (or (if (consp function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (member function (default-value hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (memq function (default-value hook)))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
174 (set-default hook
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (if append
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (append (default-value hook) (list function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 (cons function (default-value hook)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 (defun remove-hook (hook function &optional local)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 "Remove from the value of HOOK the function FUNCTION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 HOOK should be a symbol, and FUNCTION may be any valid function. If
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 The optional third argument, LOCAL, if non-nil, says to modify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 the hook's buffer-local value rather than its default value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 This makes no difference if the hook is not buffer-local.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 To make a hook variable buffer-local, always use
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 `make-local-hook', not `make-local-variable'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 (if (or (not (boundp hook)) ;unbound symbol, or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 (not (default-boundp 'hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 (null (symbol-value hook)) ;value is nil, or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 (null function)) ;function is nil, then
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 nil ;Do nothing.
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
195 (flet ((hook-remove
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
196 (function hook-value)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
197 (flet ((hook-test
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
198 (fn hel)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
199 (or (equal fn hel)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
200 (and (symbolp hel)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
201 (equal fn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
202 (get hel 'one-shot-hook-fun))))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
203 (if (and (consp hook-value)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
204 (not (functionp hook-value)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
205 (if (member* function hook-value :test 'hook-test)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
206 (setq hook-value
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
207 (delete* function (copy-sequence hook-value)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
208 :test 'hook-test)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
209 (if (equal hook-value function)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
210 (setq hook-value nil)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
211 hook-value)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
212 (if (or local
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
213 ;; Detect the case where make-local-variable was used on a hook
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
214 ;; and do what we used to do.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
215 (and (local-variable-p hook (current-buffer))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
216 (not (memq t (symbol-value hook)))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
217 (set hook (hook-remove function (symbol-value hook)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
218 (set-default hook (hook-remove function (default-value hook)))))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
219
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
220 ;; XEmacs addition
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
221 ;; #### we need a coherent scheme for indicating compatibility info,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
222 ;; so that it can be programmatically retrieved.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
223 (defun add-local-hook (hook function &optional append)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
224 "Add to the local value of HOOK the function FUNCTION.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
225 This modifies only the buffer-local value for the hook (which is
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
226 automatically make buffer-local, if necessary), not its default value.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
227 FUNCTION is not added if already present.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
228 FUNCTION is added (if necessary) at the beginning of the hook list
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
229 unless the optional argument APPEND is non-nil, in which case
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
230 FUNCTION is added at the end.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
231
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
232 HOOK should be a symbol, and FUNCTION may be any valid function. If
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
233 HOOK is void, it is first set to nil. If HOOK's value is a single
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
234 function, it is changed to a list of functions.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
235
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
236 You can remove this hook yourself using `remove-local-hook'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
237
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
238 See also `add-hook' and `make-local-hook'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
239 (make-local-hook hook)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
240 (add-hook hook function append t))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
241
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
242 ;; XEmacs addition
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
243 (defun remove-local-hook (hook function)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
244 "Remove from the local value of HOOK the function FUNCTION.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
245 This modifies only the buffer-local value for the hook, not its default
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
246 value. (Nothing happens if the hook is not buffer-local.)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
247 HOOK should be a symbol, and FUNCTION may be any valid function. If
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
248 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
249 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
250
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
251 See also `add-local-hook' and `make-local-hook'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
252 (if (local-variable-p hook (current-buffer))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
253 (remove-hook hook function t)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
254
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
255 (defun add-one-shot-hook (hook function &optional append local)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
256 "Add to the value of HOOK the one-shot function FUNCTION.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
257 FUNCTION will automatically be removed from the hook the first time
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
258 after it runs (whether to completion or to an error).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
259 FUNCTION is not added if already present.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
260 FUNCTION is added (if necessary) at the beginning of the hook list
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
261 unless the optional argument APPEND is non-nil, in which case
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
262 FUNCTION is added at the end.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
263
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
264 HOOK should be a symbol, and FUNCTION may be any valid function. If
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
265 HOOK is void, it is first set to nil. If HOOK's value is a single
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
266 function, it is changed to a list of functions.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
267
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
268 You can remove this hook yourself using `remove-hook'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
269
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
270 See also `add-hook', `add-local-hook', and `add-local-one-shot-hook'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
271 (let ((sym (gensym)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
272 (fset sym `(lambda (&rest args)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
273 (unwind-protect
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
274 (apply ',function args)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
275 (remove-hook ',hook ',sym ',local))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
276 (put sym 'one-shot-hook-fun function)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
277 (add-hook hook sym append local)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
278
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
279 (defun add-local-one-shot-hook (hook function &optional append)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
280 "Add to the local value of HOOK the one-shot function FUNCTION.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
281 FUNCTION will automatically be removed from the hook the first time
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
282 after it runs (whether to completion or to an error).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
283 FUNCTION is not added if already present.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
284 FUNCTION is added (if necessary) at the beginning of the hook list
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
285 unless the optional argument APPEND is non-nil, in which case
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
286 FUNCTION is added at the end.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
287
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
288 The optional fourth argument, LOCAL, if non-nil, says to modify
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
289 the hook's buffer-local value rather than its default value.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
290 This makes no difference if the hook is not buffer-local.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
291 To make a hook variable buffer-local, always use
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
292 `make-local-hook', not `make-local-variable'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
293
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
294 HOOK should be a symbol, and FUNCTION may be any valid function. If
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
295 HOOK is void, it is first set to nil. If HOOK's value is a single
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
296 function, it is changed to a list of functions.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
297
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
298 You can remove this hook yourself using `remove-local-hook'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
299
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
300 See also `add-hook', `add-local-hook', and `add-local-one-shot-hook'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
301 (make-local-hook hook)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
302 (add-one-shot-hook hook function append t))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (defun add-to-list (list-var element)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 The test for presence of ELEMENT is done with `equal'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 If you want to use `add-to-list' on a variable that is not defined
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 until a certain package is loaded, you should put the call to `add-to-list'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 into a hook function that will be run only after loading the package.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 `eval-after-load' provides one way to do this. In some cases
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 other hooks, such as major mode hooks, can do the job."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 (or (member element (symbol-value list-var))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (set list-var (cons element (symbol-value list-var)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 ;; XEmacs additions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 ;; called by Fkill_buffer()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (defvar kill-buffer-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318 "Function or functions to be called when a buffer is killed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 The value of this variable may be buffer-local.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 The buffer about to be killed is current when this hook is run.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 ;; in C in FSFmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 (defvar kill-emacs-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 "Function or functions to be called when `kill-emacs' is called,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 just before emacs is actually killed.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 ;; not obsolete.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 ;; #### These are a bad idea, because the CL RPLACA and RPLACD
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 ;; return the cons cell, not the new CAR/CDR. -hniksic
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 ;; The proper definition would be:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 ;; (defun rplaca (conscell newcar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 ;; (setcar conscell newcar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 ;; conscell)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 ;; ...and analogously for RPLACD.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 (define-function 'rplaca 'setcar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 (define-function 'rplacd 'setcdr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
338 (defun copy-symbol (symbol &optional copy-properties)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
339 "Return a new uninterned symbol with the same name as SYMBOL.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
340 If COPY-PROPERTIES is non-nil, the new symbol will have a copy of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
341 SYMBOL's value, function, and property lists."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
342 (let ((new (make-symbol (symbol-name symbol))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
343 (when copy-properties
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
344 ;; This will not copy SYMBOL's chain of forwarding objects, but
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
345 ;; I think that's OK. Callers should not expect such magic to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
346 ;; keep working in the copy in the first place.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
347 (and (boundp symbol)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
348 (set new (symbol-value symbol)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
349 (and (fboundp symbol)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
350 (fset new (symbol-function symbol)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
351 (setplist new (copy-list (symbol-plist symbol))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
352 new))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
353
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354 ;;;; String functions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (defun replace-in-string (str regexp newtext &optional literal)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
358 "Replace all matches in STR for REGEXP with NEWTEXT string,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 and returns the new string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360 Optional LITERAL non-nil means do a literal replacement.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 Otherwise treat \\ in NEWTEXT string as special:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 \\& means substitute original matched text,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
363 \\N means substitute match for \(...\) number N,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364 \\\\ means insert one \\."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
365 (check-argument-type 'stringp str)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
366 (check-argument-type 'stringp newtext)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
367 (let ((rtn-str "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
368 (start 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
369 (special)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
370 match prev-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
371 (while (setq match (string-match regexp str start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
372 (setq prev-start start
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
373 start (match-end 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
374 rtn-str
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
375 (concat
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
376 rtn-str
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
377 (substring str prev-start match)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
378 (cond (literal newtext)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
379 (t (mapconcat
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
380 (lambda (c)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
381 (if special
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
382 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
383 (setq special nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
384 (cond ((eq c ?\\) "\\")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
385 ((eq c ?&)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
386 (substring str
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
387 (match-beginning 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
388 (match-end 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
389 ((and (>= c ?0) (<= c ?9))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
390 (if (> c (+ ?0 (length
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
391 (match-data))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
392 ;; Invalid match num
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
393 (error "Invalid match num: %c" c)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
394 (setq c (- c ?0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
395 (substring str
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
396 (match-beginning c)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
397 (match-end c))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
398 (t (char-to-string c))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
399 (if (eq c ?\\) (progn (setq special t) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
400 (char-to-string c))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
401 newtext ""))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
402 (concat rtn-str (substring str start))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
403
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
404 (defun split-string (string &optional pattern)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
405 "Return a list of substrings of STRING which are separated by PATTERN.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
406 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
407 (or pattern
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
408 (setq pattern "[ \f\t\n\r\v]+"))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
409 (let (parts (start 0) (len (length string)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
410 (if (string-match pattern string)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
411 (setq parts (cons (substring string 0 (match-beginning 0)) parts)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
412 start (match-end 0)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
413 (while (and (< start len)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
414 (string-match pattern string (if (> start (match-beginning 0))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
415 start
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
416 (1+ start))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
417 (setq parts (cons (substring string start (match-beginning 0)) parts)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
418 start (match-end 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
419 (nreverse (cons (substring string start) parts))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
420
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
421 ;; #### #### #### AAaargh! Must be in C, because it is used insanely
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
422 ;; early in the bootstrap process.
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
423 ;(defun split-path (path)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
424 ; "Explode a search path into a list of strings.
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
425 ;The path components are separated with the characters specified
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
426 ;with `path-separator'."
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
427 ; (while (or (not stringp path-separator)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
428 ; (/= (length path-separator) 1))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
429 ; (setq path-separator (signal 'error (list "\
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
430 ;`path-separator' should be set to a single-character string"
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
431 ; path-separator))))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
432 ; (split-string-by-char path (aref separator 0)))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
433
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 (defmacro with-output-to-string (&rest forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
435 "Collect output to `standard-output' while evaluating FORMS and return
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
436 it as a string."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
437 ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> w/ mods from Stig
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
438 `(with-current-buffer (get-buffer-create
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
439 (generate-new-buffer-name " *string-output*"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
440 (setq buffer-read-only nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
441 (buffer-disable-undo (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
443 (let ((standard-output (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
444 ,@forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
445 (prog1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
446 (buffer-string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
447 (erase-buffer))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
448
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
449 (defmacro with-current-buffer (buffer &rest body)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
450 "Temporarily make BUFFER the current buffer and execute the forms in BODY.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
451 The value returned is the value of the last form in BODY.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
452 See also `with-temp-buffer'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
453 `(save-current-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
454 (set-buffer ,buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
455 ,@body))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
456
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
457 (defmacro with-temp-file (file &rest forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
458 "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
459 The value of the last form in FORMS is returned, like `progn'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
460 See also `with-temp-buffer'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
461 (let ((temp-file (make-symbol "temp-file"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
462 (temp-buffer (make-symbol "temp-buffer")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
463 `(let ((,temp-file ,file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
464 (,temp-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
465 (get-buffer-create (generate-new-buffer-name " *temp file*"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
466 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
467 (prog1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
468 (with-current-buffer ,temp-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
469 ,@forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
470 (with-current-buffer ,temp-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
471 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
472 (write-region (point-min) (point-max) ,temp-file nil 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
473 (and (buffer-name ,temp-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
474 (kill-buffer ,temp-buffer))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
475
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
476 (defmacro with-temp-buffer (&rest forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
477 "Create a temporary buffer, and evaluate FORMS there like `progn'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
478 See also `with-temp-file' and `with-output-to-string'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
479 (let ((temp-buffer (make-symbol "temp-buffer")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
480 `(let ((,temp-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
481 (get-buffer-create (generate-new-buffer-name " *temp*"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
482 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
483 (with-current-buffer ,temp-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
484 ,@forms)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
485 (and (buffer-name ,temp-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
486 (kill-buffer ,temp-buffer))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
487
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
488 ;; Moved from mule-coding.el.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
489 (defmacro with-string-as-buffer-contents (str &rest body)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
490 "With the contents of the current buffer being STR, run BODY.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
491 Returns the new contents of the buffer, as modified by BODY.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
492 The original current buffer is restored afterwards."
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
493 `(with-temp-buffer
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
494 (insert ,str)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
495 ,@body
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
496 (buffer-string)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
497
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
498 (defun insert-face (string face)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
499 "Insert STRING and highlight with FACE. Return the extent created."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
500 (let ((p (point)) ext)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
501 (insert string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
502 (setq ext (make-extent p (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
503 (set-extent-face ext face)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
504 ext))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
505
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
506 ;; not obsolete.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
507 (define-function 'string= 'string-equal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
508 (define-function 'string< 'string-lessp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
509 (define-function 'int-to-string 'number-to-string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
510 (define-function 'string-to-int 'string-to-number)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
511
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
512 ;; These two names are a bit awkward, as they conflict with the normal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
513 ;; foo-to-bar naming scheme, but CLtL2 has them, so they stay.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
514 (define-function 'char-int 'char-to-int)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
515 (define-function 'int-char 'int-to-char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
516
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
517
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
518 ;; alist/plist functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
519 (defun plist-to-alist (plist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
520 "Convert property list PLIST into the equivalent association-list form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
521 The alist is returned. This converts from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
522
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
523 \(a 1 b 2 c 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
524
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
525 into
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
526
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
527 \((a . 1) (b . 2) (c . 3))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
528
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
529 The original plist is not modified. See also `destructive-plist-to-alist'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
530 (let (alist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
531 (while plist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
532 (setq alist (cons (cons (car plist) (cadr plist)) alist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
533 (setq plist (cddr plist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
534 (nreverse alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
535
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
536 (defun destructive-plist-to-alist (plist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
537 "Convert property list PLIST into the equivalent association-list form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
538 The alist is returned. This converts from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
539
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
540 \(a 1 b 2 c 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
541
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
542 into
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
543
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
544 \((a . 1) (b . 2) (c . 3))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
545
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
546 The original plist is destroyed in the process of constructing the alist.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
547 See also `plist-to-alist'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
548 (let ((head plist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
549 next)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
550 (while plist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
551 ;; remember the next plist pair.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
552 (setq next (cddr plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
553 ;; make the cons holding the property value into the alist element.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
554 (setcdr (cdr plist) (cadr plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
555 (setcar (cdr plist) (car plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
556 ;; reattach into alist form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
557 (setcar plist (cdr plist))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
558 (setcdr plist next)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
559 (setq plist next))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
560 head))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
561
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
562 (defun alist-to-plist (alist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
563 "Convert association list ALIST into the equivalent property-list form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
564 The plist is returned. This converts from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
565
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
566 \((a . 1) (b . 2) (c . 3))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
567
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
568 into
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
569
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
570 \(a 1 b 2 c 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
571
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
572 The original alist is not modified. See also `destructive-alist-to-plist'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
573 (let (plist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
574 (while alist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
575 (let ((el (car alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
576 (setq plist (cons (cdr el) (cons (car el) plist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
577 (setq alist (cdr alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
578 (nreverse plist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
579
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
580 ;; getf, remf in cl*.el.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
581
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
582 (defmacro putf (plist prop val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
583 "Add property PROP to plist PLIST with value VAL.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
584 Analogous to (setq PLIST (plist-put PLIST PROP VAL))."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
585 `(setq ,plist (plist-put ,plist ,prop ,val)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
586
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
587 (defmacro laxputf (lax-plist prop val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
588 "Add property PROP to lax plist LAX-PLIST with value VAL.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
589 Analogous to (setq LAX-PLIST (lax-plist-put LAX-PLIST PROP VAL))."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
590 `(setq ,lax-plist (lax-plist-put ,lax-plist ,prop ,val)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
591
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
592 (defmacro laxremf (lax-plist prop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
593 "Remove property PROP from lax plist LAX-PLIST.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
594 Analogous to (setq LAX-PLIST (lax-plist-remprop LAX-PLIST PROP))."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
595 `(setq ,lax-plist (lax-plist-remprop ,lax-plist ,prop)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
596
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
597 ;;; Error functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
598
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
599 (defun error (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
600 "Signal an error, making error message by passing all args to `format'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
601 This error is not continuable: you cannot continue execution after the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
602 error using the debugger `r' command. See also `cerror'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
603 (while t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
604 (apply 'cerror args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
605
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
606 (defun cerror (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
607 "Like `error' but signals a continuable error."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
608 (signal 'error (list (apply 'format args))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
609
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
610 (defmacro check-argument-type (predicate argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
611 "Check that ARGUMENT satisfies PREDICATE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
612 If not, signal a continuable `wrong-type-argument' error until the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
613 returned value satisfies PREDICATE, and assign the returned value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
614 to ARGUMENT."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
615 `(if (not (,(eval predicate) ,argument))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
616 (setq ,argument
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
617 (wrong-type-argument ,predicate ,argument))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
618
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
619 (defun signal-error (error-symbol data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
620 "Signal a non-continuable error. Args are ERROR-SYMBOL, and associated DATA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
621 An error symbol is a symbol defined using `define-error'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
622 DATA should be a list. Its elements are printed as part of the error message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
623 If the signal is handled, DATA is made available to the handler.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
624 See also `signal', and the functions to handle errors: `condition-case'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
625 and `call-with-condition-handler'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
626 (while t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
627 (signal error-symbol data)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
628
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
629 (defun define-error (error-sym doc-string &optional inherits-from)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
630 "Define a new error, denoted by ERROR-SYM.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
631 DOC-STRING is an informative message explaining the error, and will be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
632 printed out when an unhandled error occurs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
633 ERROR-SYM is a sub-error of INHERITS-FROM (which defaults to `error').
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
634
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
635 \[`define-error' internally works by putting on ERROR-SYM an `error-message'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
636 property whose value is DOC-STRING, and an `error-conditions' property
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
637 that is a list of ERROR-SYM followed by each of its super-errors, up
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
638 to and including `error'. You will sometimes see code that sets this up
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
639 directly rather than calling `define-error', but you should *not* do this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
640 yourself.]"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
641 (check-argument-type 'symbolp error-sym)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
642 (check-argument-type 'stringp doc-string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
643 (put error-sym 'error-message doc-string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
644 (or inherits-from (setq inherits-from 'error))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
645 (let ((conds (get inherits-from 'error-conditions)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
646 (or conds (signal-error 'error (list "Not an error symbol" error-sym)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
647 (put error-sym 'error-conditions (cons error-sym conds))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
648
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
649 ;;;; Miscellanea.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
650
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
651 ;; This is now in C.
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
652 ;(defun buffer-substring-no-properties (beg end)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
653 ; "Return the text from BEG to END, without text properties, as a string."
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
654 ; (let ((string (buffer-substring beg end)))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
655 ; (set-text-properties 0 (length string) nil string)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 371
diff changeset
656 ; string))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
657
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
658 (defun get-buffer-window-list (&optional buffer minibuf frame)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
659 "Return windows currently displaying BUFFER, or nil if none.
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
660 BUFFER defaults to the current buffer.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
661 See `walk-windows' for the meaning of MINIBUF and FRAME."
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
662 (cond ((null buffer)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
663 (setq buffer (current-buffer)))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
664 ((not (bufferp buffer))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
665 (setq buffer (get-buffer buffer))))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
666 (let (windows)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
667 (walk-windows (lambda (window)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
668 (if (eq (window-buffer window) buffer)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 272
diff changeset
669 (push window windows)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
670 minibuf frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
671 windows))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
672
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
673 (defun ignore (&rest ignore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
674 "Do nothing and return nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
675 This function accepts any number of arguments, but ignores them."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
676 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
677 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
678
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
679 (define-function 'eval-in-buffer 'with-current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
680 (make-obsolete 'eval-in-buffer 'with-current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
681
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
682 ;;; The real defn is in abbrev.el but some early callers
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
683 ;;; (eg lisp-mode-abbrev-table) want this before abbrev.el is loaded...
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
684
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
685 (if (not (fboundp 'define-abbrev-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
686 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
687 (setq abbrev-table-name-list '())
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
688 (fset 'define-abbrev-table (function (lambda (name defs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
689 ;; These are fixed-up when abbrev.el loads.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
690 (setq abbrev-table-name-list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
691 (cons (cons name defs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
692 abbrev-table-name-list)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
693
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
694 ;;; `functionp' has been moved into C.
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
695
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
696 ;;(defun functionp (object)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
697 ;; "Non-nil if OBJECT can be called as a function."
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
698 ;; (or (and (symbolp object) (fboundp object))
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
699 ;; (subrp object)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
700 ;; (compiled-function-p object)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
701 ;; (eq (car-safe object) 'lambda)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
702
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
703
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
704
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
705 (defun function-interactive (function)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
706 "Return the interactive specification of FUNCTION.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
707 FUNCTION can be any funcallable object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
708 The specification will be returned as the list of the symbol `interactive'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
709 and the specs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
710 If FUNCTION is not interactive, nil will be returned."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
711 (setq function (indirect-function function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
712 (cond ((compiled-function-p function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
713 (compiled-function-interactive function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
714 ((subrp function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
715 (subr-interactive function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
716 ((eq (car-safe function) 'lambda)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
717 (let ((spec (if (stringp (nth 2 function))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
718 (nth 3 function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
719 (nth 2 function))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
720 (and (eq (car-safe spec) 'interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
721 spec)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
722 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
723 (error "Non-funcallable object: %s" function))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
724
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
725 (defun function-allows-args (function n)
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
726 "Return whether FUNCTION can be called with N arguments."
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
727 (and (<= (function-min-args function) n)
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
728 (or (null (function-max-args function))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
729 (<= n (function-max-args function)))))
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 404
diff changeset
730
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
731 ;; This function used to be an alias to `buffer-substring', except
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
732 ;; that FSF Emacs 20.4 added a BUFFER argument in an incompatible way.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
733 ;; The new FSF's semantics makes more sense, but we try to support
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
734 ;; both for backward compatibility.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
735 (defun buffer-string (&optional buffer old-end old-buffer)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
736 "Return the contents of the current buffer as a string.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
737 If narrowing is in effect, this function returns only the visible part
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
738 of the buffer.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
739
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
740 If BUFFER is specified, the contents of that buffer are returned.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
741
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
742 The arguments OLD-END and OLD-BUFFER are supported for backward
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
743 compatibility with pre-21.2 XEmacsen times when arguments to this
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
744 function were (buffer-string &optional START END BUFFER)."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
745 (cond
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
746 ((or (stringp buffer) (bufferp buffer))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
747 ;; Most definitely the new way.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
748 (buffer-substring nil nil buffer))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
749 ((or (stringp old-buffer) (bufferp old-buffer)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
750 (natnump buffer) (natnump old-end))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
751 ;; Definitely the old way.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
752 (buffer-substring buffer old-end old-buffer))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
753 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
754 ;; Probably the old way.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
755 (buffer-substring buffer old-end old-buffer))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
756
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
757 ;; This was not present before. I think Jamie had some objections
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
758 ;; to this, so I'm leaving this undefined for now. --ben
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
759
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
760 ;;; The objection is this: there is more than one way to load the same file.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
761 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
762 ;;; ways to load the exact same code. `eval-after-load' is too stupid to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
763 ;;; deal with this sort of thing. If this sort of feature is desired, then
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
764 ;;; it should work off of a hook on `provide'. Features are unique and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
765 ;;; the arguments to (load) are not. --Stig
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
766
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
767 ;; We provide this for FSFmacs compatibility, at least until we devise
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
768 ;; something better.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
769
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
770 ;;;; Specifying things to do after certain files are loaded.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
771
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
772 (defun eval-after-load (file form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
773 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
774 This makes or adds to an entry on `after-load-alist'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
775 If FILE is already loaded, evaluate FORM right now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
776 It does nothing if FORM is already on the list for FILE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
777 FILE should be the name of a library, with no directory name."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
778 ;; Make sure there is an element for FILE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
779 (or (assoc file after-load-alist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
780 (setq after-load-alist (cons (list file) after-load-alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
781 ;; Add FORM to the element if it isn't there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
782 (let ((elt (assoc file after-load-alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
783 (or (member form (cdr elt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
784 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
785 (nconc elt (list form))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
786 ;; If the file has been loaded already, run FORM right away.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
787 (and (assoc file load-history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
788 (eval form)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
789 form)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
790 (make-compatible 'eval-after-load "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
791
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
792 (defun eval-next-after-load (file)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
793 "Read the following input sexp, and run it whenever FILE is loaded.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
794 This makes or adds to an entry on `after-load-alist'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
795 FILE should be the name of a library, with no directory name."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
796 (eval-after-load file (read)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
797 (make-compatible 'eval-next-after-load "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
798
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
799 ; alternate names (not obsolete)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
800 (if (not (fboundp 'mod)) (define-function 'mod '%))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
801 (define-function 'move-marker 'set-marker)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
802 (define-function 'beep 'ding) ; preserve lingual purity
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
803 (define-function 'indent-to-column 'indent-to)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
804 (define-function 'backward-delete-char 'delete-backward-char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
805 (define-function 'search-forward-regexp (symbol-function 're-search-forward))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
806 (define-function 'search-backward-regexp (symbol-function 're-search-backward))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
807 (define-function 'remove-directory 'delete-directory)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
808 (define-function 'set-match-data 'store-match-data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
809 (define-function 'send-string-to-terminal 'external-debugging-output)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
810
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
811 ;;; subr.el ends here