From 8903eebdc484b04aa0f1721c7dfa910c01567583 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 1 Mar 2019 15:16:25 -0500 Subject: [PATCH] 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. --- core/cli/autoloads.el | 69 +++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/core/cli/autoloads.el b/core/cli/autoloads.el index 6ab127f2e..fd49c2da8 100644 --- a/core/cli/autoloads.el +++ b/core/cli/autoloads.el @@ -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,37 +166,39 @@ 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 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 (pcase type - (`defun 'defmacro) - (`cl-defun `cl-defmacro) - (_ type)) - name arglist docstring) - (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))))) - ('error - (message "Ignoring autodef %s (%s)" - name e) - nil))) - ((make-autoload sexp (abbreviate-file-name (file-name-sans-extension path))))) + (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) + (_ type)) + name arglist docstring) + (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)))))) + ('error + (message "Ignoring autodef %s (%s)" + name e) + nil))) 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")