Mercurial > hg > xemacs-beta
comparison lisp/subr.el @ 1333:1b0339b048ce
[xemacs-hg @ 2003-03-02 09:38:37 by ben]
To: xemacs-patches@xemacs.org
PROBLEMS: Include nt/PROBLEMS and update. Add note about incremental
linking badness.
cmdloop.el, custom.el, dumped-lisp.el, files.el, keydefs.el, keymap.el, lisp-mode.el, make-docfile.el, replace.el, simple.el, subr.el, view-less.el, wid-edit.el: Lots of syncing with FSF 21.2.
Use if-fboundp in wid-edit.el.
New file newcomment.el from FSF.
internals/internals.texi: Fix typo.
(Build-Time Dependencies): New node.
PROBLEMS: Delete.
config.inc.samp, xemacs.mak: Eliminate HAVE_VC6, use SUPPORT_EDIT_AND_CONTINUE in its place.
No incremental linking unless SUPPORT_EDIT_AND_CONTINUE, since it
can cause nasty crashes in pdump. Put warnings about this in
config.inc.samp. Report the full compile flags used for src
and lib-src in the Installation output.
alloc.c, lisp.h, ralloc.c, regex.c: Use ALLOCA() in regex.c to avoid excessive stack allocation.
Also fix subtle problem with REL_ALLOC() -- any call to malloc()
(direct or indirect) may relocate rel-alloced data, causing
buffer text to shift. After any such call, regex must update
all its pointers to such data. Add a system, when
ERROR_CHECK_MALLOC, whereby regex.c indicates all the places
it is prepared to handle malloc()/realloc()/free(), and any
calls anywhere in XEmacs outside of this will trigger an abort.
alloc.c, dialog-msw.c, eval.c, event-stream.c, general-slots.h, insdel.c, lisp.h, menubar-msw.c, menubar-x.c: Change *run_hook*_trapping_problems to take a warning class, not
a string. Factor out code to issue warnings, add flag to
call_trapping_problems() to postpone warning issue, and make
*run_hook*_trapping_problems issue their own warnings tailored
to the hook, postponed in the case of safe_run_hook_trapping_problems()
so that the appropriate message can be issued about resetting to
nil only when not `quit'. Make record_unwind_protect_restoring_int()
non-static.
dumper.c: Issue notes about incremental linking problems under Windows.
fileio.c: Mule-ize encrypt/decrypt-string code.
text.h: Spacing changes.
author | ben |
---|---|
date | Sun, 02 Mar 2003 09:38:54 +0000 |
parents | 3a01f3148bff |
children | c9b6a2fec10d |
comparison
equal
deleted
inserted
replaced
1332:6aa23bb3da6b | 1333:1b0339b048ce |
---|---|
1 ;;; subr.el --- basic lisp subroutines for XEmacs | 1 ;;; subr.el --- basic lisp subroutines for XEmacs |
2 | 2 |
3 ;; Copyright (C) 1985, 1986, 1992, 1994-5, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1986, 1992, 1994-5, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. | 4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. |
5 ;; Copyright (C) 1995 Sun Microsystems. | 5 ;; Copyright (C) 1995 Sun Microsystems. |
6 ;; Copyright (C) 2000, 2001, 2002 Ben Wing. | 6 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing. |
7 | 7 |
8 ;; Maintainer: XEmacs Development Team | 8 ;; Maintainer: XEmacs Development Team |
9 ;; Keywords: extensions, dumped | 9 ;; Keywords: extensions, dumped |
10 | 10 |
11 ;; This file is part of XEmacs. | 11 ;; This file is part of XEmacs. |
23 ;; You should have received a copy of the GNU General Public License | 23 ;; You should have received a copy of the GNU General Public License |
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 24 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
26 ;; 02111-1307, USA. | 26 ;; 02111-1307, USA. |
27 | 27 |
28 ;;; Synched up with: FSF 19.34. | 28 ;;; Synched up with: FSF 19.34. Some things synched up with later versions. |
29 | 29 |
30 ;;; Commentary: | 30 ;;; Commentary: |
31 | 31 |
32 ;; This file is dumped with XEmacs. | 32 ;; This file is dumped with XEmacs. |
33 | 33 |
34 ;; There's not a whole lot in common now with the FSF version, | 34 ;; There's not a whole lot in common now with the FSF version, |
35 ;; be wary when applying differences. I've left in a number of lines | 35 ;; be wary when applying differences. I've left in a number of lines |
36 ;; of commentary just to give diff(1) something to synch itself with to | 36 ;; of commentary just to give diff(1) something to synch itself with to |
37 ;; provide useful context diffs. -sb | 37 ;; provide useful context diffs. -sb |
38 | 38 |
39 ;; BEGIN SYNCHED WITH FSF 21.2 | |
40 | |
39 ;;; Code: | 41 ;;; Code: |
40 | 42 (defvar custom-declare-variable-list nil |
43 "Record `defcustom' calls made before `custom.el' is loaded to handle them. | |
44 Each element of this list holds the arguments to one call to `defcustom'.") | |
45 | |
46 ;; Use this, rather than defcustom, in subr.el and other files loaded | |
47 ;; before custom.el. | |
48 (defun custom-declare-variable-early (&rest arguments) | |
49 (setq custom-declare-variable-list | |
50 (cons arguments custom-declare-variable-list))) | |
41 | 51 |
42 ;;;; Lisp language features. | 52 ;;;; Lisp language features. |
43 | 53 |
44 (defmacro lambda (&rest cdr) | 54 (defmacro lambda (&rest cdr) |
45 "Return a lambda expression. | 55 "Return a lambda expression. |
56 INTERACTIVE should be a call to the function `interactive', which see. | 66 INTERACTIVE should be a call to the function `interactive', which see. |
57 It may also be omitted. | 67 It may also be omitted. |
58 BODY should be a list of lisp expressions." | 68 BODY should be a list of lisp expressions." |
59 `(function (lambda ,@cdr))) | 69 `(function (lambda ,@cdr))) |
60 | 70 |
71 ;; FSF 21.2 has various basic macros here. We don't because they're either | |
72 ;; in cl*.el (which we dump and hence is always available) or built-in. | |
73 | |
74 ;; More powerful versions in cl.el. | |
75 ;(defmacro push (newelt listname) | |
76 ;(defmacro pop (listname) | |
77 | |
78 ;; Built-in. | |
79 ;(defmacro when (cond &rest body) | |
80 ;(defmacro unless (cond &rest body) | |
81 | |
82 ;; More powerful versions in cl-macs.el. | |
83 ;(defmacro dolist (spec &rest body) | |
84 ;(defmacro dotimes (spec &rest body) | |
85 | |
86 ;; In cl.el. Ours are defun, but cl arranges for them to be inlined anyway. | |
87 ;(defsubst caar (x) | |
88 ;(defsubst cadr (x) | |
89 ;(defsubst cdar (x) | |
90 ;(defsubst cddr (x) | |
91 | |
92 ;; Built-in. Our `last' is more powerful in that it handles circularity. | |
93 ;(defun last (x &optional n) | |
94 ;(defun butlast (x &optional n) | |
95 ;(defun nbutlast (x &optional n) | |
96 | |
97 ;; In cl-seq.el. | |
98 ;(defun remove (elt seq) | |
99 ;(defun remq (elt list) | |
100 | |
61 (defmacro defun-when-void (&rest args) | 101 (defmacro defun-when-void (&rest args) |
62 "Define a function, just like `defun', unless it's already defined. | 102 "Define a function, just like `defun', unless it's already defined. |
63 Used for compatibility among different emacs variants." | 103 Used for compatibility among different emacs variants." |
64 `(if (fboundp ',(car args)) | 104 `(if (fboundp ',(car args)) |
65 nil | 105 nil |
71 `(if (fboundp ,(car args)) | 111 `(if (fboundp ,(car args)) |
72 nil | 112 nil |
73 (define-function ,@args))) | 113 (define-function ,@args))) |
74 | 114 |
75 | 115 |
116 (defun assoc-default (key alist &optional test default) | |
117 "Find object KEY in a pseudo-alist ALIST. | |
118 ALIST is a list of conses or objects. Each element (or the element's car, | |
119 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY). | |
120 If that is non-nil, the element matches; | |
121 then `assoc-default' returns the element's cdr, if it is a cons, | |
122 or DEFAULT if the element is not a cons. | |
123 | |
124 If no element matches, the value is nil. | |
125 If TEST is omitted or nil, `equal' is used." | |
126 (let (found (tail alist) value) | |
127 (while (and tail (not found)) | |
128 (let ((elt (car tail))) | |
129 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) | |
130 (setq found t value (if (consp elt) (cdr elt) default)))) | |
131 (setq tail (cdr tail))) | |
132 value)) | |
133 | |
134 (defun assoc-ignore-case (key alist) | |
135 "Like `assoc', but ignores differences in case and text representation. | |
136 KEY must be a string. Upper-case and lower-case letters are treated as equal." | |
137 (let (element) | |
138 (while (and alist (not element)) | |
139 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil t)) | |
140 (setq element (car alist))) | |
141 (setq alist (cdr alist))) | |
142 element)) | |
143 | |
144 (defun assoc-ignore-representation (key alist) | |
145 "Like `assoc', but ignores differences in text representation. | |
146 KEY must be a string." | |
147 (let (element) | |
148 (while (and alist (not element)) | |
149 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil)) | |
150 (setq element (car alist))) | |
151 (setq alist (cdr alist))) | |
152 element)) | |
153 | |
154 (defun member-ignore-case (elt list) | |
155 "Like `member', but ignores differences in case and text representation. | |
156 ELT must be a string. Upper-case and lower-case letters are treated as equal." | |
157 (while (and list (not (eq t (compare-strings elt 0 nil (car list) 0 nil t)))) | |
158 (setq list (cdr list))) | |
159 list) | |
160 | |
161 | |
76 ;;;; Keymap support. | 162 ;;;; Keymap support. |
77 ;; XEmacs: removed to keymap.el | 163 ;; XEmacs: removed to keymap.el |
78 | 164 |
79 ;;;; The global keymap tree. | 165 ;;;; The global keymap tree. |
80 | 166 |
83 | 169 |
84 ;;;; Event manipulation functions. | 170 ;;;; Event manipulation functions. |
85 | 171 |
86 ;; XEmacs: This stuff is done in C Code. | 172 ;; XEmacs: This stuff is done in C Code. |
87 | 173 |
88 ;;;; Obsolescent names for functions. | 174 ;;;; Obsolescent names for functions generally appear elsewhere, in |
89 ;; XEmacs: not used. | 175 ;;;; obsolete.el or in the files they are related do. Many very old |
176 ;;;; obsolete stuff has been removed entirely (e.g. anything with `dot' in | |
177 ;;;; place of `point'). | |
178 | |
179 ; alternate names (not obsolete) | |
180 (if (not (fboundp 'mod)) (define-function 'mod '%)) | |
181 (define-function 'move-marker 'set-marker) | |
182 (define-function 'beep 'ding) ; preserve lingual purity | |
183 (define-function 'indent-to-column 'indent-to) | |
184 (define-function 'backward-delete-char 'delete-backward-char) | |
185 (define-function 'search-forward-regexp (symbol-function 're-search-forward)) | |
186 (define-function 'search-backward-regexp (symbol-function 're-search-backward)) | |
187 (define-function 'remove-directory 'delete-directory) | |
188 (define-function 'set-match-data 'store-match-data) | |
189 (define-function 'send-string-to-terminal 'external-debugging-output) | |
90 | 190 |
91 ;; XEmacs: | 191 ;; XEmacs: |
92 (defun local-variable-if-set-p (sym buffer) | 192 (defun local-variable-if-set-p (sym buffer) |
93 "Return t if SYM would be local to BUFFER after it is set. | 193 "Return t if SYM would be local to BUFFER after it is set. |
94 A nil value for BUFFER is *not* the same as (current-buffer), but | 194 A nil value for BUFFER is *not* the same as (current-buffer), but |
101 | 201 |
102 ;; (defconst run-hooks 'run-hooks ...) | 202 ;; (defconst run-hooks 'run-hooks ...) |
103 | 203 |
104 (defun make-local-hook (hook) | 204 (defun make-local-hook (hook) |
105 "Make the hook HOOK local to the current buffer. | 205 "Make the hook HOOK local to the current buffer. |
206 The return value is HOOK. | |
207 | |
208 You never need to call this function now that `add-hook' does it for you | |
209 if its LOCAL argument is non-nil. | |
210 | |
106 When a hook is local, its local and global values | 211 When a hook is local, its local and global values |
107 work in concert: running the hook actually runs all the hook | 212 work in concert: running the hook actually runs all the hook |
108 functions listed in *either* the local value *or* the global value | 213 functions listed in *either* the local value *or* the global value |
109 of the hook variable. | 214 of the hook variable. |
110 | 215 |
116 one. | 221 one. |
117 | 222 |
118 This function does nothing if HOOK is already local in the current | 223 This function does nothing if HOOK is already local in the current |
119 buffer. | 224 buffer. |
120 | 225 |
121 Do not use `make-local-variable' to make a hook variable buffer-local. | 226 Do not use `make-local-variable' to make a hook variable buffer-local." |
122 | |
123 See also `add-local-hook' and `remove-local-hook'." | |
124 (if (local-variable-p hook (current-buffer)) ; XEmacs | 227 (if (local-variable-p hook (current-buffer)) ; XEmacs |
125 nil | 228 nil |
126 (or (boundp hook) (set hook nil)) | 229 (or (boundp hook) (set hook nil)) |
127 (make-local-variable hook) | 230 (make-local-variable hook) |
128 (set hook (list t)))) | 231 (set hook (list t))) |
232 hook) | |
129 | 233 |
130 (defun add-hook (hook function &optional append local) | 234 (defun add-hook (hook function &optional append local) |
131 "Add to the value of HOOK the function FUNCTION. | 235 "Add to the value of HOOK the function FUNCTION. |
132 FUNCTION is not added if already present. | 236 FUNCTION is not added if already present. |
133 FUNCTION is added (if necessary) at the beginning of the hook list | 237 FUNCTION is added (if necessary) at the beginning of the hook list |
134 unless the optional argument APPEND is non-nil, in which case | 238 unless the optional argument APPEND is non-nil, in which case |
135 FUNCTION is added at the end. | 239 FUNCTION is added at the end. |
136 | 240 |
137 The optional fourth argument, LOCAL, if non-nil, says to modify | 241 The optional fourth argument, LOCAL, if non-nil, says to modify |
138 the hook's buffer-local value rather than its default value. | 242 the hook's buffer-local value rather than its default value. |
139 This makes no difference if the hook is not buffer-local. | 243 This makes the hook buffer-local if needed. |
140 To make a hook variable buffer-local, always use | 244 To make a hook variable buffer-local, always use |
141 `make-local-hook', not `make-local-variable'. | 245 `make-local-hook', not `make-local-variable'. |
142 | 246 |
143 HOOK should be a symbol, and FUNCTION may be any valid function. If | 247 HOOK should be a symbol, and FUNCTION may be any valid function. If |
144 HOOK is void, it is first set to nil. If HOOK's value is a single | 248 HOOK is void, it is first set to nil. If HOOK's value is a single |
145 function, it is changed to a list of functions. | 249 function, it is changed to a list of functions. |
146 | 250 |
147 You can remove this hook yourself using `remove-hook'. | 251 You can remove this hook yourself using `remove-hook'. |
148 | 252 |
149 See also `add-local-hook' and `add-one-shot-hook'." | 253 See also `add-one-shot-hook'." |
150 (or (boundp hook) (set hook nil)) | 254 (or (boundp hook) (set hook nil)) |
151 (or (default-boundp hook) (set-default hook nil)) | 255 (or (default-boundp hook) (set-default hook nil)) |
152 ;; If the hook value is a single function, turn it into a list. | 256 (if local (unless (local-variable-if-set-p hook (current-buffer)) ; XEmacs |
153 (let ((old (symbol-value hook))) | 257 (make-local-hook hook)) |
154 (if (or (not (listp old)) (eq (car old) 'lambda)) | 258 ;; Detect the case where make-local-variable was used on a hook |
155 (set hook (list old)))) | 259 ;; and do what we used to do. |
156 (if (or local | 260 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) |
157 ;; Detect the case where make-local-variable was used on a hook | 261 (setq local t))) |
158 ;; and do what we used to do. | 262 (let ((hook-value (if local (symbol-value hook) (default-value hook)))) |
159 (and (local-variable-if-set-p hook (current-buffer)) ; XEmacs | 263 ;; If the hook value is a single function, turn it into a list. |
160 (not (memq t (symbol-value hook))))) | 264 (when (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) |
161 ;; Alter the local value only. | 265 (setq hook-value (list hook-value))) |
162 (or (if (consp function) | 266 ;; Do the actual addition if necessary |
163 (member function (symbol-value hook)) | 267 (unless (member function hook-value) |
164 (memq function (symbol-value hook))) | 268 (setq hook-value |
165 (set hook | 269 (if append |
166 (if append | 270 (append hook-value (list function)) |
167 (append (symbol-value hook) (list function)) | 271 (cons function hook-value)))) |
168 (cons function (symbol-value hook))))) | 272 ;; Set the actual variable |
169 ;; Alter the global value (which is also the only value, | 273 (if local (set hook hook-value) (set-default hook hook-value)))) |
170 ;; if the hook doesn't have a local value). | |
171 (or (if (consp function) | |
172 (member function (default-value hook)) | |
173 (memq function (default-value hook))) | |
174 (set-default hook | |
175 (if append | |
176 (append (default-value hook) (list function)) | |
177 (cons function (default-value hook))))))) | |
178 | 274 |
179 (defun remove-hook (hook function &optional local) | 275 (defun remove-hook (hook function &optional local) |
180 "Remove from the value of HOOK the function FUNCTION. | 276 "Remove from the value of HOOK the function FUNCTION. |
181 HOOK should be a symbol, and FUNCTION may be any valid function. If | 277 HOOK should be a symbol, and FUNCTION may be any valid function. If |
182 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | 278 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the |
183 list of hooks to run in HOOK, then nothing is done. See `add-hook'. | 279 list of hooks to run in HOOK, then nothing is done. See `add-hook'. |
184 | 280 |
185 The optional third argument, LOCAL, if non-nil, says to modify | 281 The optional third argument, LOCAL, if non-nil, says to modify |
186 the hook's buffer-local value rather than its default value. | 282 the hook's buffer-local value rather than its default value. |
187 This makes no difference if the hook is not buffer-local. | 283 This makes the hook buffer-local if needed. |
188 To make a hook variable buffer-local, always use | 284 To make a hook variable buffer-local, always use |
189 `make-local-hook', not `make-local-variable'." | 285 `make-local-hook', not `make-local-variable'." |
190 (if (or (not (boundp hook)) ;unbound symbol, or | 286 (or (boundp hook) (set hook nil)) |
191 (not (default-boundp 'hook)) | 287 (or (default-boundp hook) (set-default hook nil)) |
192 (null (symbol-value hook)) ;value is nil, or | 288 (if local (unless (local-variable-if-set-p hook (current-buffer)) ; XEmacs |
193 (null function)) ;function is nil, then | 289 (make-local-hook hook)) |
194 nil ;Do nothing. | 290 ;; Detect the case where make-local-variable was used on a hook |
195 (flet ((hook-remove | 291 ;; and do what we used to do. |
196 (function hook-value) | 292 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) |
197 (flet ((hook-test | 293 (setq local t))) |
198 (fn hel) | 294 (let ((hook-value (if local (symbol-value hook) (default-value hook)))) |
199 (or (equal fn hel) | 295 ;; Remove the function, for both the list and the non-list cases. |
200 (and (symbolp hel) | 296 ;; XEmacs: add hook-test, for handling one-shot hooks. |
201 (equal fn | 297 (flet ((hook-test |
202 (get hel 'one-shot-hook-fun)))))) | 298 (fn hel) |
203 (if (and (consp hook-value) | 299 (or (equal fn hel) |
204 (not (functionp hook-value))) | 300 (and (symbolp hel) |
205 (if (member* function hook-value :test 'hook-test) | 301 (equal fn |
206 (setq hook-value | 302 (get hel 'one-shot-hook-fun)))))) |
207 (delete* function (copy-sequence hook-value) | 303 (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) |
208 :test 'hook-test))) | 304 (if (equal hook-value function) (setq hook-value nil)) |
209 (if (equal hook-value function) | 305 (setq hook-value (delete* function (copy-sequence hook-value) |
210 (setq hook-value nil))) | 306 :test 'hook-test))) |
211 hook-value))) | 307 ;; If the function is on the global hook, we need to shadow it locally |
212 (if (or local | 308 ;;(when (and local (member* function (default-value hook) |
213 ;; Detect the case where make-local-variable was used on a hook | 309 ;; :test 'hook-test) |
214 ;; and do what we used to do. | 310 ;; (not (member* (cons 'not function) hook-value |
215 (and (local-variable-p hook (current-buffer)) | 311 ;; :test 'hook-test))) |
216 (not (memq t (symbol-value hook))))) | 312 ;; (push (cons 'not function) hook-value)) |
217 (set hook (hook-remove function (symbol-value hook))) | 313 ;; Set the actual variable |
218 (set-default hook (hook-remove function (default-value hook))))))) | 314 (if local (set hook hook-value) (set-default hook hook-value))))) |
219 | 315 |
220 ;; XEmacs addition | 316 ;; XEmacs addition |
221 ;; #### we need a coherent scheme for indicating compatibility info, | 317 ;; #### we need a coherent scheme for indicating compatibility info, |
222 ;; so that it can be programmatically retrieved. | 318 ;; so that it can be programmatically retrieved. |
223 (defun add-local-hook (hook function &optional append) | 319 (defun add-local-hook (hook function &optional append) |
224 "Add to the local value of HOOK the function FUNCTION. | 320 "Add to the local value of HOOK the function FUNCTION. |
225 This modifies only the buffer-local value for the hook (which is | 321 You don't need this any more. It's equivalent to specifying the LOCAL |
226 automatically make buffer-local, if necessary), not its default value. | 322 argument to `add-hook'." |
227 FUNCTION is not added if already present. | |
228 FUNCTION is added (if necessary) at the beginning of the hook list | |
229 unless the optional argument APPEND is non-nil, in which case | |
230 FUNCTION is added at the end. | |
231 | |
232 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
233 HOOK is void, it is first set to nil. If HOOK's value is a single | |
234 function, it is changed to a list of functions. | |
235 | |
236 You can remove this hook yourself using `remove-local-hook'. | |
237 | |
238 See also `add-hook' and `make-local-hook'." | |
239 (make-local-hook hook) | |
240 (add-hook hook function append t)) | 323 (add-hook hook function append t)) |
241 | 324 |
242 ;; XEmacs addition | 325 ;; XEmacs addition |
243 (defun remove-local-hook (hook function) | 326 (defun remove-local-hook (hook function) |
244 "Remove from the local value of HOOK the function FUNCTION. | 327 "Remove from the local value of HOOK the function FUNCTION. |
245 This modifies only the buffer-local value for the hook, not its default | 328 You don't need this any more. It's equivalent to specifying the LOCAL |
246 value. (Nothing happens if the hook is not buffer-local.) | 329 argument to `remove-hook'." |
247 HOOK should be a symbol, and FUNCTION may be any valid function. If | 330 (remove-hook hook function t)) |
248 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | |
249 list of hooks to run in HOOK, then nothing is done. See `add-hook'. | |
250 | |
251 See also `add-local-hook' and `make-local-hook'." | |
252 (if (local-variable-p hook (current-buffer)) | |
253 (remove-hook hook function t))) | |
254 | 331 |
255 (defun add-one-shot-hook (hook function &optional append local) | 332 (defun add-one-shot-hook (hook function &optional append local) |
256 "Add to the value of HOOK the one-shot function FUNCTION. | 333 "Add to the value of HOOK the one-shot function FUNCTION. |
257 FUNCTION will automatically be removed from the hook the first time | 334 FUNCTION will automatically be removed from the hook the first time |
258 after it runs (whether to completion or to an error). | 335 after it runs (whether to completion or to an error). |
265 HOOK is void, it is first set to nil. If HOOK's value is a single | 342 HOOK is void, it is first set to nil. If HOOK's value is a single |
266 function, it is changed to a list of functions. | 343 function, it is changed to a list of functions. |
267 | 344 |
268 You can remove this hook yourself using `remove-hook'. | 345 You can remove this hook yourself using `remove-hook'. |
269 | 346 |
270 See also `add-hook', `add-local-hook', and `add-local-one-shot-hook'." | 347 See also `add-hook'." |
271 (let ((sym (gensym))) | 348 (let ((sym (gensym))) |
272 (fset sym `(lambda (&rest args) | 349 (fset sym `(lambda (&rest args) |
273 (unwind-protect | 350 (unwind-protect |
274 (apply ',function args) | 351 (apply ',function args) |
275 (remove-hook ',hook ',sym ',local)))) | 352 (remove-hook ',hook ',sym ',local)))) |
276 (put sym 'one-shot-hook-fun function) | 353 (put sym 'one-shot-hook-fun function) |
277 (add-hook hook sym append local))) | 354 (add-hook hook sym append local))) |
278 | 355 |
279 (defun add-local-one-shot-hook (hook function &optional append) | 356 (defun add-local-one-shot-hook (hook function &optional append) |
280 "Add to the local value of HOOK the one-shot function FUNCTION. | 357 "Add to the local value of HOOK the one-shot function FUNCTION. |
281 FUNCTION will automatically be removed from the hook the first time | 358 You don't need this any more. It's equivalent to specifying the LOCAL |
282 after it runs (whether to completion or to an error). | 359 argument to `add-one-shot-hook'." |
283 FUNCTION is not added if already present. | |
284 FUNCTION is added (if necessary) at the beginning of the hook list | |
285 unless the optional argument APPEND is non-nil, in which case | |
286 FUNCTION is added at the end. | |
287 | |
288 The optional fourth argument, LOCAL, if non-nil, says to modify | |
289 the hook's buffer-local value rather than its default value. | |
290 This makes no difference if the hook is not buffer-local. | |
291 To make a hook variable buffer-local, always use | |
292 `make-local-hook', not `make-local-variable'. | |
293 | |
294 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
295 HOOK is void, it is first set to nil. If HOOK's value is a single | |
296 function, it is changed to a list of functions. | |
297 | |
298 You can remove this hook yourself using `remove-local-hook'. | |
299 | |
300 See also `add-hook', `add-local-hook', and `add-local-one-shot-hook'." | |
301 (make-local-hook hook) | |
302 (add-one-shot-hook hook function append t)) | 360 (add-one-shot-hook hook function append t)) |
303 | 361 |
304 (defun add-to-list (list-var element &optional append) | 362 (defun add-to-list (list-var element &optional append) |
305 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. | 363 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. |
306 The test for presence of ELEMENT is done with `equal'. | 364 The test for presence of ELEMENT is done with `equal'. |
317 (symbol-value list-var) | 375 (symbol-value list-var) |
318 (set list-var | 376 (set list-var |
319 (if append | 377 (if append |
320 (append (symbol-value list-var) (list element)) | 378 (append (symbol-value list-var) (list element)) |
321 (cons element (symbol-value list-var)))))) | 379 (cons element (symbol-value list-var)))))) |
380 | |
381 ;; END SYNCHED WITH FSF 21.2 | |
322 | 382 |
323 ;; XEmacs additions | 383 ;; XEmacs additions |
324 ;; called by Fkill_buffer() | 384 ;; called by Fkill_buffer() |
325 (defvar kill-buffer-hook nil | 385 (defvar kill-buffer-hook nil |
326 "Function or functions to be called when a buffer is killed. | 386 "Function or functions to be called when a buffer is killed. |
366 | 426 |
367 NOTE: At some point, this will be moved into C and will be very fast." | 427 NOTE: At some point, this will be moved into C and will be very fast." |
368 (with-current-buffer buffer | 428 (with-current-buffer buffer |
369 (set sym val))) | 429 (set sym val))) |
370 | 430 |
371 ;;;; String functions. | 431 |
372 | 432 ;; BEGIN SYNCHED WITH FSF 21.2 |
373 ;; XEmacs | 433 |
374 (defun string-equal-ignore-case (str1 str2) | 434 ;; #### #### #### AAaargh! Must be in C, because it is used insanely |
375 "Return t if two strings have identical contents, ignoring case differences. | 435 ;; early in the bootstrap process. |
376 Case is not significant. Text properties and extents are ignored. | 436 ;(defun split-path (path) |
377 Symbols are also allowed; their print names are used instead. | 437 ; "Explode a search path into a list of strings. |
378 | 438 ;The path components are separated with the characters specified |
379 See also `equalp'." | 439 ;with `path-separator'." |
380 (if (symbolp str1) | 440 ; (while (or (not stringp path-separator) |
381 (setq str1 (symbol-name str1))) | 441 ; (/= (length path-separator) 1)) |
382 (if (symbolp str2) | 442 ; (setq path-separator (signal 'error (list "\ |
383 (setq str2 (symbol-name str2))) | 443 ;`path-separator' should be set to a single-character string" |
384 (eq t (compare-strings str1 nil nil str2 nil nil t))) | 444 ; path-separator)))) |
385 | 445 ; (split-string-by-char path (aref separator 0))) |
386 ;; XEmacs | 446 |
447 (defmacro with-current-buffer (buffer &rest body) | |
448 "Temporarily make BUFFER the current buffer and execute the forms in BODY. | |
449 The value returned is the value of the last form in BODY. | |
450 See also `with-temp-buffer'." | |
451 `(save-current-buffer | |
452 (set-buffer ,buffer) | |
453 ,@body)) | |
454 | |
455 (defmacro with-temp-file (filename &rest forms) | |
456 "Create a new buffer, evaluate FORMS there, and write the buffer to FILENAME. | |
457 The value of the last form in FORMS is returned, like `progn'. | |
458 See also `with-temp-buffer'." | |
459 (let ((temp-file (make-symbol "temp-file")) | |
460 (temp-buffer (make-symbol "temp-buffer"))) | |
461 `(let ((,temp-file ,filename) | |
462 (,temp-buffer | |
463 (get-buffer-create (generate-new-buffer-name " *temp file*")))) | |
464 (unwind-protect | |
465 (prog1 | |
466 (with-current-buffer ,temp-buffer | |
467 ,@forms) | |
468 (with-current-buffer ,temp-buffer | |
469 (widen) | |
470 (write-region (point-min) (point-max) ,temp-file nil 0))) | |
471 (and (buffer-name ,temp-buffer) | |
472 (kill-buffer ,temp-buffer)))))) | |
473 | |
474 ;; FSF compatibility | |
475 (defmacro with-temp-message (message &rest body) | |
476 "Display MESSAGE temporarily while BODY is evaluated. | |
477 The original message is restored to the echo area after BODY has finished. | |
478 The value returned is the value of the last form in BODY. | |
479 If MESSAGE is nil, the echo area and message log buffer are unchanged. | |
480 Use a MESSAGE of \"\" to temporarily clear the echo area. | |
481 | |
482 Note that this function exists for FSF compatibility purposes. A better way | |
483 under XEmacs is to give the message a particular label (see `display-message'); | |
484 then, the old message is automatically restored when you clear your message | |
485 with `clear-message'." | |
486 ;; FSF additional doc string from 21.2: | |
487 ;; MESSAGE is written to the message log buffer if `message-log-max' is non-nil. | |
488 (let ((current-message (make-symbol "current-message")) | |
489 (temp-message (make-symbol "with-temp-message"))) | |
490 `(let ((,temp-message ,message) | |
491 (,current-message)) | |
492 (unwind-protect | |
493 (progn | |
494 (when ,temp-message | |
495 (setq ,current-message (current-message)) | |
496 (message "%s" ,temp-message)) | |
497 ,@body) | |
498 (and ,temp-message ,current-message | |
499 (message "%s" ,current-message)))))) | |
500 | |
501 (defmacro with-temp-buffer (&rest forms) | |
502 "Create a temporary buffer, and evaluate FORMS there like `progn'. | |
503 See also `with-temp-file' and `with-output-to-string'." | |
504 (let ((temp-buffer (make-symbol "temp-buffer"))) | |
505 `(let ((,temp-buffer | |
506 (get-buffer-create (generate-new-buffer-name " *temp*")))) | |
507 (unwind-protect | |
508 (with-current-buffer ,temp-buffer | |
509 ,@forms) | |
510 (and (buffer-name ,temp-buffer) | |
511 (kill-buffer ,temp-buffer)))))) | |
512 | |
513 (defmacro with-output-to-string (&rest body) | |
514 "Execute BODY, return the text it sent to `standard-output', as a string." | |
515 `(let ((standard-output | |
516 (get-buffer-create (generate-new-buffer-name " *string-output*")))) | |
517 (let ((standard-output standard-output)) | |
518 ,@body) | |
519 (with-current-buffer standard-output | |
520 (prog1 | |
521 (buffer-string) | |
522 (kill-buffer nil))))) | |
523 | |
524 ;; FSF 21.2. | |
525 | |
526 ; (defmacro combine-after-change-calls (&rest body) | |
527 ; "Execute BODY, but don't call the after-change functions till the end. | |
528 ; If BODY makes changes in the buffer, they are recorded | |
529 ; and the functions on `after-change-functions' are called several times | |
530 ; when BODY is finished. | |
531 ; The return value is the value of the last form in BODY. | |
532 | |
533 ; If `before-change-functions' is non-nil, then calls to the after-change | |
534 ; functions can't be deferred, so in that case this macro has no effect. | |
535 | |
536 ; Do not alter `after-change-functions' or `before-change-functions' | |
537 ; in BODY." | |
538 ; `(unwind-protect | |
539 ; (let ((combine-after-change-calls t)) | |
540 ; . ,body) | |
541 ; (combine-after-change-execute))) | |
542 | |
543 (defmacro with-syntax-table (table &rest body) | |
544 "Evaluate BODY with syntax table of current buffer set to a copy of TABLE. | |
545 The syntax table of the current buffer is saved, BODY is evaluated, and the | |
546 saved table is restored, even in case of an abnormal exit. | |
547 Value is what BODY returns." | |
548 (let ((old-table (make-symbol "table")) | |
549 (old-buffer (make-symbol "buffer"))) | |
550 `(let ((,old-table (syntax-table)) | |
551 (,old-buffer (current-buffer))) | |
552 (unwind-protect | |
553 (progn | |
554 (set-syntax-table (copy-syntax-table ,table)) | |
555 ,@body) | |
556 (save-current-buffer | |
557 (set-buffer ,old-buffer) | |
558 (set-syntax-table ,old-table)))))) | |
559 | |
560 (put 'with-syntax-table 'lisp-indent-function 1) | |
561 (put 'with-syntax-table 'edebug-form-spec '(form body)) | |
562 | |
563 | |
564 ;; Moved from mule-coding.el. | |
565 (defmacro with-string-as-buffer-contents (str &rest body) | |
566 "With the contents of the current buffer being STR, run BODY. | |
567 Returns the new contents of the buffer, as modified by BODY. | |
568 The original current buffer is restored afterwards." | |
569 `(with-temp-buffer | |
570 (insert ,str) | |
571 ,@body | |
572 (buffer-string))) | |
573 | |
574 | |
575 (defmacro save-match-data (&rest body) | |
576 "Execute BODY forms, restoring the global value of the match data." | |
577 (let ((original (make-symbol "match-data"))) | |
578 (list 'let (list (list original '(match-data))) | |
579 (list 'unwind-protect | |
580 (cons 'progn body) | |
581 (list 'store-match-data original))))) | |
582 | |
583 | |
584 (defun match-string (num &optional string) | |
585 "Return string of text matched by last search. | |
586 NUM specifies which parenthesized expression in the last regexp. | |
587 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
588 Zero means the entire text matched by the whole regexp or whole string. | |
589 STRING should be given if the last search was by `string-match' on STRING." | |
590 (if (match-beginning num) | |
591 (if string | |
592 (substring string (match-beginning num) (match-end num)) | |
593 (buffer-substring (match-beginning num) (match-end num))))) | |
594 | |
595 (defun match-string-no-properties (num &optional string) | |
596 "Return string of text matched by last search, without text properties. | |
597 NUM specifies which parenthesized expression in the last regexp. | |
598 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
599 Zero means the entire text matched by the whole regexp or whole string. | |
600 STRING should be given if the last search was by `string-match' on STRING." | |
601 (if (match-beginning num) | |
602 (if string | |
603 (let ((result | |
604 (substring string (match-beginning num) (match-end num)))) | |
605 (set-text-properties 0 (length result) nil result) | |
606 result) | |
607 (buffer-substring-no-properties (match-beginning num) | |
608 (match-end num))))) | |
609 | |
610 (defun split-string (string &optional separators) | |
611 "Splits STRING into substrings where there are matches for SEPARATORS. | |
612 Each match for SEPARATORS is a splitting point. | |
613 The substrings between the splitting points are made into a list | |
614 which is returned. | |
615 If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\". | |
616 | |
617 If there is match for SEPARATORS at the beginning of STRING, we do not | |
618 include a null substring for that. Likewise, if there is a match | |
619 at the end of STRING, we don't include a null substring for that. | |
620 | |
621 Modifies the match data; use `save-match-data' if necessary." | |
622 (let ((rexp (or separators "[ \f\t\n\r\v]+")) | |
623 (start 0) | |
624 notfirst | |
625 (list nil)) | |
626 (while (and (string-match rexp string | |
627 (if (and notfirst | |
628 (= start (match-beginning 0)) | |
629 (< start (length string))) | |
630 (1+ start) start)) | |
631 (< (match-beginning 0) (length string))) | |
632 (setq notfirst t) | |
633 (or (eq (match-beginning 0) 0) | |
634 (and (eq (match-beginning 0) (match-end 0)) | |
635 (eq (match-beginning 0) start)) | |
636 (setq list | |
637 (cons (substring string start (match-beginning 0)) | |
638 list))) | |
639 (setq start (match-end 0))) | |
640 (or (eq start (length string)) | |
641 (setq list | |
642 (cons (substring string start) | |
643 list))) | |
644 (nreverse list))) | |
645 | |
646 (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
647 "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
648 Unless optional argument INPLACE is non-nil, return a new string." | |
649 (let ((i (length string)) | |
650 (newstr (if inplace string (copy-sequence string)))) | |
651 (while (> i 0) | |
652 (setq i (1- i)) | |
653 (if (eq (aref newstr i) fromchar) | |
654 (aset newstr i tochar))) | |
655 newstr)) | |
656 | |
657 | |
658 ;; XEmacs addition: | |
387 (defun replace-in-string (str regexp newtext &optional literal) | 659 (defun replace-in-string (str regexp newtext &optional literal) |
388 "Replace all matches in STR for REGEXP with NEWTEXT string, | 660 "Replace all matches in STR for REGEXP with NEWTEXT string, |
389 and returns the new string. | 661 and returns the new string. |
390 Optional LITERAL non-nil means do a literal replacement. | 662 Optional LITERAL non-nil means do a literal replacement. |
391 Otherwise treat `\\' in NEWTEXT as special: | 663 Otherwise treat `\\' in NEWTEXT as special: |
414 (setq newstr (replace-match newtext t literal str) | 686 (setq newstr (replace-match newtext t literal str) |
415 start (+ (match-end 0) (- (length newstr) (length str))) | 687 start (+ (match-end 0) (- (length newstr) (length str))) |
416 str newstr)) | 688 str newstr)) |
417 str))) | 689 str))) |
418 | 690 |
419 (defun split-string (string &optional pattern) | 691 (defun replace-regexp-in-string (regexp rep string &optional |
420 "Return a list of substrings of STRING which are separated by PATTERN. | 692 fixedcase literal subexp start) |
421 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." | 693 "Replace all matches for REGEXP with REP in STRING. |
422 (or pattern | 694 |
423 (setq pattern "[ \f\t\n\r\v]+")) | 695 Return a new string containing the replacements. |
424 (let (parts (start 0) (len (length string))) | 696 |
425 (if (string-match pattern string) | 697 Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the |
426 (setq parts (cons (substring string 0 (match-beginning 0)) parts) | 698 arguments with the same names of function `replace-match'. If START |
427 start (match-end 0))) | 699 is non-nil, start replacements at that index in STRING. |
428 (while (and (< start len) | 700 |
429 (string-match pattern string (if (> start (match-beginning 0)) | 701 REP is either a string used as the NEWTEXT arg of `replace-match' or a |
430 start | 702 function. If it is a function it is applied to each match to generate |
431 (1+ start)))) | 703 the replacement passed to `replace-match'; the match-data at this |
432 (setq parts (cons (substring string start (match-beginning 0)) parts) | 704 point are such that match 0 is the function's argument. |
433 start (match-end 0))) | 705 |
434 (nreverse (cons (substring string start) parts)))) | 706 To replace only the first match (if any), make REGEXP match up to \\' |
435 | 707 and replace a sub-expression, e.g. |
436 ;; #### #### #### AAaargh! Must be in C, because it is used insanely | 708 (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1) |
437 ;; early in the bootstrap process. | 709 => \" bar foo\" |
438 ;(defun split-path (path) | 710 " |
439 ; "Explode a search path into a list of strings. | 711 |
440 ;The path components are separated with the characters specified | 712 ;; To avoid excessive consing from multiple matches in long strings, |
441 ;with `path-separator'." | 713 ;; don't just call `replace-match' continually. Walk down the |
442 ; (while (or (not stringp path-separator) | 714 ;; string looking for matches of REGEXP and building up a (reversed) |
443 ; (/= (length path-separator) 1)) | 715 ;; list MATCHES. This comprises segments of STRING which weren't |
444 ; (setq path-separator (signal 'error (list "\ | 716 ;; matched interspersed with replacements for segments that were. |
445 ;`path-separator' should be set to a single-character string" | 717 ;; [For a `large' number of replacments it's more efficient to |
446 ; path-separator)))) | 718 ;; operate in a temporary buffer; we can't tell from the function's |
447 ; (split-string-by-char path (aref separator 0))) | 719 ;; args whether to choose the buffer-based implementation, though it |
448 | 720 ;; might be reasonable to do so for long enough STRING.] |
449 (defmacro with-output-to-string (&rest body) | 721 (let ((l (length string)) |
450 "Execute BODY, return the text it sent to `standard-output', as a string." | 722 (start (or start 0)) |
451 `(let ((standard-output | 723 matches str mb me) |
452 (get-buffer-create (generate-new-buffer-name " *string-output*")))) | 724 (save-match-data |
453 (let ((standard-output standard-output)) | 725 (while (and (< start l) (string-match regexp string start)) |
454 ,@body) | 726 (setq mb (match-beginning 0) |
455 (with-current-buffer standard-output | 727 me (match-end 0)) |
456 (prog1 | 728 ;; If we matched the empty string, make sure we advance by one char |
457 (buffer-string) | 729 (when (= me mb) (setq me (min l (1+ mb)))) |
458 (kill-buffer nil))))) | 730 ;; Generate a replacement for the matched substring. |
459 | 731 ;; Operate only on the substring to minimize string consing. |
460 (defmacro with-current-buffer (buffer &rest body) | 732 ;; Set up match data for the substring for replacement; |
461 "Temporarily make BUFFER the current buffer and execute the forms in BODY. | 733 ;; presumably this is likely to be faster than munging the |
462 The value returned is the value of the last form in BODY. | 734 ;; match data directly in Lisp. |
463 See also `with-temp-buffer'." | 735 (string-match regexp (setq str (substring string mb me))) |
464 `(save-current-buffer | 736 (setq matches |
465 (set-buffer ,buffer) | 737 (cons (replace-match (if (stringp rep) |
466 ,@body)) | 738 rep |
467 | 739 (funcall rep (match-string 0 str))) |
468 (defmacro with-temp-file (filename &rest forms) | 740 fixedcase literal str subexp) |
469 "Create a new buffer, evaluate FORMS there, and write the buffer to FILENAME. | 741 (cons (substring string start mb) ; unmatched prefix |
470 The value of the last form in FORMS is returned, like `progn'. | 742 matches))) |
471 See also `with-temp-buffer'." | 743 (setq start me)) |
472 (let ((temp-file (make-symbol "temp-file")) | 744 ;; Reconstruct a string from the pieces. |
473 (temp-buffer (make-symbol "temp-buffer"))) | 745 (setq matches (cons (substring string start l) matches)) ; leftover |
474 `(let ((,temp-file ,filename) | 746 (apply #'concat (nreverse matches))))) |
475 (,temp-buffer | 747 |
476 (get-buffer-create (generate-new-buffer-name " *temp file*")))) | 748 ;; END SYNCHED WITH FSF 21.2 |
477 (unwind-protect | 749 |
478 (prog1 | 750 |
479 (with-current-buffer ,temp-buffer | 751 ;;; Basic string functions |
480 ,@forms) | 752 |
481 (with-current-buffer ,temp-buffer | 753 ;; XEmacs |
482 (widen) | 754 (defun string-equal-ignore-case (str1 str2) |
483 (write-region (point-min) (point-max) ,temp-file nil 0))) | 755 "Return t if two strings have identical contents, ignoring case differences. |
484 (and (buffer-name ,temp-buffer) | 756 Case is not significant. Text properties and extents are ignored. |
485 (kill-buffer ,temp-buffer)))))) | 757 Symbols are also allowed; their print names are used instead. |
486 | 758 |
487 (defmacro with-temp-message (message &rest body) | 759 See also `equalp'." |
488 "Display MESSAGE temporarily while BODY is evaluated. | 760 (if (symbolp str1) |
489 The original message is restored to the echo area after BODY has finished. | 761 (setq str1 (symbol-name str1))) |
490 The value returned is the value of the last form in BODY." | 762 (if (symbolp str2) |
491 (let ((current-message (make-symbol "current-message")) | 763 (setq str2 (symbol-name str2))) |
492 (temp-message (make-symbol "with-temp-message"))) | 764 (eq t (compare-strings str1 nil nil str2 nil nil t))) |
493 `(let ((,temp-message ,message) | |
494 (,current-message)) | |
495 (unwind-protect | |
496 (progn | |
497 (when ,temp-message | |
498 (setq ,current-message (current-message)) | |
499 (message "%s" ,temp-message)) | |
500 ,@body) | |
501 (and ,temp-message ,current-message | |
502 (message "%s" ,current-message)))))) | |
503 | |
504 (defmacro with-temp-buffer (&rest forms) | |
505 "Create a temporary buffer, and evaluate FORMS there like `progn'. | |
506 See also `with-temp-file' and `with-output-to-string'." | |
507 (let ((temp-buffer (make-symbol "temp-buffer"))) | |
508 `(let ((,temp-buffer | |
509 (get-buffer-create (generate-new-buffer-name " *temp*")))) | |
510 (unwind-protect | |
511 (with-current-buffer ,temp-buffer | |
512 ,@forms) | |
513 (and (buffer-name ,temp-buffer) | |
514 (kill-buffer ,temp-buffer)))))) | |
515 | |
516 ;; Moved from mule-coding.el. | |
517 (defmacro with-string-as-buffer-contents (str &rest body) | |
518 "With the contents of the current buffer being STR, run BODY. | |
519 Returns the new contents of the buffer, as modified by BODY. | |
520 The original current buffer is restored afterwards." | |
521 `(with-temp-buffer | |
522 (insert ,str) | |
523 ,@body | |
524 (buffer-string))) | |
525 | 765 |
526 (defun insert-face (string face) | 766 (defun insert-face (string face) |
527 "Insert STRING and highlight with FACE. Return the extent created." | 767 "Insert STRING and highlight with FACE. Return the extent created." |
528 (let ((p (point)) ext) | 768 (let ((p (point)) ext) |
529 (insert string) | 769 (insert string) |
604 string)) | 844 string)) |
605 | 845 |
606 ;; From FSF 21.1; ELLIPSES is XEmacs addition. | 846 ;; From FSF 21.1; ELLIPSES is XEmacs addition. |
607 | 847 |
608 (defun truncate-string-to-width (str end-column &optional start-column padding | 848 (defun truncate-string-to-width (str end-column &optional start-column padding |
609 ellipses) | 849 ellipses) |
610 "Truncate string STR to end at column END-COLUMN. | 850 "Truncate string STR to end at column END-COLUMN. |
611 The optional 3rd arg START-COLUMN, if non-nil, specifies | 851 The optional 3rd arg START-COLUMN, if non-nil, specifies |
612 the starting column; that means to return the characters occupying | 852 the starting column; that means to return the characters occupying |
613 columns START-COLUMN ... END-COLUMN of STR. | 853 columns START-COLUMN ... END-COLUMN of STR. |
614 | 854 |
1222 (buffer-substring buffer old-end old-buffer)) | 1462 (buffer-substring buffer old-end old-buffer)) |
1223 (t | 1463 (t |
1224 ;; Probably the old way. | 1464 ;; Probably the old way. |
1225 (buffer-substring buffer old-end old-buffer)))) | 1465 (buffer-substring buffer old-end old-buffer)))) |
1226 | 1466 |
1467 ;; BEGIN SYNC WITH FSF 21.2 | |
1468 | |
1227 ;; This was not present before. I think Jamie had some objections | 1469 ;; This was not present before. I think Jamie had some objections |
1228 ;; to this, so I'm leaving this undefined for now. --ben | 1470 ;; to this, so I'm leaving this undefined for now. --ben |
1229 | 1471 |
1230 ;;; The objection is this: there is more than one way to load the same file. | 1472 ;;; The objection is this: there is more than one way to load the same file. |
1231 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different | 1473 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different |
1242 (defun eval-after-load (file form) | 1484 (defun eval-after-load (file form) |
1243 "Arrange that, if FILE is ever loaded, FORM will be run at that time. | 1485 "Arrange that, if FILE is ever loaded, FORM will be run at that time. |
1244 This makes or adds to an entry on `after-load-alist'. | 1486 This makes or adds to an entry on `after-load-alist'. |
1245 If FILE is already loaded, evaluate FORM right now. | 1487 If FILE is already loaded, evaluate FORM right now. |
1246 It does nothing if FORM is already on the list for FILE. | 1488 It does nothing if FORM is already on the list for FILE. |
1247 FILE should be the name of a library, with no directory name." | 1489 FILE must match exactly. Normally FILE is the name of a library, |
1490 with no directory or extension specified, since that is how `load' | |
1491 is normally called." | |
1492 ;; Make sure `load-history' contains the files dumped with Emacs | |
1493 ;; for the case that FILE is one of the files dumped with Emacs. | |
1494 (if-fboundp 'load-symbol-file-load-history | |
1495 (load-symbol-file-load-history)) | |
1248 ;; Make sure there is an element for FILE. | 1496 ;; Make sure there is an element for FILE. |
1249 (or (assoc file after-load-alist) | 1497 (or (assoc file after-load-alist) |
1250 (setq after-load-alist (cons (list file) after-load-alist))) | 1498 (setq after-load-alist (cons (list file) after-load-alist))) |
1251 ;; Add FORM to the element if it isn't there. | 1499 ;; Add FORM to the element if it isn't there. |
1252 (let ((elt (assoc file after-load-alist))) | 1500 (let ((elt (assoc file after-load-alist))) |
1264 This makes or adds to an entry on `after-load-alist'. | 1512 This makes or adds to an entry on `after-load-alist'. |
1265 FILE should be the name of a library, with no directory name." | 1513 FILE should be the name of a library, with no directory name." |
1266 (eval-after-load file (read))) | 1514 (eval-after-load file (read))) |
1267 (make-compatible 'eval-next-after-load "") | 1515 (make-compatible 'eval-next-after-load "") |
1268 | 1516 |
1269 ; alternate names (not obsolete) | 1517 ;; END SYNC WITH FSF 21.2 |
1270 (if (not (fboundp 'mod)) (define-function 'mod '%)) | |
1271 (define-function 'move-marker 'set-marker) | |
1272 (define-function 'beep 'ding) ; preserve lingual purity | |
1273 (define-function 'indent-to-column 'indent-to) | |
1274 (define-function 'backward-delete-char 'delete-backward-char) | |
1275 (define-function 'search-forward-regexp (symbol-function 're-search-forward)) | |
1276 (define-function 'search-backward-regexp (symbol-function 're-search-backward)) | |
1277 (define-function 'remove-directory 'delete-directory) | |
1278 (define-function 'set-match-data 'store-match-data) | |
1279 (define-function 'send-string-to-terminal 'external-debugging-output) | |
1280 | 1518 |
1281 ;;; subr.el ends here | 1519 ;;; subr.el ends here |