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