##// END OF EJS Templates
Merge pull request #7011 from jdfreder/killthelayout...
Merge pull request #7011 from jdfreder/killthelayout Kill the layout manager

File last commit:

r18869:8cb6a801
r19249:949cf57f merge
Show More
editorhooks.py
129 lines | 3.9 KiB | text/x-python | PythonLexer
vivainio
crlf normalization
r851 """ 'editor' hooks for common editors that work well with ipython
They should honor the line number argument, at least.
Contributions are *very* welcome.
"""
Thomas Kluyver
Convert print statements to print function calls...
r13348 from __future__ import print_function
vivainio
crlf normalization
r851
import os
Robert McGibbon
Using pipes.quote
r9660 import pipes
Min RK
use shlex.split on editor hooks on Windows...
r18836 import shlex
Robert McGibbon
Using pipes.quote
r9660 import subprocess
Min RK
fix editorhooks typo...
r18869 import sys
MinRK
Don't rely on `get_ipython` in builtins in library code
r10580
from IPython import get_ipython
Robert McGibbon
Using pipes.quote
r9660 from IPython.core.error import TryNext
Thomas Kluyver
Fix references to raw_input()
r13355 from IPython.utils import py3compat
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Min RK
fix editorhooks typo...
r18869 def install_editor(template, wait=False):
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 """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 invoked
by IPython -- (e.g. the format in which it accepts command line options)
Parameters
----------
Robert McGibbon
rename the file to lib/editorhooks.py and chance string template to {} formating
r8880 template : basestring
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 run_template acts as a template for how your editor is invoked by
Robert McGibbon
editorhooks working with qtconsole
r8891 the shell. It should contain '{filename}', which will be replaced on
Robert McGibbon
rename the file to lib/editorhooks.py and chance string template to {} formating
r8880 invokation with the file name, and '{line}', $line by line number
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 (or 0) to invoke the file with.
wait : bool
If `wait` is true, wait until the user presses enter before returning,
to facilitate non-blocking editors that exit immediately after
the call.
vivainio
crlf normalization
r851 """
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
tried to fix idle
r8820 # not all editors support $line, so we'll leave out this check
# for substitution in ['$file', '$line']:
# if not substitution in run_template:
# raise ValueError(('run_template should contain %s'
# ' for string substitution. You supplied "%s"' % (substitution,
# run_template)))
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def call_editor(self, filename, line=0):
vivainio
crlf normalization
r851 if line is None:
line = 0
Robert McGibbon
Using pipes.quote
r9660 cmd = template.format(filename=pipes.quote(filename), line=line)
Thomas Kluyver
Convert print statements to print function calls...
r13348 print(">", cmd)
Min RK
use shlex.split on editor hooks on Windows...
r18836 # pipes.quote doesn't work right on Windows, but it does after splitting
if sys.platform.startswith('win'):
cmd = shlex.split(cmd)
Robert McGibbon
editorhooks working with qtconsole
r8891 proc = subprocess.Popen(cmd, shell=True)
if wait and proc.wait() != 0:
Brian Granger
Continuing a massive refactor of everything.
r2205 raise TryNext()
vivainio
crlf normalization
r851 if wait:
Thomas Kluyver
Fix references to raw_input()
r13355 py3compat.input("Press Enter when done editing:")
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 get_ipython().set_hook('editor', call_editor)
Robert McGibbon
editorhooks working with qtconsole
r8891 get_ipython().editor = template
vivainio
crlf normalization
r851
# in these, exe is always the path/name of the executable. Useful
# if you don't have the editor directory in your path
Robert McGibbon
editorhooks working with qtconsole
r8891 def komodo(exe=u'komodo'):
vivainio
crlf normalization
r851 """ Activestate Komodo [Edit] """
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' -l {line} {filename}', wait=True)
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
vivainio
crlf normalization
r851
Robert McGibbon
editorhooks working with qtconsole
r8891 def scite(exe=u"scite"):
vivainio
crlf normalization
r851 """ SciTE or Sc1 """
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' {filename} -goto:{line}')
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def notepadplusplus(exe=u'notepad++'):
vivainio
crlf normalization
r851 """ Notepad++ http://notepad-plus.sourceforge.net """
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' -n{line} {filename}')
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def jed(exe=u'jed'):
vivainio
crlf normalization
r851 """ JED, the lightweight emacsish editor """
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' +{line} {filename}')
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def idle(exe=u'idle'):
vivainio
crlf normalization
r851 """ Idle, the editor bundled with python
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
tried to fix idle
r8820 Parameters
----------
exe : str, None
If none, should be pretty smart about finding the executable.
vivainio
crlf normalization
r851 """
if exe is None:
import idlelib
Robert McGibbon
editorhooks working with qtconsole
r8891 p = os.path.dirname(idlelib.__filename__)
Robert McGibbon
Using pipes.quote
r9660 # i'm not sure if this actually works. Is this idle.py script
# guarenteed to be executable?
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 exe = os.path.join(p, 'idle.py')
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' {filename}')
Brian Granger
Adding TextMate to ipy_editor.py thanks to Matt Foster for the patch.
r1782
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def mate(exe=u'mate'):
Brian Granger
Adding TextMate to ipy_editor.py thanks to Matt Foster for the patch.
r1782 """ TextMate, the missing editor"""
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 # wait=True is not required since we're using the -w flag to mate
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' -w -l {line} {filename}')
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
# ##########################################
vivainio
crlf normalization
r851 # these are untested, report any problems
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819 # ##########################################
vivainio
crlf normalization
r851
Robert McGibbon
editorhooks working with qtconsole
r8891 def emacs(exe=u'emacs'):
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' +{line} {filename}')
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def gnuclient(exe=u'gnuclient'):
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' -nw +{line} {filename}')
vivainio
crlf normalization
r851
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def crimson_editor(exe=u'cedt.exe'):
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' /L:{line} {filename}')
Robert McGibbon
Fixed quarentine/ipy_editor.py so that it (0) uses string formatting instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
r8819
Robert McGibbon
editorhooks working with qtconsole
r8891 def kate(exe=u'kate'):
Robert McGibbon
Using pipes.quote
r9660 install_editor(exe + u' -u -l {line} {filename}')