Improve autoload generator

Adds support for defalias and arbitrary forms.
This commit is contained in:
Henrik Lissner 2018-06-18 01:55:37 +02:00
parent 3ac7ec5120
commit 4e5c8b6052
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395

View File

@ -434,49 +434,65 @@ even if it doesn't need reloading!"
(file-in-directory-p path doom-core-dir))) (file-in-directory-p path doom-core-dir)))
forms) forms)
(while (re-search-forward "^;;;###autodef *\\([^\n]+\\)?\n" nil t) (while (re-search-forward "^;;;###autodef *\\([^\n]+\\)?\n" nil t)
(let ((sexp (sexp-at-point)) (let* ((sexp (sexp-at-point))
(pred (match-string 1))) (pred (match-string 1))
(if (not (memq (car sexp) '(defun defmacro cl-defun cl-defmacro))) (type (car sexp))
(message "Ignoring invalid autodef %s (found %s)" (name (doom-unquote (cadr sexp)))
name type) (origin (cond ((doom-module-from-path path))
(cl-destructuring-bind (type name arglist docstring &rest body) sexp ((file-in-directory-p path doom-private-dir)
(unless (stringp docstring) `(:private . ,(intern (file-name-base path))))
(push docstring body) ((file-in-directory-p path doom-emacs-dir)
(setq docstring "No documentation.")) `(:core . ,(intern (file-name-base path))))))
(let ((origin (cond ((doom-module-from-path path)) (doom-file-form
((file-in-directory-p path doom-private-dir) `(put ',name 'doom-file ,(abbreviate-file-name path))))
`(:private . ,(intern (file-name-base path)))) (cond ((memq type '(defun defmacro cl-defun cl-defmacro))
((file-in-directory-p path doom-emacs-dir) (cl-destructuring-bind (type name arglist &rest body) sexp
`(:core . ,(intern (file-name-base path)))))) (let ((docstring (if (stringp (car body))
(doom-file-form (pop body)
`(put ',name 'doom-file ,(abbreviate-file-name path)))) "No documentation.")))
(push (cond ((not (and member-p (push (cond ((not (and member-p
(or (null pred) (or (null pred)
(eval (read pred) t)))) (eval (read pred) t))))
(push doom-file-form forms) (push doom-file-form forms)
(condition-case-unless-debug e (setq docstring (format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s"
(append origin docstring))
(list 'defmacro name arglist (condition-case-unless-debug e
(format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s" (append (list 'defmacro name arglist docstring)
origin (cl-loop for arg in arglist
docstring)) if (and (symbolp arg)
(cl-loop for arg in arglist (not (keywordp arg))
if (and (symbolp arg) (not (memq arg cl--lambda-list-keywords)))
(not (keywordp arg)) collect (list 'ignore arg)
(not (memq arg cl--lambda-list-keywords))) else if (listp arg)
collect (list 'ignore arg) collect (list 'ignore (car arg))))
else if (listp arg) ('error
collect (list 'ignore (car arg)))) (message "Ignoring autodef %s (%s)"
('error name e)
(message "Ignoring autodef %s (%s)" nil)))
name e) ((memq type '(defmacro cl-defmacro))
nil))) (push doom-file-form forms)
((memq type '(defmacro cl-defmacro)) sexp)
(push doom-file-form forms) ((make-autoload sexp path)))
sexp) forms)
((make-autoload sexp path))) (push `(put ',name 'doom-module ',origin) forms))))
forms)
(push `(put ',name 'doom-module ',origin) forms)))))) ((eq type 'defalias)
(cl-destructuring-bind (type name target &optional docstring) sexp
(let ((name (doom-unquote name))
(target (doom-unquote target)))
(unless (and member-p
(or (null pred)
(eval (read pred) t)))
(setq target #'ignore))
(push doom-file-form forms)
(push `(put ',name 'doom-module ',origin) forms)
(push `(defalias ',name #',target ,docstring)
forms))))
((and member-p
(or (null pred)
(eval (read pred) t)))
(push sexp forms)))))
(if forms (if forms
(concat (string-join (mapcar #'prin1-to-string (reverse forms)) "\n") (concat (string-join (mapcar #'prin1-to-string (reverse forms)) "\n")
"\n") "\n")
@ -543,7 +559,8 @@ modified."
;; modules, so that you will never get a void-function when you use ;; modules, so that you will never get a void-function when you use
;; them. ;; them.
(save-excursion (save-excursion
(doom--generate-autodefs (reverse targets) enabled-targets)) (doom--generate-autodefs (reverse targets) enabled-targets)
(print! (green "✓ Generated autodefs")))
;; Remove byte-compile inhibiting file variables so we can byte-compile ;; Remove byte-compile inhibiting file variables so we can byte-compile
;; the file, and autoload comments. ;; the file, and autoload comments.
(doom--cleanup-autoloads) (doom--cleanup-autoloads)