a
    ø£BeŽ  ã                   @   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 u 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   © úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/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u 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








