ó
±xYc           @  s  d  d l  m Z d  d l m Z m Z m Z d  d l m Z d  d l m	 Z	 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 m Z d d	 l m Z d
 d l m Z m Z d d d d f Z d „  Z d „  Z d „  Z  e! d „ Z" d „  Z# d S(   iÿÿÿÿ(   t   unicode_literals(   t   SelectionTypet   indentt   unindent(   t   Keys(   t   IncrementalSearchDirectiont   SEARCH_BUFFERt   SYSTEM_BUFFER(   t	   Conditiont	   EmacsModet   HasSelectiont   EmacsInsertModet   HasFocust   HasArg(   t   CompleteEventi   (   t   scroll_page_upt   scroll_page_down(   t   get_by_namei   (   t   Registryt   ConditionalRegistryu   load_emacs_bindingsu   load_emacs_search_bindingsu   load_emacs_system_bindingsu)   load_extra_emacs_page_navigation_bindingsc            s]  t  t ƒ  t ƒ  ƒ }  |  j ‰ t ƒ  } t ƒ  } ˆ t j ƒ d „  ƒ } ˆ t j ƒ t	 d ƒ ƒ ˆ t j
 ƒ t	 d ƒ ƒ ˆ t j d | ƒt	 d ƒ ƒ ˆ t j ƒ t	 d ƒ ƒ ˆ t j ƒ t	 d ƒ ƒ ˆ t j ƒ t	 d ƒ ƒ ˆ t j ƒ t	 d	 ƒ ƒ ˆ t j d
 d d | ƒt	 d ƒ ƒ ˆ t j d | ƒt	 d ƒ ƒ ˆ t j d ƒ t	 d ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j d ƒ t	 d	 ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j t j d | ƒt	 d ƒ ƒ ˆ t j t j d | ƒt	 d ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j d d „  d | ƒt	 d ƒ ƒ ˆ t j t j d d „  d | ƒt	 d ƒ ƒ ˆ t j d d | ƒt	 d ƒ ƒ ˆ t j d  d | ƒt	 d! ƒ ƒ ˆ t j d" d | ƒt	 d# ƒ ƒ ˆ t j d$ d | ƒt	 d# ƒ ƒ ˆ t j t j d | ƒt	 d% ƒ ƒ ˆ t j d& d | ƒt	 d' ƒ ƒ ˆ t j ƒ t	 d( ƒ ƒ ˆ t j d | ƒt	 d) ƒ ƒ ˆ t j d* ƒ t	 d+ ƒ ƒ ˆ t j d, ƒ t	 d- ƒ ƒ ˆ t j d. ƒ t	 d/ ƒ ƒ ˆ t j ƒ d0 „  ƒ } ˆ t j ƒ d1 „  ƒ } ‡ f d2 †  } x d3 D] } | | ƒ q‰Wˆ t j d4 d t ƒ  ƒd5 „  ƒ } ˆ d4 d t d6 „  ƒ ƒd7 „  ƒ } t d8 „  ƒ } ˆ t j t j d | | @ƒt	 d9 ƒ ƒ d: „  ‰  ˆ t j t j ƒ ‡  f d; †  ƒ } ˆ t j t j t j ƒ ‡  f d< †  ƒ } ˆ t j d= ƒ d> „  ƒ } ˆ t j d. ƒ d? „  ƒ } ˆ t j d@ d | ƒdA „  ƒ } ˆ t j dB d | ƒdC „  ƒ } ˆ t j t j ƒ dD „  ƒ } ˆ t j ƒ dE „  ƒ } ˆ t j  d | ƒdF „  ƒ } ˆ t j  d | ƒdG „  ƒ } ˆ t j! d | ƒˆ t j d
 dH d | ƒdI „  ƒ ƒ } ˆ t j dJ d | ƒdK „  ƒ } ˆ t j t j" ƒ dL „  ƒ } ˆ t j t j# ƒ dM „  ƒ } ˆ t j dN d | ƒdO „  ƒ } ˆ t j$ d  d | ƒdP „  ƒ } ˆ t j$ d d | ƒdQ „  ƒ } |  S(R   u!   
    Some e-macs extensions.
    c         S  s   d S(   u\  
        By default, ignore escape key.

        (If we don't put this here, and Esc is followed by a key which sequence
        is not handled, we'll insert an Escape character in the input stream.
        Something we don't want and happens to easily in emacs mode.
        Further, people can always use ControlQ to do a quoted insert.)
        N(    (   t   event(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   _!   s    
u   beginning-of-lineu   backward-chart   filteru	   kill-wordu   end-of-lineu   forward-charu   backward-wordu   forward-wordu   ru   yu   yanku   bu   cu   capitalize-wordu   du   fu   lu   downcase-wordu   uu   uppercase-wordu   yank-popu   backward-kill-wordu   \u   delete-horizontal-spacet   save_beforec         S  s   t  S(   N(   t   False(   t   e(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   <lambda>A   s    u   undoc         S  s   t  S(   N(   R   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   D   s    u   <u   beginning-of-historyu   >u   end-of-historyu   .u   yank-last-argu   _u   yank-nth-argu   #u   insert-commentu   operate-and-get-nextu   quoted-insertu   (u   start-kbd-macrou   )u   end-kbd-macrou   eu   call-last-kbd-macroc         S  s   |  j  j ƒ  d S(   u    Next line. N(   t   current_buffert	   auto_down(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   Z   s    c         S  s   |  j  j d |  j ƒ d S(   u    Previous line. t   countN(   R   t   auto_upt   arg(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   _   s    c           s:   ˆ ˆ  d t  ƒ  ƒˆ t j ˆ  ƒ ‡  f d †  ƒ ƒ } d S(   uf   
        Handle input of arguments.
        The first number needs to be preceeded by escape.
        R   c           s   |  j  ˆ  ƒ d  S(   N(   t   append_to_arg_count(   R   (   t   c(    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   i   s    N(   R   R   t   Escape(   R!   R   (   t   handle(   R!   sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   handle_digitd   s    u
   0123456789u   -c         S  s#   |  j  d k r |  j d ƒ n  d S(   u	   
        u   -N(   t   _argt   NoneR    (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   q   s    c         S  s   |  j  j d k S(   Nu   -(   t   input_processorR   (   t   cli(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   x   s    c         S  s   d |  j  j _ d S(   up   
        When '-' is typed again, after exactly '-' has been given as an
        argument, ignore this.
        u   -N(   R(   R'   R   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   x   s    c         S  s   |  j  j j S(   N(   R   t   accept_actiont   is_returnable(   R(   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR      s    u   accept-linec         S  sn   | d k  r. |  j  j | d t d | ƒ} n |  j  j | d t d | ƒ} | d  k	 rj |  j | 7_ n  d  S(   Ni    t   in_current_lineR   (   t   documentt   find_backwardst   Truet   findR&   t   cursor_position(   t   bufft   charR   t   match(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   character_search‡   s
    "c           s   ˆ  |  j  |  j |  j ƒ d S(   u<    When Ctl-] + a character is pressed. go to that character. N(   R   t   dataR   (   R   (   R4   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR      s    c           s   ˆ  |  j  |  j |  j ƒ d S(   u    Like Ctl-], but backwards. N(   R   R5   R   (   R   (   R4   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   –   s    u   ac         S  s   d S(   u    Previous sentence. N(    (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   œ   s    c         S  s   d S(   u    Move to end of sentence. N(    (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ¡   s    u   tc         S  s   d S(   u<   
        Swap the last two words before the cursor.
        N(    (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ¦   s    u   *c         S  sf   |  j  } t d t d t ƒ } t | j j | j | ƒ ƒ } d j d „  | Dƒ ƒ } | j	 | ƒ d S(   uR   
        `meta-*`: Insert all possible completions of the preceding text.
        t   text_insertedt   completion_requestedu    c         s  s   |  ] } | j  Vq d  S(   N(   t   text(   t   .0R!   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pys	   <genexpr>¹   s    N(
   R   R   R   R.   t   listt	   completert   get_completionsR,   t   joint   insert_text(   R   R1   t   complete_eventt   completionst   text_to_insert(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ­   s
    	c         S  sR   |  j  } | j j r6 | j | j j d t ƒ 7_ n | j | j j ƒ  7_ d S(   uc   
        Move cursor back and forth between the start and end of the current
        line.
        t   after_whitespaceN(   R   R,   t   is_cursor_at_the_end_of_lineR0   t   get_start_of_line_positionR   t   get_end_of_line_position(   R   t   buffer(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ¼   s    	!c         S  s,   |  j  } | j r( | j d t j ƒ n  d S(   uN   
        Start of the selection (if the current buffer is not empty).
        t   selection_typeN(   R   R8   t   start_selectionR   t
   CHARACTERS(   R   R1   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   É   s    		c         S  s   d |  j _ d |  j _ d S(   uK   
        Control + G: Cancel completion menu and validation state.
        N(   R&   R   t   complete_statet   validation_error(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   Ó   s    c         S  s   |  j  j ƒ  d S(   u#   
        Cancel selection.
        N(   R   t   exit_selection(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   Û   s    u   kc         S  s&   |  j  j ƒ  } |  j j j | ƒ d S(   u$   
        Cut selected text.
        N(   R   t   cut_selectionR(   t	   clipboardt   set_data(   R   R5   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   â   s    u   wc         S  s&   |  j  j ƒ  } |  j j j | ƒ d S(   u%   
        Copy selected text.
        N(   R   t   copy_selectionR(   RN   RO   (   R   R5   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ë   s    c         S  s4   |  j  } | j | j j d |  j ƒ p+ d 7_ d S(   u3   
        Cursor to start of previous word.
        R   i    N(   R   R0   R,   t   find_previous_word_beginningR   (   R   RF   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ó   s    	c         S  s=   |  j  } | j | j j d |  j ƒ p4 | j j ƒ  7_ d S(   u/   
        Cursor to start of next word.
        R   N(   R   R0   R,   t   find_next_word_beginningR   t   get_end_of_document_position(   R   RF   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   û   s    	u   /c         S  s6   |  j  } | j r | j ƒ  n |  j j d t ƒ d S(   u    
        M-/: Complete.
        t   select_firstN(   R   RJ   t   complete_nextR(   t   start_completionR.   (   R   t   b(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR     s    		c         S  s   |  j  } | j | j j d t ƒ 7_ | j j ƒ  \ } } | j j | ƒ \ } } | j j | ƒ \ } } t | | | d d |  j ƒd S(   u'   
        Indent selected text.
        RB   i   R   N(	   R   R0   R,   RD   R.   t   selection_ranget   translate_index_to_positionR   R   (   R   RF   t   from_t   toR   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR     s    	c         S  so   |  j  } | j j ƒ  \ } } | j j | ƒ \ } } | j j | ƒ \ } } t | | | d d |  j ƒd S(   u)   
        Unindent selected text.
        i   R   N(   R   R,   RX   RY   R   R   (   R   RF   RZ   R[   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR     s
    	(%   R   R   R	   t   add_bindingR   R
   R   R"   t   ControlAR   t   ControlBt   ControlDeletet   ControlEt   ControlFt   ControlLeftt   ControlRightt   ControlXt   ControlYt   ControlHt	   Backspacet   ControlUnderscoret   ControlUt   ControlOt   ControlQt   ControlNt   ControlPR   R   t   ControlJt   ControlSquareCloset   Anyt   ControlSpacet   ControlGt   ControlWt   Leftt   Rightt   ControlC(   t   registryt   insert_modet   has_selectionR   R$   R!   R*   (    (   R4   R#   sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   load_emacs_bindings   sŒ    			%"""""%%"!##""%" 
%$		$*!!
'!	!!!c          C  s@   t  ƒ  }  |  j t j t j d t ƒ  t ƒ  @ƒt d ƒ ƒ |  S(   uF   
    Pressing C-X C-E will open the buffer in an external editor.
    R   u   edit-and-execute-command(   R   R\   R   Rd   R`   R	   R
   R   (   Rw   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt"   load_emacs_open_in_editor_bindings.  s
    	c          C  s¶   t  t ƒ  t ƒ  ƒ }  |  j } t t ƒ } | t j d d | ƒd „  ƒ } | t j d | ƒ| t j d | ƒ| t j	 d | ƒd „  ƒ ƒ ƒ } | t j
 d | ƒd „  ƒ } |  S(   Nu   !R   c         S  s   |  j  j t ƒ d S(   u0   
        M-'!' opens the system prompt.
        N(   R(   t
   push_focusR   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   A  s    c         S  s%   |  j  j t j ƒ  |  j  j ƒ  d S(   u'   
        Cancel system prompt.
        N(   R(   t   buffersR   t   resett	   pop_focus(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   H  s    c         S  sD   |  j  j t } |  j  j | j ƒ | j d t ƒ |  j  j ƒ  d S(   u%   
        Run system command.
        t   append_to_historyN(   R(   R}   R   t   run_system_commandR8   R~   R.   R   (   R   t   system_line(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   R  s    (   R   R   R	   R\   R   R   R   R"   Rr   Rv   Rn   (   Rw   R#   t	   has_focusR   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   load_emacs_system_bindings;  s    	"$c           sž  t  t ƒ  t ƒ  ƒ } | j } t t ƒ } ˆ  d  k sH t ˆ  ƒ sH t ‚ ˆ  sZ d „  ‰  n  | t	 j
 d | ƒ| t	 j d | ƒd „  ƒ ƒ } | t	 j d | ƒ| t	 j d | d t ƒ‡  f d †  ƒ ƒ } | t	 j d | ƒ‡  f d †  ƒ } | t	 j d | ƒ‡  f d †  ƒ } d ‡  f d	 † ‰ | t	 j d | ƒ| t	 j d | ƒ‡ f d
 †  ƒ ƒ } | t	 j d | ƒ| t	 j d | ƒ‡ f d †  ƒ ƒ } | S(   Nc         S  s   |  j  S(   N(   t   search_state(   R(   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   get_search_statej  s    R   c         S  s+   |  j  j t } | j ƒ  |  j  j ƒ  d S(   uL   
        Abort an incremental search and restore the original line.
        N(   R(   R}   R   R~   R   (   R   t   search_buffer(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   l  s    
t   eagerc           sŠ   |  j  j j |  j  ƒ } |  j  j t } | j rI | j ˆ  |  j  ƒ _ n  | j ˆ  |  j  ƒ d t ƒ| j ƒ  | j ƒ  |  j  j	 ƒ  d S(   uy   
        When enter pressed in isearch, quit isearch mode. (Multiline
        isearch would be too complicated.)
        t   include_current_positionN(
   R(   R}   t   previousR   R8   t   apply_searchR.   R€   R~   R   (   R   t   input_bufferR‡   (   R†   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   y  s    	

c           s)   t  j ˆ  |  j ƒ _ |  j j t ƒ d  S(   N(   R   t   BACKWARDR(   t	   directionR|   R   (   R   (   R†   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ‘  s    c           s)   t  j ˆ  |  j ƒ _ |  j j t ƒ d  S(   N(   R   t   FORWARDR(   RŽ   R|   R   (   R   (   R†   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   –  s    i   c           so   ˆ  |  ƒ } | j  | k } |  j t j | _ | | _  | sk |  j j |  ƒ } | j | d t d | ƒn  d S(   u0    Apply search, but keep search buffer focussed. R‰   R   N(   RŽ   R}   R   R8   RŠ   R‹   R   (   R(   RŽ   R   R…   t   direction_changedRŒ   (   R†   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   incremental_search›  s    	c           s    ˆ  |  j  t j d |  j ƒd  S(   NR   (   R(   R   R   R   (   R   (   R‘   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ª  s    c           s    ˆ  |  j  t j d |  j ƒd  S(   NR   (   R(   R   R   R   (   R   (   R‘   (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyR   ¯  s    (   R   R   R	   R\   R   R   R&   t   callablet   AssertionErrorR   Rr   Rv   Rn   R"   R.   t   ControlRt   ControlSt   Upt   Down(   R†   Rw   R#   Rƒ   R   (    (   R†   R‘   sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   load_emacs_search_bindingsa  s$    	!-%%''c          C  sq   t  t ƒ  t ƒ  ƒ }  |  j } | t j ƒ t ƒ | t j ƒ t ƒ | t j d ƒ t	 ƒ | t j
 ƒ t	 ƒ |  S(   uˆ   
    Key bindings, for scrolling up and down through pages.
    This are separate bindings, because GNU readline doesn't have them.
    u   v(   R   R   R	   R\   R   t   ControlVR   t   PageDownR"   R   t   PageUp(   Rw   R#   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt)   load_extra_emacs_page_navigation_bindings·  s    	N($   t
   __future__R    t   prompt_toolkit.bufferR   R   R   t   prompt_toolkit.keysR   t   prompt_toolkit.enumsR   R   R   t   prompt_toolkit.filtersR   R	   R
   R   R   R   t   prompt_toolkit.completionR   t   scrollR   R   t   named_commandsR   Rw   R   R   t   __all__Rz   R{   R„   R&   R˜   Rœ   (    (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/emacs.pyt   <module>   s$   .		ÿ 		&V