Function: clojure-promote-fn-literal
clojure-promote-fn-literal is an interactive and byte-compiled
function defined in clojure-mode.el.
Signature
(clojure-promote-fn-literal)
Documentation
Convert a #(...) function into (fn [...] ...), prompting for the argument names.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/clojure-mode-20260325.811/clojure-mode.el
(defun clojure-promote-fn-literal ()
"Convert a #(...) function into (fn [...] ...), prompting for the argument names."
(interactive)
(when-let (beg (clojure-string-start))
(goto-char beg))
(if (or (looking-at-p "#(")
(ignore-errors (forward-char 1))
(re-search-backward "#(" (save-excursion (beginning-of-defun-raw) (backward-char) (point)) 'noerror))
(let* ((end (save-excursion (clojure-forward-logical-sexp) (point-marker)))
(argspec (clojure--gather-fn-literal-args))
(arity (car argspec))
(vararg (cdr argspec)))
(delete-char 1)
(save-excursion (forward-sexp 1) (insert ")"))
(save-excursion
(insert "(fn [] ")
(backward-char 2)
(mapc (lambda (n)
(let ((name (read-string (format "Name of argument %d: " n))))
(when (/= n 1) (insert " "))
(insert name)
(clojure--substitute-fn-literal-arg n name end)))
(number-sequence 1 arity))
(when vararg
(insert " & ")
(let ((name (read-string "Name of variadic argument: ")))
(insert name)
(clojure--substitute-fn-literal-arg '& name end)))))
(user-error "No #() literal at point!")))