Undoing the changes erroneously committed just before.
[bpt/emacs.git] / lisp / subr.el
CommitLineData
c88ab9ce 1;;; subr.el --- basic lisp subroutines for Emacs
630cc463 2
b021ef18 3;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000 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
68e3e5f5 27;; Use this, rather than defcustom, in subr.el and other files loaded
77a5664f
RS
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
1be152fc 54(defmacro push (newelt listname)
fa65505b 55 "Add NEWELT to the list stored in the symbol LISTNAME.
1be152fc 56This is equivalent to (setq LISTNAME (cons NEWELT LISTNAME)).
d270117a 57LISTNAME must be a symbol."
22d85d00
DL
58 (list 'setq listname
59 (list 'cons newelt listname)))
d270117a
RS
60
61(defmacro pop (listname)
62 "Return the first element of LISTNAME's value, and remove it from the list.
63LISTNAME must be a symbol whose value is a list.
64If the value is nil, `pop' returns nil but does not actually
65change the list."
66 (list 'prog1 (list 'car listname)
67 (list 'setq listname (list 'cdr listname))))
68
debff3c3 69(defmacro when (cond &rest body)
b021ef18 70 "If COND yields non-nil, do BODY, else return nil."
debff3c3 71 (list 'if cond (cons 'progn body)))
9a5336ae 72
debff3c3 73(defmacro unless (cond &rest body)
b021ef18 74 "If COND yields nil, do BODY, else return nil."
debff3c3 75 (cons 'if (cons cond (cons nil body))))
d370591d 76
a0b0756a
RS
77(defmacro dolist (spec &rest body)
78 "(dolist (VAR LIST [RESULT]) BODY...): loop over a list.
79Evaluate BODY with VAR bound to each car from LIST, in turn.
80Then evaluate RESULT to get return value, default nil."
e4295aa1
RS
81 (let ((temp (make-symbol "--dolist-temp--")))
82 (list 'let (list (list temp (nth 1 spec)) (car spec))
83 (list 'while temp
84 (list 'setq (car spec) (list 'car temp))
85 (cons 'progn
86 (append body
87 (list (list 'setq temp (list 'cdr temp))))))
88 (if (cdr (cdr spec))
89 (cons 'progn
90 (cons (list 'setq (car spec) nil) (cdr (cdr spec))))))))
a0b0756a
RS
91
92(defmacro dotimes (spec &rest body)
93 "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times.
94Evaluate BODY with VAR bound to successive integers running from 0,
95inclusive, to COUNT, exclusive. Then evaluate RESULT to get
96the return value (nil if RESULT is omitted)."
e4295aa1
RS
97 (let ((temp (make-symbol "--dotimes-temp--")))
98 (list 'let (list (list temp (nth 1 spec)) (list (car spec) 0))
99 (list 'while (list '< (car spec) temp)
100 (cons 'progn
101 (append body (list (list 'setq (car spec)
102 (list '1+ (car spec)))))))
103 (if (cdr (cdr spec))
104 (car (cdr (cdr spec)))
105 nil))))
a0b0756a 106
d370591d
RS
107(defsubst caar (x)
108 "Return the car of the car of X."
109 (car (car x)))
110
111(defsubst cadr (x)
112 "Return the car of the cdr of X."
113 (car (cdr x)))
114
115(defsubst cdar (x)
116 "Return the cdr of the car of X."
117 (cdr (car x)))
118
119(defsubst cddr (x)
120 "Return the cdr of the cdr of X."
121 (cdr (cdr x)))
e8c32c99 122
369fba5f
RS
123(defun last (x &optional n)
124 "Return the last link of the list X. Its car is the last element.
125If X is nil, return nil.
126If N is non-nil, return the Nth-to-last link of X.
127If N is bigger than the length of X, return X."
128 (if n
129 (let ((m 0) (p x))
130 (while (consp p)
131 (setq m (1+ m) p (cdr p)))
132 (if (<= n 0) p
133 (if (< n m) (nthcdr (- m n) x) x)))
134 (while (cdr x)
135 (setq x (cdr x)))
136 x))
526d204e 137
13157efc
GM
138(defun remove (elt seq)
139 "Return a copy of SEQ with all occurences of ELT removed.
140SEQ must be a list, vector, or string. The comparison is done with `equal'."
141 (if (nlistp seq)
142 ;; If SEQ isn't a list, there's no need to copy SEQ because
143 ;; `delete' will return a new object.
144 (delete elt seq)
145 (delete elt (copy-sequence seq))))
146
147(defun remq (elt list)
148 "Return a copy of LIST with all occurences of ELT removed.
149The comparison is done with `eq'."
150 (if (memq elt list)
151 (delq elt (copy-sequence list))
152 list))
153
8a288450
RS
154(defun assoc-default (key alist &optional test default)
155 "Find object KEY in a pseudo-alist ALIST.
156ALIST is a list of conses or objects. Each element (or the element's car,
157if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
158If that is non-nil, the element matches;
159then `assoc-default' returns the element's cdr, if it is a cons,
526d204e 160or DEFAULT if the element is not a cons.
8a288450
RS
161
162If no element matches, the value is nil.
163If TEST is omitted or nil, `equal' is used."
164 (let (found (tail alist) value)
165 (while (and tail (not found))
166 (let ((elt (car tail)))
167 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key)
168 (setq found t value (if (consp elt) (cdr elt) default))))
169 (setq tail (cdr tail)))
170 value))
98aae5f6
KH
171
172(defun assoc-ignore-case (key alist)
173 "Like `assoc', but ignores differences in case and text representation.
174KEY must be a string. Upper-case and lower-case letters are treated as equal.
175Unibyte strings are converted to multibyte for comparison."
176 (let (element)
177 (while (and alist (not element))
178 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil t))
179 (setq element (car alist)))
180 (setq alist (cdr alist)))
181 element))
182
183(defun assoc-ignore-representation (key alist)
184 "Like `assoc', but ignores differences in text representation.
185KEY must be a string.
186Unibyte strings are converted to multibyte for comparison."
187 (let (element)
188 (while (and alist (not element))
189 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil))
190 (setq element (car alist)))
191 (setq alist (cdr alist)))
192 element))
cbbc3205
GM
193
194(defun member-ignore-case (elt list)
195 "Like `member', but ignores differences in case and text representation.
196ELT must be a string. Upper-case and lower-case letters are treated as equal.
197Unibyte strings are converted to multibyte for comparison."
198 (let (element)
199 (while (and list (not element))
200 (if (eq t (compare-strings elt 0 nil (car list) 0 nil t))
201 (setq element (car list)))
202 (setq list (cdr list)))
203 element))
204
9a5336ae 205\f
9a5336ae 206;;;; Keymap support.
be9b65ac
DL
207
208(defun undefined ()
209 (interactive)
210 (ding))
211
212;Prevent the \{...} documentation construct
213;from mentioning keys that run this command.
214(put 'undefined 'suppress-keymap t)
215
216(defun suppress-keymap (map &optional nodigits)
217 "Make MAP override all normally self-inserting keys to be undefined.
218Normally, as an exception, digits and minus-sign are set to make prefix args,
219but optional second arg NODIGITS non-nil treats them like other chars."
80e7b471 220 (substitute-key-definition 'self-insert-command 'undefined map global-map)
be9b65ac
DL
221 (or nodigits
222 (let (loop)
223 (define-key map "-" 'negative-argument)
224 ;; Make plain numbers do numeric args.
225 (setq loop ?0)
226 (while (<= loop ?9)
227 (define-key map (char-to-string loop) 'digit-argument)
228 (setq loop (1+ loop))))))
229
be9b65ac
DL
230;Moved to keymap.c
231;(defun copy-keymap (keymap)
232; "Return a copy of KEYMAP"
233; (while (not (keymapp keymap))
234; (setq keymap (signal 'wrong-type-argument (list 'keymapp keymap))))
235; (if (vectorp keymap)
236; (copy-sequence keymap)
237; (copy-alist keymap)))
238
f14dbba7
KH
239(defvar key-substitution-in-progress nil
240 "Used internally by substitute-key-definition.")
241
7f2c2edd 242(defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
be9b65ac
DL
243 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
244In other words, OLDDEF is replaced with NEWDEF where ever it appears.
4656b314 245Alternatively, if optional fourth argument OLDMAP is specified, we redefine
ff77cf40 246in KEYMAP as NEWDEF those keys which are defined as OLDDEF in OLDMAP."
739f2672
GM
247 ;; Don't document PREFIX in the doc string because we don't want to
248 ;; advertise it. It's meant for recursive calls only. Here's its
249 ;; meaning
250
251 ;; If optional argument PREFIX is specified, it should be a key
252 ;; prefix, a string. Redefined bindings will then be bound to the
253 ;; original key, with PREFIX added at the front.
7f2c2edd
RS
254 (or prefix (setq prefix ""))
255 (let* ((scan (or oldmap keymap))
256 (vec1 (vector nil))
f14dbba7
KH
257 (prefix1 (vconcat prefix vec1))
258 (key-substitution-in-progress
259 (cons scan key-substitution-in-progress)))
7f2c2edd
RS
260 ;; Scan OLDMAP, finding each char or event-symbol that
261 ;; has any definition, and act on it with hack-key.
262 (while (consp scan)
263 (if (consp (car scan))
264 (let ((char (car (car scan)))
265 (defn (cdr (car scan))))
266 ;; The inside of this let duplicates exactly
267 ;; the inside of the following let that handles array elements.
268 (aset vec1 0 char)
269 (aset prefix1 (length prefix) char)
44d798af 270 (let (inner-def skipped)
7f2c2edd
RS
271 ;; Skip past menu-prompt.
272 (while (stringp (car-safe defn))
44d798af 273 (setq skipped (cons (car defn) skipped))
7f2c2edd 274 (setq defn (cdr defn)))
e025dddf
RS
275 ;; Skip past cached key-equivalence data for menu items.
276 (and (consp defn) (consp (car defn))
277 (setq defn (cdr defn)))
7f2c2edd 278 (setq inner-def defn)
e025dddf 279 ;; Look past a symbol that names a keymap.
7f2c2edd
RS
280 (while (and (symbolp inner-def)
281 (fboundp inner-def))
282 (setq inner-def (symbol-function inner-def)))
328a37ec
RS
283 (if (or (eq defn olddef)
284 ;; Compare with equal if definition is a key sequence.
285 ;; That is useful for operating on function-key-map.
286 (and (or (stringp defn) (vectorp defn))
287 (equal defn olddef)))
44d798af 288 (define-key keymap prefix1 (nconc (nreverse skipped) newdef))
f14dbba7 289 (if (and (keymapp defn)
350b7567
RS
290 ;; Avoid recursively scanning
291 ;; where KEYMAP does not have a submap.
afd9831b
RS
292 (let ((elt (lookup-key keymap prefix1)))
293 (or (null elt)
294 (keymapp elt)))
350b7567 295 ;; Avoid recursively rescanning keymap being scanned.
f14dbba7
KH
296 (not (memq inner-def
297 key-substitution-in-progress)))
e025dddf
RS
298 ;; If this one isn't being scanned already,
299 ;; scan it now.
7f2c2edd
RS
300 (substitute-key-definition olddef newdef keymap
301 inner-def
302 prefix1)))))
916cc49f 303 (if (vectorp (car scan))
7f2c2edd
RS
304 (let* ((array (car scan))
305 (len (length array))
306 (i 0))
307 (while (< i len)
308 (let ((char i) (defn (aref array i)))
309 ;; The inside of this let duplicates exactly
310 ;; the inside of the previous let.
311 (aset vec1 0 char)
312 (aset prefix1 (length prefix) char)
44d798af 313 (let (inner-def skipped)
7f2c2edd
RS
314 ;; Skip past menu-prompt.
315 (while (stringp (car-safe defn))
44d798af 316 (setq skipped (cons (car defn) skipped))
7f2c2edd 317 (setq defn (cdr defn)))
e025dddf
RS
318 (and (consp defn) (consp (car defn))
319 (setq defn (cdr defn)))
7f2c2edd
RS
320 (setq inner-def defn)
321 (while (and (symbolp inner-def)
322 (fboundp inner-def))
323 (setq inner-def (symbol-function inner-def)))
328a37ec
RS
324 (if (or (eq defn olddef)
325 (and (or (stringp defn) (vectorp defn))
326 (equal defn olddef)))
44d798af
RS
327 (define-key keymap prefix1
328 (nconc (nreverse skipped) newdef))
f14dbba7 329 (if (and (keymapp defn)
afd9831b
RS
330 (let ((elt (lookup-key keymap prefix1)))
331 (or (null elt)
332 (keymapp elt)))
f14dbba7
KH
333 (not (memq inner-def
334 key-substitution-in-progress)))
7f2c2edd
RS
335 (substitute-key-definition olddef newdef keymap
336 inner-def
337 prefix1)))))
97fd9abf
RS
338 (setq i (1+ i))))
339 (if (char-table-p (car scan))
340 (map-char-table
341 (function (lambda (char defn)
342 (let ()
343 ;; The inside of this let duplicates exactly
344 ;; the inside of the previous let,
345 ;; except that it uses set-char-table-range
346 ;; instead of define-key.
347 (aset vec1 0 char)
348 (aset prefix1 (length prefix) char)
349 (let (inner-def skipped)
350 ;; Skip past menu-prompt.
351 (while (stringp (car-safe defn))
352 (setq skipped (cons (car defn) skipped))
353 (setq defn (cdr defn)))
354 (and (consp defn) (consp (car defn))
355 (setq defn (cdr defn)))
356 (setq inner-def defn)
357 (while (and (symbolp inner-def)
358 (fboundp inner-def))
359 (setq inner-def (symbol-function inner-def)))
360 (if (or (eq defn olddef)
361 (and (or (stringp defn) (vectorp defn))
362 (equal defn olddef)))
9a5114ac
RS
363 (define-key keymap prefix1
364 (nconc (nreverse skipped) newdef))
97fd9abf
RS
365 (if (and (keymapp defn)
366 (let ((elt (lookup-key keymap prefix1)))
367 (or (null elt)
368 (keymapp elt)))
369 (not (memq inner-def
370 key-substitution-in-progress)))
371 (substitute-key-definition olddef newdef keymap
372 inner-def
373 prefix1)))))))
374 (car scan)))))
7f2c2edd 375 (setq scan (cdr scan)))))
9a5336ae 376
4ced66fd 377(defun define-key-after (keymap key definition &optional after)
4434d61b
RS
378 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
379This is like `define-key' except that the binding for KEY is placed
380just after the binding for the event AFTER, instead of at the beginning
c34a9d34
RS
381of the map. Note that AFTER must be an event type (like KEY), NOT a command
382\(like DEFINITION).
383
4ced66fd 384If AFTER is t or omitted, the new binding goes at the end of the keymap.
c34a9d34 385
4ced66fd
DL
386KEY must contain just one event type--that is to say, it must be a
387string or vector of length 1, but AFTER should be a single event
388type--a symbol or a character, not a sequence.
c34a9d34 389
4ced66fd 390Bindings are always added before any inherited map.
c34a9d34 391
4ced66fd
DL
392The order of bindings in a keymap matters when it is used as a menu."
393 (unless after (setq after t))
4434d61b
RS
394 (or (keymapp keymap)
395 (signal 'wrong-type-argument (list 'keymapp keymap)))
ab375e6c 396 (if (> (length key) 1)
626f67f3 397 (error "multi-event key specified in `define-key-after'"))
113d28a8 398 (let ((tail keymap) done inserted
4434d61b
RS
399 (first (aref key 0)))
400 (while (and (not done) tail)
401 ;; Delete any earlier bindings for the same key.
402 (if (eq (car-safe (car (cdr tail))) first)
403 (setcdr tail (cdr (cdr tail))))
404 ;; When we reach AFTER's binding, insert the new binding after.
405 ;; If we reach an inherited keymap, insert just before that.
113d28a8 406 ;; If we reach the end of this keymap, insert at the end.
c34a9d34
RS
407 (if (or (and (eq (car-safe (car tail)) after)
408 (not (eq after t)))
113d28a8
RS
409 (eq (car (cdr tail)) 'keymap)
410 (null (cdr tail)))
4434d61b 411 (progn
113d28a8
RS
412 ;; Stop the scan only if we find a parent keymap.
413 ;; Keep going past the inserted element
414 ;; so we can delete any duplications that come later.
415 (if (eq (car (cdr tail)) 'keymap)
416 (setq done t))
417 ;; Don't insert more than once.
418 (or inserted
419 (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))))
420 (setq inserted t)))
4434d61b
RS
421 (setq tail (cdr tail)))))
422
d128fe85
RS
423(defmacro kbd (keys)
424 "Convert KEYS to the internal Emacs key representation.
425KEYS should be a string constant in the format used for
426saving keyboard macros (see `insert-kbd-macro')."
427 (read-kbd-macro keys))
428
8bed5e3d
RS
429(put 'keyboard-translate-table 'char-table-extra-slots 0)
430
9a5336ae
JB
431(defun keyboard-translate (from to)
432 "Translate character FROM to TO at a low level.
433This function creates a `keyboard-translate-table' if necessary
434and then modifies one entry in it."
8bed5e3d
RS
435 (or (char-table-p keyboard-translate-table)
436 (setq keyboard-translate-table
437 (make-char-table 'keyboard-translate-table nil)))
9a5336ae
JB
438 (aset keyboard-translate-table from to))
439
440\f
441;;;; The global keymap tree.
442
443;;; global-map, esc-map, and ctl-x-map have their values set up in
444;;; keymap.c; we just give them docstrings here.
445
446(defvar global-map nil
447 "Default global keymap mapping Emacs keyboard input into commands.
448The value is a keymap which is usually (but not necessarily) Emacs's
449global map.")
450
451(defvar esc-map nil
452 "Default keymap for ESC (meta) commands.
453The normal global definition of the character ESC indirects to this keymap.")
454
455(defvar ctl-x-map nil
456 "Default keymap for C-x commands.
457The normal global definition of the character C-x indirects to this keymap.")
458
459(defvar ctl-x-4-map (make-sparse-keymap)
460 "Keymap for subcommands of C-x 4")
059184dd 461(defalias 'ctl-x-4-prefix ctl-x-4-map)
9a5336ae
JB
462(define-key ctl-x-map "4" 'ctl-x-4-prefix)
463
464(defvar ctl-x-5-map (make-sparse-keymap)
465 "Keymap for frame commands.")
059184dd 466(defalias 'ctl-x-5-prefix ctl-x-5-map)
9a5336ae
JB
467(define-key ctl-x-map "5" 'ctl-x-5-prefix)
468
0f03054a 469\f
9a5336ae
JB
470;;;; Event manipulation functions.
471
da16e648
KH
472;; The call to `read' is to ensure that the value is computed at load time
473;; and not compiled into the .elc file. The value is negative on most
474;; machines, but not on all!
475(defconst listify-key-sequence-1 (logior 128 (read "?\\M-\\^@")))
114137b8 476
cde6d7e3
RS
477(defun listify-key-sequence (key)
478 "Convert a key sequence to a list of events."
479 (if (vectorp key)
480 (append key nil)
481 (mapcar (function (lambda (c)
482 (if (> c 127)
114137b8 483 (logxor c listify-key-sequence-1)
cde6d7e3
RS
484 c)))
485 (append key nil))))
486
53e5a4e8
RS
487(defsubst eventp (obj)
488 "True if the argument is an event object."
489 (or (integerp obj)
490 (and (symbolp obj)
491 (get obj 'event-symbol-elements))
492 (and (consp obj)
493 (symbolp (car obj))
494 (get (car obj) 'event-symbol-elements))))
495
496(defun event-modifiers (event)
497 "Returns a list of symbols representing the modifier keys in event EVENT.
498The elements of the list may include `meta', `control',
32295976
RS
499`shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
500and `down'."
53e5a4e8
RS
501 (let ((type event))
502 (if (listp type)
503 (setq type (car type)))
504 (if (symbolp type)
505 (cdr (get type 'event-symbol-elements))
506 (let ((list nil))
da16e648 507 (or (zerop (logand type ?\M-\^@))
53e5a4e8 508 (setq list (cons 'meta list)))
da16e648 509 (or (and (zerop (logand type ?\C-\^@))
53e5a4e8
RS
510 (>= (logand type 127) 32))
511 (setq list (cons 'control list)))
da16e648 512 (or (and (zerop (logand type ?\S-\^@))
53e5a4e8
RS
513 (= (logand type 255) (downcase (logand type 255))))
514 (setq list (cons 'shift list)))
da16e648 515 (or (zerop (logand type ?\H-\^@))
53e5a4e8 516 (setq list (cons 'hyper list)))
da16e648 517 (or (zerop (logand type ?\s-\^@))
53e5a4e8 518 (setq list (cons 'super list)))
da16e648 519 (or (zerop (logand type ?\A-\^@))
53e5a4e8
RS
520 (setq list (cons 'alt list)))
521 list))))
522
d63de416
RS
523(defun event-basic-type (event)
524 "Returns the basic type of the given event (all modifiers removed).
525The value is an ASCII printing character (not upper case) or a symbol."
2b0f4ba5
JB
526 (if (consp event)
527 (setq event (car event)))
d63de416
RS
528 (if (symbolp event)
529 (car (get event 'event-symbol-elements))
530 (let ((base (logand event (1- (lsh 1 18)))))
531 (downcase (if (< base 32) (logior base 64) base)))))
532
0f03054a
RS
533(defsubst mouse-movement-p (object)
534 "Return non-nil if OBJECT is a mouse movement event."
535 (and (consp object)
536 (eq (car object) 'mouse-movement)))
537
538(defsubst event-start (event)
539 "Return the starting position of EVENT.
540If EVENT is a mouse press or a mouse click, this returns the location
541of the event.
542If EVENT is a drag, this returns the drag's starting position.
543The return value is of the form
e55c21be 544 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a
RS
545The `posn-' functions access elements of such lists."
546 (nth 1 event))
547
548(defsubst event-end (event)
549 "Return the ending location of EVENT. EVENT should be a click or drag event.
550If EVENT is a click event, this function is the same as `event-start'.
551The return value is of the form
e55c21be 552 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a 553The `posn-' functions access elements of such lists."
69b95560 554 (nth (if (consp (nth 2 event)) 2 1) event))
0f03054a 555
32295976
RS
556(defsubst event-click-count (event)
557 "Return the multi-click count of EVENT, a click or drag event.
558The return value is a positive integer."
559 (if (integerp (nth 2 event)) (nth 2 event) 1))
560
0f03054a
RS
561(defsubst posn-window (position)
562 "Return the window in POSITION.
563POSITION should be a list of the form
e55c21be 564 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a
RS
565as returned by the `event-start' and `event-end' functions."
566 (nth 0 position))
567
568(defsubst posn-point (position)
569 "Return the buffer location in POSITION.
570POSITION should be a list of the form
e55c21be 571 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a 572as returned by the `event-start' and `event-end' functions."
15db4e0e
JB
573 (if (consp (nth 1 position))
574 (car (nth 1 position))
575 (nth 1 position)))
0f03054a 576
e55c21be
RS
577(defsubst posn-x-y (position)
578 "Return the x and y coordinates in POSITION.
0f03054a 579POSITION should be a list of the form
e55c21be 580 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
0f03054a
RS
581as returned by the `event-start' and `event-end' functions."
582 (nth 2 position))
583
ed627e08 584(defun posn-col-row (position)
dbbcac56 585 "Return the column and row in POSITION, measured in characters.
e55c21be
RS
586POSITION should be a list of the form
587 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
ed627e08
RS
588as returned by the `event-start' and `event-end' functions.
589For a scroll-bar event, the result column is 0, and the row
590corresponds to the vertical position of the click in the scroll bar."
591 (let ((pair (nth 2 position))
592 (window (posn-window position)))
dbbcac56
KH
593 (if (eq (if (consp (nth 1 position))
594 (car (nth 1 position))
595 (nth 1 position))
ed627e08
RS
596 'vertical-scroll-bar)
597 (cons 0 (scroll-bar-scale pair (1- (window-height window))))
dbbcac56
KH
598 (if (eq (if (consp (nth 1 position))
599 (car (nth 1 position))
600 (nth 1 position))
ed627e08
RS
601 'horizontal-scroll-bar)
602 (cons (scroll-bar-scale pair (window-width window)) 0)
9ba60df9
RS
603 (let* ((frame (if (framep window) window (window-frame window)))
604 (x (/ (car pair) (frame-char-width frame)))
605 (y (/ (cdr pair) (frame-char-height frame))))
ed627e08 606 (cons x y))))))
e55c21be 607
0f03054a
RS
608(defsubst posn-timestamp (position)
609 "Return the timestamp of POSITION.
610POSITION should be a list of the form
e55c21be 611 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
f415c00c 612as returned by the `event-start' and `event-end' functions."
0f03054a 613 (nth 3 position))
9a5336ae 614
0f03054a 615\f
9a5336ae
JB
616;;;; Obsolescent names for functions.
617
059184dd
ER
618(defalias 'dot 'point)
619(defalias 'dot-marker 'point-marker)
620(defalias 'dot-min 'point-min)
621(defalias 'dot-max 'point-max)
622(defalias 'window-dot 'window-point)
623(defalias 'set-window-dot 'set-window-point)
624(defalias 'read-input 'read-string)
625(defalias 'send-string 'process-send-string)
626(defalias 'send-region 'process-send-region)
627(defalias 'show-buffer 'set-window-buffer)
628(defalias 'buffer-flush-undo 'buffer-disable-undo)
629(defalias 'eval-current-buffer 'eval-buffer)
630(defalias 'compiled-function-p 'byte-code-function-p)
ae1cc031 631(defalias 'define-function 'defalias)
be9b65ac 632
0cba3a0f 633(defalias 'sref 'aref)
2598a293
SM
634(make-obsolete 'sref 'aref "20.4")
635(make-obsolete 'char-bytes "Now this function always returns 1" "20.4")
6bb762b3 636
9a5336ae
JB
637;; Some programs still use this as a function.
638(defun baud-rate ()
bcacc42c
RS
639 "Obsolete function returning the value of the `baud-rate' variable.
640Please convert your programs to use the variable `baud-rate' directly."
9a5336ae
JB
641 baud-rate)
642
0a5c0893
MB
643(defalias 'focus-frame 'ignore)
644(defalias 'unfocus-frame 'ignore)
9a5336ae
JB
645\f
646;;;; Alternate names for functions - these are not being phased out.
647
059184dd
ER
648(defalias 'string= 'string-equal)
649(defalias 'string< 'string-lessp)
650(defalias 'move-marker 'set-marker)
059184dd
ER
651(defalias 'not 'null)
652(defalias 'rplaca 'setcar)
653(defalias 'rplacd 'setcdr)
eb8c3be9 654(defalias 'beep 'ding) ;preserve lingual purity
059184dd
ER
655(defalias 'indent-to-column 'indent-to)
656(defalias 'backward-delete-char 'delete-backward-char)
657(defalias 'search-forward-regexp (symbol-function 're-search-forward))
658(defalias 'search-backward-regexp (symbol-function 're-search-backward))
659(defalias 'int-to-string 'number-to-string)
024ae2c6 660(defalias 'store-match-data 'set-match-data)
d6c22d46 661;; These are the XEmacs names:
475fb2fb
KH
662(defalias 'point-at-eol 'line-end-position)
663(defalias 'point-at-bol 'line-beginning-position)
37f6661a
JB
664
665;;; Should this be an obsolete name? If you decide it should, you get
666;;; to go through all the sources and change them.
059184dd 667(defalias 'string-to-int 'string-to-number)
be9b65ac 668\f
9a5336ae 669;;;; Hook manipulation functions.
be9b65ac 670
0e4d378b
RS
671(defun make-local-hook (hook)
672 "Make the hook HOOK local to the current buffer.
71c78f01
RS
673The return value is HOOK.
674
c344cf32
SM
675You never need to call this function now that `add-hook' does it for you
676if its LOCAL argument is non-nil.
677
0e4d378b
RS
678When a hook is local, its local and global values
679work in concert: running the hook actually runs all the hook
680functions listed in *either* the local value *or* the global value
681of the hook variable.
682
7dd1926e
RS
683This function works by making `t' a member of the buffer-local value,
684which acts as a flag to run the hook functions in the default value as
685well. This works for all normal hooks, but does not work for most
686non-normal hooks yet. We will be changing the callers of non-normal
687hooks so that they can handle localness; this has to be done one by
688one.
689
690This function does nothing if HOOK is already local in the current
691buffer.
0e4d378b
RS
692
693Do not use `make-local-variable' to make a hook variable buffer-local."
694 (if (local-variable-p hook)
695 nil
696 (or (boundp hook) (set hook nil))
697 (make-local-variable hook)
71c78f01
RS
698 (set hook (list t)))
699 hook)
0e4d378b
RS
700
701(defun add-hook (hook function &optional append local)
32295976
RS
702 "Add to the value of HOOK the function FUNCTION.
703FUNCTION is not added if already present.
704FUNCTION is added (if necessary) at the beginning of the hook list
705unless the optional argument APPEND is non-nil, in which case
706FUNCTION is added at the end.
707
0e4d378b
RS
708The optional fourth argument, LOCAL, if non-nil, says to modify
709the hook's buffer-local value rather than its default value.
8947a5e2 710This makes the hook buffer-local if needed.
0e4d378b
RS
711To make a hook variable buffer-local, always use
712`make-local-hook', not `make-local-variable'.
713
32295976
RS
714HOOK should be a symbol, and FUNCTION may be any valid function. If
715HOOK is void, it is first set to nil. If HOOK's value is a single
aa09b5ca 716function, it is changed to a list of functions."
be9b65ac 717 (or (boundp hook) (set hook nil))
0e4d378b 718 (or (default-boundp hook) (set-default hook nil))
79372165 719 (if local (unless (local-variable-if-set-p hook) (make-local-hook hook))
8947a5e2
SM
720 ;; Detect the case where make-local-variable was used on a hook
721 ;; and do what we used to do.
722 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook)))
723 (setq local t)))
724 (let ((hook-value (if local (symbol-value hook) (default-value hook))))
725 ;; If the hook value is a single function, turn it into a list.
726 (when (or (not (listp hook-value)) (eq (car hook-value) 'lambda))
2248c40d 727 (setq hook-value (list hook-value)))
8947a5e2
SM
728 ;; Do the actual addition if necessary
729 (unless (member function hook-value)
730 (setq hook-value
731 (if append
732 (append hook-value (list function))
733 (cons function hook-value))))
734 ;; Set the actual variable
735 (if local (set hook hook-value) (set-default hook hook-value))))
0e4d378b
RS
736
737(defun remove-hook (hook function &optional local)
24980d16
RS
738 "Remove from the value of HOOK the function FUNCTION.
739HOOK should be a symbol, and FUNCTION may be any valid function. If
740FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
0e4d378b
RS
741list of hooks to run in HOOK, then nothing is done. See `add-hook'.
742
743The optional third argument, LOCAL, if non-nil, says to modify
744the hook's buffer-local value rather than its default value.
8947a5e2 745This makes the hook buffer-local if needed.
0e4d378b
RS
746To make a hook variable buffer-local, always use
747`make-local-hook', not `make-local-variable'."
8947a5e2
SM
748 (or (boundp hook) (set hook nil))
749 (or (default-boundp hook) (set-default hook nil))
79372165 750 (if local (unless (local-variable-if-set-p hook) (make-local-hook hook))
8947a5e2
SM
751 ;; Detect the case where make-local-variable was used on a hook
752 ;; and do what we used to do.
753 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook)))
754 (setq local t)))
755 (let ((hook-value (if local (symbol-value hook) (default-value hook))))
e4da9c1c
SM
756 ;; Remove the function, for both the list and the non-list cases.
757 (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda))
758 (if (equal hook-value function) (setq hook-value nil))
759 (setq hook-value (delete function (copy-sequence hook-value))))
8947a5e2
SM
760 ;; If the function is on the global hook, we need to shadow it locally
761 ;;(when (and local (member function (default-value hook))
762 ;; (not (member (cons 'not function) hook-value)))
763 ;; (push (cons 'not function) hook-value))
764 ;; Set the actual variable
765 (if local (set hook hook-value) (set-default hook hook-value))))
6e3af630 766
c8bfa689 767(defun add-to-list (list-var element &optional append)
8851c1f0 768 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
9f0b1f09 769The test for presence of ELEMENT is done with `equal'.
c8bfa689
MB
770If ELEMENT is added, it is added at the beginning of the list,
771unless the optional argument APPEND is non-nil, in which case
772ELEMENT is added at the end.
508bcbca 773
8851c1f0
RS
774If you want to use `add-to-list' on a variable that is not defined
775until a certain package is loaded, you should put the call to `add-to-list'
776into a hook function that will be run only after loading the package.
777`eval-after-load' provides one way to do this. In some cases
778other hooks, such as major mode hooks, can do the job."
15171a06
KH
779 (if (member element (symbol-value list-var))
780 (symbol-value list-var)
c8bfa689
MB
781 (set list-var
782 (if append
783 (append (symbol-value list-var) (list element))
784 (cons element (symbol-value list-var))))))
be9b65ac 785\f
9a5336ae
JB
786;;;; Specifying things to do after certain files are loaded.
787
788(defun eval-after-load (file form)
789 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
790This makes or adds to an entry on `after-load-alist'.
90914938 791If FILE is already loaded, evaluate FORM right now.
12c7071c 792It does nothing if FORM is already on the list for FILE.
9a5336ae 793FILE should be the name of a library, with no directory name."
90914938 794 ;; Make sure there is an element for FILE.
9a5336ae
JB
795 (or (assoc file after-load-alist)
796 (setq after-load-alist (cons (list file) after-load-alist)))
90914938 797 ;; Add FORM to the element if it isn't there.
12c7071c
RS
798 (let ((elt (assoc file after-load-alist)))
799 (or (member form (cdr elt))
90914938
RS
800 (progn
801 (nconc elt (list form))
802 ;; If the file has been loaded already, run FORM right away.
803 (and (assoc file load-history)
804 (eval form)))))
9a5336ae
JB
805 form)
806
807(defun eval-next-after-load (file)
808 "Read the following input sexp, and run it whenever FILE is loaded.
809This makes or adds to an entry on `after-load-alist'.
810FILE should be the name of a library, with no directory name."
811 (eval-after-load file (read)))
812
813\f
814;;;; Input and display facilities.
815
77a5664f 816(defvar read-quoted-char-radix 8
1ba764de 817 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
77a5664f
RS
818Legitimate radix values are 8, 10 and 16.")
819
820(custom-declare-variable-early
821 'read-quoted-char-radix 8
822 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
1ba764de
RS
823Legitimate radix values are 8, 10 and 16."
824 :type '(choice (const 8) (const 10) (const 16))
825 :group 'editing-basics)
826
9a5336ae 827(defun read-quoted-char (&optional prompt)
2444730b
RS
828 "Like `read-char', but do not allow quitting.
829Also, if the first character read is an octal digit,
830we read any number of octal digits and return the
569b03f2 831specified character code. Any nondigit terminates the sequence.
1ba764de 832If the terminator is RET, it is discarded;
2444730b
RS
833any other terminator is used itself as input.
834
569b03f2
RS
835The optional argument PROMPT specifies a string to use to prompt the user.
836The variable `read-quoted-char-radix' controls which radix to use
837for numeric input."
2444730b
RS
838 (let ((message-log-max nil) done (first t) (code 0) char)
839 (while (not done)
840 (let ((inhibit-quit first)
42e636f0
KH
841 ;; Don't let C-h get the help message--only help function keys.
842 (help-char nil)
843 (help-form
844 "Type the special character you want to use,
2444730b 845or the octal character code.
1ba764de 846RET terminates the character code and is discarded;
2444730b 847any other non-digit terminates the character code and is then used as input."))
b7de4d62 848 (setq char (read-event (and prompt (format "%s-" prompt)) t))
9a5336ae 849 (if inhibit-quit (setq quit-flag nil)))
4867f7b2
RS
850 ;; Translate TAB key into control-I ASCII character, and so on.
851 (and char
852 (let ((translated (lookup-key function-key-map (vector char))))
bf896a1b 853 (if (arrayp translated)
4867f7b2 854 (setq char (aref translated 0)))))
9a5336ae 855 (cond ((null char))
1ba764de
RS
856 ((not (integerp char))
857 (setq unread-command-events (list char)
858 done t))
bf896a1b
RS
859 ((/= (logand char ?\M-\^@) 0)
860 ;; Turn a meta-character into a character with the 0200 bit set.
861 (setq code (logior (logand char (lognot ?\M-\^@)) 128)
862 done t))
1ba764de
RS
863 ((and (<= ?0 char) (< char (+ ?0 (min 10 read-quoted-char-radix))))
864 (setq code (+ (* code read-quoted-char-radix) (- char ?0)))
865 (and prompt (setq prompt (message "%s %c" prompt char))))
866 ((and (<= ?a (downcase char))
867 (< (downcase char) (+ ?a -10 (min 26 read-quoted-char-radix))))
92304bc8
RS
868 (setq code (+ (* code read-quoted-char-radix)
869 (+ 10 (- (downcase char) ?a))))
91a6acc3 870 (and prompt (setq prompt (message "%s %c" prompt char))))
1ba764de 871 ((and (not first) (eq char ?\C-m))
2444730b
RS
872 (setq done t))
873 ((not first)
874 (setq unread-command-events (list char)
875 done t))
876 (t (setq code char
877 done t)))
878 (setq first nil))
bf896a1b 879 code))
9a5336ae 880
44071d6b
RS
881(defun read-passwd (prompt &optional confirm default)
882 "Read a password, prompting with PROMPT. Echo `.' for each character typed.
e0e4cb7a 883End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.
44071d6b
RS
884Optional argument CONFIRM, if non-nil, then read it twice to make sure.
885Optional DEFAULT is a default password to use instead of empty input."
886 (if confirm
887 (let (success)
888 (while (not success)
889 (let ((first (read-passwd prompt nil default))
890 (second (read-passwd "Confirm password: " nil default)))
891 (if (equal first second)
892 (setq success first)
893 (message "Password not repeated accurately; please start over")
894 (sit-for 1))))
895 success)
896 (let ((pass nil)
897 (c 0)
898 (echo-keystrokes 0)
899 (cursor-in-echo-area t))
900 (while (progn (message "%s%s"
901 prompt
902 (make-string (length pass) ?.))
42ccb7c8 903 (setq c (read-char-exclusive nil t))
44071d6b
RS
904 (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
905 (if (= c ?\C-u)
906 (setq pass "")
907 (if (and (/= c ?\b) (/= c ?\177))
908 (setq pass (concat pass (char-to-string c)))
909 (if (> (length pass) 0)
910 (setq pass (substring pass 0 -1))))))
b021ef18 911 (clear-this-command-keys)
44071d6b
RS
912 (message nil)
913 (or pass default ""))))
e0e4cb7a 914\f
9a5336ae
JB
915(defun force-mode-line-update (&optional all)
916 "Force the mode-line of the current buffer to be redisplayed.
7ec2a18c 917With optional non-nil ALL, force redisplay of all mode-lines."
9a5336ae
JB
918 (if all (save-excursion (set-buffer (other-buffer))))
919 (set-buffer-modified-p (buffer-modified-p)))
920
be9b65ac
DL
921(defun momentary-string-display (string pos &optional exit-char message)
922 "Momentarily display STRING in the buffer at POS.
923Display remains until next character is typed.
924If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
925otherwise it is then available as input (as a command if nothing else).
926Display MESSAGE (optional fourth arg) in the echo area.
927If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
928 (or exit-char (setq exit-char ?\ ))
c306e0e0 929 (let ((inhibit-read-only t)
ca2ec1c5
RS
930 ;; Don't modify the undo list at all.
931 (buffer-undo-list t)
be9b65ac
DL
932 (modified (buffer-modified-p))
933 (name buffer-file-name)
934 insert-end)
935 (unwind-protect
936 (progn
937 (save-excursion
938 (goto-char pos)
939 ;; defeat file locking... don't try this at home, kids!
940 (setq buffer-file-name nil)
941 (insert-before-markers string)
3eec84bf
RS
942 (setq insert-end (point))
943 ;; If the message end is off screen, recenter now.
024ae2c6 944 (if (< (window-end nil t) insert-end)
3eec84bf
RS
945 (recenter (/ (window-height) 2)))
946 ;; If that pushed message start off the screen,
947 ;; scroll to start it at the top of the screen.
948 (move-to-window-line 0)
949 (if (> (point) pos)
950 (progn
951 (goto-char pos)
952 (recenter 0))))
be9b65ac
DL
953 (message (or message "Type %s to continue editing.")
954 (single-key-description exit-char))
3547c855 955 (let ((char (read-event)))
be9b65ac 956 (or (eq char exit-char)
dbc4e1c1 957 (setq unread-command-events (list char)))))
be9b65ac
DL
958 (if insert-end
959 (save-excursion
960 (delete-region pos insert-end)))
961 (setq buffer-file-name name)
962 (set-buffer-modified-p modified))))
963
9a5336ae
JB
964\f
965;;;; Miscellanea.
966
448b61c9
RS
967;; A number of major modes set this locally.
968;; Give it a global value to avoid compiler warnings.
969(defvar font-lock-defaults nil)
970
4fb17037
RS
971(defvar suspend-hook nil
972 "Normal hook run by `suspend-emacs', before suspending.")
973
974(defvar suspend-resume-hook nil
975 "Normal hook run by `suspend-emacs', after Emacs is continued.")
976
448b61c9
RS
977;; Avoid compiler warnings about this variable,
978;; which has a special meaning on certain system types.
979(defvar buffer-file-type nil
980 "Non-nil if the visited file is a binary file.
981This variable is meaningful on MS-DOG and Windows NT.
982On those systems, it is automatically local in every buffer.
983On other systems, this variable is normally always nil.")
984
a860d25f 985;; This should probably be written in C (i.e., without using `walk-windows').
63503b24 986(defun get-buffer-window-list (buffer &optional minibuf frame)
a860d25f 987 "Return windows currently displaying BUFFER, or nil if none.
63503b24 988See `walk-windows' for the meaning of MINIBUF and FRAME."
43c5ac8c 989 (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
a860d25f
SM
990 (walk-windows (function (lambda (window)
991 (if (eq (window-buffer window) buffer)
992 (setq windows (cons window windows)))))
63503b24 993 minibuf frame)
a860d25f
SM
994 windows))
995
f9269e19
RS
996(defun ignore (&rest ignore)
997 "Do nothing and return nil.
998This function accepts any number of arguments, but ignores them."
c0f1a4f6 999 (interactive)
9a5336ae
JB
1000 nil)
1001
1002(defun error (&rest args)
aa308ce2
RS
1003 "Signal an error, making error message by passing all args to `format'.
1004In Emacs, the convention is that error messages start with a capital
1005letter but *do not* end with a period. Please follow this convention
1006for the sake of consistency."
9a5336ae
JB
1007 (while t
1008 (signal 'error (list (apply 'format args)))))
1009
cef7ae6e 1010(defalias 'user-original-login-name 'user-login-name)
9a5336ae 1011
be9b65ac
DL
1012(defun start-process-shell-command (name buffer &rest args)
1013 "Start a program in a subprocess. Return the process object for it.
1014Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
1015NAME is name for process. It is modified if necessary to make it unique.
1016BUFFER is the buffer or (buffer-name) to associate with the process.
1017 Process output goes at end of that buffer, unless you specify
1018 an output stream or filter function to handle the output.
1019 BUFFER may be also nil, meaning that this process is not associated
1020 with any buffer
1021Third arg is command name, the name of a shell command.
1022Remaining arguments are the arguments for the command.
4f1d6310 1023Wildcards and redirection are handled as usual in the shell."
a247bf21
KH
1024 (cond
1025 ((eq system-type 'vax-vms)
1026 (apply 'start-process name buffer args))
b59f6d7a
RS
1027 ;; We used to use `exec' to replace the shell with the command,
1028 ;; but that failed to handle (...) and semicolon, etc.
a247bf21
KH
1029 (t
1030 (start-process name buffer shell-file-name shell-command-switch
b59f6d7a 1031 (mapconcat 'identity args " ")))))
a7ed4c2a 1032\f
a7f284ec
RS
1033(defmacro with-current-buffer (buffer &rest body)
1034 "Execute the forms in BODY with BUFFER as the current buffer.
a2fdb55c
EN
1035The value returned is the value of the last form in BODY.
1036See also `with-temp-buffer'."
ce87039d
SM
1037 (cons 'save-current-buffer
1038 (cons (list 'set-buffer buffer)
1039 body)))
a7f284ec 1040
e5bb8a8c
SM
1041(defmacro with-temp-file (file &rest body)
1042 "Create a new buffer, evaluate BODY there, and write the buffer to FILE.
1043The value returned is the value of the last form in BODY.
a2fdb55c 1044See also `with-temp-buffer'."
a7ed4c2a 1045 (let ((temp-file (make-symbol "temp-file"))
a2fdb55c
EN
1046 (temp-buffer (make-symbol "temp-buffer")))
1047 `(let ((,temp-file ,file)
1048 (,temp-buffer
1049 (get-buffer-create (generate-new-buffer-name " *temp file*"))))
1050 (unwind-protect
1051 (prog1
1052 (with-current-buffer ,temp-buffer
e5bb8a8c 1053 ,@body)
a2fdb55c
EN
1054 (with-current-buffer ,temp-buffer
1055 (widen)
1056 (write-region (point-min) (point-max) ,temp-file nil 0)))
1057 (and (buffer-name ,temp-buffer)
1058 (kill-buffer ,temp-buffer))))))
1059
e5bb8a8c 1060(defmacro with-temp-message (message &rest body)
a600effe 1061 "Display MESSAGE temporarily if non-nil while BODY is evaluated.
e5bb8a8c
SM
1062The original message is restored to the echo area after BODY has finished.
1063The value returned is the value of the last form in BODY.
a600effe
SM
1064MESSAGE is written to the message log buffer if `message-log-max' is non-nil.
1065If MESSAGE is nil, the echo area and message log buffer are unchanged.
1066Use a MESSAGE of \"\" to temporarily clear the echo area."
110201c8
SM
1067 (let ((current-message (make-symbol "current-message"))
1068 (temp-message (make-symbol "with-temp-message")))
1069 `(let ((,temp-message ,message)
1070 (,current-message))
e5bb8a8c
SM
1071 (unwind-protect
1072 (progn
110201c8
SM
1073 (when ,temp-message
1074 (setq ,current-message (current-message))
aadf7ff3 1075 (message "%s" ,temp-message))
e5bb8a8c 1076 ,@body)
75545902
KH
1077 (and ,temp-message ,current-message
1078 (message "%s" ,current-message))))))
e5bb8a8c
SM
1079
1080(defmacro with-temp-buffer (&rest body)
1081 "Create a temporary buffer, and evaluate BODY there like `progn'.
a2fdb55c
EN
1082See also `with-temp-file' and `with-output-to-string'."
1083 (let ((temp-buffer (make-symbol "temp-buffer")))
1084 `(let ((,temp-buffer
1085 (get-buffer-create (generate-new-buffer-name " *temp*"))))
1086 (unwind-protect
1087 (with-current-buffer ,temp-buffer
e5bb8a8c 1088 ,@body)
a2fdb55c
EN
1089 (and (buffer-name ,temp-buffer)
1090 (kill-buffer ,temp-buffer))))))
1091
5db7925d
RS
1092(defmacro with-output-to-string (&rest body)
1093 "Execute BODY, return the text it sent to `standard-output', as a string."
a2fdb55c
EN
1094 `(let ((standard-output
1095 (get-buffer-create (generate-new-buffer-name " *string-output*"))))
5db7925d
RS
1096 (let ((standard-output standard-output))
1097 ,@body)
a2fdb55c
EN
1098 (with-current-buffer standard-output
1099 (prog1
1100 (buffer-string)
1101 (kill-buffer nil)))))
2ec9c94e
RS
1102
1103(defmacro combine-after-change-calls (&rest body)
1104 "Execute BODY, but don't call the after-change functions till the end.
1105If BODY makes changes in the buffer, they are recorded
1106and the functions on `after-change-functions' are called several times
1107when BODY is finished.
31aa282e 1108The return value is the value of the last form in BODY.
2ec9c94e
RS
1109
1110If `before-change-functions' is non-nil, then calls to the after-change
1111functions can't be deferred, so in that case this macro has no effect.
1112
1113Do not alter `after-change-functions' or `before-change-functions'
1114in BODY."
1115 `(unwind-protect
1116 (let ((combine-after-change-calls t))
1117 . ,body)
1118 (combine-after-change-execute)))
1119
c834b52c
SM
1120
1121(defvar combine-run-hooks t
1122 "List of hooks delayed. Or t if we're not delaying hooks.")
1123
1124(defmacro combine-run-hooks (&rest body)
1125 "Execute BODY, but delay any `run-hooks' until the end."
1126 (let ((saved-combine-run-hooks (make-symbol "saved-combine-run-hooks"))
1127 (saved-run-hooks (make-symbol "saved-run-hooks")))
1128 `(let ((,saved-combine-run-hooks combine-run-hooks)
1129 (,saved-run-hooks (symbol-function 'run-hooks)))
1130 (unwind-protect
1131 (progn
1132 ;; If we're not delaying hooks yet, setup the delaying mode
1133 (unless (listp combine-run-hooks)
1134 (setq combine-run-hooks nil)
1135 (fset 'run-hooks
1136 ,(lambda (&rest hooks)
1137 (setq combine-run-hooks
1138 (append combine-run-hooks hooks)))))
1139 ,@body)
1140 ;; If we were not already delaying, then it's now time to set things
1141 ;; back to normal and to execute the delayed hooks.
1142 (unless (listp ,saved-combine-run-hooks)
1143 (setq ,saved-combine-run-hooks combine-run-hooks)
1144 (fset 'run-hooks ,saved-run-hooks)
1145 (setq combine-run-hooks t)
1146 (apply 'run-hooks ,saved-combine-run-hooks))))))
1147
1148
7e8539cc
RS
1149(defmacro with-syntax-table (table &rest body)
1150 "Evaluate BODY with syntax table of current buffer set to a copy of TABLE.
1151The syntax table of the current buffer is saved, BODY is evaluated, and the
1152saved table is restored, even in case of an abnormal exit.
1153Value is what BODY returns."
b3f07093
RS
1154 (let ((old-table (make-symbol "table"))
1155 (old-buffer (make-symbol "buffer")))
7e8539cc
RS
1156 `(let ((,old-table (syntax-table))
1157 (,old-buffer (current-buffer)))
1158 (unwind-protect
1159 (progn
1160 (set-syntax-table (copy-syntax-table ,table))
1161 ,@body)
1162 (save-current-buffer
1163 (set-buffer ,old-buffer)
1164 (set-syntax-table ,old-table))))))
a2fdb55c 1165\f
c7ca41e6
RS
1166(defvar save-match-data-internal)
1167
1168;; We use save-match-data-internal as the local variable because
1169;; that works ok in practice (people should not use that variable elsewhere).
1170;; We used to use an uninterned symbol; the compiler handles that properly
1171;; now, but it generates slower code.
9a5336ae
JB
1172(defmacro save-match-data (&rest body)
1173 "Execute the BODY forms, restoring the global value of the match data."
64ed733a
PE
1174 ;; It is better not to use backquote here,
1175 ;; because that makes a bootstrapping problem
1176 ;; if you need to recompile all the Lisp files using interpreted code.
1177 (list 'let
1178 '((save-match-data-internal (match-data)))
1179 (list 'unwind-protect
1180 (cons 'progn body)
1181 '(set-match-data save-match-data-internal))))
993713ce 1182
cd323f89 1183(defun match-string (num &optional string)
993713ce
SM
1184 "Return string of text matched by last search.
1185NUM specifies which parenthesized expression in the last regexp.
1186 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
1187Zero means the entire text matched by the whole regexp or whole string.
1188STRING should be given if the last search was by `string-match' on STRING."
cd323f89
SM
1189 (if (match-beginning num)
1190 (if string
1191 (substring string (match-beginning num) (match-end num))
1192 (buffer-substring (match-beginning num) (match-end num)))))
58f950b4 1193
bb760c71
RS
1194(defun match-string-no-properties (num &optional string)
1195 "Return string of text matched by last search, without text properties.
1196NUM specifies which parenthesized expression in the last regexp.
1197 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
1198Zero means the entire text matched by the whole regexp or whole string.
1199STRING should be given if the last search was by `string-match' on STRING."
1200 (if (match-beginning num)
1201 (if string
1202 (let ((result
1203 (substring string (match-beginning num) (match-end num))))
1204 (set-text-properties 0 (length result) nil result)
1205 result)
1206 (buffer-substring-no-properties (match-beginning num)
1207 (match-end num)))))
1208
edce3654
RS
1209(defun split-string (string &optional separators)
1210 "Splits STRING into substrings where there are matches for SEPARATORS.
1211Each match for SEPARATORS is a splitting point.
1212The substrings between the splitting points are made into a list
1213which is returned.
b222b786
RS
1214If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\".
1215
1216If there is match for SEPARATORS at the beginning of STRING, we do not
1217include a null substring for that. Likewise, if there is a match
b021ef18
DL
1218at the end of STRING, we don't include a null substring for that.
1219
1220Modifies the match data; use `save-match-data' if necessary."
edce3654
RS
1221 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
1222 (start 0)
b222b786 1223 notfirst
edce3654 1224 (list nil))
b222b786
RS
1225 (while (and (string-match rexp string
1226 (if (and notfirst
1227 (= start (match-beginning 0))
1228 (< start (length string)))
1229 (1+ start) start))
1230 (< (match-beginning 0) (length string)))
1231 (setq notfirst t)
7eb47123 1232 (or (eq (match-beginning 0) 0)
b222b786
RS
1233 (and (eq (match-beginning 0) (match-end 0))
1234 (eq (match-beginning 0) start))
edce3654
RS
1235 (setq list
1236 (cons (substring string start (match-beginning 0))
1237 list)))
1238 (setq start (match-end 0)))
1239 (or (eq start (length string))
1240 (setq list
1241 (cons (substring string start)
1242 list)))
1243 (nreverse list)))
1ccaea52
AI
1244
1245(defun subst-char-in-string (fromchar tochar string &optional inplace)
1246 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1247Unless optional argument INPLACE is non-nil, return a new string."
e6e71807
SM
1248 (let ((i (length string))
1249 (newstr (if inplace string (copy-sequence string))))
1250 (while (> i 0)
1251 (setq i (1- i))
1252 (if (eq (aref newstr i) fromchar)
1253 (aset newstr i tochar)))
1254 newstr))
b021ef18 1255
1697159c
DL
1256(defun replace-regexp-in-string (regexp rep string &optional
1257 fixedcase literal subexp start)
b021ef18
DL
1258 "Replace all matches for REGEXP with REP in STRING.
1259
1260Return a new string containing the replacements.
1261
1262Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
1263arguments with the same names of function `replace-match'. If START
1264is non-nil, start replacements at that index in STRING.
1265
1266REP is either a string used as the NEWTEXT arg of `replace-match' or a
1267function. If it is a function it is applied to each match to generate
1268the replacement passed to `replace-match'; the match-data at this
1269point are such that match 0 is the function's argument.
1270
1697159c
DL
1271To replace only the first match (if any), make REGEXP match up to \\'
1272and replace a sub-expression, e.g.
1273 (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1)
1274 => \" bar foo\"
1275"
b021ef18
DL
1276
1277 ;; To avoid excessive consing from multiple matches in long strings,
1278 ;; don't just call `replace-match' continually. Walk down the
1279 ;; string looking for matches of REGEXP and building up a (reversed)
1280 ;; list MATCHES. This comprises segments of STRING which weren't
1281 ;; matched interspersed with replacements for segments that were.
1282 ;; [For a `large' number of replacments it's more efficient to
1283 ;; operate in a temporary buffer; we can't tell from the function's
1284 ;; args whether to choose the buffer-based implementation, though it
1285 ;; might be reasonable to do so for long enough STRING.]
1286 (let ((l (length string))
1287 (start (or start 0))
1288 matches str mb me)
1289 (save-match-data
1290 (while (and (< start l) (string-match regexp string start))
1291 (setq mb (match-beginning 0)
1292 me (match-end 0))
a9853251
SM
1293 ;; If we matched the empty string, make sure we advance by one char
1294 (when (= me mb) (setq me (min l (1+ mb))))
1295 ;; Generate a replacement for the matched substring.
1296 ;; Operate only on the substring to minimize string consing.
1297 ;; Set up match data for the substring for replacement;
1298 ;; presumably this is likely to be faster than munging the
1299 ;; match data directly in Lisp.
1300 (string-match regexp (setq str (substring string mb me)))
1301 (setq matches
1302 (cons (replace-match (if (stringp rep)
1303 rep
1304 (funcall rep (match-string 0 str)))
1305 fixedcase literal str subexp)
1306 (cons (substring string start mb) ; unmatched prefix
1307 matches)))
1308 (setq start me))
b021ef18
DL
1309 ;; Reconstruct a string from the pieces.
1310 (setq matches (cons (substring string start l) matches)) ; leftover
1311 (apply #'concat (nreverse matches)))))
a7ed4c2a 1312\f
8af7df60
RS
1313(defun shell-quote-argument (argument)
1314 "Quote an argument for passing as argument to an inferior shell."
c1c74b43 1315 (if (eq system-type 'ms-dos)
8ee75d03
EZ
1316 ;; Quote using double quotes, but escape any existing quotes in
1317 ;; the argument with backslashes.
1318 (let ((result "")
1319 (start 0)
1320 end)
1321 (if (or (null (string-match "[^\"]" argument))
1322 (< (match-end 0) (length argument)))
1323 (while (string-match "[\"]" argument start)
1324 (setq end (match-beginning 0)
1325 result (concat result (substring argument start end)
1326 "\\" (substring argument end (1+ end)))
1327 start (1+ end))))
1328 (concat "\"" result (substring argument start) "\""))
c1c74b43
RS
1329 (if (eq system-type 'windows-nt)
1330 (concat "\"" argument "\"")
e1b65a6b
RS
1331 (if (equal argument "")
1332 "''"
1333 ;; Quote everything except POSIX filename characters.
1334 ;; This should be safe enough even for really weird shells.
1335 (let ((result "") (start 0) end)
1336 (while (string-match "[^-0-9a-zA-Z_./]" argument start)
1337 (setq end (match-beginning 0)
1338 result (concat result (substring argument start end)
1339 "\\" (substring argument end (1+ end)))
1340 start (1+ end)))
1341 (concat result (substring argument start)))))))
8af7df60 1342
297d863b 1343(defun make-syntax-table (&optional oldtable)
984f718a 1344 "Return a new syntax table.
888eb98e
RS
1345If OLDTABLE is non-nil, copy OLDTABLE.
1346Otherwise, create a syntax table which inherits
1347all letters and control characters from the standard syntax table;
1348other characters are copied from the standard syntax table."
297d863b
KH
1349 (if oldtable
1350 (copy-syntax-table oldtable)
1351 (let ((table (copy-syntax-table))
1352 i)
1353 (setq i 0)
1354 (while (<= i 31)
a6889c57 1355 (aset table i nil)
297d863b
KH
1356 (setq i (1+ i)))
1357 (setq i ?A)
1358 (while (<= i ?Z)
a6889c57 1359 (aset table i nil)
297d863b
KH
1360 (setq i (1+ i)))
1361 (setq i ?a)
1362 (while (<= i ?z)
a6889c57 1363 (aset table i nil)
297d863b
KH
1364 (setq i (1+ i)))
1365 (setq i 128)
1366 (while (<= i 255)
a6889c57 1367 (aset table i nil)
297d863b
KH
1368 (setq i (1+ i)))
1369 table)))
31aa282e
KH
1370
1371(defun add-to-invisibility-spec (arg)
1372 "Add elements to `buffer-invisibility-spec'.
1373See documentation for `buffer-invisibility-spec' for the kind of elements
1374that can be added."
1375 (cond
1376 ((or (null buffer-invisibility-spec) (eq buffer-invisibility-spec t))
1377 (setq buffer-invisibility-spec (list arg)))
1378 (t
11d431ad
KH
1379 (setq buffer-invisibility-spec
1380 (cons arg buffer-invisibility-spec)))))
31aa282e
KH
1381
1382(defun remove-from-invisibility-spec (arg)
1383 "Remove elements from `buffer-invisibility-spec'."
e93b8cbb 1384 (if (consp buffer-invisibility-spec)
071a2a71 1385 (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec))))
baed0109
RS
1386\f
1387(defun global-set-key (key command)
1388 "Give KEY a global binding as COMMAND.
7bba1895
KH
1389COMMAND is the command definition to use; usually it is
1390a symbol naming an interactively-callable function.
1391KEY is a key sequence; noninteractively, it is a string or vector
1392of characters or event types, and non-ASCII characters with codes
1393above 127 (such as ISO Latin-1) can be included if you use a vector.
1394
1395Note that if KEY has a local binding in the current buffer,
1396that local binding will continue to shadow any global binding
1397that you make with this function."
baed0109
RS
1398 (interactive "KSet key globally: \nCSet key %s to command: ")
1399 (or (vectorp key) (stringp key)
1400 (signal 'wrong-type-argument (list 'arrayp key)))
ff663bbe 1401 (define-key (current-global-map) key command))
baed0109
RS
1402
1403(defun local-set-key (key command)
1404 "Give KEY a local binding as COMMAND.
7bba1895
KH
1405COMMAND is the command definition to use; usually it is
1406a symbol naming an interactively-callable function.
1407KEY is a key sequence; noninteractively, it is a string or vector
1408of characters or event types, and non-ASCII characters with codes
1409above 127 (such as ISO Latin-1) can be included if you use a vector.
1410
baed0109
RS
1411The binding goes in the current buffer's local map,
1412which in most cases is shared with all other buffers in the same major mode."
1413 (interactive "KSet key locally: \nCSet key %s locally to command: ")
1414 (let ((map (current-local-map)))
1415 (or map
1416 (use-local-map (setq map (make-sparse-keymap))))
1417 (or (vectorp key) (stringp key)
1418 (signal 'wrong-type-argument (list 'arrayp key)))
ff663bbe 1419 (define-key map key command)))
984f718a 1420
baed0109
RS
1421(defun global-unset-key (key)
1422 "Remove global binding of KEY.
1423KEY is a string representing a sequence of keystrokes."
1424 (interactive "kUnset key globally: ")
1425 (global-set-key key nil))
1426
db2474b8 1427(defun local-unset-key (key)
baed0109
RS
1428 "Remove local binding of KEY.
1429KEY is a string representing a sequence of keystrokes."
1430 (interactive "kUnset key locally: ")
1431 (if (current-local-map)
db2474b8 1432 (local-set-key key nil))
baed0109
RS
1433 nil)
1434\f
4809d0dd
KH
1435;; We put this here instead of in frame.el so that it's defined even on
1436;; systems where frame.el isn't loaded.
1437(defun frame-configuration-p (object)
1438 "Return non-nil if OBJECT seems to be a frame configuration.
1439Any list whose car is `frame-configuration' is assumed to be a frame
1440configuration."
1441 (and (consp object)
1442 (eq (car object) 'frame-configuration)))
1443
a9a44ed1 1444(defun functionp (object)
77a5664f 1445 "Non-nil if OBJECT is a type of object that can be called as a function."
c029995c 1446 (or (subrp object) (byte-code-function-p object)
a9a44ed1
RS
1447 (eq (car-safe object) 'lambda)
1448 (and (symbolp object) (fboundp object))))
1449
9a5336ae
JB
1450;; now in fns.c
1451;(defun nth (n list)
1452; "Returns the Nth element of LIST.
1453;N counts from zero. If LIST is not that long, nil is returned."
1454; (car (nthcdr n list)))
1455;
1456;(defun copy-alist (alist)
1457; "Return a copy of ALIST.
1458;This is a new alist which represents the same mapping
1459;from objects to objects, but does not share the alist structure with ALIST.
1460;The objects mapped (cars and cdrs of elements of the alist)
1461;are shared, however."
1462; (setq alist (copy-sequence alist))
1463; (let ((tail alist))
1464; (while tail
1465; (if (consp (car tail))
1466; (setcar tail (cons (car (car tail)) (cdr (car tail)))))
1467; (setq tail (cdr tail))))
1468; alist)
630cc463 1469
d3a61a11 1470(defun assq-delete-all (key alist)
a62d6695
DL
1471 "Delete from ALIST all elements whose car is KEY.
1472Return the modified alist."
a62d6695
DL
1473 (let ((tail alist))
1474 (while tail
1475 (if (eq (car (car tail)) key)
1476 (setq alist (delq (car tail) alist)))
1477 (setq tail (cdr tail)))
1478 alist))
1479
cdd9f643
RS
1480(defun make-temp-file (prefix &optional dir-flag)
1481 "Create a temporary file.
1482The returned file name (created by appending some random characters at the end
1483of PREFIX, and expanding against `temporary-file-directory' if necessary,
1484is guaranteed to point to a newly created empty file.
1485You can then use `write-region' to write new data into the file.
1486
1487If DIR-FLAG is non-nil, create a new empty directory instead of a file."
1488 (let (file)
1489 (while (condition-case ()
1490 (progn
1491 (setq file
1492 (make-temp-name
1493 (expand-file-name prefix temporary-file-directory)))
1494 (if dir-flag
1495 (make-directory file)
1496 (write-region "" nil file nil 'silent nil 'excl))
1497 nil)
1498 (file-already-exists t))
1499 ;; the file was somehow created by someone else between
1500 ;; `make-temp-name' and `write-region', let's try again.
1501 nil)
1502 file))
1503
d7d47268 1504\f
c94f4677 1505(defun add-minor-mode (toggle name &optional keymap after toggle-fun)
d7d47268 1506 "Register a new minor mode.
c94f4677 1507
0b2cf11f
SM
1508This is an XEmacs-compatibility function. Use `define-minor-mode' instead.
1509
c94f4677
GM
1510TOGGLE is a symbol which is the name of a buffer-local variable that
1511is toggled on or off to say whether the minor mode is active or not.
1512
1513NAME specifies what will appear in the mode line when the minor mode
1514is active. NAME should be either a string starting with a space, or a
1515symbol whose value is such a string.
1516
1517Optional KEYMAP is the keymap for the minor mode that will be added
1518to `minor-mode-map-alist'.
1519
1520Optional AFTER specifies that TOGGLE should be added after AFTER
1521in `minor-mode-alist'.
1522
0b2cf11f
SM
1523Optional TOGGLE-FUN is an interactive function to toggle the mode.
1524It defaults to (and should by convention be) TOGGLE.
1525
1526If TOGGLE has a non-nil `:included' property, an entry for the mode is
1527included in the mode-line minor mode menu.
1528If TOGGLE has a `:menu-tag', that is used for the menu item's label."
1529 (unless toggle-fun (setq toggle-fun toggle))
1530 ;; Add the toggle to the minor-modes menu if requested.
1531 (when (get toggle :included)
1532 (define-key mode-line-mode-menu
1533 (vector toggle)
1534 (list 'menu-item
1535 (or (get toggle :menu-tag)
1536 (if (stringp name) name (symbol-name toggle)))
1537 toggle-fun
1538 :button (cons :toggle toggle))))
1539 ;; Add the name to the minor-mode-alist.
c94f4677 1540 (when name
0b2cf11f
SM
1541 (let ((existing (assq toggle minor-mode-alist)))
1542 (when (and (stringp name) (not (get-text-property 0 'local-map name)))
d6c22d46
DL
1543 (setq name
1544 (apply 'propertize name
1545 'local-map (make-mode-line-mouse2-map toggle-fun)
1546 (unless (get-text-property 0 'help-echo name)
1547 (list 'help-echo
0b2cf11f
SM
1548 (format "mouse-2: turn off %S" toggle))))))
1549 (if existing
1550 (setcdr existing (list name))
1551 (let ((tail minor-mode-alist) found)
1552 (while (and tail (not found))
1553 (if (eq after (caar tail))
1554 (setq found tail)
1555 (setq tail (cdr tail))))
1556 (if found
1557 (let ((rest (cdr found)))
1558 (setcdr found nil)
1559 (nconc found (list (list toggle name)) rest))
1560 (setq minor-mode-alist (cons (list toggle name)
1561 minor-mode-alist)))))))
1562 ;; Add the map to the minor-mode-map-alist.
c94f4677
GM
1563 (when keymap
1564 (let ((existing (assq toggle minor-mode-map-alist)))
0b2cf11f
SM
1565 (if existing
1566 (setcdr existing keymap)
1567 (let ((tail minor-mode-map-alist) found)
1568 (while (and tail (not found))
1569 (if (eq after (caar tail))
1570 (setq found tail)
1571 (setq tail (cdr tail))))
1572 (if found
1573 (let ((rest (cdr found)))
1574 (setcdr found nil)
1575 (nconc found (list (cons toggle keymap)) rest))
1576 (setq minor-mode-map-alist (cons (cons toggle keymap)
1577 minor-mode-map-alist))))))))
d7d47268 1578
ff77cf40
DL
1579;; XEmacs compatibility/convenience.
1580(if (fboundp 'play-sound)
1581 (defun play-sound-file (file &optional volume device)
1582 "Play sound stored in FILE.
1583VOLUME and DEVICE correspond to the keywords of the sound
1584specification for `play-sound'."
1585 (interactive "fPlay sound file: ")
1586 (let ((sound (list :file file)))
1587 (if volume
1588 (plist-put sound :volume volume))
1589 (if device
1590 (plist-put sound :device device))
1591 (push 'sound sound)
1592 (play-sound sound))))
d7d47268 1593
630cc463 1594;;; subr.el ends here