JetBrains / la-clojure

Clojure plugin for IntelliJ IDEA
Apache License 2.0
220 stars 49 forks source link

automatically setting the REPL namespace to match the editor #59

Closed Chort409 closed 10 years ago

Chort409 commented 11 years ago

Currently, you have to manually use in-ns to set the namespace in the REPL any time you switch between different files in the editor. This is very disruptive and it would be much better if the REPL would be set automatically to the namespace of the file that's being edited.

cmf commented 10 years ago

I'm going to add a feature shortly to have a shortcut key that switches the REPL namespace to the current file. I'm also considering having code executed via shortcuts (i.e. evaluate top form in REPL) evaluated automatically in the namespace of the file the code comes from (if found). I think Emacs does this.

gered commented 10 years ago

While I can appreciate having a shortcut to switch the REPL namespace, I have to agree with Chort409 that having the ability (even if not the default, but as an option you can enable) to auto-switch the namespace to match the active source file would be extremely handy.

cmf commented 10 years ago

When would you want it to switch? When you execute something from the editor? I'm assuming you don't want to change the namespace when you switch editor windows, right? Would the evaluation change I described above (code evaluated from an editor is evaluated in the editor's namespace) not achieve what you want?

yogthos commented 10 years ago

The way it works in Counterclockwise is that the namespace is linked to the focused editor when it contains a file with a namespace declaration. Any code that is run from the editor should be evaluated in its namespace.

Frankly, I can't think of a reason why you would not want this to be the default behavior. I highly recommend taking a look at how Counterclockwise plugin in Eclipse behaves as an example.

cmf commented 10 years ago

Ok, thanks for all the feedback. I'll grab a copy of Counterclockwise and try it out.

yogthos commented 10 years ago

@cmf Also worth noting that CCW has a very nice strict mode. If you're going to try it out I definitely recommend taking a look at that as well. Specifically, the behavior of the backspace key when editing expressions. Take a look at how it handles something like

(defn foo [arg]
  (println "bar" arg))

when you have the cursor at the end of the outer s-exp and start hitting backspace. My experience is that you never have to worry about matching parens in this mode.

cmf commented 10 years ago

Right, they've basically emulated paredit from Emacs. I have some of this partially implemented, the rest is in the roadmap (including delete/backspace). I'm going to try developing a small project in CCW to see what I like and don't like.

yogthos commented 10 years ago

It's great to hear that this stuff is in the pipe. I really like where the plugin is headed. Thanks for the hard work. :)

hsestupin commented 10 years ago

@cmf I highly recommend you to implement that small project in Emacs directly instead of Eclipse cause itsn't guaranteed that Eclipse developers implemented paredit in a right way. Moreover Emacs Paredit is used by thousands of developers for many years and it's much more mature than Eclipse one.

cmf commented 10 years ago

@hsestupin Yeah, I've actually used Emacs a bit for Clojure work so I'm pretty familiar with paredit. I was more interested in the CCW REPL behavior.

Alefas commented 10 years ago

Moved here: http://youtrack.jetbrains.com/issue/CLJ-215