annotate lisp/prim/subr.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;; Lisp language features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defmacro lambda (&rest cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "Return a lambda expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 self-quoting; the result of evaluating the lambda expression is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 expression itself. The lambda expression may then be treated as a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 function, i.e., stored as the function value of a symbol, passed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 funcall or mapcar, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ARGS should take the same form as an argument list for a `defun'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 DOCSTRING is an optional documentation string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 If present, it should describe how to call the function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 But documentation strings are usually not useful in nameless functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 INTERACTIVE should be a call to the function `interactive', which see.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 It may also be omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 BODY should be a list of lisp expressions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; Note that this definition should not use backquotes; subr.el should not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; depend on backquote.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; #### - I don't see why. So long as backquote.el doesn't use anything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; from subr.el, there's no problem with using backquotes here. --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (list 'function (cons 'lambda cdr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (define-function 'not 'null)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if (not (fboundp 'numberp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (define-function 'numberp 'integerp)) ; different when floats
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defun local-variable-if-set-p (sym buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "Return t if SYM would be local to BUFFER after it is set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 A nil value for BUFFER is *not* the same as (current-buffer), but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 can be used to determine whether `make-variable-buffer-local' has been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 called on SYM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (local-variable-p sym buffer t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;;; Hook manipulation functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun make-local-hook (hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Make the hook HOOK local to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 When a hook is local, its local and global values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 work in concert: running the hook actually runs all the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 functions listed in *either* the local value *or* the global value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 of the hook variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 This function works by making `t' a member of the buffer-local value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 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
74 well. This works for all normal hooks, but does not work for most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 non-normal hooks yet. We will be changing the callers of non-normal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 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
77 one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 This function does nothing if HOOK is already local in the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 Do not use `make-local-variable' to make a hook variable buffer-local."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if (local-variable-p hook (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (or (boundp hook) (set hook nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (make-local-variable hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (set hook (list t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun add-hook (hook function &optional append local)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Add to the value of HOOK the function FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 FUNCTION is not added if already present.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 FUNCTION is added (if necessary) at the beginning of the hook list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 unless the optional argument APPEND is non-nil, in which case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 FUNCTION is added at the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 The optional fourth argument, LOCAL, if non-nil, says to modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 the hook's buffer-local value rather than its default value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 This makes no difference if the hook is not buffer-local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 To make a hook variable buffer-local, always use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 `make-local-hook', not `make-local-variable'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 HOOK should be a symbol, and FUNCTION may be any valid function. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 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
104 function, it is changed to a list of functions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;(interactive "SAdd to hook-var (symbol): \naAdd which function to %s? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (or (boundp hook) (set hook nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (or (default-boundp hook) (set-default hook nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; If the hook value is a single function, turn it into a list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((old (symbol-value hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (if (or (not (listp old)) (eq (car old) 'lambda))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (set hook (list old))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if (or local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; Detect the case where make-local-variable was used on a hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; and do what we used to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (and (local-variable-if-set-p hook (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (not (memq t (symbol-value hook)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; Alter the local value only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (or (if (consp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (member function (symbol-value hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (memq function (symbol-value hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (set hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (append (symbol-value hook) (list function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (cons function (symbol-value hook)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; Alter the global value (which is also the only value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; if the hook doesn't have a local value).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (or (if (consp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (member function (default-value hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (memq function (default-value hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (set-default hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (if append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (append (default-value hook) (list function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (cons function (default-value hook)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun remove-hook (hook function &optional local)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "Remove from the value of HOOK the function FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 HOOK should be a symbol, and FUNCTION may be any valid function. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 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
139 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
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 The optional third argument, LOCAL, if non-nil, says to modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 the hook's buffer-local value rather than its default value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 This makes no difference if the hook is not buffer-local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 To make a hook variable buffer-local, always use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 `make-local-hook', not `make-local-variable'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (or (not (boundp hook)) ;unbound symbol, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (not (default-boundp 'hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (null (symbol-value hook)) ;value is nil, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (null function)) ;function is nil, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 nil ;Do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if (or local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; Detect the case where make-local-variable was used on a hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; and do what we used to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (and (local-variable-p hook (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (not (memq t (symbol-value hook)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let ((hook-value (symbol-value hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if (consp hook-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if (member function hook-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq hook-value (delete function (copy-sequence hook-value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (if (equal hook-value function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq hook-value nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (set hook hook-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (let ((hook-value (default-value hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if (consp hook-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (member function hook-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq hook-value (delete function (copy-sequence hook-value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if (equal hook-value function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (setq hook-value nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (set-default hook hook-value)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun add-to-list (list-var element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 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
174 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
175 into a hook function that will be run only after loading the package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 `eval-after-load' provides one way to do this. In some cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 other hooks, such as major mode hooks, can do the job."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (or (member element (symbol-value list-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (set list-var (cons element (symbol-value list-var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; called by Fkill_buffer()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defvar kill-buffer-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "Function or functions to be called when a buffer is killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 The value of this variable may be buffer-local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 The buffer about to be killed is current when this hook is run.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; in C in FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defvar kill-emacs-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "Function or functions to be called when `kill-emacs' is called,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 just before emacs is actually killed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; not obsolete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (define-function 'rplaca 'setcar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (define-function 'rplacd 'setcdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defun mapvector (__function __seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Apply FUNCTION to each element of SEQ, making a vector of the results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 The result is a vector of the same length as SEQ.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 SEQ may be a list, a vector or a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (let* ((len (length __seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (vec (make-vector len 'nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (aset vec i (funcall __function (cond ((listp __seq)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (nth i __seq))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (t (aref __seq i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (setq i (+ i 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 vec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;;;; String functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (defun replace-in-string (str regexp newtext &optional literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 "Replaces all matches in STR for REGEXP with NEWTEXT string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 Optional LITERAL non-nil means do a literal replacement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 Otherwise treat \\ in NEWTEXT string as special:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 \\& means substitute original matched text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 \\N means substitute match for \(...\) number N,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 \\\\ means insert one \\."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (not (stringp str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (error "(replace-in-string): First argument must be a string: %s" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (if (stringp newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (error "(replace-in-string): 3rd arg must be a string: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (let ((rtn-str "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 match prev-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (while (setq match (string-match regexp str start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq prev-start start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 start (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 rtn-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 rtn-str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (substring str prev-start match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (cond (literal newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (t (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (if special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (setq special nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (cond ((eq c ?\\) "\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ((eq c ?&)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (substring str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ((and (>= c ?0) (<= c ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if (> c (+ ?0 (length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (match-data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; Invalid match num
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (error "(replace-in-string) Invalid match num: %c" c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (setq c (- c ?0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (substring str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (match-beginning c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (match-end c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (t (char-to-string c))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if (eq c ?\\) (progn (setq special t) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (char-to-string c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 newtext ""))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (concat rtn-str (substring str start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (defun split-string (string pattern)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 "Return a list of substrings of STRING which are separated by PATTERN."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (let (parts (start 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (while (string-match pattern string start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (setq parts (cons (substring string start (match-beginning 0)) parts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 start (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (nreverse (cons (substring string start) parts))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (defmacro with-output-to-string (&rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "Collect output to `standard-output' while evaluating FORMS and return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 it as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> w/ mods from Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (` (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (set-buffer (get-buffer-create " *string-output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (buffer-disable-undo (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (let ((standard-output (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (,@ forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (buffer-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (erase-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defun insert-face (string face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 "Insert STRING and highlight with FACE. Returns the extent created."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (let ((p (point)) ext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (setq ext (make-extent p (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (set-extent-face ext face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;; not obsolete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (define-function 'string= 'string-equal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (define-function 'string< 'string-lessp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (define-function 'int-to-string 'number-to-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (define-function 'string-to-int 'string-to-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; alist/plist functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defun plist-to-alist (plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "Convert property list PLIST into the equivalent association-list form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 The alist is returned. This converts from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 \(a 1 b 2 c 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 \((a . 1) (b . 2) (c . 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 The original plist is not modified. See also `destructive-plist-to-alist'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (let (alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (while plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (setq alist (cons (cons (car plist) (cadr plist)) alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (setq plist (cddr plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (nreverse alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (defun destructive-plist-to-alist (plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 "Convert property list PLIST into the equivalent association-list form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 The alist is returned. This converts from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 \(a 1 b 2 c 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 \((a . 1) (b . 2) (c . 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 The original plist is destroyed in the process of constructing the alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 See also `plist-to-alist'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((head plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (while plist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ;; remember the next plist pair.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (setq next (cddr plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; make the cons holding the property value into the alist element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (setcdr (cdr plist) (cadr plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (setcar (cdr plist) (car plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;; reattach into alist form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (setcar plist (cdr plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (setcdr plist next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (setq plist next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 head))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (defun alist-to-plist (alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 "Convert association list ALIST into the equivalent property-list form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 The plist is returned. This converts from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 \((a . 1) (b . 2) (c . 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 \(a 1 b 2 c 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 The original alist is not modified. See also `destructive-alist-to-plist'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (let (plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (let ((el (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (setq plist (cons (cdr el) (cons (car el) plist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (setq alist (cdr alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (nreverse plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ;; getf, remf in cl*.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (defmacro putf (plist prop val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 "Add property PROP to plist PLIST with value VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 Analogous to (setq PLIST (plist-put PLIST PROP VAL))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 `(setq ,plist (plist-put ,plist ,prop ,val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defmacro laxputf (lax-plist prop val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 "Add property PROP to lax plist LAX-PLIST with value VAL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 Analogous to (setq LAX-PLIST (lax-plist-put LAX-PLIST PROP VAL))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 `(setq ,lax-plist (lax-plist-put ,lax-plist ,prop ,val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (defmacro laxremf (lax-plist prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 "Remove property PROP from lax plist LAX-PLIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 Analogous to (setq LAX-PLIST (lax-plist-remprop LAX-PLIST PROP))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 `(setq ,lax-plist (lax-plist-remprop ,lax-plist ,prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;;; Error functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defun error (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "Signal an error, making error message by passing all args to `format'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 This error is not continuable: you cannot continue execution after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 error using the debugger `r' command. See also `cerror'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (apply 'cerror args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defun cerror (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "Like `error' but signals a continuable error."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (signal 'error (list (apply 'format args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defmacro check-argument-type (predicate argument)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 "Check that ARGUMENT satisfies PREDICATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 If not, signal a continuable `wrong-type-argument' error until the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 returned value satifies PREDICATE, and assign the returned value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 to ARGUMENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 `(if (not (,(eval predicate) ,argument))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (setq ,argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (wrong-type-argument ,predicate ,argument))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (defun signal-error (error-symbol data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 "Signal a non-continuable error. Args are ERROR-SYMBOL, and associated DATA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 An error symbol is a symbol defined using `define-error'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 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
406 If the signal is handled, DATA is made available to the handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 See also `signal', and the functions to handle errors: `condition-case'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 and `call-with-condition-handler'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (signal error-symbol data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defun define-error (error-sym doc-string &optional inherits-from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 "Define a new error, denoted by ERROR-SYM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 DOC-STRING is an informative message explaining the error, and will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 printed out when an unhandled error occurs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 ERROR-SYM is a sub-error of INHERITS-FROM (which defaults to `error').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 \[`define-error' internally works by putting on ERROR-SYM an `error-message'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 property whose value is DOC-STRING, and an `error-conditions' property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 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
421 to and including `error'. You will sometimes see code that sets this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 directly rather than calling `define-error', but you should *not* do this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 yourself.]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (check-argument-type 'symbolp error-sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (check-argument-type 'stringp doc-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (put error-sym 'error-message doc-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (or inherits-from (setq inherits-from 'error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (let ((conds (get inherits-from 'error-conditions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (or conds (signal-error 'error (list "Not an error symbol" error-sym)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (put error-sym 'error-conditions (cons error-sym conds))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;;;; Miscellanea.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (defun buffer-substring-no-properties (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 "Return the text from BEG to END, without text properties, as a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (let ((string (buffer-substring beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (set-text-properties 0 (length string) nil string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (defun ignore (&rest ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 "Do nothing and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 This function accepts any number of arguments, but ignores them."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (defmacro save-current-buffer (&rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 "Restore the current buffer setting after executing FORMS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 Does not restore the values of point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 See also: `save-excursion'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (` (let ((_cur_buf_ (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (progn (,@ forms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (set-buffer _cur_buf_)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (defmacro eval-in-buffer (buffer &rest forms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 "Evaluate FORMS in BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 See also: `save-current-buffer' and `save-excursion'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (` (save-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (set-buffer (, buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (,@ forms))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;;; The real defn is in abbrev.el but some early callers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;;; (eg lisp-mode-abbrev-table) want this before abbrev.el is loaded...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (if (not (fboundp 'define-abbrev-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (setq abbrev-table-name-list '())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (fset 'define-abbrev-table (function (lambda (name defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; These are fixed-up when abbrev.el loads.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (setq abbrev-table-name-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (cons (cons name defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 abbrev-table-name-list)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (defun functionp (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 "Returns t if OBJ is a function, nil otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ((symbolp obj) (fboundp obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ((subrp obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ((compiled-function-p obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ((consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; This was not present before. I think Jamie had some objections
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; to this, so I'm leaving this undefined for now. --ben
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;;; The objection is this: there is more than one way to load the same file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all differrent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;;; 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
492 ;;; 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
493 ;;; it should work off of a hook on `provide'. Features are unique and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ;;; the arguments to (load) are not. --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;;;; Specifying things to do after certain files are loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ;(defun eval-after-load (file form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 ; "Arrange that, if FILE is ever loaded, FORM will be run at that time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;This makes or adds to an entry on `after-load-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;If FILE is already loaded, evaluate FORM right now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;It does nothing if FORM is already on the list for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;FILE should be the name of a library, with no directory name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ; ;; Make sure there is an element for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ; (or (assoc file after-load-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ; (setq after-load-alist (cons (list file) after-load-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ; ;; Add FORM to the element if it isn't there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ; (let ((elt (assoc file after-load-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ; (or (member form (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ; (nconc elt (list form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ; ;; If the file has been loaded already, run FORM right away.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ; (and (assoc file load-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ; (eval form)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ; form)
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 eval-next-after-load (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ; "Read the following input sexp, and run it whenever FILE is loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;This makes or adds to an entry on `after-load-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;FILE should be the name of a library, with no directory name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ; (eval-after-load file (read)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ; alternate names (not obsolete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (if (not (fboundp 'mod)) (define-function 'mod '%))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (define-function 'move-marker 'set-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (define-function 'beep 'ding) ;preserve lingual purtity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (define-function 'indent-to-column 'indent-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (define-function 'backward-delete-char 'delete-backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (define-function 'search-forward-regexp (symbol-function 're-search-forward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (define-function 'search-backward-regexp (symbol-function 're-search-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (define-function 'remove-directory 'delete-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (define-function 'set-match-data 'store-match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (define-function 'send-string-to-terminal 'external-debugging-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (define-function 'buffer-string 'buffer-substring)