inf-clojure icon indicating copy to clipboard operation
inf-clojure copied to clipboard

Incompatibilities with Clojurescript

Open austinhaas opened this issue 6 years ago • 4 comments

inf-clojure included non-portable Clojure code, and it automatically enables an eldoc feature which triggers the non-portable code in a Clojurescript REPL.

https://github.com/clojure-emacs/inf-clojure/blob/master/inf-clojure.el#L859

(defcustom inf-clojure-arglists-form
  "(try
     (:arglists
      (clojure.core/meta
       (clojure.core/resolve
        (clojure.core/read-string \"%s\"))))
     (catch Throwable t nil))"
  "Form to query inferior Clojure for a function's arglists."
  :type 'string
  :safe #'stringp
  :package-version '(inf-clojure . "2.0.0"))

Throwable isn't available in clojurescript. Additionally, when called from clojurescript, this code will throw an error stating that the argument to resolve must be a quoted symbol.

WARNING: Use of undeclared Var cljs.user/Throwable at line 6 <cljs repl>
clojure.lang.ExceptionInfo: Assert failed: Argument to resolve must be a quoted symbol
(core/and (seq? quoted-sym) (= (quote quote) (first quoted-sym))) at line 4 <cljs repl> {:file "<cljs repl>", :line 4, :column 2, :root-source-info {:source-type :fragment, :source-form (try (:arglists (clojure.core/meta (clojure.core/resolve (clojure.core/read-string "ClojureScript")))) (catch Throwable t nil))}, :tag :cljs/analysis-error}

In spite of these issues, I don't think these "eldoc" helper functions should be called if the user doesn't have eldoc-mode enabled. I've resolved the issue by commenting out the call to inf-clojure-eldoc-setup on Line 182: https://github.com/clojure-emacs/inf-clojure/blob/master/inf-clojure.el#L182

austinhaas avatar Jul 07 '18 21:07 austinhaas

Thanks for reporting, we should definitely have a cljs REPL type. The one you see above is for Clojure only IIRC.

You can see there are customizations for Planck and Lumo in the code but not for "generic" cljs... probably nobody has ever used it - not even myself with it. I used to use Lumo quite extensively though.

arichiardi avatar Jul 08 '18 15:07 arichiardi

I started adding the CLJS REPL type: https://github.com/austinhaas/inf-clojure/blob/cljs/inf-clojure.el

The eldoc stuff seems to work ok (I've barely tested), ~~but it seems kinda slow. Emacs will hang for a fraction of a second after I move the cursor to a new expression.~~ (Edit: The slowness was due to the browser not having focus).

I also see a problem, both with this new CLJS stuff and with CLJ, where multiple prompts are printed. This may be related to the eldoc stuff, but I'm not sure. For instance, if I move the cursor to a function and for whatever reason the arguments can't be printed, a new prompt might be printed. Sometimes the prompts appear randomly. (I also don't understand why some output goes to the REPL and some goes to the JS console.)

I haven't updated ":package-version" for the new custom functions. I assume that would be set to the next version number.

I'm not sure what to do with inf-clojure-completion-form-cljs: https://github.com/austinhaas/inf-clojure/blob/cljs/inf-clojure.el#L974 The clojure version appears to use a library named clojure.complete. It is assumed that the user is including this library in their project?

austinhaas avatar Jul 08 '18 18:07 austinhaas

Btw, there's some historical context here https://github.com/clojure-emacs/inf-clojure/issues/6

I also see a problem, both with this new CLJS stuff and with CLJ, where multiple prompts are printed. This may be related to the eldoc stuff, but I'm not sure. For instance, if I move the cursor to a function and for whatever reason the arguments can't be printed, a new prompt might be printed. Sometimes the prompts appear randomly. (I also don't understand why some output goes to the REPL and some goes to the JS console.)

Multiple prompts get printed when you eval something with newlines in it. Haven't look at the code in a long time, but back in the day my solution was to simply create long single-line forms for everything.

I haven't updated ":package-version" for the new custom functions. I assume that would be set to the next version number.

Yes.

I'm not sure what to do with inf-clojure-completion-form-cljs: https://github.com/austinhaas/inf-clojure/blob/cljs/inf-clojure.el#L974 The clojure version appears to use a library named clojure.complete. It is assumed that the user is including this library in their project?

It's a lein dependency (by virtue of reply being a lein dep), which means a lot of people have it by default. The other should add this manually for the completion to work. I think at some point @arichiardi also added support for compliment. The cljs completion support should be implemented in terms of https://github.com/clojure-emacs/cljs-tooling

bbatsov avatar Jul 08 '18 21:07 bbatsov

Confirm that the cljs-tooling lib solves the completion problem in cljs and maybe after the ongoing PR will be also what lumo uses.

Away from the keyboard for our two weeks but when I come back I can validate / help this PR

arichiardi avatar Jul 09 '18 00:07 arichiardi