Skip to content

Commit 32d1076

Browse files
author
hata
committed
Add repl linkages: doc, source, macroexpand-1, and macroexpand.
1 parent e6e260e commit 32d1076

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

Default (OSX).sublime-keymap

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[
22
{ "keys": ["ctrl+super+shift+n"], "command": "clojure_inline_namespace_refactoring" },
3+
// { "keys": [""], "command": "clojure_repl_doc" },
4+
// { "keys": [""], "command": "clojure_repl_source" },
5+
// { "keys": [""], "command": "clojure_repl_macroexpand1" },
6+
// { "keys": [""], "command": "clojure_repl_macroexpand" },
37
]

Default.sublime-commands

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,21 @@
22
{
33
"caption": "Refactor inline namespace in clojure.",
44
"command": "clojure_inline_namespace_refactoring",
5-
}
5+
},
6+
{
7+
"caption": "doc -> REPL.",
8+
"command": "clojure_repl_doc",
9+
},
10+
{
11+
"caption": "source -> REPL.",
12+
"command": "clojure_repl_source",
13+
},
14+
{
15+
"caption": "macroexpand-1 -> REPL.",
16+
"command": "clojure_repl_macroexpand1",
17+
},
18+
{
19+
"caption": "macroexpand -> REPL.",
20+
"command": "clojure_repl_macroexpand",
21+
},
622
]

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@ ln -s `pwd`/sublime-clojure $HOME/Library/Application\ Support/Sublime\ Text\ 3/
2929

3030
### Plugins
3131

32-
#### Extract inline namespace phrase
32+
#### Send to REPL
33+
34+
0. Send a symbol of the cursol with **`clojure.repl/doc`** to sublime-REPL.
35+
36+
0. Send a symbol of the cursol with **`clojure.repl/source`** to sublime-REPL.
37+
38+
0. Send a block of the cursol with **`clojure.core/macroexpand-1`** to sublime-REPL.
39+
40+
0. Send a block of the cursol with **`clojure.core/macroexpand`** to sublime-REPL.
41+
42+
The above commands are not registered in [keymap](Default (OSX).sublime-keymap).
43+
You may use on **[command palette](Default.sublime-commands) (`Command + Shift + P`)**.
44+
45+
46+
#### Extract inline namespace or package modification
3347

3448
Consider a code like following.
3549

@@ -148,6 +162,7 @@ Support [Planck](http://planck-repl.org/).
148162
### Plugins
149163

150164
* clojure_inline_namespace_refactoring.py
165+
* clojure_repl_sender.py
151166

152167
### Command Mappings
153168

clojure_repl_sender.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sublime, sublime_plugin
2+
3+
sublime.CLASS_WORD_START | sublime.CLASS_WORD_END
4+
5+
def cursol_symbol(v):
6+
pos = v.sel()[0].begin()
7+
cls = sublime.CLASS_WORD_START | sublime.CLASS_WORD_END
8+
r = v.expand_by_class(pos, cls, " ({[;")
9+
_r = v.find(r"[-/\w\d.]+[-\w\d]", r.begin())
10+
return v.substr(_r)
11+
12+
def cursol_block(v):
13+
# pos = v.sel()[0].begin()
14+
# cls = sublime.CLASS_PUNCTUATION_START | sublime.CLASS_PUNCTUATION_END
15+
strs = []
16+
v.run_command("expand_selection", {"to": "brackets"})
17+
v.run_command("expand_selection", {"to": "brackets"})
18+
for s in v.sel():
19+
strs.append(v.substr(s))
20+
return "\n\n".join(strs)
21+
22+
def repl_external_id(v):
23+
return v.scope_name(0).split(" ")[0].split(".", 1)[1] # may be "clojure"
24+
25+
def repl_send(v, text):
26+
external_id = repl_external_id(v)
27+
v.run_command("repl_send", {"external_id": external_id, "text": text})
28+
29+
class ClojureReplDocCommand(sublime_plugin.TextCommand):
30+
def run(self, edit):
31+
v = self.view
32+
text = "(println) (clojure.repl/doc {})".format(cursol_symbol(v))
33+
repl_send(v, text)
34+
35+
class ClojureReplSourceCommand(sublime_plugin.TextCommand):
36+
def run(self, edit):
37+
v = self.view
38+
text = "(println) (clojure.repl/source {})".format(cursol_symbol(v))
39+
repl_send(v, text)
40+
41+
class ClojureReplMacroexpand1Command(sublime_plugin.TextCommand):
42+
def run(self, edit):
43+
v = self.view
44+
text = "(println) (clojure.core/macroexpand-1 '{})".format(cursol_block(v))
45+
repl_send(v, text)
46+
47+
class ClojureReplMacroexpandCommand(sublime_plugin.TextCommand):
48+
def run(self, edit):
49+
v = self.view
50+
text = "(println) (clojure.core/macroexpand '{})".format(cursol_block(v))
51+
repl_send(v, text)

0 commit comments

Comments
 (0)