0
|
1 ;;; subr.el --- basic lisp subroutines for XEmacs
|
|
2
|
|
3 ;;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
|
|
4 ;;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
5 ;;; Copyright (C) 1995 Sun Microsystems.
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
72
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
|
23
|
|
24 ;;; Synched up with: FSF 19.34.
|
0
|
25
|
72
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; There's not a whole lot in common now with the FSF version,
|
|
29 ;; be wary when applying differences. I've left in a number of lines
|
|
30 ;; of commentary just to give diff(1) something to synch itself with to
|
|
31 ;; provide useful context diffs. -sb
|
0
|
32
|
|
33 ;;; Code:
|
|
34
|
|
35
|
|
36 ;;;; Lisp language features.
|
|
37
|
177
|
38 ;; Moved to packages.el
|
|
39 ;(defmacro lambda (&rest cdr)
|
|
40 ; "Return a lambda expression.
|
|
41 ;A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
|
|
42 ;self-quoting; the result of evaluating the lambda expression is the
|
|
43 ;expression itself. The lambda expression may then be treated as a
|
|
44 ;function, i.e., stored as the function value of a symbol, passed to
|
|
45 ;funcall or mapcar, etc.
|
0
|
46
|
177
|
47 ;ARGS should take the same form as an argument list for a `defun'.
|
|
48 ;DOCSTRING is an optional documentation string.
|
|
49 ; If present, it should describe how to call the function.
|
|
50 ; But documentation strings are usually not useful in nameless functions.
|
|
51 ;INTERACTIVE should be a call to the function `interactive', which see.
|
|
52 ;It may also be omitted.
|
|
53 ;BODY should be a list of lisp expressions."
|
|
54 ; ;; Note that this definition should not use backquotes; subr.el should not
|
|
55 ; ;; depend on backquote.el.
|
|
56 ; ;; #### - I don't see why. So long as backquote.el doesn't use anything
|
|
57 ; ;; from subr.el, there's no problem with using backquotes here. --Stig
|
|
58 ; ;;(list 'function (cons 'lambda cdr)))
|
|
59 ; `(function (lambda ,@cdr)))
|
4
|
60
|
|
61 (defmacro defun-when-void (&rest args)
|
|
62 "Define a function, just like `defun', unless it's already defined.
|
|
63 Used for compatibility among different emacs variants."
|
|
64 `(if (fboundp ',(car args))
|
|
65 nil
|
|
66 (defun ,@args)))
|
0
|
67
|
4
|
68 (defmacro define-function-when-void (&rest args)
|
|
69 "Define a function, just like `define-function', unless it's already defined.
|
|
70 Used for compatibility among different emacs variants."
|
|
71 `(if (fboundp ,(car args))
|
|
72 nil
|
|
73 (define-function ,@args)))
|
|
74
|
72
|
75
|
|
76 ;;;; Keymap support.
|
|
77 ;; XEmacs: removed to keymap.el
|
|
78
|
|
79 ;;;; The global keymap tree.
|
|
80
|
|
81 ;;; global-map, esc-map, and ctl-x-map have their values set up in
|
|
82 ;;; keymap.c; we just give them docstrings here.
|
|
83
|
|
84 ;;;; Event manipulation functions.
|
|
85
|
|
86 ;; The call to `read' is to ensure that the value is computed at load time
|
|
87 ;; and not compiled into the .elc file. The value is negative on most
|
|
88 ;; machines, but not on all!
|
197
|
89 (defconst listify-key-sequence-1 (logior 128 (read "?\\M-\\^@")))
|
|
90
|
|
91 (defun listify-key-sequence (key)
|
|
92 "Convert a key sequence to a list of events."
|
|
93 (if (vectorp key)
|
|
94 (append key nil)
|
|
95 (mapcar (function (lambda (c)
|
|
96 (if (> c 127)
|
|
97 (logxor c listify-key-sequence-1)
|
|
98 c)))
|
|
99 (append key nil))))
|
72
|
100 ;; XEmacs: This stuff is done in C Code.
|
|
101
|
|
102 ;;;; Obsolescent names for functions.
|
|
103 ;; XEmacs: not used.
|
|
104
|
|
105 ;; XEmacs:
|
0
|
106 (define-function 'not 'null)
|
78
|
107 (define-function-when-void 'numberp 'integerp) ; different when floats
|
0
|
108
|
|
109 (defun local-variable-if-set-p (sym buffer)
|
|
110 "Return t if SYM would be local to BUFFER after it is set.
|
|
111 A nil value for BUFFER is *not* the same as (current-buffer), but
|
|
112 can be used to determine whether `make-variable-buffer-local' has been
|
|
113 called on SYM."
|
|
114 (local-variable-p sym buffer t))
|
|
115
|
|
116
|
|
117 ;;;; Hook manipulation functions.
|
|
118
|
72
|
119 ;; (defconst run-hooks 'run-hooks ...)
|
|
120
|
0
|
121 (defun make-local-hook (hook)
|
|
122 "Make the hook HOOK local to the current buffer.
|
|
123 When a hook is local, its local and global values
|
|
124 work in concert: running the hook actually runs all the hook
|
|
125 functions listed in *either* the local value *or* the global value
|
|
126 of the hook variable.
|
|
127
|
|
128 This function works by making `t' a member of the buffer-local value,
|
|
129 which acts as a flag to run the hook functions in the default value as
|
|
130 well. This works for all normal hooks, but does not work for most
|
|
131 non-normal hooks yet. We will be changing the callers of non-normal
|
|
132 hooks so that they can handle localness; this has to be done one by
|
|
133 one.
|
|
134
|
|
135 This function does nothing if HOOK is already local in the current
|
|
136 buffer.
|
|
137
|
|
138 Do not use `make-local-variable' to make a hook variable buffer-local."
|
72
|
139 (if (local-variable-p hook (current-buffer)) ; XEmacs
|
0
|
140 nil
|
|
141 (or (boundp hook) (set hook nil))
|
|
142 (make-local-variable hook)
|
|
143 (set hook (list t))))
|
|
144
|
|
145 (defun add-hook (hook function &optional append local)
|
|
146 "Add to the value of HOOK the function FUNCTION.
|
|
147 FUNCTION is not added if already present.
|
|
148 FUNCTION is added (if necessary) at the beginning of the hook list
|
|
149 unless the optional argument APPEND is non-nil, in which case
|
|
150 FUNCTION is added at the end.
|
|
151
|
|
152 The optional fourth argument, LOCAL, if non-nil, says to modify
|
|
153 the hook's buffer-local value rather than its default value.
|
|
154 This makes no difference if the hook is not buffer-local.
|
|
155 To make a hook variable buffer-local, always use
|
|
156 `make-local-hook', not `make-local-variable'.
|
|
157
|
|
158 HOOK should be a symbol, and FUNCTION may be any valid function. If
|
|
159 HOOK is void, it is first set to nil. If HOOK's value is a single
|
|
160 function, it is changed to a list of functions."
|
|
161 (or (boundp hook) (set hook nil))
|
|
162 (or (default-boundp hook) (set-default hook nil))
|
|
163 ;; If the hook value is a single function, turn it into a list.
|
|
164 (let ((old (symbol-value hook)))
|
|
165 (if (or (not (listp old)) (eq (car old) 'lambda))
|
|
166 (set hook (list old))))
|
|
167 (if (or local
|
|
168 ;; Detect the case where make-local-variable was used on a hook
|
|
169 ;; and do what we used to do.
|
72
|
170 (and (local-variable-if-set-p hook (current-buffer)) ; XEmacs
|
0
|
171 (not (memq t (symbol-value hook)))))
|
|
172 ;; Alter the local value only.
|
|
173 (or (if (consp function)
|
|
174 (member function (symbol-value hook))
|
|
175 (memq function (symbol-value hook)))
|
|
176 (set hook
|
|
177 (if append
|
|
178 (append (symbol-value hook) (list function))
|
|
179 (cons function (symbol-value hook)))))
|
|
180 ;; Alter the global value (which is also the only value,
|
|
181 ;; if the hook doesn't have a local value).
|
|
182 (or (if (consp function)
|
|
183 (member function (default-value hook))
|
|
184 (memq function (default-value hook)))
|
|
185 (set-default hook
|
|
186 (if append
|
|
187 (append (default-value hook) (list function))
|
|
188 (cons function (default-value hook)))))))
|
|
189
|
|
190 (defun remove-hook (hook function &optional local)
|
|
191 "Remove from the value of HOOK the function FUNCTION.
|
|
192 HOOK should be a symbol, and FUNCTION may be any valid function. If
|
|
193 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
|
|
194 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
|
|
195
|
|
196 The optional third argument, LOCAL, if non-nil, says to modify
|
|
197 the hook's buffer-local value rather than its default value.
|
|
198 This makes no difference if the hook is not buffer-local.
|
|
199 To make a hook variable buffer-local, always use
|
|
200 `make-local-hook', not `make-local-variable'."
|
|
201 (if (or (not (boundp hook)) ;unbound symbol, or
|
|
202 (not (default-boundp 'hook))
|
|
203 (null (symbol-value hook)) ;value is nil, or
|
|
204 (null function)) ;function is nil, then
|
|
205 nil ;Do nothing.
|
|
206 (if (or local
|
|
207 ;; Detect the case where make-local-variable was used on a hook
|
|
208 ;; and do what we used to do.
|
|
209 (and (local-variable-p hook (current-buffer))
|
|
210 (not (memq t (symbol-value hook)))))
|
|
211 (let ((hook-value (symbol-value hook)))
|
|
212 (if (consp hook-value)
|
|
213 (if (member function hook-value)
|
|
214 (setq hook-value (delete function (copy-sequence hook-value))))
|
|
215 (if (equal hook-value function)
|
|
216 (setq hook-value nil)))
|
|
217 (set hook hook-value))
|
|
218 (let ((hook-value (default-value hook)))
|
|
219 (if (consp hook-value)
|
|
220 (if (member function hook-value)
|
|
221 (setq hook-value (delete function (copy-sequence hook-value))))
|
|
222 (if (equal hook-value function)
|
|
223 (setq hook-value nil)))
|
|
224 (set-default hook hook-value)))))
|
|
225
|
|
226 (defun add-to-list (list-var element)
|
|
227 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
|
72
|
228 The test for presence of ELEMENT is done with `equal'.
|
0
|
229 If you want to use `add-to-list' on a variable that is not defined
|
|
230 until a certain package is loaded, you should put the call to `add-to-list'
|
|
231 into a hook function that will be run only after loading the package.
|
|
232 `eval-after-load' provides one way to do this. In some cases
|
|
233 other hooks, such as major mode hooks, can do the job."
|
|
234 (or (member element (symbol-value list-var))
|
|
235 (set list-var (cons element (symbol-value list-var)))))
|
|
236
|
72
|
237 ;; XEmacs additions
|
0
|
238 ;; called by Fkill_buffer()
|
|
239 (defvar kill-buffer-hook nil
|
|
240 "Function or functions to be called when a buffer is killed.
|
|
241 The value of this variable may be buffer-local.
|
|
242 The buffer about to be killed is current when this hook is run.")
|
|
243
|
|
244 ;; in C in FSFmacs
|
|
245 (defvar kill-emacs-hook nil
|
|
246 "Function or functions to be called when `kill-emacs' is called,
|
|
247 just before emacs is actually killed.")
|
|
248
|
|
249 ;; not obsolete.
|
|
250 (define-function 'rplaca 'setcar)
|
|
251 (define-function 'rplacd 'setcdr)
|
|
252
|
|
253 ;;;; String functions.
|
|
254
|
72
|
255 ;; XEmacs
|
0
|
256 (defun replace-in-string (str regexp newtext &optional literal)
|
|
257 "Replaces all matches in STR for REGEXP with NEWTEXT string.
|
|
258 Optional LITERAL non-nil means do a literal replacement.
|
|
259 Otherwise treat \\ in NEWTEXT string as special:
|
|
260 \\& means substitute original matched text,
|
|
261 \\N means substitute match for \(...\) number N,
|
|
262 \\\\ means insert one \\."
|
|
263 (if (not (stringp str))
|
|
264 (error "(replace-in-string): First argument must be a string: %s" str))
|
|
265 (if (stringp newtext)
|
|
266 nil
|
|
267 (error "(replace-in-string): 3rd arg must be a string: %s"
|
|
268 newtext))
|
|
269 (let ((rtn-str "")
|
|
270 (start 0)
|
|
271 (special)
|
|
272 match prev-start)
|
|
273 (while (setq match (string-match regexp str start))
|
|
274 (setq prev-start start
|
|
275 start (match-end 0)
|
|
276 rtn-str
|
|
277 (concat
|
|
278 rtn-str
|
|
279 (substring str prev-start match)
|
|
280 (cond (literal newtext)
|
|
281 (t (mapconcat
|
|
282 (function
|
|
283 (lambda (c)
|
|
284 (if special
|
|
285 (progn
|
|
286 (setq special nil)
|
|
287 (cond ((eq c ?\\) "\\")
|
|
288 ((eq c ?&)
|
|
289 (substring str
|
|
290 (match-beginning 0)
|
|
291 (match-end 0)))
|
|
292 ((and (>= c ?0) (<= c ?9))
|
|
293 (if (> c (+ ?0 (length
|
|
294 (match-data))))
|
|
295 ;; Invalid match num
|
|
296 (error "(replace-in-string) Invalid match num: %c" c)
|
|
297 (setq c (- c ?0))
|
|
298 (substring str
|
|
299 (match-beginning c)
|
|
300 (match-end c))))
|
|
301 (t (char-to-string c))))
|
|
302 (if (eq c ?\\) (progn (setq special t) nil)
|
|
303 (char-to-string c)))))
|
|
304 newtext ""))))))
|
|
305 (concat rtn-str (substring str start))))
|
|
306
|
159
|
307 (defun split-string (string &optional pattern)
|
0
|
308 "Return a list of substrings of STRING which are separated by PATTERN."
|
159
|
309 (or pattern
|
|
310 (setq pattern "[ \f\t\n\r\v]+"))
|
0
|
311 (let (parts (start 0))
|
|
312 (while (string-match pattern string start)
|
|
313 (setq parts (cons (substring string start (match-beginning 0)) parts)
|
|
314 start (match-end 0)))
|
|
315 (nreverse (cons (substring string start) parts))
|
|
316 ))
|
|
317
|
|
318 (defmacro with-output-to-string (&rest forms)
|
|
319 "Collect output to `standard-output' while evaluating FORMS and return
|
|
320 it as a string."
|
|
321 ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> w/ mods from Stig
|
163
|
322 (` (with-current-buffer (get-buffer-create " *string-output*")
|
0
|
323 (setq buffer-read-only nil)
|
|
324 (buffer-disable-undo (current-buffer))
|
|
325 (erase-buffer)
|
|
326 (let ((standard-output (current-buffer)))
|
|
327 (,@ forms))
|
|
328 (prog1
|
|
329 (buffer-string)
|
|
330 (erase-buffer)))))
|
|
331
|
161
|
332 (defmacro with-current-buffer (buffer &rest body)
|
|
333 "Execute the forms in BODY with BUFFER as the current buffer.
|
|
334 The value returned is the value of the last form in BODY.
|
|
335 See also `with-temp-buffer'."
|
|
336 `(save-current-buffer
|
|
337 (set-buffer ,buffer)
|
|
338 ,@body))
|
|
339
|
|
340 (defmacro with-temp-file (file &rest forms)
|
|
341 "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
|
|
342 The value of the last form in FORMS is returned, like `progn'.
|
|
343 See also `with-temp-buffer'."
|
|
344 (let ((temp-file (make-symbol "temp-file"))
|
|
345 (temp-buffer (make-symbol "temp-buffer")))
|
|
346 `(let ((,temp-file ,file)
|
|
347 (,temp-buffer
|
|
348 (get-buffer-create (generate-new-buffer-name " *temp file*"))))
|
|
349 (unwind-protect
|
|
350 (prog1
|
|
351 (with-current-buffer ,temp-buffer
|
|
352 ,@forms)
|
|
353 (with-current-buffer ,temp-buffer
|
|
354 (widen)
|
|
355 (write-region (point-min) (point-max) ,temp-file nil 0)))
|
|
356 (and (buffer-name ,temp-buffer)
|
|
357 (kill-buffer ,temp-buffer))))))
|
|
358
|
104
|
359 (defmacro with-temp-buffer (&rest forms)
|
|
360 "Create a temporary buffer, and evaluate FORMS there like `progn'."
|
|
361 (let ((temp-buffer (make-symbol "temp-buffer")))
|
|
362 `(let ((,temp-buffer
|
|
363 (get-buffer-create (generate-new-buffer-name " *temp*"))))
|
|
364 (unwind-protect
|
163
|
365 (with-current-buffer ,temp-buffer
|
104
|
366 ,@forms)
|
|
367 (and (buffer-name ,temp-buffer)
|
|
368 (kill-buffer ,temp-buffer))))))
|
|
369
|
|
370 ;; Moved from mule-coding.el.
|
|
371 (defmacro with-string-as-buffer-contents (str &rest body)
|
|
372 "With the contents of the current buffer being STR, run BODY.
|
|
373 Returns the new contents of the buffer, as modified by BODY.
|
|
374 The original current buffer is restored afterwards."
|
163
|
375 `(let ((tempbuf (get-buffer-create " *string-as-buffer-contents*")))
|
|
376 (with-current-buffer tempbuf
|
|
377 (unwind-protect
|
|
378 (progn
|
|
379 (buffer-disable-undo (current-buffer))
|
|
380 (erase-buffer)
|
|
381 (insert ,str)
|
|
382 ,@body
|
|
383 (buffer-string))
|
|
384 (erase-buffer tempbuf)))))
|
104
|
385
|
0
|
386 (defun insert-face (string face)
|
|
387 "Insert STRING and highlight with FACE. Returns the extent created."
|
|
388 (let ((p (point)) ext)
|
|
389 (insert string)
|
|
390 (setq ext (make-extent p (point)))
|
|
391 (set-extent-face ext face)
|
|
392 ext))
|
|
393
|
|
394 ;; not obsolete.
|
|
395 (define-function 'string= 'string-equal)
|
|
396 (define-function 'string< 'string-lessp)
|
|
397 (define-function 'int-to-string 'number-to-string)
|
|
398 (define-function 'string-to-int 'string-to-number)
|
207
|
399
|
|
400 ;; These two names are a bit awkward, as they conflict with the normal
|
|
401 ;; foo-to-bar naming scheme, but CLtL2 has them, so they stay.
|
|
402 (define-function 'char-int 'char-to-int)
|
|
403 (define-function 'int-char 'int-to-char)
|
|
404
|
0
|
405
|
|
406 ;; alist/plist functions
|
|
407 (defun plist-to-alist (plist)
|
|
408 "Convert property list PLIST into the equivalent association-list form.
|
|
409 The alist is returned. This converts from
|
|
410
|
|
411 \(a 1 b 2 c 3)
|
|
412
|
|
413 into
|
|
414
|
|
415 \((a . 1) (b . 2) (c . 3))
|
|
416
|
|
417 The original plist is not modified. See also `destructive-plist-to-alist'."
|
|
418 (let (alist)
|
|
419 (while plist
|
|
420 (setq alist (cons (cons (car plist) (cadr plist)) alist))
|
|
421 (setq plist (cddr plist)))
|
|
422 (nreverse alist)))
|
|
423
|
|
424 (defun destructive-plist-to-alist (plist)
|
|
425 "Convert property list PLIST into the equivalent association-list form.
|
|
426 The alist is returned. This converts from
|
|
427
|
|
428 \(a 1 b 2 c 3)
|
|
429
|
|
430 into
|
|
431
|
|
432 \((a . 1) (b . 2) (c . 3))
|
|
433
|
|
434 The original plist is destroyed in the process of constructing the alist.
|
|
435 See also `plist-to-alist'."
|
|
436 (let ((head plist)
|
|
437 next)
|
|
438 (while plist
|
|
439 ;; remember the next plist pair.
|
|
440 (setq next (cddr plist))
|
|
441 ;; make the cons holding the property value into the alist element.
|
|
442 (setcdr (cdr plist) (cadr plist))
|
|
443 (setcar (cdr plist) (car plist))
|
|
444 ;; reattach into alist form.
|
|
445 (setcar plist (cdr plist))
|
|
446 (setcdr plist next)
|
|
447 (setq plist next))
|
|
448 head))
|
|
449
|
|
450 (defun alist-to-plist (alist)
|
|
451 "Convert association list ALIST into the equivalent property-list form.
|
|
452 The plist is returned. This converts from
|
|
453
|
|
454 \((a . 1) (b . 2) (c . 3))
|
|
455
|
|
456 into
|
|
457
|
|
458 \(a 1 b 2 c 3)
|
|
459
|
|
460 The original alist is not modified. See also `destructive-alist-to-plist'."
|
|
461 (let (plist)
|
|
462 (while alist
|
|
463 (let ((el (car alist)))
|
|
464 (setq plist (cons (cdr el) (cons (car el) plist))))
|
|
465 (setq alist (cdr alist)))
|
|
466 (nreverse plist)))
|
|
467
|
|
468 ;; getf, remf in cl*.el.
|
|
469
|
|
470 (defmacro putf (plist prop val)
|
|
471 "Add property PROP to plist PLIST with value VAL.
|
|
472 Analogous to (setq PLIST (plist-put PLIST PROP VAL))."
|
|
473 `(setq ,plist (plist-put ,plist ,prop ,val)))
|
|
474
|
|
475 (defmacro laxputf (lax-plist prop val)
|
|
476 "Add property PROP to lax plist LAX-PLIST with value VAL.
|
|
477 Analogous to (setq LAX-PLIST (lax-plist-put LAX-PLIST PROP VAL))."
|
|
478 `(setq ,lax-plist (lax-plist-put ,lax-plist ,prop ,val)))
|
|
479
|
|
480 (defmacro laxremf (lax-plist prop)
|
|
481 "Remove property PROP from lax plist LAX-PLIST.
|
|
482 Analogous to (setq LAX-PLIST (lax-plist-remprop LAX-PLIST PROP))."
|
|
483 `(setq ,lax-plist (lax-plist-remprop ,lax-plist ,prop)))
|
|
484
|
|
485 ;;; Error functions
|
|
486
|
|
487 (defun error (&rest args)
|
|
488 "Signal an error, making error message by passing all args to `format'.
|
|
489 This error is not continuable: you cannot continue execution after the
|
|
490 error using the debugger `r' command. See also `cerror'."
|
|
491 (while t
|
|
492 (apply 'cerror args)))
|
|
493
|
|
494 (defun cerror (&rest args)
|
|
495 "Like `error' but signals a continuable error."
|
|
496 (signal 'error (list (apply 'format args))))
|
|
497
|
|
498 (defmacro check-argument-type (predicate argument)
|
|
499 "Check that ARGUMENT satisfies PREDICATE.
|
|
500 If not, signal a continuable `wrong-type-argument' error until the
|
108
|
501 returned value satisfies PREDICATE, and assign the returned value
|
0
|
502 to ARGUMENT."
|
|
503 `(if (not (,(eval predicate) ,argument))
|
|
504 (setq ,argument
|
|
505 (wrong-type-argument ,predicate ,argument))))
|
|
506
|
|
507 (defun signal-error (error-symbol data)
|
|
508 "Signal a non-continuable error. Args are ERROR-SYMBOL, and associated DATA.
|
|
509 An error symbol is a symbol defined using `define-error'.
|
|
510 DATA should be a list. Its elements are printed as part of the error message.
|
|
511 If the signal is handled, DATA is made available to the handler.
|
|
512 See also `signal', and the functions to handle errors: `condition-case'
|
|
513 and `call-with-condition-handler'."
|
|
514 (while t
|
|
515 (signal error-symbol data)))
|
|
516
|
|
517 (defun define-error (error-sym doc-string &optional inherits-from)
|
|
518 "Define a new error, denoted by ERROR-SYM.
|
|
519 DOC-STRING is an informative message explaining the error, and will be
|
|
520 printed out when an unhandled error occurs.
|
|
521 ERROR-SYM is a sub-error of INHERITS-FROM (which defaults to `error').
|
|
522
|
|
523 \[`define-error' internally works by putting on ERROR-SYM an `error-message'
|
|
524 property whose value is DOC-STRING, and an `error-conditions' property
|
|
525 that is a list of ERROR-SYM followed by each of its super-errors, up
|
|
526 to and including `error'. You will sometimes see code that sets this up
|
|
527 directly rather than calling `define-error', but you should *not* do this
|
|
528 yourself.]"
|
|
529 (check-argument-type 'symbolp error-sym)
|
|
530 (check-argument-type 'stringp doc-string)
|
|
531 (put error-sym 'error-message doc-string)
|
|
532 (or inherits-from (setq inherits-from 'error))
|
|
533 (let ((conds (get inherits-from 'error-conditions)))
|
|
534 (or conds (signal-error 'error (list "Not an error symbol" error-sym)))
|
|
535 (put error-sym 'error-conditions (cons error-sym conds))))
|
|
536
|
|
537 ;;;; Miscellanea.
|
|
538
|
|
539 (defun buffer-substring-no-properties (beg end)
|
171
|
540 "Return the text from BEG to END, without text properties, as a string."
|
0
|
541 (let ((string (buffer-substring beg end)))
|
171
|
542 (set-text-properties 0 (length string) nil string)
|
0
|
543 string))
|
|
544
|
197
|
545 ;; This should probably be written in C (i.e., without using `walk-windows').
|
|
546 (defun get-buffer-window-list (buffer &optional minibuf frame)
|
|
547 "Return windows currently displaying BUFFER, or nil if none.
|
|
548 See `walk-windows' for the meaning of MINIBUF and FRAME."
|
|
549 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
|
|
550 (walk-windows (function (lambda (window)
|
|
551 (if (eq (window-buffer window) buffer)
|
|
552 (setq windows (cons window windows)))))
|
|
553 minibuf frame)
|
|
554 windows))
|
|
555
|
0
|
556 (defun ignore (&rest ignore)
|
|
557 "Do nothing and return nil.
|
|
558 This function accepts any number of arguments, but ignores them."
|
|
559 (interactive)
|
|
560 nil)
|
|
561
|
187
|
562 (define-function 'mapc-internal 'mapc)
|
|
563 (make-obsolete 'mapc-internal 'mapc)
|
|
564
|
165
|
565 (define-function 'eval-in-buffer 'with-current-buffer)
|
|
566 (make-obsolete 'eval-in-buffer 'with-current-buffer)
|
0
|
567
|
|
568 ;;; The real defn is in abbrev.el but some early callers
|
|
569 ;;; (eg lisp-mode-abbrev-table) want this before abbrev.el is loaded...
|
|
570
|
|
571 (if (not (fboundp 'define-abbrev-table))
|
|
572 (progn
|
|
573 (setq abbrev-table-name-list '())
|
|
574 (fset 'define-abbrev-table (function (lambda (name defs)
|
|
575 ;; These are fixed-up when abbrev.el loads.
|
|
576 (setq abbrev-table-name-list
|
|
577 (cons (cons name defs)
|
|
578 abbrev-table-name-list)))))))
|
|
579
|
|
580 (defun functionp (obj)
|
207
|
581 "Non-nil if OBJECT is a type of object that can be called as a function."
|
0
|
582 (cond
|
|
583 ((symbolp obj) (fboundp obj))
|
|
584 ((subrp obj))
|
|
585 ((compiled-function-p obj))
|
|
586 ((consp obj)
|
|
587 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
|
|
588 (t nil)))
|
|
589
|
|
590 ;; This was not present before. I think Jamie had some objections
|
|
591 ;; to this, so I'm leaving this undefined for now. --ben
|
|
592
|
|
593 ;;; The objection is this: there is more than one way to load the same file.
|
108
|
594 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different
|
0
|
595 ;;; ways to load the exact same code. `eval-after-load' is too stupid to
|
|
596 ;;; deal with this sort of thing. If this sort of feature is desired, then
|
|
597 ;;; it should work off of a hook on `provide'. Features are unique and
|
|
598 ;;; the arguments to (load) are not. --Stig
|
|
599
|
|
600 ;;;; Specifying things to do after certain files are loaded.
|
|
601
|
104
|
602 (defun eval-after-load (file form)
|
|
603 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
|
|
604 This makes or adds to an entry on `after-load-alist'.
|
|
605 If FILE is already loaded, evaluate FORM right now.
|
|
606 It does nothing if FORM is already on the list for FILE.
|
|
607 FILE should be the name of a library, with no directory name."
|
|
608 ;; Make sure there is an element for FILE.
|
|
609 (or (assoc file after-load-alist)
|
|
610 (setq after-load-alist (cons (list file) after-load-alist)))
|
|
611 ;; Add FORM to the element if it isn't there.
|
|
612 (let ((elt (assoc file after-load-alist)))
|
|
613 (or (member form (cdr elt))
|
|
614 (progn
|
|
615 (nconc elt (list form))
|
|
616 ;; If the file has been loaded already, run FORM right away.
|
|
617 (and (assoc file load-history)
|
|
618 (eval form)))))
|
|
619 form)
|
|
620 (make-compatible 'eval-after-load "")
|
|
621
|
|
622 (defun eval-next-after-load (file)
|
|
623 "Read the following input sexp, and run it whenever FILE is loaded.
|
|
624 This makes or adds to an entry on `after-load-alist'.
|
|
625 FILE should be the name of a library, with no directory name."
|
|
626 (eval-after-load file (read)))
|
|
627 (make-compatible 'eval-next-after-load "")
|
0
|
628
|
|
629 ; alternate names (not obsolete)
|
|
630 (if (not (fboundp 'mod)) (define-function 'mod '%))
|
|
631 (define-function 'move-marker 'set-marker)
|
2
|
632 (define-function 'beep 'ding) ; preserve lingual purity
|
0
|
633 (define-function 'indent-to-column 'indent-to)
|
|
634 (define-function 'backward-delete-char 'delete-backward-char)
|
|
635 (define-function 'search-forward-regexp (symbol-function 're-search-forward))
|
|
636 (define-function 'search-backward-regexp (symbol-function 're-search-backward))
|
|
637 (define-function 'remove-directory 'delete-directory)
|
|
638 (define-function 'set-match-data 'store-match-data)
|
|
639 (define-function 'send-string-to-terminal 'external-debugging-output)
|
|
640 (define-function 'buffer-string 'buffer-substring)
|
72
|
641
|
|
642 ;;; subr.el ends here
|