Function: byte-recompile-directory

byte-recompile-directory is an autoloaded, interactive and byte-compiled function defined in bytecomp.el.gz.

Signature

(byte-recompile-directory DIRECTORY &optional ARG FORCE FOLLOW-SYMLINKS)

Documentation

Recompile every .el file in DIRECTORY that needs recompilation.

This happens when a .elc file exists but is older than the .el file. Files in subdirectories of DIRECTORY are processed also.

If the .elc file does not exist, normally this function *does not* compile the corresponding .el file. However, if the prefix argument ARG is 0, that means do compile all those files. A nonzero ARG means ask the user, for each such .el file, whether to compile it. A nonzero ARG also means ask about each subdirectory before scanning it.

If the third argument FORCE is non-nil, recompile every .el file that already has a .elc file.

This command will normally not follow symlinks when compiling files. If FOLLOW-SYMLINKS is non-nil, symlinked .el files will also be compiled.

View in manual

Probably introduced at or before Emacs version 1.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
;;;###autoload
(defun byte-recompile-directory (directory &optional arg force follow-symlinks)
  "Recompile every `.el' file in DIRECTORY that needs recompilation.
This happens when a `.elc' file exists but is older than the `.el' file.
Files in subdirectories of DIRECTORY are processed also.

If the `.elc' file does not exist, normally this function *does not*
compile the corresponding `.el' file.  However, if the prefix argument
ARG is 0, that means do compile all those files.  A nonzero
ARG means ask the user, for each such `.el' file, whether to
compile it.  A nonzero ARG also means ask about each subdirectory
before scanning it.

If the third argument FORCE is non-nil, recompile every `.el' file
that already has a `.elc' file.

This command will normally not follow symlinks when compiling
files.  If FOLLOW-SYMLINKS is non-nil, symlinked `.el' files will
also be compiled."
  (interactive "DByte recompile directory: \nP")
  (if arg (setq arg (prefix-numeric-value arg)))
  (if noninteractive
      nil
    (save-some-buffers
     nil (lambda ()
           (let ((file (buffer-file-name)))
             (and file
                  (string-match-p emacs-lisp-file-regexp file)
                  (file-in-directory-p file directory)))))
    (force-mode-line-update))
  (with-current-buffer (get-buffer-create byte-compile-log-buffer)
    (setq default-directory (expand-file-name directory))
    ;; compilation-mode copies value of default-directory.
    (unless (derived-mode-p 'compilation-mode)
      (emacs-lisp-compilation-mode))
    (let ((directories (list default-directory))
	  (default-directory default-directory)
          (ignore-files-regexp
           (if byte-compile-ignore-files
               (mapconcat #'identity byte-compile-ignore-files "\\|")
             regexp-unmatchable))
	  (skip-count 0)
	  (fail-count 0)
	  (file-count 0)
	  (dir-count 0)
	  last-dir)
      (displaying-byte-compile-warnings
       (while directories
	 (setq directory (car directories))
	 (message "Checking %s..." directory)
         (dolist (source (directory-files directory t))
           (let ((file (file-name-nondirectory source)))
	     (if (file-directory-p source)
		 (and (not (member file '("RCS" "CVS")))
		      (not (eq ?\. (aref file 0)))
                      (or follow-symlinks
                          (not (file-symlink-p source)))
		      ;; This file is a subdirectory.  Handle them differently.
		      (or (null arg) (eq 0 arg)
			  (y-or-n-p (concat "Check " source "? ")))
                      ;; Directory is requested to be ignored
                      (not (string-match-p ignore-files-regexp source))
                      (setq directories (nconc directories (list source))))
               ;; It is an ordinary file.  Decide whether to compile it.
               (if (and (string-match emacs-lisp-file-regexp source)
			;; The next 2 tests avoid compiling lock files
                        (file-readable-p source)
			(not (string-match "\\`\\.#" file))
                        (not (auto-save-file-name-p source))
                        (not (member source (dir-locals--all-files directory)))
                        ;; File is requested to be ignored
                        (not (string-match-p ignore-files-regexp source)))
                   (progn (incf
                           (pcase (byte-recompile-file source force arg)
                             ('no-byte-compile skip-count)
                             ('t file-count)
                             (_ fail-count)))
                          (or noninteractive
                              (message "Checking %s..." directory))
                          (if (not (eq last-dir directory))
                              (setq last-dir directory
                                    dir-count (1+ dir-count)))
                          )))))
	 (setq directories (cdr directories))))
      (message "Done (Total of %d file%s compiled%s%s%s)"
	       file-count (if (= file-count 1) "" "s")
	       (if (> fail-count 0) (format ", %d failed" fail-count) "")
	       (if (> skip-count 0) (format ", %d skipped" skip-count) "")
	       (if (> dir-count 1)
                   (format " in %d directories" dir-count) "")))))