bhauman / figwheel-main

Figwheel Main provides tooling for developing ClojureScript applications
https://figwheel.org
Eclipse Public License 1.0
639 stars 93 forks source link

Print to emacs repl #26

Open vemv opened 6 years ago

vemv commented 6 years ago

Hi!

One thing which I've always wanted (but to be fair, have never checked if it was possible in the prior version of Figwheel) is how to println from plain cljs code located in a source file, to the repl that is running within Emacs.

To summarize:

I recently tried to hack a solution with *print-fn* and set!, to no avail.

Why one would want this

To know when Figwheel has reloaded its code (i.e. (println-to-repl "Reloaded!")), without having to peek at the browser devtools. Most times I want to stay focused within Emacs, full-screen. Also, even if I switch to Chrome, when I see the evidence of the FW reload, I don't know if that one is for the latest change (10 seconds ago), or the prior change (e.g. 1 minute ago).

My prior approach was using Chrome notifications, but lately they only work over https, which can be a pain to setup for every project.

Side note

Whenever I say Emacs I probably could say "nrepl at my IDE" but I don't want to make assumptions about impl details.

Thanks - Victor

vemv commented 6 years ago

An even-greater result would be instead of printing to the repl (which kind of pollutes it), would be to run an arbitrary Emacs/IDE hook. For Emacs Lisp it could be (message "Reloaded").

bhauman commented 6 years ago

(enable-console-print!) interfere's with figwheel-main's printing setup. Make sure you are not using that. If you are not using (enable-console-print!) and you are not seeing println's in your nREPL then there is some sort of problem because its set up to work. It currently works in reply and CIDER.

Making printlns go to where they are coming from is a bit difficult, but I agree that printlns need to be output to the REPL.

bhauman commented 6 years ago

You must also have a long build time, but the REPL does print out the build messages, which is a decent proxy for when the reload has completed.

vemv commented 6 years ago

Thanks for the reply!

I assume your advice applies to (at least) figwheel-main.

In any case, removing (enable-console-print!) might be a hard path given one often works in mixed teams.

You must also have a long build time, but the REPL does print out the build messages, which is a decent proxy for when the reload has completed.

I don't see that behavior in lein-figwheel (I don't use figwheel-main yet), does this comment apply to both versions?

My main purpose when I opened this ticket is to try ensuring that 'reload notifications' are easy to have. Now that you're rebuilding FW from scratch it might be a good opportunity to make that a first-class concern.

Although, on second thoughts, this might be easy with nrepl-middleware regardless of what FW implements (or not...).