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