1 ;;; subr.el --- basic lisp subroutines for Emacs
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 1999 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
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
9 ;; the Free Software Foundation; either version 2, or (at your option)
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.
17 ;; You should have received a copy of the GNU General Public License
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.
23 (defvar custom-declare-variable-list nil
24 "Record `defcustom' calls made before `custom.el' is loaded to handle them.
25 Each element of this list holds the arguments to one call to `defcustom'.")
27 ;; Use this, rather than defcustom, in subr.el and other files loaded
29 (defun custom-declare-variable-early (&rest arguments
)
30 (setq custom-declare-variable-list
31 (cons arguments custom-declare-variable-list
)))
33 ;;;; Lisp language features.
35 (defmacro lambda
(&rest cdr
)
36 "Return a lambda expression.
37 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
38 self-quoting; the result of evaluating the lambda expression is the
39 expression itself. The lambda expression may then be treated as a
40 function, i.e., stored as the function value of a symbol, passed to
41 funcall or mapcar, etc.
43 ARGS should take the same form as an argument list for a `defun'.
44 DOCSTRING 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.
47 INTERACTIVE should be a call to the function `interactive', which see.
48 It may also be omitted.
49 BODY 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
)))
54 (defmacro push
(newelt listname
)
55 "Add NEWELT to the list stored in the symbol LISTNAME.
56 This is equivalent to (setq LISTNAME (cons NEWELT LISTNAME)).
57 LISTNAME must be a symbol."
59 (list 'cons newelt listname
)))
61 (defmacro pop
(listname)
62 "Return the first element of LISTNAME's value, and remove it from the list.
63 LISTNAME must be a symbol whose value is a list.
64 If the value is nil, `pop' returns nil but does not actually
66 (list 'prog1
(list 'car listname
)
67 (list 'setq listname
(list 'cdr listname
))))
69 (defmacro when
(cond &rest body
)
70 "(when COND BODY...): if COND yields non-nil, do BODY, else return nil."
71 (list 'if cond
(cons 'progn body
)))
73 (defmacro unless
(cond &rest body
)
74 "(unless COND BODY...): if COND yields nil, do BODY, else return nil."
75 (cons 'if
(cons cond
(cons nil body
))))
77 (defmacro dolist
(spec &rest body
)
78 "(dolist (VAR LIST [RESULT]) BODY...): loop over a list.
79 Evaluate BODY with VAR bound to each car from LIST, in turn.
80 Then evaluate RESULT to get return value, default nil."
81 (let ((temp (make-symbol "--dolist-temp--")))
82 (list 'let
(list (list temp
(nth 1 spec
)) (car spec
))
84 (list 'setq
(car spec
) (list 'car temp
))
87 (list (list 'setq temp
(list 'cdr temp
))))))
90 (cons (list 'setq
(car spec
) nil
) (cdr (cdr spec
))))))))
92 (defmacro dotimes
(spec &rest body
)
93 "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times.
94 Evaluate BODY with VAR bound to successive integers running from 0,
95 inclusive, to COUNT, exclusive. Then evaluate RESULT to get
96 the return value (nil if RESULT is omitted)."
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
)
101 (append body
(list (list 'setq
(car spec
)
102 (list '1+ (car spec
)))))))
104 (car (cdr (cdr spec
)))
108 "Return the car of the car of X."
112 "Return the car of the cdr of X."
116 "Return the cdr of the car of X."
120 "Return the cdr of the cdr of X."
123 (defun last (x &optional n
)
124 "Return the last link of the list X. Its car is the last element.
125 If X is nil, return nil.
126 If N is non-nil, return the Nth-to-last link of X.
127 If N is bigger than the length of X, return X."
131 (setq m
(1+ m
) p
(cdr p
)))
133 (if (< n m
) (nthcdr (- m n
) x
) x
)))
138 (defun assoc-default (key alist
&optional test default
)
139 "Find object KEY in a pseudo-alist ALIST.
140 ALIST is a list of conses or objects. Each element (or the element's car,
141 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY).
142 If that is non-nil, the element matches;
143 then `assoc-default' returns the element's cdr, if it is a cons,
144 or DEFAULT if the element is not a cons.
146 If no element matches, the value is nil.
147 If TEST is omitted or nil, `equal' is used."
148 (let (found (tail alist
) value
)
149 (while (and tail
(not found
))
150 (let ((elt (car tail
)))
151 (when (funcall (or test
'equal
) (if (consp elt
) (car elt
) elt
) key
)
152 (setq found t value
(if (consp elt
) (cdr elt
) default
))))
153 (setq tail
(cdr tail
)))
156 (defun assoc-ignore-case (key alist
)
157 "Like `assoc', but ignores differences in case and text representation.
158 KEY must be a string. Upper-case and lower-case letters are treated as equal.
159 Unibyte strings are converted to multibyte for comparison."
161 (while (and alist
(not element
))
162 (if (eq t
(compare-strings key
0 nil
(car (car alist
)) 0 nil t
))
163 (setq element
(car alist
)))
164 (setq alist
(cdr alist
)))
167 (defun assoc-ignore-representation (key alist
)
168 "Like `assoc', but ignores differences in text representation.
169 KEY must be a string.
170 Unibyte strings are converted to multibyte for comparison."
172 (while (and alist
(not element
))
173 (if (eq t
(compare-strings key
0 nil
(car (car alist
)) 0 nil
))
174 (setq element
(car alist
)))
175 (setq alist
(cdr alist
)))
184 ;Prevent the \{...} documentation construct
185 ;from mentioning keys that run this command.
186 (put 'undefined
'suppress-keymap t
)
188 (defun suppress-keymap (map &optional nodigits
)
189 "Make MAP override all normally self-inserting keys to be undefined.
190 Normally, as an exception, digits and minus-sign are set to make prefix args,
191 but optional second arg NODIGITS non-nil treats them like other chars."
192 (substitute-key-definition 'self-insert-command
'undefined map global-map
)
195 (define-key map
"-" 'negative-argument
)
196 ;; Make plain numbers do numeric args.
199 (define-key map
(char-to-string loop
) 'digit-argument
)
200 (setq loop
(1+ loop
))))))
203 ;(defun copy-keymap (keymap)
204 ; "Return a copy of KEYMAP"
205 ; (while (not (keymapp keymap))
206 ; (setq keymap (signal 'wrong-type-argument (list 'keymapp keymap))))
207 ; (if (vectorp keymap)
208 ; (copy-sequence keymap)
209 ; (copy-alist keymap)))
211 (defvar key-substitution-in-progress nil
212 "Used internally by substitute-key-definition.")
214 (defun substitute-key-definition (olddef newdef keymap
&optional oldmap prefix
)
215 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
216 In other words, OLDDEF is replaced with NEWDEF where ever it appears.
217 If optional fourth argument OLDMAP is specified, we redefine
218 in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
219 (or prefix
(setq prefix
""))
220 (let* ((scan (or oldmap keymap
))
222 (prefix1 (vconcat prefix vec1
))
223 (key-substitution-in-progress
224 (cons scan key-substitution-in-progress
)))
225 ;; Scan OLDMAP, finding each char or event-symbol that
226 ;; has any definition, and act on it with hack-key.
228 (if (consp (car scan
))
229 (let ((char (car (car scan
)))
230 (defn (cdr (car scan
))))
231 ;; The inside of this let duplicates exactly
232 ;; the inside of the following let that handles array elements.
234 (aset prefix1
(length prefix
) char
)
235 (let (inner-def skipped
)
236 ;; Skip past menu-prompt.
237 (while (stringp (car-safe defn
))
238 (setq skipped
(cons (car defn
) skipped
))
239 (setq defn
(cdr defn
)))
240 ;; Skip past cached key-equivalence data for menu items.
241 (and (consp defn
) (consp (car defn
))
242 (setq defn
(cdr defn
)))
243 (setq inner-def defn
)
244 ;; Look past a symbol that names a keymap.
245 (while (and (symbolp inner-def
)
247 (setq inner-def
(symbol-function inner-def
)))
248 (if (or (eq defn olddef
)
249 ;; Compare with equal if definition is a key sequence.
250 ;; That is useful for operating on function-key-map.
251 (and (or (stringp defn
) (vectorp defn
))
252 (equal defn olddef
)))
253 (define-key keymap prefix1
(nconc (nreverse skipped
) newdef
))
254 (if (and (keymapp defn
)
255 ;; Avoid recursively scanning
256 ;; where KEYMAP does not have a submap.
257 (let ((elt (lookup-key keymap prefix1
)))
260 ;; Avoid recursively rescanning keymap being scanned.
262 key-substitution-in-progress
)))
263 ;; If this one isn't being scanned already,
265 (substitute-key-definition olddef newdef keymap
268 (if (vectorp (car scan
))
269 (let* ((array (car scan
))
273 (let ((char i
) (defn (aref array i
)))
274 ;; The inside of this let duplicates exactly
275 ;; the inside of the previous let.
277 (aset prefix1
(length prefix
) char
)
278 (let (inner-def skipped
)
279 ;; Skip past menu-prompt.
280 (while (stringp (car-safe defn
))
281 (setq skipped
(cons (car defn
) skipped
))
282 (setq defn
(cdr defn
)))
283 (and (consp defn
) (consp (car defn
))
284 (setq defn
(cdr defn
)))
285 (setq inner-def defn
)
286 (while (and (symbolp inner-def
)
288 (setq inner-def
(symbol-function inner-def
)))
289 (if (or (eq defn olddef
)
290 (and (or (stringp defn
) (vectorp defn
))
291 (equal defn olddef
)))
292 (define-key keymap prefix1
293 (nconc (nreverse skipped
) newdef
))
294 (if (and (keymapp defn
)
295 (let ((elt (lookup-key keymap prefix1
)))
299 key-substitution-in-progress
)))
300 (substitute-key-definition olddef newdef keymap
304 (if (char-table-p (car scan
))
306 (function (lambda (char defn
)
308 ;; The inside of this let duplicates exactly
309 ;; the inside of the previous let,
310 ;; except that it uses set-char-table-range
311 ;; instead of define-key.
313 (aset prefix1
(length prefix
) char
)
314 (let (inner-def skipped
)
315 ;; Skip past menu-prompt.
316 (while (stringp (car-safe defn
))
317 (setq skipped
(cons (car defn
) skipped
))
318 (setq defn
(cdr defn
)))
319 (and (consp defn
) (consp (car defn
))
320 (setq defn
(cdr defn
)))
321 (setq inner-def defn
)
322 (while (and (symbolp inner-def
)
324 (setq inner-def
(symbol-function inner-def
)))
325 (if (or (eq defn olddef
)
326 (and (or (stringp defn
) (vectorp defn
))
327 (equal defn olddef
)))
328 (define-key keymap prefix1
329 (nconc (nreverse skipped
) newdef
))
330 (if (and (keymapp defn
)
331 (let ((elt (lookup-key keymap prefix1
)))
335 key-substitution-in-progress
)))
336 (substitute-key-definition olddef newdef keymap
340 (setq scan
(cdr scan
)))))
342 (defun define-key-after (keymap key definition after
)
343 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
344 This is like `define-key' except that the binding for KEY is placed
345 just after the binding for the event AFTER, instead of at the beginning
346 of the map. Note that AFTER must be an event type (like KEY), NOT a command
349 If AFTER is t, the new binding goes at the end of the keymap.
351 KEY must contain just one event type--that is to say, it must be
352 a string or vector of length 1.
354 The order of bindings in a keymap matters when it is used as a menu."
357 (signal 'wrong-type-argument
(list 'keymapp keymap
)))
358 (if (> (length key
) 1)
359 (error "multi-event key specified in `define-key-after'"))
360 (let ((tail keymap
) done inserted
361 (first (aref key
0)))
362 (while (and (not done
) tail
)
363 ;; Delete any earlier bindings for the same key.
364 (if (eq (car-safe (car (cdr tail
))) first
)
365 (setcdr tail
(cdr (cdr tail
))))
366 ;; When we reach AFTER's binding, insert the new binding after.
367 ;; If we reach an inherited keymap, insert just before that.
368 ;; If we reach the end of this keymap, insert at the end.
369 (if (or (and (eq (car-safe (car tail
)) after
)
371 (eq (car (cdr tail
)) 'keymap
)
374 ;; Stop the scan only if we find a parent keymap.
375 ;; Keep going past the inserted element
376 ;; so we can delete any duplications that come later.
377 (if (eq (car (cdr tail
)) 'keymap
)
379 ;; Don't insert more than once.
381 (setcdr tail
(cons (cons (aref key
0) definition
) (cdr tail
))))
383 (setq tail
(cdr tail
)))))
386 "Convert KEYS to the internal Emacs key representation.
387 KEYS should be a string constant in the format used for
388 saving keyboard macros (see `insert-kbd-macro')."
389 (read-kbd-macro keys
))
391 (put 'keyboard-translate-table
'char-table-extra-slots
0)
393 (defun keyboard-translate (from to
)
394 "Translate character FROM to TO at a low level.
395 This function creates a `keyboard-translate-table' if necessary
396 and then modifies one entry in it."
397 (or (char-table-p keyboard-translate-table
)
398 (setq keyboard-translate-table
399 (make-char-table 'keyboard-translate-table nil
)))
400 (aset keyboard-translate-table from to
))
403 ;;;; The global keymap tree.
405 ;;; global-map, esc-map, and ctl-x-map have their values set up in
406 ;;; keymap.c; we just give them docstrings here.
408 (defvar global-map nil
409 "Default global keymap mapping Emacs keyboard input into commands.
410 The value is a keymap which is usually (but not necessarily) Emacs's
414 "Default keymap for ESC (meta) commands.
415 The normal global definition of the character ESC indirects to this keymap.")
417 (defvar ctl-x-map nil
418 "Default keymap for C-x commands.
419 The normal global definition of the character C-x indirects to this keymap.")
421 (defvar ctl-x-4-map
(make-sparse-keymap)
422 "Keymap for subcommands of C-x 4")
423 (defalias 'ctl-x-4-prefix ctl-x-4-map
)
424 (define-key ctl-x-map
"4" 'ctl-x-4-prefix
)
426 (defvar ctl-x-5-map
(make-sparse-keymap)
427 "Keymap for frame commands.")
428 (defalias 'ctl-x-5-prefix ctl-x-5-map
)
429 (define-key ctl-x-map
"5" 'ctl-x-5-prefix
)
432 ;;;; Event manipulation functions.
434 ;; The call to `read' is to ensure that the value is computed at load time
435 ;; and not compiled into the .elc file. The value is negative on most
436 ;; machines, but not on all!
437 (defconst listify-key-sequence-1
(logior 128 (read "?\\M-\\^@")))
439 (defun listify-key-sequence (key)
440 "Convert a key sequence to a list of events."
443 (mapcar (function (lambda (c)
445 (logxor c listify-key-sequence-1
)
449 (defsubst eventp
(obj)
450 "True if the argument is an event object."
453 (get obj
'event-symbol-elements
))
456 (get (car obj
) 'event-symbol-elements
))))
458 (defun event-modifiers (event)
459 "Returns a list of symbols representing the modifier keys in event EVENT.
460 The elements of the list may include `meta', `control',
461 `shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
465 (setq type
(car type
)))
467 (cdr (get type
'event-symbol-elements
))
469 (or (zerop (logand type ?\M-\^
@))
470 (setq list
(cons 'meta list
)))
471 (or (and (zerop (logand type ?\C-\^
@))
472 (>= (logand type
127) 32))
473 (setq list
(cons 'control list
)))
474 (or (and (zerop (logand type ?\S-\^
@))
475 (= (logand type
255) (downcase (logand type
255))))
476 (setq list
(cons 'shift list
)))
477 (or (zerop (logand type ?\H-\^
@))
478 (setq list
(cons 'hyper list
)))
479 (or (zerop (logand type ?\s-\^
@))
480 (setq list
(cons 'super list
)))
481 (or (zerop (logand type ?\A-\^
@))
482 (setq list
(cons 'alt list
)))
485 (defun event-basic-type (event)
486 "Returns the basic type of the given event (all modifiers removed).
487 The value is an ASCII printing character (not upper case) or a symbol."
489 (setq event
(car event
)))
491 (car (get event
'event-symbol-elements
))
492 (let ((base (logand event
(1- (lsh 1 18)))))
493 (downcase (if (< base
32) (logior base
64) base
)))))
495 (defsubst mouse-movement-p
(object)
496 "Return non-nil if OBJECT is a mouse movement event."
498 (eq (car object
) 'mouse-movement
)))
500 (defsubst event-start
(event)
501 "Return the starting position of EVENT.
502 If EVENT is a mouse press or a mouse click, this returns the location
504 If EVENT is a drag, this returns the drag's starting position.
505 The return value is of the form
506 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
507 The `posn-' functions access elements of such lists."
510 (defsubst event-end
(event)
511 "Return the ending location of EVENT. EVENT should be a click or drag event.
512 If EVENT is a click event, this function is the same as `event-start'.
513 The return value is of the form
514 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
515 The `posn-' functions access elements of such lists."
516 (nth (if (consp (nth 2 event
)) 2 1) event
))
518 (defsubst event-click-count
(event)
519 "Return the multi-click count of EVENT, a click or drag event.
520 The return value is a positive integer."
521 (if (integerp (nth 2 event
)) (nth 2 event
) 1))
523 (defsubst posn-window
(position)
524 "Return the window in POSITION.
525 POSITION should be a list of the form
526 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
527 as returned by the `event-start' and `event-end' functions."
530 (defsubst posn-point
(position)
531 "Return the buffer location in POSITION.
532 POSITION should be a list of the form
533 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
534 as returned by the `event-start' and `event-end' functions."
535 (if (consp (nth 1 position
))
536 (car (nth 1 position
))
539 (defsubst posn-x-y
(position)
540 "Return the x and y coordinates in POSITION.
541 POSITION should be a list of the form
542 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
543 as returned by the `event-start' and `event-end' functions."
546 (defun posn-col-row (position)
547 "Return the column and row in POSITION, measured in characters.
548 POSITION should be a list of the form
549 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
550 as returned by the `event-start' and `event-end' functions.
551 For a scroll-bar event, the result column is 0, and the row
552 corresponds to the vertical position of the click in the scroll bar."
553 (let ((pair (nth 2 position
))
554 (window (posn-window position
)))
555 (if (eq (if (consp (nth 1 position
))
556 (car (nth 1 position
))
558 'vertical-scroll-bar
)
559 (cons 0 (scroll-bar-scale pair
(1- (window-height window
))))
560 (if (eq (if (consp (nth 1 position
))
561 (car (nth 1 position
))
563 'horizontal-scroll-bar
)
564 (cons (scroll-bar-scale pair
(window-width window
)) 0)
565 (let* ((frame (if (framep window
) window
(window-frame window
)))
566 (x (/ (car pair
) (frame-char-width frame
)))
567 (y (/ (cdr pair
) (frame-char-height frame
))))
570 (defsubst posn-timestamp
(position)
571 "Return the timestamp of POSITION.
572 POSITION should be a list of the form
573 (WINDOW BUFFER-POSITION (X . Y) TIMESTAMP)
574 as returned by the `event-start' and `event-end' functions."
578 ;;;; Obsolescent names for functions.
580 (defalias 'dot
'point
)
581 (defalias 'dot-marker
'point-marker
)
582 (defalias 'dot-min
'point-min
)
583 (defalias 'dot-max
'point-max
)
584 (defalias 'window-dot
'window-point
)
585 (defalias 'set-window-dot
'set-window-point
)
586 (defalias 'read-input
'read-string
)
587 (defalias 'send-string
'process-send-string
)
588 (defalias 'send-region
'process-send-region
)
589 (defalias 'show-buffer
'set-window-buffer
)
590 (defalias 'buffer-flush-undo
'buffer-disable-undo
)
591 (defalias 'eval-current-buffer
'eval-buffer
)
592 (defalias 'compiled-function-p
'byte-code-function-p
)
593 (defalias 'define-function
'defalias
)
595 (defalias 'sref
'aref
)
596 (make-obsolete 'sref
'aref
)
597 (make-obsolete 'char-bytes
"Now this function always returns 1")
599 ;; Some programs still use this as a function.
601 "Obsolete function returning the value of the `baud-rate' variable.
602 Please convert your programs to use the variable `baud-rate' directly."
605 (defalias 'focus-frame
'ignore
)
606 (defalias 'unfocus-frame
'ignore
)
608 ;;;; Alternate names for functions - these are not being phased out.
610 (defalias 'string
= 'string-equal
)
611 (defalias 'string
< 'string-lessp
)
612 (defalias 'move-marker
'set-marker
)
613 (defalias 'not
'null
)
614 (defalias 'rplaca
'setcar
)
615 (defalias 'rplacd
'setcdr
)
616 (defalias 'beep
'ding
) ;preserve lingual purity
617 (defalias 'indent-to-column
'indent-to
)
618 (defalias 'backward-delete-char
'delete-backward-char
)
619 (defalias 'search-forward-regexp
(symbol-function 're-search-forward
))
620 (defalias 'search-backward-regexp
(symbol-function 're-search-backward
))
621 (defalias 'int-to-string
'number-to-string
)
622 (defalias 'store-match-data
'set-match-data
)
623 (defalias 'point-at-eol
'line-end-position
)
624 (defalias 'point-at-bol
'line-beginning-position
)
626 ;;; Should this be an obsolete name? If you decide it should, you get
627 ;;; to go through all the sources and change them.
628 (defalias 'string-to-int
'string-to-number
)
630 ;;;; Hook manipulation functions.
632 (defun make-local-hook (hook)
633 "Make the hook HOOK local to the current buffer.
634 The return value is HOOK.
636 When a hook is local, its local and global values
637 work in concert: running the hook actually runs all the hook
638 functions listed in *either* the local value *or* the global value
639 of the hook variable.
641 This function works by making `t' a member of the buffer-local value,
642 which acts as a flag to run the hook functions in the default value as
643 well. This works for all normal hooks, but does not work for most
644 non-normal hooks yet. We will be changing the callers of non-normal
645 hooks so that they can handle localness; this has to be done one by
648 This function does nothing if HOOK is already local in the current
651 Do not use `make-local-variable' to make a hook variable buffer-local."
652 (if (local-variable-p hook
)
654 (or (boundp hook
) (set hook nil
))
655 (make-local-variable hook
)
659 (defun add-hook (hook function
&optional append local
)
660 "Add to the value of HOOK the function FUNCTION.
661 FUNCTION is not added if already present.
662 FUNCTION is added (if necessary) at the beginning of the hook list
663 unless the optional argument APPEND is non-nil, in which case
664 FUNCTION is added at the end.
666 The optional fourth argument, LOCAL, if non-nil, says to modify
667 the hook's buffer-local value rather than its default value.
668 This makes no difference if the hook is not buffer-local.
669 To make a hook variable buffer-local, always use
670 `make-local-hook', not `make-local-variable'.
672 HOOK should be a symbol, and FUNCTION may be any valid function. If
673 HOOK is void, it is first set to nil. If HOOK's value is a single
674 function, it is changed to a list of functions."
675 (or (boundp hook
) (set hook nil
))
676 (or (default-boundp hook
) (set-default hook nil
))
677 ;; If the hook value is a single function, turn it into a list.
678 (let ((old (symbol-value hook
)))
679 (if (or (not (listp old
)) (eq (car old
) 'lambda
))
680 (set hook
(list old
))))
682 ;; Detect the case where make-local-variable was used on a hook
683 ;; and do what we used to do.
684 (and (local-variable-if-set-p hook
)
685 (not (memq t
(symbol-value hook
)))))
686 ;; Alter the local value only.
687 (or (if (or (consp function
) (byte-code-function-p function
))
688 (member function
(symbol-value hook
))
689 (memq function
(symbol-value hook
)))
692 (append (symbol-value hook
) (list function
))
693 (cons function
(symbol-value hook
)))))
694 ;; Alter the global value (which is also the only value,
695 ;; if the hook doesn't have a local value).
696 (or (if (or (consp function
) (byte-code-function-p function
))
697 (member function
(default-value hook
))
698 (memq function
(default-value hook
)))
701 (append (default-value hook
) (list function
))
702 (cons function
(default-value hook
)))))))
704 (defun remove-hook (hook function
&optional local
)
705 "Remove from the value of HOOK the function FUNCTION.
706 HOOK should be a symbol, and FUNCTION may be any valid function. If
707 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
708 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
710 The optional third argument, LOCAL, if non-nil, says to modify
711 the hook's buffer-local value rather than its default value.
712 This makes no difference if the hook is not buffer-local.
713 To make a hook variable buffer-local, always use
714 `make-local-hook', not `make-local-variable'."
715 (if (or (not (boundp hook
)) ;unbound symbol, or
716 (not (default-boundp hook
))
717 (null (symbol-value hook
)) ;value is nil, or
718 (null function
)) ;function is nil, then
721 ;; Detect the case where make-local-variable was used on a hook
722 ;; and do what we used to do.
723 (and (local-variable-p hook
)
724 (consp (symbol-value hook
))
725 (not (memq t
(symbol-value hook
)))))
726 (let ((hook-value (symbol-value hook
)))
727 (if (consp hook-value
)
728 (if (member function hook-value
)
729 (setq hook-value
(delete function
(copy-sequence hook-value
))))
730 (if (equal hook-value function
)
731 (setq hook-value nil
)))
732 (set hook hook-value
))
733 (let ((hook-value (default-value hook
)))
734 (if (and (consp hook-value
) (not (functionp hook-value
)))
735 (if (member function hook-value
)
736 (setq hook-value
(delete function
(copy-sequence hook-value
))))
737 (if (equal hook-value function
)
738 (setq hook-value nil
)))
739 (set-default hook hook-value
)))))
741 (defun add-to-list (list-var element
)
742 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
743 The test for presence of ELEMENT is done with `equal'.
744 If ELEMENT is added, it is added at the beginning of the list.
746 If you want to use `add-to-list' on a variable that is not defined
747 until a certain package is loaded, you should put the call to `add-to-list'
748 into a hook function that will be run only after loading the package.
749 `eval-after-load' provides one way to do this. In some cases
750 other hooks, such as major mode hooks, can do the job."
751 (if (member element
(symbol-value list-var
))
752 (symbol-value list-var
)
753 (set list-var
(cons element
(symbol-value list-var
)))))
755 ;;;; Specifying things to do after certain files are loaded.
757 (defun eval-after-load (file form
)
758 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
759 This makes or adds to an entry on `after-load-alist'.
760 If FILE is already loaded, evaluate FORM right now.
761 It does nothing if FORM is already on the list for FILE.
762 FILE should be the name of a library, with no directory name."
763 ;; Make sure there is an element for FILE.
764 (or (assoc file after-load-alist
)
765 (setq after-load-alist
(cons (list file
) after-load-alist
)))
766 ;; Add FORM to the element if it isn't there.
767 (let ((elt (assoc file after-load-alist
)))
768 (or (member form
(cdr elt
))
770 (nconc elt
(list form
))
771 ;; If the file has been loaded already, run FORM right away.
772 (and (assoc file load-history
)
776 (defun eval-next-after-load (file)
777 "Read the following input sexp, and run it whenever FILE is loaded.
778 This makes or adds to an entry on `after-load-alist'.
779 FILE should be the name of a library, with no directory name."
780 (eval-after-load file
(read)))
783 ;;;; Input and display facilities.
785 (defvar read-quoted-char-radix
8
786 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
787 Legitimate radix values are 8, 10 and 16.")
789 (custom-declare-variable-early
790 'read-quoted-char-radix
8
791 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
792 Legitimate radix values are 8, 10 and 16."
793 :type
'(choice (const 8) (const 10) (const 16))
794 :group
'editing-basics
)
796 (defun read-quoted-char (&optional prompt
)
797 "Like `read-char', but do not allow quitting.
798 Also, if the first character read is an octal digit,
799 we read any number of octal digits and return the
800 specified character code. Any nondigit terminates the sequence.
801 If the terminator is RET, it is discarded;
802 any other terminator is used itself as input.
804 The optional argument PROMPT specifies a string to use to prompt the user.
805 The variable `read-quoted-char-radix' controls which radix to use
807 (let ((message-log-max nil
) done
(first t
) (code 0) char
)
809 (let ((inhibit-quit first
)
810 ;; Don't let C-h get the help message--only help function keys.
813 "Type the special character you want to use,
814 or the octal character code.
815 RET terminates the character code and is discarded;
816 any other non-digit terminates the character code and is then used as input."))
817 (setq char
(read-event (and prompt
(format "%s-" prompt
)) t
))
818 (if inhibit-quit
(setq quit-flag nil
)))
819 ;; Translate TAB key into control-I ASCII character, and so on.
821 (let ((translated (lookup-key function-key-map
(vector char
))))
822 (if (arrayp translated
)
823 (setq char
(aref translated
0)))))
825 ((not (integerp char
))
826 (setq unread-command-events
(list char
)
828 ((/= (logand char ?\M-\^
@) 0)
829 ;; Turn a meta-character into a character with the 0200 bit set.
830 (setq code
(logior (logand char
(lognot ?\M-\^
@)) 128)
832 ((and (<= ?
0 char
) (< char
(+ ?
0 (min 10 read-quoted-char-radix
))))
833 (setq code
(+ (* code read-quoted-char-radix
) (- char ?
0)))
834 (and prompt
(setq prompt
(message "%s %c" prompt char
))))
835 ((and (<= ?a
(downcase char
))
836 (< (downcase char
) (+ ?a -
10 (min 26 read-quoted-char-radix
))))
837 (setq code
(+ (* code read-quoted-char-radix
)
838 (+ 10 (- (downcase char
) ?a
))))
839 (and prompt
(setq prompt
(message "%s %c" prompt char
))))
840 ((and (not first
) (eq char ?\C-m
))
843 (setq unread-command-events
(list char
)
850 (defun read-passwd (prompt &optional confirm default
)
851 "Read a password, prompting with PROMPT. Echo `.' for each character typed.
852 End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.
853 Optional argument CONFIRM, if non-nil, then read it twice to make sure.
854 Optional DEFAULT is a default password to use instead of empty input."
858 (let ((first (read-passwd prompt nil default
))
859 (second (read-passwd "Confirm password: " nil default
)))
860 (if (equal first second
)
862 (message "Password not repeated accurately; please start over")
865 (clear-this-command-keys)
869 (cursor-in-echo-area t
))
870 (while (progn (message "%s%s"
872 (make-string (length pass
) ?.
))
873 (setq c
(read-char nil t
))
874 (and (/= c ?
\r) (/= c ?
\n) (/= c ?\e
)))
877 (if (and (/= c ?
\b) (/= c ?
\177))
878 (setq pass
(concat pass
(char-to-string c
)))
879 (if (> (length pass
) 0)
880 (setq pass
(substring pass
0 -
1))))))
882 (or pass default
""))))
884 (defun force-mode-line-update (&optional all
)
885 "Force the mode-line of the current buffer to be redisplayed.
886 With optional non-nil ALL, force redisplay of all mode-lines."
887 (if all
(save-excursion (set-buffer (other-buffer))))
888 (set-buffer-modified-p (buffer-modified-p)))
890 (defun momentary-string-display (string pos
&optional exit-char message
)
891 "Momentarily display STRING in the buffer at POS.
892 Display remains until next character is typed.
893 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
894 otherwise it is then available as input (as a command if nothing else).
895 Display MESSAGE (optional fourth arg) in the echo area.
896 If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
897 (or exit-char
(setq exit-char ?\
))
898 (let ((inhibit-read-only t
)
899 ;; Don't modify the undo list at all.
901 (modified (buffer-modified-p))
902 (name buffer-file-name
)
908 ;; defeat file locking... don't try this at home, kids!
909 (setq buffer-file-name nil
)
910 (insert-before-markers string
)
911 (setq insert-end
(point))
912 ;; If the message end is off screen, recenter now.
913 (if (< (window-end nil t
) insert-end
)
914 (recenter (/ (window-height) 2)))
915 ;; If that pushed message start off the screen,
916 ;; scroll to start it at the top of the screen.
917 (move-to-window-line 0)
922 (message (or message
"Type %s to continue editing.")
923 (single-key-description exit-char
))
924 (let ((char (read-event)))
925 (or (eq char exit-char
)
926 (setq unread-command-events
(list char
)))))
929 (delete-region pos insert-end
)))
930 (setq buffer-file-name name
)
931 (set-buffer-modified-p modified
))))
936 ;; A number of major modes set this locally.
937 ;; Give it a global value to avoid compiler warnings.
938 (defvar font-lock-defaults nil
)
940 (defvar suspend-hook nil
941 "Normal hook run by `suspend-emacs', before suspending.")
943 (defvar suspend-resume-hook nil
944 "Normal hook run by `suspend-emacs', after Emacs is continued.")
946 ;; Avoid compiler warnings about this variable,
947 ;; which has a special meaning on certain system types.
948 (defvar buffer-file-type nil
949 "Non-nil if the visited file is a binary file.
950 This variable is meaningful on MS-DOG and Windows NT.
951 On those systems, it is automatically local in every buffer.
952 On other systems, this variable is normally always nil.")
954 ;; This should probably be written in C (i.e., without using `walk-windows').
955 (defun get-buffer-window-list (buffer &optional minibuf frame
)
956 "Return windows currently displaying BUFFER, or nil if none.
957 See `walk-windows' for the meaning of MINIBUF and FRAME."
958 (let ((buffer (if (bufferp buffer
) buffer
(get-buffer buffer
))) windows
)
959 (walk-windows (function (lambda (window)
960 (if (eq (window-buffer window
) buffer
)
961 (setq windows
(cons window windows
)))))
965 (defun ignore (&rest ignore
)
966 "Do nothing and return nil.
967 This function accepts any number of arguments, but ignores them."
971 (defun error (&rest args
)
972 "Signal an error, making error message by passing all args to `format'.
973 In Emacs, the convention is that error messages start with a capital
974 letter but *do not* end with a period. Please follow this convention
975 for the sake of consistency."
977 (signal 'error
(list (apply 'format args
)))))
979 (defalias 'user-original-login-name
'user-login-name
)
981 (defun start-process-shell-command (name buffer
&rest args
)
982 "Start a program in a subprocess. Return the process object for it.
983 Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
984 NAME is name for process. It is modified if necessary to make it unique.
985 BUFFER is the buffer or (buffer-name) to associate with the process.
986 Process output goes at end of that buffer, unless you specify
987 an output stream or filter function to handle the output.
988 BUFFER may be also nil, meaning that this process is not associated
990 Third arg is command name, the name of a shell command.
991 Remaining arguments are the arguments for the command.
992 Wildcards and redirection are handled as usual in the shell."
994 ((eq system-type
'vax-vms
)
995 (apply 'start-process name buffer args
))
996 ;; We used to use `exec' to replace the shell with the command,
997 ;; but that failed to handle (...) and semicolon, etc.
999 (start-process name buffer shell-file-name shell-command-switch
1000 (mapconcat 'identity args
" ")))))
1002 (defmacro with-current-buffer
(buffer &rest body
)
1003 "Execute the forms in BODY with BUFFER as the current buffer.
1004 The value returned is the value of the last form in BODY.
1005 See also `with-temp-buffer'."
1006 (cons 'save-current-buffer
1007 (cons (list 'set-buffer buffer
)
1010 (defmacro with-temp-file
(file &rest body
)
1011 "Create a new buffer, evaluate BODY there, and write the buffer to FILE.
1012 The value returned is the value of the last form in BODY.
1013 See also `with-temp-buffer'."
1014 (let ((temp-file (make-symbol "temp-file"))
1015 (temp-buffer (make-symbol "temp-buffer")))
1016 `(let ((,temp-file
,file
)
1018 (get-buffer-create (generate-new-buffer-name " *temp file*"))))
1021 (with-current-buffer ,temp-buffer
1023 (with-current-buffer ,temp-buffer
1025 (write-region (point-min) (point-max) ,temp-file nil
0)))
1026 (and (buffer-name ,temp-buffer
)
1027 (kill-buffer ,temp-buffer
))))))
1029 (defmacro with-temp-message
(message &rest body
)
1030 "Display MESSAGE temporarily if non-nil while BODY is evaluated.
1031 The original message is restored to the echo area after BODY has finished.
1032 The value returned is the value of the last form in BODY.
1033 MESSAGE is written to the message log buffer if `message-log-max' is non-nil.
1034 If MESSAGE is nil, the echo area and message log buffer are unchanged.
1035 Use a MESSAGE of \"\" to temporarily clear the echo area."
1036 (let ((current-message (make-symbol "current-message"))
1037 (temp-message (make-symbol "with-temp-message")))
1038 `(let ((,temp-message
,message
)
1043 (setq ,current-message
(current-message))
1044 (message "%s" ,temp-message
))
1046 (and ,temp-message
,current-message
1047 (message "%s" ,current-message
))))))
1049 (defmacro with-temp-buffer
(&rest body
)
1050 "Create a temporary buffer, and evaluate BODY there like `progn'.
1051 See also `with-temp-file' and `with-output-to-string'."
1052 (let ((temp-buffer (make-symbol "temp-buffer")))
1053 `(let ((,temp-buffer
1054 (get-buffer-create (generate-new-buffer-name " *temp*"))))
1056 (with-current-buffer ,temp-buffer
1058 (and (buffer-name ,temp-buffer
)
1059 (kill-buffer ,temp-buffer
))))))
1061 (defmacro with-output-to-string
(&rest body
)
1062 "Execute BODY, return the text it sent to `standard-output', as a string."
1063 `(let ((standard-output
1064 (get-buffer-create (generate-new-buffer-name " *string-output*"))))
1065 (let ((standard-output standard-output
))
1067 (with-current-buffer standard-output
1070 (kill-buffer nil
)))))
1072 (defmacro combine-after-change-calls
(&rest body
)
1073 "Execute BODY, but don't call the after-change functions till the end.
1074 If BODY makes changes in the buffer, they are recorded
1075 and the functions on `after-change-functions' are called several times
1076 when BODY is finished.
1077 The return value is the value of the last form in BODY.
1079 If `before-change-functions' is non-nil, then calls to the after-change
1080 functions can't be deferred, so in that case this macro has no effect.
1082 Do not alter `after-change-functions' or `before-change-functions'
1085 (let ((combine-after-change-calls t
))
1087 (combine-after-change-execute)))
1089 (defmacro with-syntax-table
(table &rest body
)
1090 "Evaluate BODY with syntax table of current buffer set to a copy of TABLE.
1091 The syntax table of the current buffer is saved, BODY is evaluated, and the
1092 saved table is restored, even in case of an abnormal exit.
1093 Value is what BODY returns."
1094 (let ((old-table (make-symbol "table"))
1095 (old-buffer (make-symbol "buffer")))
1096 `(let ((,old-table
(syntax-table))
1097 (,old-buffer
(current-buffer)))
1100 (set-syntax-table (copy-syntax-table ,table
))
1102 (save-current-buffer
1103 (set-buffer ,old-buffer
)
1104 (set-syntax-table ,old-table
))))))
1106 (defvar save-match-data-internal
)
1108 ;; We use save-match-data-internal as the local variable because
1109 ;; that works ok in practice (people should not use that variable elsewhere).
1110 ;; We used to use an uninterned symbol; the compiler handles that properly
1111 ;; now, but it generates slower code.
1112 (defmacro save-match-data
(&rest body
)
1113 "Execute the BODY forms, restoring the global value of the match data."
1114 ;; It is better not to use backquote here,
1115 ;; because that makes a bootstrapping problem
1116 ;; if you need to recompile all the Lisp files using interpreted code.
1118 '((save-match-data-internal (match-data)))
1119 (list 'unwind-protect
1121 '(set-match-data save-match-data-internal
))))
1123 (defun match-string (num &optional string
)
1124 "Return string of text matched by last search.
1125 NUM specifies which parenthesized expression in the last regexp.
1126 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
1127 Zero means the entire text matched by the whole regexp or whole string.
1128 STRING should be given if the last search was by `string-match' on STRING."
1129 (if (match-beginning num
)
1131 (substring string
(match-beginning num
) (match-end num
))
1132 (buffer-substring (match-beginning num
) (match-end num
)))))
1134 (defun match-string-no-properties (num &optional string
)
1135 "Return string of text matched by last search, without text properties.
1136 NUM specifies which parenthesized expression in the last regexp.
1137 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
1138 Zero means the entire text matched by the whole regexp or whole string.
1139 STRING should be given if the last search was by `string-match' on STRING."
1140 (if (match-beginning num
)
1143 (substring string
(match-beginning num
) (match-end num
))))
1144 (set-text-properties 0 (length result
) nil result
)
1146 (buffer-substring-no-properties (match-beginning num
)
1149 (defun split-string (string &optional separators
)
1150 "Splits STRING into substrings where there are matches for SEPARATORS.
1151 Each match for SEPARATORS is a splitting point.
1152 The substrings between the splitting points are made into a list
1154 If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\".
1156 If there is match for SEPARATORS at the beginning of STRING, we do not
1157 include a null substring for that. Likewise, if there is a match
1158 at the end of STRING, we don't include a null substring for that."
1159 (let ((rexp (or separators
"[ \f\t\n\r\v]+"))
1163 (while (and (string-match rexp string
1165 (= start
(match-beginning 0))
1166 (< start
(length string
)))
1168 (< (match-beginning 0) (length string
)))
1170 (or (eq (match-beginning 0) 0)
1171 (and (eq (match-beginning 0) (match-end 0))
1172 (eq (match-beginning 0) start
))
1174 (cons (substring string start
(match-beginning 0))
1176 (setq start
(match-end 0)))
1177 (or (eq start
(length string
))
1179 (cons (substring string start
)
1183 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
1184 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
1185 Unless optional argument INPLACE is non-nil, return a new string."
1186 (let ((i (length string
))
1187 (newstr (if inplace string
(copy-sequence string
))))
1190 (if (eq (aref newstr i
) fromchar
)
1191 (aset newstr i tochar
)))
1194 (defun shell-quote-argument (argument)
1195 "Quote an argument for passing as argument to an inferior shell."
1196 (if (eq system-type
'ms-dos
)
1197 ;; Quote using double quotes, but escape any existing quotes in
1198 ;; the argument with backslashes.
1202 (if (or (null (string-match "[^\"]" argument
))
1203 (< (match-end 0) (length argument
)))
1204 (while (string-match "[\"]" argument start
)
1205 (setq end
(match-beginning 0)
1206 result
(concat result
(substring argument start end
)
1207 "\\" (substring argument end
(1+ end
)))
1209 (concat "\"" result
(substring argument start
) "\""))
1210 (if (eq system-type
'windows-nt
)
1211 (concat "\"" argument
"\"")
1212 (if (equal argument
"")
1214 ;; Quote everything except POSIX filename characters.
1215 ;; This should be safe enough even for really weird shells.
1216 (let ((result "") (start 0) end
)
1217 (while (string-match "[^-0-9a-zA-Z_./]" argument start
)
1218 (setq end
(match-beginning 0)
1219 result
(concat result
(substring argument start end
)
1220 "\\" (substring argument end
(1+ end
)))
1222 (concat result
(substring argument start
)))))))
1224 (defun make-syntax-table (&optional oldtable
)
1225 "Return a new syntax table.
1226 If OLDTABLE is non-nil, copy OLDTABLE.
1227 Otherwise, create a syntax table which inherits
1228 all letters and control characters from the standard syntax table;
1229 other characters are copied from the standard syntax table."
1231 (copy-syntax-table oldtable
)
1232 (let ((table (copy-syntax-table))
1252 (defun add-to-invisibility-spec (arg)
1253 "Add elements to `buffer-invisibility-spec'.
1254 See documentation for `buffer-invisibility-spec' for the kind of elements
1257 ((or (null buffer-invisibility-spec
) (eq buffer-invisibility-spec t
))
1258 (setq buffer-invisibility-spec
(list arg
)))
1260 (setq buffer-invisibility-spec
1261 (cons arg buffer-invisibility-spec
)))))
1263 (defun remove-from-invisibility-spec (arg)
1264 "Remove elements from `buffer-invisibility-spec'."
1265 (if (consp buffer-invisibility-spec
)
1266 (setq buffer-invisibility-spec
(delete arg buffer-invisibility-spec
))))
1268 (defun global-set-key (key command
)
1269 "Give KEY a global binding as COMMAND.
1270 COMMAND is the command definition to use; usually it is
1271 a symbol naming an interactively-callable function.
1272 KEY is a key sequence; noninteractively, it is a string or vector
1273 of characters or event types, and non-ASCII characters with codes
1274 above 127 (such as ISO Latin-1) can be included if you use a vector.
1276 Note that if KEY has a local binding in the current buffer,
1277 that local binding will continue to shadow any global binding
1278 that you make with this function."
1279 (interactive "KSet key globally: \nCSet key %s to command: ")
1280 (or (vectorp key
) (stringp key
)
1281 (signal 'wrong-type-argument
(list 'arrayp key
)))
1282 (define-key (current-global-map) key command
))
1284 (defun local-set-key (key command
)
1285 "Give KEY a local binding as COMMAND.
1286 COMMAND is the command definition to use; usually it is
1287 a symbol naming an interactively-callable function.
1288 KEY is a key sequence; noninteractively, it is a string or vector
1289 of characters or event types, and non-ASCII characters with codes
1290 above 127 (such as ISO Latin-1) can be included if you use a vector.
1292 The binding goes in the current buffer's local map,
1293 which in most cases is shared with all other buffers in the same major mode."
1294 (interactive "KSet key locally: \nCSet key %s locally to command: ")
1295 (let ((map (current-local-map)))
1297 (use-local-map (setq map
(make-sparse-keymap))))
1298 (or (vectorp key
) (stringp key
)
1299 (signal 'wrong-type-argument
(list 'arrayp key
)))
1300 (define-key map key command
)))
1302 (defun global-unset-key (key)
1303 "Remove global binding of KEY.
1304 KEY is a string representing a sequence of keystrokes."
1305 (interactive "kUnset key globally: ")
1306 (global-set-key key nil
))
1308 (defun local-unset-key (key)
1309 "Remove local binding of KEY.
1310 KEY is a string representing a sequence of keystrokes."
1311 (interactive "kUnset key locally: ")
1312 (if (current-local-map)
1313 (local-set-key key nil
))
1316 ;; We put this here instead of in frame.el so that it's defined even on
1317 ;; systems where frame.el isn't loaded.
1318 (defun frame-configuration-p (object)
1319 "Return non-nil if OBJECT seems to be a frame configuration.
1320 Any list whose car is `frame-configuration' is assumed to be a frame
1323 (eq (car object
) 'frame-configuration
)))
1325 (defun functionp (object)
1326 "Non-nil if OBJECT is a type of object that can be called as a function."
1327 (or (subrp object
) (byte-code-function-p object
)
1328 (eq (car-safe object
) 'lambda
)
1329 (and (symbolp object
) (fboundp object
))))
1332 ;(defun nth (n list)
1333 ; "Returns the Nth element of LIST.
1334 ;N counts from zero. If LIST is not that long, nil is returned."
1335 ; (car (nthcdr n list)))
1337 ;(defun copy-alist (alist)
1338 ; "Return a copy of ALIST.
1339 ;This is a new alist which represents the same mapping
1340 ;from objects to objects, but does not share the alist structure with ALIST.
1341 ;The objects mapped (cars and cdrs of elements of the alist)
1342 ;are shared, however."
1343 ; (setq alist (copy-sequence alist))
1344 ; (let ((tail alist))
1346 ; (if (consp (car tail))
1347 ; (setcar tail (cons (car (car tail)) (cdr (car tail)))))
1348 ; (setq tail (cdr tail))))
1351 (defun assoc-delete-all (key alist
)
1352 "Delete from ALIST all elements whose car is KEY.
1353 Return the modified alist."
1354 (setq alist
(copy-sequence alist
))
1357 (if (eq (car (car tail
)) key
)
1358 (setq alist
(delq (car tail
) alist
)))
1359 (setq tail
(cdr tail
)))
1362 (defun make-temp-file (prefix &optional dir-flag
)
1363 "Create a temporary file.
1364 The returned file name (created by appending some random characters at the end
1365 of PREFIX, and expanding against `temporary-file-directory' if necessary,
1366 is guaranteed to point to a newly created empty file.
1367 You can then use `write-region' to write new data into the file.
1369 If DIR-FLAG is non-nil, create a new empty directory instead of a file."
1371 (while (condition-case ()
1375 (expand-file-name prefix temporary-file-directory
)))
1377 (make-directory file
)
1378 (write-region "" nil file nil
'silent nil
'excl
))
1380 (file-already-exists t
))
1381 ;; the file was somehow created by someone else between
1382 ;; `make-temp-name' and `write-region', let's try again.
1386 ;;; subr.el ends here