2018-09-07 21:49:49 -04:00
|
|
|
;;; core/cli/autoloads.el -*- lexical-binding: t; -*-
|
|
|
|
|
2019-07-22 06:02:21 +02:00
|
|
|
(defvar doom-autoload-excluded-packages '("gh")
|
2019-12-29 21:25:40 -05:00
|
|
|
"What packages whose autoloads file we won't index.
|
|
|
|
|
|
|
|
These packages have silly or destructive autoload files that try to load
|
2019-07-22 06:02:21 +02:00
|
|
|
everyone in the universe and their dog, causing errors that make babies cry. No
|
|
|
|
one wants that.")
|
|
|
|
|
2019-12-29 21:25:40 -05:00
|
|
|
(defvar doom-autoload-cached-vars
|
|
|
|
'(load-path
|
|
|
|
auto-mode-alist
|
2020-01-13 22:55:02 -05:00
|
|
|
interpreter-mode-alist
|
2019-12-29 21:25:40 -05:00
|
|
|
Info-directory-list
|
|
|
|
doom-disabled-packages)
|
|
|
|
"A list of variables to be cached in `doom-package-autoload-file'.")
|
|
|
|
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
;; externs
|
2019-07-22 06:02:21 +02:00
|
|
|
(defvar autoload-timestamps)
|
|
|
|
(defvar generated-autoload-load-name)
|
2018-09-07 21:49:49 -04:00
|
|
|
|
2020-01-01 13:31:40 -05:00
|
|
|
(defun doom-cli-reload-autoloads ()
|
|
|
|
"Reloads `doom-autoload-file' and `doom-package-autoload-file' files."
|
|
|
|
(doom-cli-reload-core-autoloads)
|
|
|
|
(doom-cli-reload-package-autoloads))
|
|
|
|
|
|
|
|
(defun doom-cli-reload-core-autoloads (&optional file)
|
2019-12-29 21:25:40 -05:00
|
|
|
(print! (start "(Re)generating core autoloads..."))
|
|
|
|
(print-group!
|
2020-01-24 18:15:56 -05:00
|
|
|
(let ((file (or file doom-autoload-file))
|
|
|
|
doom-autoload-cached-vars)
|
2020-01-01 13:31:40 -05:00
|
|
|
(cl-check-type file string)
|
|
|
|
(and (print! (start "Generating core autoloads..."))
|
|
|
|
(doom-cli--write-autoloads
|
2020-05-03 16:00:34 -04:00
|
|
|
file
|
|
|
|
(doom-cli--generate-emacs-version-check)
|
|
|
|
(doom-cli--generate-autoloads
|
|
|
|
(cl-loop for dir
|
|
|
|
in (append (list doom-core-dir)
|
|
|
|
(cdr (doom-module-load-path 'all-p))
|
|
|
|
(list doom-private-dir))
|
|
|
|
if (doom-glob dir "autoload.el") collect it
|
|
|
|
if (doom-glob dir "autoload/*.el") append it)
|
|
|
|
'scan))
|
2020-01-01 13:31:40 -05:00
|
|
|
(print! (start "Byte-compiling core autoloads file..."))
|
|
|
|
(doom-cli--byte-compile-file file)
|
|
|
|
(print! (success "Generated %s")
|
|
|
|
(relpath (byte-compile-dest-file file)
|
|
|
|
doom-emacs-dir))))))
|
|
|
|
|
|
|
|
(defun doom-cli-reload-package-autoloads (&optional file)
|
2019-12-29 21:25:40 -05:00
|
|
|
(print! (start "(Re)generating package autoloads..."))
|
|
|
|
(print-group!
|
|
|
|
(doom-initialize-packages)
|
2020-01-01 13:31:40 -05:00
|
|
|
(let ((file (or file doom-package-autoload-file)))
|
|
|
|
(cl-check-type file string)
|
|
|
|
(and (print! (start "Generating package autoloads..."))
|
|
|
|
(doom-cli--write-autoloads
|
|
|
|
file
|
|
|
|
(doom-cli--generate-var-cache doom-autoload-cached-vars)
|
|
|
|
(doom-cli--generate-autoloads
|
|
|
|
(mapcar #'straight--autoloads-file
|
|
|
|
(cl-set-difference (hash-table-keys straight--build-cache)
|
|
|
|
doom-autoload-excluded-packages
|
|
|
|
:test #'string=))))
|
|
|
|
(print! (start "Byte-compiling package autoloads file..."))
|
|
|
|
(doom-cli--byte-compile-file file)
|
|
|
|
(print! (success "Generated %s")
|
|
|
|
(relpath (byte-compile-dest-file file)
|
|
|
|
doom-emacs-dir))))))
|
2018-09-07 21:49:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-12-29 21:25:40 -05:00
|
|
|
;;; Helpers
|
2018-09-07 21:49:49 -04:00
|
|
|
|
2019-12-29 21:25:40 -05:00
|
|
|
(defun doom-cli--write-autoloads (file &rest forms)
|
|
|
|
(make-directory (file-name-directory file) 'parents)
|
|
|
|
(condition-case-unless-debug e
|
|
|
|
(with-temp-file file
|
|
|
|
(let ((standard-output (current-buffer))
|
|
|
|
(print-quoted t)
|
|
|
|
(print-level nil)
|
|
|
|
(print-length nil))
|
|
|
|
(insert ";; -*- lexical-binding: t; -*-\n"
|
|
|
|
";; This file is autogenerated by Doom, DO NOT EDIT IT!!\n")
|
|
|
|
(dolist (form (delq nil forms))
|
|
|
|
(mapc #'print form))
|
|
|
|
t))
|
|
|
|
(error (delete-file file)
|
|
|
|
(signal 'doom-autoload-error (list file e)))))
|
|
|
|
|
|
|
|
(defun doom-cli--byte-compile-file (file)
|
|
|
|
(condition-case-unless-debug e
|
|
|
|
(let ((byte-compile-warnings (if doom-debug-mode byte-compile-warnings))
|
|
|
|
(byte-compile-dynamic-docstrings t))
|
|
|
|
(when (byte-compile-file file)
|
|
|
|
(unless doom-interactive-mode
|
|
|
|
(add-hook 'doom-cli-post-success-execute-hook #'doom-cli--warn-refresh-session-h))
|
|
|
|
(load (byte-compile-dest-file file) nil t)))
|
|
|
|
(error
|
|
|
|
(delete-file (byte-compile-dest-file file))
|
|
|
|
(signal 'doom-autoload-error (list file e)))))
|
|
|
|
|
|
|
|
(defun doom-cli--warn-refresh-session-h ()
|
|
|
|
(print! "Restart or reload Doom Emacs for changes to take effect:")
|
|
|
|
(print-group! (print! "M-x doom/restart-and-restore")
|
|
|
|
(print! "M-x doom/restart")
|
|
|
|
(print! "M-x doom/reload")))
|
|
|
|
|
2020-05-03 16:00:34 -04:00
|
|
|
(defun doom-cli--generate-emacs-version-check ()
|
|
|
|
`((unless (equal emacs-major-version (eval-when-compile emacs-major-version))
|
|
|
|
(signal 'doom-error
|
|
|
|
(list "Your installed (major) version of Emacs has changed"
|
|
|
|
"Run 'doom sync && doom build' to bring Doom up to speed")))))
|
|
|
|
|
2019-12-29 21:25:40 -05:00
|
|
|
(defun doom-cli--generate-var-cache (vars)
|
|
|
|
`((setq ,@(cl-loop for var in vars
|
|
|
|
append `(,var ',(symbol-value var))))))
|
|
|
|
|
|
|
|
(defun doom-cli--filter-form (form &optional expand)
|
|
|
|
(let ((func (car-safe form)))
|
|
|
|
(cond ((memq func '(provide custom-autoload))
|
|
|
|
nil)
|
|
|
|
((and (eq func 'add-to-list)
|
|
|
|
(memq (doom-unquote (cadr form))
|
|
|
|
doom-autoload-cached-vars))
|
|
|
|
nil)
|
|
|
|
((not (eq func 'autoload))
|
|
|
|
form)
|
|
|
|
((and expand (not (file-name-absolute-p (nth 2 form))))
|
|
|
|
(defvar doom--autoloads-path-cache nil)
|
|
|
|
(setf (nth 2 form)
|
|
|
|
(let ((path (nth 2 form)))
|
|
|
|
(or (cdr (assoc path doom--autoloads-path-cache))
|
|
|
|
(when-let* ((libpath (locate-library path))
|
|
|
|
(libpath (file-name-sans-extension libpath))
|
|
|
|
(libpath (abbreviate-file-name libpath)))
|
|
|
|
(push (cons path libpath) doom--autoloads-path-cache)
|
|
|
|
libpath)
|
|
|
|
path)))
|
|
|
|
form)
|
|
|
|
(form))))
|
|
|
|
|
|
|
|
(defun doom-cli--generate-autoloads-autodefs (file buffer module &optional module-enabled-p)
|
2020-01-30 19:39:36 -05:00
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents file)
|
2019-07-21 15:39:45 +02:00
|
|
|
(while (re-search-forward "^;;;###autodef *\\([^\n]+\\)?\n" nil t)
|
2019-12-29 21:25:40 -05:00
|
|
|
(let* ((standard-output buffer)
|
|
|
|
(form (read (current-buffer)))
|
|
|
|
(altform (match-string 1))
|
|
|
|
(definer (car-safe form))
|
|
|
|
(symbol (doom-unquote (cadr form))))
|
|
|
|
(cond ((and (not module-enabled-p) altform)
|
|
|
|
(print (read altform)))
|
|
|
|
((memq definer '(defun defmacro cl-defun cl-defmacro))
|
|
|
|
(if module-enabled-p
|
|
|
|
(print (make-autoload form file))
|
|
|
|
(cl-destructuring-bind (_ _ arglist &rest body) form
|
|
|
|
(print
|
|
|
|
(if altform
|
|
|
|
(read altform)
|
|
|
|
(append
|
|
|
|
(list (pcase definer
|
|
|
|
(`defun 'defmacro)
|
|
|
|
(`cl-defun `cl-defmacro)
|
|
|
|
(_ type))
|
|
|
|
symbol arglist
|
|
|
|
(format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s"
|
|
|
|
module
|
|
|
|
(if (stringp (car body))
|
|
|
|
(pop body)
|
|
|
|
"No documentation.")))
|
|
|
|
(cl-loop for arg in arglist
|
|
|
|
if (and (symbolp arg)
|
|
|
|
(not (keywordp arg))
|
|
|
|
(not (memq arg cl--lambda-list-keywords)))
|
|
|
|
collect arg into syms
|
|
|
|
else if (listp arg)
|
|
|
|
collect (car arg) into syms
|
|
|
|
finally return (if syms `((ignore ,@syms)))))))))
|
|
|
|
(print `(put ',symbol 'doom-module ',module)))
|
|
|
|
((eq definer 'defalias)
|
|
|
|
(cl-destructuring-bind (_ _ target &optional docstring) form
|
|
|
|
(unless module-enabled-p
|
|
|
|
(setq target #'ignore
|
|
|
|
docstring
|
|
|
|
(format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s"
|
|
|
|
module docstring)))
|
|
|
|
(print `(put ',symbol 'doom-module ',module))
|
|
|
|
(print `(defalias ',symbol #',(doom-unquote target) ,docstring))))
|
|
|
|
(module-enabled-p (print form)))))))
|
|
|
|
|
|
|
|
(defun doom-cli--generate-autoloads-buffer (file)
|
2019-12-30 23:19:56 -05:00
|
|
|
(let* (;; Prevent `autoload-find-file' from firing file hooks, e.g. adding
|
|
|
|
;; to recentf.
|
|
|
|
find-file-hook
|
|
|
|
write-file-functions
|
|
|
|
;; Prevent a possible source of crashes when there's a syntax error
|
|
|
|
;; in the autoloads file
|
|
|
|
debug-on-error
|
|
|
|
;; The following bindings are in `package-generate-autoloads'.
|
|
|
|
;; Presumably for a good reason, so I just copied them
|
|
|
|
(backup-inhibited t)
|
|
|
|
(version-control 'never)
|
|
|
|
case-fold-search ; reduce magic
|
|
|
|
autoload-timestamps ; reduce noise in generated files
|
|
|
|
;; Needed for `autoload-generate-file-autoloads'
|
|
|
|
(generated-autoload-load-name (file-name-sans-extension file))
|
|
|
|
(target-buffer (current-buffer))
|
|
|
|
(module (doom-module-from-path file))
|
|
|
|
(module-enabled-p (and (or (memq (car module) '(:core :private))
|
|
|
|
(doom-module-p (car module) (cdr module)))
|
|
|
|
(doom-file-cookie-p file "if" t))))
|
|
|
|
(save-excursion
|
|
|
|
(when module-enabled-p
|
|
|
|
(quiet! (autoload-generate-file-autoloads file target-buffer)))
|
|
|
|
(doom-cli--generate-autoloads-autodefs
|
|
|
|
file target-buffer module module-enabled-p))))
|
2019-12-29 21:25:40 -05:00
|
|
|
|
|
|
|
(defun doom-cli--generate-autoloads (files &optional scan)
|
|
|
|
(require 'autoload)
|
|
|
|
(let (autoloads)
|
2019-12-30 17:06:49 -05:00
|
|
|
(dolist (file
|
|
|
|
(cl-remove-if-not #'file-readable-p files)
|
|
|
|
(nreverse (delq nil autoloads)))
|
|
|
|
(with-temp-buffer
|
2020-01-01 13:31:40 -05:00
|
|
|
(print! (debug "- Scanning %s") (relpath file doom-emacs-dir))
|
2019-12-30 17:06:49 -05:00
|
|
|
(if scan
|
|
|
|
(doom-cli--generate-autoloads-buffer file)
|
2020-01-01 03:01:30 -05:00
|
|
|
(insert-file-contents file))
|
2019-12-30 17:06:49 -05:00
|
|
|
(save-excursion
|
|
|
|
(let ((filestr (prin1-to-string file)))
|
|
|
|
(while (re-search-forward "\\_<load-file-name\\_>" nil t)
|
|
|
|
;; `load-file-name' is meaningless in a concatenated
|
|
|
|
;; mega-autoloads file, so we replace references to it with the
|
|
|
|
;; file they came from.
|
2020-01-04 17:13:05 -05:00
|
|
|
(let ((ppss (save-excursion (syntax-ppss))))
|
|
|
|
(or (nth 3 ppss)
|
|
|
|
(nth 4 ppss)
|
|
|
|
(replace-match filestr t t))))))
|
2019-12-30 17:06:49 -05:00
|
|
|
(let ((load-file-name file)
|
|
|
|
(load-path
|
|
|
|
(append (list doom-private-dir)
|
|
|
|
doom-modules-dirs
|
|
|
|
load-path)))
|
|
|
|
(condition-case _
|
|
|
|
(while t
|
|
|
|
(push (doom-cli--filter-form (read (current-buffer))
|
|
|
|
scan)
|
|
|
|
autoloads))
|
|
|
|
(end-of-file)))))))
|