Mercurial > hg > xemacs-beta
annotate lisp/subr.el @ 5458:97968d099404
Replace #'font-hex-string-to-number, #'font-warn with builtins, font.el
2011-04-23 Aidan Kehoe <kehoea@parhasard.net>
* font.el:
* font.el (font-warn): Removed.
* font.el (font-hex-string-to-number): Removed.
* font.el (internal-facep):
* font.el (font-lookup-rgb-components):
* font.el (font-parse-rgb-components):
Use #'string-to-number with the BASE argument instead of
#'font-hex-string-to-number, #'display-warning instead of
#'font-warn.
This entire file smells bitrotted, with lots of functions of very
little relevance to XEmacs, but addressing that is more work than
I can do today.
Lines beginning with 'HG:' are removed.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 23 Apr 2011 16:24:24 +0100 |
parents | f00192e1cd49 |
children | ac37a5f7e5be |
rev | line source |
---|---|
428 | 1 ;;; subr.el --- basic lisp subroutines for XEmacs |
2 | |
2525 | 3 ;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 2003 |
4 ;; Free Software Foundation, Inc. | |
428 | 5 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. |
6 ;; Copyright (C) 1995 Sun Microsystems. | |
1333 | 7 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing. |
428 | 8 |
9 ;; Maintainer: XEmacs Development Team | |
2525 | 10 ;; Keywords: extensions, dumped, internal |
428 | 11 |
12 ;; This file is part of XEmacs. | |
13 | |
14 ;; XEmacs is free software; you can redistribute it and/or modify it | |
15 ;; under the terms of the GNU General Public License as published by | |
16 ;; the Free Software Foundation; either version 2, or (at your option) | |
17 ;; any later version. | |
18 | |
19 ;; XEmacs is distributed in the hope that it will be useful, but | |
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 ;; General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
3000 | 26 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
428 | 28 |
1333 | 29 ;;; Synched up with: FSF 19.34. Some things synched up with later versions. |
428 | 30 |
31 ;;; Commentary: | |
32 | |
33 ;; This file is dumped with XEmacs. | |
34 | |
35 ;; There's not a whole lot in common now with the FSF version, | |
36 ;; be wary when applying differences. I've left in a number of lines | |
37 ;; of commentary just to give diff(1) something to synch itself with to | |
38 ;; provide useful context diffs. -sb | |
39 | |
1333 | 40 ;; BEGIN SYNCHED WITH FSF 21.2 |
41 | |
5284
d27c1ee1943b
Make the order of preloaded-file-list more sane.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5281
diff
changeset
|
42 ;; XEmacs; no need for custom-declare-variable-list, preloaded-file-list is |
d27c1ee1943b
Make the order of preloaded-file-list more sane.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5281
diff
changeset
|
43 ;; ordered to make it unnecessary. |
428 | 44 |
2525 | 45 (defun macro-declaration-function (macro decl) |
46 "Process a declaration found in a macro definition. | |
47 This is set as the value of the variable `macro-declaration-function'. | |
48 MACRO is the name of the macro being defined. | |
49 DECL is a list `(declare ...)' containing the declarations. | |
50 The return value of this function is not used." | |
51 (dolist (d (cdr decl)) | |
52 (cond ((and (consp d) (eq (car d) 'indent)) | |
53 (put macro 'lisp-indent-function (cadr d))) | |
54 ((and (consp d) (eq (car d) 'debug)) | |
55 (put macro 'edebug-form-spec (cadr d))) | |
56 (t | |
57 (message "Unknown declaration %s" d))))) | |
58 | |
59 (setq macro-declaration-function 'macro-declaration-function) | |
5281
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
60 |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
61 ;; XEmacs; this is here because we use it in backquote.el, so it needs to be |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
62 ;; available the first time a `(...) form is expanded. |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
63 (defun list* (first &rest rest) ; See compiler macro in cl-macs.el |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
64 "Return a new list with specified args as elements, cons'd to last arg. |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
65 Thus, `(list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
66 `(cons A (cons B (cons C D)))'." |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
67 (cond ((not rest) first) |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
68 ((not (cdr rest)) (cons first (car rest))) |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
69 (t (let* ((n (length rest)) |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
70 (copy (copy-sequence rest)) |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
71 (last (nthcdr (- n 2) copy))) |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
72 (setcdr last (car (cdr last))) |
aa20a889ff14
Remove a couple of redundant functions, backquote.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
5220
diff
changeset
|
73 (cons first copy))))) |
428 | 74 |
75 ;;;; Lisp language features. | |
76 | |
77 (defmacro lambda (&rest cdr) | |
78 "Return a lambda expression. | |
79 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is | |
80 self-quoting; the result of evaluating the lambda expression is the | |
81 expression itself. The lambda expression may then be treated as a | |
82 function, i.e., stored as the function value of a symbol, passed to | |
83 funcall or mapcar, etc. | |
84 | |
85 ARGS should take the same form as an argument list for a `defun'. | |
3842 | 86 Optional DOCSTRING is a documentation string. |
87 If present, it should describe how to call the function. Docstrings are | |
88 rarely useful unless the lambda will be named, eg, using `fset'. | |
89 Optional INTERACTIVE should be a call to the function `interactive'. | |
90 BODY should be a list of lisp expressions. | |
91 | |
92 The byte-compiler treats lambda expressions specially. If the lambda | |
93 expression is syntactically a function to be called, it will be compiled | |
94 unless protected by `quote'. Conversely, quoting a lambda expression with | |
95 `function' hints to the byte-compiler that it should compile the expression. | |
96 \(The byte-compiler may or may not actually compile it; for example it will | |
97 never compile lambdas nested in a data structure: `'(#'(lambda (x) x))'). | |
98 | |
99 The byte-compiler will warn about common problems such as the form | |
100 `(fset 'f '(lambda (x) x))' (the lambda cannot be byte-compiled; probably | |
101 the programmer intended `#'', although leaving the lambda unquoted will | |
102 normally suffice), but in general is it the programmer's responsibility to | |
103 quote lambda expressions appropriately." | |
428 | 104 `(function (lambda ,@cdr))) |
105 | |
1333 | 106 ;; FSF 21.2 has various basic macros here. We don't because they're either |
107 ;; in cl*.el (which we dump and hence is always available) or built-in. | |
108 | |
109 ;; More powerful versions in cl.el. | |
110 ;(defmacro push (newelt listname) | |
111 ;(defmacro pop (listname) | |
112 | |
113 ;; Built-in. | |
114 ;(defmacro when (cond &rest body) | |
115 ;(defmacro unless (cond &rest body) | |
116 | |
117 ;; More powerful versions in cl-macs.el. | |
118 ;(defmacro dolist (spec &rest body) | |
119 ;(defmacro dotimes (spec &rest body) | |
120 | |
121 ;; In cl.el. Ours are defun, but cl arranges for them to be inlined anyway. | |
122 ;(defsubst caar (x) | |
123 ;(defsubst cadr (x) | |
124 ;(defsubst cdar (x) | |
125 ;(defsubst cddr (x) | |
126 | |
127 ;; Built-in. Our `last' is more powerful in that it handles circularity. | |
128 ;(defun last (x &optional n) | |
129 ;(defun butlast (x &optional n) | |
130 ;(defun nbutlast (x &optional n) | |
131 | |
132 ;; In cl-seq.el. | |
133 ;(defun remove (elt seq) | |
134 ;(defun remq (elt list) | |
135 | |
428 | 136 (defmacro defun-when-void (&rest args) |
137 "Define a function, just like `defun', unless it's already defined. | |
138 Used for compatibility among different emacs variants." | |
139 `(if (fboundp ',(car args)) | |
140 nil | |
141 (defun ,@args))) | |
142 | |
143 (defmacro define-function-when-void (&rest args) | |
144 "Define a function, just like `define-function', unless it's already defined. | |
145 Used for compatibility among different emacs variants." | |
146 `(if (fboundp ,(car args)) | |
147 nil | |
148 (define-function ,@args))) | |
149 | |
150 | |
5338
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
151 (defun delete (item sequence) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
152 "Delete by side effect any occurrences of ITEM as a member of SEQUENCE. |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
153 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
154 The modified SEQUENCE is returned. Comparison is done with `equal'. |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
155 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
156 If the first member of a list SEQUENCE is ITEM, there is no way to remove it |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
157 by side effect; therefore, write `(setq foo (delete element foo))' to be |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
158 sure of changing the value of `foo'. Also see: `remove'." |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
159 (delete* item sequence :test #'equal)) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
160 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
161 (defun delq (item sequence) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
162 "Delete by side effect any occurrences of ITEM as a member of SEQUENCE. |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
163 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
164 The modified SEQUENCE is returned. Comparison is done with `eq'. If |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
165 SEQUENCE is a list and its first member is ITEM, there is no way to remove |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
166 it by side effect; therefore, write `(setq foo (delq element foo))' to be |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
167 sure of changing the value of `foo'." |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
168 (delete* item sequence :test #'eq)) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
169 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
170 (defun remove (item sequence) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
171 "Remove all occurrences of ITEM in SEQUENCE, testing with `equal'. |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
172 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
173 This is a non-destructive function; it makes a copy of SEQUENCE if necessary |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
174 to avoid corrupting the original SEQUENCE. |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
175 Also see: `remove*', `delete', `delete*'" |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
176 (remove* item sequence :test #'equal)) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
177 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
178 (defun remq (item sequence) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
179 "Remove all occurrences of ITEM in SEQUENCE, comparing with `eq'. |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
180 |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
181 This is a non-destructive function; it makes a copy of SEQUENCE to avoid |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
182 corrupting the original SEQUENCE. See also the more general `remove*'." |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
183 (remove* item sequence :test #'eq)) |
8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5327
diff
changeset
|
184 |
1333 | 185 (defun assoc-default (key alist &optional test default) |
186 "Find object KEY in a pseudo-alist ALIST. | |
187 ALIST is a list of conses or objects. Each element (or the element's car, | |
188 if it is a cons) is compared with KEY by evaluating (TEST (car elt) KEY). | |
189 If that is non-nil, the element matches; | |
190 then `assoc-default' returns the element's cdr, if it is a cons, | |
191 or DEFAULT if the element is not a cons. | |
192 | |
193 If no element matches, the value is nil. | |
194 If TEST is omitted or nil, `equal' is used." | |
195 (let (found (tail alist) value) | |
196 (while (and tail (not found)) | |
197 (let ((elt (car tail))) | |
198 (when (funcall (or test 'equal) (if (consp elt) (car elt) elt) key) | |
199 (setq found t value (if (consp elt) (cdr elt) default)))) | |
200 (setq tail (cdr tail))) | |
201 value)) | |
202 | |
203 (defun assoc-ignore-case (key alist) | |
204 "Like `assoc', but ignores differences in case and text representation. | |
205 KEY must be a string. Upper-case and lower-case letters are treated as equal." | |
206 (let (element) | |
207 (while (and alist (not element)) | |
208 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil t)) | |
209 (setq element (car alist))) | |
210 (setq alist (cdr alist))) | |
211 element)) | |
212 | |
213 (defun assoc-ignore-representation (key alist) | |
214 "Like `assoc', but ignores differences in text representation. | |
215 KEY must be a string." | |
216 (let (element) | |
217 (while (and alist (not element)) | |
218 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil)) | |
219 (setq element (car alist))) | |
220 (setq alist (cdr alist))) | |
221 element)) | |
222 | |
223 (defun member-ignore-case (elt list) | |
224 "Like `member', but ignores differences in case and text representation. | |
225 ELT must be a string. Upper-case and lower-case letters are treated as equal." | |
226 (while (and list (not (eq t (compare-strings elt 0 nil (car list) 0 nil t)))) | |
227 (setq list (cdr list))) | |
228 list) | |
229 | |
230 | |
428 | 231 ;;;; Keymap support. |
232 ;; XEmacs: removed to keymap.el | |
233 | |
234 ;;;; The global keymap tree. | |
235 | |
236 ;;; global-map, esc-map, and ctl-x-map have their values set up in | |
237 ;;; keymap.c; we just give them docstrings here. | |
238 | |
239 ;;;; Event manipulation functions. | |
240 | |
241 ;; XEmacs: This stuff is done in C Code. | |
242 | |
1333 | 243 ;;;; Obsolescent names for functions generally appear elsewhere, in |
244 ;;;; obsolete.el or in the files they are related do. Many very old | |
245 ;;;; obsolete stuff has been removed entirely (e.g. anything with `dot' in | |
246 ;;;; place of `point'). | |
247 | |
248 ; alternate names (not obsolete) | |
249 (if (not (fboundp 'mod)) (define-function 'mod '%)) | |
250 (define-function 'move-marker 'set-marker) | |
251 (define-function 'beep 'ding) ; preserve lingual purity | |
252 (define-function 'indent-to-column 'indent-to) | |
253 (define-function 'backward-delete-char 'delete-backward-char) | |
254 (define-function 'search-forward-regexp (symbol-function 're-search-forward)) | |
255 (define-function 'search-backward-regexp (symbol-function 're-search-backward)) | |
256 (define-function 'remove-directory 'delete-directory) | |
257 (define-function 'set-match-data 'store-match-data) | |
258 (define-function 'send-string-to-terminal 'external-debugging-output) | |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
259 (define-function 'special-form-p 'special-operator-p) |
428 | 260 |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5004
diff
changeset
|
261 ;; XEmacs; this is in Lisp, its bytecode now taken by subseq. |
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5004
diff
changeset
|
262 (define-function 'substring 'subseq) |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
263 |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
264 (define-function 'sort 'sort*) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
265 (define-function 'fillarray 'fill) |
5089
99f8ebc082d9
Make #'substring an alias of #'subseq; give the latter the byte code.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5004
diff
changeset
|
266 |
428 | 267 ;; XEmacs: |
268 (defun local-variable-if-set-p (sym buffer) | |
269 "Return t if SYM would be local to BUFFER after it is set. | |
270 A nil value for BUFFER is *not* the same as (current-buffer), but | |
271 can be used to determine whether `make-variable-buffer-local' has been | |
272 called on SYM." | |
273 (local-variable-p sym buffer t)) | |
274 | |
275 | |
276 ;;;; Hook manipulation functions. | |
277 | |
278 ;; (defconst run-hooks 'run-hooks ...) | |
279 | |
280 (defun make-local-hook (hook) | |
281 "Make the hook HOOK local to the current buffer. | |
1333 | 282 The return value is HOOK. |
283 | |
284 You never need to call this function now that `add-hook' does it for you | |
285 if its LOCAL argument is non-nil. | |
286 | |
428 | 287 When a hook is local, its local and global values |
288 work in concert: running the hook actually runs all the hook | |
289 functions listed in *either* the local value *or* the global value | |
290 of the hook variable. | |
291 | |
292 This function works by making `t' a member of the buffer-local value, | |
293 which acts as a flag to run the hook functions in the default value as | |
294 well. This works for all normal hooks, but does not work for most | |
295 non-normal hooks yet. We will be changing the callers of non-normal | |
296 hooks so that they can handle localness; this has to be done one by | |
297 one. | |
298 | |
299 This function does nothing if HOOK is already local in the current | |
300 buffer. | |
301 | |
1333 | 302 Do not use `make-local-variable' to make a hook variable buffer-local." |
428 | 303 (if (local-variable-p hook (current-buffer)) ; XEmacs |
304 nil | |
305 (or (boundp hook) (set hook nil)) | |
306 (make-local-variable hook) | |
1333 | 307 (set hook (list t))) |
308 hook) | |
428 | 309 |
310 (defun add-hook (hook function &optional append local) | |
311 "Add to the value of HOOK the function FUNCTION. | |
312 FUNCTION is not added if already present. | |
313 FUNCTION is added (if necessary) at the beginning of the hook list | |
314 unless the optional argument APPEND is non-nil, in which case | |
315 FUNCTION is added at the end. | |
316 | |
317 The optional fourth argument, LOCAL, if non-nil, says to modify | |
318 the hook's buffer-local value rather than its default value. | |
1333 | 319 This makes the hook buffer-local if needed. |
428 | 320 To make a hook variable buffer-local, always use |
321 `make-local-hook', not `make-local-variable'. | |
322 | |
323 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
324 HOOK is void, it is first set to nil. If HOOK's value is a single | |
442 | 325 function, it is changed to a list of functions. |
326 | |
327 You can remove this hook yourself using `remove-hook'. | |
328 | |
1333 | 329 See also `add-one-shot-hook'." |
428 | 330 (or (boundp hook) (set hook nil)) |
331 (or (default-boundp hook) (set-default hook nil)) | |
1333 | 332 (if local (unless (local-variable-if-set-p hook (current-buffer)) ; XEmacs |
333 (make-local-hook hook)) | |
334 ;; Detect the case where make-local-variable was used on a hook | |
335 ;; and do what we used to do. | |
336 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) | |
337 (setq local t))) | |
338 (let ((hook-value (if local (symbol-value hook) (default-value hook)))) | |
339 ;; If the hook value is a single function, turn it into a list. | |
340 (when (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) | |
341 (setq hook-value (list hook-value))) | |
342 ;; Do the actual addition if necessary | |
343 (unless (member function hook-value) | |
344 (setq hook-value | |
345 (if append | |
346 (append hook-value (list function)) | |
347 (cons function hook-value)))) | |
348 ;; Set the actual variable | |
349 (if local (set hook hook-value) (set-default hook hook-value)))) | |
428 | 350 |
351 (defun remove-hook (hook function &optional local) | |
352 "Remove from the value of HOOK the function FUNCTION. | |
353 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
354 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | |
355 list of hooks to run in HOOK, then nothing is done. See `add-hook'. | |
356 | |
357 The optional third argument, LOCAL, if non-nil, says to modify | |
358 the hook's buffer-local value rather than its default value. | |
1333 | 359 This makes the hook buffer-local if needed. |
428 | 360 To make a hook variable buffer-local, always use |
361 `make-local-hook', not `make-local-variable'." | |
1333 | 362 (or (boundp hook) (set hook nil)) |
363 (or (default-boundp hook) (set-default hook nil)) | |
364 (if local (unless (local-variable-if-set-p hook (current-buffer)) ; XEmacs | |
365 (make-local-hook hook)) | |
366 ;; Detect the case where make-local-variable was used on a hook | |
367 ;; and do what we used to do. | |
368 (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) | |
369 (setq local t))) | |
370 (let ((hook-value (if local (symbol-value hook) (default-value hook)))) | |
371 ;; Remove the function, for both the list and the non-list cases. | |
372 ;; XEmacs: add hook-test, for handling one-shot hooks. | |
373 (flet ((hook-test | |
374 (fn hel) | |
375 (or (equal fn hel) | |
376 (and (symbolp hel) | |
377 (equal fn | |
378 (get hel 'one-shot-hook-fun)))))) | |
379 (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) | |
380 (if (equal hook-value function) (setq hook-value nil)) | |
381 (setq hook-value (delete* function (copy-sequence hook-value) | |
382 :test 'hook-test))) | |
383 ;; If the function is on the global hook, we need to shadow it locally | |
384 ;;(when (and local (member* function (default-value hook) | |
385 ;; :test 'hook-test) | |
386 ;; (not (member* (cons 'not function) hook-value | |
387 ;; :test 'hook-test))) | |
388 ;; (push (cons 'not function) hook-value)) | |
389 ;; Set the actual variable | |
390 (if local (set hook hook-value) (set-default hook hook-value))))) | |
442 | 391 |
392 ;; XEmacs addition | |
393 ;; #### we need a coherent scheme for indicating compatibility info, | |
394 ;; so that it can be programmatically retrieved. | |
395 (defun add-local-hook (hook function &optional append) | |
396 "Add to the local value of HOOK the function FUNCTION. | |
1333 | 397 You don't need this any more. It's equivalent to specifying the LOCAL |
398 argument to `add-hook'." | |
442 | 399 (add-hook hook function append t)) |
400 | |
401 ;; XEmacs addition | |
402 (defun remove-local-hook (hook function) | |
403 "Remove from the local value of HOOK the function FUNCTION. | |
1333 | 404 You don't need this any more. It's equivalent to specifying the LOCAL |
405 argument to `remove-hook'." | |
406 (remove-hook hook function t)) | |
442 | 407 |
408 (defun add-one-shot-hook (hook function &optional append local) | |
409 "Add to the value of HOOK the one-shot function FUNCTION. | |
410 FUNCTION will automatically be removed from the hook the first time | |
411 after it runs (whether to completion or to an error). | |
412 FUNCTION is not added if already present. | |
413 FUNCTION is added (if necessary) at the beginning of the hook list | |
414 unless the optional argument APPEND is non-nil, in which case | |
415 FUNCTION is added at the end. | |
416 | |
417 HOOK should be a symbol, and FUNCTION may be any valid function. If | |
418 HOOK is void, it is first set to nil. If HOOK's value is a single | |
419 function, it is changed to a list of functions. | |
420 | |
421 You can remove this hook yourself using `remove-hook'. | |
422 | |
1333 | 423 See also `add-hook'." |
442 | 424 (let ((sym (gensym))) |
425 (fset sym `(lambda (&rest args) | |
426 (unwind-protect | |
427 (apply ',function args) | |
428 (remove-hook ',hook ',sym ',local)))) | |
429 (put sym 'one-shot-hook-fun function) | |
430 (add-hook hook sym append local))) | |
431 | |
432 (defun add-local-one-shot-hook (hook function &optional append) | |
433 "Add to the local value of HOOK the one-shot function FUNCTION. | |
1333 | 434 You don't need this any more. It's equivalent to specifying the LOCAL |
435 argument to `add-one-shot-hook'." | |
442 | 436 (add-one-shot-hook hook function append t)) |
428 | 437 |
4461
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
438 (defun add-to-list (list-var element &optional append compare-fn) |
428 | 439 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. |
4461
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
440 The test for presence of ELEMENT is done with COMPARE-FN; if |
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
441 COMPARE-FN is nil, then it defaults to `equal'. If ELEMENT is added, |
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
442 it is added at the beginning of the list, unless the optional argument |
42fad34efb3f
Support COMPARE-FN in add-to-list; thank you Brian Palmer.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4369
diff
changeset
|
443 APPEND is non-nil, in which case ELEMENT is added at the end. |
878 | 444 |
428 | 445 If you want to use `add-to-list' on a variable that is not defined |
446 until a certain package is loaded, you should put the call to `add-to-list' | |
447 into a hook function that will be run only after loading the package. | |
448 `eval-after-load' provides one way to do this. In some cases | |
449 other hooks, such as major mode hooks, can do the job." | |
4463 | 450 (if (member* element (symbol-value list-var) :test (or compare-fn #'equal)) |
878 | 451 (symbol-value list-var) |
452 (set list-var | |
453 (if append | |
454 (append (symbol-value list-var) (list element)) | |
455 (cons element (symbol-value list-var)))))) | |
428 | 456 |
1333 | 457 ;; END SYNCHED WITH FSF 21.2 |
458 | |
428 | 459 ;; XEmacs additions |
460 ;; called by Fkill_buffer() | |
461 (defvar kill-buffer-hook nil | |
462 "Function or functions to be called when a buffer is killed. | |
463 The value of this variable may be buffer-local. | |
464 The buffer about to be killed is current when this hook is run.") | |
465 | |
466 ;; in C in FSFmacs | |
467 (defvar kill-emacs-hook nil | |
468 "Function or functions to be called when `kill-emacs' is called, | |
469 just before emacs is actually killed.") | |
470 | |
471 ;; not obsolete. | |
472 ;; #### These are a bad idea, because the CL RPLACA and RPLACD | |
473 ;; return the cons cell, not the new CAR/CDR. -hniksic | |
474 ;; The proper definition would be: | |
475 ;; (defun rplaca (conscell newcar) | |
476 ;; (setcar conscell newcar) | |
477 ;; conscell) | |
478 ;; ...and analogously for RPLACD. | |
479 (define-function 'rplaca 'setcar) | |
480 (define-function 'rplacd 'setcdr) | |
481 | |
482 (defun copy-symbol (symbol &optional copy-properties) | |
483 "Return a new uninterned symbol with the same name as SYMBOL. | |
484 If COPY-PROPERTIES is non-nil, the new symbol will have a copy of | |
485 SYMBOL's value, function, and property lists." | |
486 (let ((new (make-symbol (symbol-name symbol)))) | |
487 (when copy-properties | |
488 ;; This will not copy SYMBOL's chain of forwarding objects, but | |
489 ;; I think that's OK. Callers should not expect such magic to | |
490 ;; keep working in the copy in the first place. | |
491 (and (boundp symbol) | |
492 (set new (symbol-value symbol))) | |
493 (and (fboundp symbol) | |
494 (fset new (symbol-function symbol))) | |
495 (setplist new (copy-list (symbol-plist symbol)))) | |
496 new)) | |
497 | |
442 | 498 (defun set-symbol-value-in-buffer (sym val buffer) |
499 "Set the value of SYM to VAL in BUFFER. Useful with buffer-local variables. | |
500 If SYM has a buffer-local value in BUFFER, or will have one if set, this | |
501 function allows you to set the local value. | |
502 | |
503 NOTE: At some point, this will be moved into C and will be very fast." | |
504 (with-current-buffer buffer | |
505 (set sym val))) | |
444 | 506 |
1333 | 507 |
508 ;; BEGIN SYNCHED WITH FSF 21.2 | |
509 | |
510 ;; #### #### #### AAaargh! Must be in C, because it is used insanely | |
511 ;; early in the bootstrap process. | |
512 ;(defun split-path (path) | |
513 ; "Explode a search path into a list of strings. | |
514 ;The path components are separated with the characters specified | |
515 ;with `path-separator'." | |
516 ; (while (or (not stringp path-separator) | |
517 ; (/= (length path-separator) 1)) | |
518 ; (setq path-separator (signal 'error (list "\ | |
519 ;`path-separator' should be set to a single-character string" | |
520 ; path-separator)))) | |
521 ; (split-string-by-char path (aref separator 0))) | |
522 | |
523 (defmacro with-current-buffer (buffer &rest body) | |
524 "Temporarily make BUFFER the current buffer and execute the forms in BODY. | |
525 The value returned is the value of the last form in BODY. | |
526 See also `with-temp-buffer'." | |
527 `(save-current-buffer | |
528 (set-buffer ,buffer) | |
529 ,@body)) | |
530 | |
531 (defmacro with-temp-file (filename &rest forms) | |
532 "Create a new buffer, evaluate FORMS there, and write the buffer to FILENAME. | |
533 The value of the last form in FORMS is returned, like `progn'. | |
534 See also `with-temp-buffer'." | |
535 (let ((temp-file (make-symbol "temp-file")) | |
536 (temp-buffer (make-symbol "temp-buffer"))) | |
537 `(let ((,temp-file ,filename) | |
538 (,temp-buffer | |
539 (get-buffer-create (generate-new-buffer-name " *temp file*")))) | |
540 (unwind-protect | |
541 (prog1 | |
542 (with-current-buffer ,temp-buffer | |
543 ,@forms) | |
544 (with-current-buffer ,temp-buffer | |
545 (widen) | |
546 (write-region (point-min) (point-max) ,temp-file nil 0))) | |
547 (and (buffer-name ,temp-buffer) | |
548 (kill-buffer ,temp-buffer)))))) | |
549 | |
550 ;; FSF compatibility | |
551 (defmacro with-temp-message (message &rest body) | |
552 "Display MESSAGE temporarily while BODY is evaluated. | |
553 The original message is restored to the echo area after BODY has finished. | |
554 The value returned is the value of the last form in BODY. | |
555 If MESSAGE is nil, the echo area and message log buffer are unchanged. | |
556 Use a MESSAGE of \"\" to temporarily clear the echo area. | |
428 | 557 |
1333 | 558 Note that this function exists for FSF compatibility purposes. A better way |
559 under XEmacs is to give the message a particular label (see `display-message'); | |
560 then, the old message is automatically restored when you clear your message | |
561 with `clear-message'." | |
562 ;; FSF additional doc string from 21.2: | |
563 ;; MESSAGE is written to the message log buffer if `message-log-max' is non-nil. | |
564 (let ((current-message (make-symbol "current-message")) | |
565 (temp-message (make-symbol "with-temp-message"))) | |
566 `(let ((,temp-message ,message) | |
567 (,current-message)) | |
568 (unwind-protect | |
569 (progn | |
570 (when ,temp-message | |
571 (setq ,current-message (current-message)) | |
572 (message "%s" ,temp-message)) | |
573 ,@body) | |
574 (and ,temp-message ,current-message | |
575 (message "%s" ,current-message)))))) | |
576 | |
577 (defmacro with-temp-buffer (&rest forms) | |
578 "Create a temporary buffer, and evaluate FORMS there like `progn'. | |
579 See also `with-temp-file' and `with-output-to-string'." | |
580 (let ((temp-buffer (make-symbol "temp-buffer"))) | |
581 `(let ((,temp-buffer | |
582 (get-buffer-create (generate-new-buffer-name " *temp*")))) | |
583 (unwind-protect | |
584 (with-current-buffer ,temp-buffer | |
585 ,@forms) | |
586 (and (buffer-name ,temp-buffer) | |
587 (kill-buffer ,temp-buffer)))))) | |
588 | |
589 (defmacro with-output-to-string (&rest body) | |
590 "Execute BODY, return the text it sent to `standard-output', as a string." | |
591 `(let ((standard-output | |
592 (get-buffer-create (generate-new-buffer-name " *string-output*")))) | |
593 (let ((standard-output standard-output)) | |
594 ,@body) | |
595 (with-current-buffer standard-output | |
596 (prog1 | |
597 (buffer-string) | |
598 (kill-buffer nil))))) | |
599 | |
2135 | 600 (defmacro with-local-quit (&rest body) |
601 "Execute BODY with `inhibit-quit' temporarily bound to nil." | |
602 `(condition-case nil | |
603 (let ((inhibit-quit nil)) | |
604 ,@body) | |
605 (quit (setq quit-flag t)))) | |
606 | |
607 ;; FSF 21.3. | |
1333 | 608 |
609 ; (defmacro combine-after-change-calls (&rest body) | |
610 ; "Execute BODY, but don't call the after-change functions till the end. | |
611 ; If BODY makes changes in the buffer, they are recorded | |
612 ; and the functions on `after-change-functions' are called several times | |
613 ; when BODY is finished. | |
614 ; The return value is the value of the last form in BODY. | |
615 | |
616 ; If `before-change-functions' is non-nil, then calls to the after-change | |
617 ; functions can't be deferred, so in that case this macro has no effect. | |
618 | |
619 ; Do not alter `after-change-functions' or `before-change-functions' | |
620 ; in BODY." | |
2135 | 621 ; (declare (indent 0) (debug t)) |
1333 | 622 ; `(unwind-protect |
623 ; (let ((combine-after-change-calls t)) | |
624 ; . ,body) | |
625 ; (combine-after-change-execute))) | |
801 | 626 |
4369
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
627 (defmacro with-case-table (table &rest body) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
628 "Execute the forms in BODY with TABLE as the current case table. |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
629 The value returned is the value of the last form in BODY." |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
630 (declare (indent 1) (debug t)) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
631 (let ((old-case-table (make-symbol "table")) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
632 (old-buffer (make-symbol "buffer"))) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
633 `(let ((,old-case-table (current-case-table)) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
634 (,old-buffer (current-buffer))) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
635 (unwind-protect |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
636 (progn (set-case-table ,table) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
637 ,@body) |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
638 (with-current-buffer ,old-buffer |
ef9eb714f0e4
Add ascii-case-table, #'with-case-table; make iso8859-1.el more comprehensible.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
639 (set-case-table ,old-case-table)))))) |
2135 | 640 |
641 (defvar delay-mode-hooks nil | |
642 "If non-nil, `run-mode-hooks' should delay running the hooks.") | |
643 (defvar delayed-mode-hooks nil | |
644 "List of delayed mode hooks waiting to be run.") | |
645 (make-variable-buffer-local 'delayed-mode-hooks) | |
646 (put 'delay-mode-hooks 'permanent-local t) | |
647 | |
648 (defun run-mode-hooks (&rest hooks) | |
649 "Run mode hooks `delayed-mode-hooks' and HOOKS, or delay HOOKS. | |
650 Execution is delayed if `delay-mode-hooks' is non-nil. | |
651 Major mode functions should use this." | |
652 (if delay-mode-hooks | |
653 ;; Delaying case. | |
654 (dolist (hook hooks) | |
655 (push hook delayed-mode-hooks)) | |
656 ;; Normal case, just run the hook as before plus any delayed hooks. | |
657 (setq hooks (nconc (nreverse delayed-mode-hooks) hooks)) | |
658 (setq delayed-mode-hooks nil) | |
659 (apply 'run-hooks hooks))) | |
660 | |
661 (defmacro delay-mode-hooks (&rest body) | |
662 "Execute BODY, but delay any `run-mode-hooks'. | |
663 Only affects hooks run in the current buffer." | |
664 `(progn | |
665 (make-local-variable 'delay-mode-hooks) | |
666 (let ((delay-mode-hooks t)) | |
667 ,@body))) | |
668 | |
1333 | 669 (defmacro with-syntax-table (table &rest body) |
670 "Evaluate BODY with syntax table of current buffer set to a copy of TABLE. | |
671 The syntax table of the current buffer is saved, BODY is evaluated, and the | |
672 saved table is restored, even in case of an abnormal exit. | |
673 Value is what BODY returns." | |
674 (let ((old-table (make-symbol "table")) | |
675 (old-buffer (make-symbol "buffer"))) | |
676 `(let ((,old-table (syntax-table)) | |
677 (,old-buffer (current-buffer))) | |
678 (unwind-protect | |
679 (progn | |
680 (set-syntax-table (copy-syntax-table ,table)) | |
681 ,@body) | |
682 (save-current-buffer | |
683 (set-buffer ,old-buffer) | |
684 (set-syntax-table ,old-table)))))) | |
685 | |
686 (put 'with-syntax-table 'lisp-indent-function 1) | |
687 (put 'with-syntax-table 'edebug-form-spec '(form body)) | |
688 | |
689 | |
690 ;; Moved from mule-coding.el. | |
691 (defmacro with-string-as-buffer-contents (str &rest body) | |
692 "With the contents of the current buffer being STR, run BODY. | |
4516
e96f3aca4d63
Document initial position of point in `with-string-as-buffer-contents'.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4504
diff
changeset
|
693 Point starts positioned to end of buffer. |
1333 | 694 Returns the new contents of the buffer, as modified by BODY. |
695 The original current buffer is restored afterwards." | |
696 `(with-temp-buffer | |
697 (insert ,str) | |
698 ,@body | |
699 (buffer-string))) | |
700 | |
701 | |
702 (defmacro save-match-data (&rest body) | |
703 "Execute BODY forms, restoring the global value of the match data." | |
704 (let ((original (make-symbol "match-data"))) | |
705 (list 'let (list (list original '(match-data))) | |
706 (list 'unwind-protect | |
707 (cons 'progn body) | |
708 (list 'store-match-data original))))) | |
709 | |
710 | |
711 (defun match-string (num &optional string) | |
712 "Return string of text matched by last search. | |
713 NUM specifies which parenthesized expression in the last regexp. | |
714 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
715 Zero means the entire text matched by the whole regexp or whole string. | |
716 STRING should be given if the last search was by `string-match' on STRING." | |
717 (if (match-beginning num) | |
718 (if string | |
719 (substring string (match-beginning num) (match-end num)) | |
720 (buffer-substring (match-beginning num) (match-end num))))) | |
801 | 721 |
1333 | 722 (defun match-string-no-properties (num &optional string) |
723 "Return string of text matched by last search, without text properties. | |
724 NUM specifies which parenthesized expression in the last regexp. | |
725 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
726 Zero means the entire text matched by the whole regexp or whole string. | |
727 STRING should be given if the last search was by `string-match' on STRING." | |
728 (if (match-beginning num) | |
729 (if string | |
730 (let ((result | |
731 (substring string (match-beginning num) (match-end num)))) | |
732 (set-text-properties 0 (length result) nil result) | |
733 result) | |
734 (buffer-substring-no-properties (match-beginning num) | |
735 (match-end num))))) | |
736 | |
1425 | 737 (defconst split-string-default-separators "[ \f\t\n\r\v]+" |
738 "The default value of separators for `split-string'. | |
739 | |
740 A regexp matching strings of whitespace. May be locale-dependent | |
741 \(as yet unimplemented). Should not match non-breaking spaces. | |
742 | |
743 Warning: binding this to a different value and using it as default is | |
744 likely to have undesired semantics.") | |
745 | |
746 ;; specification for `split-string' agreed with rms 2003-04-23 | |
747 ;; xemacs design <87vfx5vor0.fsf@tleepslib.sk.tsukuba.ac.jp> | |
748 | |
1495 | 749 ;; The specification says that if both SEPARATORS and OMIT-NULLS are |
750 ;; defaulted, OMIT-NULLS should be treated as t. Simplifying the logical | |
751 ;; expression leads to the equivalent implementation that if SEPARATORS | |
752 ;; is defaulted, OMIT-NULLS is treated as t. | |
753 | |
1425 | 754 (defun split-string (string &optional separators omit-nulls) |
755 "Splits STRING into substrings bounded by matches for SEPARATORS. | |
756 | |
757 The beginning and end of STRING, and each match for SEPARATORS, are | |
758 splitting points. The substrings matching SEPARATORS are removed, and | |
759 the substrings between the splitting points are collected as a list, | |
1333 | 760 which is returned. |
1425 | 761 |
2138 | 762 If SEPARATORS is non-`nil', it should be a regular expression matching text |
763 which separates, but is not part of, the substrings. If `nil' it defaults to | |
1495 | 764 `split-string-default-separators', normally \"[ \\f\\t\\n\\r\\v]+\", and |
2138 | 765 OMIT-NULLS is forced to `t'. |
1333 | 766 |
2138 | 767 If OMIT-NULLS is `t', zero-length substrings are omitted from the list \(so |
1425 | 768 that for the default value of SEPARATORS leading and trailing whitespace |
2138 | 769 are effectively trimmed). If `nil', all zero-length substrings are retained, |
1425 | 770 which correctly parses CSV format, for example. |
771 | |
1495 | 772 Note that the effect of `(split-string STRING)' is the same as |
773 `(split-string STRING split-string-default-separators t)'). In the rare | |
774 case that you wish to retain zero-length substrings when splitting on | |
775 whitespace, use `(split-string STRING split-string-default-separators nil)'. | |
1333 | 776 |
2138 | 777 Modifies the match data when successful; use `save-match-data' if necessary." |
1425 | 778 |
1495 | 779 (let ((keep-nulls (not (if separators omit-nulls t))) |
1425 | 780 (rexp (or separators split-string-default-separators)) |
1333 | 781 (start 0) |
782 notfirst | |
783 (list nil)) | |
784 (while (and (string-match rexp string | |
785 (if (and notfirst | |
786 (= start (match-beginning 0)) | |
787 (< start (length string))) | |
788 (1+ start) start)) | |
1425 | 789 (< start (length string))) |
1333 | 790 (setq notfirst t) |
1425 | 791 (if (or keep-nulls (< start (match-beginning 0))) |
1333 | 792 (setq list |
793 (cons (substring string start (match-beginning 0)) | |
794 list))) | |
795 (setq start (match-end 0))) | |
1425 | 796 (if (or keep-nulls (< start (length string))) |
1333 | 797 (setq list |
798 (cons (substring string start) | |
799 list))) | |
800 (nreverse list))) | |
801 | |
802 (defun subst-char-in-string (fromchar tochar string &optional inplace) | |
803 "Replace FROMCHAR with TOCHAR in STRING each time it occurs. | |
804 Unless optional argument INPLACE is non-nil, return a new string." | |
5321
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
805 (funcall (if inplace #'nsubstitute #'substitute) tochar fromchar |
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
806 (the string string) :test #'eq)) |
1333 | 807 |
808 ;; XEmacs addition: | |
428 | 809 (defun replace-in-string (str regexp newtext &optional literal) |
810 "Replace all matches in STR for REGEXP with NEWTEXT string, | |
811 and returns the new string. | |
812 Optional LITERAL non-nil means do a literal replacement. | |
442 | 813 Otherwise treat `\\' in NEWTEXT as special: |
814 `\\&' in NEWTEXT means substitute original matched text. | |
815 `\\N' means substitute what matched the Nth `\\(...\\)'. | |
816 If Nth parens didn't match, substitute nothing. | |
817 `\\\\' means insert one `\\'. | |
818 `\\u' means upcase the next character. | |
819 `\\l' means downcase the next character. | |
820 `\\U' means begin upcasing all following characters. | |
821 `\\L' means begin downcasing all following characters. | |
822 `\\E' means terminate the effect of any `\\U' or `\\L'." | |
428 | 823 (check-argument-type 'stringp str) |
824 (check-argument-type 'stringp newtext) | |
442 | 825 (if (> (length str) 50) |
924 | 826 (let ((cfs case-fold-search)) |
827 (with-temp-buffer | |
828 (setq case-fold-search cfs) | |
829 (insert str) | |
830 (goto-char 1) | |
442 | 831 (while (re-search-forward regexp nil t) |
832 (replace-match newtext t literal)) | |
924 | 833 (buffer-string))) |
834 (let ((start 0) newstr) | |
835 (while (string-match regexp str start) | |
836 (setq newstr (replace-match newtext t literal str) | |
837 start (+ (match-end 0) (- (length newstr) (length str))) | |
838 str newstr)) | |
839 str))) | |
428 | 840 |
1333 | 841 (defun replace-regexp-in-string (regexp rep string &optional |
842 fixedcase literal subexp start) | |
843 "Replace all matches for REGEXP with REP in STRING. | |
844 | |
845 Return a new string containing the replacements. | |
846 | |
4199 | 847 Optional arguments FIXEDCASE and LITERAL are like the arguments with |
848 the same names of function `replace-match'. If START is non-nil, | |
849 start replacements at that index in STRING. | |
850 | |
851 For compatibility with old XEmacs code and with recent GNU Emacs, the | |
852 interpretation of SUBEXP is somewhat complicated. If SUBEXP is a | |
853 buffer, it is interpreted as the buffer which provides syntax tables | |
854 and case tables for the match and replacement. If it is not a buffer, | |
855 the current buffer is used. If SUBEXP is an integer, it is the index | |
856 of the subexpression of REGEXP which is to be replaced. | |
428 | 857 |
1333 | 858 REP is either a string used as the NEWTEXT arg of `replace-match' or a |
859 function. If it is a function it is applied to each match to generate | |
860 the replacement passed to `replace-match'; the match-data at this | |
4199 | 861 point are such that `(match-string SUBEXP STRING)' is the function's |
862 argument if SUBEXP is an integer \(otherwise the whole match is passed | |
863 and replaced). | |
428 | 864 |
1333 | 865 To replace only the first match (if any), make REGEXP match up to \\' |
866 and replace a sub-expression, e.g. | |
867 (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1) | |
868 => \" bar foo\" | |
4199 | 869 |
870 Signals `invalid-argument' if SUBEXP is not an integer, buffer, or nil; | |
871 or is an integer, but the indicated subexpression was not matched. | |
872 Signals `invalid-argument' if STRING is nil but the last text matched was a string, | |
873 or if STRING is a string but the last text matched was a buffer." | |
428 | 874 |
1333 | 875 ;; To avoid excessive consing from multiple matches in long strings, |
876 ;; don't just call `replace-match' continually. Walk down the | |
877 ;; string looking for matches of REGEXP and building up a (reversed) | |
878 ;; list MATCHES. This comprises segments of STRING which weren't | |
879 ;; matched interspersed with replacements for segments that were. | |
880 ;; [For a `large' number of replacments it's more efficient to | |
881 ;; operate in a temporary buffer; we can't tell from the function's | |
882 ;; args whether to choose the buffer-based implementation, though it | |
883 ;; might be reasonable to do so for long enough STRING.] | |
884 (let ((l (length string)) | |
885 (start (or start 0)) | |
4199 | 886 (expndx (if (integerp subexp) subexp 0)) |
1333 | 887 matches str mb me) |
888 (save-match-data | |
889 (while (and (< start l) (string-match regexp string start)) | |
890 (setq mb (match-beginning 0) | |
891 me (match-end 0)) | |
892 ;; If we matched the empty string, make sure we advance by one char | |
893 (when (= me mb) (setq me (min l (1+ mb)))) | |
894 ;; Generate a replacement for the matched substring. | |
895 ;; Operate only on the substring to minimize string consing. | |
896 ;; Set up match data for the substring for replacement; | |
897 ;; presumably this is likely to be faster than munging the | |
898 ;; match data directly in Lisp. | |
899 (string-match regexp (setq str (substring string mb me))) | |
900 (setq matches | |
901 (cons (replace-match (if (stringp rep) | |
902 rep | |
4199 | 903 (funcall rep (match-string expndx str))) |
904 ;; no, this subexp shouldn't be expndx | |
1333 | 905 fixedcase literal str subexp) |
906 (cons (substring string start mb) ; unmatched prefix | |
907 matches))) | |
908 (setq start me)) | |
909 ;; Reconstruct a string from the pieces. | |
910 (setq matches (cons (substring string start l) matches)) ; leftover | |
911 (apply #'concat (nreverse matches))))) | |
428 | 912 |
1333 | 913 ;; END SYNCHED WITH FSF 21.2 |
914 | |
915 | |
1899 | 916 ;; BEGIN SYNCHED WITH FSF 21.3 |
917 | |
918 (defun add-to-invisibility-spec (arg) | |
919 "Add elements to `buffer-invisibility-spec'. | |
920 See documentation for `buffer-invisibility-spec' for the kind of elements | |
921 that can be added." | |
922 (if (eq buffer-invisibility-spec t) | |
923 (setq buffer-invisibility-spec (list t))) | |
924 (setq buffer-invisibility-spec | |
925 (cons arg buffer-invisibility-spec))) | |
926 | |
927 (defun remove-from-invisibility-spec (arg) | |
928 "Remove elements from `buffer-invisibility-spec'." | |
929 (if (consp buffer-invisibility-spec) | |
930 (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec)))) | |
931 | |
932 ;; END SYNCHED WITH FSF 21.3 | |
933 | |
934 | |
1333 | 935 ;;; Basic string functions |
883 | 936 |
1333 | 937 ;; XEmacs |
938 (defun string-equal-ignore-case (str1 str2) | |
939 "Return t if two strings have identical contents, ignoring case differences. | |
940 Case is not significant. Text properties and extents are ignored. | |
941 Symbols are also allowed; their print names are used instead. | |
428 | 942 |
1333 | 943 See also `equalp'." |
944 (if (symbolp str1) | |
945 (setq str1 (symbol-name str1))) | |
946 (if (symbolp str2) | |
947 (setq str2 (symbol-name str2))) | |
948 (eq t (compare-strings str1 nil nil str2 nil nil t))) | |
428 | 949 |
950 (defun insert-face (string face) | |
951 "Insert STRING and highlight with FACE. Return the extent created." | |
952 (let ((p (point)) ext) | |
953 (insert string) | |
954 (setq ext (make-extent p (point))) | |
955 (set-extent-face ext face) | |
956 ext)) | |
957 | |
958 ;; not obsolete. | |
959 (define-function 'string= 'string-equal) | |
960 (define-function 'string< 'string-lessp) | |
961 (define-function 'int-to-string 'number-to-string) | |
962 (define-function 'string-to-int 'string-to-number) | |
963 | |
964 ;; These two names are a bit awkward, as they conflict with the normal | |
965 ;; foo-to-bar naming scheme, but CLtL2 has them, so they stay. | |
966 (define-function 'char-int 'char-to-int) | |
967 (define-function 'int-char 'int-to-char) | |
968 | |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
969 ;; XEmacs addition. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
970 (defun integer-to-bit-vector (integer &optional minlength) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
971 "Return INTEGER converted to a bit vector. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
972 Optional argument MINLENGTH gives a minimum length for the returned vector. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
973 If MINLENGTH is not given, zero high-order bits will be ignored." |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
974 (check-argument-type #'integerp integer) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
975 (setq minlength (or minlength 0)) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
976 (check-nonnegative-number minlength) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
977 (read (format (format "#*%%0%db" minlength) integer))) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
978 |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
979 ;; XEmacs addition. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
980 (defun bit-vector-to-integer (bit-vector) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
981 "Return BIT-VECTOR converted to an integer. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
982 If bignum support is available, BIT-VECTOR's length is unlimited. |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
983 Otherwise the limit is the number of value bits in an Lisp integer. " |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
984 (check-argument-type #'bit-vector-p bit-vector) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
985 (setq bit-vector (prin1-to-string bit-vector)) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
986 (aset bit-vector 1 ?b) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
987 (read bit-vector)) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4267
diff
changeset
|
988 |
771 | 989 (defun string-width (string) |
990 "Return number of columns STRING occupies when displayed. | |
991 With international (Mule) support, uses the charset-columns attribute of | |
992 the characters in STRING, which may not accurately represent the actual | |
993 display width when using a window system. With no international support, | |
994 simply returns the length of the string." | |
5321
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
995 (reduce #'+ (the string string) :initial-value 0 :key #'char-width)) |
771 | 996 |
777 | 997 (defun char-width (character) |
998 "Return number of columns a CHARACTER occupies when displayed." | |
5321
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
999 (charset-width (char-charset character))) |
777 | 1000 |
1001 ;; The following several functions are useful in GNU Emacs 20 because | |
1002 ;; of the multibyte "characters" the internal representation of which | |
1003 ;; leaks into Lisp. In XEmacs/Mule they are trivial and unnecessary. | |
1004 ;; We provide them for compatibility reasons solely. | |
1005 | |
1006 (defun string-to-sequence (string type) | |
1007 "Convert STRING to a sequence of TYPE which contains characters in STRING. | |
1008 TYPE should be `list' or `vector'." | |
1009 (ecase type | |
1010 (list | |
4267 | 1011 (append string nil)) |
777 | 1012 (vector |
4267 | 1013 (vconcat string)))) |
777 | 1014 |
1015 (defun string-to-list (string) | |
1016 "Return a list of characters in STRING." | |
4267 | 1017 (append string nil)) |
777 | 1018 |
1019 (defun string-to-vector (string) | |
1020 "Return a vector of characters in STRING." | |
4267 | 1021 (vconcat string)) |
777 | 1022 |
1023 (defun store-substring (string idx obj) | |
1024 "Embed OBJ (string or character) at index IDX of STRING." | |
5321
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
1025 (if (stringp obj) |
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
1026 (replace (the string string) obj :start1 idx) |
57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5284
diff
changeset
|
1027 (prog1 string (aset string idx obj)))) |
777 | 1028 |
851 | 1029 ;; From FSF 21.1; ELLIPSES is XEmacs addition. |
1030 | |
1031 (defun truncate-string-to-width (str end-column &optional start-column padding | |
1333 | 1032 ellipses) |
777 | 1033 "Truncate string STR to end at column END-COLUMN. |
814 | 1034 The optional 3rd arg START-COLUMN, if non-nil, specifies |
777 | 1035 the starting column; that means to return the characters occupying |
1036 columns START-COLUMN ... END-COLUMN of STR. | |
1037 | |
814 | 1038 The optional 4th arg PADDING, if non-nil, specifies a padding character |
777 | 1039 to add at the end of the result if STR doesn't reach column END-COLUMN, |
1040 or if END-COLUMN comes in the middle of a character in STR. | |
1041 PADDING is also added at the beginning of the result | |
1042 if column START-COLUMN appears in the middle of a character in STR. | |
1043 | |
1044 If PADDING is nil, no padding is added in these cases, so | |
851 | 1045 the resulting string may be narrower than END-COLUMN. |
1046 | |
1047 BUG: Currently assumes that the padding character is of width one. You | |
1048 will get weird results if not. | |
1049 | |
1050 If ELLIPSES is non-nil, add ellipses (specified by ELLIPSES if a string, | |
1051 else `...') if STR extends past END-COLUMN. The ellipses will be added in | |
1052 such a way that the total string occupies no more than END-COLUMN columns | |
1053 -- i.e. if the string goes past END-COLUMN, it will be truncated somewhere | |
1054 short of END-COLUMN so that, with the ellipses added (and padding, if the | |
1055 proper place to truncate the string would be in the middle of a character), | |
1056 the string occupies exactly END-COLUMN columns." | |
777 | 1057 (or start-column |
1058 (setq start-column 0)) | |
814 | 1059 (let ((len (length str)) |
1060 (idx 0) | |
1061 (column 0) | |
1062 (head-padding "") (tail-padding "") | |
1063 ch last-column last-idx from-idx) | |
851 | 1064 |
1065 ;; find the index of START-COLUMN; bail out if end of string reached. | |
814 | 1066 (condition-case nil |
1067 (while (< column start-column) | |
1068 (setq ch (aref str idx) | |
1069 column (+ column (char-width ch)) | |
1070 idx (1+ idx))) | |
1071 (args-out-of-range (setq idx len))) | |
1072 (if (< column start-column) | |
851 | 1073 ;; if string ends before START-COLUMN, return either a blank string |
1074 ;; or a string entirely padded. | |
1075 (if padding (make-string (- end-column start-column) padding) "") | |
814 | 1076 (if (and padding (> column start-column)) |
1077 (setq head-padding (make-string (- column start-column) padding))) | |
1078 (setq from-idx idx) | |
851 | 1079 ;; If END-COLUMN is before START-COLUMN, then bail out. |
814 | 1080 (if (< end-column column) |
851 | 1081 (setq idx from-idx ellipses "") |
1082 | |
1083 ;; handle ELLIPSES | |
1084 (cond ((null ellipses) (setq ellipses "")) | |
1085 ((if (<= (string-width str) end-column) | |
1086 ;; string fits, no ellipses | |
1087 (setq ellipses ""))) | |
1088 (t | |
1089 ;; else, insert default value and ... | |
1090 (or (stringp ellipses) (setq ellipses "...")) | |
1091 ;; ... take away the width of the ellipses from the | |
1092 ;; destination. do all computations with new, shorter | |
1093 ;; width. the padding computed will get us exactly up to | |
1094 ;; the shorted width, which is right -- it just gets added | |
1095 ;; to the right of the ellipses. | |
924 | 1096 (setq end-column (- end-column (string-width ellipses))))) |
851 | 1097 |
1098 ;; find the index of END-COLUMN; bail out if end of string reached. | |
814 | 1099 (condition-case nil |
1100 (while (< column end-column) | |
1101 (setq last-column column | |
1102 last-idx idx | |
1103 ch (aref str idx) | |
1104 column (+ column (char-width ch)) | |
1105 idx (1+ idx))) | |
1106 (args-out-of-range (setq idx len))) | |
851 | 1107 ;; if we went too far (stopped in middle of character), back up. |
814 | 1108 (if (> column end-column) |
1109 (setq column last-column idx last-idx)) | |
851 | 1110 ;; compute remaining padding |
814 | 1111 (if (and padding (< column end-column)) |
1112 (setq tail-padding (make-string (- end-column column) padding)))) | |
851 | 1113 ;; get substring ... |
814 | 1114 (setq str (substring str from-idx idx)) |
851 | 1115 ;; and construct result |
814 | 1116 (if padding |
851 | 1117 (concat head-padding str tail-padding ellipses) |
1118 (concat str ellipses))))) | |
801 | 1119 |
428 | 1120 |
1121 ;; alist/plist functions | |
1122 (defun plist-to-alist (plist) | |
1123 "Convert property list PLIST into the equivalent association-list form. | |
1124 The alist is returned. This converts from | |
1125 | |
1126 \(a 1 b 2 c 3) | |
1127 | |
1128 into | |
1129 | |
1130 \((a . 1) (b . 2) (c . 3)) | |
1131 | |
1132 The original plist is not modified. See also `destructive-plist-to-alist'." | |
1133 (let (alist) | |
1134 (while plist | |
1135 (setq alist (cons (cons (car plist) (cadr plist)) alist)) | |
1136 (setq plist (cddr plist))) | |
1137 (nreverse alist))) | |
1138 | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1139 ((macro |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1140 . (lambda (map-plist-definition) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1141 "Replace the variable names in MAP-PLIST-DEFINITION with uninterned |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1142 symbols, avoiding the risk of interference with variables in other functions |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1143 introduced by dynamic scope." |
5327
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1144 (nsublis '((mp-function . #:function) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1145 (plist . #:plist) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1146 (result . #:result)) |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1147 ;; Need to specify #'eq as the test, otherwise we have a |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1148 ;; bootstrap issue, since #'eql is in cl.el, loaded after |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1149 ;; this file. |
d1b17a33450b
Move the heavy lifting from cl-seq.el to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5321
diff
changeset
|
1150 map-plist-definition :test #'eq))) |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1151 (defun map-plist (mp-function plist) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1152 "Map FUNCTION (a function of two args) over each key/value pair in PLIST. |
783 | 1153 Return a list of the results." |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1154 (let (result) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1155 (while plist |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1156 (push (funcall mp-function (car plist) (cadr plist)) result) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1157 (setq plist (cddr plist))) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1158 (nreverse result)))) |
783 | 1159 |
428 | 1160 (defun destructive-plist-to-alist (plist) |
1161 "Convert property list PLIST into the equivalent association-list form. | |
1162 The alist is returned. This converts from | |
1163 | |
1164 \(a 1 b 2 c 3) | |
1165 | |
1166 into | |
1167 | |
1168 \((a . 1) (b . 2) (c . 3)) | |
1169 | |
1170 The original plist is destroyed in the process of constructing the alist. | |
1171 See also `plist-to-alist'." | |
1172 (let ((head plist) | |
1173 next) | |
1174 (while plist | |
1175 ;; remember the next plist pair. | |
1176 (setq next (cddr plist)) | |
1177 ;; make the cons holding the property value into the alist element. | |
1178 (setcdr (cdr plist) (cadr plist)) | |
1179 (setcar (cdr plist) (car plist)) | |
1180 ;; reattach into alist form. | |
1181 (setcar plist (cdr plist)) | |
1182 (setcdr plist next) | |
1183 (setq plist next)) | |
1184 head)) | |
1185 | |
1186 (defun alist-to-plist (alist) | |
1187 "Convert association list ALIST into the equivalent property-list form. | |
1188 The plist is returned. This converts from | |
1189 | |
1190 \((a . 1) (b . 2) (c . 3)) | |
1191 | |
1192 into | |
1193 | |
1194 \(a 1 b 2 c 3) | |
1195 | |
1196 The original alist is not modified. See also `destructive-alist-to-plist'." | |
1197 (let (plist) | |
1198 (while alist | |
1199 (let ((el (car alist))) | |
1200 (setq plist (cons (cdr el) (cons (car el) plist)))) | |
1201 (setq alist (cdr alist))) | |
1202 (nreverse plist))) | |
1203 | |
1204 ;; getf, remf in cl*.el. | |
1205 | |
444 | 1206 (defmacro putf (plist property value) |
1207 "Add property PROPERTY to plist PLIST with value VALUE. | |
1208 Analogous to (setq PLIST (plist-put PLIST PROPERTY VALUE))." | |
1209 `(setq ,plist (plist-put ,plist ,property ,value))) | |
428 | 1210 |
444 | 1211 (defmacro laxputf (lax-plist property value) |
1212 "Add property PROPERTY to lax plist LAX-PLIST with value VALUE. | |
1213 Analogous to (setq LAX-PLIST (lax-plist-put LAX-PLIST PROPERTY VALUE))." | |
1214 `(setq ,lax-plist (lax-plist-put ,lax-plist ,property ,value))) | |
428 | 1215 |
444 | 1216 (defmacro laxremf (lax-plist property) |
1217 "Remove property PROPERTY from lax plist LAX-PLIST. | |
1218 Analogous to (setq LAX-PLIST (lax-plist-remprop LAX-PLIST PROPERTY))." | |
1219 `(setq ,lax-plist (lax-plist-remprop ,lax-plist ,property))) | |
428 | 1220 |
1221 ;;; Error functions | |
1222 | |
442 | 1223 (defun error (datum &rest args) |
1224 "Signal a non-continuable error. | |
1225 DATUM should normally be an error symbol, i.e. a symbol defined using | |
1226 `define-error'. ARGS will be made into a list, and DATUM and ARGS passed | |
1227 as the two arguments to `signal', the most basic error handling function. | |
1228 | |
428 | 1229 This error is not continuable: you cannot continue execution after the |
442 | 1230 error using the debugger `r' command. See also `cerror'. |
1231 | |
1232 The correct semantics of ARGS varies from error to error, but for most | |
1233 errors that need to be generated in Lisp code, the first argument | |
1234 should be a string describing the *context* of the error (i.e. the | |
1235 exact operation being performed and what went wrong), and the remaining | |
1236 arguments or \"frobs\" (most often, there is one) specify the | |
1237 offending object(s) and/or provide additional details such as the exact | |
1238 error when a file error occurred, e.g.: | |
1239 | |
1240 -- the buffer in which an editing error occurred. | |
1241 -- an invalid value that was encountered. (In such cases, the string | |
1242 should describe the purpose or \"semantics\" of the value [e.g. if the | |
1243 value is an argument to a function, the name of the argument; if the value | |
1244 is the value corresponding to a keyword, the name of the keyword; if the | |
1245 value is supposed to be a list length, say this and say what the purpose | |
1246 of the list is; etc.] as well as specifying why the value is invalid, if | |
1247 that's not self-evident.) | |
1248 -- the file in which an error occurred. (In such cases, there should be a | |
1249 second frob, probably a string, specifying the exact error that occurred. | |
1250 This does not occur in the string that precedes the first frob, because | |
1251 that frob describes the exact operation that was happening. | |
1252 | |
1253 For historical compatibility, DATUM can also be a string. In this case, | |
1254 DATUM and ARGS are passed together as the arguments to `format', and then | |
1255 an error is signalled using the error symbol `error' and formatted string. | |
1256 Although this usage of `error' is very common, it is deprecated because it | |
1257 totally defeats the purpose of having structured errors. There is now | |
1258 a rich set of defined errors you can use: | |
1259 | |
563 | 1260 quit |
1261 | |
442 | 1262 error |
1263 invalid-argument | |
563 | 1264 syntax-error |
1265 invalid-read-syntax | |
1266 invalid-regexp | |
1267 structure-formation-error | |
1268 list-formation-error | |
1269 malformed-list | |
1270 malformed-property-list | |
1271 circular-list | |
1272 circular-property-list | |
1273 invalid-function | |
1274 no-catch | |
1275 undefined-keystroke-sequence | |
1276 invalid-constant | |
442 | 1277 wrong-type-argument |
1278 args-out-of-range | |
1279 wrong-number-of-arguments | |
428 | 1280 |
442 | 1281 invalid-state |
1282 void-function | |
1283 cyclic-function-indirection | |
1284 void-variable | |
1285 cyclic-variable-indirection | |
509 | 1286 invalid-byte-code |
563 | 1287 stack-overflow |
1288 out-of-memory | |
1289 invalid-key-binding | |
1290 internal-error | |
442 | 1291 |
1292 invalid-operation | |
1293 invalid-change | |
1294 setting-constant | |
563 | 1295 protected-field |
442 | 1296 editing-error |
1297 beginning-of-buffer | |
1298 end-of-buffer | |
1299 buffer-read-only | |
1300 io-error | |
509 | 1301 file-error |
1302 file-already-exists | |
1303 file-locked | |
1304 file-supersession | |
563 | 1305 end-of-file |
1306 process-error | |
1307 network-error | |
509 | 1308 tooltalk-error |
563 | 1309 gui-error |
1310 dialog-box-error | |
1311 sound-error | |
1312 conversion-error | |
1313 text-conversion-error | |
1314 image-conversion-error | |
1315 base64-conversion-error | |
1316 selection-conversion-error | |
442 | 1317 arith-error |
1318 range-error | |
1319 domain-error | |
1320 singularity-error | |
1321 overflow-error | |
1322 underflow-error | |
509 | 1323 search-failed |
563 | 1324 printing-unreadable-object |
1325 unimplemented | |
509 | 1326 |
563 | 1327 Note the semantic differences between some of the more common errors: |
442 | 1328 |
563 | 1329 -- `invalid-argument' is for all cases where a bad value is encountered. |
1330 -- `invalid-constant' is for arguments where only a specific set of values | |
1331 is allowed. | |
1332 -- `syntax-error' is when complex structures (parsed strings, lists, | |
1333 and the like) are badly formed. If the problem is just a single bad | |
1334 value inside the structure, you should probably be using something else, | |
1335 e.g. `invalid-constant', `wrong-type-argument', or `invalid-argument'. | |
442 | 1336 -- `invalid-state' means that some settings have been changed in such a way |
1337 that their current state is unallowable. More and more, code is being | |
1338 written more carefully, and catches the error when the settings are being | |
1339 changed, rather than afterwards. This leads us to the next error: | |
1340 -- `invalid-change' means that an attempt is being made to change some settings | |
1341 into an invalid state. `invalid-change' is a type of `invalid-operation'. | |
1342 -- `invalid-operation' refers to all cases where code is trying to do something | |
563 | 1343 that's disallowed, or when an error occurred during an operation. (These |
1344 two concepts are merged because there's no clear distinction between them.) | |
1345 -- `io-error' refers to errors involving interaction with any external | |
1346 components (files, other programs, the operating system, etc). | |
442 | 1347 |
1348 See also `cerror', `signal', and `signal-error'." | |
1349 (while t (apply | |
1350 'cerror datum args))) | |
1351 | |
1352 (defun cerror (datum &rest args) | |
428 | 1353 "Like `error' but signals a continuable error." |
442 | 1354 (cond ((stringp datum) |
1355 (signal 'error (list (apply 'format datum args)))) | |
1356 ((defined-error-p datum) | |
1357 (signal datum args)) | |
1358 (t | |
1359 (error 'invalid-argument "datum not string or error symbol" datum)))) | |
428 | 1360 |
1361 (defmacro check-argument-type (predicate argument) | |
1362 "Check that ARGUMENT satisfies PREDICATE. | |
442 | 1363 This is a macro, and ARGUMENT is not evaluated. If ARGUMENT is an lvalue, |
1364 this function signals a continuable `wrong-type-argument' error until the | |
1365 returned value satisfies PREDICATE, and assigns the returned value | |
1366 to ARGUMENT. Otherwise, this function signals a non-continuable | |
1367 `wrong-type-argument' error if the returned value does not satisfy PREDICATE." | |
1368 (if (symbolp argument) | |
1369 `(if (not (,(eval predicate) ,argument)) | |
1370 (setq ,argument | |
1371 (wrong-type-argument ,predicate ,argument))) | |
1372 `(if (not (,(eval predicate) ,argument)) | |
1373 (signal-error 'wrong-type-argument (list ,predicate ,argument))))) | |
428 | 1374 |
872 | 1375 (defun args-out-of-range (value min max) |
1376 "Signal an error until the correct in-range value is given by the user. | |
1377 This function loops, signalling a continuable `args-out-of-range' error | |
1378 with VALUE, MIN and MAX as the data associated with the error and then | |
1379 checking the returned value to make sure it's not outside the given | |
1380 boundaries \(nil for either means no boundary on that side). At that | |
1381 point, the gotten value is returned." | |
1382 (loop | |
1383 for newval = (signal 'args-out-of-range (list value min max)) | |
1384 do (setq value newval) | |
1385 finally return value | |
1386 while (not (argument-in-range-p value min max)))) | |
1387 | |
1388 (defun argument-in-range-p (argument min max) | |
1389 "Return true if ARGUMENT is within the range of [MIN, MAX]. | |
1390 This includes boundaries. nil for either value means no limit on that side." | |
1391 (and (or (not min) (<= min argument)) | |
1392 (or (not max) (<= argument max)))) | |
1393 | |
1394 (defmacro check-argument-range (argument min max) | |
1395 "Check that ARGUMENT is within the range [MIN, MAX]. | |
1396 This is a macro, and ARGUMENT is not evaluated. If ARGUMENT is an lvalue, | |
1397 this function signals a continuable `args-out-of-range' error until the | |
1398 returned value is within range, and assigns the returned value | |
1399 to ARGUMENT. Otherwise, this function signals a non-continuable | |
1400 `args-out-of-range' error if the returned value is out of range." | |
1401 (if (symbolp argument) | |
1402 `(if (not (argument-in-range-p ,argument ,min ,max)) | |
924 | 1403 (setq ,argument |
1404 (args-out-of-range ,argument ,min ,max))) | |
872 | 1405 (let ((newsym (gensym))) |
1406 `(let ((,newsym ,argument)) | |
924 | 1407 (if (not (argument-in-range-p ,newsym ,min ,max)) |
4103 | 1408 (signal-error 'args-out-of-range (list ,newsym ,min ,max))))))) |
872 | 1409 |
428 | 1410 (defun signal-error (error-symbol data) |
1411 "Signal a non-continuable error. Args are ERROR-SYMBOL, and associated DATA. | |
1412 An error symbol is a symbol defined using `define-error'. | |
1413 DATA should be a list. Its elements are printed as part of the error message. | |
1414 If the signal is handled, DATA is made available to the handler. | |
1415 See also `signal', and the functions to handle errors: `condition-case' | |
1416 and `call-with-condition-handler'." | |
1417 (while t | |
1418 (signal error-symbol data))) | |
1419 | |
1420 (defun define-error (error-sym doc-string &optional inherits-from) | |
1421 "Define a new error, denoted by ERROR-SYM. | |
1422 DOC-STRING is an informative message explaining the error, and will be | |
1423 printed out when an unhandled error occurs. | |
1424 ERROR-SYM is a sub-error of INHERITS-FROM (which defaults to `error'). | |
1425 | |
1426 \[`define-error' internally works by putting on ERROR-SYM an `error-message' | |
1427 property whose value is DOC-STRING, and an `error-conditions' property | |
1428 that is a list of ERROR-SYM followed by each of its super-errors, up | |
1429 to and including `error'. You will sometimes see code that sets this up | |
1430 directly rather than calling `define-error', but you should *not* do this | |
1431 yourself.]" | |
1432 (check-argument-type 'symbolp error-sym) | |
1433 (check-argument-type 'stringp doc-string) | |
1434 (put error-sym 'error-message doc-string) | |
1435 (or inherits-from (setq inherits-from 'error)) | |
1436 (let ((conds (get inherits-from 'error-conditions))) | |
1437 (or conds (signal-error 'error (list "Not an error symbol" error-sym))) | |
1438 (put error-sym 'error-conditions (cons error-sym conds)))) | |
1439 | |
442 | 1440 (defun defined-error-p (sym) |
1441 "Returns non-nil if SYM names a currently-defined error." | |
1442 (and (symbolp sym) (not (null (get sym 'error-conditions))))) | |
1443 | |
793 | 1444 (defun backtrace-in-condition-handler-eliminating-handler (handler-arg-name) |
1445 "Return a backtrace inside of a condition handler, eliminating the handler. | |
1446 This is for use in the condition handler inside of call-with-condition-handler, | |
1447 when written like this: | |
1448 | |
1449 \(call-with-condition-handler | |
1450 #'(lambda (__some_weird_arg__) | |
1451 do the handling ...) | |
1452 #'(lambda () | |
1453 do the stuff that might cause an error)) | |
1454 | |
1455 Pass in the name (a symbol) of the argument used in the lambda function | |
1456 that specifies the handler, and make sure the argument name is unique, and | |
1457 this function generates a backtrace and strips off the part above where the | |
1458 error occurred (i.e. the handler itself)." | |
1459 (let* ((bt (with-output-to-string (backtrace nil t))) | |
1460 (bt (save-match-data | |
1461 ;; Try to eliminate the part of the backtrace | |
1462 ;; above where the error occurred. | |
1463 (if (string-match | |
1464 (concat "bind (\\(?:.* \\)?" (symbol-name handler-arg-name) | |
1465 "\\(?:.* \\)?)[ \t\n]*\\(?:(lambda \\|#<compiled-function \\)(" | |
1466 (symbol-name handler-arg-name) | |
1467 ").*\n\\(\\(?:.\\|\n\\)*\\)$") | |
1468 bt) (match-string 1 bt) bt)))) | |
1469 bt)) | |
1470 | |
1471 (put 'with-trapping-errors 'lisp-indent-function 0) | |
1472 (defmacro with-trapping-errors (&rest keys-body) | |
1473 "Trap errors in BODY, outputting a warning and a backtrace. | |
1474 Usage looks like | |
1475 | |
1476 \(with-trapping-errors | |
1477 [:operation OPERATION] | |
1478 [:error-form ERROR-FORM] | |
1479 [:no-backtrace NO-BACKTRACE] | |
1480 [:class CLASS] | |
1481 [:level LEVEL] | |
1482 [:resignal RESIGNAL] | |
1483 BODY) | |
1484 | |
1485 Return value without error is whatever BODY returns. With error, return | |
1486 result of ERROR-FORM (which will be evaluated only when the error actually | |
1487 occurs), which defaults to nil. OPERATION is given in the warning message. | |
1488 CLASS and LEVEL are the warning class and level (default to class | |
1489 `general', level `warning'). If NO-BACKTRACE is given, no backtrace is | |
1490 displayed. If RESIGNAL is given, the error is resignaled after the warning | |
1491 is displayed and the ERROR-FORM is executed." | |
1492 (let ((operation "unknown") | |
1493 (error-form nil) | |
1494 (no-backtrace nil) | |
1495 (class ''general) | |
1496 (level ''warning) | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1497 (resignal nil) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1498 (cte-cc-var '#:cte-cc-var) |
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1499 (call-trapping-errors-arg '#:call-trapping-errors-Ldc9FC5Hr)) |
793 | 1500 (let* ((keys '(operation error-form no-backtrace class level resignal)) |
1501 (keys-with-colon | |
1502 (mapcar #'(lambda (sym) | |
1503 (intern (concat ":" (symbol-name sym)))) keys))) | |
1504 (while (memq (car keys-body) keys-with-colon) | |
1505 (let* ((key-with-colon (pop keys-body)) | |
1506 (key (intern (substring (symbol-name key-with-colon) 1)))) | |
1507 (set key (pop keys-body))))) | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1508 `(condition-case ,(if resignal cte-cc-var nil) |
793 | 1509 (call-with-condition-handler |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1510 #'(lambda (,call-trapping-errors-arg) |
793 | 1511 (let ((errstr (error-message-string |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1512 ,call-trapping-errors-arg))) |
793 | 1513 ,(if no-backtrace |
1514 `(lwarn ,class ,level | |
1515 (if (warning-level-< | |
1516 ,level | |
1517 display-warning-minimum-level) | |
1518 "Error in %s: %s" | |
1519 "Error in %s:\n%s\n") | |
1520 ,operation errstr) | |
1521 `(lwarn ,class ,level | |
1522 "Error in %s: %s\n\nBacktrace follows:\n\n%s" | |
1523 ,operation errstr | |
1524 (backtrace-in-condition-handler-eliminating-handler | |
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4575
diff
changeset
|
1525 ',call-trapping-errors-arg))))) |
793 | 1526 #'(lambda () |
1527 (progn ,@keys-body))) | |
1528 (error | |
1529 ,error-form | |
4817
0142cb4d1049
Fix a bug I introduced in #'with-trapping-errors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
1530 ,@(if resignal `((signal (car ,cte-cc-var) (cdr ,cte-cc-var))))) |
793 | 1531 ))) |
1532 | |
428 | 1533 ;;;; Miscellanea. |
1534 | |
1535 ;; This is now in C. | |
444 | 1536 ;(defun buffer-substring-no-properties (start end) |
1537 ; "Return the text from START to END, without text properties, as a string." | |
1538 ; (let ((string (buffer-substring start end))) | |
428 | 1539 ; (set-text-properties 0 (length string) nil string) |
1540 ; string)) | |
1541 | |
1542 (defun get-buffer-window-list (&optional buffer minibuf frame) | |
1543 "Return windows currently displaying BUFFER, or nil if none. | |
1544 BUFFER defaults to the current buffer. | |
1545 See `walk-windows' for the meaning of MINIBUF and FRAME." | |
1546 (cond ((null buffer) | |
1547 (setq buffer (current-buffer))) | |
1548 ((not (bufferp buffer)) | |
1549 (setq buffer (get-buffer buffer)))) | |
1550 (let (windows) | |
1551 (walk-windows (lambda (window) | |
1552 (if (eq (window-buffer window) buffer) | |
1553 (push window windows))) | |
1554 minibuf frame) | |
1555 windows)) | |
1556 | |
1557 (defun ignore (&rest ignore) | |
1558 "Do nothing and return nil. | |
1559 This function accepts any number of arguments, but ignores them." | |
1560 (interactive) | |
1561 nil) | |
1562 | |
883 | 1563 ;; defined in lisp/bindings.el in GNU Emacs. |
1564 (defmacro bound-and-true-p (var) | |
1565 "Return the value of symbol VAR if it is bound, else nil." | |
1566 `(and (boundp (quote ,var)) ,var)) | |
1567 | |
1568 ;; `propertize' is a builtin in GNU Emacs 21. | |
1569 (defun propertize (string &rest properties) | |
1570 "Return a copy of STRING with text properties added. | |
1571 First argument is the string to copy. | |
1572 Remaining arguments form a sequence of PROPERTY VALUE pairs for text | |
1573 properties to add to the result." | |
1574 (let ((str (copy-sequence string))) | |
1575 (add-text-properties 0 (length str) | |
1576 properties | |
1577 str) | |
1578 str)) | |
1579 | |
1580 ;; `delete-and-extract-region' is a builtin in GNU Emacs 21. | |
1581 (defun delete-and-extract-region (start end) | |
1582 "Delete the text between START and END and return it." | |
1583 (let ((region (buffer-substring start end))) | |
1584 (delete-region start end) | |
1585 region)) | |
1586 | |
428 | 1587 (define-function 'eval-in-buffer 'with-current-buffer) |
1588 (make-obsolete 'eval-in-buffer 'with-current-buffer) | |
1589 | |
1590 ;;; `functionp' has been moved into C. | |
1591 | |
1592 ;;(defun functionp (object) | |
1593 ;; "Non-nil if OBJECT can be called as a function." | |
1594 ;; (or (and (symbolp object) (fboundp object)) | |
1595 ;; (subrp object) | |
1596 ;; (compiled-function-p object) | |
1597 ;; (eq (car-safe object) 'lambda))) | |
1598 | |
1599 (defun function-interactive (function) | |
1600 "Return the interactive specification of FUNCTION. | |
1601 FUNCTION can be any funcallable object. | |
1602 The specification will be returned as the list of the symbol `interactive' | |
1603 and the specs. | |
1604 If FUNCTION is not interactive, nil will be returned." | |
1605 (setq function (indirect-function function)) | |
1606 (cond ((compiled-function-p function) | |
1607 (compiled-function-interactive function)) | |
1608 ((subrp function) | |
1609 (subr-interactive function)) | |
1610 ((eq (car-safe function) 'lambda) | |
1611 (let ((spec (if (stringp (nth 2 function)) | |
1612 (nth 3 function) | |
1613 (nth 2 function)))) | |
1614 (and (eq (car-safe spec) 'interactive) | |
1615 spec))) | |
1616 (t | |
1617 (error "Non-funcallable object: %s" function)))) | |
1618 | |
442 | 1619 (defun function-allows-args (function n) |
1620 "Return whether FUNCTION can be called with N arguments." | |
1621 (and (<= (function-min-args function) n) | |
1622 (or (null (function-max-args function)) | |
1623 (<= n (function-max-args function))))) | |
1624 | |
428 | 1625 ;; This function used to be an alias to `buffer-substring', except |
1626 ;; that FSF Emacs 20.4 added a BUFFER argument in an incompatible way. | |
1627 ;; The new FSF's semantics makes more sense, but we try to support | |
1628 ;; both for backward compatibility. | |
1629 (defun buffer-string (&optional buffer old-end old-buffer) | |
1630 "Return the contents of the current buffer as a string. | |
1631 If narrowing is in effect, this function returns only the visible part | |
1632 of the buffer. | |
1633 | |
1634 If BUFFER is specified, the contents of that buffer are returned. | |
1635 | |
1636 The arguments OLD-END and OLD-BUFFER are supported for backward | |
1637 compatibility with pre-21.2 XEmacsen times when arguments to this | |
1638 function were (buffer-string &optional START END BUFFER)." | |
1639 (cond | |
1640 ((or (stringp buffer) (bufferp buffer)) | |
1641 ;; Most definitely the new way. | |
1642 (buffer-substring nil nil buffer)) | |
1643 ((or (stringp old-buffer) (bufferp old-buffer) | |
1644 (natnump buffer) (natnump old-end)) | |
1645 ;; Definitely the old way. | |
1646 (buffer-substring buffer old-end old-buffer)) | |
1647 (t | |
1648 ;; Probably the old way. | |
1649 (buffer-substring buffer old-end old-buffer)))) | |
1650 | |
1333 | 1651 ;; BEGIN SYNC WITH FSF 21.2 |
1652 | |
428 | 1653 ;; This was not present before. I think Jamie had some objections |
1654 ;; to this, so I'm leaving this undefined for now. --ben | |
1655 | |
1656 ;;; The objection is this: there is more than one way to load the same file. | |
1657 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different | |
1658 ;;; ways to load the exact same code. `eval-after-load' is too stupid to | |
1659 ;;; deal with this sort of thing. If this sort of feature is desired, then | |
1660 ;;; it should work off of a hook on `provide'. Features are unique and | |
1661 ;;; the arguments to (load) are not. --Stig | |
1662 | |
1663 ;; We provide this for FSFmacs compatibility, at least until we devise | |
1664 ;; something better. | |
1665 | |
1666 ;;;; Specifying things to do after certain files are loaded. | |
1667 | |
1668 (defun eval-after-load (file form) | |
1669 "Arrange that, if FILE is ever loaded, FORM will be run at that time. | |
1670 This makes or adds to an entry on `after-load-alist'. | |
1671 If FILE is already loaded, evaluate FORM right now. | |
1672 It does nothing if FORM is already on the list for FILE. | |
1333 | 1673 FILE must match exactly. Normally FILE is the name of a library, |
1674 with no directory or extension specified, since that is how `load' | |
1675 is normally called." | |
1676 ;; Make sure `load-history' contains the files dumped with Emacs | |
1677 ;; for the case that FILE is one of the files dumped with Emacs. | |
1678 (if-fboundp 'load-symbol-file-load-history | |
1679 (load-symbol-file-load-history)) | |
428 | 1680 ;; Make sure there is an element for FILE. |
1681 (or (assoc file after-load-alist) | |
1682 (setq after-load-alist (cons (list file) after-load-alist))) | |
1683 ;; Add FORM to the element if it isn't there. | |
1684 (let ((elt (assoc file after-load-alist))) | |
1685 (or (member form (cdr elt)) | |
1686 (progn | |
1687 (nconc elt (list form)) | |
1688 ;; If the file has been loaded already, run FORM right away. | |
1689 (and (assoc file load-history) | |
1690 (eval form))))) | |
1691 form) | |
1692 (make-compatible 'eval-after-load "") | |
1693 | |
1694 (defun eval-next-after-load (file) | |
1695 "Read the following input sexp, and run it whenever FILE is loaded. | |
1696 This makes or adds to an entry on `after-load-alist'. | |
1697 FILE should be the name of a library, with no directory name." | |
1698 (eval-after-load file (read))) | |
1699 (make-compatible 'eval-next-after-load "") | |
1700 | |
1333 | 1701 ;; END SYNC WITH FSF 21.2 |
428 | 1702 |
3000 | 1703 ;; BEGIN SYNC WITH FSF 22.0.50.1 (CVS) |
1704 (defun delete-dups (list) | |
1705 "Destructively remove `equal' duplicates from LIST. | |
1706 Store the result in LIST and return it. LIST must be a proper list. | |
1707 Of several `equal' occurrences of an element in LIST, the first | |
1708 one is kept." | |
1709 (let ((tail list)) | |
1710 (while tail | |
1711 (setcdr tail (delete (car tail) (cdr tail))) | |
1712 (setq tail (cdr tail)))) | |
1713 list) | |
1714 | |
1715 ;; END SYNC WITH FSF 22.0.50.1 (CVS) | |
1716 | |
2525 | 1717 ;; (defun shell-quote-argument (argument) in process.el. |
1718 | |
1719 ;; (defun make-syntax-table (&optional oldtable) in syntax.el. | |
1720 | |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1721 ;; (defun syntax-after (pos) in syntax.el. |
2525 | 1722 |
1723 ;; global-set-key, local-set-key, global-unset-key, local-unset-key in | |
1724 ;; keymap.el. | |
1725 | |
1726 ;; frame-configuration-p is in frame.el. | |
1727 | |
1728 ;; functionp is built-in. | |
1729 | |
1730 ;; interactive-form in obsolete.el. | |
1731 | |
1732 ;; assq-del-all in obsolete.el. | |
1733 | |
4266 | 1734 ;; make-temp-file in files.el. |
2525 | 1735 |
1736 ;; add-minor-mode in modeline.el. | |
1737 | |
1738 ;; text-clone stuff #### doesn't exist; should go in text-props.el and | |
1739 ;; requires changes to extents.c (modification hooks). | |
1740 | |
1741 ;; play-sound is built-in. | |
1742 | |
1743 ;; define-mail-user-agent is in simple.el. | |
1744 | |
4501
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1745 ;; XEmacs; added. |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1746 (defun skip-chars-quote (string) |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1747 "Return a string that means all characters in STRING will be skipped, |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1748 if passed to `skip-chars-forward' or `skip-chars-backward'. |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1749 |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1750 Ranges and carets are not treated specially. This implementation is |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1751 in Lisp; do not use it in performance-critical code." |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1752 (let ((list (delete-duplicates (string-to-list string) :test #'=))) |
5366
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5338
diff
changeset
|
1753 (when (not (eql 1 (length list))) ;; No quoting needed in a string of |
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5338
diff
changeset
|
1754 ;; length 1. |
f00192e1cd49
Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents:
5338
diff
changeset
|
1755 (when (eql ?^ (car list)) |
4504
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1756 (setq list (nconc (cdr list) '(?^)))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1757 (when (memq ?\\ list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1758 (setq list (delq ?\\ list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1759 list (nconc (list ?\\ ?\\) list))) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1760 (when (memq ?- list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1761 (setq list (delq ?- list) |
b82fdf7305ee
Correct the implementation, add a few basic tests for #'skip-chars-quote.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4501
diff
changeset
|
1762 list (nconc list '(?\\ ?-))))) |
4501
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1763 (apply #'string list))) |
c4fd85dd95bd
Add #'skip-chars-quote to subr.el
Aidan Kehoe <kehoea@parhasard.net>
parents:
4463
diff
changeset
|
1764 |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1765 ;; XEmacs addition to subr.el; docstring and API taken initially from GNU's |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1766 ;; data.c, revision 1.275, GPLv2. |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1767 (defun subr-arity (subr) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1768 "Return minimum and maximum number of args allowed for SUBR. |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1769 SUBR must be a built-in function (not just a symbol that refers to one). |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1770 The returned value is a pair (MIN . MAX). MIN is the minimum number |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1771 of args. MAX is the maximum number or the symbol `many', for a |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
1772 function with `&rest' args, or `unevalled' for a special operator. |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1773 |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
1774 See also `special-operator-p', `subr-min-args', `subr-max-args', |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1775 `function-allows-args'. " |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1776 (check-argument-type #'subrp subr) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1777 (cons (subr-min-args subr) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1778 (cond |
4905
755ae5b97edb
Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4817
diff
changeset
|
1779 ((special-operator-p subr) |
4575
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1780 'unevalled) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1781 ((null (subr-max-args subr)) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1782 'many) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1783 (t (subr-max-args subr))))) |
eecd28508f4a
Add #'subr-arity, API taken from GNU, implementation our own.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4516
diff
changeset
|
1784 |
5004
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1785 ;; XEmacs; move these here from C. Would be nice to drop them entirely, but |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1786 ;; they're used reasonably often, since they've been around for a long time |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1787 ;; and they're portable to GNU. |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1788 |
5182
2e528066e2fc
Move #'sort*, #'fill, #'merge to C from cl-seq.el.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5089
diff
changeset
|
1789 ;; No longer used in C, now list_merge() accepts a KEY argument. |
5004
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1790 (defun car-less-than-car (a b) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1791 "Return t if the car of A is numerically less than the car of B." |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1792 (< (car a) (car b))) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1793 |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1794 ;; Used in packages. |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1795 (defun cdr-less-than-cdr (a b) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1796 "Return t if (cdr A) is numerically less than (cdr B)." |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1797 (< (cdr a) (cdr b))) |
788c38f20376
Do not assume #'format-decode exists in fileio.c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4905
diff
changeset
|
1798 |
5220
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1799 ;; XEmacs; this is in editfns.c in GNU. |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1800 (defun float-time (&optional specified-time) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1801 "Convert time value SPECIFIED-TIME to a floating point number. |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1802 |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1803 See `current-time'. Since the result is a floating-point number, this may |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1804 not have the same accuracy as does the result of `current-time'. |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1805 |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1806 If not supplied, SPECIFIED-TIME defaults to the result of `current-time'." |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1807 (or specified-time (setq specified-time (current-time))) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1808 (+ (* (pop specified-time) (+ #x10000 0.0)) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1809 (if (consp specified-time) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1810 (pop specified-time) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1811 (prog1 |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1812 specified-time |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1813 (setq specified-time nil))) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1814 (or (and specified-time |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1815 (/ (car specified-time) 1000000.0)) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1816 0.0))) |
2157ecaedc1d
Add `float-time', implemented in Lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5182
diff
changeset
|
1817 |
428 | 1818 ;;; subr.el ends here |