annotate lisp/subr.el @ 1333:1b0339b048ce

[xemacs-hg @ 2003-03-02 09:38:37 by ben] To: xemacs-patches@xemacs.org PROBLEMS: Include nt/PROBLEMS and update. Add note about incremental linking badness. cmdloop.el, custom.el, dumped-lisp.el, files.el, keydefs.el, keymap.el, lisp-mode.el, make-docfile.el, replace.el, simple.el, subr.el, view-less.el, wid-edit.el: Lots of syncing with FSF 21.2. Use if-fboundp in wid-edit.el. New file newcomment.el from FSF. internals/internals.texi: Fix typo. (Build-Time Dependencies): New node. PROBLEMS: Delete. config.inc.samp, xemacs.mak: Eliminate HAVE_VC6, use SUPPORT_EDIT_AND_CONTINUE in its place. No incremental linking unless SUPPORT_EDIT_AND_CONTINUE, since it can cause nasty crashes in pdump. Put warnings about this in config.inc.samp. Report the full compile flags used for src and lib-src in the Installation output. alloc.c, lisp.h, ralloc.c, regex.c: Use ALLOCA() in regex.c to avoid excessive stack allocation. Also fix subtle problem with REL_ALLOC() -- any call to malloc() (direct or indirect) may relocate rel-alloced data, causing buffer text to shift. After any such call, regex must update all its pointers to such data. Add a system, when ERROR_CHECK_MALLOC, whereby regex.c indicates all the places it is prepared to handle malloc()/realloc()/free(), and any calls anywhere in XEmacs outside of this will trigger an abort. alloc.c, dialog-msw.c, eval.c, event-stream.c, general-slots.h, insdel.c, lisp.h, menubar-msw.c, menubar-x.c: Change *run_hook*_trapping_problems to take a warning class, not a string. Factor out code to issue warnings, add flag to call_trapping_problems() to postpone warning issue, and make *run_hook*_trapping_problems issue their own warnings tailored to the hook, postponed in the case of safe_run_hook_trapping_problems() so that the appropriate message can be issued about resetting to nil only when not `quit'. Make record_unwind_protect_restoring_int() non-static. dumper.c: Issue notes about incremental linking problems under Windows. fileio.c: Mule-ize encrypt/decrypt-string code. text.h: Spacing changes.
author ben
date Sun, 02 Mar 2003 09:38:54 +0000
parents 3a01f3148bff
children c9b6a2fec10d
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1992, 1994-5, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Copyright (C) 1995 Sun Microsystems.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
6 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; Keywords: extensions, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
28 ;;; 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
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; 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
35 ;; 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
36 ;; 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
37 ;; provide useful context diffs. -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
39 ;; BEGIN SYNCHED WITH FSF 21.2
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
40
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;;; Code:
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
42 (defvar custom-declare-variable-list nil
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
43 "Record `defcustom' calls made before `custom.el' is loaded to handle them.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
44 Each element of this list holds the arguments to one call to `defcustom'.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
46 ;; Use this, rather than defcustom, in subr.el and other files loaded
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
47 ;; before custom.el.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
48 (defun custom-declare-variable-early (&rest arguments)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
49 (setq custom-declare-variable-list
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
50 (cons arguments custom-declare-variable-list)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;;;; Lisp language features.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 (defmacro lambda (&rest cdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 "Return a lambda expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 self-quoting; the result of evaluating the lambda expression is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 expression itself. The lambda expression may then be treated as a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 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
60 funcall or mapcar, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ARGS should take the same form as an argument list for a `defun'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 DOCSTRING is an optional documentation string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 If present, it should describe how to call the function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 But documentation strings are usually not useful in nameless functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 INTERACTIVE should be a call to the function `interactive', which see.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 It may also be omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 BODY should be a list of lisp expressions."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 `(function (lambda ,@cdr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
71 ;; 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
72 ;; 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
73
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
74 ;; More powerful versions in cl.el.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
75 ;(defmacro push (newelt listname)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
76 ;(defmacro pop (listname)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
77
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
78 ;; Built-in.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
79 ;(defmacro when (cond &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
80 ;(defmacro unless (cond &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
81
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
82 ;; More powerful versions in cl-macs.el.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
83 ;(defmacro dolist (spec &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
84 ;(defmacro dotimes (spec &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
85
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
86 ;; 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
87 ;(defsubst caar (x)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
88 ;(defsubst cadr (x)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
89 ;(defsubst cdar (x)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
90 ;(defsubst cddr (x)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
91
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
92 ;; 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
93 ;(defun last (x &optional n)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
94 ;(defun butlast (x &optional n)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
95 ;(defun nbutlast (x &optional n)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
96
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
97 ;; In cl-seq.el.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
98 ;(defun remove (elt seq)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
99 ;(defun remq (elt list)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
100
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (defmacro defun-when-void (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 "Define a function, just like `defun', unless it's already defined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 Used for compatibility among different emacs variants."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 `(if (fboundp ',(car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (defun ,@args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (defmacro define-function-when-void (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 "Define a function, just like `define-function', unless it's already defined.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 Used for compatibility among different emacs variants."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 `(if (fboundp ,(car args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (define-function ,@args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
116 (defun assoc-default (key alist &optional test default)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
117 "Find object KEY in a pseudo-alist ALIST.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
118 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
119 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
120 If that is non-nil, the element matches;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
121 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
122 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
123
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
124 If no element matches, the value is nil.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
125 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
126 (let (found (tail alist) value)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
127 (while (and tail (not found))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
128 (let ((elt (car tail)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
129 (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
130 (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
131 (setq tail (cdr tail)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
132 value))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
133
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
134 (defun assoc-ignore-case (key alist)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
135 "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
136 KEY must be a string. Upper-case and lower-case letters are treated as equal."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
137 (let (element)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
138 (while (and alist (not element))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
139 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil t))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
140 (setq element (car alist)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
141 (setq alist (cdr alist)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
142 element))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
143
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
144 (defun assoc-ignore-representation (key alist)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
145 "Like `assoc', but ignores differences in text representation.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
146 KEY must be a string."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
147 (let (element)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
148 (while (and alist (not element))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
149 (if (eq t (compare-strings key 0 nil (car (car alist)) 0 nil))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
150 (setq element (car alist)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
151 (setq alist (cdr alist)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
152 element))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
153
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
154 (defun member-ignore-case (elt list)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
155 "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
156 ELT must be a string. Upper-case and lower-case letters are treated as equal."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
157 (while (and list (not (eq t (compare-strings elt 0 nil (car list) 0 nil t))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
158 (setq list (cdr list)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
159 list)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
160
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
161
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 ;;;; Keymap support.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;; XEmacs: removed to keymap.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ;;;; The global keymap tree.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;;; 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
168 ;;; keymap.c; we just give them docstrings here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 ;;;; Event manipulation functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 ;; XEmacs: This stuff is done in C Code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
174 ;;;; Obsolescent names for functions generally appear elsewhere, in
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
175 ;;;; 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
176 ;;;; 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
177 ;;;; place of `point').
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
178
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
179 ; alternate names (not obsolete)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
180 (if (not (fboundp 'mod)) (define-function 'mod '%))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
181 (define-function 'move-marker 'set-marker)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
182 (define-function 'beep 'ding) ; preserve lingual purity
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
183 (define-function 'indent-to-column 'indent-to)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
184 (define-function 'backward-delete-char 'delete-backward-char)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
185 (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
186 (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
187 (define-function 'remove-directory 'delete-directory)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
188 (define-function 'set-match-data 'store-match-data)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
189 (define-function 'send-string-to-terminal 'external-debugging-output)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 ;; XEmacs:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (defun local-variable-if-set-p (sym buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 "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
194 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
195 can be used to determine whether `make-variable-buffer-local' has been
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 called on SYM."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (local-variable-p sym buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 ;;;; Hook manipulation functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 ;; (defconst run-hooks 'run-hooks ...)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (defun make-local-hook (hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 "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
206 The return value is HOOK.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
207
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
208 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
209 if its LOCAL argument is non-nil.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
210
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 When a hook is local, its local and global values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 work in concert: running the hook actually runs all the hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 functions listed in *either* the local value *or* the global value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 of the hook variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 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
217 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
218 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
219 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
220 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
221 one.
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 This function does nothing if HOOK is already local in the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
226 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
227 (if (local-variable-p hook (current-buffer)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (or (boundp hook) (set hook nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (make-local-variable hook)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
231 (set hook (list t)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
232 hook)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (defun add-hook (hook function &optional append local)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 "Add to the value of HOOK the function FUNCTION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 FUNCTION is not added if already present.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 FUNCTION is added (if necessary) at the beginning of the hook list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 unless the optional argument APPEND is non-nil, in which case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 FUNCTION is added at the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 The optional fourth argument, LOCAL, if non-nil, says to modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 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
243 This makes the hook buffer-local if needed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 To make a hook variable buffer-local, always use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 `make-local-hook', not `make-local-variable'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 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
248 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
249 function, it is changed to a list of functions.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
250
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
251 You can remove this hook yourself using `remove-hook'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
252
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
253 See also `add-one-shot-hook'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (or (boundp hook) (set hook nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (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
256 (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
257 (make-local-hook hook))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
258 ;; 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
259 ;; and do what we used to do.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
260 (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
261 (setq local t)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
262 (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
263 ;; 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
264 (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
265 (setq hook-value (list hook-value)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
266 ;; Do the actual addition if necessary
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
267 (unless (member function hook-value)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
268 (setq hook-value
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
269 (if append
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
270 (append hook-value (list function))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
271 (cons function hook-value))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
272 ;; Set the actual variable
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
273 (if local (set hook hook-value) (set-default hook hook-value))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (defun remove-hook (hook function &optional local)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 "Remove from the value of HOOK the function FUNCTION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 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
278 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
279 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
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 The optional third argument, LOCAL, if non-nil, says to modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 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
283 This makes the hook buffer-local if needed.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 To make a hook variable buffer-local, always use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 `make-local-hook', not `make-local-variable'."
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
286 (or (boundp hook) (set hook nil))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
287 (or (default-boundp hook) (set-default hook nil))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
288 (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
289 (make-local-hook hook))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
290 ;; 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
291 ;; and do what we used to do.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
292 (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
293 (setq local t)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
294 (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
295 ;; Remove the function, for both the list and the non-list cases.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
296 ;; XEmacs: add hook-test, for handling one-shot hooks.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
297 (flet ((hook-test
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
298 (fn hel)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
299 (or (equal fn hel)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
300 (and (symbolp hel)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
301 (equal fn
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
302 (get hel 'one-shot-hook-fun))))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
303 (if (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
304 (if (equal hook-value function) (setq hook-value nil))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
305 (setq hook-value (delete* function (copy-sequence hook-value)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
306 :test 'hook-test)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
307 ;; If the function is on the global hook, we need to shadow it locally
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
308 ;;(when (and local (member* function (default-value hook)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
309 ;; :test 'hook-test)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
310 ;; (not (member* (cons 'not function) hook-value
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
311 ;; :test 'hook-test)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
312 ;; (push (cons 'not function) hook-value))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
313 ;; Set the actual variable
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
314 (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
315
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
316 ;; XEmacs addition
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
317 ;; #### we need a coherent scheme for indicating compatibility info,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
318 ;; so that it can be programmatically retrieved.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
319 (defun add-local-hook (hook function &optional append)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
320 "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
321 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
322 argument to `add-hook'."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
323 (add-hook hook function append t))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
324
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
325 ;; XEmacs addition
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
326 (defun remove-local-hook (hook function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
327 "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
328 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
329 argument to `remove-hook'."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
330 (remove-hook hook function t))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
331
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
332 (defun add-one-shot-hook (hook function &optional append local)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
333 "Add to the value of HOOK the one-shot function FUNCTION.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
334 FUNCTION will automatically be removed from the hook the first time
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
335 after it runs (whether to completion or to an error).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
336 FUNCTION is not added if already present.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
337 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
338 unless the optional argument APPEND is non-nil, in which case
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
339 FUNCTION is added at the end.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
340
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
341 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
342 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
343 function, it is changed to a list of functions.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
344
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
345 You can remove this hook yourself using `remove-hook'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
346
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
347 See also `add-hook'."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
348 (let ((sym (gensym)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
349 (fset sym `(lambda (&rest args)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
350 (unwind-protect
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
351 (apply ',function args)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
352 (remove-hook ',hook ',sym ',local))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
353 (put sym 'one-shot-hook-fun function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
354 (add-hook hook sym append local)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
355
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
356 (defun add-local-one-shot-hook (hook function &optional append)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
357 "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
358 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
359 argument to `add-one-shot-hook'."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
360 (add-one-shot-hook hook function append t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361
878
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
362 (defun add-to-list (list-var element &optional append)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 The test for presence of ELEMENT is done with `equal'.
878
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
365 If ELEMENT is added, it is added at the beginning of the list,
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
366 unless the optional argument APPEND is non-nil, in which case
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
367 ELEMENT is added at the end.
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
368
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 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
370 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
371 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
372 `eval-after-load' provides one way to do this. In some cases
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 other hooks, such as major mode hooks, can do the job."
878
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
374 (if (member element (symbol-value list-var))
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
375 (symbol-value list-var)
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
376 (set list-var
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
377 (if append
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
378 (append (symbol-value list-var) (list element))
64f38afaab2d [xemacs-hg @ 2002-06-23 22:03:32 by youngs]
youngs
parents: 872
diff changeset
379 (cons element (symbol-value list-var))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
381 ;; END SYNCHED WITH FSF 21.2
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
382
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 ;; XEmacs additions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 ;; called by Fkill_buffer()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (defvar kill-buffer-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 "Function or functions to be called when a buffer is killed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 The value of this variable may be buffer-local.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 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
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 ;; in C in FSFmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (defvar kill-emacs-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 "Function or functions to be called when `kill-emacs' is called,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 just before emacs is actually killed.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 ;; not obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 ;; #### These are a bad idea, because the CL RPLACA and RPLACD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 ;; return the cons cell, not the new CAR/CDR. -hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 ;; The proper definition would be:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 ;; (defun rplaca (conscell newcar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 ;; (setcar conscell newcar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 ;; conscell)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 ;; ...and analogously for RPLACD.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (define-function 'rplaca 'setcar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (define-function 'rplacd 'setcdr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (defun copy-symbol (symbol &optional copy-properties)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 "Return a new uninterned symbol with the same name as SYMBOL.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 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
409 SYMBOL's value, function, and property lists."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (let ((new (make-symbol (symbol-name symbol))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (when copy-properties
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 ;; This will not copy SYMBOL's chain of forwarding objects, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 ;; I think that's OK. Callers should not expect such magic to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 ;; keep working in the copy in the first place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (and (boundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (set new (symbol-value symbol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (and (fboundp symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (fset new (symbol-function symbol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (setplist new (copy-list (symbol-plist symbol))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
422 (defun set-symbol-value-in-buffer (sym val buffer)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
423 "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
424 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
425 function allows you to set the local value.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
426
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
427 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
428 (with-current-buffer buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
429 (set sym val)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
430
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
431
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
432 ;; BEGIN SYNCHED WITH FSF 21.2
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
433
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
434 ;; #### #### #### AAaargh! Must be in C, because it is used insanely
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
435 ;; early in the bootstrap process.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
436 ;(defun split-path (path)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
437 ; "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
438 ;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
439 ;with `path-separator'."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
440 ; (while (or (not stringp path-separator)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
441 ; (/= (length path-separator) 1))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
442 ; (setq path-separator (signal 'error (list "\
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
443 ;`path-separator' should be set to a single-character string"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
444 ; path-separator))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
445 ; (split-string-by-char path (aref separator 0)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
446
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
447 (defmacro with-current-buffer (buffer &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
448 "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
449 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
450 See also `with-temp-buffer'."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
451 `(save-current-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
452 (set-buffer ,buffer)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
453 ,@body))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
454
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
455 (defmacro with-temp-file (filename &rest forms)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
456 "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
457 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
458 See also `with-temp-buffer'."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
459 (let ((temp-file (make-symbol "temp-file"))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
460 (temp-buffer (make-symbol "temp-buffer")))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
461 `(let ((,temp-file ,filename)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
462 (,temp-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
463 (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
464 (unwind-protect
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
465 (prog1
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
466 (with-current-buffer ,temp-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
467 ,@forms)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
468 (with-current-buffer ,temp-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
469 (widen)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
470 (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
471 (and (buffer-name ,temp-buffer)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
472 (kill-buffer ,temp-buffer))))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
473
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
474 ;; FSF compatibility
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
475 (defmacro with-temp-message (message &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
476 "Display MESSAGE temporarily while BODY is evaluated.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
477 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
478 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
479 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
480 Use a MESSAGE of \"\" to temporarily clear the echo area.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
482 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
483 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
484 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
485 with `clear-message'."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
486 ;; FSF additional doc string from 21.2:
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
487 ;; 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
488 (let ((current-message (make-symbol "current-message"))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
489 (temp-message (make-symbol "with-temp-message")))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
490 `(let ((,temp-message ,message)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
491 (,current-message))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
492 (unwind-protect
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
493 (progn
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
494 (when ,temp-message
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
495 (setq ,current-message (current-message))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
496 (message "%s" ,temp-message))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
497 ,@body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
498 (and ,temp-message ,current-message
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
499 (message "%s" ,current-message))))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
500
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
501 (defmacro with-temp-buffer (&rest forms)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
502 "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
503 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
504 (let ((temp-buffer (make-symbol "temp-buffer")))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
505 `(let ((,temp-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
506 (get-buffer-create (generate-new-buffer-name " *temp*"))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
507 (unwind-protect
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
508 (with-current-buffer ,temp-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
509 ,@forms)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
510 (and (buffer-name ,temp-buffer)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
511 (kill-buffer ,temp-buffer))))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
512
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
513 (defmacro with-output-to-string (&rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
514 "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
515 `(let ((standard-output
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
516 (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
517 (let ((standard-output standard-output))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
518 ,@body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
519 (with-current-buffer standard-output
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
520 (prog1
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
521 (buffer-string)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
522 (kill-buffer nil)))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
523
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
524 ;; FSF 21.2.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
525
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
526 ; (defmacro combine-after-change-calls (&rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
527 ; "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
528 ; 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
529 ; 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
530 ; when BODY is finished.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
531 ; 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
532
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
533 ; 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
534 ; 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
535
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
536 ; 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
537 ; in BODY."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
538 ; `(unwind-protect
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
539 ; (let ((combine-after-change-calls t))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
540 ; . ,body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
541 ; (combine-after-change-execute)))
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
542
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
543 (defmacro with-syntax-table (table &rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
544 "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
545 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
546 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
547 Value is what BODY returns."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
548 (let ((old-table (make-symbol "table"))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
549 (old-buffer (make-symbol "buffer")))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
550 `(let ((,old-table (syntax-table))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
551 (,old-buffer (current-buffer)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
552 (unwind-protect
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
553 (progn
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
554 (set-syntax-table (copy-syntax-table ,table))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
555 ,@body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
556 (save-current-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
557 (set-buffer ,old-buffer)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
558 (set-syntax-table ,old-table))))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
559
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
560 (put 'with-syntax-table 'lisp-indent-function 1)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
561 (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
562
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
563
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
564 ;; Moved from mule-coding.el.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
565 (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
566 "With the contents of the current buffer being STR, run BODY.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
567 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
568 The original current buffer is restored afterwards."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
569 `(with-temp-buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
570 (insert ,str)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
571 ,@body
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
572 (buffer-string)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
573
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 save-match-data (&rest body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
576 "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
577 (let ((original (make-symbol "match-data")))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
578 (list 'let (list (list original '(match-data)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
579 (list 'unwind-protect
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
580 (cons 'progn body)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
581 (list 'store-match-data original)))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
582
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
583
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
584 (defun match-string (num &optional string)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
585 "Return string of text matched by last search.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
586 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
587 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
588 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
589 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
590 (if (match-beginning num)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
591 (if string
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
592 (substring string (match-beginning num) (match-end num))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
593 (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
594
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
595 (defun match-string-no-properties (num &optional string)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
596 "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
597 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
598 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
599 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
600 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
601 (if (match-beginning num)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
602 (if string
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
603 (let ((result
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
604 (substring string (match-beginning num) (match-end num))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
605 (set-text-properties 0 (length result) nil result)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
606 result)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
607 (buffer-substring-no-properties (match-beginning num)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
608 (match-end num)))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
609
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
610 (defun split-string (string &optional separators)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
611 "Splits STRING into substrings where there are matches for SEPARATORS.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
612 Each match for SEPARATORS is a splitting point.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
613 The substrings between the splitting points are made into a list
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
614 which is returned.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
615 If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\".
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
616
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
617 If there is match for SEPARATORS at the beginning of STRING, we do not
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
618 include a null substring for that. Likewise, if there is a match
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
619 at the end of STRING, we don't include a null substring for that.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
620
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
621 Modifies the match data; use `save-match-data' if necessary."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
622 (let ((rexp (or separators "[ \f\t\n\r\v]+"))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
623 (start 0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
624 notfirst
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
625 (list nil))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
626 (while (and (string-match rexp string
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
627 (if (and notfirst
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
628 (= start (match-beginning 0))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
629 (< start (length string)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
630 (1+ start) start))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
631 (< (match-beginning 0) (length string)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
632 (setq notfirst t)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
633 (or (eq (match-beginning 0) 0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
634 (and (eq (match-beginning 0) (match-end 0))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
635 (eq (match-beginning 0) start))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
636 (setq list
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
637 (cons (substring string start (match-beginning 0))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
638 list)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
639 (setq start (match-end 0)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
640 (or (eq start (length string))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
641 (setq list
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
642 (cons (substring string start)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
643 list)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
644 (nreverse list)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
645
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
646 (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
647 "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
648 Unless optional argument INPLACE is non-nil, return a new string."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
649 (let ((i (length string))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
650 (newstr (if inplace string (copy-sequence string))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
651 (while (> i 0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
652 (setq i (1- i))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
653 (if (eq (aref newstr i) fromchar)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
654 (aset newstr i tochar)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
655 newstr))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
656
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
657
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
658 ;; XEmacs addition:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 (defun replace-in-string (str regexp newtext &optional literal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 "Replace all matches in STR for REGEXP with NEWTEXT string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 and returns the new string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 Optional LITERAL non-nil means do a literal replacement.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
663 Otherwise treat `\\' in NEWTEXT as special:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
664 `\\&' in NEWTEXT means substitute original matched text.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
665 `\\N' means substitute what matched the Nth `\\(...\\)'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
666 If Nth parens didn't match, substitute nothing.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
667 `\\\\' means insert one `\\'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
668 `\\u' means upcase the next character.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
669 `\\l' means downcase the next character.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
670 `\\U' means begin upcasing all following characters.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
671 `\\L' means begin downcasing all following characters.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
672 `\\E' means terminate the effect of any `\\U' or `\\L'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 (check-argument-type 'stringp str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (check-argument-type 'stringp newtext)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
675 (if (> (length str) 50)
924
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
676 (let ((cfs case-fold-search))
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
677 (with-temp-buffer
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
678 (setq case-fold-search cfs)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
679 (insert str)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
680 (goto-char 1)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
681 (while (re-search-forward regexp nil t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
682 (replace-match newtext t literal))
924
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
683 (buffer-string)))
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
684 (let ((start 0) newstr)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
685 (while (string-match regexp str start)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
686 (setq newstr (replace-match newtext t literal str)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
687 start (+ (match-end 0) (- (length newstr) (length str)))
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
688 str newstr))
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
689 str)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
691 (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
692 fixedcase literal subexp start)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
693 "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
694
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
695 Return a new string containing the replacements.
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 Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
698 arguments with the same names of function `replace-match'. If START
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
699 is non-nil, start replacements at that index in STRING.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
701 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
702 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
703 the replacement passed to `replace-match'; the match-data at this
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
704 point are such that match 0 is the function's argument.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
706 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
707 and replace a sub-expression, e.g.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
708 (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
709 => \" bar foo\"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
710 "
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
712 ;; 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
713 ;; 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
714 ;; 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
715 ;; 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
716 ;; matched interspersed with replacements for segments that were.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
717 ;; [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
718 ;; 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
719 ;; 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
720 ;; 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
721 (let ((l (length string))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
722 (start (or start 0))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
723 matches str mb me)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
724 (save-match-data
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
725 (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
726 (setq mb (match-beginning 0)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
727 me (match-end 0))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
728 ;; 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
729 (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
730 ;; Generate a replacement for the matched substring.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
731 ;; 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
732 ;; 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
733 ;; 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
734 ;; match data directly in Lisp.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
735 (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
736 (setq matches
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
737 (cons (replace-match (if (stringp rep)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
738 rep
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
739 (funcall rep (match-string 0 str)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
740 fixedcase literal str subexp)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
741 (cons (substring string start mb) ; unmatched prefix
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
742 matches)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
743 (setq start me))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
744 ;; Reconstruct a string from the pieces.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
745 (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
746 (apply #'concat (nreverse matches)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
748 ;; END SYNCHED WITH FSF 21.2
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
749
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
750
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
751 ;;; Basic string functions
883
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
752
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
753 ;; XEmacs
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
754 (defun string-equal-ignore-case (str1 str2)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
755 "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
756 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
757 Symbols are also allowed; their print names are used instead.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
759 See also `equalp'."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
760 (if (symbolp str1)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
761 (setq str1 (symbol-name str1)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
762 (if (symbolp str2)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
763 (setq str2 (symbol-name str2)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
764 (eq t (compare-strings str1 nil nil str2 nil nil t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (defun insert-face (string face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 "Insert STRING and highlight with FACE. Return the extent created."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (let ((p (point)) ext)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (insert string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (setq ext (make-extent p (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 (set-extent-face ext face)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 ext))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 ;; not obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 (define-function 'string= 'string-equal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (define-function 'string< 'string-lessp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 (define-function 'int-to-string 'number-to-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 (define-function 'string-to-int 'string-to-number)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 ;; 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
781 ;; foo-to-bar naming scheme, but CLtL2 has them, so they stay.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (define-function 'char-int 'char-to-int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (define-function 'int-char 'int-to-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
785 (defun string-width (string)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
786 "Return number of columns STRING occupies when displayed.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
787 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
788 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
789 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
790 simply returns the length of the string."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
791 (if (featurep 'mule)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
792 (let ((col 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
793 (len (length string))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
794 (i 0))
772
d682c0f82a71 [xemacs-hg @ 2002-03-13 10:00:06 by ben]
ben
parents: 771
diff changeset
795 (with-fboundp '(charset-width char-charset)
d682c0f82a71 [xemacs-hg @ 2002-03-13 10:00:06 by ben]
ben
parents: 771
diff changeset
796 (while (< i len)
d682c0f82a71 [xemacs-hg @ 2002-03-13 10:00:06 by ben]
ben
parents: 771
diff changeset
797 (setq col (+ col (charset-width (char-charset (aref string i)))))
d682c0f82a71 [xemacs-hg @ 2002-03-13 10:00:06 by ben]
ben
parents: 771
diff changeset
798 (setq i (1+ i))))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
799 col)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
800 (length string)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 563
diff changeset
801
777
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
802 (defun char-width (character)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
803 "Return number of columns a CHARACTER occupies when displayed."
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
804 (if (featurep 'mule)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
805 (with-fboundp '(charset-width char-charset)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
806 (charset-width (char-charset character)))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
807 1))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
808
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
809 ;; 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
810 ;; 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
811 ;; 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
812 ;; We provide them for compatibility reasons solely.
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
813
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
814 (defun string-to-sequence (string type)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
815 "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
816 TYPE should be `list' or `vector'."
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
817 (ecase type
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
818 (list
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
819 (mapcar #'identity string))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
820 (vector
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
821 (mapvector #'identity string))))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
822
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
823 (defun string-to-list (string)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
824 "Return a list of characters in STRING."
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
825 (mapcar #'identity string))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
826
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
827 (defun string-to-vector (string)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
828 "Return a vector of characters in STRING."
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
829 (mapvector #'identity string))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
830
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
831 (defun store-substring (string idx obj)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
832 "Embed OBJ (string or character) at index IDX of STRING."
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
833 (let* ((str (cond ((stringp obj) obj)
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
834 ((characterp obj) (char-to-string obj))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
835 (t (error
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
836 "Invalid argument (should be string or character): %s"
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
837 obj))))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
838 (string-len (length string))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
839 (len (length str))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
840 (i 0))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
841 (while (and (< i len) (< idx string-len))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
842 (aset string idx (aref str i))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
843 (setq idx (1+ idx) i (1+ i)))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
844 string))
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
845
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
846 ;; From FSF 21.1; ELLIPSES is XEmacs addition.
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
847
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
848 (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
849 ellipses)
777
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
850 "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
851 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
852 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
853 columns START-COLUMN ... END-COLUMN of STR.
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
854
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
855 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
856 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
857 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
858 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
859 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
860
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
861 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
862 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
863
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
864 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
865 will get weird results if not.
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
866
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
867 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
868 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
869 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
870 -- 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
871 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
872 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
873 the string occupies exactly END-COLUMN columns."
777
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
874 (or start-column
e65d9cf16707 [xemacs-hg @ 2002-03-15 11:00:28 by ben]
ben
parents: 772
diff changeset
875 (setq start-column 0))
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
876 (let ((len (length str))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
877 (idx 0)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
878 (column 0)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
879 (head-padding "") (tail-padding "")
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
880 ch last-column last-idx from-idx)
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
881
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
882 ;; 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
883 (condition-case nil
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
884 (while (< column start-column)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
885 (setq ch (aref str idx)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
886 column (+ column (char-width ch))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
887 idx (1+ idx)))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
888 (args-out-of-range (setq idx len)))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
889 (if (< column start-column)
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
890 ;; 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
891 ;; or a string entirely padded.
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
892 (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
893 (if (and padding (> column start-column))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
894 (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
895 (setq from-idx idx)
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
896 ;; 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
897 (if (< end-column column)
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
898 (setq idx from-idx ellipses "")
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
899
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
900 ;; handle ELLIPSES
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
901 (cond ((null ellipses) (setq ellipses ""))
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
902 ((if (<= (string-width str) end-column)
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
903 ;; string fits, no ellipses
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
904 (setq ellipses "")))
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
905 (t
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
906 ;; else, insert default value and ...
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
907 (or (stringp ellipses) (setq ellipses "..."))
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
908 ;; ... 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
909 ;; destination. do all computations with new, shorter
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
910 ;; 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
911 ;; 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
912 ;; to the right of the ellipses.
924
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
913 (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
914
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
915 ;; 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
916 (condition-case nil
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
917 (while (< column end-column)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
918 (setq last-column column
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
919 last-idx idx
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
920 ch (aref str idx)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
921 column (+ column (char-width ch))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
922 idx (1+ idx)))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
923 (args-out-of-range (setq idx len)))
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
924 ;; 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
925 (if (> column end-column)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
926 (setq column last-column idx last-idx))
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
927 ;; compute remaining padding
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
928 (if (and padding (< column end-column))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
929 (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
930 ;; get substring ...
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
931 (setq str (substring str from-idx idx))
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
932 ;; and construct result
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
933 (if padding
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
934 (concat head-padding str tail-padding ellipses)
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 814
diff changeset
935 (concat str ellipses)))))
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 793
diff changeset
936
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 ;; alist/plist functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 (defun plist-to-alist (plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 "Convert property list PLIST into the equivalent association-list form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 The alist is returned. This converts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 \(a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 \((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 The original plist is not modified. See also `destructive-plist-to-alist'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (let (alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 (while plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 (setq alist (cons (cons (car plist) (cadr plist)) alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 (setq plist (cddr plist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 (nreverse alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955
783
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
956 (defun map-plist (_mp_fun _mp_plist)
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
957 "Map _MP_FUN (a function of two args) over each key/value pair in _MP_PLIST.
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
958 Return a list of the results."
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
959 (let (_mp_result)
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
960 (while _mp_plist
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
961 (push (funcall _mp_fun (car _mp_plist) (cadr _mp_plist)) _mp_result)
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
962 (setq _mp_plist (cddr _mp_plist)))
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
963 (nreverse _mp_result)))
6fadd0a2230b [xemacs-hg @ 2002-03-19 02:38:51 by ben]
ben
parents: 777
diff changeset
964
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 (defun destructive-plist-to-alist (plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 "Convert property list PLIST into the equivalent association-list form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 The alist is returned. This converts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 \(a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 \((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 The original plist is destroyed in the process of constructing the alist.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 See also `plist-to-alist'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (let ((head plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (while plist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 ;; remember the next plist pair.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (setq next (cddr plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 ;; make the cons holding the property value into the alist element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (setcdr (cdr plist) (cadr plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (setcar (cdr plist) (car plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 ;; reattach into alist form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (setcar plist (cdr plist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (setcdr plist next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (setq plist next))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 head))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 (defun alist-to-plist (alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 "Convert association list ALIST into the equivalent property-list form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 The plist is returned. This converts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 \((a . 1) (b . 2) (c . 3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 \(a 1 b 2 c 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 The original alist is not modified. See also `destructive-alist-to-plist'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 (let (plist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 (while alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (let ((el (car alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 (setq plist (cons (cdr el) (cons (car el) plist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (setq alist (cdr alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 (nreverse plist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 ;; getf, remf in cl*.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1011 (defmacro putf (plist property value)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1012 "Add property PROPERTY to plist PLIST with value VALUE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1013 Analogous to (setq PLIST (plist-put PLIST PROPERTY VALUE))."
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1014 `(setq ,plist (plist-put ,plist ,property ,value)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1016 (defmacro laxputf (lax-plist property value)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1017 "Add property PROPERTY to lax plist LAX-PLIST with value VALUE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1018 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
1019 `(setq ,lax-plist (lax-plist-put ,lax-plist ,property ,value)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1021 (defmacro laxremf (lax-plist property)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1022 "Remove property PROPERTY from lax plist LAX-PLIST.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1023 Analogous to (setq LAX-PLIST (lax-plist-remprop LAX-PLIST PROPERTY))."
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1024 `(setq ,lax-plist (lax-plist-remprop ,lax-plist ,property)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 ;;; Error functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1028 (defun error (datum &rest args)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1029 "Signal a non-continuable error.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1030 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
1031 `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
1032 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
1033
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 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
1035 error using the debugger `r' command. See also `cerror'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1036
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1037 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
1038 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
1039 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
1040 exact operation being performed and what went wrong), and the remaining
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1041 arguments or \"frobs\" (most often, there is one) specify the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1042 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
1043 error when a file error occurred, e.g.:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1044
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1045 -- the buffer in which an editing error occurred.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1046 -- an invalid value that was encountered. (In such cases, the string
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1047 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
1048 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
1049 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
1050 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
1051 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
1052 that's not self-evident.)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1053 -- 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
1054 second frob, probably a string, specifying the exact error that occurred.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1055 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
1056 that frob describes the exact operation that was happening.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1057
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1058 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
1059 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
1060 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
1061 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
1062 totally defeats the purpose of having structured errors. There is now
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1063 a rich set of defined errors you can use:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1064
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1065 quit
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1066
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1067 error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1068 invalid-argument
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1069 syntax-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1070 invalid-read-syntax
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1071 invalid-regexp
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1072 structure-formation-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1073 list-formation-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1074 malformed-list
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1075 malformed-property-list
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1076 circular-list
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1077 circular-property-list
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1078 invalid-function
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1079 no-catch
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1080 undefined-keystroke-sequence
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1081 invalid-constant
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1082 wrong-type-argument
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1083 args-out-of-range
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1084 wrong-number-of-arguments
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1086 invalid-state
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1087 void-function
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1088 cyclic-function-indirection
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1089 void-variable
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1090 cyclic-variable-indirection
509
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1091 invalid-byte-code
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1092 stack-overflow
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1093 out-of-memory
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1094 invalid-key-binding
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1095 internal-error
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1096
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1097 invalid-operation
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1098 invalid-change
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1099 setting-constant
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1100 protected-field
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1101 editing-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1102 beginning-of-buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1103 end-of-buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1104 buffer-read-only
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1105 io-error
509
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1106 file-error
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1107 file-already-exists
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1108 file-locked
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1109 file-supersession
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1110 end-of-file
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1111 process-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1112 network-error
509
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1113 tooltalk-error
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1114 gui-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1115 dialog-box-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1116 sound-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1117 conversion-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1118 text-conversion-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1119 image-conversion-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1120 base64-conversion-error
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1121 selection-conversion-error
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1122 arith-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1123 range-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1124 domain-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1125 singularity-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1126 overflow-error
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1127 underflow-error
509
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1128 search-failed
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1129 printing-unreadable-object
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1130 unimplemented
509
68eb53e4b7e5 [xemacs-hg @ 2001-05-05 10:53:29 by ben]
ben
parents: 444
diff changeset
1131
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1132 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
1133
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1134 -- `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
1135 -- `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
1136 is allowed.
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 510
diff changeset
1137 -- `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
1138 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
1139 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
1140 e.g. `invalid-constant', `wrong-type-argument', or `invalid-argument'.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1141 -- `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
1142 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
1143 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
1144 changed, rather than afterwards. This leads us to the next error:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1145 -- `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
1146 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
1147 -- `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
1148 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
1149 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
1150 -- `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
1151 components (files, other programs, the operating system, etc).
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1152
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1153 See also `cerror', `signal', and `signal-error'."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1154 (while t (apply
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1155 'cerror datum args)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1156
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1157 (defun cerror (datum &rest args)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 "Like `error' but signals a continuable error."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1159 (cond ((stringp datum)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1160 (signal 'error (list (apply 'format datum args))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1161 ((defined-error-p datum)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1162 (signal datum args))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1163 (t
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1164 (error 'invalid-argument "datum not string or error symbol" datum))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (defmacro check-argument-type (predicate argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 "Check that ARGUMENT satisfies PREDICATE.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1168 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
1169 this function signals a continuable `wrong-type-argument' error until the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1170 returned value satisfies PREDICATE, and assigns the returned value
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1171 to ARGUMENT. Otherwise, this function signals a non-continuable
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1172 `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
1173 (if (symbolp argument)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1174 `(if (not (,(eval predicate) ,argument))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1175 (setq ,argument
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1176 (wrong-type-argument ,predicate ,argument)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1177 `(if (not (,(eval predicate) ,argument))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1178 (signal-error 'wrong-type-argument (list ,predicate ,argument)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1180 (defun args-out-of-range (value min max)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1181 "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
1182 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
1183 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
1184 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
1185 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
1186 point, the gotten value is returned."
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1187 (loop
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1188 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
1189 do (setq value newval)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1190 finally return value
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1191 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
1192
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1193 (defun argument-in-range-p (argument min max)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1194 "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
1195 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
1196 (and (or (not min) (<= min argument))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1197 (or (not max) (<= argument max))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1198
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1199 (defmacro check-argument-range (argument min max)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1200 "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
1201 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
1202 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
1203 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
1204 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
1205 `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
1206 (if (symbolp argument)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1207 `(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
1208 (setq ,argument
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1209 (args-out-of-range ,argument ,min ,max)))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1210 (let ((newsym (gensym)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1211 `(let ((,newsym ,argument))
924
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1212 (if (not (argument-in-range-p ,newsym ,min ,max))
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1213 (signal-error 'args-out-of-range ,newsym ,min ,max))))))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 851
diff changeset
1214
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (defun signal-error (error-symbol data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 "Signal a non-continuable error. Args are ERROR-SYMBOL, and associated DATA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 An error symbol is a symbol defined using `define-error'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 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
1219 If the signal is handled, DATA is made available to the handler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 See also `signal', and the functions to handle errors: `condition-case'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 and `call-with-condition-handler'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (while t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (signal error-symbol data)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (defun define-error (error-sym doc-string &optional inherits-from)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 "Define a new error, denoted by ERROR-SYM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 DOC-STRING is an informative message explaining the error, and will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 printed out when an unhandled error occurs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 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
1230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 \[`define-error' internally works by putting on ERROR-SYM an `error-message'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 property whose value is DOC-STRING, and an `error-conditions' property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 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
1234 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
1235 directly rather than calling `define-error', but you should *not* do this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 yourself.]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 (check-argument-type 'symbolp error-sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 (check-argument-type 'stringp doc-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (put error-sym 'error-message doc-string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 (or inherits-from (setq inherits-from 'error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 (let ((conds (get inherits-from 'error-conditions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 (or conds (signal-error 'error (list "Not an error symbol" error-sym)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 (put error-sym 'error-conditions (cons error-sym conds))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1245 (defun defined-error-p (sym)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1246 "Returns non-nil if SYM names a currently-defined error."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1247 (and (symbolp sym) (not (null (get sym 'error-conditions)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1248
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1249 (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
1250 "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
1251 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
1252 when written like this:
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1253
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1254 \(call-with-condition-handler
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1255 #'(lambda (__some_weird_arg__)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1256 do the handling ...)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1257 #'(lambda ()
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1258 do the stuff that might cause an error))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1259
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1260 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
1261 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
1262 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
1263 error occurred (i.e. the handler itself)."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1264 (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
1265 (bt (save-match-data
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1266 ;; Try to eliminate the part of the backtrace
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1267 ;; above where the error occurred.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1268 (if (string-match
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1269 (concat "bind (\\(?:.* \\)?" (symbol-name handler-arg-name)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1270 "\\(?:.* \\)?)[ \t\n]*\\(?:(lambda \\|#<compiled-function \\)("
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1271 (symbol-name handler-arg-name)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1272 ").*\n\\(\\(?:.\\|\n\\)*\\)$")
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1273 bt) (match-string 1 bt) bt))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1274 bt))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1275
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1276 (put 'with-trapping-errors 'lisp-indent-function 0)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1277 (defmacro with-trapping-errors (&rest keys-body)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1278 "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
1279 Usage looks like
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1280
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1281 \(with-trapping-errors
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1282 [:operation OPERATION]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1283 [:error-form ERROR-FORM]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1284 [:no-backtrace NO-BACKTRACE]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1285 [:class CLASS]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1286 [:level LEVEL]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1287 [:resignal RESIGNAL]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1288 BODY)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1289
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1290 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
1291 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
1292 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
1293 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
1294 `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
1295 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
1296 is displayed and the ERROR-FORM is executed."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1297 (let ((operation "unknown")
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1298 (error-form nil)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1299 (no-backtrace nil)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1300 (class ''general)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1301 (level ''warning)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1302 (resignal nil))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1303 (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
1304 (keys-with-colon
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1305 (mapcar #'(lambda (sym)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1306 (intern (concat ":" (symbol-name sym)))) keys)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1307 (while (memq (car keys-body) keys-with-colon)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1308 (let* ((key-with-colon (pop keys-body))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1309 (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
1310 (set key (pop keys-body)))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1311 `(condition-case ,(if resignal '__cte_cc_var__ nil)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1312 (call-with-condition-handler
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1313 #'(lambda (__call_trapping_errors_arg__)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1314 (let ((errstr (error-message-string
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1315 __call_trapping_errors_arg__)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1316 ,(if no-backtrace
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1317 `(lwarn ,class ,level
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1318 (if (warning-level-<
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1319 ,level
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1320 display-warning-minimum-level)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1321 "Error in %s: %s"
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1322 "Error in %s:\n%s\n")
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1323 ,operation errstr)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1324 `(lwarn ,class ,level
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1325 "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
1326 ,operation errstr
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1327 (backtrace-in-condition-handler-eliminating-handler
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1328 '__call_trapping_errors_arg__)))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1329 #'(lambda ()
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1330 (progn ,@keys-body)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1331 (error
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1332 ,error-form
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1333 ,@(if resignal '((signal (car __cte_cc_var__) (cdr __cte_cc_var__)))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1334 )))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 783
diff changeset
1335
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 ;;;; Miscellanea.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 ;; This is now in C.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1339 ;(defun buffer-substring-no-properties (start end)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1340 ; "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
1341 ; (let ((string (buffer-substring start end)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 ; (set-text-properties 0 (length string) nil string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 ; string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (defun get-buffer-window-list (&optional buffer minibuf frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 "Return windows currently displaying BUFFER, or nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 See `walk-windows' for the meaning of MINIBUF and FRAME."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (cond ((null buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (setq buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 ((not (bufferp buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 (setq buffer (get-buffer buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 (let (windows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 (walk-windows (lambda (window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 (if (eq (window-buffer window) buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (push window windows)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 minibuf frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 windows))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (defun ignore (&rest ignore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 "Do nothing and return nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 This function accepts any number of arguments, but ignores them."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365
883
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1366 ;; defined in lisp/bindings.el in GNU Emacs.
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1367 (defmacro bound-and-true-p (var)
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1368 "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
1369 `(and (boundp (quote ,var)) ,var))
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1370
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1371 ;; `propertize' is a builtin in GNU Emacs 21.
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1372 (defun propertize (string &rest properties)
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1373 "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
1374 First argument is the string to copy.
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1375 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
1376 properties to add to the result."
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1377 (let ((str (copy-sequence string)))
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1378 (add-text-properties 0 (length str)
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1379 properties
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1380 str)
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1381 str))
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1382
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1383 ;; `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
1384 (defun delete-and-extract-region (start end)
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1385 "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
1386 (let ((region (buffer-substring start end)))
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1387 (delete-region start end)
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1388 region))
1e9272790fe0 [xemacs-hg @ 2002-06-26 00:11:15 by youngs]
youngs
parents: 878
diff changeset
1389
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 (define-function 'eval-in-buffer 'with-current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 (make-obsolete 'eval-in-buffer 'with-current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 ;;; The real defn is in abbrev.el but some early callers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 ;;; (eg lisp-mode-abbrev-table) want this before abbrev.el is loaded...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (if (not (fboundp 'define-abbrev-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (setq abbrev-table-name-list '())
924
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1399 (fset 'define-abbrev-table
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1400 (function (lambda (name defs)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1401 ;; These are fixed-up when abbrev.el loads.
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1402 (setq abbrev-table-name-list
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1403 (cons (cons name defs)
1b114504fa80 [xemacs-hg @ 2002-07-16 08:18:35 by didierv]
didierv
parents: 883
diff changeset
1404 abbrev-table-name-list)))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 ;;; `functionp' has been moved into C.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 ;;(defun functionp (object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 ;; "Non-nil if OBJECT can be called as a function."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 ;; (or (and (symbolp object) (fboundp object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 ;; (subrp object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 ;; (compiled-function-p object)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 ;; (eq (car-safe object) 'lambda)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 (defun function-interactive (function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 "Return the interactive specification of FUNCTION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 FUNCTION can be any funcallable object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 The specification will be returned as the list of the symbol `interactive'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 and the specs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 If FUNCTION is not interactive, nil will be returned."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 (setq function (indirect-function function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 (cond ((compiled-function-p function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 (compiled-function-interactive function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 ((subrp function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 (subr-interactive function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 ((eq (car-safe function) 'lambda)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 (let ((spec (if (stringp (nth 2 function))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 (nth 3 function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 (nth 2 function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 (and (eq (car-safe spec) 'interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 spec)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (error "Non-funcallable object: %s" function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1435 (defun function-allows-args (function n)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1436 "Return whether FUNCTION can be called with N arguments."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1437 (and (<= (function-min-args function) n)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1438 (or (null (function-max-args function))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1439 (<= n (function-max-args function)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1440
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 ;; This function used to be an alias to `buffer-substring', except
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 ;; 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
1443 ;; 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
1444 ;; both for backward compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 (defun buffer-string (&optional buffer old-end old-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 "Return the contents of the current buffer as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 If narrowing is in effect, this function returns only the visible part
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 If BUFFER is specified, the contents of that buffer are returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 The arguments OLD-END and OLD-BUFFER are supported for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 compatibility with pre-21.2 XEmacsen times when arguments to this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 function were (buffer-string &optional START END BUFFER)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 ((or (stringp buffer) (bufferp buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 ;; Most definitely the new way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 (buffer-substring nil nil buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 ((or (stringp old-buffer) (bufferp old-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 (natnump buffer) (natnump old-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 ;; Definitely the old way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (buffer-substring buffer old-end old-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 ;; Probably the old way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (buffer-substring buffer old-end old-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
1467 ;; BEGIN SYNC WITH FSF 21.2
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
1468
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 ;; This was not present before. I think Jamie had some objections
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 ;; to this, so I'm leaving this undefined for now. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 ;;; 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
1473 ;;; "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
1474 ;;; 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
1475 ;;; 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
1476 ;;; 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
1477 ;;; the arguments to (load) are not. --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 ;; We provide this for FSFmacs compatibility, at least until we devise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 ;; something better.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 ;;;; Specifying things to do after certain files are loaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 (defun eval-after-load (file form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 "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
1486 This makes or adds to an entry on `after-load-alist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 If FILE is already loaded, evaluate FORM right now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 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
1489 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
1490 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
1491 is normally called."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
1492 ;; 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
1493 ;; 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
1494 (if-fboundp 'load-symbol-file-load-history
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
1495 (load-symbol-file-load-history))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 ;; Make sure there is an element for FILE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 (or (assoc file after-load-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 (setq after-load-alist (cons (list file) after-load-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 ;; Add FORM to the element if it isn't there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 (let ((elt (assoc file after-load-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 (or (member form (cdr elt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (nconc elt (list form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 ;; If the file has been loaded already, run FORM right away.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 (and (assoc file load-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (eval form)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 (make-compatible 'eval-after-load "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (defun eval-next-after-load (file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 "Read the following input sexp, and run it whenever FILE is loaded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 This makes or adds to an entry on `after-load-alist'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 FILE should be the name of a library, with no directory name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 (eval-after-load file (read)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 (make-compatible 'eval-next-after-load "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1037
diff changeset
1517 ;; END SYNC WITH FSF 21.2
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 ;;; subr.el ends here