Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Clojure evaluation #674

Open
davd33 opened this issue Nov 13, 2023 · 7 comments
Open

Error with Clojure evaluation #674

davd33 opened this issue Nov 13, 2023 · 7 comments

Comments

@davd33
Copy link

davd33 commented Nov 13, 2023

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
Copy link

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
Copy link

ComedyTomedy commented Nov 16, 2023

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
Copy link
Author

davd33 commented Nov 16, 2023

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
Copy link

ComedyTomedy commented Nov 16, 2023

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
Copy link
Author

davd33 commented Nov 17, 2023

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

@davd33 davd33 closed this as completed Nov 17, 2023
@winterscar
Copy link

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

@davd33
Copy link
Author

davd33 commented Dec 3, 2023

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.

@davd33 davd33 reopened this Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants