(strout, printchar): Handle minibuffer_auto_raise.
[bpt/emacs.git] / lisp / subr.el
CommitLineData
c88ab9ce 1;;; subr.el --- basic lisp subroutines for Emacs
630cc463 2
b578f267 3;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
be9b65ac
DL
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
492878e4 9;; the Free Software Foundation; either version 2, or (at your option)
be9b65ac
DL
10;; any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
b578f267
EN
18;; along with GNU Emacs; see the file COPYING. If not, write to the
19;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20;; Boston, MA 02111-1307, USA.
be9b65ac 21
630cc463 22;;; Code:
77a5664f
RS
23(defvar custom-declare-variable-list nil
24 "Record `defcustom' calls made before `custom.el' is loaded to handle them.
25Each element of this list holds the arguments to one call to `defcustom'.")
26
27;; Use this rather that defcustom, in subr.el and other files loaded
28;; before custom.el.
29(defun custom-declare-variable-early (&rest arguments)
30 (setq custom-declare-variable-list
31 (cons arguments custom-declare-variable-list)))
9a5336ae
JB
32\f
33;;;; Lisp language features.
34
35(defmacro lambda (&rest cdr)
36 "Return a lambda expression.
37A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
38self-quoting; the result of evaluating the lambda expression is the
39expression itself. The lambda expression may then be treated as a
bec0d7f9
RS
40function, i.e., stored as the function value of a symbol, passed to
41funcall or mapcar, etc.
42
9a5336ae 43ARGS should take the same form as an argument list for a `defun'.
8fd68088
RS
44DOCSTRING is an optional documentation string.
45 If present, it should describe how to call the function.
46 But documentation strings are usually not useful in nameless functions.
9a5336ae
JB
47INTERACTIVE should be a call to the function `interactive', which see.
48It may also be omitted.
49BODY should be a list of lisp expressions."
50 ;; Note that this definition should not use backquotes; subr.el should not
51 ;; depend on backquote.el.
52 (list 'function (cons 'lambda cdr)))
53
debff3c3
RS
54(defmacro when (cond &rest body)
55 "(when COND BODY...): if COND yields non-nil, do BODY, else return nil."
56 (list 'if cond (cons 'progn body)))
11d431ad
KH
57(put 'when 'lisp-indent-function 1)
58(put 'when 'edebug-form-spec '(&rest form))
9a5336ae 59
debff3c3
RS
60(defmacro unless (cond &rest body)
61 "(unless COND BODY...): if COND yields nil, do BODY, else return nil."
62 (cons 'if (cons cond (cons nil body))))
11d431ad
KH
63(put 'unless 'lisp-indent-function 1)
64(put 'unless 'edebug-form-spec '(&rest form))
9a5336ae 65\f
9a5336ae 66;;;; Keymap support.
be9b65ac
DL
67
68(defun undefined ()
69 (interactive)
70 (ding))
71
72;Prevent the \{...} documentation construct
73;from mentioning keys that run this command.
74(put 'undefined 'suppress-keymap t)
75
76(defun suppress-keymap (map &optional nodigits)
77 "Make MAP override all normally self-inserting keys to be undefined.
78Normally, as an exception, digits and minus-sign are set to make prefix args,
79but optional second arg NODIGITS non-nil treats them like other chars."
80e7b471 80 (substitute-key-definition 'self-insert-command 'undefined map global-map)
be9b65ac
DL
81 (or nodigits
82 (let (loop)
83 (define-key map "-" 'negative-argument)
84 ;; Make plain numbers do numeric args.
85 (setq loop ?0)
86 (while (<= loop ?9)
87 (define-key map (char-to-string loop) 'digit-argument)
88 (setq loop (1+ loop))))))
89
be9b65ac
DL
90;Moved to keymap.c
91;(defun copy-keymap (keymap)
92; "Return a copy of KEYMAP"
93; (while (not (keymapp keymap))
94; (setq keymap (signal 'wrong-type-argument (list 'keymapp keymap))))
95; (if (vectorp keymap)
96; (copy-sequence keymap)
97; (copy-alist keymap)))
98
f14dbba7
KH
99(defvar key-substitution-in-progress nil
100 "Used internally by substitute-key-definition.")
101
7f2c2edd 102(defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
be9b65ac
DL
103 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
104In other words, OLDDEF is replaced with NEWDEF where ever it appears.
7f2c2edd
RS
105If optional fourth argument OLDMAP is specified, we redefine
106in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
107 (or prefix (setq prefix ""))
108 (let* ((scan (or oldmap keymap))
109 (vec1 (vector nil))
f14dbba7
KH
110 (prefix1 (vconcat prefix vec1))
111 (key-substitution-in-progress
112 (cons scan key-substitution-in-progress)))
7f2c2edd
RS
113 ;; Scan OLDMAP, finding each char or event-symbol that
114 ;; has any definition, and act on it with hack-key.
115 (while (consp scan)
116 (if (consp (car scan))
117 (let ((char (car (car scan)))
118 (defn (cdr (car scan))))
119 ;; The inside of this let duplicates exactly
120 ;; the inside of the following let that handles array elements.
121 (aset vec1 0 char)
122 (aset prefix1 (length prefix) char)
44d798af 123 (let (inner-def skipped)
7f2c2edd
RS
124 ;; Skip past menu-prompt.
125 (while (stringp (car-safe defn))
44d798af 126 (setq skipped (cons (car defn) skipped))
7f2c2edd 127 (setq defn (cdr defn)))
e025dddf
RS
128 ;; Skip past cached key-equivalence data for menu items.
129 (and (consp defn) (consp (car defn))
130 (setq defn (cdr defn)))
7f2c2edd 131 (setq inner-def defn)
e025dddf 132 ;; Look past a symbol that names a keymap.
7f2c2edd
RS
133 (while (and (symbolp inner-def)
134 (fboundp inner-def))
135 (setq inner-def (symbol-function inner-def)))
328a37ec
RS
136 (if (or (eq defn olddef)
137 ;; Compare with equal if definition is a key sequence.
138 ;; That is useful for operating on function-key-map.
139 (and (or (stringp defn) (vectorp defn))
140 (equal defn olddef)))
44d798af 141 (define-key keymap prefix1 (nconc (nreverse skipped) newdef))
f14dbba7 142 (if (and (keymapp defn)
350b7567
RS
143 ;; Avoid recursively scanning
144 ;; where KEYMAP does not have a submap.
afd9831b
RS
145 (let ((elt (lookup-key keymap prefix1)))
146 (or (null elt)
147 (keymapp elt)))
350b7567 148 ;; Avoid recursively rescanning keymap being scanned.
f14dbba7
KH
149 (not (memq inner-def
150 key-substitution-in-progress)))
e025dddf
RS
151 ;; If this one isn't being scanned already,
152 ;; scan it now.
7f2c2edd
RS
153 (substitute-key-definition olddef newdef keymap
154 inner-def
155 prefix1)))))
916cc49f 156 (if (vectorp (car scan))
7f2c2edd
RS
157 (let* ((array (car scan))
158 (len (length array))
159 (i 0))
160 (while (< i len)
161 (let ((char i) (defn (aref array i)))
162 ;; The inside of this let duplicates exactly
163 ;; the inside of the previous let.
164 (aset vec1 0 char)
165 (aset prefix1 (length prefix) char)
44d798af 166 (let (inner-def skipped)
7f2c2edd
RS
167 ;; Skip past menu-prompt.
168 (while (stringp (car-safe defn))
44d798af 169 (setq skipped (cons (car defn) skipped))
7f2c2edd 170 (setq defn (cdr defn)))
e025dddf
RS
171 (and (consp defn) (consp (car defn))
172 (setq defn (cdr defn)))
7f2c2edd
RS
173 (setq inner-def defn)
174 (while (and (symbolp inner-def)
175 (fboundp inner-def))
176 (setq inner-def (symbol-function inner-def)))
328a37ec
RS
177 (if (or (eq defn olddef)
178 (and (or (stringp defn) (vectorp defn))
179 (equal defn olddef)))
44d798af
RS
180 (define-key keymap prefix1
181 (nconc (nreverse skipped) newdef))
f14dbba7 182 (if (and (keymapp defn)
afd9831b
RS
183 (let ((elt (lookup-key keymap prefix1)))
184 (or (null elt)
185 (keymapp elt)))
f14dbba7
KH
186 (not (memq inner-def
187 key-substitution-in-progress)))
7f2c2edd
RS
188 (substitute-key-definition olddef newdef keymap
189 inner-def
190 prefix1)))))
97fd9abf
RS
191 (setq i (1+ i))))
192 (if (char-table-p (car scan))
193 (map-char-table
194 (function (lambda (char defn)
195 (let ()
196 ;; The inside of this let duplicates exactly
197 ;; the inside of the previous let,
198 ;; except that it uses set-char-table-range
199 ;; instead of define-key.
200 (aset vec1 0 char)
201 (aset prefix1 (length prefix) char)
202 (let (inner-def skipped)
203 ;; Skip past menu-prompt.
204 (while (stringp (car-safe defn))
205 (setq skipped (cons (car defn) skipped))
206 (setq defn (cdr defn)))
207 (and (consp defn) (consp (car defn))
208 (setq defn (cdr defn)))
209 (setq inner-def defn)
210 (while (and (symbolp inner-def)
211 (fboundp inner-def))
212 (setq inner-def (symbol-function inner-def)))
213 (if (or (eq defn olddef)
214 (and (or (stringp defn) (vectorp defn))
215 (equal defn olddef)))
9a5114ac
RS
216 (define-key keymap prefix1
217 (nconc (nreverse skipped) newdef))
97fd9abf
RS
218 (if (and (keymapp defn)
219 (let ((elt (lookup-key keymap prefix1)))
220 (or (null elt)
221 (keymapp elt)))
222 (not (memq inner-def
223 key-substitution-in-progress)))
224 (substitute-key-definition olddef newdef keymap
225 inner-def
226 prefix1)))))))
227 (car scan)))))
7f2c2edd 228 (setq scan (cdr scan)))))
9a5336ae 229
06ae9cf2 230(defun define-key-after (keymap key definition after)
4434d61b
RS
231 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
232This is like `define-key' except that the binding for KEY is placed
233just after the binding for the event AFTER, instead of at the beginning
c34a9d34
RS
234of the map. Note that AFTER must be an event type (like KEY), NOT a command
235\(like DEFINITION).
236
237If AFTER is t, the new binding goes at the end of the keymap.
238
9ed287b0 239KEY must contain just one event type--that is to say, it must be
c34a9d34
RS
240a string or vector of length 1.
241
242The order of bindings in a keymap matters when it is used as a menu."
243
4434d61b
RS
244 (or (keymapp keymap)
245 (signal 'wrong-type-argument (list 'keymapp keymap)))
ab375e6c 246 (if (> (length key) 1)
626f67f3 247 (error "multi-event key specified in `define-key-after'"))
113d28a8 248 (let ((tail keymap) done inserted
4434d61b
RS
249 (first (aref key 0)))
250 (while (and (not done) tail)
251 ;; Delete any earlier bindings for the same key.
252 (if (eq (car-safe (car (cdr tail))) first)
253 (setcdr tail (cdr (cdr tail))))
254 ;; When we reach AFTER's binding, insert the new binding after.
255 ;; If we reach an inherited keymap, insert just before that.
113d28a8 256 ;; If we reach the end of this keymap, insert at the end.
c34a9d34
RS
257 (if (or (and (eq (car-safe (car tail)) after)
258 (not (eq after t)))
113d28a8
RS
259 (eq (car (cdr tail)) 'keymap)
260 (null (cdr tail)))
4434d61b 261 (progn
113d28a8
RS
262 ;; Stop the scan only if we find a parent keymap.
263 ;; Keep going past the inserted element
264 ;; so we can delete any duplications that come later.
265 (if (eq (car (cdr tail)) 'keymap)
266 (setq done t))
267 ;; Don't insert more than once.
268 (or inserted
269 (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))))
270 (setq inserted t)))
4434d61b
RS
271 (setq tail (cdr tail)))))
272
d128fe85
RS
273(defmacro kbd (keys)
274 "Convert KEYS to the internal Emacs key representation.
275KEYS should be a string constant in the format used for
276saving keyboard macros (see `insert-kbd-macro')."
277 (read-kbd-macro keys))
278
8bed5e3d
RS
279(put 'keyboard-translate-table 'char-table-extra-slots 0)
280
9a5336ae
JB
281(defun keyboard-translate (from to)
282 "Translate character FROM to TO at a low level.
283This function creates a `keyboard-translate-table' if necessary
284and then modifies one entry in it."
8bed5e3d
RS
285 (or (char-table-p keyboard-translate-table)
286 (setq keyboard-translate-table
287 (make-char-table 'keyboard-translate-table nil)))
9a5336ae
JB
288 (aset keyboard-translate-table from to))
289
290\f
291;;;; The global keymap tree.
292
293;;; global-map, esc-map, and ctl-x-map have their values set up in
294;;; keymap.c; we just give them docstrings here.
295
296(defvar global-map nil
297 "Default global keymap mapping Emacs keyboard input into commands.
298The value is a keymap which is usually (but not necessarily) Emacs's
299global map.")
300
301(defvar esc-map nil
302 "Default keymap for ESC (meta) commands.
303The normal global definition of the character ESC indirects to this keymap.")
304
305(defvar ctl-x-map nil
306 "Default keymap for C-x commands.
307The normal global definition of the character C-x indirects to this keymap.")
308
309(defvar ctl-x-4-map (make-sparse-keymap)
310 "Keymap for subcommands of C-x 4")
059184dd 311(defalias 'ctl-x-4-prefix ctl-x-4-map)
9a5336ae
JB
312(define-key ctl-x-map "4" 'ctl-x-4-prefix)
313
314(defvar ctl-x-5-map (make-sparse-keymap)
315 "Keymap for frame commands.")
059184dd 316(defalias 'ctl-x-5-prefix ctl-x-5-map)
9a5336ae
JB
317(define-key ctl-x-map "5" 'ctl-x-5-prefix)
318
0f03054a 319\f
9a5336ae
JB
320;;;; Event manipulation functions.
321
da16e648
KH
322;; The call to `read' is to ensure that the value is computed at load time
323;; and not compiled into the .elc file. The value is negative on most
324;; machines, but not on all!
325(defconst listify-key-sequence-1 (logior 128 (read "?\\M-\\^@")))
114137b8 326
cde6d7e3
RS
327(defun listify-key-sequence (key)
328 "Convert a key sequence to a list of events."
329 (if (vectorp key)
330 (append key nil)
331 (mapcar (function (lambda (c)
332 (if (> c 127)
114137b8 333 (logxor c listify-key-sequence-1)
cde6d7e3
RS
334 c)))
335 (append key nil))))
336
53e5a4e8
RS
337(defsubst eventp (obj)
338 "True if the argument is an event object."
339 (or (integerp obj)
340 (and (symbolp obj)
341 (get obj 'event-symbol-elements))
342 (and (consp obj)
343 (symbolp (car obj))
344 (get (car obj) 'event-symbol-elements))))
345
346(defun event-modifiers (event)
347 "Returns a list of symbols representing the modifier keys in event EVENT.
348The elements of the list may include `meta', `control',
32295976
RS
349`shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
350and `down'."
53e5a4e8
RS
351 (let ((type event))
352 (if (listp type)
353 (setq type (car type)))
354 (if (symbolp type)
355 (cdr (get type 'event-symbol-elements))
356 (let ((list nil))
da16e648 357 (or (zerop (logand type ?\M-\^@))
53e5a4e8 358 (setq list (cons 'meta list)))
da16e648 359 (or (and (zerop (logand type ?\C-\^@))
53e5a4e8
RS
360 (>= (logand type 127) 32))
361 (setq list (cons 'control list)))
da16e648 362 (or (and (zerop (logand type ?\S-\^@))
53e5a4e8
RS
363 (= (logand type 255) (downcase (logand type 255))))
364 (setq list (cons 'shift list)))
da16e648 365 (or (zerop (logand type ?\H-\^@))
53e5a4e8 366 (setq list (cons 'hyper list)))
da16e648 367 (or (zerop (logand type ?\s-\^@))
53e5a4e8 368 (setq list (cons 'super list)))
da16e648 369 (or (zerop (logand type ?\A-\^@))
53e5a4e8
RS
370 (setq list (cons 'alt list)))
371 list))))
372
d63de416
RS
373(defun event-basic-type (event)
374 "Returns the basic type of the given event (all modifiers removed).
375The value is an ASCII printing character (not upper case) or a symbol."
2b0f4ba5
JB
376 (if (consp event)
377 (setq event (car event)))
d63de416
RS
378 (if (symbolp event)
379 (car (get event 'event-symbol-elements))
380 (let ((base (logand event (1- (lsh 1 18)))))
381 (downcase (if (< base 32) (logior base 64) base)))))
382
0f03054a
RS
383(defsubst mouse-movement-p (object)
384 "Return non-nil if OBJECT is a mouse movement event."
385 (and (consp object)
386 (eq (car object) 'mouse-movement)))
387
388(defsubst event-start (event)
389 "Return the starting position of EVENT.
390If EVENT is a mouse press or a mouse click, this returns the location
391of the event.
392If EVENT is a drag, this returns the drag's starting position.
393The return value is of the form
e55c21be 394 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a
RS
395The `posn-' functions access elements of such lists."
396 (nth 1 event))
397
398(defsubst event-end (event)
399 "Return the ending location of EVENT. EVENT should be a click or drag event.
400If EVENT is a click event, this function is the same as `event-start'.
401The return value is of the form
e55c21be 402 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a 403The `posn-' functions access elements of such lists."
69b95560 404 (nth (if (consp (nth 2 event)) 2 1) event))
0f03054a 405
32295976
RS
406(defsubst event-click-count (event)
407 "Return the multi-click count of EVENT, a click or drag event.
408The return value is a positive integer."
409 (if (integerp (nth 2 event)) (nth 2 event) 1))
410
0f03054a
RS
411(defsubst posn-window (position)
412 "Return the window in POSITION.
413POSITION should be a list of the form
e55c21be 414 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a
RS
415as returned by the `event-start' and `event-end' functions."
416 (nth 0 position))
417
418(defsubst posn-point (position)
419 "Return the buffer location in POSITION.
420POSITION should be a list of the form
e55c21be 421 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a 422as returned by the `event-start' and `event-end' functions."
15db4e0e
JB
423 (if (consp (nth 1 position))
424 (car (nth 1 position))
425 (nth 1 position)))
0f03054a 426
e55c21be
RS
427(defsubst posn-x-y (position)
428 "Return the x and y coordinates in POSITION.
0f03054a 429POSITION should be a list of the form
e55c21be 430 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a
RS
431as returned by the `event-start' and `event-end' functions."
432 (nth 2 position))
433
ed627e08 434(defun posn-col-row (position)
dbbcac56 435 "Return the column and row in POSITION, measured in characters.
e55c21be
RS
436POSITION should be a list of the form
437 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
ed627e08
RS
438as returned by the `event-start' and `event-end' functions.
439For a scroll-bar event, the result column is 0, and the row
440corresponds to the vertical position of the click in the scroll bar."
441 (let ((pair (nth 2 position))
442 (window (posn-window position)))
dbbcac56
KH
443 (if (eq (if (consp (nth 1 position))
444 (car (nth 1 position))
445 (nth 1 position))
ed627e08
RS
446 'vertical-scroll-bar)
447 (cons 0 (scroll-bar-scale pair (1- (window-height window))))
dbbcac56
KH
448 (if (eq (if (consp (nth 1 position))
449 (car (nth 1 position))
450 (nth 1 position))
ed627e08
RS
451 'horizontal-scroll-bar)
452 (cons (scroll-bar-scale pair (window-width window)) 0)
9ba60df9
RS
453 (let* ((frame (if (framep window) window (window-frame window)))
454 (x (/ (car pair) (frame-char-width frame)))
455 (y (/ (cdr pair) (frame-char-height frame))))
ed627e08 456 (cons x y))))))
e55c21be 457
0f03054a
RS
458(defsubst posn-timestamp (position)
459 "Return the timestamp of POSITION.
460POSITION should be a list of the form
e55c21be 461 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
f415c00c 462as returned by the `event-start' and `event-end' functions."
0f03054a 463 (nth 3 position))
9a5336ae 464
0f03054a 465\f
9a5336ae
JB
466;;;; Obsolescent names for functions.
467
059184dd
ER
468(defalias 'dot 'point)
469(defalias 'dot-marker 'point-marker)
470(defalias 'dot-min 'point-min)
471(defalias 'dot-max 'point-max)
472(defalias 'window-dot 'window-point)
473(defalias 'set-window-dot 'set-window-point)
474(defalias 'read-input 'read-string)
475(defalias 'send-string 'process-send-string)
476(defalias 'send-region 'process-send-region)
477(defalias 'show-buffer 'set-window-buffer)
478(defalias 'buffer-flush-undo 'buffer-disable-undo)
479(defalias 'eval-current-buffer 'eval-buffer)
480(defalias 'compiled-function-p 'byte-code-function-p)
ae1cc031 481(defalias 'define-function 'defalias)
be9b65ac 482
9a5336ae
JB
483;; Some programs still use this as a function.
484(defun baud-rate ()
bcacc42c
RS
485 "Obsolete function returning the value of the `baud-rate' variable.
486Please convert your programs to use the variable `baud-rate' directly."
9a5336ae
JB
487 baud-rate)
488
0a5c0893
MB
489(defalias 'focus-frame 'ignore)
490(defalias 'unfocus-frame 'ignore)
9a5336ae
JB
491\f
492;;;; Alternate names for functions - these are not being phased out.
493
059184dd
ER
494(defalias 'string= 'string-equal)
495(defalias 'string< 'string-lessp)
496(defalias 'move-marker 'set-marker)
059184dd
ER
497(defalias 'not 'null)
498(defalias 'rplaca 'setcar)
499(defalias 'rplacd 'setcdr)
eb8c3be9 500(defalias 'beep 'ding) ;preserve lingual purity
059184dd
ER
501(defalias 'indent-to-column 'indent-to)
502(defalias 'backward-delete-char 'delete-backward-char)
503(defalias 'search-forward-regexp (symbol-function 're-search-forward))
504(defalias 'search-backward-regexp (symbol-function 're-search-backward))
505(defalias 'int-to-string 'number-to-string)
1e0a78a1 506(defalias 'set-match-data 'store-match-data)
37f6661a
JB
507
508;;; Should this be an obsolete name? If you decide it should, you get
509;;; to go through all the sources and change them.
059184dd 510(defalias 'string-to-int 'string-to-number)
be9b65ac 511\f
9a5336ae 512;;;; Hook manipulation functions.
be9b65ac 513
0e4d378b
RS
514(defun make-local-hook (hook)
515 "Make the hook HOOK local to the current buffer.
516When a hook is local, its local and global values
517work in concert: running the hook actually runs all the hook
518functions listed in *either* the local value *or* the global value
519of the hook variable.
520
7dd1926e
RS
521This function works by making `t' a member of the buffer-local value,
522which acts as a flag to run the hook functions in the default value as
523well. This works for all normal hooks, but does not work for most
524non-normal hooks yet. We will be changing the callers of non-normal
525hooks so that they can handle localness; this has to be done one by
526one.
527
528This function does nothing if HOOK is already local in the current
529buffer.
0e4d378b
RS
530
531Do not use `make-local-variable' to make a hook variable buffer-local."
532 (if (local-variable-p hook)
533 nil
534 (or (boundp hook) (set hook nil))
535 (make-local-variable hook)
536 (set hook (list t))))
537
538(defun add-hook (hook function &optional append local)
32295976
RS
539 "Add to the value of HOOK the function FUNCTION.
540FUNCTION is not added if already present.
541FUNCTION is added (if necessary) at the beginning of the hook list
542unless the optional argument APPEND is non-nil, in which case
543FUNCTION is added at the end.
544
0e4d378b
RS
545The optional fourth argument, LOCAL, if non-nil, says to modify
546the hook's buffer-local value rather than its default value.
547This makes no difference if the hook is not buffer-local.
548To make a hook variable buffer-local, always use
549`make-local-hook', not `make-local-variable'.
550
32295976
RS
551HOOK should be a symbol, and FUNCTION may be any valid function. If
552HOOK is void, it is first set to nil. If HOOK's value is a single
aa09b5ca 553function, it is changed to a list of functions."
be9b65ac 554 (or (boundp hook) (set hook nil))
0e4d378b 555 (or (default-boundp hook) (set-default hook nil))
32295976
RS
556 ;; If the hook value is a single function, turn it into a list.
557 (let ((old (symbol-value hook)))
558 (if (or (not (listp old)) (eq (car old) 'lambda))
559 (set hook (list old))))
f4e5bca5
RS
560 (if (or local
561 ;; Detect the case where make-local-variable was used on a hook
562 ;; and do what we used to do.
cd2db344 563 (and (local-variable-if-set-p hook)
f4e5bca5 564 (not (memq t (symbol-value hook)))))
0e4d378b
RS
565 ;; Alter the local value only.
566 (or (if (consp function)
567 (member function (symbol-value hook))
568 (memq function (symbol-value hook)))
569 (set hook
570 (if append
571 (append (symbol-value hook) (list function))
572 (cons function (symbol-value hook)))))
573 ;; Alter the global value (which is also the only value,
574 ;; if the hook doesn't have a local value).
575 (or (if (consp function)
576 (member function (default-value hook))
577 (memq function (default-value hook)))
578 (set-default hook
579 (if append
580 (append (default-value hook) (list function))
581 (cons function (default-value hook)))))))
582
583(defun remove-hook (hook function &optional local)
24980d16
RS
584 "Remove from the value of HOOK the function FUNCTION.
585HOOK should be a symbol, and FUNCTION may be any valid function. If
586FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
0e4d378b
RS
587list of hooks to run in HOOK, then nothing is done. See `add-hook'.
588
589The optional third argument, LOCAL, if non-nil, says to modify
590the hook's buffer-local value rather than its default value.
591This makes no difference if the hook is not buffer-local.
592To make a hook variable buffer-local, always use
593`make-local-hook', not `make-local-variable'."
24980d16 594 (if (or (not (boundp hook)) ;unbound symbol, or
0e4d378b 595 (not (default-boundp 'hook))
24980d16
RS
596 (null (symbol-value hook)) ;value is nil, or
597 (null function)) ;function is nil, then
598 nil ;Do nothing.
f4e5bca5
RS
599 (if (or local
600 ;; Detect the case where make-local-variable was used on a hook
601 ;; and do what we used to do.
602 (and (local-variable-p hook)
603 (not (memq t (symbol-value hook)))))
0e4d378b
RS
604 (let ((hook-value (symbol-value hook)))
605 (if (consp hook-value)
606 (if (member function hook-value)
607 (setq hook-value (delete function (copy-sequence hook-value))))
608 (if (equal hook-value function)
609 (setq hook-value nil)))
610 (set hook hook-value))
611 (let ((hook-value (default-value hook)))
612 (if (consp hook-value)
613 (if (member function hook-value)
614 (setq hook-value (delete function (copy-sequence hook-value))))
615 (if (equal hook-value function)
616 (setq hook-value nil)))
617 (set-default hook hook-value)))))
6e3af630
RS
618
619(defun add-to-list (list-var element)
8851c1f0 620 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
9f0b1f09 621The test for presence of ELEMENT is done with `equal'.
8851c1f0
RS
622If you want to use `add-to-list' on a variable that is not defined
623until a certain package is loaded, you should put the call to `add-to-list'
624into a hook function that will be run only after loading the package.
625`eval-after-load' provides one way to do this. In some cases
626other hooks, such as major mode hooks, can do the job."
6e3af630
RS
627 (or (member element (symbol-value list-var))
628 (set list-var (cons element (symbol-value list-var)))))
be9b65ac 629\f
9a5336ae
JB
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.
634This makes or adds to an entry on `after-load-alist'.
90914938 635If FILE is already loaded, evaluate FORM right now.
12c7071c 636It does nothing if FORM is already on the list for FILE.
9a5336ae 637FILE should be the name of a library, with no directory name."
90914938 638 ;; Make sure there is an element for FILE.
9a5336ae
JB
639 (or (assoc file after-load-alist)
640 (setq after-load-alist (cons (list file) after-load-alist)))
90914938 641 ;; Add FORM to the element if it isn't there.
12c7071c
RS
642 (let ((elt (assoc file after-load-alist)))
643 (or (member form (cdr elt))
90914938
RS
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)))))
9a5336ae
JB
649 form)
650
651(defun eval-next-after-load (file)
652 "Read the following input sexp, and run it whenever FILE is loaded.
653This makes or adds to an entry on `after-load-alist'.
654FILE should be the name of a library, with no directory name."
655 (eval-after-load file (read)))
656
657\f
658;;;; Input and display facilities.
659
77a5664f 660(defvar read-quoted-char-radix 8
1ba764de 661 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
77a5664f
RS
662Legitimate radix values are 8, 10 and 16.")
663
664(custom-declare-variable-early
665 'read-quoted-char-radix 8
666 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
1ba764de
RS
667Legitimate radix values are 8, 10 and 16."
668 :type '(choice (const 8) (const 10) (const 16))
669 :group 'editing-basics)
670
9a5336ae 671(defun read-quoted-char (&optional prompt)
2444730b
RS
672 "Like `read-char', but do not allow quitting.
673Also, if the first character read is an octal digit,
674we read any number of octal digits and return the
675soecified character code. Any nondigit terminates the sequence.
1ba764de 676If the terminator is RET, it is discarded;
2444730b
RS
677any other terminator is used itself as input.
678
679The optional argument PROMPT specifies a string to use to prompt the user."
680 (let ((message-log-max nil) done (first t) (code 0) char)
681 (while (not done)
682 (let ((inhibit-quit first)
42e636f0
KH
683 ;; Don't let C-h get the help message--only help function keys.
684 (help-char nil)
685 (help-form
686 "Type the special character you want to use,
2444730b 687or the octal character code.
1ba764de 688RET terminates the character code and is discarded;
2444730b 689any other non-digit terminates the character code and is then used as input."))
9a5336ae 690 (and prompt (message "%s-" prompt))
1ba764de 691 (setq char (read-event))
9a5336ae 692 (if inhibit-quit (setq quit-flag nil)))
4867f7b2
RS
693 ;; Translate TAB key into control-I ASCII character, and so on.
694 (and char
695 (let ((translated (lookup-key function-key-map (vector char))))
696 (if translated
697 (setq char (aref translated 0)))))
9a5336ae 698 (cond ((null char))
1ba764de
RS
699 ((not (integerp char))
700 (setq unread-command-events (list char)
701 done t))
702 ((and (<= ?0 char) (< char (+ ?0 (min 10 read-quoted-char-radix))))
703 (setq code (+ (* code read-quoted-char-radix) (- char ?0)))
704 (and prompt (setq prompt (message "%s %c" prompt char))))
705 ((and (<= ?a (downcase char))
706 (< (downcase char) (+ ?a -10 (min 26 read-quoted-char-radix))))
707 (setq code (+ (* code read-quoted-char-radix) (+ 10 (- char ?a))))
91a6acc3 708 (and prompt (setq prompt (message "%s %c" prompt char))))
1ba764de 709 ((and (not first) (eq char ?\C-m))
2444730b
RS
710 (setq done t))
711 ((not first)
712 (setq unread-command-events (list char)
713 done t))
714 (t (setq code char
715 done t)))
716 (setq first nil))
0342b545 717 ;; Turn a meta-character into a character with the 0200 bit set.
1219a2a4 718 (logior (if (/= (logand code ?\M-\^@) 0) 128 0)
637b4708 719 code)))
9a5336ae
JB
720
721(defun force-mode-line-update (&optional all)
722 "Force the mode-line of the current buffer to be redisplayed.
7ec2a18c 723With optional non-nil ALL, force redisplay of all mode-lines."
9a5336ae
JB
724 (if all (save-excursion (set-buffer (other-buffer))))
725 (set-buffer-modified-p (buffer-modified-p)))
726
be9b65ac
DL
727(defun momentary-string-display (string pos &optional exit-char message)
728 "Momentarily display STRING in the buffer at POS.
729Display remains until next character is typed.
730If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
731otherwise it is then available as input (as a command if nothing else).
732Display MESSAGE (optional fourth arg) in the echo area.
733If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
734 (or exit-char (setq exit-char ?\ ))
735 (let ((buffer-read-only nil)
ca2ec1c5
RS
736 ;; Don't modify the undo list at all.
737 (buffer-undo-list t)
be9b65ac
DL
738 (modified (buffer-modified-p))
739 (name buffer-file-name)
740 insert-end)
741 (unwind-protect
742 (progn
743 (save-excursion
744 (goto-char pos)
745 ;; defeat file locking... don't try this at home, kids!
746 (setq buffer-file-name nil)
747 (insert-before-markers string)
3eec84bf
RS
748 (setq insert-end (point))
749 ;; If the message end is off screen, recenter now.
750 (if (> (window-end) insert-end)
751 (recenter (/ (window-height) 2)))
752 ;; If that pushed message start off the screen,
753 ;; scroll to start it at the top of the screen.
754 (move-to-window-line 0)
755 (if (> (point) pos)
756 (progn
757 (goto-char pos)
758 (recenter 0))))
be9b65ac
DL
759 (message (or message "Type %s to continue editing.")
760 (single-key-description exit-char))
3547c855 761 (let ((char (read-event)))
be9b65ac 762 (or (eq char exit-char)
dbc4e1c1 763 (setq unread-command-events (list char)))))
be9b65ac
DL
764 (if insert-end
765 (save-excursion
766 (delete-region pos insert-end)))
767 (setq buffer-file-name name)
768 (set-buffer-modified-p modified))))
769
9a5336ae
JB
770\f
771;;;; Miscellanea.
772
448b61c9
RS
773;; A number of major modes set this locally.
774;; Give it a global value to avoid compiler warnings.
775(defvar font-lock-defaults nil)
776
777;; Avoid compiler warnings about this variable,
778;; which has a special meaning on certain system types.
779(defvar buffer-file-type nil
780 "Non-nil if the visited file is a binary file.
781This variable is meaningful on MS-DOG and Windows NT.
782On those systems, it is automatically local in every buffer.
783On other systems, this variable is normally always nil.")
784
a860d25f 785;; This should probably be written in C (i.e., without using `walk-windows').
63503b24 786(defun get-buffer-window-list (buffer &optional minibuf frame)
a860d25f 787 "Return windows currently displaying BUFFER, or nil if none.
63503b24 788See `walk-windows' for the meaning of MINIBUF and FRAME."
43c5ac8c 789 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
a860d25f
SM
790 (walk-windows (function (lambda (window)
791 (if (eq (window-buffer window) buffer)
792 (setq windows (cons window windows)))))
63503b24 793 minibuf frame)
a860d25f
SM
794 windows))
795
f9269e19
RS
796(defun ignore (&rest ignore)
797 "Do nothing and return nil.
798This function accepts any number of arguments, but ignores them."
c0f1a4f6 799 (interactive)
9a5336ae
JB
800 nil)
801
802(defun error (&rest args)
aa308ce2
RS
803 "Signal an error, making error message by passing all args to `format'.
804In Emacs, the convention is that error messages start with a capital
805letter but *do not* end with a period. Please follow this convention
806for the sake of consistency."
9a5336ae
JB
807 (while t
808 (signal 'error (list (apply 'format args)))))
809
cef7ae6e 810(defalias 'user-original-login-name 'user-login-name)
9a5336ae 811
be9b65ac
DL
812(defun start-process-shell-command (name buffer &rest args)
813 "Start a program in a subprocess. Return the process object for it.
814Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
815NAME is name for process. It is modified if necessary to make it unique.
816BUFFER is the buffer or (buffer-name) to associate with the process.
817 Process output goes at end of that buffer, unless you specify
818 an output stream or filter function to handle the output.
819 BUFFER may be also nil, meaning that this process is not associated
820 with any buffer
821Third arg is command name, the name of a shell command.
822Remaining arguments are the arguments for the command.
4f1d6310 823Wildcards and redirection are handled as usual in the shell."
a247bf21
KH
824 (cond
825 ((eq system-type 'vax-vms)
826 (apply 'start-process name buffer args))
b59f6d7a
RS
827 ;; We used to use `exec' to replace the shell with the command,
828 ;; but that failed to handle (...) and semicolon, etc.
a247bf21
KH
829 (t
830 (start-process name buffer shell-file-name shell-command-switch
b59f6d7a 831 (mapconcat 'identity args " ")))))
a7ed4c2a 832\f
a7f284ec
RS
833(defmacro with-current-buffer (buffer &rest body)
834 "Execute the forms in BODY with BUFFER as the current buffer.
a2fdb55c
EN
835The value returned is the value of the last form in BODY.
836See also `with-temp-buffer'."
a7f284ec
RS
837 `(save-current-buffer
838 (set-buffer ,buffer)
a2fdb55c 839 ,@body))
a7f284ec 840
a7ed4c2a
RS
841(defmacro with-temp-file (file &rest forms)
842 "Create a new buffer, evaluate FORMS there, and write the buffer to FILE.
a2fdb55c
EN
843The value of the last form in FORMS is returned, like `progn'.
844See also `with-temp-buffer'."
a7ed4c2a 845 (let ((temp-file (make-symbol "temp-file"))
a2fdb55c
EN
846 (temp-buffer (make-symbol "temp-buffer")))
847 `(let ((,temp-file ,file)
848 (,temp-buffer
849 (get-buffer-create (generate-new-buffer-name " *temp file*"))))
850 (unwind-protect
851 (prog1
852 (with-current-buffer ,temp-buffer
853 ,@forms)
854 (with-current-buffer ,temp-buffer
855 (widen)
856 (write-region (point-min) (point-max) ,temp-file nil 0)))
857 (and (buffer-name ,temp-buffer)
858 (kill-buffer ,temp-buffer))))))
859
860(defmacro with-temp-buffer (&rest forms)
861 "Create a temporary buffer, and evaluate FORMS there like `progn'.
862See also `with-temp-file' and `with-output-to-string'."
863 (let ((temp-buffer (make-symbol "temp-buffer")))
864 `(let ((,temp-buffer
865 (get-buffer-create (generate-new-buffer-name " *temp*"))))
866 (unwind-protect
867 (with-current-buffer ,temp-buffer
868 ,@forms)
869 (and (buffer-name ,temp-buffer)
870 (kill-buffer ,temp-buffer))))))
871
5db7925d
RS
872(defmacro with-output-to-string (&rest body)
873 "Execute BODY, return the text it sent to `standard-output', as a string."
a2fdb55c
EN
874 `(let ((standard-output
875 (get-buffer-create (generate-new-buffer-name " *string-output*"))))
5db7925d
RS
876 (let ((standard-output standard-output))
877 ,@body)
a2fdb55c
EN
878 (with-current-buffer standard-output
879 (prog1
880 (buffer-string)
881 (kill-buffer nil)))))
2ec9c94e
RS
882
883(defmacro combine-after-change-calls (&rest body)
884 "Execute BODY, but don't call the after-change functions till the end.
885If BODY makes changes in the buffer, they are recorded
886and the functions on `after-change-functions' are called several times
887when BODY is finished.
31aa282e 888The return value is the value of the last form in BODY.
2ec9c94e
RS
889
890If `before-change-functions' is non-nil, then calls to the after-change
891functions can't be deferred, so in that case this macro has no effect.
892
893Do not alter `after-change-functions' or `before-change-functions'
894in BODY."
895 `(unwind-protect
896 (let ((combine-after-change-calls t))
897 . ,body)
898 (combine-after-change-execute)))
899
a2fdb55c 900\f
c7ca41e6
RS
901(defvar save-match-data-internal)
902
903;; We use save-match-data-internal as the local variable because
904;; that works ok in practice (people should not use that variable elsewhere).
905;; We used to use an uninterned symbol; the compiler handles that properly
906;; now, but it generates slower code.
9a5336ae
JB
907(defmacro save-match-data (&rest body)
908 "Execute the BODY forms, restoring the global value of the match data."
9fc0eb95 909 `(let ((save-match-data-internal (match-data)))
c7ca41e6
RS
910 (unwind-protect
911 (progn ,@body)
ecc06779 912 (store-match-data save-match-data-internal))))
993713ce 913
cd323f89 914(defun match-string (num &optional string)
993713ce
SM
915 "Return string of text matched by last search.
916NUM specifies which parenthesized expression in the last regexp.
917 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
918Zero means the entire text matched by the whole regexp or whole string.
919STRING should be given if the last search was by `string-match' on STRING."
cd323f89
SM
920 (if (match-beginning num)
921 (if string
922 (substring string (match-beginning num) (match-end num))
923 (buffer-substring (match-beginning num) (match-end num)))))
58f950b4 924
edce3654
RS
925(defun split-string (string &optional separators)
926 "Splits STRING into substrings where there are matches for SEPARATORS.
927Each match for SEPARATORS is a splitting point.
928The substrings between the splitting points are made into a list
929which is returned.
930If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
931 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
932 (start 0)
933 (list nil))
934 (while (string-match rexp string start)
7eb47123 935 (or (eq (match-beginning 0) 0)
edce3654
RS
936 (setq list
937 (cons (substring string start (match-beginning 0))
938 list)))
939 (setq start (match-end 0)))
940 (or (eq start (length string))
941 (setq list
942 (cons (substring string start)
943 list)))
944 (nreverse list)))
a7ed4c2a 945\f
8af7df60
RS
946(defun shell-quote-argument (argument)
947 "Quote an argument for passing as argument to an inferior shell."
c1c74b43
RS
948 (if (eq system-type 'ms-dos)
949 ;; MS-DOS shells don't have quoting, so don't do any.
950 argument
951 (if (eq system-type 'windows-nt)
952 (concat "\"" argument "\"")
e1b65a6b
RS
953 (if (equal argument "")
954 "''"
955 ;; Quote everything except POSIX filename characters.
956 ;; This should be safe enough even for really weird shells.
957 (let ((result "") (start 0) end)
958 (while (string-match "[^-0-9a-zA-Z_./]" argument start)
959 (setq end (match-beginning 0)
960 result (concat result (substring argument start end)
961 "\\" (substring argument end (1+ end)))
962 start (1+ end)))
963 (concat result (substring argument start)))))))
8af7df60 964
297d863b 965(defun make-syntax-table (&optional oldtable)
984f718a 966 "Return a new syntax table.
888eb98e
RS
967If OLDTABLE is non-nil, copy OLDTABLE.
968Otherwise, create a syntax table which inherits
969all letters and control characters from the standard syntax table;
970other characters are copied from the standard syntax table."
297d863b
KH
971 (if oldtable
972 (copy-syntax-table oldtable)
973 (let ((table (copy-syntax-table))
974 i)
975 (setq i 0)
976 (while (<= i 31)
a6889c57 977 (aset table i nil)
297d863b
KH
978 (setq i (1+ i)))
979 (setq i ?A)
980 (while (<= i ?Z)
a6889c57 981 (aset table i nil)
297d863b
KH
982 (setq i (1+ i)))
983 (setq i ?a)
984 (while (<= i ?z)
a6889c57 985 (aset table i nil)
297d863b
KH
986 (setq i (1+ i)))
987 (setq i 128)
988 (while (<= i 255)
a6889c57 989 (aset table i nil)
297d863b
KH
990 (setq i (1+ i)))
991 table)))
31aa282e
KH
992
993(defun add-to-invisibility-spec (arg)
994 "Add elements to `buffer-invisibility-spec'.
995See documentation for `buffer-invisibility-spec' for the kind of elements
996that can be added."
997 (cond
998 ((or (null buffer-invisibility-spec) (eq buffer-invisibility-spec t))
999 (setq buffer-invisibility-spec (list arg)))
1000 (t
11d431ad
KH
1001 (setq buffer-invisibility-spec
1002 (cons arg buffer-invisibility-spec)))))
31aa282e
KH
1003
1004(defun remove-from-invisibility-spec (arg)
1005 "Remove elements from `buffer-invisibility-spec'."
1006 (if buffer-invisibility-spec
071a2a71 1007 (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec))))
baed0109
RS
1008\f
1009(defun global-set-key (key command)
1010 "Give KEY a global binding as COMMAND.
1011COMMAND is a symbol naming an interactively-callable function.
1012KEY is a key sequence (a string or vector of characters or event types).
1013Non-ASCII characters with codes above 127 (such as ISO Latin-1)
1014can be included if you use a vector.
1015Note that if KEY has a local binding in the current buffer
1016that local binding will continue to shadow any global binding."
1017 (interactive "KSet key globally: \nCSet key %s to command: ")
1018 (or (vectorp key) (stringp key)
1019 (signal 'wrong-type-argument (list 'arrayp key)))
1020 (define-key (current-global-map) key command)
1021 nil)
1022
1023(defun local-set-key (key command)
1024 "Give KEY a local binding as COMMAND.
1025COMMAND is a symbol naming an interactively-callable function.
1026KEY is a key sequence (a string or vector of characters or event types).
1027Non-ASCII characters with codes above 127 (such as ISO Latin-1)
1028can be included if you use a vector.
1029The binding goes in the current buffer's local map,
1030which in most cases is shared with all other buffers in the same major mode."
1031 (interactive "KSet key locally: \nCSet key %s locally to command: ")
1032 (let ((map (current-local-map)))
1033 (or map
1034 (use-local-map (setq map (make-sparse-keymap))))
1035 (or (vectorp key) (stringp key)
1036 (signal 'wrong-type-argument (list 'arrayp key)))
1037 (define-key map key command))
1038 nil)
984f718a 1039
baed0109
RS
1040(defun global-unset-key (key)
1041 "Remove global binding of KEY.
1042KEY is a string representing a sequence of keystrokes."
1043 (interactive "kUnset key globally: ")
1044 (global-set-key key nil))
1045
db2474b8 1046(defun local-unset-key (key)
baed0109
RS
1047 "Remove local binding of KEY.
1048KEY is a string representing a sequence of keystrokes."
1049 (interactive "kUnset key locally: ")
1050 (if (current-local-map)
db2474b8 1051 (local-set-key key nil))
baed0109
RS
1052 nil)
1053\f
4809d0dd
KH
1054;; We put this here instead of in frame.el so that it's defined even on
1055;; systems where frame.el isn't loaded.
1056(defun frame-configuration-p (object)
1057 "Return non-nil if OBJECT seems to be a frame configuration.
1058Any list whose car is `frame-configuration' is assumed to be a frame
1059configuration."
1060 (and (consp object)
1061 (eq (car object) 'frame-configuration)))
1062
a9a44ed1 1063(defun functionp (object)
77a5664f 1064 "Non-nil if OBJECT is a type of object that can be called as a function."
a9a44ed1
RS
1065 (or (subrp object) (compiled-function-p object)
1066 (eq (car-safe object) 'lambda)
1067 (and (symbolp object) (fboundp object))))
1068
9a5336ae
JB
1069;; now in fns.c
1070;(defun nth (n list)
1071; "Returns the Nth element of LIST.
1072;N counts from zero. If LIST is not that long, nil is returned."
1073; (car (nthcdr n list)))
1074;
1075;(defun copy-alist (alist)
1076; "Return a copy of ALIST.
1077;This is a new alist which represents the same mapping
1078;from objects to objects, but does not share the alist structure with ALIST.
1079;The objects mapped (cars and cdrs of elements of the alist)
1080;are shared, however."
1081; (setq alist (copy-sequence alist))
1082; (let ((tail alist))
1083; (while tail
1084; (if (consp (car tail))
1085; (setcar tail (cons (car (car tail)) (cdr (car tail)))))
1086; (setq tail (cdr tail))))
1087; alist)
630cc463
ER
1088
1089;;; subr.el ends here