annotate lisp/subr.el @ 293:403535bfea94

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