U
    1e                     @   s   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 dddZd d
d	Zd!ddZd"ddZd#ddZd$ddZd%ddZd&ddZd'ddZd(ddZd)ddZdS )*z 'editor' hooks for common editors that work well with ipython

They should honor the line number argument, at least.

Contributions are *very* welcome.
    N)get_ipython)TryNext)	py3compatFc                    s*   d fdd	}t  d|  t  _dS )ay  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
    ----------
    template : basestring
        run_template acts as a template for how your editor is invoked by
        the shell. It should contain '{filename}', which will be replaced on
        invocation with the file name, and '{line}', $line by line number
        (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.
    r   c                    sr   |d krd} j t||d}td| tjdr@t|}tj	|dd}|
 dkr`t rntd d S )Nr   )filenameline>winT)shellzPress Enter when done editing:)formatshlexquoteprintsysplatform
startswithsplit
subprocessPopenwaitr   r   input)selfr   r   cmdproctemplater    ;/tmp/pip-unpacked-wheel-3hxk2k58/IPython/lib/editorhooks.pycall_editor.   s    

z#install_editor.<locals>.call_editoreditorN)r   )r   Zset_hookr   )r   r   r   r   r   r   install_editor   s    r   komodoc                 C   s   t | d dd dS )z Activestate Komodo [Edit] z -l {line} {filename}T)r   Nr   exer   r   r   r    B   s    scitec                 C   s   t | d  dS )z SciTE or Sc1 z {filename} -goto:{line}Nr!   r"   r   r   r   r$   G   s    	notepad++c                 C   s   t | d  dS )z/ Notepad++ http://notepad-plus.sourceforge.net z -n{line} {filename}Nr!   r"   r   r   r   notepadplusplusL   s    r&   jedc                 C   s   t | d  dS )z& JED, the lightweight emacsish editor  +{line} {filename}Nr!   r"   r   r   r   r'   Q   s    idlec                 C   s<   | dkr,ddl }tj|j}tj|d} t| d  dS )z Idle, the editor bundled with python

    Parameters
    ----------
    exe : str, None
        If none, should be pretty smart about finding the executable.
    Nr   zidle.pyz {filename})idlelibospathdirnameZ__filename__joinr   )r#   r*   pr   r   r   r)   V   s
    matec                 C   s   t | d  dS )z TextMate, the missing editorz -w -l {line} {filename}Nr!   r"   r   r   r   r0   g   s    emacsc                 C   s   t | d  d S )Nr(   r!   r"   r   r   r   r1   r   s    	gnuclientc                 C   s   t | d  d S )Nz -nw +{line} {filename}r!   r"   r   r   r   r2   v   s    cedt.exec                 C   s   t | d  d S )Nz /L:{line} {filename}r!   r"   r   r   r   crimson_editorz   s    r4   katec                 C   s   t | d  d S )Nz -u -l {line} {filename}r!   r"   r   r   r   r5   ~   s    )F)r    )r$   )r%   )r'   )r)   )r0   )r1   )r2   )r3   )r5   )__doc__r+   r   r   r   ZIPythonr   ZIPython.core.errorr   ZIPython.utilsr   r   r    r$   r&   r'   r)   r0   r1   r2   r4   r5   r   r   r   r   <module>   s$   
0








