(intervals.o): Depend on puresize.h.
[bpt/emacs.git] / lisp / subr.el
CommitLineData
c88ab9ce 1;;; subr.el --- basic lisp subroutines for Emacs
630cc463 2
492878e4 3;;; Copyright (C) 1985, 1986, 1992 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
18;; along with GNU Emacs; see the file COPYING. If not, write to
19;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
630cc463 21;;; Code:
be9b65ac 22
9a5336ae
JB
23\f
24;;;; Lisp language features.
25
26(defmacro lambda (&rest cdr)
27 "Return a lambda expression.
28A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
29self-quoting; the result of evaluating the lambda expression is the
30expression itself. The lambda expression may then be treated as a
31function, i. e. stored as the function value of a symbol, passed to
32funcall or mapcar, etcetera.
33ARGS should take the same form as an argument list for a `defun'.
34DOCSTRING should be a string, as described for `defun'. It may be omitted.
35INTERACTIVE should be a call to the function `interactive', which see.
36It may also be omitted.
37BODY should be a list of lisp expressions."
38 ;; Note that this definition should not use backquotes; subr.el should not
39 ;; depend on backquote.el.
40 (list 'function (cons 'lambda cdr)))
41
42;;(defmacro defun-inline (name args &rest body)
43;; "Create an \"inline defun\" (actually a macro).
44;;Use just like `defun'."
45;; (nconc (list 'defmacro name '(&rest args))
46;; (if (stringp (car body))
47;; (prog1 (list (car body))
48;; (setq body (or (cdr body) body))))
49;; (list (list 'cons (list 'quote
50;; (cons 'lambda (cons args body)))
51;; 'args))))
52
53\f
54;;;; Window tree functions.
55
492878e4 56(defun one-window-p (&optional nomini)
be9b65ac
DL
57 "Returns non-nil if there is only one window.
58Optional arg NOMINI non-nil means don't count the minibuffer
59even if it is active."
492878e4
JB
60 (let ((base-window (selected-window)))
61 (if (and nomini (eq base-window (minibuffer-window)))
62 (setq base-window (next-window base-window)))
63 (eq base-window
64 (next-window base-window (if nomini 'arg)))))
be9b65ac 65
0cc89026 66(defun walk-windows (proc &optional minibuf all-frames)
be9b65ac
DL
67 "Cycle through all visible windows, calling PROC for each one.
68PROC is called with a window as argument.
69Optional second arg MINIBUF t means count the minibuffer window
70even if not active. If MINIBUF is neither t nor nil it means
71not to count the minibuffer even if it is active.
f1f2d09a
RS
72
73Optional third arg ALL-FRAMES, if t, means include all frames.
74ALL-FRAMES nil or omitted means cycle within the selected frame,
75but include the minibuffer window (if MINIBUF says so) that that
76frame uses, even if it is on another frame.
77If ALL-FRAMES is neither nil nor t, stick strictly to the selected frame."
be9b65ac
DL
78 (let* ((walk-windows-start (selected-window))
79 (walk-windows-current walk-windows-start))
80 (while (progn
81 (setq walk-windows-current
0cc89026 82 (next-window walk-windows-current minibuf all-frames))
be9b65ac
DL
83 (funcall proc walk-windows-current)
84 (not (eq walk-windows-current walk-windows-start))))))
85
79e0df73
RS
86(defun minibuffer-window-active-p (window)
87 "Return t if WINDOW (a minibuffer window) is now active."
88 ;; nil nil means include WINDOW's frame
89 ;; and other frames using WINDOW as minibuffer,
90 ;; and include minibuffer if active.
91 (let ((prev (previous-window window nil nil)))
92 ;; If PREV equals WINDOW, WINDOW must be on a minibuffer-only frame
93 ;; and it's not currently being used. So return nil.
94 (and (not (eq window prev))
95 (let ((should-be-same (next-window prev nil nil)))
96 ;; If next-window doesn't reverse previous-window,
97 ;; WINDOW must be outside the cycle specified by nil nil.
98 (eq should-be-same window)))))
9a5336ae
JB
99\f
100;;;; Keymap support.
be9b65ac
DL
101
102(defun undefined ()
103 (interactive)
104 (ding))
105
106;Prevent the \{...} documentation construct
107;from mentioning keys that run this command.
108(put 'undefined 'suppress-keymap t)
109
110(defun suppress-keymap (map &optional nodigits)
111 "Make MAP override all normally self-inserting keys to be undefined.
112Normally, as an exception, digits and minus-sign are set to make prefix args,
113but optional second arg NODIGITS non-nil treats them like other chars."
80e7b471 114 (substitute-key-definition 'self-insert-command 'undefined map global-map)
be9b65ac
DL
115 (or nodigits
116 (let (loop)
117 (define-key map "-" 'negative-argument)
118 ;; Make plain numbers do numeric args.
119 (setq loop ?0)
120 (while (<= loop ?9)
121 (define-key map (char-to-string loop) 'digit-argument)
122 (setq loop (1+ loop))))))
123
be9b65ac
DL
124;Moved to keymap.c
125;(defun copy-keymap (keymap)
126; "Return a copy of KEYMAP"
127; (while (not (keymapp keymap))
128; (setq keymap (signal 'wrong-type-argument (list 'keymapp keymap))))
129; (if (vectorp keymap)
130; (copy-sequence keymap)
131; (copy-alist keymap)))
132
7f2c2edd 133(defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
be9b65ac
DL
134 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
135In other words, OLDDEF is replaced with NEWDEF where ever it appears.
7f2c2edd
RS
136If optional fourth argument OLDMAP is specified, we redefine
137in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
138 (or prefix (setq prefix ""))
139 (let* ((scan (or oldmap keymap))
140 (vec1 (vector nil))
141 (prefix1 (vconcat prefix vec1)))
142 ;; Scan OLDMAP, finding each char or event-symbol that
143 ;; has any definition, and act on it with hack-key.
144 (while (consp scan)
145 (if (consp (car scan))
146 (let ((char (car (car scan)))
147 (defn (cdr (car scan))))
148 ;; The inside of this let duplicates exactly
149 ;; the inside of the following let that handles array elements.
150 (aset vec1 0 char)
151 (aset prefix1 (length prefix) char)
152 (let (inner-def)
153 ;; Skip past menu-prompt.
154 (while (stringp (car-safe defn))
155 (setq defn (cdr defn)))
156 (setq inner-def defn)
157 (while (and (symbolp inner-def)
158 (fboundp inner-def))
159 (setq inner-def (symbol-function inner-def)))
160 (if (eq defn olddef)
161 (define-key keymap prefix1 newdef)
162 (if (keymapp defn)
163 (substitute-key-definition olddef newdef keymap
164 inner-def
165 prefix1)))))
166 (if (arrayp (car scan))
167 (let* ((array (car scan))
168 (len (length array))
169 (i 0))
170 (while (< i len)
171 (let ((char i) (defn (aref array i)))
172 ;; The inside of this let duplicates exactly
173 ;; the inside of the previous let.
174 (aset vec1 0 char)
175 (aset prefix1 (length prefix) char)
176 (let (inner-def)
177 ;; Skip past menu-prompt.
178 (while (stringp (car-safe defn))
179 (setq defn (cdr defn)))
180 (setq inner-def defn)
181 (while (and (symbolp inner-def)
182 (fboundp inner-def))
183 (setq inner-def (symbol-function inner-def)))
184 (if (eq defn olddef)
185 (define-key keymap prefix1 newdef)
186 (if (keymapp defn)
187 (substitute-key-definition olddef newdef keymap
188 inner-def
189 prefix1)))))
190 (setq i (1+ i))))))
191 (setq scan (cdr scan)))))
9a5336ae 192
06ae9cf2 193(defun define-key-after (keymap key definition after)
4434d61b
RS
194 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
195This is like `define-key' except that the binding for KEY is placed
196just after the binding for the event AFTER, instead of at the beginning
197of the map.
626f67f3
RS
198The order matters when the keymap is used as a menu.
199KEY must contain just one event type--it must be a string or vector
200of length 1."
4434d61b
RS
201 (or (keymapp keymap)
202 (signal 'wrong-type-argument (list 'keymapp keymap)))
ab375e6c 203 (if (> (length key) 1)
626f67f3 204 (error "multi-event key specified in `define-key-after'"))
113d28a8 205 (let ((tail keymap) done inserted
4434d61b
RS
206 (first (aref key 0)))
207 (while (and (not done) tail)
208 ;; Delete any earlier bindings for the same key.
209 (if (eq (car-safe (car (cdr tail))) first)
210 (setcdr tail (cdr (cdr tail))))
211 ;; When we reach AFTER's binding, insert the new binding after.
212 ;; If we reach an inherited keymap, insert just before that.
113d28a8 213 ;; If we reach the end of this keymap, insert at the end.
4434d61b 214 (if (or (eq (car-safe (car tail)) after)
113d28a8
RS
215 (eq (car (cdr tail)) 'keymap)
216 (null (cdr tail)))
4434d61b 217 (progn
113d28a8
RS
218 ;; Stop the scan only if we find a parent keymap.
219 ;; Keep going past the inserted element
220 ;; so we can delete any duplications that come later.
221 (if (eq (car (cdr tail)) 'keymap)
222 (setq done t))
223 ;; Don't insert more than once.
224 (or inserted
225 (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))))
226 (setq inserted t)))
4434d61b
RS
227 (setq tail (cdr tail)))))
228
9a5336ae
JB
229(defun keyboard-translate (from to)
230 "Translate character FROM to TO at a low level.
231This function creates a `keyboard-translate-table' if necessary
232and then modifies one entry in it."
233 (or (arrayp keyboard-translate-table)
234 (setq keyboard-translate-table ""))
235 (if (or (> from (length keyboard-translate-table))
236 (> to (length keyboard-translate-table)))
237 (progn
238 (let* ((i (length keyboard-translate-table))
f4ebbdbe
RS
239 (table (concat keyboard-translate-table
240 (make-string (- 256 i) 0))))
9a5336ae
JB
241 (while (< i 256)
242 (aset table i i)
243 (setq i (1+ i)))
244 (setq keyboard-translate-table table))))
245 (aset keyboard-translate-table from to))
246
247\f
248;;;; The global keymap tree.
249
250;;; global-map, esc-map, and ctl-x-map have their values set up in
251;;; keymap.c; we just give them docstrings here.
252
253(defvar global-map nil
254 "Default global keymap mapping Emacs keyboard input into commands.
255The value is a keymap which is usually (but not necessarily) Emacs's
256global map.")
257
258(defvar esc-map nil
259 "Default keymap for ESC (meta) commands.
260The normal global definition of the character ESC indirects to this keymap.")
261
262(defvar ctl-x-map nil
263 "Default keymap for C-x commands.
264The normal global definition of the character C-x indirects to this keymap.")
265
266(defvar ctl-x-4-map (make-sparse-keymap)
267 "Keymap for subcommands of C-x 4")
059184dd 268(defalias 'ctl-x-4-prefix ctl-x-4-map)
9a5336ae
JB
269(define-key ctl-x-map "4" 'ctl-x-4-prefix)
270
271(defvar ctl-x-5-map (make-sparse-keymap)
272 "Keymap for frame commands.")
059184dd 273(defalias 'ctl-x-5-prefix ctl-x-5-map)
9a5336ae
JB
274(define-key ctl-x-map "5" 'ctl-x-5-prefix)
275
0f03054a 276\f
9a5336ae
JB
277;;;; Event manipulation functions.
278
114137b8
RS
279;; This code exists specifically to make sure that the
280;; resulting number does not appear in the .elc file.
281;; The number is negative on most machines, but not on all!
282(defconst listify-key-sequence-1
283 (lsh 1 7))
284(setq listify-key-sequence-1 (logior (lsh 1 23) listify-key-sequence-1))
285
cde6d7e3
RS
286(defun listify-key-sequence (key)
287 "Convert a key sequence to a list of events."
288 (if (vectorp key)
289 (append key nil)
290 (mapcar (function (lambda (c)
291 (if (> c 127)
114137b8 292 (logxor c listify-key-sequence-1)
cde6d7e3
RS
293 c)))
294 (append key nil))))
295
53e5a4e8
RS
296(defsubst eventp (obj)
297 "True if the argument is an event object."
298 (or (integerp obj)
299 (and (symbolp obj)
300 (get obj 'event-symbol-elements))
301 (and (consp obj)
302 (symbolp (car obj))
303 (get (car obj) 'event-symbol-elements))))
304
305(defun event-modifiers (event)
306 "Returns a list of symbols representing the modifier keys in event EVENT.
307The elements of the list may include `meta', `control',
32295976
RS
308`shift', `hyper', `super', `alt', `click', `double', `triple', `drag',
309and `down'."
53e5a4e8
RS
310 (let ((type event))
311 (if (listp type)
312 (setq type (car type)))
313 (if (symbolp type)
314 (cdr (get type 'event-symbol-elements))
315 (let ((list nil))
316 (or (zerop (logand type (lsh 1 23)))
317 (setq list (cons 'meta list)))
318 (or (and (zerop (logand type (lsh 1 22)))
319 (>= (logand type 127) 32))
320 (setq list (cons 'control list)))
321 (or (and (zerop (logand type (lsh 1 21)))
322 (= (logand type 255) (downcase (logand type 255))))
323 (setq list (cons 'shift list)))
324 (or (zerop (logand type (lsh 1 20)))
325 (setq list (cons 'hyper list)))
326 (or (zerop (logand type (lsh 1 19)))
327 (setq list (cons 'super list)))
328 (or (zerop (logand type (lsh 1 18)))
329 (setq list (cons 'alt list)))
330 list))))
331
d63de416
RS
332(defun event-basic-type (event)
333 "Returns the basic type of the given event (all modifiers removed).
334The value is an ASCII printing character (not upper case) or a symbol."
2b0f4ba5
JB
335 (if (consp event)
336 (setq event (car event)))
d63de416
RS
337 (if (symbolp event)
338 (car (get event 'event-symbol-elements))
339 (let ((base (logand event (1- (lsh 1 18)))))
340 (downcase (if (< base 32) (logior base 64) base)))))
341
0f03054a
RS
342(defsubst mouse-movement-p (object)
343 "Return non-nil if OBJECT is a mouse movement event."
344 (and (consp object)
345 (eq (car object) 'mouse-movement)))
346
347(defsubst event-start (event)
348 "Return the starting position of EVENT.
349If EVENT is a mouse press or a mouse click, this returns the location
350of the event.
351If EVENT is a drag, this returns the drag's starting position.
352The return value is of the form
353 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
354The `posn-' functions access elements of such lists."
355 (nth 1 event))
356
357(defsubst event-end (event)
358 "Return the ending location of EVENT. EVENT should be a click or drag event.
359If EVENT is a click event, this function is the same as `event-start'.
360The return value is of the form
361 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
362The `posn-' functions access elements of such lists."
69b95560 363 (nth (if (consp (nth 2 event)) 2 1) event))
0f03054a 364
32295976
RS
365(defsubst event-click-count (event)
366 "Return the multi-click count of EVENT, a click or drag event.
367The return value is a positive integer."
368 (if (integerp (nth 2 event)) (nth 2 event) 1))
369
0f03054a
RS
370(defsubst posn-window (position)
371 "Return the window in POSITION.
372POSITION should be a list of the form
373 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
374as returned by the `event-start' and `event-end' functions."
375 (nth 0 position))
376
377(defsubst posn-point (position)
378 "Return the buffer location in POSITION.
379POSITION should be a list of the form
380 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
381as returned by the `event-start' and `event-end' functions."
15db4e0e
JB
382 (if (consp (nth 1 position))
383 (car (nth 1 position))
384 (nth 1 position)))
0f03054a
RS
385
386(defsubst posn-col-row (position)
387 "Return the row and column in POSITION.
388POSITION should be a list of the form
389 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
390as returned by the `event-start' and `event-end' functions."
391 (nth 2 position))
392
393(defsubst posn-timestamp (position)
394 "Return the timestamp of POSITION.
395POSITION should be a list of the form
396 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
f415c00c 397as returned by the `event-start' and `event-end' functions."
0f03054a 398 (nth 3 position))
9a5336ae 399
0f03054a 400\f
9a5336ae
JB
401;;;; Obsolescent names for functions.
402
059184dd
ER
403(defalias 'make-syntax-table 'copy-syntax-table)
404(defalias 'dot 'point)
405(defalias 'dot-marker 'point-marker)
406(defalias 'dot-min 'point-min)
407(defalias 'dot-max 'point-max)
408(defalias 'window-dot 'window-point)
409(defalias 'set-window-dot 'set-window-point)
410(defalias 'read-input 'read-string)
411(defalias 'send-string 'process-send-string)
412(defalias 'send-region 'process-send-region)
413(defalias 'show-buffer 'set-window-buffer)
414(defalias 'buffer-flush-undo 'buffer-disable-undo)
415(defalias 'eval-current-buffer 'eval-buffer)
416(defalias 'compiled-function-p 'byte-code-function-p)
be9b65ac 417
9a5336ae
JB
418;; Some programs still use this as a function.
419(defun baud-rate ()
bcacc42c
RS
420 "Obsolete function returning the value of the `baud-rate' variable.
421Please convert your programs to use the variable `baud-rate' directly."
9a5336ae
JB
422 baud-rate)
423
424\f
425;;;; Alternate names for functions - these are not being phased out.
426
059184dd
ER
427(defalias 'string= 'string-equal)
428(defalias 'string< 'string-lessp)
429(defalias 'move-marker 'set-marker)
430(defalias 'eql 'eq)
431(defalias 'not 'null)
432(defalias 'rplaca 'setcar)
433(defalias 'rplacd 'setcdr)
eb8c3be9 434(defalias 'beep 'ding) ;preserve lingual purity
059184dd
ER
435(defalias 'indent-to-column 'indent-to)
436(defalias 'backward-delete-char 'delete-backward-char)
437(defalias 'search-forward-regexp (symbol-function 're-search-forward))
438(defalias 'search-backward-regexp (symbol-function 're-search-backward))
439(defalias 'int-to-string 'number-to-string)
37f6661a
JB
440
441;;; Should this be an obsolete name? If you decide it should, you get
442;;; to go through all the sources and change them.
059184dd 443(defalias 'string-to-int 'string-to-number)
be9b65ac 444\f
9a5336ae 445;;;; Hook manipulation functions.
be9b65ac 446
be9b65ac
DL
447(defun run-hooks (&rest hooklist)
448 "Takes hook names and runs each one in turn. Major mode functions use this.
449Each argument should be a symbol, a hook variable.
450These symbols are processed in the order specified.
451If a hook symbol has a non-nil value, that value may be a function
452or a list of functions to be called to run the hook.
453If the value is a function, it is called with no arguments.
454If it is a list, the elements are called, in order, with no arguments."
455 (while hooklist
456 (let ((sym (car hooklist)))
457 (and (boundp sym)
458 (symbol-value sym)
459 (let ((value (symbol-value sym)))
460 (if (and (listp value) (not (eq (car value) 'lambda)))
461 (mapcar 'funcall value)
462 (funcall value)))))
463 (setq hooklist (cdr hooklist))))
464
465;; Tell C code how to call this function.
466(defconst run-hooks 'run-hooks
467 "Variable by which C primitives find the function `run-hooks'.
468Don't change it.")
469
08159178 470(defun add-hook (hook function &optional append)
32295976
RS
471 "Add to the value of HOOK the function FUNCTION.
472FUNCTION is not added if already present.
473FUNCTION is added (if necessary) at the beginning of the hook list
474unless the optional argument APPEND is non-nil, in which case
475FUNCTION is added at the end.
476
477HOOK should be a symbol, and FUNCTION may be any valid function. If
478HOOK is void, it is first set to nil. If HOOK's value is a single
479function, it is changed to a list of functions."
be9b65ac 480 (or (boundp hook) (set hook nil))
32295976
RS
481 ;; If the hook value is a single function, turn it into a list.
482 (let ((old (symbol-value hook)))
483 (if (or (not (listp old)) (eq (car old) 'lambda))
484 (set hook (list old))))
be9b65ac
DL
485 (or (if (consp function)
486 ;; Clever way to tell whether a given lambda-expression
487 ;; is equal to anything in the hook.
488 (let ((tail (assoc (cdr function) (symbol-value hook))))
489 (equal function tail))
490 (memq function (symbol-value hook)))
08159178
ER
491 (set hook
492 (if append
493 (nconc (symbol-value hook) (list function))
494 (cons function (symbol-value hook))))))
9a5336ae 495
be9b65ac 496\f
9a5336ae
JB
497;;;; Specifying things to do after certain files are loaded.
498
499(defun eval-after-load (file form)
500 "Arrange that, if FILE is ever loaded, FORM will be run at that time.
501This makes or adds to an entry on `after-load-alist'.
502FILE should be the name of a library, with no directory name."
503 (or (assoc file after-load-alist)
504 (setq after-load-alist (cons (list file) after-load-alist)))
505 (nconc (assoc file after-load-alist) (list form))
506 form)
507
508(defun eval-next-after-load (file)
509 "Read the following input sexp, and run it whenever FILE is loaded.
510This makes or adds to an entry on `after-load-alist'.
511FILE should be the name of a library, with no directory name."
512 (eval-after-load file (read)))
513
514\f
515;;;; Input and display facilities.
516
517(defun read-quoted-char (&optional prompt)
518 "Like `read-char', except that if the first character read is an octal
519digit, we read up to two more octal digits and return the character
520represented by the octal number consisting of those digits.
521Optional argument PROMPT specifies a string to use to prompt the user."
522 (let ((count 0) (code 0) char)
523 (while (< count 3)
524 (let ((inhibit-quit (zerop count))
525 (help-form nil))
526 (and prompt (message "%s-" prompt))
527 (setq char (read-char))
528 (if inhibit-quit (setq quit-flag nil)))
529 (cond ((null char))
530 ((and (<= ?0 char) (<= char ?7))
531 (setq code (+ (* code 8) (- char ?0))
532 count (1+ count))
533 (and prompt (message (setq prompt
534 (format "%s %c" prompt char)))))
535 ((> count 0)
536 (setq unread-command-events (list char) count 259))
537 (t (setq code char count 259))))
538 (logand 255 code)))
539
540(defun force-mode-line-update (&optional all)
541 "Force the mode-line of the current buffer to be redisplayed.
542With optional non-nil ALL then force then force redisplay of all mode-lines."
543 (if all (save-excursion (set-buffer (other-buffer))))
544 (set-buffer-modified-p (buffer-modified-p)))
545
be9b65ac
DL
546(defun momentary-string-display (string pos &optional exit-char message)
547 "Momentarily display STRING in the buffer at POS.
548Display remains until next character is typed.
549If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
550otherwise it is then available as input (as a command if nothing else).
551Display MESSAGE (optional fourth arg) in the echo area.
552If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
553 (or exit-char (setq exit-char ?\ ))
554 (let ((buffer-read-only nil)
555 (modified (buffer-modified-p))
556 (name buffer-file-name)
557 insert-end)
558 (unwind-protect
559 (progn
560 (save-excursion
561 (goto-char pos)
562 ;; defeat file locking... don't try this at home, kids!
563 (setq buffer-file-name nil)
564 (insert-before-markers string)
3eec84bf
RS
565 (setq insert-end (point))
566 ;; If the message end is off screen, recenter now.
567 (if (> (window-end) insert-end)
568 (recenter (/ (window-height) 2)))
569 ;; If that pushed message start off the screen,
570 ;; scroll to start it at the top of the screen.
571 (move-to-window-line 0)
572 (if (> (point) pos)
573 (progn
574 (goto-char pos)
575 (recenter 0))))
be9b65ac
DL
576 (message (or message "Type %s to continue editing.")
577 (single-key-description exit-char))
3547c855 578 (let ((char (read-event)))
be9b65ac 579 (or (eq char exit-char)
dbc4e1c1 580 (setq unread-command-events (list char)))))
be9b65ac
DL
581 (if insert-end
582 (save-excursion
583 (delete-region pos insert-end)))
584 (setq buffer-file-name name)
585 (set-buffer-modified-p modified))))
586
9a5336ae
JB
587\f
588;;;; Miscellanea.
589
590(defun ignore (&rest ignore)
591 "Do nothing.
592Accept any number of arguments, but ignore them."
593 nil)
594
595(defun error (&rest args)
596 "Signal an error, making error message by passing all args to `format'."
597 (while t
598 (signal 'error (list (apply 'format args)))))
599
600(defun user-original-login-name ()
601 "Return user's login name from original login.
602This tries to remain unaffected by `su', by looking in environment variables."
603 (or (getenv "LOGNAME") (getenv "USER") (user-login-name)))
604
be9b65ac
DL
605(defun start-process-shell-command (name buffer &rest args)
606 "Start a program in a subprocess. Return the process object for it.
607Args are NAME BUFFER COMMAND &rest COMMAND-ARGS.
608NAME is name for process. It is modified if necessary to make it unique.
609BUFFER is the buffer or (buffer-name) to associate with the process.
610 Process output goes at end of that buffer, unless you specify
611 an output stream or filter function to handle the output.
612 BUFFER may be also nil, meaning that this process is not associated
613 with any buffer
614Third arg is command name, the name of a shell command.
615Remaining arguments are the arguments for the command.
616Wildcards and redirection are handle as usual in the shell."
617 (if (eq system-type 'vax-vms)
618 (apply 'start-process name buffer args)
619 (start-process name buffer shell-file-name "-c"
620 (concat "exec " (mapconcat 'identity args " ")))))
be9b65ac 621
9a5336ae
JB
622(defmacro save-match-data (&rest body)
623 "Execute the BODY forms, restoring the global value of the match data."
624 (let ((original (make-symbol "match-data")))
625 (list
626 'let (list (list original '(match-data)))
627 (list 'unwind-protect
628 (cons 'progn body)
629 (list 'store-match-data original)))))
ffd56f97 630
9a5336ae
JB
631;; now in fns.c
632;(defun nth (n list)
633; "Returns the Nth element of LIST.
634;N counts from zero. If LIST is not that long, nil is returned."
635; (car (nthcdr n list)))
636;
637;(defun copy-alist (alist)
638; "Return a copy of ALIST.
639;This is a new alist which represents the same mapping
640;from objects to objects, but does not share the alist structure with ALIST.
641;The objects mapped (cars and cdrs of elements of the alist)
642;are shared, however."
643; (setq alist (copy-sequence alist))
644; (let ((tail alist))
645; (while tail
646; (if (consp (car tail))
647; (setcar tail (cons (car (car tail)) (cdr (car tail)))))
648; (setq tail (cdr tail))))
649; alist)
630cc463
ER
650
651;;; subr.el ends here
9a5336ae 652