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