annotate lisp/prim/subr.el @ 207:e45d5e7c476e r20-4b2

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