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