Skip to content

Commit 9722f74

Browse files
committed
Copy evaluation result (closes #37)
1 parent 0bd53b5 commit 9722f74

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

Default (Linux).sublime-keymap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@
3535
// {"keys": ["ctrl+alt+d"],
3636
// "command": "sublime_clojure_lookup_symbol",
3737
// "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]},
38+
39+
// // Copy Evaluation Result
40+
// {"keys": ["ctrl+c"],
41+
// "command": "sublime_clojure_copy",
42+
// "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]},
3843
]

Default (OSX).sublime-keymap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@
3535
// {"keys": ["ctrl+d"],
3636
// "command": "sublime_clojure_lookup_symbol",
3737
// "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]},
38+
39+
// // Copy Evaluation Result
40+
// {"keys": ["super+c"],
41+
// "command": "sublime_clojure_copy",
42+
// "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]},
3843
]

Default (Windows).sublime-keymap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@
3535
// {"keys": ["ctrl+alt+d"],
3636
// "command": "sublime_clojure_lookup_symbol",
3737
// "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]},
38+
39+
// // Copy Evaluation Result
40+
// {"keys": ["ctrl+c"],
41+
// "command": "sublime_clojure_copy",
42+
// "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]},
3843
]

Default.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"caption": "Clojure REPL: Interrupt Pending Evaluations",
2424
"command": "sublime_clojure_interrupt_eval"
2525
},
26+
{
27+
"caption": "Clojure REPL: Copy Evaluation Result",
28+
"command": "sublime_clojure_copy"
29+
},
2630
{
2731
"caption": "Clojure REPL: Toggle Stacktrace",
2832
"command": "sublime_clojure_toggle_trace"

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ By default, Sublime Clojure will also print evaluation time if it took more than
115115

116116
<img src="https://raw.github.com/tonsky/sublime-clojure/master/screenshots/eval_elapsed.png" width="500" height="139" alt="Elapsed time">
117117

118+
### Copying evaluation results
119+
120+
Sometimes you want to copy evaluation result. It is recommended to rebind `Cmd+C`/`Ctrl+C` from `copy` to `sublime_clojure_copy`. This will copy evaluation result if inside evaluated region and fallback to default `copy` otherwise.
121+
118122
### Interrupting
119123

120124
If your evaluation runs too long and you want to interrupt it, run `Clojure REPL: Interrupt Pending Evaluations`:
@@ -176,6 +180,7 @@ Evaluate Buffer | <kbd>Ctrl</kbd> <kbd>B</kbd> | <kbd>Ctrl</kb
176180
Interrupt Pending Evaluations | <kbd>Ctrl</kbd> <kbd>C</kbd> | <kbd>Ctrl</kbd> <kbd>Alt</kbd> <kbd>C</kbd> | [C]ancel
177181
Toggle Info | <kbd>Ctrl</kbd> <kbd>I</kbd> | <kbd>Ctrl</kbd> <kbd>Alt</kbd> <kbd>I</kbd> | [I]nfo
178182
Clear Evaluation Results | <kbd>Ctrl</kbd> <kbd>L</kbd> | <kbd>Ctrl</kbd> <kbd>Alt</kbd> <kbd>L</kbd> | c[L]ear
183+
Copy Evaluation Results | <kbd>Command</kbd> <kbd>C</kbd> | <kbd>Ctrl</kbd> <kbd>C</kbd> | [C]opy
179184

180185
To set it up, run `Preferences: Sublime Clojure Key Bindings` command and copy example keybindings to your local Key Bindings file.
181186

package.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, view, region):
3131
self.msg = None
3232
self.trace = None
3333
self.phantom_id = None
34+
self.value = None
3435
Eval.next_id += 1
3536
self.update("pending", None, region)
3637

@@ -59,6 +60,7 @@ def region(self):
5960

6061
def update(self, status, value, region = None, time_taken = None):
6162
self.status = status
63+
self.value = value
6264
region = region or self.region()
6365
if region:
6466
scope, color = self.scope_color()
@@ -424,6 +426,17 @@ def run(self, code):
424426
def is_enabled(self):
425427
return conn.ready()
426428

429+
class SublimeClojureCopyCommand(sublime_plugin.TextCommand):
430+
def eval(self):
431+
view = self.view
432+
return conn.find_eval(view, view.sel()[0])
433+
434+
def run(self, edir):
435+
if conn.ready() and len(self.view.sel()) == 1 and self.view.sel()[0].empty() and (eval := self.eval()) and eval.value:
436+
sublime.set_clipboard(eval.value)
437+
else:
438+
self.view.run_command("copy", {})
439+
427440
class SublimeClojureClearEvalsCommand(sublime_plugin.TextCommand):
428441
def run(self, edit):
429442
conn.erase_evals(lambda eval: eval.status not in {"pending", "interrupt"}, self.view)

0 commit comments

Comments
 (0)