Skip to content

Commit aa17a88

Browse files
committed
new run_command function (with examples usage)
The example is commented out by default, but I actually them: F12 clear the current figure via "plt.clf()" F11 closes all figures via "plt.close('all')"
1 parent d9384fa commit aa17a88

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

ftplugin/python/ipy.vim

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ def print_prompt(prompt,msg_id=None):
307307
else:
308308
echo("In[]: %s" % prompt)
309309

310-
def with_subchannel(f):
310+
def with_subchannel(f,*args):
311311
"conditionally monitor subchannel"
312-
def f_with_update():
312+
def f_with_update(*args):
313313
try:
314-
f()
314+
f(*args)
315315
if monitor_subchannel:
316316
update_subchannel_msgs()
317317
except AttributeError: #if km is None
@@ -328,6 +328,13 @@ def run_this_line():
328328
msg_id = send(vim.current.line)
329329
print_prompt(vim.current.line, msg_id)
330330

331+
@with_subchannel
332+
def run_command(cmd):
333+
msg_id = send(cmd)
334+
print_prompt(cmd, msg_id)
335+
if monitor_subchannel:
336+
update_subchannel_msgs()
337+
331338
@with_subchannel
332339
def run_these_lines():
333340
r = vim.current.range
@@ -427,6 +434,10 @@ if g:ipy_perform_mappings != 0
427434
imap <S-F5> <C-O><S-F5>
428435
imap <silent> <F5> <C-O><F5>
429436
map <C-F5> :call <SID>toggle_send_on_save()<CR>
437+
"" Example of how to quickly clear the current plot with a keystroke
438+
"map <silent> <F12> :python run_command("plt.clf()")<cr>
439+
"" Example of how to quickly close all figures with a keystroke
440+
"map <silent> <F11> :python run_command("plt.close('all')")<cr>
430441

431442
"pi custom
432443
map <silent> <C-Return> :python run_this_file()<CR>

0 commit comments

Comments
 (0)