ó
&9_[c           @   sh  d  d l  Z  d  d l Z d  d l m Z m Z d  d l m Z m Z m Z m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z e d „  ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  e j! d k rdd  d l" m# Z# d  d l$ m% Z% m& Z& m' Z' e d „  ƒ Z( n  d S(   iÿÿÿÿN(   t   DEFAULT_BUFFERt   SEARCH_BUFFER(   t   HasFocust   HasSelectiont	   Conditiont   ViInsertModet   EmacsInsertModet   HasCompletions(   t   ViMode(   t   Keys(   t!   display_completions_like_readline(   t   undocc         C   s#   |  j  j j j } | p" | j ƒ  S(   N(   t   applicationt   buffert   documentt   current_line_before_cursort   isspace(   t   clit   before(    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyt   cursor_in_leading_ws   s    c         C   sF  t  ƒ  t ƒ  B} |  j t j d t t ƒ t ƒ  @| @ƒt | ƒ ƒ |  j t j	 ƒ t
 ƒ |  j t j d t  ƒ  t t ƒ @ƒt ƒ |  j t j d t  ƒ  t t ƒ @ƒt ƒ |  j t j d t t ƒ t ƒ  @ƒt ƒ |  j t j d t t ƒ ƒt ƒ |  j t j d t t ƒ ƒt ƒ t d „  ƒ } |  j t j d | ƒt ƒ |  j t j d t t ƒ t ƒ  @| @t @ƒt ƒ |  j t j d t t ƒ t ƒ  @ƒt ƒ |  j t j d t t ƒ ƒt ƒ | j  d k r|  j t j d t t ƒ t ƒ  @| @t @ƒt! ƒ n  t" j# d k rB|  j t j$ d t t ƒ t% ƒ  @ƒt& ƒ n  d S(   s8   Set up the prompt_toolkit keyboard shortcuts for IPythont   filterc         S   s   t  t d ƒ S(   Nt   SIGTSTP(   t   hasattrt   signal(   R   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyt   <lambda>1   s    t   readlineliket   win32N('   R   R   t   add_bindingR	   t   ControlJR   R    R   t   newline_or_execute_outert   ControlBackslasht
   force_exitt   ControlPt'   previous_history_or_previous_completiont   ControlNt   next_history_or_next_completiont   ControlGR   t   dismiss_completiont   ControlCt   reset_bufferR   t   reset_search_bufferR   t   ControlZt   suspend_to_bgt   ControlIR   t   indent_buffert   ControlOt   newline_with_copy_margint   F2t   open_input_in_editort   display_completionsR
   t   syst   platformt   ControlVR   t	   win_paste(   t   registryt   shellt   insert_modet   supports_suspend(    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyt   register_ipython_shortcuts   sN    	
c            s   ‡  f d †  } | S(   Nc            s&  |  j  } | j } | j rK | j j } | r= | j | ƒ n
 | j ƒ  d S| j d k rf | j } n | j | j  } ˆ  j	 j
 | d ƒ \ } } | j p´ | j | j | j ƒ  k sÖ | j d d | pÌ d ƒ d S| d k r| j j r| j j |  j | ƒ n | j d d | pd ƒ d S(   sC   When the user presses return, insert a newline or execute the code.Ni   s   
t    i    t
   incomplete(   t   current_bufferR   t   complete_statet   current_completiont   apply_completiont   cancel_completiont
   line_countt   textt   cursor_positiont   input_splittert   check_completet   on_last_linet   cursor_position_rowt   empty_line_count_at_the_endt   insert_textt   accept_actiont   is_returnablet   validate_and_handleR   (   t   eventt   bt   dt   cct
   check_textt   statust   indent(   R7   (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyt   newline_or_executeV   s&    			
	(    (   R7   RU   (    (   R7   s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR   U   s    c         C   s   |  j  j ƒ  d S(   s    
    Control-P in vi edit mode on readline is history next, unlike default prompt toolkit.

    If completer is open this still select previous completion.
    N(   R=   t   auto_up(   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR!   x   s    c         C   s   |  j  j ƒ  d S(   s    
    Control-N in vi edit mode on readline is history previous, unlike default prompt toolkit.

    If completer is open this still select next completion.
    N(   R=   t	   auto_down(   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR#      s    c         C   s#   |  j  } | j r | j ƒ  n  d  S(   N(   R=   R>   RA   (   RN   RO   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR%   Š   s    		c         C   s-   |  j  } | j r | j ƒ  n
 | j ƒ  d  S(   N(   R=   R>   RA   t   reset(   RN   RO   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR'      s    		c         C   s3   |  j  j j r |  j  j ƒ  n |  j j t ƒ d  S(   N(   R=   R   RC   RX   R   t
   push_focusR    (   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR(   ˜   s    c         C   s   |  j  j ƒ  d  S(   N(   R   t   suspend_to_background(   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR*      s    c         C   s   t  j d ƒ d S(   s3   
    Force exit (with a non-zero return value)
    t   QuitN(   R2   t   exit(   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR   ¡   s    c         C   s   |  j  j d ƒ d  S(   NR;   i   s       (   R=   RJ   (   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR,   §   s    c         C   sn   |  j  } | j j } | j d t ƒ | j d d ƒ | j j } | | k rj | | } | j d | ƒ n  d S(   sh   
    Preserve margin and cursor position when using
    Control-O to insert a newline in EMACS mode
    t   copy_margint   counti   N(   R=   R   t   cursor_position_colt   newlinet   Truet	   cursor_upt   cursor_right(   RN   RO   t   cursor_start_post   cursor_end_post   pos_diff(    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR.   ª   s    	
c         C   s)   d |  j  j _ |  j  j j |  j  ƒ d  S(   Ns   .py(   R   R=   t   tempfile_suffixt   open_in_editor(   RN   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR0   ¸   s    R   (   t   TryNext(   t   ClipboardEmptyt   win32_clipboard_gett   tkinter_clipboard_getc         C   sz   y t  ƒ  } WnJ t k
 rH y t ƒ  } WqZ t t f k
 rD d  SXn t k
 rY d  SX|  j j | j d d ƒ ƒ d  S(   Ns   	R;   i   s       (   Rk   Ri   Rl   Rj   R=   RJ   t   replace(   RN   RC   (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyR5   Ã   s    ()   R   R2   t   prompt_toolkit.enumsR    R   t   prompt_toolkit.filtersR   R   R   R   R   R   t   prompt_toolkit.filters.cliR   t   prompt_toolkit.keysR	   t.   prompt_toolkit.key_binding.bindings.completionR
   t   IPython.utils.decoratorsR   R   R:   R   R!   R#   R%   R'   R(   R*   R   R,   R.   R0   R3   t   IPython.core.errorRi   t   IPython.lib.clipboardRj   Rk   Rl   R5   (    (    (    s9   lib/python2.7/site-packages/IPython/terminal/shortcuts.pyt   <module>   s0   .	C	#												