##// END OF EJS Templates
default line is zero in call_editor!
vivainio -
Show More
@@ -1,80 +1,80 b''
1 """ 'editor' hooks for common editors that work well with ipython
1 """ 'editor' hooks for common editors that work well with ipython
2
2
3 They should honor the line number argument, at least.
3 They should honor the line number argument, at least.
4
4
5 Contributions are *very* welcome.
5 Contributions are *very* welcome.
6 """
6 """
7
7
8 import IPython.ipapi
8 import IPython.ipapi
9 ip = IPython.ipapi.get()
9 ip = IPython.ipapi.get()
10
10
11 from IPython.Itpl import itplns
11 from IPython.Itpl import itplns
12 import os
12 import os
13
13
14 def install_editor(run_template, wait = False):
14 def install_editor(run_template, wait = False):
15 """ Gets a template in format "myeditor bah bah $file bah bah $line"
15 """ Gets a template in format "myeditor bah bah $file bah bah $line"
16
16
17 $file will be replaced by file name, $line by line number (or 0).
17 $file will be replaced by file name, $line by line number (or 0).
18 Installs the editor that is called by IPython, instead of the default
18 Installs the editor that is called by IPython, instead of the default
19 notepad or vi.
19 notepad or vi.
20
20
21 If wait is true, wait until the user presses enter before returning,
21 If wait is true, wait until the user presses enter before returning,
22 to facilitate non-blocking editors that exit immediately after
22 to facilitate non-blocking editors that exit immediately after
23 the call.
23 the call.
24 """
24 """
25
25
26 def call_editor(self, file, line):
26 def call_editor(self, file, line=0):
27 if line is None:
27 if line is None:
28 line = 0
28 line = 0
29 cmd = itplns(run_template, locals())
29 cmd = itplns(run_template, locals())
30 print ">",cmd
30 print ">",cmd
31 os.system(cmd)
31 os.system(cmd)
32 if wait:
32 if wait:
33 raw_input("Press Enter when done editing:")
33 raw_input("Press Enter when done editing:")
34
34
35 ip.set_hook('editor',call_editor)
35 ip.set_hook('editor',call_editor)
36
36
37
37
38 # in these, exe is always the path/name of the executable. Useful
38 # in these, exe is always the path/name of the executable. Useful
39 # if you don't have the editor directory in your path
39 # if you don't have the editor directory in your path
40
40
41 def komodo(exe = 'komodo'):
41 def komodo(exe = 'komodo'):
42 """ Activestate Komodo [Edit] """
42 """ Activestate Komodo [Edit] """
43 install_editor(exe + ' -l $line "$file"', wait = True)
43 install_editor(exe + ' -l $line "$file"', wait = True)
44
44
45 def scite(exe = "scite"):
45 def scite(exe = "scite"):
46 """ SciTE or Sc1 """
46 """ SciTE or Sc1 """
47 install_editor(exe + ' "$file" -goto:$line')
47 install_editor(exe + ' "$file" -goto:$line')
48
48
49 def notepadplusplus(exe = 'notepad++'):
49 def notepadplusplus(exe = 'notepad++'):
50 """ Notepad++ http://notepad-plus.sourceforge.net """
50 """ Notepad++ http://notepad-plus.sourceforge.net """
51 install_editor(exe + ' -n$line "$file"')
51 install_editor(exe + ' -n$line "$file"')
52
52
53 def jed(exe = 'jed'):
53 def jed(exe = 'jed'):
54 """ JED, the lightweight emacsish editor """
54 """ JED, the lightweight emacsish editor """
55 install_editor(exe + ' +$line "$file"')
55 install_editor(exe + ' +$line "$file"')
56
56
57 def idle(exe = None):
57 def idle(exe = None):
58 """ Idle, the editor bundled with python
58 """ Idle, the editor bundled with python
59
59
60 Should be pretty smart about finding the executable.
60 Should be pretty smart about finding the executable.
61 """
61 """
62 if exe is None:
62 if exe is None:
63 import idlelib
63 import idlelib
64 p = os.path.dirname(idlelib.__file__)
64 p = os.path.dirname(idlelib.__file__)
65 exe = p + '/idle.py'
65 exe = p + '/idle.py'
66 install_editor(exe + ' "$file"')
66 install_editor(exe + ' "$file"')
67
67
68
68
69 # these are untested, report any problems
69 # these are untested, report any problems
70
70
71 def emacs(exe = 'emacs'):
71 def emacs(exe = 'emacs'):
72 install_editor(exe + ' +$line "$file"')
72 install_editor(exe + ' +$line "$file"')
73
73
74 def gnuclient(exe= 'gnuclient'):
74 def gnuclient(exe= 'gnuclient'):
75 install_editor(exe + ' -nw +$line "$file"')
75 install_editor(exe + ' -nw +$line "$file"')
76
76
77 def crimson_editor(exe = 'cedt.exe'):
77 def crimson_editor(exe = 'cedt.exe'):
78 install_editor(exe + ' /L:%line "$file"')
78 install_editor(exe + ' /L:%line "$file"')
79
79
80 No newline at end of file
80
General Comments 0
You need to be logged in to leave comments. Login now