MCPcopy Create free account
hub / github.com/ipython/ipython / install_editor

Function install_editor

IPython/lib/editorhooks.py:19–62  ·  view source on GitHub ↗

Installs the editor that is called by IPython for the %edit magic. This overrides the default editor, which is generally set by your EDITOR environment variable or is notepad (windows) or vi (linux). By supplying a template string `run_template`, you can control how the editor is invoke

(template, wait=False)

Source from the content-addressed store, hash-verified

17
18
19def install_editor(template, wait=False):
20 """Installs the editor that is called by IPython for the %edit magic.
21
22 This overrides the default editor, which is generally set by your EDITOR
23 environment variable or is notepad (windows) or vi (linux). By supplying a
24 template string `run_template`, you can control how the editor is invoked
25 by IPython -- (e.g. the format in which it accepts command line options)
26
27 Parameters
28 ----------
29 template : basestring
30 run_template acts as a template for how your editor is invoked by
31 the shell. It should contain '{filename}', which will be replaced on
32 invocation with the file name, and '{line}', $line by line number
33 (or 0) to invoke the file with.
34 wait : bool
35 If `wait` is true, wait until the user presses enter before returning,
36 to facilitate non-blocking editors that exit immediately after
37 the call.
38 """
39
40 # not all editors support $line, so we'll leave out this check
41 # for substitution in ['$file', '$line']:
42 # if not substitution in run_template:
43 # raise ValueError(('run_template should contain %s'
44 # ' for string substitution. You supplied "%s"' % (substitution,
45 # run_template)))
46
47 def call_editor(self, filename, line=0):
48 if line is None:
49 line = 0
50 cmd = template.format(filename=pipes.quote(filename), line=line)
51 print(">", cmd)
52 # pipes.quote doesn't work right on Windows, but it does after splitting
53 if sys.platform.startswith('win'):
54 cmd = shlex.split(cmd)
55 proc = subprocess.Popen(cmd, shell=True)
56 if proc.wait() != 0:
57 raise TryNext()
58 if wait:
59 py3compat.input("Press Enter when done editing:")
60
61 get_ipython().set_hook('editor', call_editor)
62 get_ipython().editor = template
63
64
65# in these, exe is always the path/name of the executable. Useful

Callers 10

komodoFunction · 0.85
sciteFunction · 0.85
notepadplusplusFunction · 0.85
jedFunction · 0.85
idleFunction · 0.85
mateFunction · 0.85
emacsFunction · 0.85
gnuclientFunction · 0.85
crimson_editorFunction · 0.85
kateFunction · 0.85

Calls 2

get_ipythonFunction · 0.90
set_hookMethod · 0.80

Tested by

no test coverage detected