abo-abo / lispy

Short and sweet LISP editing
http://oremacs.com/lispy/
1.19k stars 129 forks source link

Error with Clojure evaluation #674

Open davd33 opened 8 months ago

davd33 commented 8 months ago

Hi ! I have the following error message in the Messages buffer when evaluating a clojure form (with e or E):

Syntax error compiling at (clojure-noob:localhost:40003(clj)*:1:1).
No such var: lispy.clojure/pp

I also see the following compilation error message in the CIDER REPL after the first evaluation:

Syntax error (FileNotFoundException) compiling at (lispy-clojure.clj:1:1).
Could not locate clojure/tools/namespace/file__init.class, clojure/tools/namespace/file.clj or clojure/tools/namespace/file.cljc on classpath.

Could you please help me with this issue ? Do you need further information for helping me?

Thank you very much.

ComedyTomedy commented 8 months ago

I've started getting this too - the fix is to add the missing libraries to deps.edn under :deps. Not tested it, but I'm fairly confident this will work:

org.clojure/tools.namespace {:mvn/version "1.4.4"}
org.clojure/java.classpath {:mvn/version "1.0.0"}
ComedyTomedy commented 8 months ago

It's slightly awkward, but you can fix this per-project by adding those deps to your own project's deps.edn (or lein equivalent), perhaps under :dev if you've got cider set up to add -A:dev. I can't actually figure out what Lispy's deps.edn is for, presumably just for development of Lispy.

Another solution/hack without needing anything per-project would be to rebind Lispy's keys. Following code assumes that clojure is always clojure-mode, which might not be true (?). This has taken me a few tries, because I'd forgotten how Lispy bindings work, but I think it's working now!

;; Patch broken Clojure eval
(defun my/lispy-eval (&optional arg)
  (interactive)
  (if (eq major-mode 'clojure-mode)
      (cider-eval-last-sexp)
    (lispy-eval arg)))

(defun my/lispy-eval-and-insert ()
  (interactive)
  (if (eq major-mode 'clojure-mode)
      (cider-eval-last-sexp t)
    (lispy-eval-and-insert)))

(lispy-define-key lispy-mode-map "e" #'my/lispy-eval)
(lispy-define-key lispy-mode-map "E" #'my/lispy-eval-and-insert)
davd33 commented 8 months ago

Hello @ComedyTomedy, thank you for your answer, I like the emacs config solution. Only one thing is missing: the CIDER connection the first time you try to eval something. I tried to include it in your code but I'm not proficient in elisp and I get the following error: if: Invalid function: (= (length (cider-connections)) 0)

(defun d33/lispy-eval (&optional arg)
  (interactive)
  (if (eq major-mode 'clojure-mode)
      (progn
        (when ((= (length (cider-connections)) 0)) (cider-jack-in-clj))
        (cider-eval-last-sexp))
    (lispy-eval arg)))

  (defun d33/lispy-eval-and-insert ()
    (interactive)
    (if (eq major-mode 'clojure-mode)
        (progn
          (when ((= (length (cider-connections)) 0)) (cider-jack-in-clj))
          (cider-eval-last-sexp t))
      (lispy-eval-and-insert)))

May be the function cider-connections is not to be used in this place? Or there's a better function to check if the CIDER session already exists?

ComedyTomedy commented 8 months ago

You've put double parens on ((= ...)) - as if = returns a function. Another problem is that cider-jack-in-clj takes a mandatory argument (which can be an empty list / nil).

So the immediate solution will be (when (= (length (cider-connections)) 0) (cider-jack-in-clj nil)), but also in Elisp an empty list is falsey (it's literally identical to nil), so you can abbreviate to (unless (cider-connections) (cider-jack-in-clj nil)). Clojure's when-not is called unless in most Lisps.

(unless (cider-connections)
        (cider-jack-in-clj nil))
davd33 commented 8 months ago

Ok, I understand, thank you for your help. It's fixed now!

winterscar commented 7 months ago

Should this issue be closed @davd33 ? The above solution seems more like a hack than a proper fix.

davd33 commented 7 months ago

Hi @winterscar, indeed, this hack works for me, but the issue remains. I'm not well aware of how issues are managed. But I'll re-open this one then.