annotate lisp/bytecomp-runtime.el @ 826:6728e641994e

[xemacs-hg @ 2002-05-05 11:30:15 by ben] syntax cache, 8-bit-format, lots of code cleanup README.packages: Update info about --package-path. i.c: Create an inheritable event and pass it on to XEmacs, so that ^C can be handled properly. Intercept ^C and signal the event. "Stop Build" in VC++ now works. bytecomp-runtime.el: Doc string changes. compat.el: Some attempts to redo this to make it truly useful and fix the "multiple versions interacting with each other" problem. Not yet done. Currently doesn't work. files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code. xemacs.mak: Split up CFLAGS into a version without flags specifying the C library. The problem seems to be that minitar depends on zlib, which depends specifically on libc.lib, not on any of the other C libraries. Unless you compile with libc.lib, you get errors -- specifically, no _errno in the other libraries, which must make it something other than an int. (#### But this doesn't seem to obtain in XEmacs, which also uses zlib, and can be linked with any of the C libraries. Maybe zlib is used differently and doesn't need errno, or maybe XEmacs provides an int errno; ... I don't understand. Makefile.in.in: Fix so that packages are around when testing. abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch. -- FUNCTIONALITY CHANGES: add partial support for 8-bit-fixed, 16-bit-fixed, and 32-bit-fixed formats. not quite done yet. (in particular, needs functions to actually convert the buffer.) NOTE: lots of changes to regex.c here. also, many new *_fmt() inline funs that take an Internal_Format argument. redo syntax cache code. make the cache per-buffer; keep the cache valid across calls to functions that use it. also keep it valid across insertions/deletions and extent changes, as much as is possible. eliminate the junky regex-reentrancy code by passing in the relevant lisp info to the regex routines as local vars. add general mechanism in extents code for signalling extent changes. fix numerous problems with the case-table implementation; yoshiki never properly transferred many algorithms from old-style to new-style case tables. redo char tables to support a default argument, so that mapping only occurs over changed args. change many chartab functions to accept Lisp_Object instead of Lisp_Char_Table *. comment out the code in font-lock.c by default, because font-lock.el no longer uses it. we should consider eliminating it entirely. Don't output bell as ^G in console-stream when not a TTY. add -mswindows-termination-handle to interface with i.c, so we can properly kill a build. add more error-checking to buffer/string macros. add some additional buffer_or_string_() funs. -- INTERFACE CHANGES AFFECTING MORE CODE: switch the arguments of write_c_string and friends to be consistent with write_fmt_string, which must have printcharfun first. change BI_* macros to BYTE_* for increased clarity; similarly for bi_* local vars. change VOID_TO_LISP to be a one-argument function. eliminate no-longer-needed CVOID_TO_LISP. -- char/string macro changes: rename MAKE_CHAR() to make_emchar() for slightly less confusion with make_char(). (The former generates an Emchar, the latter a Lisp object. Conceivably we should rename make_char() -> wrap_char() and similarly for make_int(), make_float().) Similar changes for other *CHAR* macros -- we now consistently use names with `emchar' whenever we are working with Emchars. Any remaining name with just `char' always refers to a Lisp object. rename macros with XSTRING_* to string_* except for those that reference actual fields in the Lisp_String object, following conventions used elsewhere. rename set_string_{data,length} macros (the only ones to work with a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_* to make the difference clear. try to be consistent about caps vs. lowercase in macro/inline-fun names for chars and such, which wasn't the case before. we now reserve caps either for XFOO_ macros that reference object fields (e.g. XSTRING_DATA) or for things that have non-function semantics, e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an arg (any arg) more than once. otherwise, use lowercase. here is a summary of most of the macros/inline funs changed by all of the above changes: BYTE_*_P -> byte_*_p XSTRING_BYTE -> string_byte set_string_data/length -> set_lispstringp_data/length XSTRING_CHAR_LENGTH -> string_char_length XSTRING_CHAR -> string_emchar INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p charptr_copy_char -> charptr_copy_emchar LEADING_BYTE_* -> leading_byte_* CHAR_* -> EMCHAR_* *_CHAR_* -> *_EMCHAR_* *_CHAR -> *_EMCHAR CHARSET_BY_ -> charset_by_* BYTE_SHIFT_JIS* -> byte_shift_jis* BYTE_BIG5* -> byte_big5* REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte char_to_unicode -> emchar_to_unicode valid_char_p -> valid_emchar_p Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality). -- INTERFACE CHANGES AFFECTING LESS CODE: use DECLARE_INLINE_HEADER in various places. remove '#ifdef emacs' from XEmacs-only files. eliminate CHAR_TABLE_VALUE(), which duplicated the functionality of get_char_table(). add BUFFER_TEXT_LOOP to simplify iterations over buffer text. define typedefs for signed and unsigned types of fixed sizes (INT_32_BIT, UINT_32_BIT, etc.). create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE; fix code to use it. add charptr_emchar_len to return the text length of the character pointed to by a ptr; use it in place of charcount_to_bytecount(..., 1). add emchar_len to return the text length of a given character. add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount and Charbpos/Charcount, in code (particularly, the extents code and redisplay code) that works with either kind of index. rename redisplay struct params with names such as `charbpos' to e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos. eliminate xxDEFUN in place of DEFUN; no longer necessary with changes awhile back to doc.c. split up big ugly combined list of EXFUNs in lisp.h on a file-by-file basis, since other prototypes are similarly split. rewrite some "*_UNSAFE" macros as inline funs and eliminate the _UNSAFE suffix. move most string code from lisp.h to text.h; the string code and text.h code is now intertwined in such a fashion that they need to be in the same place and partially interleaved. (you can't create forward references for inline funs) automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in batch mode. Fix up some problems in lisp-tests/symbol-tests that were causing spurious failures.
author ben
date Sun, 05 May 2002 11:33:57 +0000
parents 79940b592197
children a28c97bd4634
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.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
4 ;; Copyright (C) 2002 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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
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 ;;; Synched up with: FSF 19.30.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; 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
35 ;; like "defsubst" which should work interpreted as well. The code in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; bytecomp.el and byte-optimize.el can be loaded as needed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; interface to selectively inlining functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; This only happens when source-code optimization is turned on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; Redefined in byte-optimize.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; 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
45 (fset 'inline 'progn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 (put 'inline 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;;; Interface to inline functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;; 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
52 (defmacro proclaim-inline (&rest fns)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 "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
54 They will only be compiled open-coded when `byte-optimize' is true."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 (cons 'eval-and-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 'nconc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #'(lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 `((or (memq (get ',x 'byte-optimizer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 '(nil byte-compile-inline-expand))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 "%s already has a byte-optimizer, can't make it inline"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ',x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (put ',x 'byte-optimizer 'byte-compile-inline-expand)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 fns))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (defmacro proclaim-notinline (&rest fns)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 "Cause the named functions to no longer be open-coded."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (cons 'eval-and-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 'nconc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (mapcar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #'(lambda (x)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 `((if (eq (get ',x 'byte-optimizer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 'byte-compile-inline-expand)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (put ',x 'byte-optimizer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 fns))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;; This has a special byte-hunk-handler in bytecomp.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (defmacro defsubst (name arglist &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 "Define an inline function. The syntax is just like that of `defun'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (or (memq (get name 'byte-optimizer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 '(nil byte-compile-inline-expand))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (error "`%s' is a primitive" name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (list 'prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (cons 'defun (cons name (cons arglist body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (list 'proclaim-inline name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ; Instead of the above line, FSF has this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ; (list 'eval-and-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ; (list 'put (list 'quote name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 ; ''byte-optimizer ''byte-compile-inline-expand))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (defun make-obsolete (fn new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 "Make the byte-compiler warn that FUNCTION is obsolete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 The warning will say that NEW should be used instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 If NEW is a string, that is the `use instead' message."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (let ((handler (get fn 'byte-compile)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (if (eq 'byte-compile-obsolete handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (setcar (get fn 'byte-obsolete-info) new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 (put fn 'byte-obsolete-info (cons new handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (put fn 'byte-compile 'byte-compile-obsolete)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (defun make-obsolete-variable (var new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 "Make the byte-compiler warn that VARIABLE is obsolete,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 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
110 `use instead' message."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (if (equal str "") (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 (intern str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 (car (read-from-string (read-string "Obsoletion replacement: ")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 (put var 'byte-obsolete-variable new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ;; By overwhelming demand, we separate out truly obsolete symbols from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 ;; those that are present for GNU Emacs compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (defun make-compatible (fn new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 "Make the byte-compiler know that FUNCTION is provided for compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 The warning will say that NEW should be used instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 If NEW is a string, that is the `use instead' message."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (interactive "aMake function compatible: \nxCompatible replacement: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 (let ((handler (get fn 'byte-compile)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (if (eq 'byte-compile-compatible handler)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (setcar (get fn 'byte-compatible-info) new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (put fn 'byte-compatible-info (cons new handler))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (put fn 'byte-compile 'byte-compile-compatible)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 fn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (defun make-compatible-variable (var new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 "Make the byte-compiler know that VARIABLE is provided for compatibility.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 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
137 `use instead' message."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (let ((str (completing-read "Make variable compatible: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 obarray 'boundp t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (if (equal str "") (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (intern str))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (car (read-from-string (read-string "Compatible replacement: ")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (put var 'byte-compatible-variable new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (put 'dont-compile 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (defmacro dont-compile (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 "Like `progn', but the body always runs interpreted (not compiled).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 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
152 (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
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 ;;; interface to evaluating things at compile time and/or load time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 ;;; 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
157 ;;; definition in the file overrides the magic definitions on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 ;;; byte-compile-macro-environment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (put 'eval-when-compile 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (defmacro eval-when-compile (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 "Like `progn', but evaluates the body at compile time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 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
164 ;; Not necessary because we have it in b-c-initial-macro-environment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ;; (list 'quote (eval (cons 'progn body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (cons 'progn body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (put 'eval-and-compile 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (defmacro eval-and-compile (&rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 "Like `progn', but evaluates the body at compile time and at load time."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 ;; Remember, it's magic.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (cons 'progn body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 ;;; From Emacs 20.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (put 'eval-when-feature 'lisp-indent-hook 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (defmacro eval-when-feature (feature &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 "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
178 Called (eval-when-feature (FEATURE [. FILENAME]) BODYFORMS...).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 If (featurep 'FEATURE), evals now; otherwise adds an elt to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 `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
181 (let ((file (or (cdr feature) (symbol-name (car feature)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 `(let ((bodythunk #'(lambda () ,@body)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (if (featurep ',(car feature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 (funcall bodythunk)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (setq after-load-alist (cons '(,file . (list 'lambda '() bodythunk))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 after-load-alist))))))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
187
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
188
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
189
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
190 ;;; Functions to cleanly eliminate warnings about undefined functions
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
191 ;;; 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
192 ;;; 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
193 ;;; a package and used within it.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
194
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
195 ;; 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
196 ;; "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
197 ;; 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
198
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
199 ;; #### 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
200 ;; 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
201 ;; 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
202 ;; 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
203 ;; 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
204 ;; one.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
205
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
206 (put 'with-boundp 'lisp-indent-function 1)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
207 (defmacro with-boundp (variables &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
208 "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
209 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
210 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
211 `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
212 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
213
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
214 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
215 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
216 `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
217 `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
218 variable)."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
219 (setq variables (eval variables))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
220 (unless (consp variables)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
221 (setq variables (list variables)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
222 `(progn
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
223 (declare (special ,@variables))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
224 ,@body))
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 (put 'if-boundp 'lisp-indent-function 2)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
227 (defmacro if-boundp (variable then &rest else)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
228 "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
229 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
230 `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
231 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
232 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
233 `(with-boundp ,variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
234 (if (boundp ,variable) ,then ,@else)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
235
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
236 (put 'when-boundp 'lisp-indent-function 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
237 (defmacro when-boundp (variable &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
238 "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
239 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
240 `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
241 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
242 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
243 `(with-boundp ,variable
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
244 (when (boundp ,variable) ,@body)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
245
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
246 (put 'and-boundp 'lisp-indent-function 1)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
247 (defmacro and-boundp (variable &rest args)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
248 "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
249 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
250 `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
251 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
252 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
253 `(with-boundp ,variable
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
254 (and (boundp ,variable) ,@args)))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
255
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
256 (defmacro declare-boundp (variable)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
257 "Evaluate VARIABLE without bytecomp warnings about the symbol.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
258
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
259 Sample usage is
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
260
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
261 (declare-boundp gpm-minor-mode)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
262
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
263 which is equivalent to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
264
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
265 (with-boundp 'gpm-minor-mode
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
266 gpm-minor-mode)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
267
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
268 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 ,variable))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
270
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
271 (defmacro globally-declare-boundp (variables)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
272 "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
273 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
274
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
275 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
276 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
277 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
278
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
279 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
280 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
281 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
282 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
283 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
284 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
285 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
286 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
287 `globally-declare-fboundp' for more information."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
288 (setq variables (eval variables))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
289 (if (not (consp variables))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
290 (setq variables (list variables)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
291 `(progn
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
292 ;; (defvar FOO) has no side effects.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
293 ,@(mapcar #'(lambda (sym) `(defvar ,sym)) variables)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
294
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
295 (defun byte-compile-with-fboundp (form)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
296 (byte-compile-form (cons 'progn (cdr (cdr form))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
297 ;; 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
298 ;; 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
299 ;; following warnings:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
300
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
301 ;; "defsubst %s was used before it was defined"
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
302 ;; "%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
303
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
304 ;; 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
305 ;; 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
306 ;; `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
307 ;; file, so this is not a big deal.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
308
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
309 (let ((symbols (eval (car (cdr form)))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
310 (unless (consp symbols)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
311 (setq symbols (list symbols)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
312 (setq symbols (mapcar #'(lambda (sym) (cons sym nil)) symbols))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
313 (setq byte-compile-unresolved-functions
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
314 (set-difference byte-compile-unresolved-functions symbols
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
315 :key #'car))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
316 ))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
317
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
318 ;; 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
319 ;; 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
320 ;; 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
321 ;; 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
322 ;; 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
323 ;; 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
324 ;; 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
325 ;; 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
326 ;; `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
327 ;; 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
328 ;; `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
329 ;; 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
330 ;; (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
331 ;; guaranteed to work.)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
332 ;;
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
333 ;; 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
334 ;; `cl-block-wrapper'.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
335
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
336 (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
337 (defalias 'with-fboundp-1 'progn)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
338
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
339 (put 'with-fboundp 'lisp-indent-function 1)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
340 (defmacro with-fboundp (functions &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
341 "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
342 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
343 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
344 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
345 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
346
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
347 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
348 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
349 `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
350 `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
351 function)."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
352 `(with-fboundp-1 ,functions ,@body))
502
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 (put 'if-fboundp 'lisp-indent-function 2)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
355 (defmacro if-fboundp (function then &rest else)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
356 "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
357 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
358 `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
359 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
360 `with-fboundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
361 `(with-fboundp ,function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
362 (if (fboundp ,function) ,then ,@else)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
363
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
364 (put 'when-fboundp 'lisp-indent-function 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
365 (defmacro when-fboundp (function &rest body)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
366 "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
367 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
368 `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
369 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
370 `with-fboundp' and friends."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
371 `(with-fboundp ,function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
372 (when (fboundp ,function) ,@body)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
373
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
374 (put 'and-fboundp 'lisp-indent-function 1)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
375 (defmacro and-fboundp (function &rest args)
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
376 "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
377 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
378 `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
379 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
380 `with-fboundp' and friends."
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
381 `(with-fboundp ,function
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
382 (and (fboundp ,function) ,@args)))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
383
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
384 (defmacro declare-fboundp (form)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
385 "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
386 Sample usage is
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
387
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
388 (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
389
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
390 which is equivalent to
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
391
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
392 (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
393 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
394
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
395 See also `with-fboundp' and friends."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
396 `(with-fboundp ',(car form) ,form))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
397
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
398 (defmacro globally-declare-fboundp (functions)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
399 "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
400 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
401
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
402 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
403 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
404 in the file.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
405
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 (when (cl-compiling-file)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
419 (setq functions (eval functions))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
420 (if (not (consp functions))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
421 (setq functions (list functions)))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
422 ;; 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
423 ;; 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
424 ;; 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
425 ;; 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
426 ;; 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
427 ;; 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
428 (setq byte-compile-autoload-environment
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
429 (append (mapcar #'(lambda (sym) (cons sym nil)) functions)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
430 byte-compile-autoload-environment)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
431 nil)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
432
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
433 (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
434 (let ((byte-compile-warnings byte-compile-warnings)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
435 (types (car (cdr form))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
436 (unless (consp types)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
437 (setq types (list types)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
438 (if (eq byte-compile-warnings t)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
439 (setq byte-compile-warnings byte-compile-default-warnings))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
440 (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
441 (byte-compile-form (cons 'progn (cdr (cdr form))))))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
442
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
443 ;; Same hack here as with `with-fboundp'.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
444 (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
445 'byte-compile-with-byte-compiler-warnings-suppressed)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
446 (defalias 'with-byte-compiler-warnings-suppressed-1 'progn)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
447
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
448 (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
449 (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
450 "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
451 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
452 `free-vars', `unresolved', `unused-vars', `obsolete', or `pedantic',
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
453 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
454 TYPE must be quoted.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
455
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
456 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
457 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
458
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
459 -- 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
460 dynamically-scoped variables.
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
461 -- 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
462 when you know the function actually exists.
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
463 -- 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
464 when you know the variable actually exists.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
465 -- 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
466 are purposely using such a variable or function."
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
467 `(with-byte-compiler-warnings-suppressed-1 ,type ,@body))
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 ;; #### 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
470 ;; `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
471 ;; 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
472 ;; 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
473 ;; 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
474 ;; 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
475 ;; 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
476
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
477 (put 'with-obsolete-variable 'lisp-indent-function 1)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
478 (defmacro with-obsolete-variable (symbol &rest body)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
479 "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
480 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
481 `with-obsolete-function'."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
482 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body))
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-obsolete-function 'lisp-indent-function 1)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
485 (defmacro with-obsolete-function (symbol &rest body)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
486 "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
487 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
488 `with-obsolete-variable'."
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
489 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 ;;; Interface to file-local byte-compiler parameters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 ;;; Redefined in bytecomp.el.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 ;;; The great RMS speaketh:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 ;;; 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
498 ;;; using it. These options are a matter of installation preference,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 ;;; and have nothing to do with particular source files; it's a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 ;;; mistake to suggest to users that they should associate these with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 ;;; particular source files. There is hardly any reason to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 ;;; these parameters, anyway. --rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 ;;; But I'll leave this stuff alone. --ben
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (put 'byte-compiler-options 'lisp-indent-hook 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (defmacro byte-compiler-options (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 "Set some compilation-parameters for this file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 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
510 evaluated, or when loaded from a .el file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 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
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 Keys: Values: Corresponding variable:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 verbose t, nil byte-compile-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 optimize t, nil, source, byte byte-optimize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 warnings list of warnings byte-compile-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 file-format emacs19, emacs20 byte-compile-emacs19-compatibility
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 The value specified with the `warnings' option must be a list, containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 some subset of the following flags:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 free-vars references to variables not in the current lexical scope.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 unused-vars references to non-global variables bound but not referenced.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 unresolved calls to unknown functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 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
528 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
529 redefine function cell redefined from a macro to a lambda or vice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 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
531 obsolete use of an obsolete function or variable.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 428
diff changeset
532 pedantic warn of use of compatible symbols.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 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
535 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
536 entire set of warnings being overwritten.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 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
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (byte-compiler-options
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (optimize t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (warnings (- callargs)) ; Don't warn about arglist mismatch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (warnings (+ unused-vars)) ; Do warn about unused bindings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (file-format emacs19))"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 ;;; bytecomp-runtime.el ends here