
    Zg'                        S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
JrJr  SSKJr  SSKJr  \(       a  SSKJr  Sr\SSS	 jj5       r\SS
 j5       r\SSS jj5       rSSS jjr " S S\5      r " S S5      rg)z#API for working with a Nvim Buffer.    )annotations)	AnyIteratorListOptionalTYPE_CHECKINGTupleUnioncastoverload)Remote)check_async)Nvim)BufferNc                    g N idxdefaults     3/usr/lib/python3/dist-packages/pynvim/api/buffer.pyadjust_indexr              c                    g r   r   r   s     r   r   r      r   r   c                    g r   r   r   s     r   r   r      r   r   c                &    U c  U$ U S:  a  U S-
  $ U $ )zDConvert from python indexing convention to nvim indexing convention.r      r   r   s     r   r   r   !   s!    
{	qQw
r   c                    ^  \ rS rSr% SrSrS\S'   SU 4S jjrSS jr\	SS j5       r
\	S S	 j5       r
S!S
 jr
\	S"S j5       r\	      S#S j5       r      S$S jrS%S jrS&S jrS'S jr S(     S)S jjrS*S jrS+S jr    S,               S-S jjr   S.           S/S jjr    S0             S1S jjr\S2S j5       r\R.                  S3S j5       r\S4S j5       r\S4S j5       r\SS j5       rSrU =r$ )5r   +   zA remote Nvim buffer.	nvim_buf_z'Nvim'_sessionc                $   > [         TU ]  X5        g)z4Initialize from Nvim and code_data immutable object.N)super__init__)selfsession	code_data	__class__s      r   r%   Buffer.__init__2   s    ,r   c                $    U R                  S5      $ )z1Return the number of lines contained in a Buffer.nvim_buf_line_countrequestr&   s    r   __len__Buffer.__len__6   s    ||122r   c                    g r   r   r&   r   s     r   __getitem__Buffer.__getitem__:       r   c                    g r   r   r3   s     r   r4   r5   >   r6   r   c                    [        U[        5      (       d$  [        U5      nU R                  SX"S-   S5      S   $ [        UR                  S5      n[        UR
                  S5      nU R                  SX4S5      $ )a  Get a buffer line or slice by integer index.

Indexes may be negative to specify positions from the end of the
buffer. For example, -1 is the last line, -2 is the line before that
and so on.

When retrieving slices, omitting indexes(eg: `buffer[:]`) will bring
the whole buffer.
nvim_buf_get_linesr   Tr   F)
isinstanceslicer   r.   startstop)r&   r   ir=   ends        r   r4   r5   B   sl     #u%%S!A<< 4aQEaHHSYY*388R(||0%eDDr   c                    g r   r   r&   r   items      r   __setitem__Buffer.__setitem__S   r6   r   c                    g r   r   rB   s      r   rD   rE   W   s     	r   c                p   [        U[        5      (       dA  [        U[        5      (       a   e[        U5      nUb  U/O/ nU R	                  SX3S-   SU5      $ Uc  / nO[        U[
        5      (       a  U/nOUn[        UR                  S5      n[        UR                  S5      nU R	                  SXVSU5      $ )zReplace a buffer line or slice by integer index.

Like with `__getitem__`, indexes may be negative.

When replacing slices, omitting indexes(eg: `buffer[:]`) will replace
the whole buffer.
nvim_buf_set_linesr   Tr   r:   F)r;   r<   listr   r.   strr=   r>   )r&   r   rC   r?   linesr=   r@   s          r   rD   rE   ]   s     #u%%!$----S!A".TFBE<< 4aQeLL<Ec""FEESYY*388R(||0%eUKKr   c              #  0   #    U SS nU H  nUv   M	     g7f)zIterate lines of a buffer.

This will retrieve all lines locally before iteration starts. This
approach is used because for most cases, the gain is much greater by
minimizing the number of API calls by transferring all data needed to
work.
Nr   )r&   rK   lines      r   __iter__Buffer.__iter__v   s      QDJ s   c                (    U R                  US5        g)zYDelete line or slice of lines from the buffer.

This is the same as __setitem__(idx, [])
N)rD   r3   s     r   __delitem__Buffer.__delitem__   s    
 	d#r   c                .    U R                  U5      (       + $ )zCTest inequality of Buffers.

Necessary for Python 2 compatibility.
)__eq__)r&   others     r   __ne__Buffer.__ne__   s    
 ;;u%%%r   c                f    [        U[        [        45      (       a  U/nU R                  SX"SU5      $ )z/Append a string or list of lines to the buffer.rH   T)r;   rJ   bytesr.   )r&   rK   indexs      r   appendBuffer.append   s2     ec5\**GE||0%eLLr   c           	     n    [        [        [        [        4   [        U R	                  SU5      5      5      $ )z)Return (row, col) tuple for a named mark.nvim_buf_get_mark)r   r	   inttupler.   )r&   names     r   markBuffer.mark   s(    E#s(OU4<<8KT+R%STTr   c                    [        XU5      $ )z=Return a `Range` object, which represents part of the Buffer.)Range)r&   r=   r@   s      r   rangeBuffer.range   s    T#&&r   c           
     J    [        XgUS:g  5      nU R                  SUUUUUUS9$ )zAdd a highlight to the buffer.r   nvim_buf_add_highlightasync_r   r.   )r&   hl_grouprM   	col_startcol_endsrc_idrk   kwargss           r   add_highlightBuffer.add_highlight   s?     VVq[9||$  
 	
r   c                >    [        XES5      nU R                  SXX4S9  g)z!Clear highlights from the buffer.Tnvim_buf_clear_highlightrj   Nrl   )r&   rp   
line_startline_endrk   rq   s         r   clear_highlightBuffer.clear_highlight   s(     VT2&H 	 	
r   c           	     r    U(       a  Uc  SnU R                   R                  5       nUR                  XX#XFS9  g)ax  Add or update highlights in batch to avoid unnecessary redraws.

A `src_id` must have been allocated prior to use of this function. Use
for instance `nvim.new_highlight_source()` to get a src_id for your
plugin.

`hls` should be a list of highlight items. Each item should be a list
or tuple on the form `("GroupName", linenr, col_start, col_end)` or
`("GroupName", linenr)` to highlight an entire line.

By default existing highlights are preserved. Specify a line range with
clear_start and clear_end to replace highlights in this range. As a
shorthand, use clear=True to clear the entire buffer before adding the
new highlights.
Nr   rj   )r"   _get_lua_privateupdate_highlights)r&   rp   hlsclear_start	clear_endclearrk   luas           r   r|   Buffer.update_highlights   s8    0 [(Kmm,,.dCiWr   c                $    U R                  S5      $ )zGet the buffer name.nvim_buf_get_namer-   r/   s    r   ra   Buffer.name        ||/00r   c                &    U R                  SU5      $ )z:Set the buffer name. BufFilePre/BufFilePost are triggered.nvim_buf_set_namer-   )r&   values     r   ra   r      s     ||/77r   c                $    U R                  S5      $ )z'Return True if the buffer still exists.nvim_buf_is_validr-   r/   s    r   validBuffer.valid   r   r   c                $    U R                  S5      $ )z.Return True if the buffer is valid and loaded.nvim_buf_is_loadedr-   r/   s    r   loadedBuffer.loaded   s     ||011r   c                    U R                   $ )zGet the buffer number.)handler/   s    r   numberBuffer.number   s     {{r   r   )r'   r   r(   zTuple[int, Any]returnr_   r   r_   r   rJ   r   r<   r   z	List[str]r   Union[int, slice]r   zUnion[str, List[str]])r   r_   rC   Optional[str]r   None)r   r<   rC   zOptional[Union[List[str], str]]r   r   )r   r   rC   Union[None, str, List[str]]r   r   r   zIterator[str])r   r   r   r   )rU   r   r   bool)r:   )rK   *Union[str, bytes, List[Union[str, bytes]]]rZ   r_   r   r   )ra   rJ   r   zTuple[int, int])r=   r_   r@   r_   r   re   )r   r:   r:   N)rm   rJ   rM   r_   rn   r_   ro   r_   rp   r_   rk   Optional[bool]rq   r   r   r_   )r   r:   N)rp   r_   rv   r_   rw   r_   rk   r   rq   r   r   r   )Nr:   FT)rp   r_   r}   z7List[Union[Tuple[str, int], Tuple[str, int, int, int]]]r~   Optional[int]r   r_   r   r   rk   r   r   r   )r   rJ   )r   rJ   r   r   )r   r   )__name__
__module____qualname____firstlineno____doc___api_prefix__annotations__r%   r0   r   r4   rD   rN   rQ   rV   r[   rb   rf   rr   rx   r|   propertyra   setterr   r   r   __static_attributes____classcell__)r)   s   @r   r   r   +   s_   K-3    E"    ?	 
L$L,GL	L2
$& OQM?MHKM	MU' !%

 
 	

 
 
 
 
 

2 !%

 
 	

 
 
 

$ &*XX EX #	X
 X X X 
X: 1 1 
[[8 8 1 1 2 2  r   r   c                      \ rS rSrSS jrSS jr\SS j5       r\SS j5       rSS jr\SS j5       r\SS j5       r      SS	 jrSS
 jr	 S     SS jjr
\SS j5       r\SS j5       rSS jrSrg)re      c                8    Xl         US-
  U l        US-
  U l        g Nr   )_bufferr=   r@   )r&   bufferr=   r@   s       r   r%   Range.__init__   s    QY
7r   c                :    U R                   U R                  -
  S-   $ r   r@   r=   r/   s    r   r0   Range.__len__  s    xx$**$q((r   c                    g r   r   r3   s     r   r4   Range.__getitem__  r6   r   c                    g r   r   r3   s     r   r4   r   	  r6   r   c                2   [        U[        5      (       d  U R                  U R                  U5         $ U R                  UR                  5      nU R                  UR
                  5      nUc  U R                  nUc  U R                  S-   nU R                  X# $ r   )r;   r<   r   _normalize_indexr=   r>   r@   )r&   r   r=   r@   s       r   r4   r     s    #u%%<< 5 5c :;;%%cii0##CHH-=JJE;((Q,C||E&&r   c                    g r   r   r&   r   rK   s      r   rD   Range.__setitem__  r6   r   c                    g r   r   r   s      r   rD   r     r6   r   c                `   [        U[        5      (       d5  [        U[        5      (       a   eX R                  U R	                  U5      '   g U R	                  UR
                  5      nU R	                  UR                  5      nUc  U R
                  nUc  U R                  nX R                  X4S-   & g r   )r;   r<   rI   r   r   r=   r>   r@   )r&   r   rK   r=   r@   s        r   rD   r      s     #u%%!%....7<LL..s34%%cii0##CHH-=JJE;((C&+U7#r   c              #     #    [        U R                  U R                  S-   5       H  nU R                  U   v   M     g 7fr   )rf   r=   r@   r   )r&   r?   s     r   rN   Range.__iter__/  s0     tzz488a<0A,,q/! 1s   =?Nc                    U R                  U5      nUc  U R                  S-   nU R                  R                  X5        g r   )r   r@   r   r[   )r&   rK   r?   s      r   r[   Range.append3  s8     !!!$91AE%r   c                    g r   r   r&   rZ   s     r   r   Range._normalize_index;  r6   r   c                    g r   r   r   s     r   r   r   ?  r6   r   c                    Uc  g US:  a  U R                   nU$ XR                  -  nXR                   :  a  U R                   nU$ )Nr   r   r   s     r   r   r   C  sG    =19HHE
  ZZExxr   )r   r@   r=   )r   r   r=   r_   r@   r_   r   r   r   r   )r   r_   rK   r   r   r   )r   r<   rK   zOptional[List[str]]r   r   )r   r   rK   r   r   r   r   r   )rK   r   r?   r   r   r   )rZ   r_   r   r_   )rZ   r   r   r   )rZ   r   r   r   )r   r   r   r   r%   r0   r   r4   rD   rN   r[   r   r   r   r   r   re   re      s    
)    	'    ,$,-H,	,"
 UY&?&DQ&	&    	r   re   r   )r   r_   r   r   r   r_   )r   r   r   r_   r   r_   )r   r   r   r   r   r   )r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   pynvim.api.commonr   pynvim.compatr   
pynvim.apir   __all__r   r   re   r   r   r   <module>r      s    ) "   % %  
 
 
 
 
 
MV M`Q Qr   