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