2018-09-07 21:49:49 -04:00
|
|
|
;;; core/cli/autoloads.el -*- lexical-binding: t; -*-
|
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defvar doom-autoloads-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.")
|
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defvar doom-autoloads-cached-vars
|
|
|
|
'(doom-modules
|
|
|
|
doom-disabled-packages
|
|
|
|
load-path
|
2019-12-29 21:25:40 -05:00
|
|
|
auto-mode-alist
|
2020-01-13 22:55:02 -05:00
|
|
|
interpreter-mode-alist
|
2020-05-25 03:36:38 -04:00
|
|
|
Info-directory-list)
|
2020-08-24 00:36:52 -04:00
|
|
|
"A list of variables to be cached in `doom-autoloads-file'.")
|
2019-12-29 21:25:40 -05:00
|
|
|
|
2020-05-26 04:15:46 -04:00
|
|
|
(defvar doom-autoloads-files ()
|
|
|
|
"A list of additional files or file globs to scan for autoloads.")
|
|
|
|
|
2018-09-07 21:49:49 -04:00
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
;;
|
|
|
|
;;; Library
|
2020-01-01 13:31:40 -05:00
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defun doom-autoloads-reload (&optional file)
|
|
|
|
"Regenerates Doom's autoloads and writes them to FILE."
|
|
|
|
(unless file
|
2020-08-24 00:36:52 -04:00
|
|
|
(setq file doom-autoloads-file))
|
2020-05-25 03:36:38 -04:00
|
|
|
(print! (start "(Re)generating autoloads file..."))
|
2019-12-29 21:25:40 -05:00
|
|
|
(print-group!
|
2020-05-25 03:36:38 -04:00
|
|
|
(cl-check-type file string)
|
2019-12-29 21:25:40 -05:00
|
|
|
(doom-initialize-packages)
|
2020-05-25 03:36:38 -04:00
|
|
|
(and (print! (start "Generating autoloads file..."))
|
|
|
|
(doom-autoloads--write
|
|
|
|
file
|
|
|
|
`((unless (equal emacs-major-version ,emacs-major-version)
|
|
|
|
(signal 'doom-error
|
|
|
|
(list "The installed version of Emacs has changed since last 'doom sync' ran"
|
|
|
|
"Run 'doom sync && doom build' to bring Doom up to speed")))
|
|
|
|
(unless (equal doom-version ,doom-version)
|
|
|
|
(signal 'doom-error
|
|
|
|
(list "The installed version of Doom has changed since last 'doom sync' ran"
|
|
|
|
"Run 'doom sync' to bring Doom up to speed"))))
|
|
|
|
(mapcar (lambda (var) `(set ',var ',(symbol-value var)))
|
|
|
|
doom-autoloads-cached-vars)
|
|
|
|
(doom-autoloads--scan
|
2020-05-26 04:15:46 -04:00
|
|
|
(append (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)
|
|
|
|
(mapcan #'doom-glob doom-autoloads-files)))
|
2020-05-25 03:36:38 -04:00
|
|
|
(doom-autoloads--scan
|
|
|
|
(mapcar #'straight--autoloads-file
|
2020-05-26 04:18:20 -04:00
|
|
|
(seq-difference (hash-table-keys straight--build-cache)
|
|
|
|
doom-autoloads-excluded-packages))
|
2020-05-25 03:36:38 -04:00
|
|
|
'literal))
|
|
|
|
(print! (start "Byte-compiling autoloads file..."))
|
|
|
|
(doom-autoloads--compile-file file)
|
|
|
|
(print! (success "Generated %s")
|
|
|
|
(relpath (byte-compile-dest-file file)
|
|
|
|
doom-emacs-dir)))))
|
|
|
|
|
|
|
|
(defun doom-autoloads--write (file &rest forms)
|
2019-12-29 21:25:40 -05:00
|
|
|
(make-directory (file-name-directory file) 'parents)
|
|
|
|
(condition-case-unless-debug e
|
|
|
|
(with-temp-file file
|
2020-05-25 03:36:38 -04:00
|
|
|
(setq-local coding-system-for-write 'utf-8)
|
2019-12-29 21:25:40 -05:00
|
|
|
(let ((standard-output (current-buffer))
|
|
|
|
(print-quoted t)
|
|
|
|
(print-level nil)
|
|
|
|
(print-length nil))
|
2020-05-25 03:36:38 -04:00
|
|
|
(insert ";; -*- lexical-binding: t; coding: utf-8; -*-\n"
|
|
|
|
";; This file is autogenerated by 'doom sync', DO NOT EDIT IT!!\n")
|
2019-12-29 21:25:40 -05:00
|
|
|
(dolist (form (delq nil forms))
|
2020-05-25 03:36:38 -04:00
|
|
|
(mapc #'prin1 form))
|
2019-12-29 21:25:40 -05:00
|
|
|
t))
|
|
|
|
(error (delete-file file)
|
|
|
|
(signal 'doom-autoload-error (list file e)))))
|
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defun doom-autoloads--compile-file (file)
|
2019-12-29 21:25:40 -05:00
|
|
|
(condition-case-unless-debug e
|
2020-05-25 03:36:38 -04:00
|
|
|
(let ((byte-compile-warnings (if doom-debug-p byte-compile-warnings)))
|
2020-05-26 04:09:11 -04:00
|
|
|
(and (byte-compile-file file)
|
|
|
|
(load (byte-compile-dest-file file) nil t)))
|
2019-12-29 21:25:40 -05:00
|
|
|
(error
|
|
|
|
(delete-file (byte-compile-dest-file file))
|
|
|
|
(signal 'doom-autoload-error (list file e)))))
|
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defun doom-autoloads--cleanup-form (form &optional expand)
|
2019-12-29 21:25:40 -05:00
|
|
|
(let ((func (car-safe form)))
|
|
|
|
(cond ((memq func '(provide custom-autoload))
|
|
|
|
nil)
|
|
|
|
((and (eq func 'add-to-list)
|
|
|
|
(memq (doom-unquote (cadr form))
|
2020-05-25 03:36:38 -04:00
|
|
|
doom-autoloads-cached-vars))
|
2019-12-29 21:25:40 -05:00
|
|
|
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))))
|
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defun doom-autoloads--scan-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)))))))
|
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defvar autoload-timestamps)
|
|
|
|
(defvar generated-autoload-load-name)
|
|
|
|
(defun doom-autoloads--scan-file (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)))
|
2020-05-25 03:36:38 -04:00
|
|
|
(doom-autoloads--scan-autodefs
|
2019-12-30 23:19:56 -05:00
|
|
|
file target-buffer module module-enabled-p))))
|
2019-12-29 21:25:40 -05:00
|
|
|
|
2020-05-25 03:36:38 -04:00
|
|
|
(defun doom-autoloads--scan (files &optional literal)
|
2019-12-29 21:25:40 -05:00
|
|
|
(require 'autoload)
|
|
|
|
(let (autoloads)
|
2019-12-30 17:06:49 -05:00
|
|
|
(dolist (file
|
2020-05-26 04:18:20 -04:00
|
|
|
(seq-filter #'file-readable-p files)
|
2019-12-30 17:06:49 -05:00
|
|
|
(nreverse (delq nil autoloads)))
|
|
|
|
(with-temp-buffer
|
2020-01-01 13:31:40 -05:00
|
|
|
(print! (debug "- Scanning %s") (relpath file doom-emacs-dir))
|
2020-05-25 03:36:38 -04:00
|
|
|
(if literal
|
|
|
|
(insert-file-contents file)
|
|
|
|
(doom-autoloads--scan-file 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
|
2020-05-25 03:36:38 -04:00
|
|
|
(push (doom-autoloads--cleanup-form (read (current-buffer))
|
|
|
|
(not literal))
|
2019-12-30 17:06:49 -05:00
|
|
|
autoloads))
|
|
|
|
(end-of-file)))))))
|