Change purpose of autodef cookie argument
;;;###autodef FORM FORM was used as a predicate for inclusion as an autodef. Now it is used as the replacement sexp in case the module is disabled. Oh, you don't know what autdefs are? Well let me explain (thanks for asking, by the way). An autdef'ed function, macro, or function alias is always available to be called, anywhere in Doom, even if its containing module is disabled. For instance: ;;;###autodef (defun say-hello! (name) ; the trailing ! denotes an autodef (message "Hello %s" name)) This makes it safe to call `do-something` without a check whether it exists (or if its module is enabled). When the module is enabled, an autoload entry is added to the Doom autoloads file: (autoload 'do-something "path/to/some/modules/autoloads") And it is autoloaded as normal when it is first used. However, if the module is disabled, then this is inserted instead: (defmacro do-something (&rest _)) This no-ops; it does nothing and doesn't evaluate its arguments. If FORM above was provided, that is used instead of a noop macro. It's a little smarter than simple substitution, but that's the gist of it.
This commit is contained in:
parent
8832737671
commit
8903eebdc4
1 changed files with 34 additions and 35 deletions
|
@ -156,7 +156,7 @@ even if it doesn't need reloading!"
|
|||
forms)
|
||||
(while (re-search-forward "^;;;###autodef *\\([^\n]+\\)?\n" nil t)
|
||||
(let* ((sexp (sexp-at-point))
|
||||
(pred (match-string 1))
|
||||
(alt-sexp (match-string 1))
|
||||
(type (car sexp))
|
||||
(name (doom-unquote (cadr sexp)))
|
||||
(origin (cond ((doom-module-from-path path))
|
||||
|
@ -166,19 +166,22 @@ even if it doesn't need reloading!"
|
|||
`(: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))
|
||||
(cond ((and (not member-p) alt-sexp)
|
||||
(push (read alt-sexp) forms))
|
||||
|
||||
((memq type '(defun defmacro cl-defun cl-defmacro))
|
||||
(cl-destructuring-bind (_ name arglist &rest body) sexp
|
||||
(let ((docstring (if (stringp (car body))
|
||||
(pop body)
|
||||
"No documentation.")))
|
||||
(push (cond ((not (and member-p
|
||||
(or (null pred)
|
||||
(let ((load-file-name path))
|
||||
(eval (read pred) t)))))
|
||||
(push (if member-p
|
||||
(make-autoload sexp (abbreviate-file-name (file-name-sans-extension path)))
|
||||
(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
|
||||
(if alt-sexp
|
||||
(read alt-sexp)
|
||||
(append (list (pcase type
|
||||
(`defun 'defmacro)
|
||||
(`cl-defun `cl-defmacro)
|
||||
|
@ -191,12 +194,11 @@ even if it doesn't need reloading!"
|
|||
collect arg into syms
|
||||
else if (listp arg)
|
||||
collect (car arg) into syms
|
||||
finally return (if syms `((ignore ,@syms)))))
|
||||
finally return (if syms `((ignore ,@syms))))))
|
||||
('error
|
||||
(message "Ignoring autodef %s (%s)"
|
||||
name e)
|
||||
nil)))
|
||||
((make-autoload sexp (abbreviate-file-name (file-name-sans-extension path)))))
|
||||
forms)
|
||||
(push `(put ',name 'doom-module ',origin) forms))))
|
||||
|
||||
|
@ -204,19 +206,16 @@ even if it doesn't need reloading!"
|
|||
(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)
|
||||
(let ((load-file-name path))
|
||||
(eval (read pred) t))))
|
||||
(unless member-p
|
||||
(setq docstring (format "THIS FUNCTION DOES NOTHING BECAUSE %s IS DISABLED\n\n%s"
|
||||
origin docstring))
|
||||
(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)))
|
||||
(member-p
|
||||
(push sexp forms)))))
|
||||
(if forms
|
||||
(concat (string-join (mapcar #'prin1-to-string (reverse forms)) "\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue