Mercurial > hg > xemacs-beta
annotate lisp/subr.el @ 5182:2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
lisp/ChangeLog addition:
2010-04-01 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el (fill, sort*, merge): Move these functions to fns.c.
(stable-sort): Make this docstring reflect the argument names used
in the #'sort* docstring.
* cl-macs.el (stable-sort): Make #'stable-sort exactly equivalent
to #'sort* in compiled code.
* bytecomp.el (byte-compile-maybe-add-*):
New macro, for functions like #'sort and #'mapcar that, to be
strictly compatible, should only take two args, but in our
implementation can take more, because they're aliases of #'sort*
and #'mapcar*.
(byte-compile-mapcar, byte-compile-sort, byte-compile-fillarray):
Use this new macro.
(map-into): Add a byte-compile method for #'map-into in passing.
* apropos.el (apropos-print): Use #'sort* with a :key argument,
now it's in C.
* compat.el (extent-at): Ditto.
* register.el (list-registers): Ditto.
* package-ui.el (pui-list-packages): Ditto.
* help.el (sorted-key-descriptions): Ditto.
src/ChangeLog addition:
2010-03-31 Aidan Kehoe <kehoea@parhasard.net>
* fns.c (STRING_DATA_TO_OBJECT_ARRAY)
(BIT_VECTOR_TO_OBJECT_ARRAY, c_merge_predicate_key)
(c_merge_predicate_nokey, list_merge, array_merge)
(list_array_merge_into_list, list_list_merge_into_array)
(list_array_merge_into_array, CHECK_KEY_ARGUMENT, Fmerge)
(list_sort, array_sort, FsortX):
Move #'sort*, #'fill, #'merge from cl-seq.el to C, extending the
implementations of Fsort, Ffillarray, and merge() to do so.
* keymap.c (keymap_submaps, map_keymap_sort_predicate)
(describe_map_sort_predicate):
Change the calling semantics of the C sort predicates to return a
non-nil Lisp object if the first argument is less than the second,
rather than C integers.
* fontcolor-msw.c (sort_font_list_function):
* fileio.c (build_annotations):
* dired.c (Fdirectory_files):
* abbrev.c (Finsert_abbrev_table_description):
Call list_sort instead of Fsort, list_merge instead of merge() in
these functions.
man/ChangeLog addition:
2010-04-01 Aidan Kehoe <kehoea@parhasard.net>
* lispref/lists.texi (Rearrangement):
Update the documentation of #'sort here, now that it accepts any
type of sequence and the KEY keyword argument. (Though this is
probably now the wrong place for this function, given that.)
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 01 Apr 2010 20:22:50 +0100 |
parents | 99f8ebc082d9 |
children | 2157ecaedc1d |
rev | line source |
---|---|
428 | 1 ;;; subr.el --- basic lisp subroutines for XEmacs |
2 | |
2525 | 3 ;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 2003 |
4 ;; Free Software Foundation, Inc. | |
428 | 5 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. |
6 ;; Copyright (C) 1995 Sun Microsystems. | |
1333 | 7 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing. |
428 | 8 |
9 ;; Maintainer: XEmacs Development Team | |
2525 | 10 ;; Keywords: extensions, dumped, internal |
428 | 11 |
12 ;; This file is part of XEmacs. | |
13 | |
14 ;; XEmacs is free software; you can redistribute it and/or modify it | |
15 ;; under the terms of the GNU General Public License as published by | |
16 ;; the Free Software Foundation; either version 2, or (at your option) | |
17 ;; any later version. | |
18 | |
19 ;; XEmacs is distributed in the hope that it will be useful, but | |
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 ;; General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
3000 | 26 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
428 | 28 |
1333 | 29 ;;; Synched up with: FSF 19.34. Some things synched up with later versions. |
428 | 30 |
31 ;;; Commentary: | |
32 | |
33 ;; This file is dumped with XEmacs. | |
34 | |
35 ;; There's not a whole lot in common now with the FSF version, | |
36 ;; be wary when applying differences. I've left in a number of lines | |
37 ;; of commentary just to give diff(1) something to synch itself with to | |
38 ;; provide useful context diffs. -sb | |
39 | |
1333 | 40 ;; BEGIN SYNCHED WITH FSF 21.2 |
41 | |
428 | 42 ;;; Code: |
1333 | 43 (defvar custom-declare-variable-list nil |
44 "Record `defcustom' calls made before `custom.el' is loaded to handle them. | |
45 Each element of this list holds the arguments to one call to `defcustom'.") | |
428 | 46 |
1333 | 47 ;; Use this, rather than defcustom, in subr.el and other files loaded |
1336 | 48 ;; before custom.el. See dumped-lisp.el. |
1333 | 49 (defun custom-declare-variable-early (&rest arguments) |
50 (setq custom-declare-variable-list | |
51 (cons arguments custom-declare-variable-list))) | |
2525 | 52 |
53 | |
54 (defun macro-declaration-function (macro decl) | |
55 "Process a declaration found in a macro definition. | |
56 This is set as the value of the variable `macro-declaration-function'. | |
57 MACRO is the name of the macro being defined. | |
58 DECL is a list `(declare ...)' containing the declarations. | |
59 The return value of this function is not used." | |
60 (dolist (d (cdr decl)) | |
61 (cond ((and (consp d) (eq (car d) 'indent)) | |
62 (put macro 'lisp-indent-function (cadr d))) | |
63 ((and (consp d) (eq (car d) 'debug)) | |
64 (put macro 'edebug-form-spec (cadr d))) | |
65 (t | |
66 (message "Unknown declaration %s" d))))) | |
67 | |
68 (setq macro-declaration-function 'macro-declaration-function) | |
69 | |
428 | 70 |
71 ;;;; Lisp language features. | |
72 | |
73 (defmacro lambda (&rest cdr) | |
74 "Return a lambda expression. | |
75 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is | |
76 self-quoting; the result of evaluating the lambda expression is the | |
77 expression itself. The lambda expression may then be treated as a | |
78 function, i.e., stored as the function value of a symbol, passed to | |
79 funcall or mapcar, etc. | |
80 | |
81 ARGS should take the same form as an argument list for a `defun'. | |
3842 | 82 Optional DOCSTRING is a documentation string. |
83 If present, it should describe how to call the function. Docstrings are | |
84 rarely useful unless the lambda will be named, eg, using `fset'. | |
85 Optional INTERACTIVE should be a call to the function `interactive'. | |
86 BODY should be a list of lisp expressions. | |
87 | |
88 The byte-compiler treats lambda expressions specially. If the lambda | |
89 expression is syntactically a function to be called, it will be compiled | |
90 unless protected by `quote'. Conversely, quoting a lambda expression with | |
91 `function' hints to the byte-compiler that it should compile the expression. | |
92 \(The byte-compiler may or may not actually compile it; for example it will | |
93 never compile lambdas nested in a data structure: `'(#'(lambda (x) x))'). | |
94 | |
95 The byte-compiler will warn about common problems such as the form | |
96 `(fset 'f '(lambda (x) x))' (the lambda cannot be byte-compiled; probably | |
97 the programmer intended `#'', although leaving the lambda unquoted will | |
98 normally suffice), but in general is it the programmer's responsibility to | |
99 quote lambda expressions appropriately." | |
428 | 100 `(function (lambda ,@cdr))) |
101 | |
1333 | 102 ;; FSF 21.2 has various basic macros here. We don't because they're either |
103 ;; in cl*.el (which we dump and hence is always available) or built-in. | |
104 | |
105 ;; More powerful versions in cl.el. | |
106 ;(defmacro push (newelt listname) | |
107 ;(defmacro pop (listname) | |
108 | |
109 ;; Built-in. | |
110 ;(defmacro when (cond &rest body) | |
111 ;(defmacro unless (cond &rest body) | |
112 | |
113 ;; More powerful versions in cl-macs.el. | |
114 ;(defmacro dolist (spec &rest body) | |
115 ;(defmacro dotimes (spec &rest body) | |
116 | |
117 ;; In cl.el. Ours are defun, but cl arranges for them to be inlined anyway. | |
118 ;(defsubst caar (x) | |
119 ;(defsubst cadr (x) | |
120 ;(defsubst cdar (x) | |
121 ;(defsubst cddr (x) | |
122 | |
123 ;; Built-in. Our `last' is more powerful in that it handles circularity. | |
124 ;(defun last (x &optional n) | |
125 ;(defun butlast (x &optional n) | |
126 ;(defun nbutlast (x &optional n) | |
127 | |
128 ;; In cl-seq.el. | |
129 ;(defun remove (elt seq) | |
130 ;(defun remq (elt list) | |
131 | |
428 | 132 (defmacro defun-when-void (&rest args) |
133 "Define a function, just like `defun', unless it's already defined. | |
134 Used for compatibility among different emacs variants." | |
135 `(if (fboundp ',(car args)) | |
136 nil | |
137 (defun ,@args))) | |
138 | |
139 (defmacro define-function-when-void (&rest args) | |
140 "Define a function, just like `define-function', unless it's already defined. | |
141 Used for compatibility among different emacs variants." | |
142 `(if (fboundp ,(car args)) | |
143 nil | |
144 (define-function ,@args))) | |
145 | |
146 | |
1333 | 147 (defun assoc-default (key alist &optional test default) |
148 "Find object KEY in a pseudo-alist ALIST. | |
149 ALIST is a list of conses or objects. Each element (or the element's car, | |
150 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY). | |
151 If that is non-nil, the element matches; | |
152 then `assoc-default' returns the element's cdr, if it is a cons, | |
153 or DEFAULT if the element is not a cons. | |
154 | |
155 If no element matches, the value is nil. | |
156 If TEST is omitted or nil, `equal' is used." | |
157 (let (found (tail alist) value) | |
158 (while (and tail (not found)) | |
159 (let ((elt (car tail))) | |
160 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) | |
161 (setq found t value (if (consp elt) (cdr elt) default)))) | |
162 (setq tail (cdr tail))) | |
163 value)) | |
164 | |
165 (defun assoc-ignore-case (key alist) | |
166 "Like `assoc', but ignores differences in case and text representation. | |
167 KEY must be a string. Upper-case and lower-case letters are treated as equal." | |
168 (let (element) | |
169 (while (and alist (not element)) | |
170 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil t)) | |
171 (setq element (car alist))) | |
172 (setq alist (cdr alist))) | |
173 element)) | |
174 | |
175 (defun assoc-ignore-representation (key alist) | |
176 "Like `assoc', but ignores differences in text representation. | |
177 KEY must be a string." | |
178 (let (element) | |
179 (while (and alist (not element)) | |
180 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil)) | |
181 (setq element (car alist))) | |
182 (setq alist (cdr alist))) | |
183 element)) | |
184 | |
185 (defun member-ignore-case (elt list) | |
186 "Like `member', but ignores differences in case and text representation. | |
187 ELT must be a string. Upper-case and lower-case letters are treated as equal." | |
188 (while (and list (not (eq t (compare-strings elt 0 nil (car list) 0 nil t)))) | |
189 (setq list (cdr list))) | |
190 list) | |
191 | |
192 | |
428 | 193 ;;;; Keymap support. |
194 ;; XEmacs: removed to keymap.el | |
195 | |
196 ;;;; The global keymap tree. | |
197 | |
198 ;;; global-map, esc-map, and ctl-x-map have their values set up in | |
199 ;;; keymap.c; we just give them docstrings here. | |
200 | |
201 ;;;; Event manipulation functions. | |
202 | |
203 ;; XEmacs: This stuff is done in C Code. | |
204 | |
1333 | 205 ;;;; Obsolescent names for functions generally appear elsewhere, in |
206 ;;;; obsolete.el or in the files they are related do. Many very old | |
207 ;;;; obsolete stuff has been removed entirely (e.g. anything with `dot' in | |
208 ;;;; place of `point'). | |
209 | |
210 ; alternate names (not obsolete) | |
211 (if (not (fboundp 'mod)) (define-function 'mod '%)) | |
212 (define-function 'move-marker 'set-marker) | |
213 (define-function 'beep 'ding) ; preserve lingual purity | |
214 (define-function 'indent-to-column 'indent-to) | |
215 (define-function 'backward-delete-char 'delete-backward-char) | |
216 (define-function 'search-forward-regexp (symbol-function 're-search-forward)) | |
217 (define-function 'search-backward-regexp (symbol-function 're-search-backward)) | |
218 (define-function 'remove-directory 'delete-directory) | |
219 (define-function 'set-match-data 'store-match-data) | |
220 (define-function 'send-string-to-terminal 'external-debugging-output) | |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
221 (define-function 'special-form-p 'special-operator-p) |
428 | 222 |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5004
diff
changeset
|
223 ;; XEmacs; this is in Lisp, its bytecode now taken by subseq. |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5004
diff
changeset
|
224 (define-function 'substring 'subseq) |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5004
diff
changeset
|
225 |
428 | 226 ;; XEmacs: |
227 (defun local-variable-if-set-p (sym buffer) | |
228 "Return t if SYM would be local to BUFFER after it is set. | |
229 A nil value for BUFFER is *not* the same as (current-buffer), but | |
230 can be used to determine whether `make-variable-buffer-local' has been | |
231 called on SYM." | |
232 (local-variable-p sym buffer t)) | |
233 | |
234 | |
235 ;;;; Hook manipulation functions. | |
236 | |
237 ;; (defconst run-hooks 'run-hooks ...) | |
238 | |
239 (defun make-local-hook (hook) | |
240 "Make the hook HOOK local to the current buffer. | |
1333 | 241 The return value is HOOK. |
242 | |
243 You never need to call this function now that `add-hook' does it for you | |
244 if its LOCAL argument is non-nil. | |
245 | |
428 | 246 When a hook is local, its local and global values |
247 work in concert: running the hook actually runs all the hook | |
248 functions listed in *either* the local value *or* the global value | |
249 of the hook variable. | |
250 | |
251 This function works by making `t' a member of the buffer-local value, | |
252 which acts as a flag to run the hook functions in the default value as | |
253 well. This works for all normal hooks, but does not work for most | |
254 non-normal hooks yet. We will be changing the callers of non-normal | |
255 hooks so that they can handle localness; this has to be done one by | |
256 one. | |
257 | |
258 This function does nothing if HOOK is already local in the current | |
259 buffer. | |
260 | |
1333 | 261 Do not use `make-local-variable' to make a hook variable buffer-local." |
428 | 262 (if (local-variable-p hook (current-buffer)) ; XEmacs |
263 nil | |
264 (or (boundp hook) (set hook nil)) | |
265 (make-local-variable hook) | |
1333 | 266 (set hook (list t))) |
267 hook) | |
428 | 268 |
269 (defun add-hook (hook function &optional append local) | |
270 "Add to the value of HOOK the function FUNCTION. | |
271 FUNCTION is not added if already present. | |
272 FUNCTION is added (if necessary) at the beginning of the hook list | |
273 unless the optional argument APPEND is non-nil, in which case | |
274 FUNCTION is added at the end. | |
275 | |
276 The optional fourth argument, LOCAL, if non-nil, says to modify | |
277 the hook's buffer-local value rather than its default value. | |
1333 | 278 This makes the hook buffer-local if needed. |
428 | 279 To make a hook variable buffer-local, always use |
280 `make-local-hook', not `make-local-variable'. | |
281 | |
282 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
283 HOOK is void, it is first set to nil. If HOOK's value is a single | |
442 | 284 function, it is changed to a list of functions. |
285 | |
286 You can remove this hook yourself using `remove-hook'. | |
287 | |
1333 | 288 See also `add-one-shot-hook'." |
428 | 289 (or (boundp hook) (set hook nil)) |
290 (or (default-boundp hook) (set-default hook nil)) | |
1333 | 291 (if local (unless (local-variable-if-set-p hook (current-buffer)) ; XEmacs |
292 (make-local-hook hook)) | |
293 ;; Detect the case where make-local-variable was used on a hook | |
294 ;; and do what we used to do. | |
295 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) | |
296 (setq local t))) | |
297 (let ((hook-value (if local (symbol-value hook) (default-value hook)))) | |
298 ;; If the hook value is a single function, turn it into a list. | |
299 (when (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) | |
300 (setq hook-value (list hook-value))) | |
301 ;; Do the actual addition if necessary | |
302 (unless (member function hook-value) | |
303 (setq hook-value | |
304 (if append | |
305 (append hook-value (list function)) | |
306 (cons function hook-value)))) | |
307 ;; Set the actual variable | |
308 (if local (set hook hook-value) (set-default hook hook-value)))) | |
428 | 309 |
310 (defun remove-hook (hook function &optional local) | |
311 "Remove from the value of HOOK the function FUNCTION. | |
312 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
313 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | |
314 list of hooks to run in HOOK, then nothing is done. See `add-hook'. | |
315 | |
316 The optional third argument, LOCAL, if non-nil, says to modify | |
317 the hook's buffer-local value rather than its default value. | |
1333 | 318 This makes the hook buffer-local if needed. |
428 | 319 To make a hook variable buffer-local, always use |
320 `make-local-hook', not `make-local-variable'." | |
1333 | 321 (or (boundp hook) (set hook nil)) |
322 (or (default-boundp hook) (set-default hook nil)) | |
323 (if local (unless (local-variable-if-set-p hook (current-buffer)) ; XEmacs | |
324 (make-local-hook hook)) | |
325 ;; Detect the case where make-local-variable was used on a hook | |
326 ;; and do what we used to do. | |
327 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) | |
328 (setq local t))) | |
329 (let ((hook-value (if local (symbol-value hook) (default-value hook)))) | |
330 ;; Remove the function, for both the list and the non-list cases. | |
331 ;; XEmacs: add hook-test, for handling one-shot hooks. | |
332 (flet ((hook-test | |
333 (fn hel) | |
334 (or (equal fn hel) | |
335 (and (symbolp hel) | |
336 (equal fn | |
337 (get hel 'one-shot-hook-fun)))))) | |
338 (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) | |
339 (if (equal hook-value function) (setq hook-value nil)) | |
340 (setq hook-value (delete* function (copy-sequence hook-value) | |
341 :test 'hook-test))) | |
342 ;; If the function is on the global hook, we need to shadow it locally | |
343 ;;(when (and local (member* function (default-value hook) | |
344 ;; :test 'hook-test) | |
345 ;; (not (member* (cons 'not function) hook-value | |
346 ;; :test 'hook-test))) | |
347 ;; (push (cons 'not function) hook-value)) | |
348 ;; Set the actual variable | |
349 (if local (set hook hook-value) (set-default hook hook-value))))) | |
442 | 350 |
351 ;; XEmacs addition | |
352 ;; #### we need a coherent scheme for indicating compatibility info, | |
353 ;; so that it can be programmatically retrieved. | |
354 (defun add-local-hook (hook function &optional append) | |
355 "Add to the local value of HOOK the function FUNCTION. | |
1333 | 356 You don't need this any more. It's equivalent to specifying the LOCAL |
357 argument to `add-hook'." | |
442 | 358 (add-hook hook function append t)) |
359 | |
360 ;; XEmacs addition | |
361 (defun remove-local-hook (hook function) | |
362 "Remove from the local value of HOOK the function FUNCTION. | |
1333 | 363 You don't need this any more. It's equivalent to specifying the LOCAL |
364 argument to `remove-hook'." | |
365 (remove-hook hook function t)) | |
442 | 366 |
367 (defun add-one-shot-hook (hook function &optional append local) | |
368 "Add to the value of HOOK the one-shot function FUNCTION. | |
369 FUNCTION will automatically be removed from the hook the first time | |
370 after it runs (whether to completion or to an error). | |
371 FUNCTION is not added if already present. | |
372 FUNCTION is added (if necessary) at the beginning of the hook list | |
373 unless the optional argument APPEND is non-nil, in which case | |
374 FUNCTION is added at the end. | |
375 | |
376 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
377 HOOK is void, it is first set to nil. If HOOK's value is a single | |
378 function, it is changed to a list of functions. | |
379 | |
380 You can remove this hook yourself using `remove-hook'. | |
381 | |
1333 | 382 See also `add-hook'." |
442 | 383 (let ((sym (gensym))) |
384 (fset sym `(lambda (&rest args) | |
385 (unwind-protect | |
386 (apply ',function args) | |
387 (remove-hook ',hook ',sym ',local)))) | |
388 (put sym 'one-shot-hook-fun function) | |
389 (add-hook hook sym append local))) | |
390 | |
391 (defun add-local-one-shot-hook (hook function &optional append) | |
392 "Add to the local value of HOOK the one-shot function FUNCTION. | |
1333 | 393 You don't need this any more. It's equivalent to specifying the LOCAL |
394 argument to `add-one-shot-hook'." | |
442 | 395 (add-one-shot-hook hook function append t)) |
428 | 396 |
4461
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
397 (defun add-to-list (list-var element &optional append compare-fn) |
428 | 398 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. |
4461
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
399 The test for presence of ELEMENT is done with COMPARE-FN; if |
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
400 COMPARE-FN is nil, then it defaults to `equal'. If ELEMENT is added, |
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
401 it is added at the beginning of the list, unless the optional argument |
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
402 APPEND is non-nil, in which case ELEMENT is added at the end. |
878 | 403 |
428 | 404 If you want to use `add-to-list' on a variable that is not defined |
405 until a certain package is loaded, you should put the call to `add-to-list' | |
406 into a hook function that will be run only after loading the package. | |
407 `eval-after-load' provides one way to do this. In some cases | |
408 other hooks, such as major mode hooks, can do the job." | |
4463 | 409 (if (member* element (symbol-value list-var) :test (or compare-fn #'equal)) |
878 | 410 (symbol-value list-var) |
411 (set list-var | |
412 (if append | |
413 (append (symbol-value list-var) (list element)) | |
414 (cons element (symbol-value list-var)))))) | |
428 | 415 |
1333 | 416 ;; END SYNCHED WITH FSF 21.2 |
417 | |
428 | 418 ;; XEmacs additions |
419 ;; called by Fkill_buffer() | |
420 (defvar kill-buffer-hook nil | |
421 "Function or functions to be called when a buffer is killed. | |
422 The value of this variable may be buffer-local. | |
423 The buffer about to be killed is current when this hook is run.") | |
424 | |
425 ;; in C in FSFmacs | |
426 (defvar kill-emacs-hook nil | |
427 "Function or functions to be called when `kill-emacs' is called, | |
428 just before emacs is actually killed.") | |
429 | |
430 ;; not obsolete. | |
431 ;; #### These are a bad idea, because the CL RPLACA and RPLACD | |
432 ;; return the cons cell, not the new CAR/CDR. -hniksic | |
433 ;; The proper definition would be: | |
434 ;; (defun rplaca (conscell newcar) | |
435 ;; (setcar conscell newcar) | |
436 ;; conscell) | |
437 ;; ...and analogously for RPLACD. | |
438 (define-function 'rplaca 'setcar) | |
439 (define-function 'rplacd 'setcdr) | |
440 | |
441 (defun copy-symbol (symbol &optional copy-properties) | |
442 "Return a new uninterned symbol with the same name as SYMBOL. | |
443 If COPY-PROPERTIES is non-nil, the new symbol will have a copy of | |
444 SYMBOL's value, function, and property lists." | |
445 (let ((new (make-symbol (symbol-name symbol)))) | |
446 (when copy-properties | |
447 ;; This will not copy SYMBOL's chain of forwarding objects, but | |
448 ;; I think that's OK. Callers should not expect such magic to | |
449 ;; keep working in the copy in the first place. | |
450 (and (boundp symbol) | |
451 (set new (symbol-value symbol))) | |
452 (and (fboundp symbol) | |
453 (fset new (symbol-function symbol))) | |
454 (setplist new (copy-list (symbol-plist symbol)))) | |
455 new)) | |
456 | |
442 | 457 (defun set-symbol-value-in-buffer (sym val buffer) |
458 "Set the value of SYM to VAL in BUFFER. Useful with buffer-local variables. | |
459 If SYM has a buffer-local value in BUFFER, or will have one if set, this | |
460 function allows you to set the local value. | |
461 | |
462 NOTE: At some point, this will be moved into C and will be very fast." | |
463 (with-current-buffer buffer | |
464 (set sym val))) | |
444 | 465 |
1333 | 466 |
467 ;; BEGIN SYNCHED WITH FSF 21.2 | |
468 | |
469 ;; #### #### #### AAaargh! Must be in C, because it is used insanely | |
470 ;; early in the bootstrap process. | |
471 ;(defun split-path (path) | |
472 ; "Explode a search path into a list of strings. | |
473 ;The path components are separated with the characters specified | |
474 ;with `path-separator'." | |
475 ; (while (or (not stringp path-separator) | |
476 ; (/= (length path-separator) 1)) | |
477 ; (setq path-separator (signal 'error (list "\ | |
478 ;`path-separator' should be set to a single-character string" | |
479 ; path-separator)))) | |
480 ; (split-string-by-char path (aref separator 0))) | |
481 | |
482 (defmacro with-current-buffer (buffer &rest body) | |
483 "Temporarily make BUFFER the current buffer and execute the forms in BODY. | |
484 The value returned is the value of the last form in BODY. | |
485 See also `with-temp-buffer'." | |
486 `(save-current-buffer | |
487 (set-buffer ,buffer) | |
488 ,@body)) | |
489 | |
490 (defmacro with-temp-file (filename &rest forms) | |
491 "Create a new buffer, evaluate FORMS there, and write the buffer to FILENAME. | |
492 The value of the last form in FORMS is returned, like `progn'. | |
493 See also `with-temp-buffer'." | |
494 (let ((temp-file (make-symbol "temp-file")) | |
495 (temp-buffer (make-symbol "temp-buffer"))) | |
496 `(let ((,temp-file ,filename) | |
497 (,temp-buffer | |
498 (get-buffer-create (generate-new-buffer-name " *temp file*")))) | |
499 (unwind-protect | |
500 (prog1 | |
501 (with-current-buffer ,temp-buffer | |
502 ,@forms) | |
503 (with-current-buffer ,temp-buffer | |
504 (widen) | |
505 (write-region (point-min) (point-max) ,temp-file nil 0))) | |
506 (and (buffer-name ,temp-buffer) | |
507 (kill-buffer ,temp-buffer)))))) | |
508 | |
509 ;; FSF compatibility | |
510 (defmacro with-temp-message (message &rest body) | |
511 "Display MESSAGE temporarily while BODY is evaluated. | |
512 The original message is restored to the echo area after BODY has finished. | |
513 The value returned is the value of the last form in BODY. | |
514 If MESSAGE is nil, the echo area and message log buffer are unchanged. | |
515 Use a MESSAGE of \"\" to temporarily clear the echo area. | |
428 | 516 |
1333 | 517 Note that this function exists for FSF compatibility purposes. A better way |
518 under XEmacs is to give the message a particular label (see `display-message'); | |
519 then, the old message is automatically restored when you clear your message | |
520 with `clear-message'." | |
521 ;; FSF additional doc string from 21.2: | |
522 ;; MESSAGE is written to the message log buffer if `message-log-max' is non-nil. | |
523 (let ((current-message (make-symbol "current-message")) | |
524 (temp-message (make-symbol "with-temp-message"))) | |
525 `(let ((,temp-message ,message) | |
526 (,current-message)) | |
527 (unwind-protect | |
528 (progn | |
529 (when ,temp-message | |
530 (setq ,current-message (current-message)) | |
531 (message "%s" ,temp-message)) | |
532 ,@body) | |
533 (and ,temp-message ,current-message | |
534 (message "%s" ,current-message)))))) | |
535 | |
536 (defmacro with-temp-buffer (&rest forms) | |
537 "Create a temporary buffer, and evaluate FORMS there like `progn'. | |
538 See also `with-temp-file' and `with-output-to-string'." | |
539 (let ((temp-buffer (make-symbol "temp-buffer"))) | |
540 `(let ((,temp-buffer | |
541 (get-buffer-create (generate-new-buffer-name " *temp*")))) | |
542 (unwind-protect | |
543 (with-current-buffer ,temp-buffer | |
544 ,@forms) | |
545 (and (buffer-name ,temp-buffer) | |
546 (kill-buffer ,temp-buffer)))))) | |
547 | |
548 (defmacro with-output-to-string (&rest body) | |
549 "Execute BODY, return the text it sent to `standard-output', as a string." | |
550 `(let ((standard-output | |
551 (get-buffer-create (generate-new-buffer-name " *string-output*")))) | |
552 (let ((standard-output standard-output)) | |
553 ,@body) | |
554 (with-current-buffer standard-output | |
555 (prog1 | |
556 (buffer-string) | |
557 (kill-buffer nil))))) | |
558 | |
2135 | 559 (defmacro with-local-quit (&rest body) |
560 "Execute BODY with `inhibit-quit' temporarily bound to nil." | |
561 `(condition-case nil | |
562 (let ((inhibit-quit nil)) | |
563 ,@body) | |
564 (quit (setq quit-flag t)))) | |
565 | |
566 ;; FSF 21.3. | |
1333 | 567 |
568 ; (defmacro combine-after-change-calls (&rest body) | |
569 ; "Execute BODY, but don't call the after-change functions till the end. | |
570 ; If BODY makes changes in the buffer, they are recorded | |
571 ; and the functions on `after-change-functions' are called several times | |
572 ; when BODY is finished. | |
573 ; The return value is the value of the last form in BODY. | |
574 | |
575 ; If `before-change-functions' is non-nil, then calls to the after-change | |
576 ; functions can't be deferred, so in that case this macro has no effect. | |
577 | |
578 ; Do not alter `after-change-functions' or `before-change-functions' | |
579 ; in BODY." | |
2135 | 580 ; (declare (indent 0) (debug t)) |
1333 | 581 ; `(unwind-protect |
582 ; (let ((combine-after-change-calls t)) | |
583 ; . ,body) | |
584 ; (combine-after-change-execute))) | |
801 | 585 |
4369
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
586 (defmacro with-case-table (table &rest body) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
587 "Execute the forms in BODY with TABLE as the current case table. |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
588 The value returned is the value of the last form in BODY." |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
589 (declare (indent 1) (debug t)) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
590 (let ((old-case-table (make-symbol "table")) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
591 (old-buffer (make-symbol "buffer"))) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
592 `(let ((,old-case-table (current-case-table)) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
593 (,old-buffer (current-buffer))) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
594 (unwind-protect |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
595 (progn (set-case-table ,table) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
596 ,@body) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
597 (with-current-buffer ,old-buffer |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
598 (set-case-table ,old-case-table)))))) |
2135 | 599 |
600 (defvar delay-mode-hooks nil | |
601 "If non-nil, `run-mode-hooks' should delay running the hooks.") | |
602 (defvar delayed-mode-hooks nil | |
603 "List of delayed mode hooks waiting to be run.") | |
604 (make-variable-buffer-local 'delayed-mode-hooks) | |
605 (put 'delay-mode-hooks 'permanent-local t) | |
606 | |
607 (defun run-mode-hooks (&rest hooks) | |
608 "Run mode hooks `delayed-mode-hooks' and HOOKS, or delay HOOKS. | |
609 Execution is delayed if `delay-mode-hooks' is non-nil. | |
610 Major mode functions should use this." | |
611 (if delay-mode-hooks | |
612 ;; Delaying case. | |
613 (dolist (hook hooks) | |
614 (push hook delayed-mode-hooks)) | |
615 ;; Normal case, just run the hook as before plus any delayed hooks. | |
616 (setq hooks (nconc (nreverse delayed-mode-hooks) hooks)) | |
617 (setq delayed-mode-hooks nil) | |
618 (apply 'run-hooks hooks))) | |
619 | |
620 (defmacro delay-mode-hooks (&rest body) | |
621 "Execute BODY, but delay any `run-mode-hooks'. | |
622 Only affects hooks run in the current buffer." | |
623 `(progn | |
624 (make-local-variable 'delay-mode-hooks) | |
625 (let ((delay-mode-hooks t)) | |
626 ,@body))) | |
627 | |
1333 | 628 (defmacro with-syntax-table (table &rest body) |
629 "Evaluate BODY with syntax table of current buffer set to a copy of TABLE. | |
630 The syntax table of the current buffer is saved, BODY is evaluated, and the | |
631 saved table is restored, even in case of an abnormal exit. | |
632 Value is what BODY returns." | |
633 (let ((old-table (make-symbol "table")) | |
634 (old-buffer (make-symbol "buffer"))) | |
635 `(let ((,old-table (syntax-table)) | |
636 (,old-buffer (current-buffer))) | |
637 (unwind-protect | |
638 (progn | |
639 (set-syntax-table (copy-syntax-table ,table)) | |
640 ,@body) | |
641 (save-current-buffer | |
642 (set-buffer ,old-buffer) | |
643 (set-syntax-table ,old-table)))))) | |
644 | |
645 (put 'with-syntax-table 'lisp-indent-function 1) | |
646 (put 'with-syntax-table 'edebug-form-spec '(form body)) | |
647 | |
648 | |
649 ;; Moved from mule-coding.el. | |
650 (defmacro with-string-as-buffer-contents (str &rest body) | |
651 "With the contents of the current buffer being STR, run BODY. | |
4516
e96f3aca4d63
Document initial position of point in `with-string-as-buffer-contents'.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4504
diff
changeset
|
652 Point starts positioned to end of buffer. |
1333 | 653 Returns the new contents of the buffer, as modified by BODY. |
654 The original current buffer is restored afterwards." | |
655 `(with-temp-buffer | |
656 (insert ,str) | |
657 ,@body | |
658 (buffer-string))) | |
659 | |
660 | |
661 (defmacro save-match-data (&rest body) | |
662 "Execute BODY forms, restoring the global value of the match data." | |
663 (let ((original (make-symbol "match-data"))) | |
664 (list 'let (list (list original '(match-data))) | |
665 (list 'unwind-protect | |
666 (cons 'progn body) | |
667 (list 'store-match-data original))))) | |
668 | |
669 | |
670 (defun match-string (num &optional string) | |
671 "Return string of text matched by last search. | |
672 NUM specifies which parenthesized expression in the last regexp. | |
673 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
674 Zero means the entire text matched by the whole regexp or whole string. | |
675 STRING should be given if the last search was by `string-match' on STRING." | |
676 (if (match-beginning num) | |
677 (if string | |
678 (substring string (match-beginning num) (match-end num)) | |
679 (buffer-substring (match-beginning num) (match-end num))))) | |
801 | 680 |
1333 | 681 (defun match-string-no-properties (num &optional string) |
682 "Return string of text matched by last search, without text properties. | |
683 NUM specifies which parenthesized expression in the last regexp. | |
684 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
685 Zero means the entire text matched by the whole regexp or whole string. | |
686 STRING should be given if the last search was by `string-match' on STRING." | |
687 (if (match-beginning num) | |
688 (if string | |
689 (let ((result | |
690 (substring string (match-beginning num) (match-end num)))) | |
691 (set-text-properties 0 (length result) nil result) | |
692 result) | |
693 (buffer-substring-no-properties (match-beginning num) | |
694 (match-end num))))) | |
695 | |
1425 | 696 (defconst split-string-default-separators "[ \f\t\n\r\v]+" |
697 "The default value of separators for `split-string'. | |
698 | |
699 A regexp matching strings of whitespace. May be locale-dependent | |
700 \(as yet unimplemented). Should not match non-breaking spaces. | |
701 | |
702 Warning: binding this to a different value and using it as default is | |
703 likely to have undesired semantics.") | |
704 | |
705 ;; specification for `split-string' agreed with rms 2003-04-23 | |
706 ;; xemacs design <87vfx5vor0.fsf@tleepslib.sk.tsukuba.ac.jp> | |
707 | |
1495 | 708 ;; The specification says that if both SEPARATORS and OMIT-NULLS are |
709 ;; defaulted, OMIT-NULLS should be treated as t. Simplifying the logical | |
710 ;; expression leads to the equivalent implementation that if SEPARATORS | |
711 ;; is defaulted, OMIT-NULLS is treated as t. | |
712 | |
1425 | 713 (defun split-string (string &optional separators omit-nulls) |
714 "Splits STRING into substrings bounded by matches for SEPARATORS. | |
715 | |
716 The beginning and end of STRING, and each match for SEPARATORS, are | |
717 splitting points. The substrings matching SEPARATORS are removed, and | |
718 the substrings between the splitting points are collected as a list, | |
1333 | 719 which is returned. |
1425 | 720 |
2138 | 721 If SEPARATORS is non-`nil', it should be a regular expression matching text |
722 which separates, but is not part of, the substrings. If `nil' it defaults to | |
1495 | 723 `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\", and |
2138 | 724 OMIT-NULLS is forced to `t'. |
1333 | 725 |
2138 | 726 If OMIT-NULLS is `t', zero-length substrings are omitted from the list \(so |
1425 | 727 that for the default value of SEPARATORS leading and trailing whitespace |
2138 | 728 are effectively trimmed). If `nil', all zero-length substrings are retained, |
1425 | 729 which correctly parses CSV format, for example. |
730 | |
1495 | 731 Note that the effect of `(split-string STRING)' is the same as |
732 `(split-string STRING split-string-default-separators t)'). In the rare | |
733 case that you wish to retain zero-length substrings when splitting on | |
734 whitespace, use `(split-string STRING split-string-default-separators nil)'. | |
1333 | 735 |
2138 | 736 Modifies the match data when successful; use `save-match-data' if necessary." |
1425 | 737 |
1495 | 738 (let ((keep-nulls (not (if separators omit-nulls t))) |
1425 | 739 (rexp (or separators split-string-default-separators)) |
1333 | 740 (start 0) |
741 notfirst | |
742 (list nil)) | |
743 (while (and (string-match rexp string | |
744 (if (and notfirst | |
745 (= start (match-beginning 0)) | |
746 (< start (length string))) | |
747 (1+ start) start)) | |
1425 | 748 (< start (length string))) |
1333 | 749 (setq notfirst t) |
1425 | 750 (if (or keep-nulls (< start (match-beginning 0))) |
1333 | 751 (setq list |
752 (cons (substring string start (match-beginning 0)) | |
753 list))) | |
754 (setq start (match-end 0))) | |
1425 | 755 (if (or keep-nulls (< start (length string))) |
1333 | 756 (setq list |
757 (cons (substring string start) | |
758 list))) | |
759 (nreverse list))) | |
760 | |
761 (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
762 "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
763 Unless optional argument INPLACE is non-nil, return a new string." | |
764 (let ((i (length string)) | |
765 (newstr (if inplace string (copy-sequence string)))) | |
766 (while (> i 0) | |
767 (setq i (1- i)) | |
768 (if (eq (aref newstr i) fromchar) | |
769 (aset newstr i tochar))) | |
770 newstr)) | |
771 | |
772 | |
773 ;; XEmacs addition: | |
428 | 774 (defun replace-in-string (str regexp newtext &optional literal) |
775 "Replace all matches in STR for REGEXP with NEWTEXT string, | |
776 and returns the new string. | |
777 Optional LITERAL non-nil means do a literal replacement. | |
442 | 778 Otherwise treat `\\' in NEWTEXT as special: |
779 `\\&' in NEWTEXT means substitute original matched text. | |
780 `\\N' means substitute what matched the Nth `\\(...\\)'. | |
781 If Nth parens didn't match, substitute nothing. | |
782 `\\\\' means insert one `\\'. | |
783 `\\u' means upcase the next character. | |
784 `\\l' means downcase the next character. | |
785 `\\U' means begin upcasing all following characters. | |
786 `\\L' means begin downcasing all following characters. | |
787 `\\E' means terminate the effect of any `\\U' or `\\L'." | |
428 | 788 (check-argument-type 'stringp str) |
789 (check-argument-type 'stringp newtext) | |
442 | 790 (if (> (length str) 50) |
924 | 791 (let ((cfs case-fold-search)) |
792 (with-temp-buffer | |
793 (setq case-fold-search cfs) | |
794 (insert str) | |
795 (goto-char 1) | |
442 | 796 (while (re-search-forward regexp nil t) |
797 (replace-match newtext t literal)) | |
924 | 798 (buffer-string))) |
799 (let ((start 0) newstr) | |
800 (while (string-match regexp str start) | |
801 (setq newstr (replace-match newtext t literal str) | |
802 start (+ (match-end 0) (- (length newstr) (length str))) | |
803 str newstr)) | |
804 str))) | |
428 | 805 |
1333 | 806 (defun replace-regexp-in-string (regexp rep string &optional |
807 fixedcase literal subexp start) | |
808 "Replace all matches for REGEXP with REP in STRING. | |
809 | |
810 Return a new string containing the replacements. | |
811 | |
4199 | 812 Optional arguments FIXEDCASE and LITERAL are like the arguments with |
813 the same names of function `replace-match'. If START is non-nil, | |
814 start replacements at that index in STRING. | |
815 | |
816 For compatibility with old XEmacs code and with recent GNU Emacs, the | |
817 interpretation of SUBEXP is somewhat complicated. If SUBEXP is a | |
818 buffer, it is interpreted as the buffer which provides syntax tables | |
819 and case tables for the match and replacement. If it is not a buffer, | |
820 the current buffer is used. If SUBEXP is an integer, it is the index | |
821 of the subexpression of REGEXP which is to be replaced. | |
428 | 822 |
1333 | 823 REP is either a string used as the NEWTEXT arg of `replace-match' or a |
824 function. If it is a function it is applied to each match to generate | |
825 the replacement passed to `replace-match'; the match-data at this | |
4199 | 826 point are such that `(match-string SUBEXP STRING)' is the function's |
827 argument if SUBEXP is an integer \(otherwise the whole match is passed | |
828 and replaced). | |
428 | 829 |
1333 | 830 To replace only the first match (if any), make REGEXP match up to \\' |
831 and replace a sub-expression, e.g. | |
832 (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1) | |
833 => \" bar foo\" | |
4199 | 834 |
835 Signals `invalid-argument' if SUBEXP is not an integer, buffer, or nil; | |
836 or is an integer, but the indicated subexpression was not matched. | |
837 Signals `invalid-argument' if STRING is nil but the last text matched was a string, | |
838 or if STRING is a string but the last text matched was a buffer." | |
428 | 839 |
1333 | 840 ;; To avoid excessive consing from multiple matches in long strings, |
841 ;; don't just call `replace-match' continually. Walk down the | |
842 ;; string looking for matches of REGEXP and building up a (reversed) | |
843 ;; list MATCHES. This comprises segments of STRING which weren't | |
844 ;; matched interspersed with replacements for segments that were. | |
845 ;; [For a `large' number of replacments it's more efficient to | |
846 ;; operate in a temporary buffer; we can't tell from the function's | |
847 ;; args whether to choose the buffer-based implementation, though it | |
848 ;; might be reasonable to do so for long enough STRING.] | |
849 (let ((l (length string)) | |
850 (start (or start 0)) | |
4199 | 851 (expndx (if (integerp subexp) subexp 0)) |
1333 | 852 matches str mb me) |
853 (save-match-data | |
854 (while (and (< start l) (string-match regexp string start)) | |
855 (setq mb (match-beginning 0) | |
856 me (match-end 0)) | |
857 ;; If we matched the empty string, make sure we advance by one char | |
858 (when (= me mb) (setq me (min l (1+ mb)))) | |
859 ;; Generate a replacement for the matched substring. | |
860 ;; Operate only on the substring to minimize string consing. | |
861 ;; Set up match data for the substring for replacement; | |
862 ;; presumably this is likely to be faster than munging the | |
863 ;; match data directly in Lisp. | |
864 (string-match regexp (setq str (substring string mb me))) | |
865 (setq matches | |
866 (cons (replace-match (if (stringp rep) | |
867 rep | |
4199 | 868 (funcall rep (match-string expndx str))) |
869 ;; no, this subexp shouldn't be expndx | |
1333 | 870 fixedcase literal str subexp) |
871 (cons (substring string start mb) ; unmatched prefix | |
872 matches))) | |
873 (setq start me)) | |
874 ;; Reconstruct a string from the pieces. | |
875 (setq matches (cons (substring string start l) matches)) ; leftover | |
876 (apply #'concat (nreverse matches))))) | |
428 | 877 |
1333 | 878 ;; END SYNCHED WITH FSF 21.2 |
879 | |
880 | |
1899 | 881 ;; BEGIN SYNCHED WITH FSF 21.3 |
882 | |
883 (defun add-to-invisibility-spec (arg) | |
884 "Add elements to `buffer-invisibility-spec'. | |
885 See documentation for `buffer-invisibility-spec' for the kind of elements | |
886 that can be added." | |
887 (if (eq buffer-invisibility-spec t) | |
888 (setq buffer-invisibility-spec (list t))) | |
889 (setq buffer-invisibility-spec | |
890 (cons arg buffer-invisibility-spec))) | |
891 | |
892 (defun remove-from-invisibility-spec (arg) | |
893 "Remove elements from `buffer-invisibility-spec'." | |
894 (if (consp buffer-invisibility-spec) | |
895 (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec)))) | |
896 | |
897 ;; END SYNCHED WITH FSF 21.3 | |
898 | |
899 | |
1333 | 900 ;;; Basic string functions |
883 | 901 |
1333 | 902 ;; XEmacs |
903 (defun string-equal-ignore-case (str1 str2) | |
904 "Return t if two strings have identical contents, ignoring case differences. | |
905 Case is not significant. Text properties and extents are ignored. | |
906 Symbols are also allowed; their print names are used instead. | |
428 | 907 |
1333 | 908 See also `equalp'." |
909 (if (symbolp str1) | |
910 (setq str1 (symbol-name str1))) | |
911 (if (symbolp str2) | |
912 (setq str2 (symbol-name str2))) | |
913 (eq t (compare-strings str1 nil nil str2 nil nil t))) | |
428 | 914 |
915 (defun insert-face (string face) | |
916 "Insert STRING and highlight with FACE. Return the extent created." | |
917 (let ((p (point)) ext) | |
918 (insert string) | |
919 (setq ext (make-extent p (point))) | |
920 (set-extent-face ext face) | |
921 ext)) | |
922 | |
923 ;; not obsolete. | |
924 (define-function 'string= 'string-equal) | |
925 (define-function 'string< 'string-lessp) | |
926 (define-function 'int-to-string 'number-to-string) | |
927 (define-function 'string-to-int 'string-to-number) | |
928 | |
929 ;; These two names are a bit awkward, as they conflict with the normal | |
930 ;; foo-to-bar naming scheme, but CLtL2 has them, so they stay. | |
931 (define-function 'char-int 'char-to-int) | |
932 (define-function 'int-char 'int-to-char) | |
933 | |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
934 ;; XEmacs addition. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
935 (defun integer-to-bit-vector (integer &optional minlength) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
936 "Return INTEGER converted to a bit vector. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
937 Optional argument MINLENGTH gives a minimum length for the returned vector. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
938 If MINLENGTH is not given, zero high-order bits will be ignored." |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
939 (check-argument-type #'integerp integer) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
940 (setq minlength (or minlength 0)) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
941 (check-nonnegative-number minlength) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
942 (read (format (format "#*%%0%db" minlength) integer))) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
943 |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
944 ;; XEmacs addition. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
945 (defun bit-vector-to-integer (bit-vector) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
946 "Return BIT-VECTOR converted to an integer. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
947 If bignum support is available, BIT-VECTOR's length is unlimited. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
948 Otherwise the limit is the number of value bits in an Lisp integer. " |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
949 (check-argument-type #'bit-vector-p bit-vector) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
950 (setq bit-vector (prin1-to-string bit-vector)) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
951 (aset bit-vector 1 ?b) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
952 (read bit-vector)) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
953 |
771 | 954 (defun string-width (string) |
955 "Return number of columns STRING occupies when displayed. | |
956 With international (Mule) support, uses the charset-columns attribute of | |
957 the characters in STRING, which may not accurately represent the actual | |
958 display width when using a window system. With no international support, | |
959 simply returns the length of the string." | |
960 (if (featurep 'mule) | |
961 (let ((col 0) | |
962 (len (length string)) | |
963 (i 0)) | |
772 | 964 (with-fboundp '(charset-width char-charset) |
965 (while (< i len) | |
966 (setq col (+ col (charset-width (char-charset (aref string i))))) | |
967 (setq i (1+ i)))) | |
771 | 968 col) |
969 (length string))) | |
970 | |
777 | 971 (defun char-width (character) |
972 "Return number of columns a CHARACTER occupies when displayed." | |
973 (if (featurep 'mule) | |
974 (with-fboundp '(charset-width char-charset) | |
975 (charset-width (char-charset character))) | |
976 1)) | |
977 | |
978 ;; The following several functions are useful in GNU Emacs 20 because | |
979 ;; of the multibyte "characters" the internal representation of which | |
980 ;; leaks into Lisp. In XEmacs/Mule they are trivial and unnecessary. | |
981 ;; We provide them for compatibility reasons solely. | |
982 | |
983 (defun string-to-sequence (string type) | |
984 "Convert STRING to a sequence of TYPE which contains characters in STRING. | |
985 TYPE should be `list' or `vector'." | |
986 (ecase type | |
987 (list | |
4267 | 988 (append string nil)) |
777 | 989 (vector |
4267 | 990 (vconcat string)))) |
777 | 991 |
992 (defun string-to-list (string) | |
993 "Return a list of characters in STRING." | |
4267 | 994 (append string nil)) |
777 | 995 |
996 (defun string-to-vector (string) | |
997 "Return a vector of characters in STRING." | |
4267 | 998 (vconcat string)) |
777 | 999 |
1000 (defun store-substring (string idx obj) | |
1001 "Embed OBJ (string or character) at index IDX of STRING." | |
1002 (let* ((str (cond ((stringp obj) obj) | |
1003 ((characterp obj) (char-to-string obj)) | |
1004 (t (error | |
1005 "Invalid argument (should be string or character): %s" | |
1006 obj)))) | |
1007 (string-len (length string)) | |
1008 (len (length str)) | |
1009 (i 0)) | |
1010 (while (and (< i len) (< idx string-len)) | |
1011 (aset string idx (aref str i)) | |
1012 (setq idx (1+ idx) i (1+ i))) | |
1013 string)) | |
1014 | |
851 | 1015 ;; From FSF 21.1; ELLIPSES is XEmacs addition. |
1016 | |
1017 (defun truncate-string-to-width (str end-column &optional start-column padding | |
1333 | 1018 ellipses) |
777 | 1019 "Truncate string STR to end at column END-COLUMN. |
814 | 1020 The optional 3rd arg START-COLUMN, if non-nil, specifies |
777 | 1021 the starting column; that means to return the characters occupying |
1022 columns START-COLUMN ... END-COLUMN of STR. | |
1023 | |
814 | 1024 The optional 4th arg PADDING, if non-nil, specifies a padding character |
777 | 1025 to add at the end of the result if STR doesn't reach column END-COLUMN, |
1026 or if END-COLUMN comes in the middle of a character in STR. | |
1027 PADDING is also added at the beginning of the result | |
1028 if column START-COLUMN appears in the middle of a character in STR. | |
1029 | |
1030 If PADDING is nil, no padding is added in these cases, so | |
851 | 1031 the resulting string may be narrower than END-COLUMN. |
1032 | |
1033 BUG: Currently assumes that the padding character is of width one. You | |
1034 will get weird results if not. | |
1035 | |
1036 If ELLIPSES is non-nil, add ellipses (specified by ELLIPSES if a string, | |
1037 else `...') if STR extends past END-COLUMN. The ellipses will be added in | |
1038 such a way that the total string occupies no more than END-COLUMN columns | |
1039 -- i.e. if the string goes past END-COLUMN, it will be truncated somewhere | |
1040 short of END-COLUMN so that, with the ellipses added (and padding, if the | |
1041 proper place to truncate the string would be in the middle of a character), | |
1042 the string occupies exactly END-COLUMN columns." | |
777 | 1043 (or start-column |
1044 (setq start-column 0)) | |
814 | 1045 (let ((len (length str)) |
1046 (idx 0) | |
1047 (column 0) | |
1048 (head-padding "") (tail-padding "") | |
1049 ch last-column last-idx from-idx) | |
851 | 1050 |
1051 ;; find the index of START-COLUMN; bail out if end of string reached. | |
814 | 1052 (condition-case nil |
1053 (while (< column start-column) | |
1054 (setq ch (aref str idx) | |
1055 column (+ column (char-width ch)) | |
1056 idx (1+ idx))) | |
1057 (args-out-of-range (setq idx len))) | |
1058 (if (< column start-column) | |
851 | 1059 ;; if string ends before START-COLUMN, return either a blank string |
1060 ;; or a string entirely padded. | |
1061 (if padding (make-string (- end-column start-column) padding) "") | |
814 | 1062 (if (and padding (> column start-column)) |
1063 (setq head-padding (make-string (- column start-column) padding))) | |
1064 (setq from-idx idx) | |
851 | 1065 ;; If END-COLUMN is before START-COLUMN, then bail out. |
814 | 1066 (if (< end-column column) |
851 | 1067 (setq idx from-idx ellipses "") |
1068 | |
1069 ;; handle ELLIPSES | |
1070 (cond ((null ellipses) (setq ellipses "")) | |
1071 ((if (<= (string-width str) end-column) | |
1072 ;; string fits, no ellipses | |
1073 (setq ellipses ""))) | |
1074 (t | |
1075 ;; else, insert default value and ... | |
1076 (or (stringp ellipses) (setq ellipses "...")) | |
1077 ;; ... take away the width of the ellipses from the | |
1078 ;; destination. do all computations with new, shorter | |
1079 ;; width. the padding computed will get us exactly up to | |
1080 ;; the shorted width, which is right -- it just gets added | |
1081 ;; to the right of the ellipses. | |
924 | 1082 (setq end-column (- end-column (string-width ellipses))))) |
851 | 1083 |
1084 ;; find the index of END-COLUMN; bail out if end of string reached. | |
814 | 1085 (condition-case nil |
1086 (while (< column end-column) | |
1087 (setq last-column column | |
1088 last-idx idx | |
1089 ch (aref str idx) | |
1090 column (+ column (char-width ch)) | |
1091 idx (1+ idx))) | |
1092 (args-out-of-range (setq idx len))) | |
851 | 1093 ;; if we went too far (stopped in middle of character), back up. |
814 | 1094 (if (> column end-column) |
1095 (setq column last-column idx last-idx)) | |
851 | 1096 ;; compute remaining padding |
814 | 1097 (if (and padding (< column end-column)) |
1098 (setq tail-padding (make-string (- end-column column) padding)))) | |
851 | 1099 ;; get substring ... |
814 | 1100 (setq str (substring str from-idx idx)) |
851 | 1101 ;; and construct result |
814 | 1102 (if padding |
851 | 1103 (concat head-padding str tail-padding ellipses) |
1104 (concat str ellipses))))) | |
801 | 1105 |
428 | 1106 |
1107 ;; alist/plist functions | |
1108 (defun plist-to-alist (plist) | |
1109 "Convert property list PLIST into the equivalent association-list form. | |
1110 The alist is returned. This converts from | |
1111 | |
1112 \(a 1 b 2 c 3) | |
1113 | |
1114 into | |
1115 | |
1116 \((a . 1) (b . 2) (c . 3)) | |
1117 | |
1118 The original plist is not modified. See also `destructive-plist-to-alist'." | |
1119 (let (alist) | |
1120 (while plist | |
1121 (setq alist (cons (cons (car plist) (cadr plist)) alist)) | |
1122 (setq plist (cddr plist))) | |
1123 (nreverse alist))) | |
1124 | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1125 ((macro |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1126 . (lambda (map-plist-definition) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1127 "Replace the variable names in MAP-PLIST-DEFINITION with uninterned |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1128 symbols, avoiding the risk of interference with variables in other functions |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1129 introduced by dynamic scope." |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1130 (if-fboundp 'nsublis |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1131 (nsublis |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1132 '((mp-function . #:function) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1133 (plist . #:plist) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1134 (result . #:result)) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1135 map-plist-definition) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1136 map-plist-definition))) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1137 (defun map-plist (mp-function plist) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1138 "Map FUNCTION (a function of two args) over each key/value pair in PLIST. |
783 | 1139 Return a list of the results." |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1140 (let (result) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1141 (while plist |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1142 (push (funcall mp-function (car plist) (cadr plist)) result) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1143 (setq plist (cddr plist))) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1144 (nreverse result)))) |
783 | 1145 |
428 | 1146 (defun destructive-plist-to-alist (plist) |
1147 "Convert property list PLIST into the equivalent association-list form. | |
1148 The alist is returned. This converts from | |
1149 | |
1150 \(a 1 b 2 c 3) | |
1151 | |
1152 into | |
1153 | |
1154 \((a . 1) (b . 2) (c . 3)) | |
1155 | |
1156 The original plist is destroyed in the process of constructing the alist. | |
1157 See also `plist-to-alist'." | |
1158 (let ((head plist) | |
1159 next) | |
1160 (while plist | |
1161 ;; remember the next plist pair. | |
1162 (setq next (cddr plist)) | |
1163 ;; make the cons holding the property value into the alist element. | |
1164 (setcdr (cdr plist) (cadr plist)) | |
1165 (setcar (cdr plist) (car plist)) | |
1166 ;; reattach into alist form. | |
1167 (setcar plist (cdr plist)) | |
1168 (setcdr plist next) | |
1169 (setq plist next)) | |
1170 head)) | |
1171 | |
1172 (defun alist-to-plist (alist) | |
1173 "Convert association list ALIST into the equivalent property-list form. | |
1174 The plist is returned. This converts from | |
1175 | |
1176 \((a . 1) (b . 2) (c . 3)) | |
1177 | |
1178 into | |
1179 | |
1180 \(a 1 b 2 c 3) | |
1181 | |
1182 The original alist is not modified. See also `destructive-alist-to-plist'." | |
1183 (let (plist) | |
1184 (while alist | |
1185 (let ((el (car alist))) | |
1186 (setq plist (cons (cdr el) (cons (car el) plist)))) | |
1187 (setq alist (cdr alist))) | |
1188 (nreverse plist))) | |
1189 | |
1190 ;; getf, remf in cl*.el. | |
1191 | |
444 | 1192 (defmacro putf (plist property value) |
1193 "Add property PROPERTY to plist PLIST with value VALUE. | |
1194 Analogous to (setq PLIST (plist-put PLIST PROPERTY VALUE))." | |
1195 `(setq ,plist (plist-put ,plist ,property ,value))) | |
428 | 1196 |
444 | 1197 (defmacro laxputf (lax-plist property value) |
1198 "Add property PROPERTY to lax plist LAX-PLIST with value VALUE. | |
1199 Analogous to (setq LAX-PLIST (lax-plist-put LAX-PLIST PROPERTY VALUE))." | |
1200 `(setq ,lax-plist (lax-plist-put ,lax-plist ,property ,value))) | |
428 | 1201 |
444 | 1202 (defmacro laxremf (lax-plist property) |
1203 "Remove property PROPERTY from lax plist LAX-PLIST. | |
1204 Analogous to (setq LAX-PLIST (lax-plist-remprop LAX-PLIST PROPERTY))." | |
1205 `(setq ,lax-plist (lax-plist-remprop ,lax-plist ,property))) | |
428 | 1206 |
1207 ;;; Error functions | |
1208 | |
442 | 1209 (defun error (datum &rest args) |
1210 "Signal a non-continuable error. | |
1211 DATUM should normally be an error symbol, i.e. a symbol defined using | |
1212 `define-error'. ARGS will be made into a list, and DATUM and ARGS passed | |
1213 as the two arguments to `signal', the most basic error handling function. | |
1214 | |
428 | 1215 This error is not continuable: you cannot continue execution after the |
442 | 1216 error using the debugger `r' command. See also `cerror'. |
1217 | |
1218 The correct semantics of ARGS varies from error to error, but for most | |
1219 errors that need to be generated in Lisp code, the first argument | |
1220 should be a string describing the *context* of the error (i.e. the | |
1221 exact operation being performed and what went wrong), and the remaining | |
1222 arguments or \"frobs\" (most often, there is one) specify the | |
1223 offending object(s) and/or provide additional details such as the exact | |
1224 error when a file error occurred, e.g.: | |
1225 | |
1226 -- the buffer in which an editing error occurred. | |
1227 -- an invalid value that was encountered. (In such cases, the string | |
1228 should describe the purpose or \"semantics\" of the value [e.g. if the | |
1229 value is an argument to a function, the name of the argument; if the value | |
1230 is the value corresponding to a keyword, the name of the keyword; if the | |
1231 value is supposed to be a list length, say this and say what the purpose | |
1232 of the list is; etc.] as well as specifying why the value is invalid, if | |
1233 that's not self-evident.) | |
1234 -- the file in which an error occurred. (In such cases, there should be a | |
1235 second frob, probably a string, specifying the exact error that occurred. | |
1236 This does not occur in the string that precedes the first frob, because | |
1237 that frob describes the exact operation that was happening. | |
1238 | |
1239 For historical compatibility, DATUM can also be a string. In this case, | |
1240 DATUM and ARGS are passed together as the arguments to `format', and then | |
1241 an error is signalled using the error symbol `error' and formatted string. | |
1242 Although this usage of `error' is very common, it is deprecated because it | |
1243 totally defeats the purpose of having structured errors. There is now | |
1244 a rich set of defined errors you can use: | |
1245 | |
563 | 1246 quit |
1247 | |
442 | 1248 error |
1249 invalid-argument | |
563 | 1250 syntax-error |
1251 invalid-read-syntax | |
1252 invalid-regexp | |
1253 structure-formation-error | |
1254 list-formation-error | |
1255 malformed-list | |
1256 malformed-property-list | |
1257 circular-list | |
1258 circular-property-list | |
1259 invalid-function | |
1260 no-catch | |
1261 undefined-keystroke-sequence | |
1262 invalid-constant | |
442 | 1263 wrong-type-argument |
1264 args-out-of-range | |
1265 wrong-number-of-arguments | |
428 | 1266 |
442 | 1267 invalid-state |
1268 void-function | |
1269 cyclic-function-indirection | |
1270 void-variable | |
1271 cyclic-variable-indirection | |
509 | 1272 invalid-byte-code |
563 | 1273 stack-overflow |
1274 out-of-memory | |
1275 invalid-key-binding | |
1276 internal-error | |
442 | 1277 |
1278 invalid-operation | |
1279 invalid-change | |
1280 setting-constant | |
563 | 1281 protected-field |
442 | 1282 editing-error |
1283 beginning-of-buffer | |
1284 end-of-buffer | |
1285 buffer-read-only | |
1286 io-error | |
509 | 1287 file-error |
1288 file-already-exists | |
1289 file-locked | |
1290 file-supersession | |
563 | 1291 end-of-file |
1292 process-error | |
1293 network-error | |
509 | 1294 tooltalk-error |
563 | 1295 gui-error |
1296 dialog-box-error | |
1297 sound-error | |
1298 conversion-error | |
1299 text-conversion-error | |
1300 image-conversion-error | |
1301 base64-conversion-error | |
1302 selection-conversion-error | |
442 | 1303 arith-error |
1304 range-error | |
1305 domain-error | |
1306 singularity-error | |
1307 overflow-error | |
1308 underflow-error | |
509 | 1309 search-failed |
563 | 1310 printing-unreadable-object |
1311 unimplemented | |
509 | 1312 |
563 | 1313 Note the semantic differences between some of the more common errors: |
442 | 1314 |
563 | 1315 -- `invalid-argument' is for all cases where a bad value is encountered. |
1316 -- `invalid-constant' is for arguments where only a specific set of values | |
1317 is allowed. | |
1318 -- `syntax-error' is when complex structures (parsed strings, lists, | |
1319 and the like) are badly formed. If the problem is just a single bad | |
1320 value inside the structure, you should probably be using something else, | |
1321 e.g. `invalid-constant', `wrong-type-argument', or `invalid-argument'. | |
442 | 1322 -- `invalid-state' means that some settings have been changed in such a way |
1323 that their current state is unallowable. More and more, code is being | |
1324 written more carefully, and catches the error when the settings are being | |
1325 changed, rather than afterwards. This leads us to the next error: | |
1326 -- `invalid-change' means that an attempt is being made to change some settings | |
1327 into an invalid state. `invalid-change' is a type of `invalid-operation'. | |
1328 -- `invalid-operation' refers to all cases where code is trying to do something | |
563 | 1329 that's disallowed, or when an error occurred during an operation. (These |
1330 two concepts are merged because there's no clear distinction between them.) | |
1331 -- `io-error' refers to errors involving interaction with any external | |
1332 components (files, other programs, the operating system, etc). | |
442 | 1333 |
1334 See also `cerror', `signal', and `signal-error'." | |
1335 (while t (apply | |
1336 'cerror datum args))) | |
1337 | |
1338 (defun cerror (datum &rest args) | |
428 | 1339 "Like `error' but signals a continuable error." |
442 | 1340 (cond ((stringp datum) |
1341 (signal 'error (list (apply 'format datum args)))) | |
1342 ((defined-error-p datum) | |
1343 (signal datum args)) | |
1344 (t | |
1345 (error 'invalid-argument "datum not string or error symbol" datum)))) | |
428 | 1346 |
1347 (defmacro check-argument-type (predicate argument) | |
1348 "Check that ARGUMENT satisfies PREDICATE. | |
442 | 1349 This is a macro, and ARGUMENT is not evaluated. If ARGUMENT is an lvalue, |
1350 this function signals a continuable `wrong-type-argument' error until the | |
1351 returned value satisfies PREDICATE, and assigns the returned value | |
1352 to ARGUMENT. Otherwise, this function signals a non-continuable | |
1353 `wrong-type-argument' error if the returned value does not satisfy PREDICATE." | |
1354 (if (symbolp argument) | |
1355 `(if (not (,(eval predicate) ,argument)) | |
1356 (setq ,argument | |
1357 (wrong-type-argument ,predicate ,argument))) | |
1358 `(if (not (,(eval predicate) ,argument)) | |
1359 (signal-error 'wrong-type-argument (list ,predicate ,argument))))) | |
428 | 1360 |
872 | 1361 (defun args-out-of-range (value min max) |
1362 "Signal an error until the correct in-range value is given by the user. | |
1363 This function loops, signalling a continuable `args-out-of-range' error | |
1364 with VALUE, MIN and MAX as the data associated with the error and then | |
1365 checking the returned value to make sure it's not outside the given | |
1366 boundaries \(nil for either means no boundary on that side). At that | |
1367 point, the gotten value is returned." | |
1368 (loop | |
1369 for newval = (signal 'args-out-of-range (list value min max)) | |
1370 do (setq value newval) | |
1371 finally return value | |
1372 while (not (argument-in-range-p value min max)))) | |
1373 | |
1374 (defun argument-in-range-p (argument min max) | |
1375 "Return true if ARGUMENT is within the range of [MIN, MAX]. | |
1376 This includes boundaries. nil for either value means no limit on that side." | |
1377 (and (or (not min) (<= min argument)) | |
1378 (or (not max) (<= argument max)))) | |
1379 | |
1380 (defmacro check-argument-range (argument min max) | |
1381 "Check that ARGUMENT is within the range [MIN, MAX]. | |
1382 This is a macro, and ARGUMENT is not evaluated. If ARGUMENT is an lvalue, | |
1383 this function signals a continuable `args-out-of-range' error until the | |
1384 returned value is within range, and assigns the returned value | |
1385 to ARGUMENT. Otherwise, this function signals a non-continuable | |
1386 `args-out-of-range' error if the returned value is out of range." | |
1387 (if (symbolp argument) | |
1388 `(if (not (argument-in-range-p ,argument ,min ,max)) | |
924 | 1389 (setq ,argument |
1390 (args-out-of-range ,argument ,min ,max))) | |
872 | 1391 (let ((newsym (gensym))) |
1392 `(let ((,newsym ,argument)) | |
924 | 1393 (if (not (argument-in-range-p ,newsym ,min ,max)) |
4103 | 1394 (signal-error 'args-out-of-range (list ,newsym ,min ,max))))))) |
872 | 1395 |
428 | 1396 (defun signal-error (error-symbol data) |
1397 "Signal a non-continuable error. Args are ERROR-SYMBOL, and associated DATA. | |
1398 An error symbol is a symbol defined using `define-error'. | |
1399 DATA should be a list. Its elements are printed as part of the error message. | |
1400 If the signal is handled, DATA is made available to the handler. | |
1401 See also `signal', and the functions to handle errors: `condition-case' | |
1402 and `call-with-condition-handler'." | |
1403 (while t | |
1404 (signal error-symbol data))) | |
1405 | |
1406 (defun define-error (error-sym doc-string &optional inherits-from) | |
1407 "Define a new error, denoted by ERROR-SYM. | |
1408 DOC-STRING is an informative message explaining the error, and will be | |
1409 printed out when an unhandled error occurs. | |
1410 ERROR-SYM is a sub-error of INHERITS-FROM (which defaults to `error'). | |
1411 | |
1412 \[`define-error' internally works by putting on ERROR-SYM an `error-message' | |
1413 property whose value is DOC-STRING, and an `error-conditions' property | |
1414 that is a list of ERROR-SYM followed by each of its super-errors, up | |
1415 to and including `error'. You will sometimes see code that sets this up | |
1416 directly rather than calling `define-error', but you should *not* do this | |
1417 yourself.]" | |
1418 (check-argument-type 'symbolp error-sym) | |
1419 (check-argument-type 'stringp doc-string) | |
1420 (put error-sym 'error-message doc-string) | |
1421 (or inherits-from (setq inherits-from 'error)) | |
1422 (let ((conds (get inherits-from 'error-conditions))) | |
1423 (or conds (signal-error 'error (list "Not an error symbol" error-sym))) | |
1424 (put error-sym 'error-conditions (cons error-sym conds)))) | |
1425 | |
442 | 1426 (defun defined-error-p (sym) |
1427 "Returns non-nil if SYM names a currently-defined error." | |
1428 (and (symbolp sym) (not (null (get sym 'error-conditions))))) | |
1429 | |
793 | 1430 (defun backtrace-in-condition-handler-eliminating-handler (handler-arg-name) |
1431 "Return a backtrace inside of a condition handler, eliminating the handler. | |
1432 This is for use in the condition handler inside of call-with-condition-handler, | |
1433 when written like this: | |
1434 | |
1435 \(call-with-condition-handler | |
1436 #'(lambda (__some_weird_arg__) | |
1437 do the handling ...) | |
1438 #'(lambda () | |
1439 do the stuff that might cause an error)) | |
1440 | |
1441 Pass in the name (a symbol) of the argument used in the lambda function | |
1442 that specifies the handler, and make sure the argument name is unique, and | |
1443 this function generates a backtrace and strips off the part above where the | |
1444 error occurred (i.e. the handler itself)." | |
1445 (let* ((bt (with-output-to-string (backtrace nil t))) | |
1446 (bt (save-match-data | |
1447 ;; Try to eliminate the part of the backtrace | |
1448 ;; above where the error occurred. | |
1449 (if (string-match | |
1450 (concat "bind (\\(?:.* \\)?" (symbol-name handler-arg-name) | |
1451 "\\(?:.* \\)?)[ \t\n]*\\(?:(lambda \\|#<compiled-function \\)(" | |
1452 (symbol-name handler-arg-name) | |
1453 ").*\n\\(\\(?:.\\|\n\\)*\\)$") | |
1454 bt) (match-string 1 bt) bt)))) | |
1455 bt)) | |
1456 | |
1457 (put 'with-trapping-errors 'lisp-indent-function 0) | |
1458 (defmacro with-trapping-errors (&rest keys-body) | |
1459 "Trap errors in BODY, outputting a warning and a backtrace. | |
1460 Usage looks like | |
1461 | |
1462 \(with-trapping-errors | |
1463 [:operation OPERATION] | |
1464 [:error-form ERROR-FORM] | |
1465 [:no-backtrace NO-BACKTRACE] | |
1466 [:class CLASS] | |
1467 [:level LEVEL] | |
1468 [:resignal RESIGNAL] | |
1469 BODY) | |
1470 | |
1471 Return value without error is whatever BODY returns. With error, return | |
1472 result of ERROR-FORM (which will be evaluated only when the error actually | |
1473 occurs), which defaults to nil. OPERATION is given in the warning message. | |
1474 CLASS and LEVEL are the warning class and level (default to class | |
1475 `general', level `warning'). If NO-BACKTRACE is given, no backtrace is | |
1476 displayed. If RESIGNAL is given, the error is resignaled after the warning | |
1477 is displayed and the ERROR-FORM is executed." | |
1478 (let ((operation "unknown") | |
1479 (error-form nil) | |
1480 (no-backtrace nil) | |
1481 (class ''general) | |
1482 (level ''warning) | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1483 (resignal nil) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1484 (cte-cc-var '#:cte-cc-var) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1485 (call-trapping-errors-arg '#:call-trapping-errors-Ldc9FC5Hr)) |
793 | 1486 (let* ((keys '(operation error-form no-backtrace class level resignal)) |
1487 (keys-with-colon | |
1488 (mapcar #'(lambda (sym) | |
1489 (intern (concat ":" (symbol-name sym)))) keys))) | |
1490 (while (memq (car keys-body) keys-with-colon) | |
1491 (let* ((key-with-colon (pop keys-body)) | |
1492 (key (intern (substring (symbol-name key-with-colon) 1)))) | |
1493 (set key (pop keys-body))))) | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1494 `(condition-case ,(if resignal cte-cc-var nil) |
793 | 1495 (call-with-condition-handler |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1496 #'(lambda (,call-trapping-errors-arg) |
793 | 1497 (let ((errstr (error-message-string |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1498 ,call-trapping-errors-arg))) |
793 | 1499 ,(if no-backtrace |
1500 `(lwarn ,class ,level | |
1501 (if (warning-level-< | |
1502 ,level | |
1503 display-warning-minimum-level) | |
1504 "Error in %s: %s" | |
1505 "Error in %s:\n%s\n") | |
1506 ,operation errstr) | |
1507 `(lwarn ,class ,level | |
1508 "Error in %s: %s\n\nBacktrace follows:\n\n%s" | |
1509 ,operation errstr | |
1510 (backtrace-in-condition-handler-eliminating-handler | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1511 ',call-trapping-errors-arg))))) |
793 | 1512 #'(lambda () |
1513 (progn ,@keys-body))) | |
1514 (error | |
1515 ,error-form | |
4817
0142cb4d1049
Fix a bug I introduced in #'with-trapping-errors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
1516 ,@(if resignal `((signal (car ,cte-cc-var) (cdr ,cte-cc-var))))) |
793 | 1517 ))) |
1518 | |
428 | 1519 ;;;; Miscellanea. |
1520 | |
1521 ;; This is now in C. | |
444 | 1522 ;(defun buffer-substring-no-properties (start end) |
1523 ; "Return the text from START to END, without text properties, as a string." | |
1524 ; (let ((string (buffer-substring start end))) | |
428 | 1525 ; (set-text-properties 0 (length string) nil string) |
1526 ; string)) | |
1527 | |
1528 (defun get-buffer-window-list (&optional buffer minibuf frame) | |
1529 "Return windows currently displaying BUFFER, or nil if none. | |
1530 BUFFER defaults to the current buffer. | |
1531 See `walk-windows' for the meaning of MINIBUF and FRAME." | |
1532 (cond ((null buffer) | |
1533 (setq buffer (current-buffer))) | |
1534 ((not (bufferp buffer)) | |
1535 (setq buffer (get-buffer buffer)))) | |
1536 (let (windows) | |
1537 (walk-windows (lambda (window) | |
1538 (if (eq (window-buffer window) buffer) | |
1539 (push window windows))) | |
1540 minibuf frame) | |
1541 windows)) | |
1542 | |
1543 (defun ignore (&rest ignore) | |
1544 "Do nothing and return nil. | |
1545 This function accepts any number of arguments, but ignores them." | |
1546 (interactive) | |
1547 nil) | |
1548 | |
883 | 1549 ;; defined in lisp/bindings.el in GNU Emacs. |
1550 (defmacro bound-and-true-p (var) | |
1551 "Return the value of symbol VAR if it is bound, else nil." | |
1552 `(and (boundp (quote ,var)) ,var)) | |
1553 | |
1554 ;; `propertize' is a builtin in GNU Emacs 21. | |
1555 (defun propertize (string &rest properties) | |
1556 "Return a copy of STRING with text properties added. | |
1557 First argument is the string to copy. | |
1558 Remaining arguments form a sequence of PROPERTY VALUE pairs for text | |
1559 properties to add to the result." | |
1560 (let ((str (copy-sequence string))) | |
1561 (add-text-properties 0 (length str) | |
1562 properties | |
1563 str) | |
1564 str)) | |
1565 | |
1566 ;; `delete-and-extract-region' is a builtin in GNU Emacs 21. | |
1567 (defun delete-and-extract-region (start end) | |
1568 "Delete the text between START and END and return it." | |
1569 (let ((region (buffer-substring start end))) | |
1570 (delete-region start end) | |
1571 region)) | |
1572 | |
428 | 1573 (define-function 'eval-in-buffer 'with-current-buffer) |
1574 (make-obsolete 'eval-in-buffer 'with-current-buffer) | |
1575 | |
1576 ;;; The real defn is in abbrev.el but some early callers | |
1577 ;;; (eg lisp-mode-abbrev-table) want this before abbrev.el is loaded... | |
1578 | |
1579 (if (not (fboundp 'define-abbrev-table)) | |
1580 (progn | |
1581 (setq abbrev-table-name-list '()) | |
924 | 1582 (fset 'define-abbrev-table |
1583 (function (lambda (name defs) | |
1584 ;; These are fixed-up when abbrev.el loads. | |
1585 (setq abbrev-table-name-list | |
1586 (cons (cons name defs) | |
1587 abbrev-table-name-list))))))) | |
428 | 1588 |
1589 ;;; `functionp' has been moved into C. | |
1590 | |
1591 ;;(defun functionp (object) | |
1592 ;; "Non-nil if OBJECT can be called as a function." | |
1593 ;; (or (and (symbolp object) (fboundp object)) | |
1594 ;; (subrp object) | |
1595 ;; (compiled-function-p object) | |
1596 ;; (eq (car-safe object) 'lambda))) | |
1597 | |
1598 (defun function-interactive (function) | |
1599 "Return the interactive specification of FUNCTION. | |
1600 FUNCTION can be any funcallable object. | |
1601 The specification will be returned as the list of the symbol `interactive' | |
1602 and the specs. | |
1603 If FUNCTION is not interactive, nil will be returned." | |
1604 (setq function (indirect-function function)) | |
1605 (cond ((compiled-function-p function) | |
1606 (compiled-function-interactive function)) | |
1607 ((subrp function) | |
1608 (subr-interactive function)) | |
1609 ((eq (car-safe function) 'lambda) | |
1610 (let ((spec (if (stringp (nth 2 function)) | |
1611 (nth 3 function) | |
1612 (nth 2 function)))) | |
1613 (and (eq (car-safe spec) 'interactive) | |
1614 spec))) | |
1615 (t | |
1616 (error "Non-funcallable object: %s" function)))) | |
1617 | |
442 | 1618 (defun function-allows-args (function n) |
1619 "Return whether FUNCTION can be called with N arguments." | |
1620 (and (<= (function-min-args function) n) | |
1621 (or (null (function-max-args function)) | |
1622 (<= n (function-max-args function))))) | |
1623 | |
428 | 1624 ;; This function used to be an alias to `buffer-substring', except |
1625 ;; that FSF Emacs 20.4 added a BUFFER argument in an incompatible way. | |
1626 ;; The new FSF's semantics makes more sense, but we try to support | |
1627 ;; both for backward compatibility. | |
1628 (defun buffer-string (&optional buffer old-end old-buffer) | |
1629 "Return the contents of the current buffer as a string. | |
1630 If narrowing is in effect, this function returns only the visible part | |
1631 of the buffer. | |
1632 | |
1633 If BUFFER is specified, the contents of that buffer are returned. | |
1634 | |
1635 The arguments OLD-END and OLD-BUFFER are supported for backward | |
1636 compatibility with pre-21.2 XEmacsen times when arguments to this | |
1637 function were (buffer-string &optional START END BUFFER)." | |
1638 (cond | |
1639 ((or (stringp buffer) (bufferp buffer)) | |
1640 ;; Most definitely the new way. | |
1641 (buffer-substring nil nil buffer)) | |
1642 ((or (stringp old-buffer) (bufferp old-buffer) | |
1643 (natnump buffer) (natnump old-end)) | |
1644 ;; Definitely the old way. | |
1645 (buffer-substring buffer old-end old-buffer)) | |
1646 (t | |
1647 ;; Probably the old way. | |
1648 (buffer-substring buffer old-end old-buffer)))) | |
1649 | |
1333 | 1650 ;; BEGIN SYNC WITH FSF 21.2 |
1651 | |
428 | 1652 ;; This was not present before. I think Jamie had some objections |
1653 ;; to this, so I'm leaving this undefined for now. --ben | |
1654 | |
1655 ;;; The objection is this: there is more than one way to load the same file. | |
1656 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different | |
1657 ;;; ways to load the exact same code. `eval-after-load' is too stupid to | |
1658 ;;; deal with this sort of thing. If this sort of feature is desired, then | |
1659 ;;; it should work off of a hook on `provide'. Features are unique and | |
1660 ;;; the arguments to (load) are not. --Stig | |
1661 | |
1662 ;; We provide this for FSFmacs compatibility, at least until we devise | |
1663 ;; something better. | |
1664 | |
1665 ;;;; Specifying things to do after certain files are loaded. | |
1666 | |
1667 (defun eval-after-load (file form) | |
1668 "Arrange that, if FILE is ever loaded, FORM will be run at that time. | |
1669 This makes or adds to an entry on `after-load-alist'. | |
1670 If FILE is already loaded, evaluate FORM right now. | |
1671 It does nothing if FORM is already on the list for FILE. | |
1333 | 1672 FILE must match exactly. Normally FILE is the name of a library, |
1673 with no directory or extension specified, since that is how `load' | |
1674 is normally called." | |
1675 ;; Make sure `load-history' contains the files dumped with Emacs | |
1676 ;; for the case that FILE is one of the files dumped with Emacs. | |
1677 (if-fboundp 'load-symbol-file-load-history | |
1678 (load-symbol-file-load-history)) | |
428 | 1679 ;; Make sure there is an element for FILE. |
1680 (or (assoc file after-load-alist) | |
1681 (setq after-load-alist (cons (list file) after-load-alist))) | |
1682 ;; Add FORM to the element if it isn't there. | |
1683 (let ((elt (assoc file after-load-alist))) | |
1684 (or (member form (cdr elt)) | |
1685 (progn | |
1686 (nconc elt (list form)) | |
1687 ;; If the file has been loaded already, run FORM right away. | |
1688 (and (assoc file load-history) | |
1689 (eval form))))) | |
1690 form) | |
1691 (make-compatible 'eval-after-load "") | |
1692 | |
1693 (defun eval-next-after-load (file) | |
1694 "Read the following input sexp, and run it whenever FILE is loaded. | |
1695 This makes or adds to an entry on `after-load-alist'. | |
1696 FILE should be the name of a library, with no directory name." | |
1697 (eval-after-load file (read))) | |
1698 (make-compatible 'eval-next-after-load "") | |
1699 | |
1333 | 1700 ;; END SYNC WITH FSF 21.2 |
428 | 1701 |
3000 | 1702 ;; BEGIN SYNC WITH FSF 22.0.50.1 (CVS) |
1703 (defun delete-dups (list) | |
1704 "Destructively remove `equal' duplicates from LIST. | |
1705 Store the result in LIST and return it. LIST must be a proper list. | |
1706 Of several `equal' occurrences of an element in LIST, the first | |
1707 one is kept." | |
1708 (let ((tail list)) | |
1709 (while tail | |
1710 (setcdr tail (delete (car tail) (cdr tail))) | |
1711 (setq tail (cdr tail)))) | |
1712 list) | |
1713 | |
1714 ;; END SYNC WITH FSF 22.0.50.1 (CVS) | |
1715 | |
2525 | 1716 ;; (defun shell-quote-argument (argument) in process.el. |
1717 | |
1718 ;; (defun make-syntax-table (&optional oldtable) in syntax.el. | |
1719 | |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1720 ;; (defun syntax-after (pos) in syntax.el. |
2525 | 1721 |
1722 ;; global-set-key, local-set-key, global-unset-key, local-unset-key in | |
1723 ;; keymap.el. | |
1724 | |
1725 ;; frame-configuration-p is in frame.el. | |
1726 | |
1727 ;; functionp is built-in. | |
1728 | |
1729 ;; interactive-form in obsolete.el. | |
1730 | |
1731 ;; assq-del-all in obsolete.el. | |
1732 | |
4266 | 1733 ;; make-temp-file in files.el. |
2525 | 1734 |
1735 ;; add-minor-mode in modeline.el. | |
1736 | |
1737 ;; text-clone stuff #### doesn't exist; should go in text-props.el and | |
1738 ;; requires changes to extents.c (modification hooks). | |
1739 | |
1740 ;; play-sound is built-in. | |
1741 | |
1742 ;; define-mail-user-agent is in simple.el. | |
1743 | |
4501
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1744 ;; XEmacs; added. |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1745 (defun skip-chars-quote (string) |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1746 "Return a string that means all characters in STRING will be skipped, |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1747 if passed to `skip-chars-forward' or `skip-chars-backward'. |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1748 |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1749 Ranges and carets are not treated specially. This implementation is |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1750 in Lisp; do not use it in performance-critical code." |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1751 (let ((list (delete-duplicates (string-to-list string) :test #'=))) |
4504
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1752 (when (/= 1 (length list)) ;; No quoting needed in a string of length 1. |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1753 (when (eq ?^ (car list)) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1754 (setq list (nconc (cdr list) '(?^)))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1755 (when (memq ?\\ list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1756 (setq list (delq ?\\ list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1757 list (nconc (list ?\\ ?\\) list))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1758 (when (memq ?- list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1759 (setq list (delq ?- list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1760 list (nconc list '(?\\ ?-))))) |
4501
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1761 (apply #'string list))) |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1762 |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1763 ;; XEmacs addition to subr.el; docstring and API taken initially from GNU's |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1764 ;; data.c, revision 1.275, GPLv2. |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1765 (defun subr-arity (subr) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1766 "Return minimum and maximum number of args allowed for SUBR. |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1767 SUBR must be a built-in function (not just a symbol that refers to one). |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1768 The returned value is a pair (MIN . MAX). MIN is the minimum number |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1769 of args. MAX is the maximum number or the symbol `many', for a |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
1770 function with `&rest' args, or `unevalled' for a special operator. |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1771 |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
1772 See also `special-operator-p', `subr-min-args', `subr-max-args', |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1773 `function-allows-args'. " |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1774 (check-argument-type #'subrp subr) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1775 (cons (subr-min-args subr) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1776 (cond |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
1777 ((special-operator-p subr) |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1778 'unevalled) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1779 ((null (subr-max-args subr)) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1780 'many) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1781 (t (subr-max-args subr))))) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1782 |
5004
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1783 ;; XEmacs; move these here from C. Would be nice to drop them entirely, but |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1784 ;; they're used reasonably often, since they've been around for a long time |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1785 ;; and they're portable to GNU. |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1786 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
1787 ;; No longer used in C, now list_merge() accepts a KEY argument. |
5004
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1788 (defun car-less-than-car (a b) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1789 "Return t if the car of A is numerically less than the car of B." |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1790 (< (car a) (car b))) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1791 |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1792 ;; Used in packages. |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1793 (defun cdr-less-than-cdr (a b) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1794 "Return t if (cdr A) is numerically less than (cdr B)." |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1795 (< (cdr a) (cdr b))) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1796 |
428 | 1797 ;;; subr.el ends here |