annotate lisp/bytecomp-runtime.el @ 5630:f5315ccbf005

Cons less, be more careful about always using the environment, #'macroexpand 2011-12-30 Aidan Kehoe <kehoea@parhasard.net> * eval.c (Fmacroexpand): Don't cons if ENVIRONMENT is the same object as byte-compile-macro-environment. Always look up symbol- and other macros in the (possibly modified) byte-compile-macro-environment, not the supplied ENVIRONMENT. byte-compile-macro-environment reflects ENVIRONMENT, so that's OK and preferred.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 30 Dec 2011 12:43:52 +0000
parents 5f4f92a31875
children
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 ;;; bytecomp-runtime.el --- byte-compiler support for inlining
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) 1992, 1997 Free Software Foundation, Inc.
4949
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
4 ;; Copyright (C) 2002, 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Author: Jamie Zawinski <jwz@jwz.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Author: Hallvard Furuseth <hbf@ulrik.uio.no>
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: internal, 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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
13 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
14 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
15 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
16 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
20 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
21 ;; for more details.
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5264
diff changeset
24 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.30.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
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 ;; This file is dumped with XEmacs.
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 ;; The code in this file should always be loaded, because it defines things
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; like "defsubst" which should work interpreted as well. The code in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; bytecomp.el and byte-optimize.el can be loaded as needed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; interface to selectively inlining functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;; This only happens when source-code optimization is turned on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
5506
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
41 ;; We define macro-declaration-function here because it is needed to
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
42 ;; handle declarations in macro definitions and this is the first file
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
43 ;; loaded by loadup.el that uses declarations in macros.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
44 (defun macro-declaration-function (macro decl)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
45 "Process a declaration found in a macro definition.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
46 This is set as the value of the variable `macro-declaration-function'.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
47 MACRO is the name of the macro being defined.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
48 DECL is a list `(declare ...)' containing the declarations.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
49 The return value of this function is not used.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
50
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
51 XEmacs; any forms handed to the function described by the variable
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
52 `macro-declaration-function' will also (eventually) be handled by the
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
53 `declare' macro; see its documentation for further details of this."
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
54 ;; We can't use `dolist' or `cadr' yet for bootstrapping reasons.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
55 (let (d)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
56 ;; Ignore the first element of `decl' (it's always `declare').
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
57 (while (setq decl (cdr decl))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
58 (setq d (car decl))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
59 (if (and (consp d)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
60 (listp (cdr d))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
61 (null (cdr (cdr d))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
62 (cond ((eq (car d) 'indent)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
63 (put macro 'lisp-indent-function (car (cdr d))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
64 ((eq (car d) 'debug)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
65 (put macro 'edebug-form-spec (car (cdr d))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
66 ((eq (car d) 'doc-string)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
67 ;;; #### XEmacs; not sure that this does anything sensible.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
68 (put macro 'doc-string-elt (car (cdr d))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
69 ;; XEmacs; don't warn about the known XEmacs declarations.
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
70 ((memq (car d) '(special inline notinline optimize warn)))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
71 (t
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
72 (message "Unknown declaration %s" d)))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
73 (message "Invalid declaration %s" d)))))
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
74
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
75 (setq macro-declaration-function 'macro-declaration-function)
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
76
b0d87f92e60b Complete support for macro-declaration-function, bytecomp{,-runtime}.el
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
77
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 ;; Redefined in byte-optimize.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 ;; This is not documented--it's not clear that we should promote it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (fset 'inline 'progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (put 'inline 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;;; Interface to inline functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;; FSF comments the next two out, but I see no reason to do so. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (defmacro proclaim-inline (&rest fns)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 "Cause the named functions to be open-coded when called from compiled code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 They will only be compiled open-coded when `byte-optimize' is true."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (cons 'eval-and-compile
5264
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
91 (mapcan
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
92 #'(lambda (x)
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
93 `((or (memq (get ',x 'byte-optimizer)
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
94 '(nil byte-compile-inline-expand))
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
95 (error
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
96 "%s already has a byte-optimizer, can't make it inline"
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
97 ',x))
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
98 (put ',x 'byte-optimizer 'byte-compile-inline-expand)))
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
99 fns)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (defmacro proclaim-notinline (&rest fns)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 "Cause the named functions to no longer be open-coded."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (cons 'eval-and-compile
5264
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
105 (mapcan
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
106 #'(lambda (x)
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
107 `((if (eq (get ',x 'byte-optimizer)
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
108 'byte-compile-inline-expand)
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
109 (put ',x 'byte-optimizer nil))))
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
110 fns)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 ;; This has a special byte-hunk-handler in bytecomp.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (defmacro defsubst (name arglist &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 "Define an inline function. The syntax is just like that of `defun'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 (or (memq (get name 'byte-optimizer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 '(nil byte-compile-inline-expand))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 (error "`%s' is a primitive" name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 (list 'prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (cons 'defun (cons name (cons arglist body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 (list 'proclaim-inline name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ; Instead of the above line, FSF has this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ; (list 'eval-and-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ; (list 'put (list 'quote name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ; ''byte-optimizer ''byte-compile-inline-expand))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
2444
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
126 (defun make-obsolete (fn new &optional when)
991
a28c97bd4634 [xemacs-hg @ 2002-09-03 05:36:51 by scop]
scop
parents: 826
diff changeset
127 "Make the byte-compiler warn that function FN is obsolete.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 The warning will say that NEW should be used instead.
2444
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
129 If NEW is a string, that is the `use instead' message.
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
130 If provided, WHEN should be a string indicating when the function
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
131 was first made obsolete, for example a date or a release number."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (let ((handler (get fn 'byte-compile)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (if (eq 'byte-compile-obsolete handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 (setcar (get fn 'byte-obsolete-info) new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (put fn 'byte-obsolete-info (cons new handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (put fn 'byte-compile 'byte-compile-obsolete)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
2444
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
140 (defun make-obsolete-variable (var new &optional when)
991
a28c97bd4634 [xemacs-hg @ 2002-09-03 05:36:51 by scop]
scop
parents: 826
diff changeset
141 "Make the byte-compiler warn that variable VAR is obsolete,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 and NEW should be used instead. If NEW is a string, then that is the
2444
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
143 `use instead' message.
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
144 If provided, WHEN should be a string indicating when the variable
0e3842cd22e2 [xemacs-hg @ 2004-12-17 18:11:26 by scop]
scop
parents: 991
diff changeset
145 was first made obsolete, for example a date or a release number."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (if (equal str "") (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (intern str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (car (read-from-string (read-string "Obsoletion replacement: ")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (put var 'byte-obsolete-variable new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ;; By overwhelming demand, we separate out truly obsolete symbols from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 ;; those that are present for GNU Emacs compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (defun make-compatible (fn new)
991
a28c97bd4634 [xemacs-hg @ 2002-09-03 05:36:51 by scop]
scop
parents: 826
diff changeset
158 "Make the byte-compiler know that function FN is provided for compatibility.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 The warning will say that NEW should be used instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 If NEW is a string, that is the `use instead' message."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (interactive "aMake function compatible: \nxCompatible replacement: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (let ((handler (get fn 'byte-compile)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (if (eq 'byte-compile-compatible handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (setcar (get fn 'byte-compatible-info) new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (put fn 'byte-compatible-info (cons new handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (put fn 'byte-compile 'byte-compile-compatible)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (defun make-compatible-variable (var new)
991
a28c97bd4634 [xemacs-hg @ 2002-09-03 05:36:51 by scop]
scop
parents: 826
diff changeset
170 "Make the byte-compiler know that variable VAR is provided for compatibility,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 and NEW should be used instead. If NEW is a string, then that is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 `use instead' message."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (let ((str (completing-read "Make variable compatible: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 obarray 'boundp t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (if (equal str "") (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (intern str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (car (read-from-string (read-string "Compatible replacement: ")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (put var 'byte-compatible-variable new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (put 'dont-compile 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 (defmacro dont-compile (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 "Like `progn', but the body always runs interpreted (not compiled).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 If you think you need this, you're probably making a mistake somewhere."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 ;;; interface to evaluating things at compile time and/or load time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 ;;; these macro must come after any uses of them in this file, as their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ;;; definition in the file overrides the magic definitions on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 ;;; byte-compile-macro-environment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (put 'eval-when-compile 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (defmacro eval-when-compile (&rest body)
5264
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
197 "Like `progn', but evaluates BODY at compile time, and when interpeted.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 The result of the body appears to the compiler as a quoted constant."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 ;; Not necessary because we have it in b-c-initial-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 ;; (list 'quote (eval (cons 'progn body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (cons 'progn body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (put 'eval-and-compile 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (defmacro eval-and-compile (&rest body)
5264
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
205 "Like `progn', but evaluates the body at compile time and at load time,
0d43872986b6 Change (apply 'nconc (mapcar ...)) to (mapcan ...); warn about first form.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4949
diff changeset
206 and when interpreted."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;; Remember, it's magic.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (cons 'progn body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 ;;; From Emacs 20.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (put 'eval-when-feature 'lisp-indent-hook 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (defmacro eval-when-feature (feature &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 "Run the body forms when FEATURE is featurep, be it now or later.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 Called (eval-when-feature (FEATURE [. FILENAME]) BODYFORMS...).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 If (featurep 'FEATURE), evals now; otherwise adds an elt to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 `after-load-alist' (which see), using FEATURE as filename if FILENAME is nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (let ((file (or (cdr feature) (symbol-name (car feature)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 `(let ((bodythunk #'(lambda () ,@body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (if (featurep ',(car feature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (funcall bodythunk)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (setq after-load-alist (cons '(,file . (list 'lambda '() bodythunk))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 after-load-alist))))))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
223
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
224
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
225
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
226 ;;; Functions to cleanly eliminate warnings about undefined functions
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
227 ;;; or variables when the code knows what it's doing. These macros DO
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
228 ;;; NOT rely on any byte-compiler changes, and thus can be copied into
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
229 ;;; a package and used within it.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
230
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
231 ;; NOTE: As a result of the above requirement, the macros rely on
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
232 ;; "tricks" to get the warnings suppressed. A cleaner way, of course,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
233 ;; would be to extend the byte compiler to provide a proper interface.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
234
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
235 ;; #### Should we require an unquoted symbol rather than a quoted one,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
236 ;; as we currently do? The quoting gets no generality, as `eval' is
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
237 ;; called at compile time. But most functions and macros want quoted
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
238 ;; arguments, and I find it extremely confusing to deal with cases
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
239 ;; such as `throw' requiring a quoted argument but `block' an unquoted
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
240 ;; one.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
241
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
242 (put 'with-boundp 'lisp-indent-function 1)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
243 (defmacro with-boundp (variables &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
244 "Evaluate BODY, but do not issue bytecomp warnings about VARIABLES undefined.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
245 VARIABLES can be a symbol or a list of symbols and must be quoted. When
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
246 compiling this file, the warnings `reference to free variable VARIABLE' and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
247 `assignment to free variable VARIABLE' will not occur anywhere in BODY, for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
248 any of the listed variables. This is a clean way to avoid such warnings.
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
249
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
250 See also `if-boundp', `when-boundp', and `and-boundp' (ways to
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
251 conditionalize on a variable being bound and avoid warnings),
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
252 `declare-boundp' (issue a variable call without warnings), and
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
253 `globally-declare-boundp' (avoid warnings throughout a file about a
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
254 variable)."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
255 (setq variables (eval variables))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
256 (unless (consp variables)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
257 (setq variables (list variables)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
258 `(progn
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
259 (declare (special ,@variables))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
260 ,@body))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
261
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
262 (put 'if-boundp 'lisp-indent-function 2)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
263 (defmacro if-boundp (variable then &rest else)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
264 "Equivalent to (if (boundp VARIABLE) THEN ELSE) but handles bytecomp warnings.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
265 VARIABLE should be a quoted symbol. When compiling this file, the warnings
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
266 `reference to free variable VARIABLE' and `assignment to free variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
267 VARIABLE' will not occur anywhere in the if-statement. This is a clean way
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
268 to avoid such warnings. See also `with-boundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
269 `(with-boundp ,variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
270 (if (boundp ,variable) ,then ,@else)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
271
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
272 (put 'when-boundp 'lisp-indent-function 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
273 (defmacro when-boundp (variable &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
274 "Equivalent to (when (boundp VARIABLE) BODY) but handles bytecomp warnings.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
275 VARIABLE should be a quoted symbol. When compiling this file, the warnings
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
276 `reference to free variable VARIABLE' and `assignment to free variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
277 VARIABLE' will not occur anywhere in the when-statement. This is a clean
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
278 way to avoid such warnings. See also `with-boundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
279 `(with-boundp ,variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
280 (when (boundp ,variable) ,@body)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
281
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
282 (put 'and-boundp 'lisp-indent-function 1)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
283 (defmacro and-boundp (variable &rest args)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
284 "Equivalent to (and (boundp VARIABLE) ARGS) but handles bytecomp warnings.
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
285 VARIABLE should be a quoted symbol. When compiling this file, the warnings
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
286 `reference to free variable VARIABLE' and `assignment to free variable
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
287 VARIABLE' will not occur anywhere in the and-statement. This is a clean
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
288 way to avoid such warnings. See also `with-boundp' and friends."
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
289 `(with-boundp ,variable
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
290 (and (boundp ,variable) ,@args)))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
291
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
292 (defmacro declare-boundp (variable)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
293 "Evaluate VARIABLE without bytecomp warnings about the symbol.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
294
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
295 Sample usage is
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
296
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
297 (declare-boundp gpm-minor-mode)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
298
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
299 which is equivalent to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
300
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
301 (with-boundp 'gpm-minor-mode
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
302 gpm-minor-mode)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
303
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
304 See also `with-boundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
305 `(with-boundp ',variable ,variable))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
306
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
307 (defmacro globally-declare-boundp (variables)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
308 "Declare that all free uses of VARIABLES in this file are valid.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
309 VARIABLES can be a symbol or a list of symbols and must be quoted.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
310
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
311 When compiling this file, the warnings `reference to free variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
312 VARIABLE' and `assignment to free variable VARIABLE' will not occur
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
313 regardless of where references to VARIABLE occur in the file.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
314
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
315 In general, you should *NOT* use this; use `with-boundp' or its friends to
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
316 wrap individual uses, as necessary. That way, you're more likely to
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
317 remember to put in the explicit checks for the variable's existence that
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
318 are usually necessary. However, `globally-declare-boundp' is better in
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
319 some circumstances, such as when writing an ELisp package that makes
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
320 integral use of optionally-compiled-in functionality (typically, an
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
321 interface onto a system library) and checks for the existence of the
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
322 functionality at some entry point to the package. See
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
323 `globally-declare-fboundp' for more information."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
324 (setq variables (eval variables))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
325 (if (not (consp variables))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
326 (setq variables (list variables)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
327 `(progn
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
328 ;; (defvar FOO) has no side effects.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
329 ,@(mapcar #'(lambda (sym) `(defvar ,sym)) variables)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
330
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
331 (defun byte-compile-with-fboundp (form)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
332 (byte-compile-form (cons 'progn (cdr (cdr form))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
333 ;; Unfortunately, byte-compile-unresolved-functions is used not only
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
334 ;; for unresolved-function warnings, but also in connection with the
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
335 ;; following warnings:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
336
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
337 ;; "defsubst %s was used before it was defined"
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
338 ;; "%s being defined to take %s%s, but was previously called with %s"
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
339
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
340 ;; By hacking byte-compile-unresolved-functions like this, we
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
341 ;; effectively disable these warnings. But code should not be using
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
342 ;; `with-fboundp' with a function defined later on in the same
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
343 ;; file, so this is not a big deal.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
344
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
345 (let ((symbols (eval (car (cdr form)))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
346 (unless (consp symbols)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
347 (setq symbols (list symbols)))
5363
311f6817efc2 Remove various redundant wrapper lambdas, core lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5264
diff changeset
348 (setq symbols (mapcar #'list symbols))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
349 (setq byte-compile-unresolved-functions
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
350 (set-difference byte-compile-unresolved-functions symbols
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
351 :key #'car))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
352 ))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
353
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
354 ;; EEEEEEEEVIL hack. We need to create our own byte-compilation
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
355 ;; method so that the proper variables are bound while compilation
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
356 ;; takes place (which is when the warnings get noticed and batched
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
357 ;; up). What we really want to do is make `with-fboundp' a macro
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
358 ;; that simply `progn's its BODY; but GOD DAMN IT, macros can't have
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
359 ;; their own byte-compilation methods! So we make `with-fboundp' a
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
360 ;; macro calling `with-fboundp-1', which is cleverly aliased to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
361 ;; progn. This way we can put a byte-compilation method on
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
362 ;; `with-fboundp-1', and when interpreting, progn will duly skip
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
363 ;; the first, quoted argument, i.e. the symbol name. (We could make
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
364 ;; `with-fboundp-1' a regular function, but then we'd have to thunk
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
365 ;; BODY and eval it at runtime. We could probably just do this using
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
366 ;; (apply 'progn BODY), but the existing method is more obviously
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
367 ;; guaranteed to work.)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
368 ;;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
369 ;; In defense, cl-macs.el does a very similar thing with
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
370 ;; `cl-block-wrapper'.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
371
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
372 (put 'with-fboundp-1 'byte-compile 'byte-compile-with-fboundp)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
373 (defalias 'with-fboundp-1 'progn)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
374
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
375 (put 'with-fboundp 'lisp-indent-function 1)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
376 (defmacro with-fboundp (functions &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
377 "Evaluate BODY, but do not issue bytecomp warnings about FUNCTIONS undefined.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
378 FUNCTIONS can be a symbol or a list of symbols and must be quoted. When
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
379 compiling this file, the warning `the function FUNCTION is not known to be
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
380 defined' will not occur anywhere in BODY, for any of the listed functions.
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
381 This is a clean way to avoid such warnings.
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
382
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
383 See also `if-fboundp', `when-fboundp', and `and-fboundp' (ways to
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
384 conditionalize on a function being bound and avoid warnings),
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
385 `declare-fboundp' (issue a function call without warnings), and
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
386 `globally-declare-fboundp' (avoid warnings throughout a file about a
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
387 function)."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
388 `(with-fboundp-1 ,functions ,@body))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
389
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
390 (put 'if-fboundp 'lisp-indent-function 2)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
391 (defmacro if-fboundp (function then &rest else)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
392 "Equivalent to (if (fboundp FUNCTION) THEN ELSE) but handles bytecomp warnings.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
393 FUNCTION should be a quoted symbol. When compiling this file, the warning
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
394 `the function FUNCTION is not known to be defined' will not occur anywhere
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
395 in the if-statement. This is a clean way to avoid such warnings. See also
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
396 `with-fboundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
397 `(with-fboundp ,function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
398 (if (fboundp ,function) ,then ,@else)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
399
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
400 (put 'when-fboundp 'lisp-indent-function 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
401 (defmacro when-fboundp (function &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
402 "Equivalent to (when (fboundp FUNCTION) BODY) but handles bytecomp warnings.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
403 FUNCTION should be a quoted symbol. When compiling this file, the warning
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
404 `the function FUNCTION is not known to be defined' will not occur anywhere
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
405 in the when-statement. This is a clean way to avoid such warnings. See also
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
406 `with-fboundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
407 `(with-fboundp ,function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
408 (when (fboundp ,function) ,@body)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
409
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
410 (put 'and-fboundp 'lisp-indent-function 1)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
411 (defmacro and-fboundp (function &rest args)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
412 "Equivalent to (and (fboundp FUNCTION) ARGS) but handles bytecomp warnings.
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
413 FUNCTION should be a quoted symbol. When compiling this file, the warning
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
414 `the function FUNCTION is not known to be defined' will not occur anywhere
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
415 in the and-statement. This is a clean way to avoid such warnings. See also
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
416 `with-fboundp' and friends."
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
417 `(with-fboundp ,function
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
418 (and (fboundp ,function) ,@args)))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
419
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
420 (defmacro declare-fboundp (form)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
421 "Execute FORM (a function call) without bytecomp warnings about the call.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
422 Sample usage is
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
423
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
424 (declare-fboundp (x-keysym-on-keyboard-sans-modifiers-p 'backspace))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
425
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
426 which is equivalent to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
427
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
428 (with-fboundp 'x-keysym-on-keyboard-sans-modifiers-p
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
429 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
430
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
431 See also `with-fboundp' and friends."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
432 `(with-fboundp ',(car form) ,form))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
433
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
434 (defmacro globally-declare-fboundp (functions)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
435 "Declare that all calls to function FUNCTIONS in this file are valid.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
436 FUNCTIONS can be a symbol or a list of symbols and must be quoted.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
437
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
438 When compiling this file, the warning `the function FUNCTION is not known
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
439 to be defined' will not occur regardless of where calls to FUNCTION occur
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
440 in the file.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
441
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
442 In general, you should *NOT* use this; use `with-fboundp' or its friends to
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
443 wrap individual uses, as necessary. That way, you're more likely to
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
444 remember to put in the explicit checks for the function's existence that
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
445 are usually necessary. However, `globally-declare-fboundp' is better in
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
446 some circumstances, such as when writing an ELisp package that makes
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
447 integral use of optionally-compiled-in functionality (typically, an
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
448 interface onto a system library) and checks for the existence of the
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
449 functionality at some entry point to the package. The file `ldap.el' is a
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
450 good example: It provides a layer on top of the optional LDAP ELisp
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
451 primitives, makes calls to them throughout its code, and verifies the
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
452 presence of LDAP support at load time. Putting calls to `declare-fboundp'
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
453 throughout the code would be a major annoyance."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
454 (when (cl-compiling-file)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
455 (setq functions (eval functions))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
456 (if (not (consp functions))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
457 (setq functions (list functions)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
458 ;; Another hack. This works because the autoload environment is
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
459 ;; currently used ONLY to suppress warnings, and the actual
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
460 ;; autoload definition is not used. (NOTE: With this definition,
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
461 ;; we will get spurious "multiple autoloads for %s" warnings if we
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
462 ;; have an autoload later in the file for any functions in FUNCTIONS.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
463 ;; This is not something that code should ever do, though.)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
464 (setq byte-compile-autoload-environment
5363
311f6817efc2 Remove various redundant wrapper lambdas, core lisp.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5264
diff changeset
465 (append (mapcar #'list functions)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
466 byte-compile-autoload-environment)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
467 nil)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
468
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
469 (defun byte-compile-with-byte-compiler-warnings-suppressed (form)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
470 (let ((byte-compile-warnings byte-compile-warnings)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
471 (types (car (cdr form))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
472 (unless (consp types)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
473 (setq types (list types)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
474 (if (eq byte-compile-warnings t)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
475 (setq byte-compile-warnings byte-compile-default-warnings))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
476 (setq byte-compile-warnings (set-difference byte-compile-warnings types))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
477 (byte-compile-form (cons 'progn (cdr (cdr form))))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
478
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
479 ;; Same hack here as with `with-fboundp'.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
480 (put 'with-byte-compiler-warnings-suppressed-1 'byte-compile
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
481 'byte-compile-with-byte-compiler-warnings-suppressed)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
482 (defalias 'with-byte-compiler-warnings-suppressed-1 'progn)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
483
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
484 (put 'with-byte-compiler-warnings-suppressed 'lisp-indent-function 1)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
485 (defmacro with-byte-compiler-warnings-suppressed (type &rest body)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
486 "Evaluate BODY, but do not issue bytecomp warnings TYPE.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
487 TYPE should be one of `redefine', `callargs', `subr-callargs',
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
488 `free-vars', `unresolved', `unused-vars', `obsolete', or `pedantic',
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
489 or a list of one or more of these symbols. (See `byte-compile-warnings'.)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
490 TYPE must be quoted.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
491
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
492 NOTE: You should *NOT* under normal circumstances be using this!
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
493 There are better ways of avoiding most of these warnings. In particular:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
494
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
495 -- use (declare (special ...)) if you are making use of
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
496 dynamically-scoped variables.
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
497 -- use `with-fboundp' and friends to avoid warnings about undefined functions
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
498 when you know the function actually exists.
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
499 -- use `with-boundp' and friends to avoid warnings about undefined variables
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
500 when you know the variable actually exists.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
501 -- use `with-obsolete-variable' or `with-obsolete-function' if you
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
502 are purposely using such a variable or function."
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
503 `(with-byte-compiler-warnings-suppressed-1 ,type ,@body))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
504
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
505 ;; #### These should be more clever. You could (e.g.) try fletting
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
506 ;; `byte-compile-obsolete' or temporarily removing the obsolete info
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
507 ;; from the symbol and putting it back with an unwind-protect. (Or
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
508 ;; better, modify the byte-compiler to provide a proper solution, and
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
509 ;; fix these macros to use it if available, or fall back on the way
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
510 ;; below. Remember, these definitions need to work with an unchanged
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
511 ;; byte compiler so that they can be copied and used in packages.)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
512
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
513 (put 'with-obsolete-variable 'lisp-indent-function 1)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
514 (defmacro with-obsolete-variable (symbol &rest body)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
515 "Evaluate BODY but do not warn about usage of obsolete variable SYMBOL.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 776
diff changeset
516 SYMBOL must be quoted and can be a list of SYMBOLS. See also
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 776
diff changeset
517 `with-obsolete-function'."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
518 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
519
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
520 (put 'with-obsolete-function 'lisp-indent-function 1)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
521 (defmacro with-obsolete-function (symbol &rest body)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
522 "Evaluate BODY but do not warn about usage of obsolete function SYMBOL.
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 776
diff changeset
523 SYMBOL must be quoted and can be a list of SYMBOLS. See also
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 776
diff changeset
524 `with-obsolete-variable'."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
525 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527
4949
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
528
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
529 (defmacro error-unless-tests-match (test &optional source)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
530 "Signal an error unless TEST matches when being compiled and loaded.
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
531 This is for use in a file that will be byte-compiled. Unless TEST has the
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
532 same nilness or non-nilness when the file is compiled and loaded, an error
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
533 will be signalled. SOURCE is the name of the source file."
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
534 (let ((source (eval source)))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
535 `(unless (eq (not ,test) ,(not (eval test)))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
536 (error ,(format "This file was compiled with `%s' %s,
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
537 but it was %s when run. This file needs to be compiled with
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
538 the same value for the expression as when it is run. Please delete
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
539 %s and rebuild."
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
540 test (if (eval test) "true" "false")
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
541 (if (eval test) "false" "true")
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
542 (cond
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
543 ((null source) "the .elc for this file")
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
544 ((string-match "\.elc$" source) source)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
545 ((string-match "\.el$" source) (concat source "c"))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
546 (t (concat source ".elc"))))))))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
547
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
548 (defun byte-compile-file-being-compiled ()
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
549 "When byte-compiling a file, return the name of the file being compiled.
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
550 Return nil otherwise."
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
551 (or
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
552 ;;The first of these, but not the second, seems to work noninteractively;
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
553 ;;vice-versa interactively. This is because interactively a *Compile Log*
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
554 ;;buffer is created and byte-compile-log-1 inserts a "Compiling file ..."
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
555 ;;message into thelog buffer, and then sets byte-compile-current-file to
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
556 ;;nil to indicate that the message shouldn't be printed again.
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
557 (and-boundp 'byte-compile-current-file byte-compile-current-file)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
558 (and-boundp 'byte-compile-log-buffer
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
559 (with-current-buffer byte-compile-log-buffer
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
560 (save-excursion
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
561 (and (re-search-backward "Compiling file \\(.*\\) at " nil t)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
562 (match-string 1)))))))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
563
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
564
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
565 (defmacro compiled-if (test if &rest else)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
566 "Like a regular `if' statement but the TEST will be evalled at compile time.
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
567 If TEST doesn't match at compile time and load time, an error will be
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
568 signalled."
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
569 (let ((being-compiled (byte-compile-file-being-compiled)))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
570 `(progn
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
571 (error-unless-tests-match ,test ,being-compiled)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
572 ,(if (eval test)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
573 if
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
574 `(progn ,else)))))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
575
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
576 (defmacro compiled-when (test &rest when)
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
577 "Like a regular `when' statement but the TEST will be evalled at compile time.
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
578 See `compiled-if'."
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
579 `(compiled-if ,test (progn ,@when)))
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
580
018e13fdeaeb compile-related functions added, for use in Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents: 2444
diff changeset
581
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 ;;; Interface to file-local byte-compiler parameters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 ;;; Redefined in bytecomp.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 ;;; The great RMS speaketh:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 ;;; I nuked this because it's not a good idea for users to think of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 ;;; using it. These options are a matter of installation preference,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 ;;; and have nothing to do with particular source files; it's a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 ;;; mistake to suggest to users that they should associate these with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 ;;; particular source files. There is hardly any reason to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 ;;; these parameters, anyway. --rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 ;;; But I'll leave this stuff alone. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (put 'byte-compiler-options 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (defmacro byte-compiler-options (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 "Set some compilation-parameters for this file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 This will affect only the file in which it appears; this does nothing when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 evaluated, or when loaded from a .el file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 Each argument to this macro must be a list of a key and a value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 Keys: Values: Corresponding variable:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 verbose t, nil byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 optimize t, nil, source, byte byte-optimize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 warnings list of warnings byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 file-format emacs19, emacs20 byte-compile-emacs19-compatibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 The value specified with the `warnings' option must be a list, containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 some subset of the following flags:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 free-vars references to variables not in the current lexical scope.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 unused-vars references to non-global variables bound but not referenced.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 unresolved calls to unknown functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 callargs lambda calls with args that don't match the definition.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
618 subr-callargs calls to subrs with args that don't match the definition.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 redefine function cell redefined from a macro to a lambda or vice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 versa, or redefined to take a different number of arguments.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
621 obsolete use of an obsolete function or variable.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
622 pedantic warn of use of compatible symbols.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 If the first element if the list is `+' or `-' then the specified elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 are added to or removed from the current set of warnings, instead of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 entire set of warnings being overwritten.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 For example, something like this might appear at the top of a source file:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (byte-compiler-options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (optimize t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (warnings (- callargs)) ; Don't warn about arglist mismatch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (warnings (+ unused-vars)) ; Do warn about unused bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (file-format emacs19))"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 ;;; bytecomp-runtime.el ends here