##// END OF EJS Templates
Remove bundled Itpl module.
Thomas Kluyver -
Show More
@@ -1,89 +1,91 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 from IPython.core import ipapi
8 from IPython.core import ipapi
9 from IPython.core.error import TryNext
9 from IPython.core.error import TryNext
10 ip = ipapi.get()
10 ip = ipapi.get()
11
11
12 # We no longer bundle Itpl. If you update this module, you should use advanced
13 # string formatting instead.
12 from IPython.external.Itpl import itplns
14 from IPython.external.Itpl import itplns
13 import os
15 import os
14
16
15 def install_editor(run_template, wait = False):
17 def install_editor(run_template, wait = False):
16 """ Gets a template in format "myeditor bah bah $file bah bah $line"
18 """ Gets a template in format "myeditor bah bah $file bah bah $line"
17
19
18 $file will be replaced by file name, $line by line number (or 0).
20 $file will be replaced by file name, $line by line number (or 0).
19 Installs the editor that is called by IPython, instead of the default
21 Installs the editor that is called by IPython, instead of the default
20 notepad or vi.
22 notepad or vi.
21
23
22 If wait is true, wait until the user presses enter before returning,
24 If wait is true, wait until the user presses enter before returning,
23 to facilitate non-blocking editors that exit immediately after
25 to facilitate non-blocking editors that exit immediately after
24 the call.
26 the call.
25 """
27 """
26
28
27 def call_editor(self, file, line=0):
29 def call_editor(self, file, line=0):
28 if line is None:
30 if line is None:
29 line = 0
31 line = 0
30 cmd = itplns(run_template, locals())
32 cmd = itplns(run_template, locals())
31 print ">",cmd
33 print ">",cmd
32 if os.system(cmd) != 0:
34 if os.system(cmd) != 0:
33 raise TryNext()
35 raise TryNext()
34 if wait:
36 if wait:
35 raw_input("Press Enter when done editing:")
37 raw_input("Press Enter when done editing:")
36
38
37 ip.set_hook('editor',call_editor)
39 ip.set_hook('editor',call_editor)
38
40
39
41
40 # in these, exe is always the path/name of the executable. Useful
42 # in these, exe is always the path/name of the executable. Useful
41 # if you don't have the editor directory in your path
43 # if you don't have the editor directory in your path
42
44
43 def komodo(exe = 'komodo'):
45 def komodo(exe = 'komodo'):
44 """ Activestate Komodo [Edit] """
46 """ Activestate Komodo [Edit] """
45 install_editor(exe + ' -l $line "$file"', wait = True)
47 install_editor(exe + ' -l $line "$file"', wait = True)
46
48
47 def scite(exe = "scite"):
49 def scite(exe = "scite"):
48 """ SciTE or Sc1 """
50 """ SciTE or Sc1 """
49 install_editor(exe + ' "$file" -goto:$line')
51 install_editor(exe + ' "$file" -goto:$line')
50
52
51 def notepadplusplus(exe = 'notepad++'):
53 def notepadplusplus(exe = 'notepad++'):
52 """ Notepad++ http://notepad-plus.sourceforge.net """
54 """ Notepad++ http://notepad-plus.sourceforge.net """
53 install_editor(exe + ' -n$line "$file"')
55 install_editor(exe + ' -n$line "$file"')
54
56
55 def jed(exe = 'jed'):
57 def jed(exe = 'jed'):
56 """ JED, the lightweight emacsish editor """
58 """ JED, the lightweight emacsish editor """
57 install_editor(exe + ' +$line "$file"')
59 install_editor(exe + ' +$line "$file"')
58
60
59 def idle(exe = None):
61 def idle(exe = None):
60 """ Idle, the editor bundled with python
62 """ Idle, the editor bundled with python
61
63
62 Should be pretty smart about finding the executable.
64 Should be pretty smart about finding the executable.
63 """
65 """
64 if exe is None:
66 if exe is None:
65 import idlelib
67 import idlelib
66 p = os.path.dirname(idlelib.__file__)
68 p = os.path.dirname(idlelib.__file__)
67 exe = p + '/idle.py'
69 exe = p + '/idle.py'
68 install_editor(exe + ' "$file"')
70 install_editor(exe + ' "$file"')
69
71
70 def mate(exe = 'mate'):
72 def mate(exe = 'mate'):
71 """ TextMate, the missing editor"""
73 """ TextMate, the missing editor"""
72 install_editor(exe + ' -w -l $line "$file"')
74 install_editor(exe + ' -w -l $line "$file"')
73
75
74 # these are untested, report any problems
76 # these are untested, report any problems
75
77
76 def emacs(exe = 'emacs'):
78 def emacs(exe = 'emacs'):
77 install_editor(exe + ' +$line "$file"')
79 install_editor(exe + ' +$line "$file"')
78
80
79 def gnuclient(exe= 'gnuclient'):
81 def gnuclient(exe= 'gnuclient'):
80 install_editor(exe + ' -nw +$line "$file"')
82 install_editor(exe + ' -nw +$line "$file"')
81
83
82 def crimson_editor(exe = 'cedt.exe'):
84 def crimson_editor(exe = 'cedt.exe'):
83 install_editor(exe + ' /L:$line "$file"')
85 install_editor(exe + ' /L:$line "$file"')
84
86
85 def kate(exe = 'kate'):
87 def kate(exe = 'kate'):
86 install_editor(exe + ' -u -l $line "$file"')
88 install_editor(exe + ' -u -l $line "$file"')
87
89
88
90
89 No newline at end of file
91
@@ -1,65 +1,67 b''
1 """ IPython extension: Render templates from variables and paste to clipbard """
1 """ IPython extension: Render templates from variables and paste to clipbard """
2
2
3 from IPython.core import ipapi
3 from IPython.core import ipapi
4
4
5 ip = ipapi.get()
5 ip = ipapi.get()
6
6
7 from string import Template
7 from string import Template
8 import sys,os
8 import sys,os
9
9
10 # We no longer bundle Itpl. If you update this module, you should use advanced
11 # string formatting instead.
10 from IPython.external.Itpl import itplns
12 from IPython.external.Itpl import itplns
11
13
12 def toclip_w32(s):
14 def toclip_w32(s):
13 """ Places contents of s to clipboard
15 """ Places contents of s to clipboard
14
16
15 Needs pyvin32 to work:
17 Needs pyvin32 to work:
16 http://sourceforge.net/projects/pywin32/
18 http://sourceforge.net/projects/pywin32/
17 """
19 """
18 import win32clipboard as cl
20 import win32clipboard as cl
19 import win32con
21 import win32con
20 cl.OpenClipboard()
22 cl.OpenClipboard()
21 cl.EmptyClipboard()
23 cl.EmptyClipboard()
22 cl.SetClipboardText( s.replace('\n','\r\n' ))
24 cl.SetClipboardText( s.replace('\n','\r\n' ))
23 cl.CloseClipboard()
25 cl.CloseClipboard()
24
26
25 try:
27 try:
26 import win32clipboard
28 import win32clipboard
27 toclip = toclip_w32
29 toclip = toclip_w32
28 except ImportError:
30 except ImportError:
29 def toclip(s): pass
31 def toclip(s): pass
30
32
31
33
32 def render(tmpl):
34 def render(tmpl):
33 """ Render a template (Itpl format) from ipython variables
35 """ Render a template (Itpl format) from ipython variables
34
36
35 Example:
37 Example:
36
38
37 $ import ipy_render
39 $ import ipy_render
38 $ my_name = 'Bob' # %store this for convenience
40 $ my_name = 'Bob' # %store this for convenience
39 $ t_submission_form = "Submission report, author: $my_name" # %store also
41 $ t_submission_form = "Submission report, author: $my_name" # %store also
40 $ render t_submission_form
42 $ render t_submission_form
41
43
42 => returns "Submission report, author: Bob" and copies to clipboard on win32
44 => returns "Submission report, author: Bob" and copies to clipboard on win32
43
45
44 # if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
46 # if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
45 $ ;render c:/templates/greeting.txt
47 $ ;render c:/templates/greeting.txt
46
48
47 Template examples (Ka-Ping Yee's Itpl library):
49 Template examples (Ka-Ping Yee's Itpl library):
48
50
49 Here is a $string.
51 Here is a $string.
50 Here is a $module.member.
52 Here is a $module.member.
51 Here is an $object.member.
53 Here is an $object.member.
52 Here is a $functioncall(with, arguments).
54 Here is a $functioncall(with, arguments).
53 Here is an ${arbitrary + expression}.
55 Here is an ${arbitrary + expression}.
54 Here is an $array[3] member.
56 Here is an $array[3] member.
55 Here is a $dictionary['member'].
57 Here is a $dictionary['member'].
56 """
58 """
57
59
58 if os.path.isfile(tmpl):
60 if os.path.isfile(tmpl):
59 tmpl = open(tmpl).read()
61 tmpl = open(tmpl).read()
60
62
61 res = itplns(tmpl, ip.user_ns)
63 res = itplns(tmpl, ip.user_ns)
62 toclip(res)
64 toclip(res)
63 return res
65 return res
64
66
65 ip.push('render')
67 ip.push('render')
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now