Last active
October 29, 2025 12:54
-
-
Save bolivier/059555e911ba8e524f6b05445c493c1f to your computer and use it in GitHub Desktop.
Evaluate let bindings into the current namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun bso/cider-inside-let-p () | |
| "Check if I'm immediately inside a let binding" | |
| (interactive) | |
| (condition-case err | |
| (save-excursion | |
| (paredit-backward-up 2) | |
| (looking-at "(let")) | |
| (error nil))) | |
| (defun bso/cider-def-var () | |
| "Read the previous sexp and define | |
| it as (def NAME <sexp>) in Clojure using CIDER." | |
| (interactive) | |
| (save-excursion | |
| (let* ((sexp (save-excursion | |
| (paredit-backward 1) | |
| (thing-at-point 'sexp t)))) | |
| (cond | |
| ((save-excursion | |
| (paredit-backward 2) | |
| (looking-at "{:keys")) | |
| (progn | |
| (paredit-backward 2) | |
| (paredit-forward-down 2) | |
| (let ((names (list))) | |
| (while (not (looking-at "}")) | |
| (push (thing-at-point 'symbol t) names) | |
| (paredit-forward) | |
| (forward-char 1)) | |
| (--map (cider-interactive-eval (format "(def %s (:%s %s))" it it sexp)) names)))) | |
| (t (let ((name (if (bso/cider-inside-let-p) | |
| (progn | |
| (backward-sexp) | |
| (thing-at-point 'symbol t)) | |
| (read-string "Var name: ")))) | |
| (cider-interactive-eval (format "(def %s %s)" name sexp)))))))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bind this and place your cursor after values in a
letbinding, and evaluate those vals into the current ns.