<commit_before>;;; core/cli/byte-compile.el -*- lexical-binding: t; -*-

(defcli! (compile c)
    ((recompile-p ["-r" "--recompile"])
     &rest targets)
  "Byte-compiles your config or selected modules.

  compile [TARGETS...]
  compile :core :private lang/python
  compile feature lang

Accepts :core and :private as special arguments, which target Doom's core files
and your private config files, respectively. To recompile your packages, use
'doom rebuild' instead."
  (doom-cli-byte-compile targets recompile-p))

(defcli! clean ()
  "Delete all *.elc files."
  :bare t
  (doom-clean-byte-compiled-files))


;;
;; Helpers

(defun doom--byte-compile-ignore-file-p (path)
  (let ((filename (file-name-nondirectory path)))
    (or (string-prefix-p "." filename)
        (string-prefix-p "test-" filename)
        (not (equal (file-name-extension path) "el"))
        (member filename (list "packages.el" "doctor.el")))))

(cl-defun doom-cli-byte-compile (&optional modules recompile-p)
  "Byte compiles your emacs configuration.

init.el is always byte-compiled by this.

If MODULES is specified (a list of module strings, e.g. \"lang/php\"), those are
byte-compiled. Otherwise, all enabled modules are byte-compiled, including Doom
core. It always ignores unit tests and files with `no-byte-compile' enabled.

WARNING: byte-compilation yields marginal gains and makes debugging new issues
difficult. It is recommended you don't use it unless you understand the
reprecussions.

Use `doom-clean-byte-compiled-files' or `make clean' to reverse
byte-compilation.

If RECOMPILE-P is non-nil, only recompile out-of-date files."
  (let ((default-directory doom-emacs-dir)
        (doom-modules (doom-modules))
        (byte-compile-verbose doom-debug-mode)
        (byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))

        ;; In case it is changed during compile-time
        (auto-mode-alist auto-mode-alist)
        (noninteractive t)

        targets)

    (let (target-dirs)
      (dolist (module (delete-dups modules))
        (pcase module
          (":core"
           (push (doom-glob doom-emacs-dir "init.el") targets)
           (push doom-core-dir target-dirs))
          (":private"
           (push doom-private-dir target-dirs))
          ((pred file-directory-p)
           (push module target-dirs))
          ((pred (string-match "^\\([^/]+\\)/\\([^/]+\\)$"))
           (push (doom-module-locate-path
                  (doom-keyword-intern (match-string 1 module))
                  (intern (match-string 2 module)))
                 target-dirs))
          (_ (user-error "%S is not a valid target" module))))

      (and (or (null modules) (member ":private" modules))
           (not recompile-p)
           (not (or doom-auto-accept
                    (y-or-n-p
                     (concat "Warning: byte compiling is for advanced users. It will interfere with your\n"
                             "efforts to debug issues. It is not recommended you do it if you frequently\n"
                             "tinker with your Emacs config.\n\n"
                             "Alternatively, use `bin/doom compile :core` instead to byte-compile only the\n"
                             "Doom core files, as these don't change often.\n\n"
                             "If you have issues, please make sure byte-compilation isn't the cause by using\n"
                             "`bin/doom clean` to clear out your *.elc files.\n\n"
                             "Byte-compile anyway?"))))
           (user-error "Aborting"))

      ;; But first we must be sure that Doom and your private config have been
      ;; fully loaded. Which usually aren't so in an noninteractive session.
      (let ((doom-interactive-mode 'byte-compile))
        (doom-initialize 'force)
        (doom-initialize-core))

      ;;
      (unless target-dirs
        (push (doom-glob doom-emacs-dir "init.el") targets)
        ;; If no targets were supplied, then we use your module list.
        (appendq! target-dirs
                  (list doom-core-dir)
                  (nreverse
                   (cl-remove-if-not
                    (lambda (path) (file-in-directory-p path doom-emacs-dir))
                    ;; Omit `doom-private-dir', which is always first
                    (cdr (doom-module-load-path))))))

      ;; Assemble el files we want to compile; taking into account that MODULES<commit_msg>Fix #2104: prevent double-package-init on 'doom refresh'<commit_after>;;; core/cli/byte-compile.el -*- lexical-binding: t; -*-

(defcli! (compile c)
    ((recompile-p ["-r" "--recompile"])
     &rest targets)
  "Byte-compiles your config or selected modules.

  compile [TARGETS...]
  compile :core :private lang/python
  compile feature lang

Accepts :core and :private as special arguments, which target Doom's core files
and your private config files, respectively. To recompile your packages, use
'doom rebuild' instead."
  (doom-cli-byte-compile targets recompile-p))

(defcli! clean ()
  "Delete all *.elc files."
  :bare t
  (doom-clean-byte-compiled-files))


;;
;; Helpers

(defun doom--byte-compile-ignore-file-p (path)
  (let ((filename (file-name-nondirectory path)))
    (or (string-prefix-p "." filename)
        (string-prefix-p "test-" filename)
        (not (equal (file-name-extension path) "el"))
        (member filename (list "packages.el" "doctor.el")))))

(cl-defun doom-cli-byte-compile (&optional modules recompile-p)
  "Byte compiles your emacs configuration.

init.el is always byte-compiled by this.

If MODULES is specified (a list of module strings, e.g. \"lang/php\"), those are
byte-compiled. Otherwise, all enabled modules are byte-compiled, including Doom
core. It always ignores unit tests and files with `no-byte-compile' enabled.

WARNING: byte-compilation yields marginal gains and makes debugging new issues
difficult. It is recommended you don't use it unless you understand the
reprecussions.

Use `doom-clean-byte-compiled-files' or `make clean' to reverse
byte-compilation.

If RECOMPILE-P is non-nil, only recompile out-of-date files."
  (let ((default-directory doom-emacs-dir)
        (doom-modules (doom-modules))
        (byte-compile-verbose doom-debug-mode)
        (byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))

        ;; In case it is changed during compile-time
        (auto-mode-alist auto-mode-alist)
        (noninteractive t)

        targets)

    (let (target-dirs)
      (dolist (module (delete-dups modules))
        (pcase module
          (":core"
           (push (doom-glob doom-emacs-dir "init.el") targets)
           (push doom-core-dir target-dirs))
          (":private"
           (push doom-private-dir target-dirs))
          ((pred file-directory-p)
           (push module target-dirs))
          ((pred (string-match "^\\([^/]+\\)/\\([^/]+\\)$"))
           (push (doom-module-locate-path
                  (doom-keyword-intern (match-string 1 module))
                  (intern (match-string 2 module)))
                 target-dirs))
          (_ (user-error "%S is not a valid target" module))))

      (and (or (null modules) (member ":private" modules))
           (not recompile-p)
           (not (or doom-auto-accept
                    (y-or-n-p
                     (concat "Warning: byte compiling is for advanced users. It will interfere with your\n"
                             "efforts to debug issues. It is not recommended you do it if you frequently\n"
                             "tinker with your Emacs config.\n\n"
                             "Alternatively, use `bin/doom compile :core` instead to byte-compile only the\n"
                             "Doom core files, as these don't change often.\n\n"
                             "If you have issues, please make sure byte-compilation isn't the cause by using\n"
                             "`bin/doom clean` to clear out your *.elc files.\n\n"
                             "Byte-compile anyway?"))))
           (user-error "Aborting"))

      ;; But first we must be sure that Doom and your private config have been
      ;; fully loaded. Which usually aren't so in an noninteractive session.
      (let ((doom-interactive-mode 'byte-compile))
        (doom-initialize)
        (doom-initialize-packages)
        (doom-initialize-core))

      ;;
      (unless target-dirs
        (push (doom-glob doom-emacs-dir "init.el") targets)
        ;; If no targets were supplied, then we use your module list.
        (appendq! target-dirs
                  (list doom-core-dir)
                  (nreverse
                   (cl-remove-if-not
                    (lambda (path) (file-in-directory-p path doom-emacs-dir))
                    ;; Omit `doom-private-dir', which is always first
                    (cdr (doom-module-load-path))))))

      ;; Assemble el files we want to compile; taking into account that MODULES
{'fraction_non_alphanumeric': 0.11831080326220535, 'fraction_numerical': 0.0008937548877220422, 'mean_word_length': 2.1487864931410483, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1844033', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2538, 'n_words': 839}