Improve autoload generator
Adds support for defalias and arbitrary forms.
This commit is contained in:
parent
3ac7ec5120
commit
4e5c8b6052
|
@ -434,49 +434,65 @@ even if it doesn't need reloading!"
|
|||
(file-in-directory-p path doom-core-dir)))
|
||||
forms)
|
||||
(while (re-search-forward "^;;;###autodef *\\([^\n]+\\)?\n" nil t)
|
||||
(let ((sexp (sexp-at-point))
|
||||
(pred (match-string 1)))
|
||||
(if (not (memq (car sexp) '(defun defmacro cl-defun cl-defmacro)))
|
||||
(message "Ignoring invalid autodef %s (found %s)"
|
||||
name type)
|
||||
(cl-destructuring-bind (type name arglist docstring &rest body) sexp
|
||||
(unless (stringp docstring)
|
||||
(push docstring body)
|
||||
(setq docstring "No documentation."))
|
||||
(let ((origin (cond ((doom-module-from-path path))
|
||||
((file-in-directory-p path doom-private-dir)
|
||||
`(:private . ,(intern (file-name-base path))))
|
||||
((file-in-directory-p path doom-emacs-dir)
|
||||
`(:core . ,(intern (file-name-base path))))))
|
||||
(doom-file-form
|
||||
`(put ',name 'doom-file ,(abbreviate-file-name path))))
|
||||
(push (cond ((not (and member-p
|
||||
(or (null pred)
|
||||
(eval (read pred) t))))
|
||||
(push doom-file-form forms)
|
||||
(condition-case-unless-debug e
|
||||
(append
|
||||
(list 'defmacro name arglist
|
||||
(format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s"
|
||||
origin
|
||||
docstring))
|
||||
(cl-loop for arg in arglist
|
||||
if (and (symbolp arg)
|
||||
(not (keywordp arg))
|
||||
(not (memq arg cl--lambda-list-keywords)))
|
||||
collect (list 'ignore arg)
|
||||
else if (listp arg)
|
||||
collect (list 'ignore (car arg))))
|
||||
('error
|
||||
(message "Ignoring autodef %s (%s)"
|
||||
name e)
|
||||
nil)))
|
||||
((memq type '(defmacro cl-defmacro))
|
||||
(push doom-file-form forms)
|
||||
sexp)
|
||||
((make-autoload sexp path)))
|
||||
forms)
|
||||
(push `(put ',name 'doom-module ',origin) forms))))))
|
||||
(let* ((sexp (sexp-at-point))
|
||||
(pred (match-string 1))
|
||||
(type (car sexp))
|
||||
(name (doom-unquote (cadr sexp)))
|
||||
(origin (cond ((doom-module-from-path path))
|
||||
((file-in-directory-p path doom-private-dir)
|
||||
`(:private . ,(intern (file-name-base path))))
|
||||
((file-in-directory-p path doom-emacs-dir)
|
||||
`(:core . ,(intern (file-name-base path))))))
|
||||
(doom-file-form
|
||||
`(put ',name 'doom-file ,(abbreviate-file-name path))))
|
||||
(cond ((memq type '(defun defmacro cl-defun cl-defmacro))
|
||||
(cl-destructuring-bind (type name arglist &rest body) sexp
|
||||
(let ((docstring (if (stringp (car body))
|
||||
(pop body)
|
||||
"No documentation.")))
|
||||
(push (cond ((not (and member-p
|
||||
(or (null pred)
|
||||
(eval (read pred) t))))
|
||||
(push doom-file-form forms)
|
||||
(setq docstring (format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s"
|
||||
origin docstring))
|
||||
(condition-case-unless-debug e
|
||||
(append (list 'defmacro name arglist docstring)
|
||||
(cl-loop for arg in arglist
|
||||
if (and (symbolp arg)
|
||||
(not (keywordp arg))
|
||||
(not (memq arg cl--lambda-list-keywords)))
|
||||
collect (list 'ignore arg)
|
||||
else if (listp arg)
|
||||
collect (list 'ignore (car arg))))
|
||||
('error
|
||||
(message "Ignoring autodef %s (%s)"
|
||||
name e)
|
||||
nil)))
|
||||
((memq type '(defmacro cl-defmacro))
|
||||
(push doom-file-form forms)
|
||||
sexp)
|
||||
((make-autoload sexp path)))
|
||||
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
|
||||
(concat (string-join (mapcar #'prin1-to-string (reverse forms)) "\n")
|
||||
"\n")
|
||||
|
@ -543,7 +559,8 @@ modified."
|
|||
;; modules, so that you will never get a void-function when you use
|
||||
;; them.
|
||||
(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
|
||||
;; the file, and autoload comments.
|
||||
(doom--cleanup-autoloads)
|
||||
|
|
Loading…
Reference in New Issue
Block a user