annotate lisp/subr.el @ 5631:5e256f495401

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