aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2009-09-05 19:10:37 +0000
committerGlenn Morris2009-09-05 19:10:37 +0000
commit3f12e5bd4c9bd9b849c5a2ff50a5a2b97500c82e (patch)
tree8eef88dc895f38fc8b39759ccc62f604e685997a
parent604f2fc044f69760c78ae7948f2e35d025113d00 (diff)
downloademacs-3f12e5bd4c9bd9b849c5a2ff50a5a2b97500c82e.tar.gz
emacs-3f12e5bd4c9bd9b849c5a2ff50a5a2b97500c82e.zip
(emacs-lisp-file-regexp): Doc fix.
(byte-compile-dest-file-function): New option. (byte-compile-dest-file): Doc fix. Obey byte-compile-dest-file-function. (byte-compile-cl-file-p): New function. (byte-compile-eval): Only suppress noruntime warnings about cl functions if the cl-functions warning is enabled. Use byte-compile-cl-file-p. (byte-compile-eval): Check for non-nil byte-compile-cl-functions rather than for file being previously loaded. (byte-compile-find-cl-functions): Use byte-compile-cl-file-p. (byte-compile-file-form-require): Handle the case where requiring a file indirectly causes CL to be loaded.
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/emacs-lisp/bytecomp.el101
2 files changed, 85 insertions, 31 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8d5200e5ddf..7b5dc9afe5c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12009-09-05 Glenn Morris <rgm@gnu.org>
2
3 * emacs-lisp/bytecomp.el (emacs-lisp-file-regexp): Doc fix.
4 (byte-compile-dest-file-function): New option.
5 (byte-compile-dest-file): Doc fix.
6 Obey byte-compile-dest-file-function.
7 (byte-compile-cl-file-p): New function.
8 (byte-compile-eval): Only suppress noruntime warnings about cl functions
9 if the cl-functions warning is enabled. Use byte-compile-cl-file-p.
10 (byte-compile-eval): Check for non-nil byte-compile-cl-functions rather
11 than for file being previously loaded.
12 (byte-compile-find-cl-functions): Use byte-compile-cl-file-p.
13 (byte-compile-file-form-require): Handle the case where requiring a file
14 indirectly causes CL to be loaded.
15
12009-09-05 Karl Fogel <kfogel@red-bean.com> 162009-09-05 Karl Fogel <kfogel@red-bean.com>
2 17
3 * files.el (find-alternate-file): Run `kill-buffer-hook' manually 18 * files.el (find-alternate-file): Run `kill-buffer-hook' manually
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 5c18d2a4515..0e7b9781601 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -200,11 +200,18 @@
200 200
201(defcustom emacs-lisp-file-regexp "\\.el\\'" 201(defcustom emacs-lisp-file-regexp "\\.el\\'"
202 "Regexp which matches Emacs Lisp source files. 202 "Regexp which matches Emacs Lisp source files.
203You may want to redefine the function `byte-compile-dest-file' 203If you change this, you might want to set `byte-compile-dest-file-function'."
204if you change this variable."
205 :group 'bytecomp 204 :group 'bytecomp
206 :type 'regexp) 205 :type 'regexp)
207 206
207(defcustom byte-compile-dest-file-function nil
208 "Function for the function `byte-compile-dest-file' to call.
209It should take one argument, the name of an Emacs Lisp source
210file name, and return the name of the compiled file."
211 :group 'bytecomp
212 :type '(choice (const nil) function)
213 :version "23.2")
214
208;; This enables file name handlers such as jka-compr 215;; This enables file name handlers such as jka-compr
209;; to remove parts of the file name that should not be copied 216;; to remove parts of the file name that should not be copied
210;; through to the output file name. 217;; through to the output file name.
@@ -218,15 +225,21 @@ if you change this variable."
218(or (fboundp 'byte-compile-dest-file) 225(or (fboundp 'byte-compile-dest-file)
219 ;; The user may want to redefine this along with emacs-lisp-file-regexp, 226 ;; The user may want to redefine this along with emacs-lisp-file-regexp,
220 ;; so only define it if it is undefined. 227 ;; so only define it if it is undefined.
228 ;; Note - redefining this function is obsolete as of 23.2.
229 ;; Customize byte-compile-dest-file-function instead.
221 (defun byte-compile-dest-file (filename) 230 (defun byte-compile-dest-file (filename)
222 "Convert an Emacs Lisp source file name to a compiled file name. 231 "Convert an Emacs Lisp source file name to a compiled file name.
223If FILENAME matches `emacs-lisp-file-regexp' (by default, files 232If `byte-compile-dest-file-function' is non-nil, uses that
224with the extension `.el'), add `c' to it; otherwise add `.elc'." 233function to do the work. Otherwise, if FILENAME matches
225 (setq filename (byte-compiler-base-file-name filename)) 234`emacs-lisp-file-regexp' (by default, files with the extension `.el'),
226 (setq filename (file-name-sans-versions filename)) 235adds `c' to it; otherwise adds `.elc'."
227 (cond ((string-match emacs-lisp-file-regexp filename) 236 (if byte-compile-dest-file-function
228 (concat (substring filename 0 (match-beginning 0)) ".elc")) 237 (funcall byte-compile-dest-file-function filename)
229 (t (concat filename ".elc"))))) 238 (setq filename (file-name-sans-versions
239 (byte-compiler-base-file-name filename)))
240 (cond ((string-match emacs-lisp-file-regexp filename)
241 (concat (substring filename 0 (match-beginning 0)) ".elc"))
242 (t (concat filename ".elc"))))))
230 243
231;; This can be the 'byte-compile property of any symbol. 244;; This can be the 'byte-compile property of any symbol.
232(autoload 'byte-compile-inline-expand "byte-opt") 245(autoload 'byte-compile-inline-expand "byte-opt")
@@ -864,6 +877,11 @@ otherwise pop it")
864 877
865;;; compile-time evaluation 878;;; compile-time evaluation
866 879
880(defun byte-compile-cl-file-p (file)
881 "Return non-nil if FILE is one of the CL files."
882 (and (stringp file)
883 (string-match "^cl\\>" (file-name-nondirectory file))))
884
867(defun byte-compile-eval (form) 885(defun byte-compile-eval (form)
868 "Eval FORM and mark the functions defined therein. 886 "Eval FORM and mark the functions defined therein.
869Each function's symbol gets added to `byte-compile-noruntime-functions'." 887Each function's symbol gets added to `byte-compile-noruntime-functions'."
@@ -880,7 +898,15 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
880 old-autoloads) 898 old-autoloads)
881 ;; Make sure the file was not already loaded before. 899 ;; Make sure the file was not already loaded before.
882 (unless (or (assoc (car xs) hist-orig) 900 (unless (or (assoc (car xs) hist-orig)
883 (equal (car xs) "cl")) 901 ;; Don't give both the "noruntime" and
902 ;; "cl-functions" warning for the same function.
903 ;; FIXME This seems incorrect - these are two
904 ;; independent warnings. For example, you may be
905 ;; choosing to see the cl warnings but ignore them.
906 ;; You probably don't want to ignore noruntime in the
907 ;; same way.
908 (and (byte-compile-warning-enabled-p 'cl-functions)
909 (byte-compile-cl-file-p (car xs))))
884 (dolist (s xs) 910 (dolist (s xs)
885 (cond 911 (cond
886 ((symbolp s) 912 ((symbolp s)
@@ -900,21 +926,23 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
900 (push (cdr s) old-autoloads))))))) 926 (push (cdr s) old-autoloads)))))))
901 (when (byte-compile-warning-enabled-p 'cl-functions) 927 (when (byte-compile-warning-enabled-p 'cl-functions)
902 (let ((hist-new load-history)) 928 (let ((hist-new load-history))
903 ;; Go through load-history, look for newly loaded files 929 ;; Go through load-history, looking for the cl files.
904 ;; and mark all the functions defined therein. 930 ;; Since new files are added at the start of load-history,
905 (while (and hist-new (not (eq hist-new hist-orig))) 931 ;; we scan the new history until the tail matches the old.
906 (let ((xs (pop hist-new))) 932 (while (and (not byte-compile-cl-functions)
907 ;; Make sure the file was not already loaded before. 933 hist-new (not (eq hist-new hist-orig)))
908 (and (stringp (car xs)) 934 ;; We used to check if the file had already been loaded,
909 (string-match "^cl\\>" (file-name-nondirectory (car xs))) 935 ;; but it is better to check non-nil byte-compile-cl-functions.
910 (not (assoc (car xs) hist-orig)) 936 (and (byte-compile-cl-file-p (car (pop hist-new)))
911 (byte-compile-find-cl-functions))))))))) 937 (byte-compile-find-cl-functions))))))))
912 938
913(defun byte-compile-eval-before-compile (form) 939(defun byte-compile-eval-before-compile (form)
914 "Evaluate FORM for `eval-and-compile'." 940 "Evaluate FORM for `eval-and-compile'."
915 (let ((hist-nil-orig current-load-list)) 941 (let ((hist-nil-orig current-load-list))
916 (prog1 (eval form) 942 (prog1 (eval form)
917 ;; (eval-and-compile (require 'cl) turns off warnings for cl functions. 943 ;; (eval-and-compile (require 'cl) turns off warnings for cl functions.
944 ;; FIXME Why does it do that - just as a hack?
945 ;; There are other ways to do this nowadays.
918 (let ((tem current-load-list)) 946 (let ((tem current-load-list))
919 (while (not (eq tem hist-nil-orig)) 947 (while (not (eq tem hist-nil-orig))
920 (when (equal (car tem) '(require . cl)) 948 (when (equal (car tem) '(require . cl))
@@ -1409,15 +1437,16 @@ extra args."
1409(defvar byte-compile-cl-functions nil 1437(defvar byte-compile-cl-functions nil
1410 "List of functions defined in CL.") 1438 "List of functions defined in CL.")
1411 1439
1440;; Can't just add this to cl-load-hook, because that runs just before
1441;; the forms from cl.el get added to load-history.
1412(defun byte-compile-find-cl-functions () 1442(defun byte-compile-find-cl-functions ()
1413 (unless byte-compile-cl-functions 1443 (unless byte-compile-cl-functions
1414 (dolist (elt load-history) 1444 (dolist (elt load-history)
1415 (when (and (stringp (car elt)) 1445 (and (byte-compile-cl-file-p (car elt))
1416 (string-match 1446 (dolist (e (cdr elt))
1417 "^cl\\>" (file-name-nondirectory (car elt)))) 1447 ;; Includes the cl-foo functions that cl autoloads.
1418 (dolist (e (cdr elt)) 1448 (when (memq (car-safe e) '(autoload defun))
1419 (when (memq (car-safe e) '(autoload defun)) 1449 (push (cdr e) byte-compile-cl-functions)))))))
1420 (push (cdr e) byte-compile-cl-functions)))))))
1421 1450
1422(defun byte-compile-cl-warn (form) 1451(defun byte-compile-cl-warn (form)
1423 "Warn if FORM is a call of a function from the CL package." 1452 "Warn if FORM is a call of a function from the CL package."
@@ -2331,13 +2360,23 @@ list that represents a doc string reference.
2331 2360
2332(put 'require 'byte-hunk-handler 'byte-compile-file-form-require) 2361(put 'require 'byte-hunk-handler 'byte-compile-file-form-require)
2333(defun byte-compile-file-form-require (form) 2362(defun byte-compile-file-form-require (form)
2334 (let ((args (mapcar 'eval (cdr form)))) 2363 (let ((args (mapcar 'eval (cdr form)))
2364 (hist-orig load-history)
2365 hist-new)
2335 (apply 'require args) 2366 (apply 'require args)
2336 ;; Detect (require 'cl) in a way that works even if cl is already loaded. 2367 (when (byte-compile-warning-enabled-p 'cl-functions)
2337 (when (and (member (car args) '("cl" cl)) 2368 ;; Detect (require 'cl) in a way that works even if cl is already loaded.
2338 (byte-compile-warning-enabled-p 'cl-functions)) 2369 (if (member (car args) '("cl" cl))
2339 (byte-compile-warn "cl package required at runtime") 2370 (progn
2340 (byte-compile-disable-warning 'cl-functions))) 2371 (byte-compile-warn "cl package required at runtime")
2372 (byte-compile-disable-warning 'cl-functions))
2373 ;; We may have required something that causes cl to be loaded, eg
2374 ;; the uncompiled version of a file that requires cl when compiling.
2375 (setq hist-new load-history)
2376 (while (and (not byte-compile-cl-functions)
2377 hist-new (not (eq hist-new hist-orig)))
2378 (and (byte-compile-cl-file-p (car (pop hist-new)))
2379 (byte-compile-find-cl-functions))))))
2341 (byte-compile-keep-pending form 'byte-compile-normal-call)) 2380 (byte-compile-keep-pending form 'byte-compile-normal-call))
2342 2381
2343(put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn) 2382(put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn)