Optimize make autoloads & improve path expansion
Make autoloads will expand the include paths of Doom autoload cookies. This fixes an issue where paths were expanded to include a file extension, bypassing the benefits of byte-compilation.
This commit is contained in:
parent
b4a7e5348a
commit
3e6d7f174a
1 changed files with 47 additions and 25 deletions
|
@ -155,6 +155,7 @@ and `auto-mode-alist'.")
|
|||
(insert ";;; -*- lexical-binding:t -*-\n"
|
||||
";; This file was autogenerated by `doom|refresh-cache', DO NOT EDIT!\n")
|
||||
(prin1 `(setq load-path ',load-path
|
||||
auto-mode-alist ',auto-mode-alist
|
||||
Info-directory-list ',Info-directory-list
|
||||
doom-disabled-packages ',doom-disabled-packages
|
||||
package-activated-list ',package-activated-list)
|
||||
|
@ -742,7 +743,7 @@ This should be run whenever init.el or an autoload file is modified. Running
|
|||
;; in case this function has side effects.
|
||||
(progn
|
||||
(doom-packages--async-run 'doom//reload-autoloads)
|
||||
(load doom-autoload-file t nil t))
|
||||
(load doom-autoload-file 'noerror nil 'nosuffix))
|
||||
(let ((default-directory doom-emacs-dir)
|
||||
(targets
|
||||
(file-expand-wildcards
|
||||
|
@ -760,7 +761,7 @@ This should be run whenever init.el or an autoload file is modified. Running
|
|||
(message "Deleted old autoloads.el"))
|
||||
(message "Generating new autoloads.el")
|
||||
(dolist (file (mapcar #'file-truename (reverse targets)))
|
||||
(let ((generated-autoload-load-name file))
|
||||
(let ((generated-autoload-load-name (file-name-sans-extension file)))
|
||||
(message
|
||||
(cond ((not (doom-packages--read-if-cookies file))
|
||||
"⚠ Ignoring %s")
|
||||
|
@ -775,37 +776,58 @@ This should be run whenever init.el or an autoload file is modified. Running
|
|||
(load-path (append (list doom-emacs-dir)
|
||||
doom-psuedo-module-dirs
|
||||
doom-modules-dirs
|
||||
load-path)))
|
||||
load-path))
|
||||
library-cache)
|
||||
(unwind-protect
|
||||
(condition-case-unless-debug ex
|
||||
(with-current-buffer buf
|
||||
(delay-mode-hooks (emacs-lisp-mode))
|
||||
(goto-char (point-min))
|
||||
(insert ";;; -*- lexical-binding:t -*-\n"
|
||||
";; This file is autogenerated by `doom//reload-autoloads', DO NOT EDIT !!\n\n")
|
||||
|
||||
(save-excursion
|
||||
;; Replace autoload paths with absolute paths for faster
|
||||
;; resolution during load and simpler `load-path'
|
||||
(while (re-search-forward "^\\s-*(autoload\\s-+'[^ ]+\\s-+\"\\([^/][^\"]*\\)\"" nil t)
|
||||
(let ((path (match-string 1)))
|
||||
;; (delete-region (match-beginning 1) (match-end 1))
|
||||
(replace-match
|
||||
(or (cdr (assoc path library-cache))
|
||||
(when-let* ((libpath (locate-library path))
|
||||
(libpath (file-name-sans-extension libpath)))
|
||||
(push (cons path libpath) library-cache)
|
||||
libpath)
|
||||
(progn
|
||||
(warn "Couldn't find absolute path for: %s" path)
|
||||
path))
|
||||
t t nil 1)))
|
||||
(message "✓ Autoload paths expanded"))
|
||||
|
||||
(save-excursion
|
||||
;; insert package autoloads
|
||||
(dolist (file (doom-packages--files doom-packages-dir "-autoloads\\.el$"))
|
||||
(when doom-debug-mode
|
||||
(message "⚠ Including %s" (file-relative-name file package-user-dir)))
|
||||
(let ((pfile (prin1-to-string file)))
|
||||
(insert "\n(let ((load-file-name " pfile "))")
|
||||
(insert
|
||||
(with-temp-buffer
|
||||
(insert "\n(let ((load-file-name " (prin1-to-string file) "))")
|
||||
(insert-file-contents file)
|
||||
(while (re-search-forward "#\\$\\|^;\\(.*\n\\)" nil 'move)
|
||||
(unless (nth 8 (syntax-ppss))
|
||||
(replace-match (if (match-end 1) "" pfile) t t)))
|
||||
(while (re-search-forward "^;;\\(.*\n\\)" nil 'move)
|
||||
(replace-match "" t t))
|
||||
(unless (bolp) (insert "\n"))
|
||||
(insert ")\n")))
|
||||
(message "✓ Package autoloads included")
|
||||
(insert ")\n")
|
||||
(buffer-string))))
|
||||
(message "✓ Package autoloads included"))
|
||||
|
||||
;; Replace autoload paths with absolute paths for faster
|
||||
;; resolution during load and simpler `load-path'
|
||||
(while (re-search-forward "^\\s-*(add-to-list\\s-+'\\(?:load-path\\|auto-mode-alist\\)" nil t)
|
||||
(beginning-of-line-text)
|
||||
(kill-sexp))
|
||||
(message "✓ Autoload load-path entries removed")
|
||||
|
||||
(goto-char (point-max))
|
||||
(insert "
|
||||
;; Local\sVariables:
|
||||
;; version-control: never
|
||||
;; no-byte-compile: t
|
||||
;; no-update-autoloads: t
|
||||
;; End:\n")
|
||||
(quiet! (eval-buffer buf))
|
||||
(save-buffer)
|
||||
(let (byte-compile-warnings)
|
||||
;; give the file a chance to reveal errors
|
||||
(load doom-autoload-file nil 'nomessage 'nosuffix))
|
||||
(message "Done!"))
|
||||
('error
|
||||
(delete-file doom-autoload-file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue