clojure-emacs / inf-clojure

Basic interaction with a Clojure subprocess
250 stars 45 forks source link

inf-clojure-eval-last-sexp should respect current namespace of a file evaluating from #205

Open Inc0n opened 2 years ago

Inc0n commented 2 years ago

Steps to reproduce the problem

Have a script with (ns <namespace> ...) at the top. Define some variables with filler values. Run C-x C-e on one of the variables. The inf-clojure repl will report

Syntax error compiling at (REPL:0:0).
Unable to resolve symbol: <variable name> in this context

 Make C-x C-e respecet the file namespace it was triggered from

This will be convenient to have.

Environment & Version information

Clojure CLI version 1.11.1.1189

inf-clojure version information

3.2.1

Lein/Boot version

clojure-cli

Emacs version

28.1

Operating system

Mac Monterey M1

dpsutton commented 2 years ago

I'm not sure that I want this. A fundamental value proposition of inf-clojure to me is that it is dead simple and works with a standard repl. To me, I have a regular repl and inf-clojure sends simple commands. Adding this changes this assumption, and makes the client more complicated and opaque.

I'm not 100% opposed, and I would like to see what the VS Code extension Clover does in this instance.

Inc0n commented 2 years ago

Fair enough. Here is the extension that requires cider-current-ns from CIDER to work.

(defun inf-clojure-eval-last-sexp-in-ns ()
    (interactive)
    (inf-clojure-eval-string
     (format "(binding [*ns* (find-ns '%s)] (eval '%s))"
             (cider-current-ns)
             (buffer-substring
              (save-excursion (backward-sexp) (point))
              (point)))))

Here is a link for some more ways to get this to work (instead of using binding). https://stackoverflow.com/questions/7684656/clojure-eval-code-in-different-namespace