Commit 3f12e5bd authored by Glenn Morris's avatar Glenn Morris
Browse files

(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.
parent 604f2fc0
2009-09-05 Glenn Morris <rgm@gnu.org>
* emacs-lisp/bytecomp.el (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.
2009-09-05 Karl Fogel <kfogel@red-bean.com> 2009-09-05 Karl Fogel <kfogel@red-bean.com>
* files.el (find-alternate-file): Run `kill-buffer-hook' manually * files.el (find-alternate-file): Run `kill-buffer-hook' manually
......
...@@ -200,11 +200,18 @@ ...@@ -200,11 +200,18 @@
(defcustom emacs-lisp-file-regexp "\\.el\\'" (defcustom emacs-lisp-file-regexp "\\.el\\'"
"Regexp which matches Emacs Lisp source files. "Regexp which matches Emacs Lisp source files.
You may want to redefine the function `byte-compile-dest-file' If you change this, you might want to set `byte-compile-dest-file-function'."
if you change this variable."
:group 'bytecomp :group 'bytecomp
:type 'regexp) :type 'regexp)
(defcustom byte-compile-dest-file-function nil
"Function for the function `byte-compile-dest-file' to call.
It should take one argument, the name of an Emacs Lisp source
file name, and return the name of the compiled file."
:group 'bytecomp
:type '(choice (const nil) function)
:version "23.2")
;; This enables file name handlers such as jka-compr ;; This enables file name handlers such as jka-compr
;; to remove parts of the file name that should not be copied ;; to remove parts of the file name that should not be copied
;; through to the output file name. ;; through to the output file name.
...@@ -218,15 +225,21 @@ if you change this variable." ...@@ -218,15 +225,21 @@ if you change this variable."
(or (fboundp 'byte-compile-dest-file) (or (fboundp 'byte-compile-dest-file)
;; The user may want to redefine this along with emacs-lisp-file-regexp, ;; The user may want to redefine this along with emacs-lisp-file-regexp,
;; so only define it if it is undefined. ;; so only define it if it is undefined.
;; Note - redefining this function is obsolete as of 23.2.
;; Customize byte-compile-dest-file-function instead.
(defun byte-compile-dest-file (filename) (defun byte-compile-dest-file (filename)
"Convert an Emacs Lisp source file name to a compiled file name. "Convert an Emacs Lisp source file name to a compiled file name.
If FILENAME matches `emacs-lisp-file-regexp' (by default, files If `byte-compile-dest-file-function' is non-nil, uses that
with the extension `.el'), add `c' to it; otherwise add `.elc'." function to do the work. Otherwise, if FILENAME matches
(setq filename (byte-compiler-base-file-name filename)) `emacs-lisp-file-regexp' (by default, files with the extension `.el'),
(setq filename (file-name-sans-versions filename)) adds `c' to it; otherwise adds `.elc'."
(cond ((string-match emacs-lisp-file-regexp filename) (if byte-compile-dest-file-function
(concat (substring filename 0 (match-beginning 0)) ".elc")) (funcall byte-compile-dest-file-function filename)
(t (concat filename ".elc"))))) (setq filename (file-name-sans-versions
(byte-compiler-base-file-name filename)))
(cond ((string-match emacs-lisp-file-regexp filename)
(concat (substring filename 0 (match-beginning 0)) ".elc"))
(t (concat filename ".elc"))))))
;; This can be the 'byte-compile property of any symbol. ;; This can be the 'byte-compile property of any symbol.
(autoload 'byte-compile-inline-expand "byte-opt") (autoload 'byte-compile-inline-expand "byte-opt")
...@@ -864,6 +877,11 @@ otherwise pop it") ...@@ -864,6 +877,11 @@ otherwise pop it")
;;; compile-time evaluation ;;; compile-time evaluation
(defun byte-compile-cl-file-p (file)
"Return non-nil if FILE is one of the CL files."
(and (stringp file)
(string-match "^cl\\>" (file-name-nondirectory file))))
(defun byte-compile-eval (form) (defun byte-compile-eval (form)
"Eval FORM and mark the functions defined therein. "Eval FORM and mark the functions defined therein.
Each function's symbol gets added to `byte-compile-noruntime-functions'." Each 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,7 +898,15 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
old-autoloads) old-autoloads)
;; Make sure the file was not already loaded before. ;; Make sure the file was not already loaded before.
(unless (or (assoc (car xs) hist-orig) (unless (or (assoc (car xs) hist-orig)
(equal (car xs) "cl")) ;; Don't give both the "noruntime" and
;; "cl-functions" warning for the same function.
;; FIXME This seems incorrect - these are two
;; independent warnings. For example, you may be
;; choosing to see the cl warnings but ignore them.
;; You probably don't want to ignore noruntime in the
;; same way.
(and (byte-compile-warning-enabled-p 'cl-functions)
(byte-compile-cl-file-p (car xs))))
(dolist (s xs) (dolist (s xs)
(cond (cond
((symbolp s) ((symbolp s)
...@@ -900,21 +926,23 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'." ...@@ -900,21 +926,23 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'."
(push (cdr s) old-autoloads))))))) (push (cdr s) old-autoloads)))))))
(when (byte-compile-warning-enabled-p 'cl-functions) (when (byte-compile-warning-enabled-p 'cl-functions)
(let ((hist-new load-history)) (let ((hist-new load-history))
;; Go through load-history, look for newly loaded files ;; Go through load-history, looking for the cl files.
;; and mark all the functions defined therein. ;; Since new files are added at the start of load-history,
(while (and hist-new (not (eq hist-new hist-orig))) ;; we scan the new history until the tail matches the old.
(let ((xs (pop hist-new))) (while (and (not byte-compile-cl-functions)
;; Make sure the file was not already loaded before. hist-new (not (eq hist-new hist-orig)))
(and (stringp (car xs)) ;; We used to check if the file had already been loaded,
(string-match "^cl\\>" (file-name-nondirectory (car xs))) ;; but it is better to check non-nil byte-compile-cl-functions.
(not (assoc (car xs) hist-orig)) (and (byte-compile-cl-file-p (car (pop hist-new)))
(byte-compile-find-cl-functions))))))))) (byte-compile-find-cl-functions))))))))
(defun byte-compile-eval-before-compile (form) (defun byte-compile-eval-before-compile (form)
"Evaluate FORM for `eval-and-compile'." "Evaluate FORM for `eval-and-compile'."
(let ((hist-nil-orig current-load-list)) (let ((hist-nil-orig current-load-list))
(prog1 (eval form) (prog1 (eval form)
;; (eval-and-compile (require 'cl) turns off warnings for cl functions. ;; (eval-and-compile (require 'cl) turns off warnings for cl functions.
;; FIXME Why does it do that - just as a hack?
;; There are other ways to do this nowadays.
(let ((tem current-load-list)) (let ((tem current-load-list))
(while (not (eq tem hist-nil-orig)) (while (not (eq tem hist-nil-orig))
(when (equal (car tem) '(require . cl)) (when (equal (car tem) '(require . cl))
...@@ -1409,15 +1437,16 @@ extra args." ...@@ -1409,15 +1437,16 @@ extra args."
(defvar byte-compile-cl-functions nil (defvar byte-compile-cl-functions nil
"List of functions defined in CL.") "List of functions defined in CL.")
;; Can't just add this to cl-load-hook, because that runs just before
;; the forms from cl.el get added to load-history.
(defun byte-compile-find-cl-functions () (defun byte-compile-find-cl-functions ()
(unless byte-compile-cl-functions (unless byte-compile-cl-functions
(dolist (elt load-history) (dolist (elt load-history)
(when (and (stringp (car elt)) (and (byte-compile-cl-file-p (car elt))
(string-match (dolist (e (cdr elt))
"^cl\\>" (file-name-nondirectory (car elt)))) ;; Includes the cl-foo functions that cl autoloads.
(dolist (e (cdr elt)) (when (memq (car-safe e) '(autoload defun))
(when (memq (car-safe e) '(autoload defun)) (push (cdr e) byte-compile-cl-functions)))))))
(push (cdr e) byte-compile-cl-functions)))))))
(defun byte-compile-cl-warn (form) (defun byte-compile-cl-warn (form)
"Warn if FORM is a call of a function from the CL package." "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,13 +2360,23 @@ list that represents a doc string reference.
(put 'require 'byte-hunk-handler 'byte-compile-file-form-require) (put 'require 'byte-hunk-handler 'byte-compile-file-form-require)
(defun byte-compile-file-form-require (form) (defun byte-compile-file-form-require (form)
(let ((args (mapcar 'eval (cdr form)))) (let ((args (mapcar 'eval (cdr form)))
(hist-orig load-history)
hist-new)
(apply 'require args) (apply 'require args)
;; Detect (require 'cl) in a way that works even if cl is already loaded. (when (byte-compile-warning-enabled-p 'cl-functions)
(when (and (member (car args) '("cl" cl)) ;; Detect (require 'cl) in a way that works even if cl is already loaded.
(byte-compile-warning-enabled-p 'cl-functions)) (if (member (car args) '("cl" cl))
(byte-compile-warn "cl package required at runtime") (progn
(byte-compile-disable-warning 'cl-functions))) (byte-compile-warn "cl package required at runtime")
(byte-compile-disable-warning 'cl-functions))
;; We may have required something that causes cl to be loaded, eg
;; the uncompiled version of a file that requires cl when compiling.
(setq hist-new load-history)
(while (and (not byte-compile-cl-functions)
hist-new (not (eq hist-new hist-orig)))
(and (byte-compile-cl-file-p (car (pop hist-new)))
(byte-compile-find-cl-functions))))))
(byte-compile-keep-pending form 'byte-compile-normal-call)) (byte-compile-keep-pending form 'byte-compile-normal-call))
(put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn) (put 'progn 'byte-hunk-handler 'byte-compile-file-form-progn)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment