Show More
@@ -1,85 +1,88 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=0): |
|
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 | if os.system(cmd) != 0: |
|
31 | if os.system(cmd) != 0: | |
32 | raise IPython.ipapi.TryNext() |
|
32 | raise IPython.ipapi.TryNext() | |
33 | if wait: |
|
33 | if wait: | |
34 | raw_input("Press Enter when done editing:") |
|
34 | raw_input("Press Enter when done editing:") | |
35 |
|
35 | |||
36 | ip.set_hook('editor',call_editor) |
|
36 | ip.set_hook('editor',call_editor) | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | # in these, exe is always the path/name of the executable. Useful |
|
39 | # in these, exe is always the path/name of the executable. Useful | |
40 | # if you don't have the editor directory in your path |
|
40 | # if you don't have the editor directory in your path | |
41 |
|
41 | |||
42 | def komodo(exe = 'komodo'): |
|
42 | def komodo(exe = 'komodo'): | |
43 | """ Activestate Komodo [Edit] """ |
|
43 | """ Activestate Komodo [Edit] """ | |
44 | install_editor(exe + ' -l $line "$file"', wait = True) |
|
44 | install_editor(exe + ' -l $line "$file"', wait = True) | |
45 |
|
45 | |||
46 | def scite(exe = "scite"): |
|
46 | def scite(exe = "scite"): | |
47 | """ SciTE or Sc1 """ |
|
47 | """ SciTE or Sc1 """ | |
48 | install_editor(exe + ' "$file" -goto:$line') |
|
48 | install_editor(exe + ' "$file" -goto:$line') | |
49 |
|
49 | |||
50 | def notepadplusplus(exe = 'notepad++'): |
|
50 | def notepadplusplus(exe = 'notepad++'): | |
51 | """ Notepad++ http://notepad-plus.sourceforge.net """ |
|
51 | """ Notepad++ http://notepad-plus.sourceforge.net """ | |
52 | install_editor(exe + ' -n$line "$file"') |
|
52 | install_editor(exe + ' -n$line "$file"') | |
53 |
|
53 | |||
54 | def jed(exe = 'jed'): |
|
54 | def jed(exe = 'jed'): | |
55 | """ JED, the lightweight emacsish editor """ |
|
55 | """ JED, the lightweight emacsish editor """ | |
56 | install_editor(exe + ' +$line "$file"') |
|
56 | install_editor(exe + ' +$line "$file"') | |
57 |
|
57 | |||
58 | def idle(exe = None): |
|
58 | def idle(exe = None): | |
59 | """ Idle, the editor bundled with python |
|
59 | """ Idle, the editor bundled with python | |
60 |
|
60 | |||
61 | Should be pretty smart about finding the executable. |
|
61 | Should be pretty smart about finding the executable. | |
62 | """ |
|
62 | """ | |
63 | if exe is None: |
|
63 | if exe is None: | |
64 | import idlelib |
|
64 | import idlelib | |
65 | p = os.path.dirname(idlelib.__file__) |
|
65 | p = os.path.dirname(idlelib.__file__) | |
66 | exe = p + '/idle.py' |
|
66 | exe = p + '/idle.py' | |
67 | install_editor(exe + ' "$file"') |
|
67 | install_editor(exe + ' "$file"') | |
68 |
|
68 | |||
|
69 | def mate(exe = 'mate'): | |||
|
70 | """ TextMate, the missing editor""" | |||
|
71 | install_editor(exe + ' -w -l $line "$file"') | |||
69 |
|
72 | |||
70 | # these are untested, report any problems |
|
73 | # these are untested, report any problems | |
71 |
|
74 | |||
72 | def emacs(exe = 'emacs'): |
|
75 | def emacs(exe = 'emacs'): | |
73 | install_editor(exe + ' +$line "$file"') |
|
76 | install_editor(exe + ' +$line "$file"') | |
74 |
|
77 | |||
75 | def gnuclient(exe= 'gnuclient'): |
|
78 | def gnuclient(exe= 'gnuclient'): | |
76 | install_editor(exe + ' -nw +$line "$file"') |
|
79 | install_editor(exe + ' -nw +$line "$file"') | |
77 |
|
80 | |||
78 | def crimson_editor(exe = 'cedt.exe'): |
|
81 | def crimson_editor(exe = 'cedt.exe'): | |
79 | install_editor(exe + ' /L:$line "$file"') |
|
82 | install_editor(exe + ' /L:$line "$file"') | |
80 |
|
83 | |||
81 | def kate(exe = 'kate'): |
|
84 | def kate(exe = 'kate'): | |
82 | install_editor(exe + ' -u -l $line "$file"') |
|
85 | install_editor(exe + ' -u -l $line "$file"') | |
83 |
|
86 | |||
84 |
|
87 | |||
85 | No newline at end of file |
|
88 |
General Comments 0
You need to be logged in to leave comments.
Login now