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

:repl-options :init seems to be ignored by lein repl :headless #788

Closed
mjwillson opened this issue Sep 18, 2012 · 14 comments
Closed

:repl-options :init seems to be ignored by lein repl :headless #788

mjwillson opened this issue Sep 18, 2012 · 14 comments

Comments

@mjwillson
Copy link

$ cat ~/.lein/profiles.clj 
{:user
  {
    :plugins [
      [lein-midje "2.0.0-SNAPSHOT"]
     ]
    :repl-options {
      :init (do
         (print "hello")
         (set! *print-length* 20)
         (use 'clojure.stacktrace)
      )
      :timeout 90000
    }
  }
}

If I do a lein repl the init code runs (the 'hello' visible, print-length change has taken effect), whereas if I do a lein repl :headless and connect to it via lein repl :connect, the init code doesn't run, in particular my print-length setting doesn't take effect, which is the main goal here, I want to stop emacs / nrepl.el hanging nastily if I accidentally type some big lazy sequence into the repl.

(Also, neither lein repl nor lein repl :headless seems to run the init code if I run it outside of a folder with a project.clj. Was this intentional? It would be nice if my profiles.clj applied everywhere)

@mjwillson
Copy link
Author

Should have said: this is using Leiningen 2.0.0-preview10

@mjwillson
Copy link
Author

Anyone have any ideas on this? it's a bit of a drag having to manually enable basic conveniences like stacktrace, pprint, print-level etc, in every new REPL (affecting emacs nrepl.el and other IDEs which use a headless repl)

@technomancy
Copy link
Owner

Hoping to get this fixed in the next release. In the mean time you should be able to just add those kinds of conveniences to the :user profile's :injections key and they will be applied to every project invocation, not just repls.

@technomancy
Copy link
Owner

The problem here is that the :init stuff is currently handled by the reply client, so when we don't spin up a client we lose it. We need to support that stuff server-side instead. Need to add this into both the start-server function and the trampoline-repl function. Shouldn't be too tricky for a new contributor if anyone wants to give it a shot.

@kingtim
Copy link
Contributor

kingtim commented Oct 9, 2012

I am going to take a crack at this.

@kingtim
Copy link
Contributor

kingtim commented Oct 11, 2012

I have a pull request that fixes this for the lein repl :headless case, which I will be submitting shortly.

Trampoline is a slightly different story.
lein trampoline repl seems to be trying to handle this already, but seems to be bombing when I have :repl-options :init in my profiles.clj. Seems like a bug somewhere.. possibly on the repl-y side, have not tracked it down yet.

$ cat ~/.lein/profiles.clj 
{:user
  {
    :repl-options {
      :init (do
         (set! *print-length* 20)
      )
    }
  }
}
$ lein trampoline repl
REPL-y 0.1.0-beta11
Clojure 1.4.0
CompilerException java.lang.RuntimeException: Unable to resolve symbol: ... in this context, compiling:(NO_SOURCE_PATH:1) 
reply.eval-modes.nrepl=> Bye for now!

$ mv ~/.lein/profiles.clj /tmp
$ lein trampoline repl
REPL-y 0.1.0-beta11
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
          (user/sourcery function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Examples from clojuredocs.org: [clojuredocs or cdoc]
          (user/clojuredocs name-here)
          (user/clojuredocs "ns-here" "name-here")
user=> 

@technomancy
Copy link
Owner

Thanks for the fix! For trampolining it looks like the problem here is that options-for-reply is ignored in trampoline-repl.

@kingtim
Copy link
Contributor

kingtim commented Oct 11, 2012

I'll take a look at the trampoline and and address that in a separate PR.

@technomancy
Copy link
Owner

Hoping to do a release candidate soon; should I plan on this making it in or should we push this off to the next release?

@kingtim
Copy link
Contributor

kingtim commented Oct 26, 2012

Apologies for the delay. I am planning to try to get you a fix this weekend. When are you trying to do RC?

@technomancy
Copy link
Owner

No problem; it's probably a week out at this point. Thanks!

@kingtim
Copy link
Contributor

kingtim commented Oct 29, 2012

I spent some time with this over the weekend and here are my findings.

lein trampoline repl is correctly passing the init options to the repl:

$ cat ~/.lein/profiles.clj
{:user { :repl-options { :init (def ^:dynamic *earmuff* 10) } } }
$ lein trampoline repl
Warning: *earmuff* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *earmuff* or change the name. (NO_SOURCE_PATH:1)
REPL-y 0.1.0-beta11
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
          (user/sourcery function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Examples from clojuredocs.org: [clojuredocs or cdoc]
          (user/clojuredocs name-here)
          (user/clojuredocs "ns-here" "name-here")
user=> *earmuff*
10

If I set *print-length* in the init options however, somewhere in the pipeline the init form is being abbreviated with ellipses e.g. (ns-java-methods ns))) ...)))
(do [init-forms-elided] (concat special-forms (namespaces ns) (ns-vars ns) (ns-classes ns) (ns-java-methods ns))) ...))) (catch java.lang.Exception f__1852__auto__ (clojure.core/intern (clojure.core/create-ns (quote complete.core)) (quote completions) (clojure.core/fn [prefix__1853__auto__ ns__1854__auto__] [])) (clojure.core/println "Unable to initialize completions."))))) ...) nil (do (set! *print-length* 20)) nil)

which of course causes the the repl startup to fail:

$ lein trampoline repl
REPL-y 0.1.0-beta11
Clojure 1.4.0
CompilerException java.lang.RuntimeException: Unable to resolve symbol: ... in this context, compiling:(NO_SOURCE_PATH:1) 
reply.eval-modes.nrepl=> Bye for now!

This appears to be an issue on the reply side of things and I plan to log it against that.
To me it seems like this particular issue could be resolved, but its up to you how you'd like to handle that.

@technomancy
Copy link
Owner

OK, my bad; not sure what I was thinking earlier. Thanks for tracking this down. I think you're right that the metadata issue needs to be addressed upstream in reply.

@kingtim
Copy link
Contributor

kingtim commented Oct 30, 2012

I submitted trptcolin/reply#89 for the reply issue.

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

No branches or pull requests

3 participants