Function: batch-byte-compile

batch-byte-compile is an autoloaded and byte-compiled function defined in bytecomp.el.gz.

Signature

(batch-byte-compile &optional NOFORCE)

Documentation

Run byte-compile-file on the files remaining on the command line.

Use this from the command line, with -batch; it won't work in an interactive Emacs.

Each file is processed even if an error occurred previously. If a file name denotes a directory, all Emacs Lisp source files in that directory (that have previously been compiled) will be recompiled if newer than the compiled files. In this case, NOFORCE is ignored.

For example, invoke "emacs -batch -f batch-byte-compile $emacs/ ~/*.el".

If NOFORCE is non-nil, don't recompile a file that seems to be already up-to-date.

View in manual

Probably introduced at or before Emacs version 17.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
;;; by crl@newton.purdue.edu
;;;  Only works noninteractively.
;;;###autoload
(defun batch-byte-compile (&optional noforce)
  "Run `byte-compile-file' on the files remaining on the command line.
Use this from the command line, with `-batch';
it won't work in an interactive Emacs.

Each file is processed even if an error occurred previously.  If
a file name denotes a directory, all Emacs Lisp source files in
that directory (that have previously been compiled) will be
recompiled if newer than the compiled files.  In this case,
NOFORCE is ignored.

For example, invoke \"emacs -batch -f batch-byte-compile $emacs/ ~/*.el\".

If NOFORCE is non-nil, don't recompile a file that seems to be
already up-to-date."
  ;; command-line-args-left is what is left of the command line, from
  ;; startup.el.
  (defvar command-line-args-left)	;Avoid 'free variable' warning
  (if (not noninteractive)
      (error "`batch-byte-compile' is to be used only with -batch"))
  ;; Better crash loudly than attempting to recover from undefined
  ;; behavior.
  (setq attempt-stack-overflow-recovery nil
        attempt-orderly-shutdown-on-fatal-signal nil)
  (let ((error nil))
    (while command-line-args-left
      (if (file-directory-p (expand-file-name (car command-line-args-left)))
	  ;; Directory as argument.
	  (let (source dest)
	    (dolist (file (directory-files (car command-line-args-left)))
	      (if (and (string-match emacs-lisp-file-regexp file)
		       (not (auto-save-file-name-p file))
		       (setq source
                             (expand-file-name file
                                               (car command-line-args-left)))
		       (setq dest (byte-compile-dest-file source))
		       (file-exists-p dest)
		       (file-newer-than-file-p source dest))
		  (if (null (batch-byte-compile-file source))
		      (setq error t)))))
	;; Specific file argument
	(if (or (not noforce)
		(let* ((source (car command-line-args-left))
		       (dest (byte-compile-dest-file source)))
		  (or (not (file-exists-p dest))
		      (file-newer-than-file-p source dest))))
	    (if (null (batch-byte-compile-file (car command-line-args-left)))
                (setq error t))))
      (setq command-line-args-left (cdr command-line-args-left)))
    (kill-emacs (if error 1 0))))