Skip to content

Instantly share code, notes, and snippets.

@bolivier
Last active October 29, 2025 12:54
Show Gist options
  • Select an option

  • Save bolivier/059555e911ba8e524f6b05445c493c1f to your computer and use it in GitHub Desktop.

Select an option

Save bolivier/059555e911ba8e524f6b05445c493c1f to your computer and use it in GitHub Desktop.
Evaluate let bindings into the current namespace
(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))))))))
@bolivier
Copy link
Author

Bind this and place your cursor after values in a let binding, and evaluate those vals into the current ns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment