##// END OF EJS Templates
add some preconfigured editors
vivainio -
Show More
@@ -1,43 +1,79 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 Installs the editor that is called by IPython, instead of the default
17 Installs the editor that is called by IPython, instead of the default
18 notepad or vi.
18 notepad or vi.
19
20 If wait is true, wait until the user presses enter before returning,
21 to facilitate non-blocking editors that exit immediately after
22 the call.
19 """
23 """
20
24
21 def call_editor(self, file, line):
25 def call_editor(self, file, line):
22 if line is None:
26 if line is None:
23 line = 0
27 line = 0
24 cmd = itplns(run_template, locals())
28 cmd = itplns(run_template, locals())
25 print ">",cmd
29 print ">",cmd
26 os.system(cmd)
30 os.system(cmd)
27 if wait:
31 if wait:
28 raw_input("Press Enter when done editing:")
32 raw_input("Press Enter when done editing:")
29
33
30 ip.set_hook('editor',call_editor)
34 ip.set_hook('editor',call_editor)
31
35
32 def komodo(exe = 'komodo'):
33 """ Activestate Komodo [Edit]
34
36
35 Warning - komodo does not block, so can't be used for plain %edit
37 # in these, exe is always the path/name of the executable. Useful
38 # if you don't have the editor directory in your path
36
39
37 """
40 def komodo(exe = 'komodo'):
41 """ Activestate Komodo [Edit] """
38 install_editor(exe + ' -l $line "$file"', wait = True)
42 install_editor(exe + ' -l $line "$file"', wait = True)
39
43
40 def scite(exe = "scite"):
44 def scite(exe = "scite"):
41 """ Exe is the executable name of your scite.
45 """ SciTE or Sc1 """
42 """
43 install_editor(exe + ' "$file" -goto:$line')
46 install_editor(exe + ' "$file" -goto:$line')
47
48 def notepadplusplus(exe = 'notepad++'):
49 """ Notepad++ http://notepad-plus.sourceforge.net """
50 install_editor(exe + ' -n$line "$file"')
51
52 def jed(exe = 'jed'):
53 """ JED, the lightweight emacsish editor """
54 install_editor(exe + ' +$line "$file"')
55
56 def idle(exe = None):
57 """ Idle, the editor bundled with python
58
59 Should be pretty smart about finding the executable.
60 """
61 if exe is None:
62 import idlelib
63 p = os.path.dirname(idlelib.__file__)
64 exe = p + '/idle.py'
65 install_editor(exe + ' "$file"')
66
67
68 # these are untested, report any problems
69
70 def emacs(exe = 'emacs'):
71 install_editor(exe + ' +$line "$file"')
72
73 def gnuclient(exe= 'gnuclient'):
74 install_editor(exe + ' -nw +$line "$file"')
75
76 def crimson_editor(exe = 'cedt.exe'):
77 install_editor(exe + ' /L:%line "$file"')
78
79 No newline at end of file
@@ -1,73 +1,75 b''
1 """ User configuration file for IPython
1 """ User configuration file for IPython
2
2
3 This is a more flexible and safe way to configure ipython than *rc files
3 This is a more flexible and safe way to configure ipython than *rc files
4 (ipythonrc, ipythonrc-pysh etc.)
4 (ipythonrc, ipythonrc-pysh etc.)
5
5
6 This file is always imported on ipython startup. You can import the
6 This file is always imported on ipython startup. You can import the
7 ipython extensions you need here (see IPython/Extensions directory).
7 ipython extensions you need here (see IPython/Extensions directory).
8
8
9 Feel free to edit this file to customize your ipython experience.
9 Feel free to edit this file to customize your ipython experience.
10
10
11 Note that as such this file does nothing, for backwards compatibility.
11 Note that as such this file does nothing, for backwards compatibility.
12 Consult e.g. file 'ipy_profile_sh.py' for an example of the things
12 Consult e.g. file 'ipy_profile_sh.py' for an example of the things
13 you can do here.
13 you can do here.
14
14
15 See http://ipython.scipy.org/moin/IpythonExtensionApi for detailed
15 See http://ipython.scipy.org/moin/IpythonExtensionApi for detailed
16 description on what you could do here.
16 description on what you could do here.
17 """
17 """
18
18
19 # Most of your config files and extensions will probably start with this import
19 # Most of your config files and extensions will probably start with this import
20
20
21 import IPython.ipapi
21 import IPython.ipapi
22 ip = IPython.ipapi.get()
22 ip = IPython.ipapi.get()
23
23
24 # You probably want to uncomment this if you did %upgrade -nolegacy
24 # You probably want to uncomment this if you did %upgrade -nolegacy
25 # import ipy_defaults
25 # import ipy_defaults
26
26
27 import os
27 import os
28
28
29 def main():
29 def main():
30 # Handy tab-completers for %cd, %run, import etc.
30 # Handy tab-completers for %cd, %run, import etc.
31 # Try commenting this out if you have completion problems/slowness
31 # Try commenting this out if you have completion problems/slowness
32 # import ipy_stock_completers
32 # import ipy_stock_completers
33
33
34 # uncomment if you want to get ipython -p sh behaviour
34 # uncomment if you want to get ipython -p sh behaviour
35 # without having to use command line switches
35 # without having to use command line switches
36
36
37 # import ipy_profile_sh
37 # import ipy_profile_sh
38
38
39
39
40 # Configure your favourite editor?
40 # Configure your favourite editor?
41 # Good idea e.g. for %edit os.path.isfile
41 # Good idea e.g. for %edit os.path.isfile
42
42
43 #import ipy_editors
43 #import ipy_editors
44
44
45 # Choose one of these:
45 # Choose one of these:
46
46
47 #ipy_editors.scite()
47 #ipy_editors.scite()
48 #ipy_editors.scite('c:/opt/scite/scite.exe')
48 #ipy_editors.scite('c:/opt/scite/scite.exe')
49 #ipy_editors.komodo()
49 #ipy_editors.komodo()
50 #ipy_editors.idle()
51 # ... or many others, try 'ipy_editors??' after import to see them
50
52
51 # Or roll your own:
53 # Or roll your own:
52 #ipy_editors.install_editor("c:/opt/jed +$line $file")
54 #ipy_editors.install_editor("c:/opt/jed +$line $file")
53
55
54
56
55 o = ip.options
57 o = ip.options
56 # An example on how to set options
58 # An example on how to set options
57 #o.autocall = 1
59 #o.autocall = 1
58 o.system_verbose = 0
60 o.system_verbose = 0
59
61
60 #import_all("os sys")
62 #import_all("os sys")
61 #execf('~/_ipython/ns.py')
63 #execf('~/_ipython/ns.py')
62
64
63 # some config helper functions you can use
65 # some config helper functions you can use
64 def import_all(modules):
66 def import_all(modules):
65 """ Usage: import_all("os sys") """
67 """ Usage: import_all("os sys") """
66 for m in modules.split():
68 for m in modules.split():
67 ip.ex("from %s import *" % m)
69 ip.ex("from %s import *" % m)
68
70
69 def execf(fname):
71 def execf(fname):
70 """ Execute a file in user namespace """
72 """ Execute a file in user namespace """
71 ip.ex('execfile("%s")' % os.path.expanduser(fname))
73 ip.ex('execfile("%s")' % os.path.expanduser(fname))
72
74
73 main()
75 main()
General Comments 0
You need to be logged in to leave comments. Login now