ipy_editors.py
42 lines
| 1.1 KiB
| text/x-python
|
PythonLexer
vivainio
|
r843 | """ 'editor' hooks for common editors that work well with ipython | |
They should honor the line number argument, at least. | |||
Contributions are *very* welcome. | |||
""" | |||
import IPython.ipapi | |||
ip = IPython.ipapi.get() | |||
from IPython.Itpl import itplns | |||
import os | |||
vivainio
|
r847 | def install_editor(run_template, wait = False): | |
""" Gets a template in format "myeditor bah bah $file bah bah $line | |||
Installs the editor that is called by IPython, instead of the default | |||
notepad or vi. | |||
""" | |||
vivainio
|
r843 | def call_editor(self, file, line): | |
if line is None: | |||
line = 0 | |||
cmd = itplns(run_template, locals()) | |||
print ">",cmd | |||
os.system(cmd) | |||
vivainio
|
r847 | if wait: | |
raw_input("Press Enter when done editing:") | |||
vivainio
|
r843 | ||
ip.set_hook('editor',call_editor) | |||
def komodo(exe = 'komodo'): | |||
vivainio
|
r847 | """ Activestate Komodo [Edit] | |
Warning - komodo does not block, so can't be used for plain %edit | |||
""" | |||
install_editor(exe + ' -l $line "$file"', wait = True) | |||
vivainio
|
r843 | ||
def scite(exe = "scite"): | |||
""" Exe is the executable name of your scite. | |||
""" | |||
install_editor(exe + ' "$file" -goto:$line') |