JetBrains / la-clojure

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

Keyboard-shortcut for switching namespace #70

Closed rzdoronok closed 10 years ago

rzdoronok commented 10 years ago

It would be great if developers add keyboard-shortcut for switching in REPL to namespase of opened file, like in clojure plugin for eclipse. In my working copy of la-clojure i`ve added org.jetbrains.plugins.clojure.repl.actions.SwitchNamespaceClojureFileInConsoleAction class, extending ClojureConsoleActionBase, implementing actionPerformed(AnActionEvent e) method:

public void actionPerformed(AnActionEvent e) { .. final String namespace = ((ClojureFile) psiFile).getNamespace(); if (namespace == null) return; final String command = "(ns " + namespace + ")"; executeCommand(project, command); }

and registered REPL-related action in plugin.xml: <action id="org.jetbrains.plugins.clojure.repl.actions.SwitchNamespaceClojureFileInConsoleAction" class="org.jetbrains.plugins.clojure.repl.actions.SwitchNamespaceClojureFileInConsoleAction" text="Switch to file's namespace in REPL"> <keyboard-shortcut keymap="$default" first-keystroke="ctrl shift M"/> </action>

sco11morgan commented 10 years ago

That's a great idea.

I'd also like a shortcut to exec some arbitrary code in the REPL. In my case "(run-specs)" for Speclj support, though other people might want "(check-facts)" for Midje support. This way in the editor I could select a portion of my testcase, run the selected text (to define the test), then kick off the test run with another hot key.

Alefas commented 10 years ago

It would be better to have pull request, however I just pushed this change for the upcoming IDEA 13.1.

sco11morgan commented 10 years ago

Thanks @Alefas for adding the ns switch. Do you know the best way I could add support for executing a predefined piece of code in the REPL? I tried recording a macro of switching to REPL, typing in (run-specs), and executing, but the macro didn't record the window switch. My other option is to setup an action in the plugin, but then I'd need to provide the user a way of editing code snippets. Is there a way for the macro to record the window switch?

Alefas commented 10 years ago

@captmorgan I don't know about macro and switching windows. However It's quite simple to create shortcut, which shows popup with Clojure editor, code from which you can send to REPL.