diff --git a/core/autoload/packages.el b/core/autoload/packages.el index a08110f81..a042b5069 100644 --- a/core/autoload/packages.el +++ b/core/autoload/packages.el @@ -162,7 +162,7 @@ each package." (list (intern (car module)) (ignore-errors (intern (cadr module))) current-prefix-arg))) - (mapc (fn! ((cat . mod)) + (mapc (lambda! ((cat . mod)) (if-let (packages-file (pcase cat (:private (car (doom-glob doom-private-dir "packages.el"))) diff --git a/core/autoload/print.el b/core/autoload/print.el index 9caba15a6..73b4fd2e1 100644 --- a/core/autoload/print.el +++ b/core/autoload/print.el @@ -321,9 +321,9 @@ Each argument in ARGS can be a list, as if they were arguments to `format!': `nil' and empty strings in SEQUENCE are omitted." (mapconcat (doom-partial #'format "%s") - (seq-remove (fn!! (or (null %) - (and (stringp %) - (string-empty-p %)))) + (seq-remove (fn! (or (null %) + (and (stringp %) + (string-empty-p %)))) sequence) (or separator " "))) diff --git a/core/cli/ci.el b/core/cli/ci.el index f86a4a0b2..cb8e799d8 100644 --- a/core/cli/ci.el +++ b/core/cli/ci.el @@ -57,12 +57,12 @@ Each element of this list can be one of: (defvar doom-ci-commit-rules ;; TODO Extract into named functions - (list (fn! (&key subject) + (list (lambda! (&key subject) "If a fixup/squash commit, don't lint this commit" (when (string-match "^\\(\\(?:fixup\\|squash\\)!\\|FIXUP\\|WIP\\) " subject) (skip! (format "Found %S commit, skipping commit" (match-string 1 subject))))) - (fn! (&key type subject) + (lambda! (&key type subject) "Test SUBJECT length" (let ((len (length subject))) (cond ((memq type '(bump revert))) @@ -77,27 +77,27 @@ Each element of this list can be one of: (warn! "Subject is %d characters; <=50 is ideal" len))))) - (fn! (&key type) + (lambda! (&key type) "Ensure commit has valid type" (or (memq type doom-ci-commit-types) (if type (fail! "Invalid commit type: %s" type) (fail! "Commit has no detectable type")))) - (fn! (&key summary) + (lambda! (&key summary) "Ensure commit has a summary" (when (or (not (stringp summary)) (string-blank-p summary)) (fail! "Commit has no summary"))) - (fn! (&key type summary subject) + (lambda! (&key type summary subject) "Ensure summary isn't needlessly capitalized" (and (stringp summary) (string-match-p "^[A-Z][^-A-Z.]" summary) (fail! "%S in summary should not be capitalized" (car (split-string summary " "))))) - (fn! (&rest plist &key type scopes) + (lambda! (&rest plist &key type scopes) "Ensure scopes are valid" (dolist (scope scopes) (condition-case e @@ -113,12 +113,12 @@ Each element of this list can be one of: (fail! "Invalid scope: %s" scope))) (user-error (fail! "%s" (error-message-string e)))))) - (fn! (&key scopes) + (lambda! (&key scopes) "Esnure scopes are sorted correctly" (unless (equal scopes (sort (copy-sequence scopes) #'string-lessp)) (fail! "Scopes are not in lexicographical order"))) - (fn! (&key type body) + (lambda! (&key type body) "Enforce 72 character line width for BODY" (catch 'result (with-temp-buffer @@ -136,7 +136,7 @@ Each element of this list can be one of: (re-search-backward "^\\(?:#\\| +\\)" nil t) (throw 'result (fail! "Line(s) in commit body exceed 72 characters")))))))) - (fn! (&key bang body type) + (lambda! (&key bang body type) "Ensure ! is accompanied by a 'BREAKING CHANGE:' in BODY" (if bang (cond ((not (string-match-p "^BREAKING CHANGE:" body)) @@ -147,7 +147,7 @@ Each element of this list can be one of: (fail! "'BREAKING CHANGE:' present in body, but missing '!' after %S" type)))) - (fn! (&key type body) + (lambda! (&key type body) "Ensure bump commits have package ref lines" (and (eq type 'bump) (let ((bump-re "\\(?:https?://.+\\|[^/]+\\)/[^/]+@\\([a-z0-9]+\\)")) @@ -155,7 +155,7 @@ Each element of this list can be one of: body))) (fail! "Bump commit is missing commit hash diffs"))) - (fn! (&key body) + (lambda! (&key body) "Ensure commit hashes in bump lines are 12 characters long" (with-temp-buffer (insert body) @@ -169,7 +169,7 @@ Each element of this list can be one of: (length refs) (string-join (nreverse refs) ", ")))))) ;; TODO Add bump validations for revert: type. - (fn! (&key body trailers) + (lambda! (&key body trailers) "Validate commit trailers." (let* ((keys (mapcar #'car doom-ci-commit-trailer-keys)) (key-re (regexp-opt keys t)) diff --git a/core/cli/help.el b/core/cli/help.el index ee50c2e11..efddee5c3 100644 --- a/core/cli/help.el +++ b/core/cli/help.el @@ -98,7 +98,7 @@ OPTIONS: (let* ((key "ENVIRONMENT VARIABLES") (clis (if command (doom-cli-find command) (hash-table-values doom-cli--table))) (clis (seq-remove #'doom-cli-alias clis)) - (clis (seq-filter (fn!! (cdr (assoc key (doom-cli-docs %)))) clis)) + (clis (seq-filter (fn! (cdr (assoc key (doom-cli-docs %)))) clis)) (clis (seq-group-by #'doom-cli-command clis))) (print! "List of environment variables for %s:\n" command) (if (null clis) @@ -154,7 +154,7 @@ OPTIONS: (defun doom-cli-help-similar-commands (command &optional maxscore) "Return N commands that are similar to COMMAND." (seq-take-while - (fn!! (>= (car %) (or maxscore 0.0))) + (fn! (>= (car %) (or maxscore 0.0))) (seq-sort-by #'car #'> (cl-loop with prefix = (seq-find #'doom-cli-get (nreverse (doom-cli--command-expand command t))) @@ -261,9 +261,9 @@ OPTIONS: (subcommands? (doom-cli-subcommands rcli 1 :predicate? t))) `((command . ,(doom-cli-command cli)) (options ,@opts) - (required ,@(mapcar (fn!! (upcase (format "`%s'" %))) (if subcommands? '(command) (alist-get '&required args)))) - (optional ,@(mapcar (fn!! (upcase (format "[`%s']" %)))(alist-get '&optional args))) - (rest ,@(mapcar (fn!! (upcase (format "[`%s'...]" %))) (if subcommands? '(args) (alist-get '&args args)))) + (required ,@(mapcar (fn! (upcase (format "`%s'" %))) (if subcommands? '(command) (alist-get '&required args)))) + (optional ,@(mapcar (fn! (upcase (format "[`%s']" %)))(alist-get '&optional args))) + (rest ,@(mapcar (fn! (upcase (format "[`%s'...]" %))) (if subcommands? '(args) (alist-get '&args args)))) (examples ,@(doom-cli-help--parse-docs (doom-cli-find cli t) "SYNOPSIS"))))) (defun doom-cli-help--render-synopsis (synopsis &optional prefix with-examples?) @@ -312,7 +312,7 @@ OPTIONS: (cl-defun doom-cli-help--render-commands (commands &key prefix grouped? docs? (inline? t)) (with-temp-buffer (let* ((doom-print-indent 0) - (commands (seq-group-by (fn!! (if grouped? (doom-cli-prop (doom-cli-get % t) :group))) commands)) + (commands (seq-group-by (fn! (if grouped? (doom-cli-prop (doom-cli-get % t) :group))) commands)) (toplevel (assq nil commands)) (rest (remove toplevel commands)) (drop (if prefix (length prefix) 0)) @@ -358,7 +358,7 @@ OPTIONS: The alist's CAR are lists of formatted switches plus their arguments, e.g. '((\"`--foo'\" \"`BAR'\") ...). Their CDR is their formatted documentation." (let* ((docs (doom-cli-help--parse-docs (doom-cli-find cli t) "OPTIONS")) - (docs (mapcar (fn!! (cons (split-string (car %) ", ") + (docs (mapcar (fn! (cons (split-string (car %) ", ") (cdr %))) docs)) (strfmt (if noformatting? "%s" "`%s'")) @@ -408,7 +408,7 @@ The alist's CAR are lists of formatted switches plus their arguments, e.g. (insert! ("%s%s\n%s" (mapconcat - (fn!! + (fn! (when (member "..." (cdr %)) (setq multiple? t)) (string-trim-right diff --git a/core/core-cli-lib.el b/core/core-cli-lib.el index 32e469b1e..467598974 100644 --- a/core/core-cli-lib.el +++ b/core/core-cli-lib.el @@ -230,7 +230,7 @@ prepended, and the keyword is in front." command (or (cl-position :root command :from-end t) 0)))) (when (or command prefix) - (cl-loop with map = (fn!! (if (or (stringp %) (keywordp %)) % (prin1-to-string %))) + (cl-loop with map = (fn! (if (or (stringp %) (keywordp %)) % (prin1-to-string %))) for c in (delq nil (cons type (seq-remove #'keywordp command))) if (listp c) collect (mapcar map c) @@ -420,7 +420,7 @@ TARGET can be a `doom-cli', `doom-cli-context', or a command list." If RECURSIVE, includes breadcrumbs leading up to COMMANDSPEC." (funcall (if recursive? #'identity - (fn!! (cl-loop with cmdlen = (length (car %)) + (fn! (cl-loop with cmdlen = (length (car %)) for command in % while (= (length command) cmdlen) collect command))) diff --git a/core/core-lib.el b/core/core-lib.el index 64e92312b..948143d76 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -251,7 +251,7 @@ NAME, ARGLIST, and BODY are the same as `defun', `defun*', `defmacro', and ,(if (eq type 'defun*) `(cl-labels ((,@rest)) ,body) `(cl-letf (((symbol-function #',(car rest)) - (fn! ,(cadr rest) ,@(cddr rest)))) + (lambda! ,(cadr rest) ,@(cddr rest)))) ,body)))) (_ (when (eq (car-safe type) 'function) @@ -298,7 +298,7 @@ See `eval-if!' for details on this macro's purpose." ;;; Closure factories -(defmacro fn! (arglist &rest body) +(defmacro lambda! (arglist &rest body) "Returns (cl-function (lambda ARGLIST BODY...)) The closure is wrapped in `cl-function', meaning ARGLIST will accept anything `cl-defun' will. Implicitly adds `&allow-other-keys' if `&key' is present in @@ -345,7 +345,7 @@ ARGLIST." (seq-doseq (elt data) (doom--fn-crawl elt args))))) -(defmacro fn!! (&rest args) +(defmacro fn! (&rest args) "Return an lambda with implicit, positional arguments. The function's arguments are determined recursively from ARGS. Each symbol from @@ -361,7 +361,7 @@ Instead of: you can use this macro and write: - (fn!! (if %1 %3 (cadr %*))) + (fn! (if %1 %3 (cadr %*))) which expands to: