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