
    Je,                    2   d Z ddlmZ ddlZddlZddlZddlmZ ddl	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lmZ ddlmZ dd	lmZmZmZmZmZmZmZmZm Z  dd
l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@ ddlAmBZB ddlCmDZD ddlEmFZFmGZGmHZHmIZImJZJmKZK ddlLmMZMmNZNmOZO ddlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZX ddlYmZZZm[Z[m\Z\ ddl]m^Z^ ddl_m`Z` ddlambZbmcZc ddldmeZemfZf ddlgmhZhmiZimjZj ddlkmlZl ddlmmnZn ddlompZqmrZr ddlsmtZtmuZumvZv ddlwmxZxmyZy dd lzm{Z{ dd!l|m}Z} dd"lwm~Z dd#lmZmZ dd$lmZmZmZmZmZ dd%lmZmZ dd&lmZ 	 ddlZdd'lmZ  ej&                  e      Z e
j,                  d(e
j.                        Zd1d)Zej G d* d+en             Z G d, d-e5      Zd. Zed/k(  r2 eej<                        d0kD  rej<                  d0   ZneZ ee       yy# e$ r dZY w xY w)2z-
Editor widget based on QtGui.QPlainTextEdit
    )categoryN)diff_match_patch)TransformerManager)parse)
QT_VERSION)to_qvariant)	QEvent
QEventLoopQRegExpQtQTimerQThreadQUrlSignalSlot)QColorQCursorQFontQKeySequenceQPaintEventQPainterQMouseEventQTextCursorQDesktopServices	QKeyEventQTextDocumentQTextFormatQTextOptionQTextCharFormatQTextLayout)QApplicationQMenuQMessageBox	QSplitter
QScrollBar)getobj)merge)Panel)_get_debug_levelrunning_under_pytest)CONF)TextDecoration)CloseBracketsExtensionCloseQuotesExtensionDocstringWriterExtensionQMenuOnlyForEnterEditorExtensionsManagerSnippetsExtension)CompletionRequestTypesTextDocumentSyncKindDiagnosticSeverity)ClassFunctionDropdownDebuggerPanelEdgeLineFoldingPanelIndentationGuideLineNumberAreaPanelsManagerScrollFlagArea)
TextHelperBlockUserDataget_file_language)DebuggerManager)
QtKillRing)ALL_LANGUAGESCELL_LANGUAGES)merge_foldingcollect_folding_regions)requesthandlesclass_register)GoToLineDialog)TextEditBaseWidget)OutlineExplorerDatais_cell_header)to_text_string	is_stringis_text_string)encoding
sourcecode)CLIPBOARD_HELPER)ima)syntaxhighlighters)SpyderPaletteQStylePalette)add_actionscreate_actionfile_urimimedata2url
start_file)get_git_remotesremote_to_url)qstring_length)PythonExporterz#?noqac                       t        j                  t              S t        j                          fd       }|S )zECall function req and then emit its results to the completion server.methodrequires_responsec                      | g|i |}|k| j                   r^| j                  j                  |f       | j                  j	                  | j
                         | j                  j                          y y y N)completions_available_pending_server_requestsappend_server_requests_timersetIntervalLSP_REQUESTS_SHORT_DELAYstart)selfargskwargsparamsrd   reqre   s       J/usr/lib/python3/dist-packages/spyder/plugins/editor/widgets/codeeditor.pywrapperz!schedule_request.<locals>.wrapperp   s{    T+D+F+$"<"<))00!235''33--/''--/ #=    )	functoolspartialschedule_requestwraps)rs   rd   re   ru   s   ``` rt   ry   ry   j   sI    
{  !1&3DF 	F __S0 0 Nrv   c                       e Zd ZdZi dej
                  dfdej                  dfdej                  dfdej                  dfdej                  d	fd
ej                  dfdej                  dfdej                  dfdej                  dfdej                  dfdej                  dfdej                   dfdej"                  dfdej$                  dfdej&                  dfdej(                  dfZdZdZdddddZdZd Z ee      Zd!Zd!Z e       Z  e       Z! ee"fd"      Z# e       Z$ e       Z% ee&      Z' e       Z( ee&e"e"      Z) ee*      Z+ e       Z, e       Z- e       Z. e       Z/ e       Z0 e       Z1 e       Z2 ee"e"      Z3 ee&      Z4 ee*      Z5 e       Z6 ee7      Z8 ee7      Z9 ee:      Z; ee:      Z< e       Z= e       Z> ee?      Z@ e       ZA ee&e&e?      ZB ee&eC      ZD ee&e*      ZE ee?      ZF e       ZG ee&      ZH ee&      ZI	  ee&e&e*      ZJ e       ZK ee&      ZL eeMeM      ZN ee&      ZO e       ZP e       ZQ e       ZR e       ZS e       ZT e       ZUd d#ZVd$ ZWd% ZXd& ZYd' ZZd( Z[d) Z\d* Z]d+ Z^d, Z_d- Z`d. Zad/ Zbd!d1Zcedd2        Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"d3Zf ege&e?      d4        Zhd5 Zid6 Zjd7 Zkd8 Zld9 Zm eneoj                  d0:      d;        Zq ereoj                  <      d=        Zt eueoj                        d>        Zvd? Zwd@ Zx eneoj                  d0:      dA        Zz eueoj                        dB        Z|dC Z}dD Z~dE ZdF ZdG ZdH ZdI ZdJ ZdK Z ereoj                  <      d#dL       Z eueoj                        dM        Z ereoj                  <      dN        Z eueoj                        dO        Z ereoj                  <      dP        Z eueoj                        dQ        Z ereoj                  <      dR        Z ereoj"                  <      d$dS       Z eueoj"                        dT        Z eg        ereoj(                  <      d dU              Z eueoj(                        dV        ZdW Z ereoj0                  <      dX        Z ereoj4                  <      dY        Z eueoj0                        dZ        Z eueoj4                        d[        Zd\ Zd] Zd^ Zd_ Z ereojD                  <      d`        Z eueojD                        da        Zdb Zdc Z ereojN                  d0:      dd        Z eneojR                  d0:      de        Zdf Zd#dgZdh Zdi Zdj Zdk Zdl Zdm Zdn Zdo Zdp Zdq Zdr Zds Zdt Zdu Zdv Zdw Zdx Zdy Zdz Zd{ Zd| Zd} Zd d~Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd!e֐j                  fdZ eg       d        Zd Zd Zd Zd Zd!d!d!d!eސj                  fdZd!d!d!d!eސj                  fdZd Z	 	 d%dZd Zd Zd Zd Zd Zd Zd Zd&dZd Zd Zd Zd Zd Z eg       d        Zd Zd Zd Z fdZd Zd dZd dZd Zd Zd dZd Zd Z eg       d        Zd Z eg       d        Z  eg       d        Z eg       d        Z eg       d        Z eg       d        Zd'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dɄ Zdʄ Zd˄ Zd̄ Zd̈́ Zd΄ Zdτ ZdЄ Zd(dфZd(d҄Zg fdӄZdԄ Zd)dՄZ	 	 d*dքZ	 	 d*dׄZ  eg       d؄        Z! eg       dل        Z"d#dڄZ#dۄ Z$d#d܄Z% eg       d݄        Z&dބ Z'd߄ Z(d Z)d#dZ*d Z+d Z,d Z-d Z.d#dZ/d Z0d Z1d Z2d Z3d Z4d Z5d dZ6d&dZ7d Z8d Z9d Z:d Z;d Z<d Z=d&dZ>d&dZ?d Z@ fdZA fdZBd ZCd ZDd ZEd ZFd ZGd ZHd  ZId ZJd ZKd ZLd ZMd ZNd ZOd ZPd ZQd)d	ZRd
 ZS fdZT fdZU fdZVd ZWd ZXd ZYd ZZd Z[d Z\d Z]d Z^d Z_d Z`edd        Zad Zbd Zcd Zdd dZed Zfd Zgd Zh xZiS (+  
CodeEditorz1Source Code Editor Widget based exclusively on QtPython#IPythonCython	Fortran77cFortran!Idl;Diff GetTextNsisHtmlYamlCpp//OpenCLEnamlMarkdownNone)
pypywpythonipyr   cppclhpytpyi  X         )r   r   i	  id  2   ,  N c                     t        j                   |        j                  t        j                         d  _         j                  t        j                  dd             t                _
        t                _         j                  j                  j                   j                           j                  j"                  j                   j$                         d  _        d  _        d  _        t-                _         j.                  j1                  d        j.                  j3                  d        j.                  j4                  j                   j6                         d _        d  _        d _        t-                _         j>                  j3                  d        j>                  j4                  j                   j@                          jB                  jD                  j                   jF                         t-                _$         jH                  j3                  d        jJ                  j                   jL                         d  _'        d  _(         jR                  jU                  tW               tX        jZ                  j\                         _/         jR                  jU                  ta               tX        jZ                  j\                         _1        d _2        d _3        d _4        tk        d       _6         jR                  jU                  to                      tq                _9         jR                  jU                  tu                       jJ                  j                   jv                          jR                  jU                  ty                      _=         jR                  jU                  t}               tX        jZ                  j~                         _@        d  _A        d  _B        d  _C        d  _D        d  _E        d  _F        d  _G        t        j                   _J        d  _K        d}|t        j                  vrt        j                  d	   }| _M        d _N         j                  t                      t        j                   _S        t        j                   _U        t        j                   _W        t        j                   _Y        tk        t        j                        j                  d
       _A        tk        t        j                         _]         jR                  jU                  t               tX        jZ                  j                         _`         jR                  j                          t                _c         j                  j                   j                         d  _f        i  _g        d  _h        d _i        d _j        d  _k        t                _m         jJ                  j                   j                         t-                _o         j                  j3                  d        j                  j4                  j                   j                         d  _q        t-                _r         j                  j3                  d        j                  j1                  d        j                  j4                  j                   j                         g  _t        t-                _u         j                  j3                  d        j                  j1                   j                          j                  j4                  j                   j                          j                         j                  j                   fd        j                  j                   j                         g  _|        t-                _}         j                  j3                  d        j                  j1                   j                          j                  j4                  j                   j                          j                  j                   j                          g  _        t                _        d  _         j                          d  _        d _        d _        d _        d _        d _        t        d        _         j                  j                  j                   j                         d _        d _        d _        d _        d _        d _        d _        t/        d        _        t-                _        d	 _         j7                  d       d _        d _        tk        t        j<                         _B        i  _        g  _         jC                          _        g  _         jH                  j                   jJ                         d  _        d  _        d  _        d  _        d _        d _        d  _        d  _        d _        d	 _        d _        d _        td        jf                   _        d _        d _        d _        g  _        d _        g  _        d _        d _        d _        d _        d _        d _        g  _        d  _        d _        d  _        d _        d _        d _        d _        d _        t        d        _         j                   j                  _         j                  j                  j                   j                         g  _        t                _         j                  j                  t                       j                  j                  t                       j                  j                  t                      t                _        d _        g  _        i  _        d _        d _        t-                _         j                  j3                  d        j                  j1                  d       y )Nmainzcursor/widthi^  Tr   FwhiteSpyderr      r   c                 8    j                   j                         S rg   )update_decorations_timerrn   )valuero   s    rt   <lambda>z%CodeEditor.__init__.<locals>.<lambda>  s    $77==? rv      r      )rL   __init__setFocusPolicyr   StrongFocuscurrent_project_pathsetCursorWidthr,   getr?   text_helperr=   _panelstooltip_widgetsig_help_requestedconnectshow_object_infosig_completion_help_requestedshow_completion_object_info_last_point_last_hover_word_last_hover_cursorr   _timer_mouse_movingrl   setSingleShottimeout_handle_hover_last_key_pressed_text_last_pressed_key_completions_hint_idle_timer_completions_hint_set_completions_hint_idlecompletion_widgetsig_completion_hintshow_hint_for_completion_timer_sync_symbols_and_foldingblockCountChanged$set_sync_symbols_and_folding_timeout_last_hover_pattern_key_last_hover_pattern_textpanelsregisterr9   r(   PositionFLOATING	edge_liner;   indent_guidesblanks_enabledunderline_errors_enabledscrollpastend_enabledr   
backgroundr:   rB   debuggerr8   sig_breakpoints_changedr<   linenumberarear7   TOPclassfuncdropdownoccurrence_colorctrl_click_colorsideareas_colormatched_p_colorunmatched_p_colornormal_colorcomment_colorshTextSHhighlighter_classhighlighterCOLOR_SCHEME_NAMEScolor_schemehighlight_current_line_enabledsetVerticalScrollBarr%   rW   COLOR_WARN_2warning_colorCOLOR_ERROR_1error_colorGROUP_9
todo_colorICON_3breakpoint_colorGROUP_2lighterCOLOR_OCCURRENCE_4found_results_colorr>   RIGHTscrollflagarearefreshiddocument_idcursorPositionChanged$_CodeEditor__cursor_position_changed_CodeEditor__find_first_pos_CodeEditor__find_argslanguagesupported_languagesupported_cell_languagecomment_stringrC   
_kill_ringupdate_bookmarkstimer_syntax_highlightrun_pygments_highlighteroccurrence_highlightingoccurrence_timermark_occurrencesoccurrencesr   UPDATE_DECORATIONS_TIMEOUTupdate_decorationsverticalScrollBarvalueChangedtextChanged_schedule_document_did_changeri   rk   rm   _process_server_requests_CodeEditor__text_has_changedfound_resultsr0   writer_docstringgotodef_actionsetup_context_menutab_indentstab_modeintelligent_backspaceautomatic_completions!automatic_completions_after_charscode_foldingr   update_folding_threadfinishedfinish_code_foldingcompletions_hintcompletions_hint_after_msclose_parentheses_enabledclose_quotes_enabledadd_colons_enabledauto_unindent_enabledformat_on_saver
   format_eventloopformat_timer*_CodeEditor__cursor_position_before_formatsetMouseTracking_CodeEditor__cursor_changed_mouse_left_button_pressedblue_bookmarks_blocks	bookmarkscreate_shortcuts	shortcuts_CodeEditor__visible_blockspainted_draw_editor_cell_divideroe_proxylast_change_positionlast_positionlast_auto_indentskip_rstripstrip_trailing_spaces_on_modifyhover_hints_enabledfilenamerh   text_versionsave_include_textopen_close_notificationsr5   FULL	sync_modewill_save_notifywill_save_until_notifyenable_hoverauto_completion_charactersresolve_completions_enabledsignature_completion_charactersgo_to_definition_enabledfind_references_enabledhighlight_enabledformatting_enabledrange_formatting_enableddocument_symbols_enabledformatting_characterscompletion_argsfolding_supported_folding_info	is_clonedoperation_in_progressformatting_in_progresssymbols_in_syncfolding_in_syncupdate_diagnostics_thread
set_errorsrunfinish_code_analysis_diagnosticsr2   editor_extensionsaddr/   r3   r.   r   differprevious_textpatchleading_whitespaces
is_undoing
is_redoing_rehighlight_timer)ro   parentccss   `  rt   r   zCodeEditor.__init__)  s
   ##D&1BNN+ %)! 	DHHV^<=%d+$T* 	..66!!	#99AA,,	. $"&#)$<   ,,S1  ..t4  ((001C1CD ')#!% ',#'-d|$$$2248$$,,44++	-22::))	+ 06d|,,,::4@&&55	7 (,$(,% --hj.3nn.E.EG "[[112B2D27..2I2IK $ ).% &+" / 	\^, (-]_-&&t'C'CD #kk22>3CD "&!5!5!#NN"
 !% $##!% ! "$b+++''*C.3+ 	!!*,/ +77(66'// - 4 4 &}'<'< = E Ec J#)-*J*J#K  #kk22>3C38>>3G3GId8 	""**4+I+IJ $"'',$"$T* 	&&t'<'<= '-Tl###11$7##++33))	+ (,$ &t++D1))$/%%--d.C.CD )/t%%%33D9%%11++	-%%--55##	% --55?	A 	  !C!CD(*%&,Tl###11$7##//0M0MN##++33))	+ 	  !8!89 !9 > #!   &*" &*"12. !%,T]"""++33D4L4LM !%),&)-&$)!"&%)" $ *4 0"4L/0, 	d# %*/' &rww!# ..0 !#T;;<  %)!! $ /3, $(  %*"!%(,%-22 %&+# *,'+0(/1,(-%',$!&"'(-%(-%%'"#!&!%*"&+#$$ *1&-1__&&*&&//77%%	' "9!>""#7#9:""#4#67""#9#;< '(
#%    #),--d3++C0rv   c                     | j                   r'| j                          | j                          d| _         | j                  D ]  \  }}}| j	                  |||        g | _        y)zProcess server requests.FN)_document_server_needs_updatedocument_did_changedo_automatic_completionsri   emit_requestro   rd   rr   re   s       rt   r  z#CodeEditor._process_server_requestsl  sk     --$$&))+16D. 261N1N 	A-FF-ff.?@	A )+%rv   c                 b    | j                   s#| j                  xr |xr | j                  |      S y)z*Check if a hover hint should be displayed:N)r1  r@  get_word_atro   points     rt   _should_display_hoverz CodeEditor._should_display_hover}  s8    ..,, 0 0((/1 /rv   c                 d   | j                   j                          | j                  }g d}| j                  |      rR| j	                  |      \  }}}| j                  |      |rt        j                  dk(  rdnd}|dv r|dz   t        d      z   }n=|dv r|dz   t        d	      z   }n'|d
v r|dz   t        d      z   }n|dz   t        d      z   }dj                  |      }| j                  ||       y| j                  |      }|j                         }|j                         |j                         }
}	|| _        rP| j                  k7  r@t!        fd|D              r| _        | j#                  |	|
|       y| j%                          yyy| j'                         s| j%                          yy)z&Handle hover hint trigger after delay.)().darwinCmdCtrlfilez + zclick to open file)mailzclick to send email)urlzclick to open urlzclick to openz<span>&nbsp;{}&nbsp;</span>)textat_pointNc              3   &   K   | ]  }|v 
 y wrg   r   ).0charr  s     rt   	<genexpr>z+CodeEditor._handle_hover.<locals>.<genexpr>  s     ADt4'As   )r   stopr   rv  get_pattern_atrs  sysplatformr)   formatshow_tooltipcursorForPositionpositionblockNumbercolumnNumberr   allrequest_hoverhide_tooltipis_completion_widget_visible)ro   posignore_charskeypattern_textcursor	ctrl_text	hint_textcursor_offsetlinecolr  s              @rt   r   zCodeEditor._handle_hover  s     %%' '%%c*(,(;(;C(@%Cv##C(D%(\\X%=E6	(? )E 1A6J4K KIH_ )E 1A6K4L LIG^ )E 1A6I4J JI )E 1Ao4F FI9@@K	!!y3!?++C0F"OO-M**,f.A.A.C#D"D--5ALAA,0D)&&tS-@%%' 6t 224 5rv   c              #      K   | j                         j                         }|j                         r8|j                         }|r| |j	                         }|j                         r7yywz*Get the list of all user data in document.N)document
firstBlockisValiduserDatanext)ro   blockdatas      rt   blockuserdata_listzCodeEditor.blockuserdata_list  sM     **,mmo>>#D
JJLE	 mmos   A%A*(A*c              #   l   K   | j                         D ]  }|j                  s|j                    ywr  )r  oedataro   r  s     rt   outlineexplorer_data_listz$CodeEditor.outlineexplorer_data_list  s/     ++- 	"D{{kk!	"s    44c                       fd}|S )z:Make a callback for cursor move event type, (e.g. "Start")c                      j                         } t        t              }| j                  |       j	                  |        y rg   )
textCursorgetattrr   movePositionsetTextCursor)r  	move_typeattrro   s     rt   cursor_move_eventz<CodeEditor.create_cursor_callback.<locals>.cursor_move_event  s7    __&FT2I	*v&rv   r   )ro   r  r  s   `` rt   create_cursor_callbackz!CodeEditor.create_cursor_callback  s    	'
 ! rv   c           	          g dd j                   fdd j                  fdd j                  fdd j                  fdd j                  fdd j
                  fdd j                  fdd	 j                  fdd
 j                  fdd j                  fdd j                  fdd j                  fdd j                  fdd fdfdd fdfdd j                  d      fdd j                  d      fdd j                  d      fdd j                  d      fdd j                  d      fdd j                  d      fdd j                  d       fdd! j                  d"      fdd# j                  fdd$ j                  fdd% j                   j"                  fdd& j                   j$                  fdd' j&                  fdd( j(                  fdd) j                  d*      fdd+ j                  d,      fdd- j*                  fdd. j,                  fdd/ j.                  fdd0 j0                  fdd1 j2                  fdd2 j4                  fdd3 j6                  fdd4 j8                  j:                  fdd5 j<                  fd6d7 j>                  fd6d8 j@                  f}g }|D ].  \  }}}|jC                  tE        jF                  ||| 9             0 |S ):z.Create the local shortcuts for the CodeEditor.editorzcode completionzduplicate line downzduplicate line upzdelete linezmove line upzmove line downzgo to new linego to definitiontoggle commentblockcommentunblockcommentztransform to uppercaseztransform to lowercaseindentc                  (     j                  d      S NTforce)r  ro   s   rt   r   z-CodeEditor.create_shortcuts.<locals>.<lambda>  s    4)@ rv   unindentc                  (     j                  d      S r  )r  r  s   rt   r   z-CodeEditor.create_shortcuts.<locals>.<lambda>  s    4==t=+D rv   zstart of lineStartOfLinezend of line	EndOfLinezprevious lineUpz	next lineDownzprevious charLeftz	next charRightzprevious wordPreviousWordz	next wordNextWordzkill to line endzkill to line startyankzrotate kill ringzkill previous wordzkill next wordzstart of documentStartzend of documentEndundoredocutcopypastedelete
select all	docstringautoformattingarray_builderzenter array inlinezenter array table)contextnamerj  )$do_completionduplicate_line_downduplicate_line_updelete_linemove_line_upmove_line_downgo_to_new_linego_to_definition_from_cursortoggle_commentr  r  transform_to_uppercasetransform_to_lowercaser  kill_line_endkill_line_startr  r  rotatekill_prev_wordkill_next_wordr  r  r  r  r  r  	selectAllr  write_docstring_for_shortcutformat_document_or_rangeenter_array_inlineenter_array_tablerj   r,   config_shortcut)ro   shortcut_context_name_callbacksr6  r  r  callbacks   `     rt   r5  zCodeEditor.create_shortcuts  s   1+($*<*<=1+,d.F.FG1+ *D,B,BC1+ }d&6&67	1+
 ~t'8'891+ ')<)<=1+ ')<)<=1+ )4+L+LM1+ ')<)<=1+ ~t'8'891+ ')<)<=1+ /1L1LM1+ /1L1LM1+ x!@A1+ z#DE1+  ((79!1+$ }((57%1+( (C(CD(IJ)1+* {D$?$?$GH+1+, (C(CF(KL-1+. {D$?$?$HI/1+0 ((8:11+4 {D$?$?
$KL51+6 )4+=+=>71+8 +T-A-AB91+: vt334;1+< )4??+A+AB=1+> +T-@-@A?1+@ ')<)<=A1+B *((13C1+F (((/1G1+J vtyy)K1+L vtyy)M1+N udhh'O1+P vtyy)Q1+R w

+S1+T x-U1+V |T^^4W1+X {""??AY1+\ ')F)FG]1+^ 2D4K4KL_1+` 143I3IJa1+'f 	'F 	H#GT8$$gDGH	H rv   c                 T    | j                   D cg c]  }|j                   c}S c c}w )z
        Returns shortcut data, a list of tuples (shortcut, text, default)
        shortcut (QShortcut or QAction instance)
        text (string): action/shortcut description
        default (string): default key sequence
        )r6  r  )ro   scs     rt   get_shortcut_datazCodeEditor.get_shortcut_data  s      #'..1B111s   %c                 |   t        | j                  t        j                        r| j                  j	                          | j
                  j                          | j
                  j                          | j                  j                          | j                  j                          t        j                  | |       y rg   )
isinstancer   r   
PygmentsSHr  r"  quitwaitr\  rL   
closeEventro   events     rt   r  zCodeEditor.closeEvent  s    d&&6!!#""'')""'')&&++-&&++-%%dE2rv   c                     | j                   S rg   )r   r  s    rt   get_document_idzCodeEditor.get_document_id  s    rv   c                    | j                  |j                                |j                         | _        |j                  | _        | j
                  j                  j                  | j                  j                         |j                  | _	        | j                          | j                  j                  j                  | j                         y)zSet as clone editorN)setDocumentr  r  r   r   ri  r   r   rehighlight	eol_chars_apply_highlighter_color_schemesig_font_changed	sync_font)ro   r  s     rt   set_as_clonezCodeEditor.set_as_clone  s    *+!113!--''//((	*)),,.))11$..Arv   c                 8    | j                  |rd       yd       y)zEnable/disable wrap modewordN)set_wrap_modero   enables     rt   toggle_wrap_modezCodeEditor.toggle_wrap_mode$  s    V666rv   Fc                 <    | j                   j                  ||       y)zEnable/disable line numbers.N)r   setup_margins)ro   linenumbersmarkerss      rt   toggle_line_numberszCodeEditor.toggle_line_numbers(  s    ))+w?rv   c                     | j                   S )z
        Returns a reference to the
        :class:`spyder.widgets.panels.managers.PanelsManager`
        used to manage the collection of installed panels
        )r   r  s    rt   r   zCodeEditor.panels,  s     ||rv   c*                 :   | j                  |       | j                  |       | j                  |       | j                  |       | j	                  |       | j                  |$|       | j                  |%       | j                  j                  |       | j                  j                  |       | j                  j                  |       | j                  j                  |       | j                  |"       | j                  dk(  r| j                  j!                  |       n.| j                  j!                  t#        | j                               | j%                  |       | j'                  |&       | j)                  |'       | j+                  |(       | j-                  |#       | j/                  ||       || _        | j3                  ||       | j5                  |       | j7                  |       | j9                  |       | j;                  |       | j=                  |        | j?                  |       | jA                  |	       | jC                  |
       | jE                  |       | jG                  |       | jI                  |       | jK                  |       | jM                  |       | jO                  |)       |Ud| _(        | jS                  |       |jT                  | _*        | jW                  |       | jX                  j[                          n(|| j]                  ||       n|| j_                  |       | ja                  |       | jc                  |       | jd                  jg                  |!xr | ji                                | jk                  |       y)a/  
        Set-up configuration for the CodeEditor instance.

        Usually the parameters here are related with a configurable preference
        in the Preference Dialog and Editor configurations:

        linenumbers: Enable/Disable line number panel. Default True.
        language: Set editor language for example python. Default None.
        markers: Enable/Disable markers panel. Used to show elements like
            Code Analysis. Default False.
        font: Base font for the Editor to use. Default None.
        color_scheme: Initial color scheme for the Editor to use. Default None.
        wrap: Enable/Disable line wrap. Default False.
        tab_mode: Enable/Disable using Tab as delimiter between word,
            Default True.
        strip_mode: strip_mode: Enable/Disable striping trailing spaces when
            modifying the file. Default False.
        intelligent_backspace: Enable/Disable automatically unindenting
            inserted text (unindenting happens if the leading text length of
            the line isn't module of the length of indentation chars being use)
            Default True.
        automatic_completions: Enable/Disable automatic completions.
            The behavior of the trigger of this the completions can be
            established with the two following kwargs. Default True.
        automatic_completions_after_chars: Number of charts to type to trigger
            an automatic completion. Default 3.
        completions_hint: Enable/Disable documentation hints for completions.
            Default True.
        completions_hint_after_ms: Number of milliseconds over a completion
            item to show the documentation hint. Default 500.
        hover_hints: Enable/Disable documentation hover hints. Default True.
        code_snippets: Enable/Disable code snippets completions. Default True.
        highlight_current_line: Enable/Disable current line highlighting.
            Default True.
        highlight_current_cell: Enable/Disable current cell highlighting.
            Default True.
        occurrence_highlighting: Enable/Disable highlighting of current word
            occurrence in the file. Default True.
        scrollflagarea : Enable/Disable flag area that shows at the left of
            the scroll bar. Default True.
        edge_line: Enable/Disable vertical line to show max number of
            characters per line. Customizable number of columns in the
            following kwarg. Default True.
        edge_line_columns: Number of columns/characters where the editor
            horizontal edge line will show. Default (79,).
        show_blanks: Enable/Disable blanks highlighting. Default False.
        underline_errors: Enable/Disable showing and underline to highlight
            errors. Default False.
        close_parentheses: Enable/Disable automatic parentheses closing
            insertion. Default True.
        close_quotes: Enable/Disable automatic closing of quotes.
            Default False.
        add_colons: Enable/Disable automatic addition of colons. Default True.
        auto_unindent: Enable/Disable automatically unindentation before else,
            elif, finally or except statements. Default True.
        indent_chars: Characters to use for indentation. Default " "*4.
        tab_stop_width_spaces: Enable/Disable using tabs for indentation.
            Default 4.
        cloned_from: Editor instance used as template to instantiate this
            CodeEditor instance. Default None.
        filename: Initial filename to show. Default None.
        occurrence_timeout : Timeout in milliseconds to start highlighting
            matches/occurrences for the current word under the cursor.
            Default 1500 ms.
        show_class_func_dropdown: Enable/Disable a Matlab like widget to show
            classes and functions available in the current file. Default False.
        indent_guides: Enable/Disable highlighting of code indentation.
            Default False.
        scroll_past_end: Enable/Disable possibility to scroll file passed
            its end. Default False.
        show_debug_panel: Enable/Disable debug panel. Default True.
        folding: Enable/Disable code folding. Default True.
        remove_trailing_spaces: Remove trailing whitespaces on lines.
            Default False.
        remove_trailing_newlines: Remove extra lines at the end of the file.
            Default False.
        add_newline: Add a newline at the end of the file if there is not one.
            Default False.
        format_on_save: Autoformat file automatically when saving.
            Default False.
        	NT)6set_close_parentheses_enabledset_close_quotes_enabledset_add_colons_enabledset_auto_unindent_enabledset_indent_charsset_debug_paneltoggle_code_foldingr   set_enabledr   set_filenamer   set_columnstoggle_identation_guidesindent_charsr   set_indentation_widthlenset_blanks_enabledset_remove_trailing_spacesset_remove_trailing_newlinesset_add_newlineset_scrollpastend_enabledr  rA  set_languageset_underline_errors_enabledset_highlight_current_cellset_highlight_current_lineset_occurrence_highlightingset_occurrence_timeoutset_tab_modetoggle_intelligent_backspacetoggle_automatic_completions%set_automatic_completions_after_charstoggle_completions_hintset_completions_hint_after_mstoggle_hover_hintstoggle_code_snippetstoggle_format_on_saverW  setFontre  r	  r   r   set_fontset_color_schemeset_tab_stop_width_spacesr  r   
setVisibleis_python_likeset_strip_mode)*ro   r  r  r  fontr   wrapr  
strip_moder  r  r   r%  r&  hover_hintscode_snippetshighlight_current_linehighlight_current_cellr  r   r   edge_line_columnsshow_blanksunderline_errorsclose_parenthesesclose_quotes
add_colonsauto_unindentr#  tab_stop_width_spacescloned_fromrA  occurrence_timeoutshow_class_func_dropdownr   scroll_past_endshow_debug_panelfoldingremove_trailing_spacesremove_trailing_newlinesadd_newliner+  s*                                             rt   setup_editorzCodeEditor.setup_editor5  sH   x 	**+<=%%l3##J/&&}5l+ 	-x8 	  ) 	''7 	""8, 	""9-""#45 	%%m4$44%' 44S9J9J5KL 	, 	''(>? 	))*BC 	[) 	&&7 	  g6 !(H- 	))*:; 	''(>? 	''(>? 	(()@A##$67 	(# 	))*?@ 	))*?@22-	/ 	$$%56**+DE 	, 	!!-0 	"">2"!DN LL %**DJ k* KK!MM$-%!!,/ 	&&'<=d# 	))*B +D.2.A.A.C	E 	J'rv   c                     || j                   v r@| j                   |   }t        | |      } ||       | j                  j                  ||       y y rg   )handler_registryr  completions_response_signalemit)ro   rd   rr   handler_namehandlers        rt   handle_responsezCodeEditor.handle_response,  sP    T***008LdL1GFO ,,11&&A +rv   c                     ||d<   | |d<   | j                   j                  | j                  j                         ||       y)zSend request to LSP manager.re   response_instanceN)sig_perform_completion_requestr]  r  lowerrq  s       rt   rp  zCodeEditor.emit_request6  s@    &7"#&*"#++00MM!66	3rv   c                 ~    t               dkD  rt        j                  |d       yt        j                  ddd       y)zj
        Log errors when handling LSP responses.

        This works when debugging is on or off.
        r   T)exc_info%   )
stack_infoN)r*   loggererror)ro   messages     rt   log_lsp_handle_errorsz CodeEditor.log_lsp_handle_errors=  s3     q LL4L0 LLaDL1rv   c                     d| _         | j                  rd}nd}| j                          t        j	                  dj                  || j                               y)z,Start completion services for this instance.Tzcloned editorr   z*Completion services available for {0}: {1}N)rh   rW  document_did_openrj  debugr  rA  )ro   additional_msgs     rt   start_completion_servicesz$CodeEditor.start_completion_servicesP  sJ    %)">>,NN""$BIIDMM+ 	,rv   c                 J   |d   }|d   }|d   }|d   }|j                  dd      | _        |j                  dt        j                        | _        |j                  dd      | _        |j                  d	d      | _        |d
   d   | _        |d   | _        |j                  dd      | _	        |d   | _
        |j                  dd      | _        |d   dgz   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        |d   | _        | j&                  j)                  |d          | xj&                  |j                  dg       z  c_        | j                   r6| j*                  j-                  d       | j.                  j1                  d       d| _        y)z
        Register completion server capabilities.

        Parameters
        ----------
        capabilities: dict
            Capabilities supported by a language server.
        textDocumentSynccompletionProvidersignatureHelpProvider documentOnTypeFormattingProvider	openCloseFchangewillSavewillSaveWaitUntilsaveincludeTexthoverProviderfoldingRangeProvidertriggerCharactersresolveProvider=definitionProviderreferencesProviderdocumentHighlightProviderdocumentFormattingProviderdocumentRangeFormattingProviderdocumentSymbolProviderfirstTriggerCharactermoreTriggerCharacterTN)r   rD  r5   NONErF  rG  rH  rC  rI  rU  rJ  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rj   format_action
setEnabledsig_refresh_formattingr]  rh   )ro   capabilitiessync_optionscompletion_optionssignature_optionsrange_formatting_optionss         rt    register_completion_capabilitiesz+CodeEditor.register_completion_capabilities]  s    $$67)*>?()@A;< 	!(4(8(8e(L%%))(4H4M4MN , 0 0U C&2&6&67J7<'>#!-f!5m!D(9!-!1!1"E"+ 23 	' ""#4e< 	( 12cU: 	,(45I(J%'34H'I$!-.I!J"./K"L:; 	% 12 	% 	""))$%<=	?""$(()?D	F" ""))$/'',,T2%)"rv   c                 V    t         j                  d| j                  z         d| _        y )Nz#Stopping completion services for %sF)rj  rp  rA  rh   r  s    rt   stop_completion_servicesz#CodeEditor.stop_completion_services  s     :T]]JK%*"rv   rc   c           	         	 | j                   j                  j                          | j                   j                  j                  | j                  t        j                         | j                         }| j                         }| j                         r| j                  |      }| j                  | j                  | j                  || |j!                         |j#                         |j%                         d}|S # t        t        f$ r Y w xY w)z0Send textDocument/didOpen request to the server.)r  r  versionr  
codeeditoroffsetselection_startselection_end)r   r   
disconnect	TypeErrorRuntimeErrorr   sync_symbols_and_foldingr   UniqueConnectionr  get_text_with_eol
is_ipythonipython_to_pythonrA  r  rB  r  selectionStartselectionEnd)ro   r  r  rr   s       rt   ro  zCodeEditor.document_did_open  s    	0088CCE 	,,44<<))2+>+>	@ "%%'??))$/DMM((oo'%446#002	
 = <( 		s   $C: :DD)rd   c                     | j                   sy| j                  | j                  j                          d| j                  i}|S )zRequest document symbols.Nr  )rR  r:  emit_request_in_progressrA  ro   rr   s     rt   request_symbolszCodeEditor.request_symbols  s=     ,,==$MM224$--(rv   c                    	 |d   }| j                  |       | j                  | j                  j                  |       d| _        y# t        $ r
 Y d| _        yt
        $ r | j                  d       Y 5w xY w# d| _        w xY w)zHandle symbols response.rr   NTzError when processing symbols)_update_classfuncdropdownr:  update_outline_infor  rZ  	Exceptionrm  )ro   rr   symbolss      rt   process_symbolszCodeEditor.process_symbols  s    	(X&G**73}}(11': $(D   	  $(D   	H&&'FG	H $(D s/   =A 	A5A8 A52A8 4A55A8 8	Bc                     |g n|}| j                   j                         r| j                   j                  |       y| j                   j                  |       y)zUpdate class/function dropdown.N)r   	isVisibleupdate_dataset_data)ro   r  s     rt   r  z$CodeEditor._update_classfuncdropdown  sG    "W!!++-""..w7""++G4rv   c                     d| _         | j                  j                  | j                         | j                  j	                          y)zSchedule a document update.TN)rm  rk   rl   LSP_REQUESTS_LONG_DELAYrn   r  s    rt   r  z(CodeEditor._schedule_document_did_change  s6    -1*##//0L0LM##))+rv   c                    d| _         d| _        d| _        | j                  ry| j	                         }| j                         r| j                  |      }| xj                  dz  c_        | j                  j                  | j                  |      | _        || _
        | j                         }| j                  | j                  || j                  |j                         |j                         |j!                         d}|S )z2Send textDocument/didChange request to the server.FNrh  )r  r  r  diffr  r  r  )rY  rZ  r[  rW  r  r  r  rB  rc  
patch_makerd  re  r  rA  r  r  r  ro   r  r  rr   s       rt   rn  zCodeEditor.document_did_change  s     ',#$$ >> %%'??))$/DQ[[++D,>,>E
!"MM((JJoo'%446#002
 rv   c                 `    | j                   j                          | j                  |d          y)zHandle linting response.rr   N)r   rn   process_code_analysisr  s     rt   process_diagnosticszCodeEditor.process_diagnostics  s+     	,,224 	""6(#34rv   c                 P   | j                         }d}| j                  j                         D ]  }||z  dk(  s| j                  |   } n |s(| j                  j                         }t	        |      d   }| j
                  j                  |t        j                  dd      z          y)z]
        Set timeout to sync symbols and folding according to the file
        size.
        Nr   id   )	get_line_count!SYNC_SYMBOLS_AND_FOLDING_TIMEOUTSkeysvalueslistr   rl   randomrandint)ro   current_linesr   linestimeoutss        rt   r   z/CodeEditor.set_sync_symbols_and_folding_timeout!  s    
 ++-;;@@B 	E&1,@@G	
 ==DDFH8nR(G 	,,88fnnT3//	1rv   c                 v    | j                   s| j                          | j                  s| j                          yy)zO
        Synchronize symbols and folding after linting results arrive.
        N)r[  request_foldingrZ  r  r  s    rt   r  z#CodeEditor.sync_symbols_and_folding7  s3     ##  "##  " $rv   c                 f    | j                          || _        | j                  j                          y)z*Process code analysis results in a thread.N)cleanup_code_analysisr`  r\  rn   )ro   diagnosticss     rt   r  z CodeEditor.process_code_analysis@  s*    ""$' 	&&,,.rv   c                 ,   | j                  d       | j                  d       | j                  d       | j                         D ]	  }g |_         | j                  d       | j                  j                          | j                  j                          y)z Remove all code analysis markersFcode_analysis_highlightcode_analysis_underlineTN)setUpdatesEnabledclear_extra_selectionsr  code_analysissig_flags_changedr]  r   updater  s     rt   r  z CodeEditor.cleanup_code_analysisH  s    u%##$=>##$=>++- 	$D!#D	$ 	t$ 	##%""$rv   c                 ~    	 | j                  d       y# t        $ r Y yt        $ r | j                  d       Y yw xY w)z0Set errors and warnings in the line number area.F	underlineNError when processing linting)_process_code_analysisr  r  rm  r  s    rt   r]  zCodeEditor.set_errorsW  sF    	H''%'8 	  	H&&'FG	Hs    	<<<c                     	 | j                  d       | j                  d       y# t        $ r Y yt        $ r | j	                  d       Y yw xY w)zUnderline errors and warnings.r  Tr  Nr  )r  r  r  r  rm  r  s    rt   rJ  zCodeEditor.underline_errorsb  sW    	H
 ''(AB''$'7 	  	H&&'FG	Hs   #& 	AAAc                     | j                   j                          | j                  r| j                          | j                  j                          | j                  j                          y)z(Finish processing code analysis results.N)r   r  r   rJ  sig_process_code_analysisr]  r  r  s    rt   r_  zCodeEditor.finish_code_analysisr  sM    ""$((!!#&&++-##%rv   c                 >    t        t        | j                              S )zR
        Return True if there are errors or warnings present in the file.
        )boolr%  r`  r  s    rt   errors_presentzCodeEditor.errors_presentz  s     C))*++rv   c                     | j                         }|r| j                         \  }}| j                  D ]  }| j                         r	|d   dk(  r|j	                  dd      }|d   }|d   }|d   }	|j	                  dd	      }
|d   }|j	                  d
t
        j                        }|j                  |d         }|j                         }d|v r| j                  dk(  rt        j                  |      |j                         }|st        |       }|r|j                         }|cxk  rk  sn |t
        j                  k(  }|r| j                  n| j                   }t#        |      }|j%                  d       ||_        ||_        |	|_        | j-                  d|j/                         |j&                         | j0                  s|j2                  j5                  ||
||f       |j7                  |        y)a  
        Process all code analysis results.

        Parameters
        ----------
        underline: bool
            Determines if errors and warnings are going to be set in
            the line number area or underlined. It's better to separate
            these two processes for perfomance reasons. That's because
            setting errors can be done in a thread whereas underlining
            them can't.
        rl  zundefined name 'get_ipython'sourcer   rangern   endcodeEseverityr  zanalysis:ignorer}   N   r  )underline_color)r  get_buffer_block_numbersr`  r  r   r6   ERRORfindBlockByNumberr  r  NOQA_INLINE_REGEXPsearchr  r@   r  r   r   r   setAlphacolorr  r  highlight_selection
_selectionrW  r  rj   setUserData)ro   r  r  first_block
last_block
diagnosticr  	msg_rangern   r  r  rl  r  r  r  r  block_nbrk  r  s                      rt   r  z!CodeEditor._process_code_analysis  s    ==?&*&C&C&E#K++ 6	(J y)-KK^^Hb1F"7+Ig&EE"C>>&#.D +G!~~.446H ..uV}=E::<D !D( }}(%,,T2>>>#D$T* ,,.(8j8$(:(@(@@E05D,,4;M;ME"5MENN3'"'EK+0D(),D&,,-F-1__->=B[[ - J ~~&&--x9 !!$'m6	(rv   c                 J   | j                         }| j                  dd      }| j                  |j                         |j	                         |j                         |j                         |j                         |d}| j                         j                         |f| _        |S )zTrigger completion.TF
completionvalid_python_variable)r  r  columnr  r  r  current_word)	r  get_current_wordrA  r  r  r  r  r  rT  )ro   	automaticr  r   rr   s        rt   r  zCodeEditor.do_completion  s     ",,"' - 
 MM&&())+oo'%446#002(
 !% 1 : : <iHrv   c                     | j                   }|yd| _         |\  }}| j                         }|j                  t        j                         | j                  |j                         d      }| j                  |      }d|z  }| j                         }		 |d   }
|
g nA|
D cg c]6  }|j                  d      s!|j                  di       j                  d      r|8 c}}
| j                  dd	
      }t        |
      dk(  rK|
d   j                  d      |k(  r4|
d   j                  di       j                  d      s|
j                          | j                         j                         }| j                  d      }|r|\  }}nd}|}dt        |      dkD  r|d   fd}t        |
|      }|D ]  }d|v r5|d   d   d   }|d   d   d   }||k(  r||k(  r|d   d   }||d<   ||d<   |d= d|v sA|d   }|j                         }|d   g}|dd D ]  }||z   }|j!                  |        |	j#                  |      }||d<    | j$                  j'                  |||       yc c}w # t(        $ r Y yt*        $ r | j-                  d       Y yw xY w)zHandle completion response.Neol rr   
insertTexttextEditnewTextTFr  rh  r   )r  r   c                     d| v r	| d   d   }n| d   }|d   }j                         xr |j                         xs" j                         xr |j                         }|| d   fS )Nr  r  r  r   sortText)isupperislower)r  text_insertionfirst_insert_lettercase_mismatchfirst_letters       rt   sort_keyz/CodeEditor.process_completion.<locals>.sort_key  s    +%/
%;I%FN%/%=N&4Q&7#!))+M0C0K0K0M O!))+M0C0K0K0M  &z*'=>>rv   r  r  rn   r  
filterTextz!Error when processing completions)rT  r  r  r   StartOfBlockget_textr  compute_whitespaceget_line_separatorr   r  r%  popget_current_word_and_positionsorted
splitlinesrj   joinr   	show_listr  r  rm  )ro   rr   rp   r  r  start_cursor	line_textleading_whitespaceindentation_whitespaceeol_charcompletionsr  prefixreplace_endunder_cursorr  replace_startr  completion_listc_replace_startc_replace_endinsert_textinsert_text_linesreindented_textinsert_liner  s                            @rt   process_completionzCodeEditor.process_completion  s    ##<#")(!!+":":;MM,"7"7"95A	!44Y?!$'9!9**,Q	L *K!).9 C
NN<0NN:r266yA  C  **u + >F K A%A""<0F:N&&z26::9E!//+446K===NL&2#m +L4y1}#Aw?  %[h?O
 . ?
+&0&<W&Eg&NO$.z$:7$CE$JM (=8%4&0&<Y&G3>
<03>
<0&z2:-",\":K(3(>(>(@%'8';&<O'8'< <&<{&J'..{;< '/mmO&DO/>J|,-?0 "",,96MCP  	  	L&&'JK	Ls2   I&  ;I!DI& 0A0I& !I& &	J1JJc                      | j                   |dS )N)r  completion_item)rA  )ro   items     rt   resolve_completion_itemz"CodeEditor.resolve_completion_itemD  s     MM#
 	
rv   c                     	 |d   }|sy | j                   j                  |       y # t        $ r Y y t        $ r | j	                  d       Y y w xY w)Nrr   z.Error when handling completion item resolution)r   augment_completion_infor  r  rm  )ro   responses     rt   !handle_completion_item_resolutionz,CodeEditor.handle_completion_item_resolutionK  s\    	B)H""::8D 	  	B&&@B	Bs   & & 	AAAc                 p    | j                         \  }}| j                  d      }| j                  |||d}|S )zAsk for signature.r  r  r  r  r  )get_cursor_line_columnget_positionrA  )ro   r  r  r  rr   s        rt   request_signaturezCodeEditor.request_signature^  sD     224f""8,MM	
 rv   c                    	 |d   }|d|v r| j                   j                  |       |d   }|d   }t        |t              r|d   }|j	                  dd      }|d   }|d	   }d}t        |      d
kD  r|t        |      k  r
||   }|d   }|d   }	| j                  |	|| j                  |       yyy# t        $ r Y yt        $ r | j                  d       Y yw xY w)zHandle signature response.rr   NactiveParameter
signaturesdocumentationr       r  
parametersr   label)	signature	parameterr  r@  zError when processing signature)sig_signature_invokedr]  r  dictreplacer%  show_calltipr  r  r  rm  )
ro   rr   signature_paramssignature_datar@  parameter_idxrB  rE  parameter_datarD  s
             rt   process_signatureszCodeEditor.process_signaturesk  s    %	J%h/ ,%)99**//0@A!1,!? . ?mT2$1'$:M !. 5 5gs C 01B C+L9
 	z?Q&=3z?+J%/%>N .w 7I*73	 !!''!]]"/	 " - : -:  	  	J&&'HI	Js   B-B2 2	C=CCc                     | j                         }| j                         }| j                  | j                  ||j	                         |j                         |j                         d}|S )N)r  r  r  r  r  r  )r  r  rA  rB  r  r  r  r  s       rt   request_cursor_eventzCodeEditor.request_cursor_event  s_    %%'"MM((oo'%446#002
 rv   c                 D    | j                   |||d}|| _        || _        |S )zRequest hover information.r9  )rA  
_show_hint_request_hover_clicked)ro   r  r  r  	show_hintclickedrr   s          rt   r  zCodeEditor.request_hover  s1     MM	
 $&-#rv   c                    t               rddlm} t        ||      ry	 |d   }|rt        |t              ry| j
                  j                  || j                         |^| j                  rQ| j                  rD| j                  }|j                  dd      }| j                  ||| j                         d| _	        yyyy# t        $ r Y yt        $ r | j                  d       Y yw xY w)	zHandle hover response.r   )MockNrr   rA  r  )inspect_wordr  zError when processing hover)r+   unittest.mockrW  r  r  sig_display_object_infor]  rS  rR  r   r   rH  rT  r  r  rm  )ro   contentsrW  contentr  s        rt   handle_hover_responsez CodeEditor.handle_hover_response  s      !* (D)	Fx(G j$7((--++ "t4;K;K,,!//'37wT(,(8(8  :#'  <L"  	  	F&&'DE	Fs   B> BB> >	C%	C%$C%c                 n   | j                   r| j                         ry|| j                         }t        |j	                               }t        |      dk(  r8|j                  t        j                         t        |j	                               }|%| j                         \  }}| j                  ||d}|S y)z4Go to definition from cursor instance (QTextCursor).Nr   )r  r  r  )rM  in_comment_or_stringr  rO   selectedTextr%  selectr   WordUnderCursorr:  rA  )ro   r  r  r  r  rr   s         rt   r  z'CodeEditor.go_to_definition_from_cursor  s     --))+>__&Ff1134t9>MM+556!&"5"5"78D668LD& F
 M rv   c                 2   	 |d   }|e|d   }|d   }| j                   |d   k(  r| j                  |d   dz   |d   dd	       y| j                  j                  |d   |d   dz   |d          yy# t        $ r Y yt
        $ r | j                  d
       Y yw xY w)z!Handle go to definition response.rr   Nr  rn   r  r  rh  	character)r  z&Error when processing go to definition)rA  
go_to_linego_to_definitionr]  r  r  rm  )ro   r  	def_rangern   s       rt   handle_go_to_definitionz"CodeEditor.handle_go_to_definition  s    	:)H#$W-	!'*==HV$44OOE&MA$5$)+$6$()- $ /
 ))..x/?/4V}q/@/4[/AC $  	  	:&&8:	:s   AA/ )A/ /	B:BBc                 ~    | j                         r| j                  r| j                          y| j                          y)z)Format current document or selected text.N)has_selected_textrQ  format_document_rangeformat_documentr  s    rt   r  z#CodeEditor.format_document_or_range  s.    !!#(E(E&&(  "rv   c                    | j                         j                         | _        | j                  sy| j                  ry| j
                  dk7  }|rt        | j
                        n| j                  }| j                  ||| j                  | j                  | j                  dd}| j                  d       | j                         j                  d       | j                  j!                          d| _        d| _        |S )zFormat current document.Nr  tab_sizeinsert_spacestrim_trailing_whitespaceinsert_final_new_linetrim_final_new_lines)r  optionsT)r  r  r.  rP  rY  r#  r%  rO  rA  rV  rX  rW  setReadOnlyr  setModifiedsig_start_operation_in_progressr]  rX  )ro   using_spacesro  rr   s       rt   rl  zCodeEditor.format_document  s     04/@/I/I/K,&&&&((D0.:C))*.. 	 MM$!-,0,G,G)-)9)9(,(E(E	
 	##D),,113%)"&*#rv   c                    | j                         j                         | _        | j                  r| j	                         sy| j
                  ry| j                         \  }}|\  }}|\  }}||kD  r
|dk(  r|dz  }||d||dd}| j                  dk7  }|rt        | j                        n| j                  }	| j                  ||	|| j                  | j                  | j                  dd}
| j                  d	       | j                         j!                  d	       | j"                  j%                          d	| _        d	| _        |
S )
zFormat selected text.Nr   rh  )r  rd  )rn   r  r  rn  )r  r  rt  T)r  r  r.  rQ  rj  rY  get_selection_start_endr#  r%  rO  rA  rV  rX  rW  ru  r  rv  rw  r]  rX  )ro   rn   r  
start_line	start_colend_lineend_col	fmt_rangerx  ro  rr   s              rt   rk  z CodeEditor.format_document_range7  sS    04/@/I/I/K,,,D4J4J4L&&113
s %
I' j W\MH #&
 !$	
	 ((D0.:C))*.. 	 MM$!-,0,G,G)-)9)9(,(E(E

 	##D),,113%)"&*#rv   c                 j   	 | j                   r| j                  |       | j                  d       | j	                         j                  d       | j	                         j                  d       | j                  j                          d| _        d| _         y# t        $ rz Y | j                  d       | j	                         j                  d       | j	                         j                  d       | j                  j                          d| _        d| _         yt        $ r | j                  d       Y w xY w# | j                  d       | j	                         j                  d       | j	                         j                  d       | j                  j                          d| _        d| _         w xY w)z$Handle document formatting response.FTNz)Error when processing document formattingrY  _apply_document_editsr  ru  r  rv  sig_stop_operation_in_progressr]  rX  r  rm  ro   editss     rt   handle_document_formattingz%CodeEditor.handle_document_formattingo  s`   	0****51 U#MMO''.MMO''-//446).D&*/D'  	  U#MMO''.MMO''-//446).D&*/D'  	5&& (4 5	5
 U#MMO''.MMO''-//446).D&*/D'0   B 	D6 D9 D62D9 5D66D9 9A9F2c                 j   	 | j                   r| j                  |       | j                  d       | j	                         j                  d       | j	                         j                  d       | j                  j                          d| _        d| _         y# t        $ rz Y | j                  d       | j	                         j                  d       | j	                         j                  d       | j                  j                          d| _        d| _         yt        $ r | j                  d       Y w xY w# | j                  d       | j	                         j                  d       | j	                         j                  d       | j                  j                          d| _        d| _         w xY w)z*Handle document range formatting response.FTNz3Error when processing document selection formattingr  r  s     rt    handle_document_range_formattingz+CodeEditor.handle_document_range_formatting  s`   	0****51 U#MMO''.MMO''-//446).D&*/D'  	  U#MMO''.MMO''-//446).D&*/D'  	?&& (> ?	?
 U#MMO''.MMO''-//446).D&*/D'r  c                    |d   }|y| j                         }t        |      }d}|D ]*  }|d   }|d   }|d   |d   }	}|d   |d   }}
|	d   |	d   }}| j                  |
|      }| j                  ||      }t        j                  |      }||d	k7  r|j                  |d	      }t        |      }t        |      }|| j                         j                         k(  r| j                  d
      }|dz  }|t        |      k(  r||dz
     d	k(  r|dz  }|dt        |dz
  d       |z   ||dz
  d z   }dj                  |      }||}t        |||      }- |'|j                  d	| j                               }| j                         }|j                          |j!                  t"        j$                         |j!                  t"        j&                  t"        j(                         |j+                  |       |j-                          | j.                  rl| j1                  t"        j$                         | j                         }|j3                  | j.                         | j5                  |       | j7                          yyy)z@Apply a set of atomic document edits to the current editor text.rr   Nr  r  rn   r  r  rd  
eofrh  r   r   )toPlainTextr  get_position_line_numberrS   get_eol_charsrH  r  
blockCountr;  r%  maxr  r'   r  r  beginEditBlockr  r   r  r  
KeepAnchorr  endEditBlockr.  
moveCursorsetPositionr  centerCursor)ro   r  r  text_tokensmerged_textedit
edit_range	repl_textrn   r  r{  r|  r}  r~  	start_posend_posrepl_eol	this_editthis_edition	text_editr  s                        rt   r  z CodeEditor._apply_document_edits  s   h= !4j #	BDgJYI#G,j.?3E$)&M53E	J #FS-=gH55j)LI33HgFG "//	:H#D(8%--h=	{+KYI4==?5577++E213{++!,41'(>Y]A)>?%&'!56L -I"'#I{DAG#	BJ "%--dD4K4K4MNK__&F !!#  1 12 + 6 68 k* ! 33 1 12*""4#G#GH""6*!!# 41 #rv   c                     | j                   }t        j                  d      }|j                  |      }d}|1|j	                  d      }|j                  d|dz        }t        |      }|S )Nz(\s+).*r   rh  r  r  )rO  recompilematchgrouprH  r%  )ro   r  ro  whitespace_regexwhitespace_matchtotal_whitespacewhitespace_charss          rt   r  zCodeEditor.compute_whitespace  sv    --::j1+11$7'/55a8/77hn &"#34rv   c                     i | _         t        | j                               j                         }t	        |      D ]%  \  }}| j                  |      }|| j                   |<   ' y rg   )rf  rO   r  r  	enumerater  )ro   r  r  r  ir  r  s          rt   update_whitespace_countz"CodeEditor.update_whitespace_count  s_    #% t//12==? ' 	;GAt#66t<*:D$$Q'	;rv   c                 P    | j                   j                  t              }i |_        y)zCleanup folding pane.N)r   r   r:   folding_regions)ro   folding_panels     rt   cleanup_foldingzCodeEditor.cleanup_folding  s    5(*%rv   c                 T    | j                   r| j                  syd| j                  i}|S )zRequest folding.Nr  )rU  r!  rA  r  s     rt   r  zCodeEditor.request_folding	  s+     %%T->->$--(rv   c                    |d   }|y	 g }|D ]+  \  }}| j                  ||      }|j                  |||f       - 	 d| _        t        j                  | j                        | j                  _
        | j                  j                          y# t        $ r
 Y d| _        yt        $ r | j                  d       Y ~w xY w# d| _        w xY w)zHandle folding response.rr   NTError when processing folding)get_text_regionrj   r  r[  r  rm  rw   rx   update_and_merge_foldingr"  r^  rn   )ro   r6  rangesextended_rangesrn   r  text_regions          rt   handle_folding_rangezCodeEditor.handle_folding_range  s     (#>
	( O$ B
s"225#>&&sK'@AB $(D  *3):):))?*<""&""((*  	  $(D   	H&&'FG	H $(D s4   2B B? 	B<B?  B<9B? ;B<<B? ?	Cc                    	 | j                   j                  t              }t        ||j                  |j
                        \  }}t        |      }||g|| _        y# t        $ r Y yt        $ r | j                  d       Y yw xY w)z)Update and merge new folding information.Nr  )r   r   r:   rF   current_treerootrG   rV  r  r  rm  )ro   r  r  r  r  folding_infos         rt   r  z#CodeEditor.update_and_merge_folding.  s    	H KKOOL9M!.!;!;"""$L$ 348L".!D|!DD 	  	H&&'FG	Hs   AA 	B(BBc                 :   | j                   j                  t              }| j                  |j	                  | j                         | j
                  j                  r?t        | j                        dkD  r&| j                         \  }}| j                  ||       yyy)zFinish processing code folding.Nr   )r   r   r:   rV  update_foldingr   _enabledr%  re  r:  r  )ro   r  r  r  s       rt   r$  zCodeEditor.finish_code_folding@  s    5
 )((););< &&3tzz?Q+>668LD&((v6 ,?&rv   c                 `    d| j                   i}| j                  r| j                         |d<   |S )zSend save request.r  r  )rA  rC  r  r  s     rt   notify_savezCodeEditor.notify_saveQ  s2     $--(!!!335F6Nrv   c                    g | _         	 | j                  j                          | j                  r6	 | j
                  j                  j                          | j                  | d}|S y# t        $ r Y Nw xY w# t        t        f$ r Y 2w xY w)zSend close request.)r  r  N)
ri   rk   r  r  rh   r   r   r  r  rA  r  s     rt   notify_closezCodeEditor.notify_closeZ  s     )+%	'',,. %% 44<<GGI
 "F M! &  		 |, s"   A& $A5 &	A21A25BBc                     | j                   j                  t              }t        |      r-|j	                         t
        d   v r|r|j                  d       y|j                  d       y)zEnable/disable debug panel.r}   TFN)r   r   r8   rQ   rd  rD   r>  )ro   rT  r  debugger_panels       rt   r  zCodeEditor.set_debug_panel{  sO    78$ M($;; %%d+%%e,rv   c                 F   | j                   j                  t              }|r|j                          y|r]d|v rY|d   }|rR| j                  rFt        j                  |      t        j                  | j                        k(  r|j                          y|j                          y)zUpdate debugger panel state.Nfname)r   r   r8   start_cleanrA  ospnormcase
stop_clean)ro   state	last_stepr  r  r  s         rt   update_debugger_panel_statez&CodeEditor.update_debugger_panel_state  s|    7&&(w)+g&E$--U+s||DMM/JJ**,!!#rv   c                 d    | j                   j                  t              }|j                  |       y)zEnable/disable folding panel.N)r   r   r:   r>  )ro   rU  r  s      rt   set_folding_panelzCodeEditor.set_folding_panel  s"    5  )rv   c                     || _         y)z|
        enabled = tab always indent
        (otherwise tab indents only when cursor is at the beginning of a line)
        N)r  r  s     rt   r1  zCodeEditor.set_tab_mode  s    
 rv   c                     || _         y)z7
        Strip all trailing spaces if enabled.
        N)r?  r  s     rt   r@  zCodeEditor.set_strip_mode  s     06,rv   c                     || _         y rg   )r  ro   r  s     rt   r2  z'CodeEditor.toggle_intelligent_backspace  
    %*"rv   c                     || _         y rg   )r  r  s     rt   r3  z'CodeEditor.toggle_automatic_completions  r  rv   c                     || _         y rg   )r@  r  s     rt   r7  zCodeEditor.toggle_hover_hints  s
    #( rv   c                     || _         y rg   )rE  r  s     rt   r8  zCodeEditor.toggle_code_snippets  s
    "rv   c                     || _         y rg   )r+  r  s     rt   r9  z CodeEditor.toggle_format_on_save  s
    #rv   c                 v    || _         | j                  |       |s| j                  j                  rd| _         y y y NT)r!  r  r   r  r  s     rt   r  zCodeEditor.toggle_code_folding  s8    !u%++44 $D 5urv   c                 d    |r| j                   sd| _         | j                  j                  |       y r  )r!  r   r  r  s     rt   r"  z#CodeEditor.toggle_identation_guides  s)    ** $D&&u-rv   c                     || _         y)zEnable/disable completion hint.N)r%  r  s     rt   r5  z"CodeEditor.toggle_completions_hint  s
     %rv   c                     || _         y)zT
        Set the number of characters after which auto completion is fired.
        N)r   )ro   numbers     rt   r4  z0CodeEditor.set_automatic_completions_after_chars  s     28.rv   c                     || _         y)zY
        Set the amount of time in ms after which the completions hint is shown.
        N)r&  )ro   mss     rt   r6  z(CodeEditor.set_completions_hint_after_ms  s     *,&rv   c                 d    || _         | j                  j                  t              }|||_        yy)z6Enable/disable automatic parentheses insertion featureN)r'  ra  r   r.   enabled)ro   r  bracket_extensions      rt   r  z(CodeEditor.set_close_parentheses_enabled  s6    )/& 22667MN((.% )rv   c                 d    || _         | j                  j                  t              }|||_        yy)z0Enable/disable automatic quote insertion featureN)r(  ra  r   r/   r  )ro   r  quote_extensions      rt   r  z#CodeEditor.set_close_quotes_enabled  s4    $*!00445IJ&&,O# 'rv   c                     || _         y)z1Enable/disable automatic colons insertion featureN)r)  r  s     rt   r  z!CodeEditor.set_add_colons_enabled  s
    "(rv   c                     || _         y)z@Enable/disable automatic unindent after else/elif/finally/exceptN)r*  r  s     rt   r  z$CodeEditor.set_auto_unindent_enabled  s
    %+"rv   c                 8    || _         |s| j                          yy)z&Enable/disable occurrence highlightingN)r  clear_occurrencesr  s     rt   r/  z&CodeEditor.set_occurrence_highlighting  s    '-$""$ rv   c                 :    | j                   j                  |       y)z(Set occurrence highlighting timeout (ms)N)r  rl   )ro   r   s     rt   r0  z!CodeEditor.set_occurrence_timeout  s    ))'2rv   c                 :    || _         |s| j                  d       yy)z.Toggle the underlining of errors and warnings.r  N)r   r  r  s     rt   r,  z'CodeEditor.set_underline_errors_enabled  s!    (-%''(AB rv   c                 l    || _         | j                   r| j                          y| j                          yz(Enable/disable current line highlightingN)r   rF  unhighlight_current_liner  s     rt   r.  z%CodeEditor.set_highlight_current_line  s+    .4+..'')))+rv   c                     |xr | j                   }|| _        | j                  r| j                          y| j                          yr  )r  highlight_current_cell_enabledrG  unhighlight_current_cell)ro   r  hl_cell_enables      rt   r-  z%CodeEditor.set_highlight_current_cell  s;    @D$@$@.<+..'')))+rv   c                 ^   ddi}|| j                   v | _        d| _        d| _        d| _        t
        j                  }|dn|}|zt        j                         D ]c  \  }}|j                         |v sd| _        | j                  |   \  }}|dk(  rd	| _        n|| _        || _        |t        v rd| _        d| _         n || j                  st        j                  |      }|t
        j                  u| _        | j                  r=|j                   j"                  d
k(  rd| _        nR|j                   j"                  | _        n6t%        j&                  |      \  }}	|	j                         }	|	|v r
||	   | _        | j)                  |       | j*                  j-                  | j                         y )NstilSTILr   TextFr   Tr   r}   SR)TAB_ALWAYS_INDENTSr  r  r  r  r   r   rD   itemsrd  	LANGUAGESrE   r  has_cell_separatorsguess_pygments_highlightersupport_language_lexerr  r  splitext_set_highlighterr   r+  )
ro   r  rA  extra_supported_languagessh_classr  r   r  r)   exts
             rt   r+  zCodeEditor.set_language	  s   %+V$4!#t'>'>> "'99%-68 - 3 3 5 e>>#u,.2D+/3~~c/B,Hni'(0(+*8D'n,7;4370 (?(?44X>H$,BII$=D!$$??''3.$'DM$,OO$8$8DMh/3iik33$=c$BDMh'++DMM:rv   c                 $   || _         | j                  6| j                  j                  d        | j                  j                  d        | j                  | j	                         | j                         | j                        | _        | j                          | | j                  _        | j                  j                  j                  | j                         | j                  j                  j                  | j                  j                         y rg   )r   r   	setParentr  r  rA  r   r  r  r  r   r  ri  r   r  )ro   r  s     rt   r  zCodeEditor._set_highlighter1	  s    !)' &&t,((.11$--/26))+262C2CE 	,,."&))11$..A''//((	*rv   c                     | j                  | j                  j                         | j                  j	                          y)z!Highlighter changed font, update.N)r:  r   rA  r  r]  r  s    rt   r  zCodeEditor.sync_fontB	  s,    T%%**+""$rv   c                 X   | j                   g S d }| j                   j                  D cg c]  } ||      s| c}| j                   _        t        | j                   j                  D ci c]  }|j                  j	                         | c}j                               S c c}w c c}w )zGet all cells.c                 X    | j                         xr | j                  | j                  k(  S rg   )is_validdef_typeCELL)r  s    rt   goodz&CodeEditor.get_cell_list.<locals>.goodM	  s!    ??$GFKK)GGrv   )r   
_cell_listr  r  r  r  )ro   r  r  s      rt   get_cell_listzCodeEditor.get_cell_listG	  s    #I	H "&!1!1!<!<'NVF'N# ++668 \\%%'/ 88=A 	A'N8s   B"B"+"B'c                     t        | j                  t        j                        xr# | j                  j                  j
                  dk(  S )NJSON)r  r   r   r  r  r  r  s    rt   is_jsonzCodeEditor.is_jsonW	  s:    4++R]]; 7  '',,6	8rv   c                 :    | j                   t        j                  u S rg   )r   r   PythonSHr  s    rt   	is_pythonzCodeEditor.is_python[	      %%44rv   c                 :    | j                   t        j                  u S rg   )r   r   	IPythonSHr  s    rt   r  zCodeEditor.is_ipython^	  s    %%55rv   c                 F    | j                         xs | j                         S rg   )r  r  r  s    rt   is_python_or_ipythonzCodeEditor.is_python_or_ipythona	  s    ~~44??#44rv   c                 :    | j                   t        j                  u S rg   )r   r   CythonSHr  s    rt   	is_cythonzCodeEditor.is_cythond	  r  rv   c                 :    | j                   t        j                  u S rg   )r   r   EnamlSHr  s    rt   is_enamlzCodeEditor.is_enamlg	  s    %%33rv   c                     | j                         xs4 | j                         xs" | j                         xs | j                         S rg   )r  r  r"  r%  r  s    rt   r?  zCodeEditor.is_python_likej	  s<      7DOO$5 7>>#7'+}}	8rv   c                    | j                  dd      }|j                         r|j                  d      r| j                          y| j	                         r"|j                  d      s| j                          y|j                  d      s|d   dk(  r| j                          y|j                         d   d	v rd
|vr| j                          y|d   dv s|j                  d      r| j                          y|j                  d      r| j                          yt        j                  d|t        j                        r| j                          y| j                          y)z/Provide intelligent behavior for Tab key press.solr  r~   r  zimport r  rz  r   )fromimportr   (,, z[^\d\W]\w*\ZN)
r  stripendswithindent_or_replacer_  r  splitr  r  UNICODEro   leading_texts     rt   intelligent_tabzCodeEditor.intelligent_tabn	  s   }}UH5!!#|'<'<S'A""$&&(1F1Fs1K ""9-b1AS1H   "1%);;<'  "%)>)>t)D""$""3'""$YYbjjA ""$rv   c                    | j                  dd      }|j                         s| j                          y| j                         r| j                          y|d   dv s|j	                  d      r| j                          y| j                          y)z4Provide intelligent behavior for Shift+Tab key pressr(  r  r  r+  r,  N)r  r-  r  r_  r.  r   r2  s     rt   intelligent_backtabzCodeEditor.intelligent_backtab	  sm    }}UH5!!#MMO&&(MMO"%)>)>t)D!!# MMOrv   c                    | j                   | j                   j                          | j                  r| j                          n| j	                          | j
                  r| j                          y| j                          y)zRehighlight the whole document.N)r   r  r  rG  r  r   rF  r  r  s    rt   r  zCodeEditor.rehighlight	  sb    '((*..'')))+..'')))+rv   c                 d   | j                         }|j                          |j                  t        j                         	 |j                  t        j
                         t        |j                         j                               }t        |      t        |j                               z
  }|dkD  r?|j                  t        j                  t        j                  |       |j                          |j                         rn |j                  t        j                         |j!                          y)zRemove trailing spacesr   N)r  r  r  r   r  
EndOfBlockrO   r  r  r%  rstripr  r  removeSelectedTextatEnd	NextBlockr  )ro   r  r  lengths       rt   trim_trailing_spaceszCodeEditor.trim_trailing_spaces	  s    "K--. 6 67!&,,."5"5"78DYs4;;=11Fz##K$4$4k6L6L$*,))+||~ 5 56  	rv   c                     | j                         }|j                          |j                  t        j                         |j                         }| j                  |      }| j                  |dz
        }| j                         dkD  r|dk(  r|j                  t        j                  t        j                         | j                  r8|dk(  r3|dk7  r.|j                  t        j                  t        j                         |dz  }|dk(  rn+| j                  |      }| j                  |dz
        }|dk(  r| j                  s.|j                  t        j                  t        j                         |j                          |j                          y)z1Remove extra newlines at the end of the document.rh  r   r   N)r  r  r  r   r  r  get_text_liner  PreviousBlockr  rX  r=  r9  r;  r  )ro   r  r  	this_lineprevious_lines        rt   trim_trailing_newlinesz!CodeEditor.trim_trailing_newlines	  sV   "KOO,!!#&&t,	**4!84  1$r/##K$=$=$/$:$:< ## B=B+>++K,A,A,7,B,BD 	19 ..t4	 $ 2 24!8 < r/   6 6 + 6 68 	!!#rv   c                 l   | j                         }|j                  t        j                         |j	                         }| j                  |      }|dk7  r_|j                          |j                  t        j                         |j                  | j                                |j                          yy)z:Add a newline to the end of the file if it does not exist.r   N)r  r  r   r  r  rA  r  r9  r  r  r  )ro   r  r  rC  s       rt   add_newline_to_filezCodeEditor.add_newline_to_file	  s    "KOO,!!#&&t,	?!!# 6 67d5578!	 rv   c                     t        | j                               }t        j                  || j                        }||k7  r0| j                          d| _        | j                  |       d| _        yy)zReplace tabs by spaces.TFN)rO   r  rS   fix_indentationr#  r  r>  insertPlainText)ro   text_before
text_afters      rt   rI  zCodeEditor.fix_indentation	  sd    $T%5%5%78//T=N=NO
*$ NN#D  ,$D %rv   c                     t        | j                               }| j                  d      }t        j                  ||      S )zReturn current object (string) r  )rO   r  r;  rS   get_primary_at)ro   source_coder  s      rt   get_current_objectzCodeEditor.get_current_object	  s8    $T%5%5%78""8,((f==rv   c                 Z   | j                         }|j                         r|S ||j                         }n|j                  |       |j	                         }|j                         }||j                         z   dz
  }||k(  r|dz   S |j                         j                  ||z
  |      |z   S )z
        Get next valid cursor position.

        Adapted from:
        https://github.com/qt/qtbase/blob/5.15.2/src/gui/text/qtextdocument_p.cpp#L1361
        rh  )r  r<  r  r  r  r>  layoutnextCursorPosition)ro   r  moder  itrn   r  s          rt   next_cursor_positionzCodeEditor.next_cursor_position	  s     "<<>O(Hx(\\^biik!A%O7Nyy{--h.>EMMrv   c                    | j                         s_| j                         }|j                         s.|j                  | j	                         t
        j                         | j                  |       | j                          y)z'Remove selected text or next character.N)	rj  r  r<  r  rV  r   r  r  remove_selected_textro   r  s     rt   r  zCodeEditor.delete
  sb     %%'__&F<<>""--/1G1GIv&!!#rv   c                 r   t         j                  t         j                  z  }| j                         }|j	                  t
        j                         t        dt        j                  |      z  t        j                        }| j                         j                  |||      }|j                         | _        |S )z*Find first occurrence: scan whole document\b%s\b)r   FindCaseSensitivelyFindWholeWordsr  r  r   r  r   escaper   CaseSensitiver  findr  r  )ro   r  flagsr  regexps        rt   __find_firstzCodeEditor.__find_first
  s    11-2N2NN"K--.W^^D%992;K;KL%%ffe< & 1rv   c                 &   t         j                  t         j                  z  }t        dt        j                  |      z  t
        j                        }| j                         j                  |||      }|j                         | j                  k7  r|S y)zFind next occurrencer[  N)r   r\  r]  r   r^  r   r_  r  r`  r  r  )ro   r  r  ra  rb  s        rt   __find_nextzCodeEditor.__find_next&
  sq    11-2N2NNW^^D%992;K;KL%%ffe<?? 5 55M 6rv   c                    | j                         \  }}| j                  j                  ||       | j                  r| j	                          n| j                          | j                  r| j                          n| j                          | j                  r| j                  j                          | j                          y)zCursor position has changedN)r:  sig_cursor_position_changedr]  r  rG  r  r   rF  r  r  r  rn   strip_trailing_spaces)ro   r  r  s      rt   __cursor_position_changedz$CodeEditor.__cursor_position_changed.
  s    224f((--dF;..'')))+..'')))+''!!'') 	""$rv   c                 h    g | _         | j                  d       | j                  j                          y)zClear occurrence markersr  N)r  r  r  r]  r  s    rt   r  zCodeEditor.clear_occurrencesA
  s*    ##M2##%rv   c                    |yt        |      }||j                  j                  |       ||j                  j                  |       |f|j                  j	                  t
        j                  t        |             |j                  j	                  t
        j                  t        |             ||j                  |       |S )zGet selection.N)
r-   r  setForegroundsetBackgroundsetPropertyr   TextUnderlineStyler   TextUnderlineColorset_outline)ro   r  foreground_colorbackground_colorr  outline_colorunderline_style	selections           rt   get_selectionzCodeEditor.get_selectionG
  s    
 >"6*	'**+;<'**+;<&(()G)G)4_)EG(()G)G)4_)EG$!!-0rv   c                     | j                  ||||||      }|y | j                  |      }	|	j                  |       | j                  ||	       y rg   )rw  get_extra_selectionsrj   set_extra_selections)
ro   r  r  rr  rs  r  rt  ru  rv  extra_selectionss
             rt   r  zCodeEditor.highlight_selection]
  s_    
 &&$&6?,	 44S9	*!!#'78rv   c                    | j                          | j                  sy| j                         j                         }|s| j	                         }|y| j                         r"| j                         j                         |k7  ry| j                         r-t        j                  t        |            st        |      dk(  ry| j                  |      }g | _        | j                  d      }d}|r|j                         }|j                         s|j                  t!        |              | j                  j#                  |       | j%                  |      }t'        |j(                  j+                               dkD  rl|j#                  |       t'        |      dk(  r|}nJ|j,                  j/                  | j0                         |j,                  j/                  | j0                         | j3                  ||      }|r| j5                  d|       t'        | j                        dkD  r-| j                  d   dk(  r| j                  j7                  d       | j8                  j;                          y)z2Marking occurrences of the currently selected wordNro   r  r   rh  r  )r  r  get_selected_textr-  r  rj  r?  rS   
is_keywordrO   _CodeEditor__find_firstr  ry  r  r  r  r@   rj   rw  r%  r  r`  r  rm  r   _CodeEditor__find_nextrz  r  r  r]  )ro   r  r  r{  first_occurrencer  rv  s          rt   r  zCodeEditor.mark_occurrencesk
  s    &&%%'--/((*D<""$&&(..0D8!&&~d';<%/ ""4(44]CLLNE>>#!!-"56##E***62I9##0023a7 ''	2'(A-'0$$$2243H3HI$++99--/%%dF3F! " 	!!-1ABt 1$)9)9")=)B   $##%rv   c                 Z   ||||d| _         t        |      }|sy|st        j                  t        |            }|rd|z  n|}t        | j	                               }|rt        j
                  n t        j                  t        j
                  z  }	 t        j                  ||      }g }g | _
        t        |      t        |      k7  }	|j                  |      D ]$  }
|	rt        j                  |
      \  }}n|
j!                         \  }}t#        | j%                               }|j&                  j)                  | j*                         |j,                  j/                  |       |j,                  j1                         }|j3                         s|j5                  t7        |              | j                  j9                  |       |j,                  j/                  |t:        j<                         |j9                  |       ' | j?                  d|       y# t        j                  $ r Y yw xY w)zHighlight all found patterns)patternr  rb  caseNr[  )ra  r`  ) r  rO   r  r^  r  	MULTILINE
IGNORECASEr  sre_constantsrk  r  r%  r`   finditerr   get_spanspanr-   r  r  rm  r   r  r  r  r  r  r@   rj   r   r  rz  )ro   r  r  rb  r  r  re_flagsregobjr{  has_unicoder  pos1pos2rv  r  s                  rt   highlight_found_resultsz"CodeEditor.highlight_found_results
  s    	
 !)iiw 78G)-)g%7d..01#'2<<R]]R\\-I	ZZx8F $i>$#77__T* 	/E[[/
d"ZZ\
d&t'89I**4+C+CD((.$$**,E>>#!!-"56%%e,(({/E/EF##I.!	/" 	!!&*:;- "" 		s   H H*)H*c                 h    g | _         | j                  d       | j                  j                          y)z Clear found results highlightingr`  N)r  r  r  r]  r  s    rt   clear_found_resultszCodeEditor.clear_found_results
  s*    ##F+##%rv   c                     | j                         j                         | _        | j                  D ]  } | j                  di | j
                    y y)z=Text has changed, eventually clear found results highlightingNr   )r  r  r;  r  r  r  )ro   results     rt   __text_has_changedzCodeEditor.__text_has_changed
  sM    $(OO$5$>$>$@! (( 	F(D((<4+;+;<	rv   c                 6    | j                   j                         S )z
        Return current line number area width.

        This method is left for backward compatibility (BaseEditMixin
        define it), any changes should be in LineNumberArea class.
        )r   	get_widthr  s    rt   get_linenumberarea_widthz#CodeEditor.get_linenumberarea_width
  s     "",,..rv   c                 R   |j                  |j                         | j                  j                  t        j
                  j                        z          |j                  |j                         | j                  j                  t        j
                  j                        z          |S z7Add offset to a point, to take into account the panels.
setXxr   margin_sizer(   r   LEFTsetYyr   rt  s     rt   calculate_real_positionz"CodeEditor.calculate_real_position
  g    

5779t{{66u~~7J7JKKL

5779t{{66u~~7I7IJJKrv   c                 R   |j                  |j                         | j                  j                  t        j
                  j                        z
         |j                  |j                         | j                  j                  t        j
                  j                        z          |S r  r  rt  s     rt   #calculate_real_position_from_globalz.CodeEditor.calculate_real_position_from_global
  r  rv   c                 Z   | j                         }|j                         }| j                  |      j                  | j	                               j                         }|| j                  |      j                         z   }|j                         r||j                         j                         k  r{|j                         }|j                         r$|}|| j                  |      j                         z   }|dz  }|j                         r"||j                         j                         k  r{|S )z#Return line number from mouse eventrh  )firstVisibleBlockr  blockBoundingGeometry
translatedcontentOffsettopblockBoundingRectheightr  r  r  r  r  )ro   r  r  line_numberr  bottoms         rt   get_linenumber_from_mouse_eventz*CodeEditor.get_linenumber_from_mouse_event
  s    &&('')((/::484F4F4HJJM#% 	t--e4;;==mmo#		"7JJLE t55e<CCEE1K mmo#		"7 rv   c                    | j                         j                  }||z
  }|} ||dz
        }| j                         }|j                  |j	                                |dkD  rCt        t        |      dz         D ](  }|j                  |j                  |j                         * n]|j                  |j                         t        t        |      dz         D ](  }|j                  |j                  |j                         * || j                         k(  r'|j                  |j                  |j                         n&|j                  |j                  |j                         | j                  |       y)z9Select line(s) after a mouse press/mouse press drag eventrh  r   N)r  r  r  r  r  r  absr  r=  r  rB  r  r9  r  r  )	ro   linenumber_pressedlinenumber_releasedfind_block_by_numbermove_n_blocksr{  start_blockr  ns	            rt   select_lineszCodeEditor.select_lines  sD   #}}@@,/AA'
*:>:";//12 13}-12 I##F$4$4f6G6GHI  0 013}-12 M##F$8$8&:K:KLM $//"33 1 163D3DE 3 3V5F5FG6"rv   c                    || j                         \  }}| j                         j                  |      }|j                         }|st	        |       }||j
                  vr|j
                  j                  ||f       |j                  |       || j                  t        |      <   | j                  j                          y)z)Add bookmark to current block's userData.N)r:  r  r  r  r@   r4  rj   r  r3  r   sig_bookmarks_changedr]  )ro   slot_numr  r  r  r  s         rt   add_bookmarkzCodeEditor.add_bookmark  s    <668LD&11$7~~ &D4>>)NN!!8V"45$,1r%y)""'')rv   c                    i }i }| j                   D ]r  }| j                   |   }|j                         s#|j                         }|s6|j                  sC|||<   |j	                         }|j                  D ]  \  }}||g||<    t || _         |S )z'Get bookmarks by going over all blocks.)r3  r  r  r4  r  )	ro   r4  pruned_bookmarks_blocksblock_idr  r  r  r  r  s	            rt   get_bookmarkszCodeEditor.get_bookmarks.  s    	"$.. 	DH**84E}}~~'DNN8=+H5"'"3"3"5K,0NN D(&/:F.C	(+D	D "9rv   c                 X    i | _         | j                         D ]	  }g |_          i | _        y)zClear bookmarks for all blocks.N)r4  r  r3  r  s     rt   clear_bookmarkszCodeEditor.clear_bookmarks>  s0    ++- 	 DDN	 !#rv   c                     | j                          |j                         D ]  \  }}| j                  ||d   |d            y)z Set bookmarks when opening file.rh     N)r  r  r  )ro   r4  r  bookmarks       rt   set_bookmarkszCodeEditor.set_bookmarksE  sE    "+//"3 	BHhhXa[A	Brv   c                 8    | j                   j                          y)z Emit signal to update bookmarks.N)r  r]  r  s    rt   r	  zCodeEditor.update_bookmarksK  s    ""'')rv   c                 B    d}| j                   j                  |||       y)z*Trigger show completion info in Help Pane.TN)sig_show_completion_object_infor]  )ro   r  rD  r  s       rt   r   z&CodeEditor.show_completion_object_infoQ  s    ,,11$	5Irv   c                 :    | j                   j                  d       y)zTrigger a calltipTN)sig_show_object_infor]  r  s    rt   r   zCodeEditor.show_object_infoV  s     	!!&&t,rv   c                    || _         | j                         j                         }|j                  |j	                         t
        j                  z         | j                   r1|j                  |j	                         t
        j                  z         n1|j                  |j	                         t
        j                   z         | j                         j                  |       | j                          y)zToggle blanks visibilityN)
r   r  defaultTextOptionsetFlagsra  r   %AddSpaceForLineAndParagraphSeparatorsShowTabsAndSpacessetDefaultTextOptionr  )ro   r  options      rt   r&  zCodeEditor.set_blanks_enabled]  s    #224#IIJ 	KOOFLLN[-J-JJKOOFLLNk.K.K-KKL,,V4rv   c                 r    || _         | j                  |       | j                  | j                                y)zv
        Allow user to scroll past the end of the document to have the last
        line on top of the screen
        N)r   setCenterOnScrollr  r  r  s     rt   r*  z$CodeEditor.set_scrollpastend_enabledk  s.    
 &+"u%)rv   c                 d    t        j                  | |       | j                  j                          y)z,Reimplemented Qt method to handle p resizingN)rL   resizeEventr   resizer  s     rt   r  zCodeEditor.resizeEventt  s"    &&tU3rv   c                 `    t         t        |   |       | j                  j	                          y)z3Overrides showEvent to update the viewport margins.N)superr|   	showEventr   r   ro   r  	__class__s     rt   r  zCodeEditor.showEventy  s"    j$)%0rv   c                    | j                   }|H| j                  |j                         |j                                |j	                         | _        |j                         | _        |j                         | _	        |j                         | _        |j                         | _        |j                         | _        |j                         | _        |j#                         | _        |j'                         | _        | j*                  j-                          | j.                  j-                          | j0                  j3                  d| j                  i       yy)z8Apply color scheme from syntax highlighter to the editorN)r   
foreground
occurrence)r   set_paletteget_background_colorget_foreground_colorget_currentline_colorcurrentline_colorget_currentcell_colorcurrentcell_colorget_occurrence_colorr   get_ctrlclick_colorr   get_sideareas_colorr   get_comment_colorr   r   get_matched_p_colorr   get_unmatched_p_colorr   r   update_colorr   sig_theme_colors_changedr]  )ro   hls     rt   r  z*CodeEditor._apply_highlighter_color_scheme  s   >(?(?(A(*(?(?(A  C%'%=%=%?D"%'%=%=%?D"$&$;$;$=D!$&$:$:$<D!#%#9#9#;D !#!5!5!7D " 7 7 9D#%#9#9#;D %'%=%=%?D"NN'')++-))..t4457! rv   c                     | j                   X| j                   j                  | j                                || j                  |       y| j                  j                          yy)z!Apply syntax highlighter settingsN)r   setup_formatsrA  r<  ri  rn   ro   r   s     rt   apply_highlighter_settingsz%CodeEditor.apply_highlighter_settings  sS    '**499;7'%%l3''--/ (rv   c                     ||| _         | j                  |       | j                  j                          | j	                  |       y)zSet fontN)r   r:  r   r   r  )ro   rA  r   s      rt   r;  zCodeEditor.set_font  s<    
 # ,DT''5rv   c                 4   || _         | j                  +| j                  j                  |       | j                          | j                  r| j                          n| j                          | j                  r| j                          y| j                          y)z(Set color scheme for syntax highlightingN)
r   r   r<  r  r  rG  r  r   rF  r  r  s     rt   r<  zCodeEditor.set_color_scheme  sx    ('--l;002..'')))+..'')))+rv   c                     | j                  |       | j                  |       t        | j                  t        j
                        r&t               s| j                  j                          yyy)zSet the text of the editor)r  N)setPlainTextset_eol_charsr  r   r   r  r+   make_charlist)ro   r  s     rt   set_textzCodeEditor.set_text  sW    $%t''7,.**, / 8rv   c                     || _         t        j                  |      \  }}|t        ||      }| j	                  ||       | j                  |       y)z,Set the text of the editor from file *fname*N)rA  rR   readrA   r+  r  )ro   rA  r  r  _encs        rt   set_text_from_filezCodeEditor.set_text_from_file  sI     ]]8,
d(48H(H-drv   c                     | j                         }|j                  t        j                         |j	                  |       y)z)Append text to the end of the text widgetN)r  r  r   r  r  )ro   r  r  s      rt   rj   zCodeEditor.append  s.    "KOO,$rv   c                     |dk(  s|dk(  r|S | j                   dk7  }|dkD  r)|rd|z  |z   S | j                   || j                  z  z  |z   S | j                  |      }t        ||       }|r|n|| j                  z  }||d S )zAdjust indentation.r   r   r  r  N)r#  rO  get_line_indentationmin)ro   r  indent_adjustmentrx  
max_indents        rt   adjust_indentationzCodeEditor.adjust_indentation  s    !TRZK((D0q ..55 %%(D,F,FFH
 ..t4

->,>?2>..$2L2LL 	 %&''rv   c                    t        j                         }t        |j                               }|j	                         j                         r|j	                         j                         }t        |D cg c]  }|j                          c}      rwt        |      dkD  r,d| j                         z   }|j                  d |D              }n=|r;|d   j                         j                  t        j                  j                   d      }| j                         }t        |j#                               dkD  r"|j                  ||z   j#                               }| j%                         }|j'                          |j)                          |j+                  |j-                                |j+                  |j/                         j1                         t2        j4                         |j7                         }||z   j#                         ^}	}
||	z   }d}| j9                         rt        |j;                               dk(  rt        |j;                               dkD  ro| j=                         }|r]t?        || jA                  |	      | jA                  |            }|| jA                  |      z
  }tC        |d      }| jE                  ||      }t        |
      dkD  rt        |j;                               dkD  r|}|tG        jH                  |      z  }|
D cg c]&  }|j;                         dk7  r| jA                  |      ( }}|rtC        |      }t?        ||       }|
D cg c]  }| jE                  ||       }
}|j                  |g|
      }d| _%        | jL                  jO                  |       |j)                          |jQ                  |       |jS                          | jT                  jO                          d| _%        y	c c}w c c}w c c}w )
a  
        Insert text or file/folder path copied from clipboard.

        Reimplement QPlainTextEdit's method to fix the following issue:
        on Windows, pasted text has only 'LF' EOL chars even if the original
        text has 'CRLF' EOL chars.
        The function also changes the clipboard data if they are copied as
        files/folders but does not change normal text data except if they are
        multiple lines. Since we are changing clipboard data we cannot use
        paste, which directly pastes from clipboard instead we use
        insertPlainText and pass the formatted/changed text without modifying
        clipboard content.
        rh  ,c              3      K   | ]B  }d |j                         j                  t        j                  j                  d      z   d z    D yw)"/N)toLocalFilerH  r  ossep)r  r  s     rt   r  z#CodeEditor.paste.<locals>.<genexpr>  sE      *A47 +.0A*1'#&&**c*B+C,/+0 *As   AA
r   r  r   TFN)+r!   	clipboardrO   r  mimeDatahasUrlsurlsr  isLocalFiler%  r  r  r  rH  r  r  r  r  r  r  r;  r  r  r  r  r   r  r`  r?  r-  find_indentationr  r  r  r  rT   remaining_lines_adjustmentr>  sig_will_paste_textr]  r  r  sig_text_was_inserted)ro   r  r  r  r  	sep_charsr  r  preceding_textfirst_line_selectedremaining_lines
first_linefirst_line_adjustmentdesired_indentlines_adjustmentr  indentations
max_dedents                     rt   r  zCodeEditor.paste  s    !**,	inn./'') %%',,.D6#COO%67t9q= #d&=&=&? ?I$>> *A;?*A AD #Aw224<<SVVZZM++-	t !A%>>4)#3"?"?"ABD "!!#600236<<>224&11	3,,.15	1A0M0M0O-o#&99
 ! !c.*>*>*@&AQ&F
((*+a/!224N "%"--.AB--n="?
 #T%>%>z%JJ & ),,A1(E%!44 57
 !#J,<,<,>(?!(C4 0 K K!    ,Ctzz|r/A ))$/CL C  .
#&'7*#E  ,- ''.>?-O - ~~z<O<=  %%d+!!#$""'') ] 7tC-s   3O;+P Pc                 :   | j                         }|j                  |j                                |j                  |j                         j	                         t
        j                         |j                         }t        j                  || j                         y)zx
        Save the indentation corresponding to the clipboard data.

        Must be called right after copying.
        N)r  r  r  r  r  r   r  r`  rT   save_indentationrO  )ro   r  r  s      rt   _save_clipboard_indentationz&CodeEditor._save_clipboard_indentationP  sv     "600236<<>224&11	3,,.))D66	8rv   c                    | j                         }|sy| j                         \  }}| j                  j                  ||       t	        j
                  |        | j                          | j                  j                          y)z>Reimplement cut to signal listeners about changes on the text.N)rj  rz  sig_will_remove_selectionr]  rL   r  r$  r  )ro   rj  rn   r  s       rt   r  zCodeEditor.cut^  sm     !224 113
s&&++E37t$((*""'')rv   c                 N    t        j                  |        | j                          y)z%Reimplement copy to save indentation.N)rL   r  r$  r  s    rt   r  zCodeEditor.copyj  s     	%((*rv   c                 6   | j                         j                         r{| xj                  dz  c_        d| _        d| _        t        j                  |        | j                  j                          | j                  j                          d| _        d| _        yy)z1Reimplement undo to decrease text version number.rh  TFN)
r  isUndoAvailablerB  r>  rg  rL   r  sig_undor]  r  r  s    rt   r  zCodeEditor.undop  z     ==?**,"#D"DO##D)MM &&++-#DO$D -rv   c                 6   | j                         j                         r{| xj                  dz  c_        d| _        d| _        t        j                  |        | j                  j                          | j                  j                          d| _        d| _        yy)z1Reimplement redo to increase text version number.rh  TFN)
r  isRedoAvailablerB  r>  rh  rL   r  sig_redor]  r  r  s    rt   r  zCodeEditor.redo}  r+  rv   c                 n    | j                          | j                  j                  | j                         y)zAQPlainTextEdit's "centerCursor" requires the widget to be visibleN)r  focus_inr  center_cursor_on_next_focusr  s    rt   r1  z&CodeEditor.center_cursor_on_next_focus  s(     	  !A!ABrv   c                 D    | j                   j                  |||d|       y)z4Go to line number *line* and eventually highlight itT)r  
end_columnmover  N)r   	goto_line)ro   r  start_columnr3  r  s        rt   re  zCodeEditor.go_to_line  s'    ""4.8t(, 	# 	.rv   c                 z    t        |       }|j                         r | j                  |j                                yy)z%Execute the GoToLineDialog dialog boxN)rK   exec_re  get_line_number)ro   dlgs     rt   exec_gotolinedialogzCodeEditor.exec_gotolinedialog  s/    T"99;OOC//12 rv   c                     | j                   j                          d| _        | j                  d       | j                  j                         r| j                  j                          yy)a&  
        Hide the tooltip widget.

        The tooltip widget is a special QLabel that looks like a tooltip,
        this method is here so it can be hidden as necessary. For example,
        when the user leaves the Linenumber area when hovering over lint
        warnings and errors.
        Nr  )r   r  r   r  r   r  hider  s    rt   r  zCodeEditor.hide_tooltip  sV     	  %%' $##$=>((*$$& +rv   c                 F    d| _         | j                  j                          y r  )r   r   trigger_completion_hintr  s    rt   r   z%CodeEditor._set_completions_hint_idle  s    &*#668rv   c                 0   | j                   rz| j                  rn|j                  dd      }||d}|rUt        |      dkD  rG| j	                  ||||| j
                  | j                         | j                  j                  |       y| j                          y)z!Show hint for completion element.rA  r  )r  rD  r   )rX  r  completion_doc	max_lines	max_widthN)
r%  r   rH  r%  rT  _DEFAULT_MAX_LINES"_DEFAULT_COMPLETION_HINT_MAX_WIDTHr   r4  r  )ro   r  r@  r  rA  s        rt   r   z#CodeEditor.show_hint_for_completion  s      T%@%@)11'3?M&*+8:N ]!3a!7!!%%#1"55"EE  G ##((2rv   c                 p    | j                   r| j                          | j                  j                          y)z8Update decorations on the visible portion of the screen.N)r   rJ  decorationsr  r  s    rt   r  zCodeEditor.update_decorations  s+    ((!!#
 	!rv   c           
         t         j                  dt         j                  dt         j                  dt         j                  di}|j
                  }| j                         }|j                         }d}g }d}	t        |d       }
|
D ]  \  }}}}|d	k(  rd
|v rd|v r|j                  d      d   }|j                         }t        |      dkD  r|d   j                         |dd z   }|j                  dd      j                  dd      }|j                         }g }d}d}|D ]  }t        j                   || j"                        }|dkD  s*t        |      dkD  r"dj%                  |dd       dz   }|dz  }|dz  }ndj%                  |      }|dz  }|j'                  |        t        |      dkD  r/|dk7  rd}|	|dz  z  }	nd}|	|z  }	dj%                  |d|       dz   }ndj%                  |      }t)        j*                  ||   ||      }|	dk\  s|j'                  |j-                  |||||              |rN| j/                  t1        d      dj%                  |      t2        j4                  |d       | j7                  |       yy) zShow warning/error messages.rk  warninginformationhintz]<img src="data:image/png;base64, {}" height="{size}" width="{size}" />&nbsp;{} <i>({} {})</i>   c                     | d   S )Nr  r   )r  s    rt   r   z7CodeEditor.show_code_analysis_results.<locals>.<lambda>  s
    1Q4 rv   r  pylint[]r  rh  r   N<z&lt;>z&gt;   )widthr  z<br>z...r      )sizezCode analysisr  T)titler  title_colorat_linewith_html_format)r6   r  WARNINGINFORMATIONHINTr  fontMetricsr  r  r0  r-  r%  upperrH  r  textwraprB  _DEFAULT_MAX_HINT_WIDTHr  rj   rU   base64_from_iconr  r  r)   rX   COLOR_ACCENT_4highlight_line_warning)ro   r  
block_dataiconsr  fmrV  templatemsglistmax_lines_msglistsorted_code_analysissrcr  sevmsg
paragraphsnew_paragraphslong_paragraphslines_per_message	paragraphnew_paragraphrB  base_64s                          rt   show_code_analysis_resultsz%CodeEditor.show_code_analysis_results  s    $$g&&	**M##V	
 #00 yy{  	 %mH#7 1	ACsCh3#:#*iinR())+C 3x!|!fllns12w. ++c6*223?C)JNO !' 9	 (66!8 %q(=)A-(.M"14E(F(N'1,)Q.)(.M(B)Q.)"))-89 >"Q& #a' !I%Q6% !I%2%kk.)"<=Fkk.1**5:tTBG A%xwS/3$  /  @ Aa1	Af (YYw')88#!%   ''
3 rv   c                     | j                  d       | j                  d|j                         |j                         | j                  j                          y)z-Highlight errors and warnings in this editor.r  )rs  N)r  r  r  r  r   r  )ro   re  s     rt   rd  z!CodeEditor.highlight_line_warning#  sQ    ##$=>  !:!+!6!6!82<2B2B 	! 	D 	""$rv   c                    | j                         j                         }| j                         j                         }g }	 |j                         }|rD|j                  r8|j                  D ])  }|j                  |d   |j                         dz   g       + |j                         dz   |k(  r	 |S |j                         })zu
        Get all warnings for the current editor and return
        a list with the message and line number.
        r  rh  )r  r  r  r  r  rj   r  r  )ro   r  
line_countwarningsr  rI  s         rt   get_current_warningszCodeEditor.get_current_warnings+  s    
 **,]]_//1
>>#D**#11 LGOOWR[%2C2C2E2I$JKL   "Q&*4 JJLE rv   c                    | j                         j                         }| j                         j                         }t	        |      D ]  }|j                         dz   }||k  r|j                         }n| j                         j                         }|j                         }|s]|j                  sj|j                         dz   }| j                  |       | j                  ||       | j                  d      c S  y)zQ
        Go to next code warning message and return new cursor position.
        rh  r  N)r  r  r  r  r  r  r  r  r  r  re  rv  r;  ro   r  ry  __r  r  s         rt   go_to_next_warningzCodeEditor.go_to_next_warning>  s     !'')]]_//1

# 	3B++-1KZ'

224>>#D**#//1A5,//TB((22	3rv   c                    | j                         j                         }| j                         j                         }t	        |      D ]  }|j                         dz   }|dkD  r|j                         }n| j                         j                         }|j                         }|s]|j                  sj|j                         dz   }| j                  |       | j                  ||       | j                  d      c S  y)zU
        Go to previous code warning message and return new cursor position.
        rh  r  N)r  r  r  r  r  r  previous	lastBlockr  r  re  rv  r;  r}  s         rt   go_to_previous_warningz!CodeEditor.go_to_previous_warningR  s     !'')]]_//1

# 	3B++-1KQ(113>>#D**#//1A5,//TB((22	3rv   c              #   z   K   | j                         D ]$  }|j                  t        j                  k(  s!| & yw)z,Get the outline explorer data for all cells.N)r  r  OEDr  )ro   r  s     rt   	cell_listzCodeEditor.cell_listf  s3     446 	F#((*	s   1;;c                    d}t        |      r3| j                         D ]  }|j                  |k(  s|j                  } n_ n]|dk(  r| j	                         j                         }n9t        | j                               }|t        |      k  r||dz
     j                  }|s#t        dj                  t        |                  t        |      }| j                  |      \  }}|S )zi
        Get cell code for a given cell.

        If the cell doesn't exist, raises an exception
        Nr   rh  zCell {} not found.)rP   r  def_namer  r  r  r  r%  r  r  reprr   get_cell_as_executable_code)ro   cellselected_blockr  r  r  	cell_coder)   s           rt   get_cell_codezCodeEditor.get_cell_codel  s     T?..* ??d*%+\\N
 qy!%!;!;!= !12	3y>)%.tax%8%>%>N3::4:FGG^,77?	1rv   c                 L    dt        t        | j                                     z   S )z Get number of cells in document.rh  )r%  r  r  r  s    rt   get_cell_countzCodeEditor.get_cell_count  s    3tDNN,-...rv   c                    | j                         j                         }| j                         j                         }	 |j	                         dz   |k  r|j                         }n| j                         j                         }|j                         }|r|j                  rne|j	                         dz   }| j                  |       | j                  t        d      |j                  t        j                  |       | j                  d      S )z.Go to next todo and return new cursor positionrh  zTo do)rW  r  rX  rY  r  )r  r  r  r  r  r  r  r  todore  r  r)   rX   rc  r;  )ro   r  ry  r  r  s        rt   go_to_next_todozCodeEditor.go_to_next_todo  s    !'')]]_//1
  "1$z1

224>>#D		  '')!+$G*%44	 	 	
   **rv   c                 2   | j                         D ]	  }d|_         |D ]\  \  }}| j                         j                  |dz
        }|j	                         }|st        |       }||_        |j                  |       ^ | j                  j                          y)zProcess todo finder resultsr   rh  N)	r  r  r  r  r  r@   r  r  r]  )ro   todo_resultsr  rl  r  r  s         rt   process_todozCodeEditor.process_todo  s    ++- 	DDI	 %1 	$ G[MMO55kAoFE>>#D$T*DId#	$ 	##%rv   c                    | j                         }| j                         rF|j                         |j                         }}t	        ||g      }| j                         }|j                  |       |j                          |j                  |       |j                         rC|j                  t        j                         |j                         |k  r|j                  |       | j                         }|j                         |k\  rO|j                  t        j                         t        |j                         j!                               }| j#                  |j                               dk(  rd|v r|j%                         r|j'                  d      sF|dk7  rA|j                  t        j(                  t        j*                  |       |j-                  |       nd|vr|j-                  |       |j/                         dk(  rnS|j                  t        j                         |j                  t        j0                         |j                         |k\  rO|j3                          y|j                          |j                  t        j                         | j#                  |j                               dk(  r#d|v r|j                  t        j4                         |j-                  |       |j3                          y)z.Add prefix to current line or selected line(s)r  r~   r   r   N)r  rj  r  r  r  r  r  atBlockStartr  r   rB  r  _CodeEditor__spaces_for_prefixr  rO   r  r  get_characterisspace
startswithr  
MoveAnchorr  r  r9  r  r  )	ro   r$  r  r  r  	first_posfirst_cursormove_numberr  s	            rt   
add_prefixzCodeEditor.add_prefix  sW   "!!#!'!6!6!8&:M:M:OwI Y01I??,L$$Y/!!#w' ""$##K$=$=>??$y0&&y1224K//#y0##K$<$<=*6<<>+>+>+@A	&&v'89S@6M)2C2C2E ) 4 4S 9 )R''(9(9(3(>(>(35 %%f-&%%f-%%'1,##K$=$=>##K$:$:;# //#y0$ ! !!# 8 89!!&//"34;v##K$8$89f%!rv   c                    | j                         }| j                         r|j                         |j                         }}t	        ||g      }| j                         }|j                  |       |j                          |j                  |       |j                         rC|j                  t        j                         |j                         |k  r|j                  |       d}|j                         |k\  r|j                  t        j                         t        |j                         j                               }|j!                  d      }| j#                  |      }	|sd}	|dk(  s||	kD  r|j%                         s|dk7  r|	}|j'                         dk(  rnR|j                  t        j                         |j                  t        j(                         |j                         |k\  r|j+                          S )z%Find the less indented level of text.r  r  r   r   )r  rj  r  r  r  r  r  r  r  r   rB  r  r  rO   r  r  r  _CodeEditor__number_of_spacesr  r  r9  r  )
ro   r  r  r  r  r  number_spacesr  start_with_spaceleft_number_spacess
             rt   __spaces_for_prefixzCodeEditor.__spaces_for_prefix  s   "!!#!'!6!6!8&:M:M:OwI Y01I??,L$$Y/!!#w' ""$##K$=$=>??$y0&&y1M//#y0##K$<$<=*6<<>+>+>+@A	#,#7#7#< %)%<%<Y%G"')*&"b((+== ) 1 1 3	R$6M%%'1,##K$=$=>##K$:$:; //#y0  !rv   c                     | j                         }|j                  |j                         t        |      z
  t        j
                         t        |j                               |k(  r|j                          yy)zU
        Remove suffix from current line (there should not be any selection)
        N)	r  r  r  r`   r   r  rO   r`  r;  )ro   suffixr  s      rt   remove_suffixzCodeEditor.remove_suffix  sa     "6??,~f/EE&11	3&--/0F:%%' ;rv   c                 l   | j                         }| j                         rt        |j                         |j	                         g      \  }}|j                  |       |j                         s/|j                  t        j                         |j                         }|j                          |j                  |       |j                         rC|j                  t        j                         |j                         |k  r|j                  |       |j                  t        j                         d}|j                         |k\  r|j                         }||k(  rno|}t        |j                         j                               }| j!                  |||       |j                  t        j                         |j                         |k\  r|j#                          y|j                  t        j                         t        |j                         j                               }| j!                  |||       y)z3Remove prefix from current line or selected line(s)N)r  rj  r  r  r  r  r  r  r   r  r  r  rB  rO   r  r  _CodeEditor__remove_prefixr  )ro   r$  r  r  r  old_posnew_posr  s           rt   remove_prefixzCodeEditor.remove_prefix  s   "!!#!')>)>)@)/)<)<)>)@ "AIwy)&&(##K$<$<="OO-	!!#w' ""$##K$=$=>??$y0&&y1 8 89G//#y0 //+g%%G*6<<>+>+>+@A	$$VVY?##K$=$=> //#y0 !  8 89&v||~':':'<=I  ;rv   c                    |j                  d      }|r| j                  |      }nd}|r| j                  |d      }n| j                  |      }|j                         r"|j	                         j                  |dz         s|j                  |dz         rd|v r|j                  t        j                  t        j                  |j                  |             |dk(  r|s|r|s|dz  dk7  s
|rD|dz  dk7  r<|j                  t        j                  t        j                  t        |dz                n8|j                  t        j                  t        j                  t        |             |j                          y|j                         r|j	                         j                  |      s|j                  |      r|j                  t        j                  t        j                  |j                  |             |j                  t        j                  t        j                  t        |             |j                          yy)	z3Handle the removal of the prefix for a single line.r  Frh  )r  r~   r  r   N)r  "_CodeEditor__even_number_of_spacesr  r-  lstripr  r   r  r  r`  r  r%  r;  )ro   r$  r  r  r  left_spacesright_number_spacess          rt   __remove_prefixzCodeEditor.__remove_prefix?  s   $//466yAKK"&"9"9)1"9"M"&"9"9)"DLLNy//1<<Vc\J''5#- 1 1 + 6 6 )v 68 $q($,<,1Dq1HA1M#(;a(?1(D ##K$5$5$/$:$:C<MO ##K$5$5$/$:$:CKI%%'lln!1!1!3!>!>v!F''/ 1 1 + 6 6 )v 68  1 1 + 6 6FE%%' 0rv   c                     t        j                  d|      }t        |      dz
  |k\  r't        ||         t        | j                        z  dk(  S y)zY
        Get if there is a correct indentation from a group of spaces of a line.
        \s+rh  r   N)r  findallr%  r#  ro   r  r  spacess       rt   __even_number_of_spacesz"CodeEditor.__even_number_of_spacesg  sM     FI.v;?e#ve}%D,=,=(>>!CC $rv   c                 n    t        j                  d|      }t        |      dz
  |k\  rt        ||         S y)z:Get the number of spaces from a group of spaces in a line.r  rh  N)r  r  r%  r  s       rt   __number_of_spaceszCodeEditor.__number_of_spaceso  s6    FI.v;?e#ve}%% $rv   c                    g }g }d}d}d}d\  }}	t        |      D ]  \  }}	|rd}|r|	|k(  rd}|	dk(  sd}|	dv r|	}%|	dk(  r|} nU|	d	v r|j                  ||	f       F|	d
v sK|r#|d   d   dddd
|	   k(  r|j                          p|j                  |	        ~~~|sGt        |      D ]9  }	|r4|d   d   dddd
|	   k(  r"|j                          |j	                  |	       9 n ~	||z   }|||fS )a  
        Return unmatched opening brackets and left-over closing brackets.

        (str, []) -> ([(pos, bracket)], [bracket], comment_pos)

        Iterate through line_text to find unmatched brackets.

        Returns three objects as a tuple:
        1) bracket_stack:
            a list of tuples of pos and char of each unmatched opening bracket
        2) closing brackets:
            this line's unmatched closing brackets + arg closing_brackets.
            If this line ad no closing brackets, arg closing_brackets might
            be matched with previously unmatched opening brackets in this line.
        3) Pos at which a # comment begins. -1 if it doesn't.'
        r  NFNN\T)'r
  r~   rx  rO  {ry  rP  }rh  rx  rO  r  )r  rj   r  r  remove)
ro   r  closing_bracketsbracket_stackbracket_unmatched_closingcomment_pos
deactivateescapedr  r   s
             rt   __get_bracketszCodeEditor.__get_bracketsu  s`   $  %'!
Q	* 	8FC
?!%J$Y"Gj
c!o%$$c1X.o% ]2%6q%9!#6q9&:!%%'-44Q71	82 W )*+  ]2%6q%9!#6q9&:!%%'$++A. 47GG/==rv   c                 r    | j                         r | j                  |i |}|S  | j                  |i |}|S )z(Indent line according to the preferences)r?  fix_indent_smartsimple_indentation)ro   rp   rq   rets       rt   
fix_indentzCodeEditor.fix_indent  sJ     '$''88C 
 *$))4:6:C
rv   c                 X   | j                         }|j                         }| j                         j                  |dz
        }t	        |j                               }t        j                  d|      j                         }|s|t        | j                        d }|j                  |       y)zM
        Simply preserve the indentation-level of the previous line.
        rh  z\s*NF)r  r  r  r  rO   r  r  r  r  r%  r#  r  )ro   forwardrq   r  r  
prev_blockprevlineindentations           rt   r  zCodeEditor.simple_indentation  s     "%%']]_66x!|D
!*//"34hhvx0668%c$*;*;&<&=>K+&rv   c                 l   | j                         }|j                         }d}d}d}d}	d}
d}g }t        |dz
  dd      D ]  }	|j                  t        j
                         t        |j                         j                               j                         }
| j                  |
|      \  }}}|
sp|
j                  d      rd}|s|s n|
j                         dk7  sd} |r|	|	|d	z
  k  r	d}
|d	z
  }	d}t        j                  d
|
j                               }|r|dz  }|
r|srh|
j                  d      rT|dz  }|d   dv r|dz  }n[| j                   dk(  r| j"                  nt%        | j                         d	z  t%        |
      k  sd}nd}n|d   dv s
|d   dk(  r|s|dz  }|	r| j'                  |	      }nd}|rd   d   dz   }nB|r>| j                   dk(  r|| j"                  |z  z   }n|t%        | j                         |z  z   }n|}|	rs|
j                  d      s|r|dz
  }n|	}|| j'                  |      }| j)                  |      j                          }| j)                  |      j                         }||k  r4|s|r0| t%        | j                         z   t%        | j                         z  }|S )a  
        Find indentation (Python only, no text selection)

        forward=True: fix indent only if text is not enough indented
                      (otherwise force indent)
        forward=False: fix indent only if text is too much indented
                       (otherwise force unindent)

        comment_or_string: Do not adjust indent level for
            unmatched opening brackets and keywords

        max_blank_lines: maximum number of blank lines to search before giving
            up

        cur_indent: current indent. This is the indent before we started
            processing. E.g. when returning, indent before rstrip.

        Returns the indentation for the current line

        Assumes self.is_python_like() to return True
        Fr   Nr   Trh  r  ):r  r  z[\s\(\[\{\}\]\)]r  )classdefelifexceptforifwhilewithr  )continuebreakpassreturnr  )r  r  r  r  r   rB  rO   r  r  r:  _CodeEditor__get_bracketsr.  r-  r  r0  r  r#  rO  r%  get_block_indentationrA  )ro   r  comment_or_string
cur_indentr  r  line_in_blockvisual_indent
add_indentr  prevtextempty_linesr  r  r  wordsprevline_indentcorrect_indentref_lineis_blanktrailing_texts                        rt   r  zCodeEditor.find_indentation  s   . "%%'
hlB3 	$H 9 9:%flln&9&9&;<CCEH;?;N;N*<,8M+[   - $ $4~~2%#)	$, 8/Hx!|4KH!|H!M ,hoo.?@!OJ-$$_5!OJQx $; ;"a
 $(#4#4#< !% : : #D$5$5 6 !	" %(M	2
 )- %)M)==1X)-a
"88BOO*2.q1A5N  D(!043M3MPZ3Z!Z!03t7H7H3IJ3V!V,N M(2C2CC2H#a< $!!77A
--h7==??H ..x8>>@M O+( %/;#d6G6G2H#H!I))*"+rv   c                 p   | j                         }|j                         }| j                  |      }| j                  |||      }|dk\  r||k(  s|r||kD  s|s||k  s| j                         }|j	                  t
        j                         | j                  dk(  r|| j                  z  }|j                  |j                         |z   t
        j                         |j                          | j                  dk(  r&d|| j                  z  z  d|| j                  z  z  z   }nd|z  }|j                  |       yy)a  
        Fix indentation (Python only, no text selection)

        forward=True: fix indent only if text is not enough indented
                      (otherwise force indent)
        forward=False: fix indent only if text is too much indented
                       (otherwise force unindent)

        comment_or_string: Do not adjust indent level for
            unmatched opening brackets and keywords

        max_blank_lines: maximum number of blank lines to search before giving
            up

        cur_indent: current indent. This is the indent before we started
            processing. E.g. when returning, indent before rstrip.

        Returns True if indent needed to be fixed

        Assumes self.is_python_like() to return True
        r   r  r  TF)r  r  r  r  r  r   r  r#  rO  r  r  r  r;  r  )	ro   r  r  r  r  r  r  r  indent_texts	            rt   r  zCodeEditor.fix_indent_smartQ  s9   . "%%'++H5..&
4 Q.(F^3 7 __&F 8 89  D(4#=#==v079O9OP%%'  D(Nd.H.HHI>D,F,FFGH 
 ".0k*rv   c           	         	 t        j                  | j                         d      }|j                  r$|j                  D ]  }d|v rg |d<   d|v sd|d<    | j	                          d| _        | j                  t        j                  |             d| _        y# t        $ r?}t        j                  | t        d      t        d	      t        |      z          Y d}~yd}~ww xY w)
z2Removes all output in the ipynb format (Json only)   
as_versionoutputsprompt_numberNTFzRemoval errorzIIt was not possible to remove outputs from this notebook. The error is:

)nbformatreadsr  cellsr  r>  rJ  writesr  r#   criticalr)   rO   )ro   nbr  es       rt   clear_all_outputzCodeEditor.clear_all_output  s    	 0 0 2qABxxHH 5D D(*,Y&$.04_-	5 NN#D  !45$D 	  q'9 @ A+A./0 	s   AB A	B 	C"#5CC"c           	      T   	 t        j                  | j                         d      }t               j	                  |      d   }| j                  j                  |       y# t
        $ r?}t        j                  | t        d      t        d      t        |      z          Y d}~yd}~ww xY w)z8Convert an IPython notebook to a Python script in editorr  r  r   zConversion errorz=It was not possible to convert this notebook. The error is:

N)r  r  r  
nbexporterfrom_notebook_noder  r#   r  r)   rO   sig_new_filer]  )ro   r  scriptr  s       rt   convert_notebookzCodeEditor.convert_notebook  s    	 0 0 2qAB\44R8;F 	v&  	  q);'<!" $? "@!/!2"34 	s   AA 	B'(5B""B'c                 b   | j                  dd      }| j                         r| j                  | j                         y|s(|j	                         r| j
                  rg| j                  r[| j                         r.| j                  d      s8| j                  | j                         y| j                  | j                         yyt        | j                        dkD  r9t        | j                        }| j                  d|t        |      |z  z
  z         y| j                  | j                         y)z
        Indent current line or selection

        force=True: indent even if cursor is not a the beginning of the line
        r(  r  Tr  rh  r  N)r  rj  r  r#  r-  r  r  r?  r  r%  r+  )ro   r  r3  r>  s       rt   r  zCodeEditor.indent  s     }}UH5!!#OOD--.<--/!!dmm""$t4OOD$5$56 1 12 5
 4$$%)T../  fc,.?&.H&I!JK  !2!23rv   c                 ~   | j                   r| j                  s| j                         s| j                          y| j	                         }| j                         t        |j                         j                               k(  r| j                          y| j	                         }|j                  |j                                | j	                         }|j                  |j                                |j                         |j                         k7  r| j                          y| j                  | j                         y)zAIndent or replace by 4 spaces depending on selection and tab modeN)r  r  rj  r  r  r}  rO   r  r  r  r  r  r  rH  r#  )ro   r  cursor1cursor2s       rt   r/  zCodeEditor.indent_or_replace  s    t7M7M7OKKM__&F&&("6<<>#6#6#89://+##F$9$9$;<//+##F$7$7$9:&&(G,?,?,AAKKMLL!2!23rv   c                    | j                         r| j                  dk(  r| j                  | j                         yt        | j                        }| j	                         }||z  }|r| j                  d|z         y| j                  | j                         y| j                  dd      }|s(|j                         r| j                  r| j                  r~| j                         r/| j                  d      s| j                  | j                         yy|j                  d      r| j                  d       y| j                  | j                         yyy)z
        Unindent current line or selection

        force=True: unindent even if cursor is not a the beginning of the line
        r  r  r(  r  Fr  N)rj  r#  r  r%  r  r  r-  r  r  r?  r  r.  )ro   r  space_countleading_spaces	remainderr3  s         rt   r  zCodeEditor.unindent  s!    !!#  D(""4#4#45 "$"3"34!%!9!9!;*[8	 &&s9}5 &&t'8'89==9L\//1%%$--&&(??5?9**4+<+<= :!**40&&t,&&t'8'89 +8%rv   c                    | j                         }t        |j                         |j                         g      \  }}|j	                  |       |j                         j                         }|j                         r
||k7  r|dz  }|j	                  |       |j                         j                         }d}d}t        ||dz         D ]  }t        |j                         j                               j                         }	|	j                  | j                        }
|	dk(  }||
xs |z  }|
rd}|j                  t        j                           |r|r| j#                          y| j%                          y)z+Toggle comment on current line or selectionrh  TFr   N)r  r  r  r  r  r  r  r  r  rO   r  r  r  r  r  r   r=  	uncommentcomment)ro   r  r  r  	last_liner  is_comment_or_whitespaceat_least_one_comment_line_nbr  
is_commentis_whitespaces               rt   r  zCodeEditor.toggle_comment  sJ    "#V%:%:%<%+%8%8%:%< =	77#LLN..0	 Y'%9NI9%\\^//1
 $( $j)A+6 	7H!&,,."5"5"78??AD)<)<=J!RZM$)D}E$'+$ 5 56	7 $(<NNLLNrv   c                     |yt        |j                               j                         }|j                  | j                        S )zXDetect inline comments.

        Return True if the block is an inline comment.
        F)rO   r  r  r  r  )ro   r  r  s      rt   r  zCodeEditor.is_comment  s:    
 =ejjl+224t2233rv   c                 @    | j                  | j                  dz          y)z"Comment current line or selection.r  N)r  r  r  s    rt   r  zCodeEditor.comment  s    ++c12rv   c                 `    | j                         }|s| j                  | j                         yy)z$Uncomment current line or selection.N)r  r  r  )ro   r  s     rt   r  zCodeEditor.uncomment#  s,    **,t223 rv   c                     | j                   dz   ddt        | j                   dz         z
  z  z   }|r(| j                   ddt        | j                         z
  z  z   }|S )z@Handle versions of blockcomment bar for backwards compatibility.r  r  O   )r  r%  )ro   compatibilityblockcomment_bars      rt   __blockcomment_barzCodeEditor.__blockcomment_bar)  sq      ..4s$&T-@-@3-F)G$G8I I#22S$&T-@-@)A$A6C  Crv   c                    | j                         }|j                         }t        |j                               }t	        |      dk(  rH|j                         }|j                  t        j                         t        |j                               }|j                         }|j                  |       | j                  |       y)z.Change to uppercase current line or selection.r   N)r  r  rO   r`  r%  ra  r   rb  r_  r  set_cursor_positionro   r  prev_posselected_textss        rt   r  z!CodeEditor.transform_to_uppercase4      "??$&v':':'<=}"(HMM+556*6+>+>+@AM!!  *rv   c                    | j                         }|j                         }t        |j                               }t	        |      dk(  rH|j                         }|j                  t        j                         t        |j                               }|j                         }|j                  |       | j                  |       y)z.Change to lowercase current line or selection.r   N)r  r  rO   r`  r%  ra  r   rb  rd  r  r&  r'  s        rt   r  z!CodeEditor.transform_to_lowercaseC  r+  rv   c                    | j                         | j                         z   }| j                         }| j                         r1| j	                          |j                         |j                         }}n|j                         x}}|j                          |j                  |       |j                  t        j                         |j                         |k  r|j                  | j                  dz          |j                  t        j                         |j!                         rnN|j                  t        j"                         |t%        | j                  dz         z  }|j                         |k  r|j                  |       |j                  t        j                         |j!                         r |j                  | j                                n|j                  t        j"                         |j                  |       |j                  |       |j                  t        j                         |j                  |       |j'                          y)z(Block comment current line or selection.r  N)_CodeEditor__blockcomment_barr  r  rj  "extend_selection_to_complete_linesr  r  r  r  r  r  r   r  r  r  r9  r<  r=  r%  r  )ro   comliner  r  r  s        rt   r  zCodeEditor.blockcommentR  s   ))+d.E.E.GG"!!#335!'!6!6!8&:M:M:OwI"(//"33I9%K445oo7*d11C78 6 67||~ 5 56s4..455G oo7* 	7#K223<<>d5578 5 56'"9%K445'"rv   c                 P    | j                         }|s| j                  d      }y|S )z+Un-block comment current line or selection.Tr"  N)_CodeEditor__unblockcomment)ro   r  s     rt   r  zCodeEditor.unblockcommentq  s.     ..0"33$3GN!!rv   c                 z     fd} j                         } ||      ry ||      s<|j                  t        j                         |j	                         dk(  rn	 ||      s< ||      sy fd}t        |      }|j                  t        j
                          ||      sh ||      r`|j                  t        j
                         |j                          j                         j                         k(  rn ||      s	 ||      r` ||      sy j                         }|j                          |j                  |j                                |j                  t        j
                         |j                         |j                         k  r|j                  t        j                  t        j                         |j                         s0s.|j                  t        j                  t        j                         |j                          |j                  t        j
                         |j                         |j                         k  r||fD ]P  }|j                  |j                                |j!                  t        j"                         |j                          R |j%                          y)z2Un-block comment current line or selection helper.c                     t        | j                         j                               j                  j	                              S )Nr2  )rO   r  r  r  r.  )r  r"  ro   s    rt   __is_comment_barz5CodeEditor.__unblockcomment.<locals>.__is_comment_bar}  s>    !&,,."5"5"7 'Z00}0MOOrv   Nr   Fc                     j                   }t        | j                         j                               j	                  |      S rg   )r  rO   r  r  r  )r  csro   s     rt   __in_block_commentz7CodeEditor.__unblockcomment.<locals>.__in_block_comment  s3    $$B!&,,."5"5"78CCBGGrv   T)r  r  r   rB  r  r=  r  r  r  r  r  r  NextCharacterr  
atBlockEndr;  ra  BlockUnderCursorr  )ro   r"  _CodeEditor__is_comment_barr  _CodeEditor__in_block_commentr  cursor3r  s   ``      rt   __unblockcommentzCodeEditor.__unblockcomment{  s5   	O
 //#G$"7+  !:!:;""$) #7+  (	H g&[223"7+0B70K  !6!67}}$--/";";"== #7+0B70K  (//# G,,./[223 7#3#3#55  !:!:!,!7!79%%' %(()B)B)4)?)?A&&(  !6!67  7#3#3#55 ( 	)F 12NN;778&&(	) 	rv   c                 t   | j                         }|j                          |j                  t        j                  t        j
                         |j                         s.|j                  t        j                  t        j
                         | j                  j                  |       | j                  |       y)z9Kill the text on the current line from the cursor forwardN)r  clearSelectionr  r   r  r  hasSelectionr=  r  kill_cursorr  rY  s     rt   r  zCodeEditor.kill_line_end  s    "K11;3I3IJ""$ 5 5 + 6 68##F+6"rv   c                     | j                         }|j                          |j                  t        j                  t        j
                         | j                  j                  |       | j                  |       y)z:Kill the text on the current line from the cursor backwardN)	r  rB  r  r   r  r  r  rD  r  rY  s     rt   r  zCodeEditor.kill_line_start  sY    "K44'22	4##F+6"rv   c                    | j                         }|dz  }|rH| j                  |j                  |            s(|dz  }|r!| j                  |j                  |            s(|rH| j                  |j                  |            r(|dz  }|r!| j                  |j                  |            r(| j                         }|j	                  | j                                |S )zFind the start of the word to the left of the given position. If a
           sequence of non-word characters precedes the first word, skip over
           them. (This emulates the behavior of bash, emacs, etc.)
        rh  )r  is_letter_or_numbercharacterAtr  r  rV  )ro   r  r  r  s       rt   _get_word_start_cursorz!CodeEditor._get_word_start_cursor  s    
 ==?A''(<(<X(FGMH ''(<(<X(FG433$$X.0MH 433$$X.0 "44467rv   c                 V   | j                         }| j                         }|j                         }|j                  t        j
                         |j                         }||k  rW| j                  |j                  |            s7| j                  |      }||k  r!| j                  |j                  |            s7||k  rW| j                  |j                  |            r7| j                  |      }||k  r!| j                  |j                  |            r7|j                  |       |S )zFind the end of the word to the right of the given position. If a
           sequence of non-word characters precedes the first word, skip over
           them. (This emulates the behavior of bash, emacs, etc.)
        )
r  r  r  r  r   r  rG  rH  rV  r  )ro   r  r  r  r  s        rt   _get_word_end_cursorzCodeEditor._get_word_end_cursor  s    
 ==?"??$KOO,oo#~++H,@,@,JK00:H #~++H,@,@,JK#~''(<(<X(FG00:H #~''(<(<X(FG8$rv   c                     | j                         j                         }| j                  |      }|j                  |t        j
                         | j                  j                  |       | j                  |       y)zKill the previous wordN)	r  r  rI  r  r   r  r  rD  r  ro   r  r  s      rt   r  zCodeEditor.kill_prev_word  s]    ??$--/,,X68[%;%;<##F+6"rv   c                     | j                         j                         }| j                  |      }|j                  |t        j
                         | j                  j                  |       | j                  |       y)zKill the next wordN)	r  r  rK  r  r   r  r  rD  r  rM  s      rt   r  zCodeEditor.kill_next_word  s]    ??$--/**848[%;%;<##F+6"rv   c                    || j                         }|j                         }|j                         |j                         z
  }|j                         }|j	                         }|r|j                         r|d   j                  }nEd}|D ];  }||j                  k\  s||j                  |j                  z   k  s0|j                  }= |y|j                         j                         j                         }|S y)zAGet the syntax highlighting color for the current cursor positionNr  )r  r  r  rR  additionalFormatsr;  r  rn   r>  r  r  r  )	ro   r  r  r  rR  block_formatscurrent_formatfmtr  s	            rt   __get_current_colorzCodeEditor.__get_current_color  s    >__&Foo%.."22002  "!.r!2!9!9!%( 4Csyy(sSYY5K/K),4 ")"--/557<<>ELrv   c                    | j                   ry|#| j                         }|r|j                  |       | j                  |      }| j                   j	                  d      }| j                   j	                  d      }||k(  s||k(  ryyy)zIs the cursor or position inside or next to a comment or string?

        If *cursor* is None, *position* is used instead. If *position* is also
        None, then the current cursor position is used.
        r  r  stringTFr   r  r  _CodeEditor__get_current_colorget_color_name)ro   r  r  current_colorr   string_colors         rt   r_  zCodeEditor.in_comment_or_string  s     ~*&&x0 44F4CM ,,;;IFM++::8DL.M\4Qrv   c                     g d}g d}|j                         }|j                         }t        |D cg c]  }||k(  	 c}      ryt        |      dk  ryt        |D cg c]
  }|d   |k(   c}      ryyc c}w c c}w )N)r  r  r  r  r  r  r  r  )elsetryr  finallyTr  Fr   )r  r0  anyr%  )ro   r  stmt_kws	whole_kwsr  wksks          rt   __colon_keywordzCodeEditor.__colon_keyword/  sw    8	{{}

Y/r
/0Z!^84R%(b.45 0 5s   A6A;c                     g d}|j                         }t        |D cg c]  }|j                  |       c}      ryyc c}w )N)r  r  rO  r  rx  r  TF)r:  ra  r.  )ro   r  	end_charsr   s       rt   __forbidden_colon_end_charz%CodeEditor.__forbidden_colon_end_char>  s9    3	{{})4Qa 45 5s   ?c                     | j                   j                  t              }t        |      D ]!  \  }}|dk(  s|j	                  |d|       r! y y)a"  
        Return whether a string has a colon which is not between brackets.
        This function returns True if the given string has a colon which is
        not between a pair of (round, square or curly) brackets. It assumes
        that the brackets in the string are balanced.
        r  NTF)ra  r   r.   r  unmatched_brackets_in_line)ro   r  bracket_extr  r  s        rt   __has_colon_not_in_bracketsz&CodeEditor.__has_colon_not_in_bracketsF  sU     ,,001GH"4 	IC#>>tDSzJ	 rv   c                 ~    | j                         j                         }dD ]  }| j                  ||d      }| y y)zp
        Checks if there are any unmatched opening brackets before the current
        cursor position.
        )rP  ry  r  Fr  T)r  r  find_brace_match)ro   r  bracer  s       rt   __has_unmatched_opening_bracketz*CodeEditor.__has_unmatched_opening_bracketT  sM    
 ??$--/$ 	E))(E5)IE 	 rv   c                    | j                   j                  t              }| j                  j	                          | j                  dd      }| j                         j                         sy| j                         ry| j                  |      sy| j                  |      ry|j                  |      ry| j                  |      ry| j                         ryy)z&Decide if we want to autoinsert colonsr(  r  FT)ra  r   r.   r   r=  r  r  r;  r_  _CodeEditor__colon_keyword%_CodeEditor__forbidden_colon_end_charrk  &_CodeEditor__has_colon_not_in_brackets*_CodeEditor__has_unmatched_opening_bracket)ro   rl  r  s      rt   autoinsert_colonszCodeEditor.autoinsert_colons`  s    ,,001GH##%MM%2	 ++-&&(%%i0,,Y733I>--i8113rv   c                     | j                         }|j                  t        j                  t        j                         t        |j                               }|S rg   )r  r  r   r:  r  rO   r`  )ro   r  	next_chars      rt   ry  zCodeEditor.next_charv  sF    "K55'22	4"6#6#6#89	rv   c                     | j                   rV|#| j                         }||j                  |       | j                  |      }| j                   j	                  d      }||k(  S y)a  Returns True if the given position is inside a comment.

        Parameters
        ----------
        cursor : QTextCursor, optional
            The position to check.
        position : int, optional
            The position to check if *cursor* is None. This parameter
            is ignored when *cursor* is not None.

        If both *cursor* and *position* are none, then the position returned
        by self.textCursor() is used instead.
        r  FrX  )ro   r  r  r[  r   s        rt   
in_commentzCodeEditor.in_comment}  sf     ~*'&&x0 44V<M ,,;;IFM!]23rv   c                     | j                   rV|#| j                         }||j                  |       | j                  |      }| j                   j	                  d      }||k(  S y)a  Returns True if the given position is inside a string.

        Parameters
        ----------
        cursor : QTextCursor, optional
            The position to check.
        position : int, optional
            The position to check if *cursor* is None. This parameter
            is ignored when *cursor* is not None.

        If both *cursor* and *position* are none, then the position returned
        by self.textCursor() is used instead.
        rW  FrX  )ro   r  r  r[  r\  s        rt   	in_stringzCodeEditor.in_string  sf     ~*'&&x0 44V<M++::8DL!\12rv   c                    t        | t        d      t        j                  d      t	        j
                  dd      | j                        | _        t        | t        d      t        j                  d      t	        j
                  dd      | j                        | _	        t        | t        d      t        j                  d      t	        j
                  dd	      | j                        | _        t        | t        d
      t        j                  d      t	        j
                  dd      | j                        | _        t        | t        d      t        j                  d      t	        j
                  dd      | j                        | _        t        | t        d      t        j                  d      t	        j
                  dd      | j                         }t        | t        d      dz   t        d      z   t        j                  d      t	        j
                  dd      | j"                        }t        | t        d      t        j                  d      | j$                        | _        t        | t        d      t        j                  d      | j(                        | _        t        | t        d      t	        j
                  dd      | j,                        | _        t        | t        d       t        j                  d!      t	        j
                  dd"      | j0                        | _        t        | t        d#      t        j                  d$      t	        j
                  dd%      | j4                        | _        t        | t        d&      t        j                  d'      t	        j
                  dd(      | j8                        | _        t        | t        d)      t	        j
                  dd*      | j<                        | _        t        | t        d+      t        j                  d,      t	        j
                  dd-      | j@                        | _!        t        | t        d.      t	        j
                  dd/      | jD                        | _#        t        | t        d0      t	        j
                  dd1      | jH                        | _%        t        | t        d2      t        j                  d3      t	        j
                  dd4      | jL                        | _'        t        | t        d5      t        j                  d6      tQ        tP        jR                        | jT                        }t        | t        d7      t        j                  d8      tQ        tP        jV                        | jX                        }t        | t        d9      tQ        d:      | jZ                        }| j\                  }t        | t        d;      t	        j
                  dd<      |j^                        | _0        t	        jb                  d=d>d?      }t        | t        d@      je                  |jg                               t	        j
                  ddA      | jh                        | _5        | jj                  jm                  dB       to        |       | _8        | j6                  | j:                  | j>                  | jB                  | jF                  | jJ                  | j.                  | j2                  dC| j                  | j                  dC| j                  | j                  | j                  |g}dC|||dC|| j`                  | jj                  g}	tr        8| j&                  | j*                  dCg}
||
z   |	z   }tu        | jp                  |       n||	z   }tu        | jp                  |       to        |       | _;        tu        | jv                  | j                  dC|| j.                  f       yC)DzSetup context menuUndor  r  )iconshortcut	triggeredRedor  Cuteditcutr  Copyeditcopyr  Paste	editpaster  z
Select All	selectallr  Commentr  	Uncommentr  r  zClear all ouputipython_consoler  r  zConvert to Python filer   zGo to definitionr  )r  r  zInspect current objectMessageBoxInformationzinspect current objectzRun cellrun_cellzrun cellzRun cell and advancerun_cell_advancezrun cell and advancezRe-run last cellzre-run last cellzRun &selection or current linerun_selectionzrun selectionzRun to current linezrun to linezRun from current linezrun from linez
Debug cell
debug_cellz
debug cellzZoom inzoom_inzZoom outzoom_outz
Zoom resetzCtrl+0Generate docstringr  r#  provider_configurationlspr  
formattingr   !Format file or selection with {0}r  FN)<rZ   r)   rU   r  r,   get_shortcutr  undo_actionr  redo_actionr  
cut_actionr  copy_actionr  paste_actionr  r  r  clear_all_output_actionr
  ipynb_convert_actionr  r  r  inspect_current_object_actionsig_run_cellrun_cell_actionsig_run_cell_and_advancerun_cell_and_advance_actionsig_re_run_last_cellre_run_last_cell_actionsig_run_selectionrun_selection_actionsig_run_to_linerun_to_line_actionsig_run_from_linerun_from_line_actionsig_debug_celldebug_cell_actionr   ZoomInr  ZoomOutr  
zoom_resetr  )write_docstring_at_first_line_of_functiondocstring_actionr   r  
capitalizer  r  r  r"   menur  rY   readonly_menu)ro   selectall_actiontoggle_comment_actionzoom_in_actionzoom_out_actionzoom_reset_actionwriter	formatter	actions_1	actions_2
nb_actionsactionss               rt   r  zCodeEditor.setup_context_menu  s   (!F)#((6"2&&x8DIIO )!F)#((6"2&&x8DIIO (!E()!4&&x7488M )!F)#((:"6&&x8DIIO *!G*388K#8&&x9jj" )!L/(=&&x>nn& !.!I,s"1[>18K&&x1AB))!+ (5!%&SXX6G-H++(-$ %2!,-CHHX4F++%-! ,!&'&&x1CD779
 .;!,-12&&x1IJ//	.1*  -!J-chhz&:&&x<'' ) ,9!*+#((;M2N&&x1GH33,5( (5!&'&&x1CD//(1$ %2!45/*&&xA,,	%.!
 #0!)*&&x?**#, %2!+,&&xA,,%.! "/!L/(>&&x>))"+ '!I,SXXi%8!,"5"56ll$ (!J-chhz&:!,"6"67mm% *!L/L,Boo'
 && -!()&&x=FF!H HHE
	
 +1299$$&(&&x1AB335 	%%e, $K	))4+K+K1143L3L,,d.G.G(($*L*L4++%%tT__%%t'8'8:JL	 >?<M0$2G2G'')	 6633T;J*,y8G		7+)+G		7+ #4[D&&%%t-=((*	+rv   c                 t   | j                   j                  |       |j                         }t        j                  t        j
                  t        j                  t        j                  h}||v r| j                          |t        j                  t        j                  hv r| j                  j                          |j                         r| j                  j                         r| j                  j                          | j                         }|dk  r| j                  j!                  d       n<|dk  r| j                  j!                  d       n| j                  j!                  d       | j                  j                          | j#                          t$        t&        | S  |       |j+                          y)Override Qt method.r   r   i  r   N)sig_key_releasedr]  r  r   Key_UpKey_Left	Key_RightKey_DownrP  r   rn   r  r
  isActiver  r  rl   %_restore_editor_cursor_and_selectionsr  r|   keyReleaseEventignore)ro   r  r  direction_keystotal_linesr  s        rt   r  zCodeEditor.keyReleaseEvent9  s@   ""5)iik))R[[",,L. %%' 299r{{++))//1 ::< **335++002 --/KT!++77<t#++77<++77=''--/224j$/6rv   c                     |j                         t        j                  k(  r|j                          yt        t
        |   |      S )zQt method override.F)typer	   ShortcutOverrider  r  r|   r  r  s     rt   r  zCodeEditor.event_  s5    ::<6222LLNT077rv   c                    t        j                  | |       t        |j                               }|rt	        t
              t	        d      k  s&t        j                  dk(  st        j                  dk(  r@| j                         }|j                  |j                                | j                  |       | j                  j                          yy)zHandle keypress events.z5.15ntr{  N)rL   keyPressEventrO   r  r   r   r  r  r  r  r  r  r  r  r  r]  )ro   r  r  r  s       rt   _handle_keypress_eventz!CodeEditor._handle_keypress_eventg  s    ((u5 ejjl+ j!E&M177d?cllh&>*""6??#45""6*&&++- rv   c                    | j                   dkD  r-d| _        | j                  j                  | j                          n| j	                          |j                          | j                  j                  |       |j                         x| _	        }t        |j                               x| _        }| j                         }|j                         t        j                   z  }|j                         t        j"                  z  }|r| j%                          |t        j&                  t        j(                  t        j*                  t        j,                  hv r| j/                          |j1                         ry|t        j2                  t        j4                  t        j6                  t        j8                  t        j:                  fv r{|rx| j=                  t?        j@                               }| jC                  |      }| jE                  |      r|jG                          y| jI                  |      r|jG                          yyh d}h d}	|| jJ                  vr"||v s||	v r| jL                  jO                          |t        jP                  t        jR                  fv r|s|s| jT                  r| jW                         r| jY                         r| j[                         j]                          | j_                  d| ja                         z          | jb                  r| je                          n| jg                          | j[                         ji                          n| jk                         r| jm                          n| j[                         j]                          | jo                  | j[                         jq                               }
| js                  |       | ju                         }| j[                         }|jw                  |jy                         j{                         t|        j~                         | ju                  |      }|xr |}| jb                  r| je                  ||
       n| jg                  ||
       | j[                         ji                          n|t        j                  k(  r&|s$|s"| j                  | j                                 n|t        j                  k(  r|s|s|s| j                  s| js                  |       nL| j                  d	d
      }t        |      }|t        |j                               z
  }| j                  d
d      }d}|j                         sX|t        | j                        kD  r@|t        | j                        z  dk(  r| j                          n| js                  |       n|r'|j                         s| j                  || d        nn|r|r}|d   |d   z   |v rp| j[                         }|j                  t|        j                         |j                  t|        j                  t|        j~                  d       |j                          n| js                  |       n|t        j                  k(  r| j                  ||       n|t        j                  k(  r| j                  ||       n|| jJ                  v r| j                  r| j_                  |       |dk(  ro| ju                         sK| j                  d	d
      }t        |      }t        |      dkD  r|d   nd}|dv s|r|j                         s| j                  d       n| j                  d       n|| j                  v r3| j                         s#| j_                  |       | j                          n|t        j                  k(  r|s| j                  r| j                  d	d
      }|j                         dv rd }t        | j[                         jy                         j                         j                               }| j                  dk(  r|j                         } ||       ||      k(  r| j                  d       | js                  |       n|t        j                  k(  r|s|s|s| j                  r| jL                  jO                          | j                  d	d
      }|j                         dv rd }t        | j[                         jy                         j                         j                               }| j                  dk(  r|j                         } ||       ||      k(  r| j                  d       | js                  |       n|t        j                  k(  r2|s0|s| j                  s| j                          n| j                          nv|t        j                  k(  rB|s@|s| j                  s| j                          n| j                          |jG                          n!|j1                         s| js                  |       |j                         s|jG                          yy)zReimplement Qt method.r   FN>   !=**<<<===>=>>*rg  &+-r  rQ  rR  @^|~r   >   %=&=*=+=-=->/=@=^=|=**=//=<<=>>=r  r  r   r  r  r  rV  )r  r  r(  r  r  )z()z[]z{}z''z""r  r  rz  rh  r   >   ry  rP  r  Tr  )r^  r`  c                 L    t        |       t        | j                               z
  S rg   r%  r  txts    rt   r   z*CodeEditor.keyPressEvent.<locals>.<lambda>$  s    #c(S->"> rv   r}   r  )r  r  c                 L    t        |       t        | j                               z
  S rg   r  r  s    rt   r   z*CodeEditor.keyPressEvent.<locals>.<lambda>6  s    #c(3szz|+<"< rv   )fr&  r   r   rn   r   r  sig_key_pressedr]  r  r   rO   r  r   rj  	modifiersr   ControlModifierShiftModifierr  r  r  r  r  r  
isAcceptedKey_Control	Key_ShiftKey_AltKey_MetaKeypadModifiermapFromGlobalr   r  r  _handle_goto_uri_eventaccept_handle_goto_definition_eventrJ  r   r=  	Key_Enter
Key_Returnr)  r?  rw  r  r  r+  r  r?  fix_and_strip_indentr  r  r  select_completion_listr  r  r  r_  r  r  r  r   r  
Key_InsertsetOverwriteModeoverwriteModeKey_Backspacer  r  r%  r:  r-  r#  r  r  r  PreviousCharacterr:  r;  Key_Homestdkey_homeKey_End
stdkey_endr  r&   isdigitr  rL  r<  	Key_Colonr*  r  r  r  	Key_SpaceKey_Tabr  r4  r/  Key_Backtabr6  )ro   r  r  r  has_selectionctrlshiftr  	operators
delimitersr  cmt_or_str_cursorr  cmt_or_str_line_begin
cmt_or_strr3  leading_lengthtrailing_spacesr  matcheslast_obj	prev_charindprevtxts                           rt   r  zCodeEditor.keyPressEvent|  s=   ))A-*/D'((..t/M/MN++- 	!!%(',yy{2-;EJJL-II#d..0 2#5#55!B$4$44""$ 299bkk2<<EE2>>2<<;; 1 13 3 ((7>>sC..s3LLN55c:LLNK	P
 t666y DJ$6&&++-2<<//++'')**,OO%446$$S4+B+B+D%DE;;113)OO%224668//1OO%446!%!;!;)557"9J//6 )-(A(A(C% "__.F&&v||~'>'>'@'2'='=?,0,E,E% -F -') "3!L7LJ;;11.8'1 2 3 *3= ( ?OO%224BMM!%!!d&8&8&:":;B$$$U4D$>$>++E2#}}UH=!$\!2"03|7J7J7L3M"M $h >:$**,#c$*;*;&<<%D,=,=(>>!C33E:$]-@-@-B&&|_4D4E'FG !!"%a(88GC!__.F''(E(EF''(A(A(3(>(>C--///6BKKUD)BJJ OOE4(D333&&T"s{002==9D%d|H,/IMRrI!_4!(*:*:*< **T*:""T"2D888&&(T"""$2<<&&==9L""$(;;>)$//*;*A*A*C#8:ddf.==H,%nn.G|$G4MMM-''.2<<&&""'')==9L""$(::<)$//*;*A*A*C#8:ddf.==H,%nn.G|$G4MMM-''.BJJt !$$& &&(BNN"4 !((* LLN!!#''.  LLN	 !rv   c                 \   | j                   sy| j                         }|j                         }|j                  t        j
                         t        |j                               }| j                  }|W|t        j                  t        j                  t        j                  t        j                  t        j                  fv rd| _        y|t        j                  k(  r|j!                  t#        d|dz
        t        j$                         |j                  t        j
                         t        |j                               }|j!                  t#        d|dz
        t        j$                         |j!                  |t        j&                         |j                         }|dk(  s|dv ry|dk(  rl|j!                  t#        d|dz
        t        j$                         |j                  t        j
                         t        |j                               }|dk7  rd}|j)                  d      r[|j!                  |dz
  t        j$                         |j                  t        j
                         t        |j                               }| j+                         xr |t        j                  k(  }t-        |      | j.                  k\  r| j0                  s|r[| j3                         sJ|j5                         s|j7                         sd|v sd|v r!| j9                  d	
       d| _        d| _        yyyy)zPerform on the fly completions.Nr   rh  r   )u    r  r  rz  r  r)   Tr  )r  r  r  ra  r   rb  rO   r`  r   r   r  
Key_Escaper  r  r  r  r  r  r  r  r  r  r%  r   r   r_  isalphaisalnumr  )ro   r  r  r  r  	prev_textr+  is_backspaces           rt   ro  z#CodeEditor.do_automatic_completionsX  s   ))"ook112f1134$$?r}}bmmzz2>>2<<A A)-& """"s1cAg0F0FGMM+556&v':':'<=Is1cAg0F0FGsK$:$:;++-IB)/E"E 2:s1cAg0F0FGMM+556!&"5"5"78Ds{ ???+sQw(>(>?MM+556!&"5"5"78D --/KC2;K;K4K 	 Y$@@@'' ,,. LLNLLN4Kd{&&&624D/-1D*	 # / rv   c                     | j                         j                         }|dkD  r
|dz
  | _         | j                  |i | | j                         j                         }| j	                         }||z
  ||z
  f| _        y)z
        Automatically fix indent and strip previous automatic indent.

        args and kwargs are forwarded to self.fix_indent
        r   rh  N)r  r  r;  r  rh  r=  )ro   rp   rq   cursor_beforecursor_afternspaces_removeds         rt   r  zCodeEditor.fix_and_strip_indent  s     )2241(5(9D%(((113446!.!@!-!?!Arv   c                     t        | j                  t        j                        r| j                  j	                          yy)zRun pygments highlighter.N)r  r   r   r  r  r  s    rt   r  z#CodeEditor.run_pygments_highlighter  s-    d&&6**, 7rv   c                 N    | j                  | j                  j                  |      S )zT
        Return key, text and cursor for pattern (if found at coordinates).
        )get_pattern_cursor_atr   patterns)ro   coordinatess     rt   r  zCodeEditor.get_pattern_at  s(     ))$*:*:*C*C*57 	7rv   c                    d\  }}}d}| j                  |      }|j                  |      D ]<  }t        |j                         j	                               D ]
  \  }}	|	s
t        j                  |      \  }
}| j                  |      }|j                  t        j                         |j                         }|j                  ||
z   |j                         | j                  |      }|j                  ||z   |j                         | j                  |      }|j                  |      }|j!                  |      s||
| }|j                  ||
z   |j"                         d} n |s= n |||fS )z
        Find pattern located at the line where the coordinate is located.

        This returns the actual match and the cursor that selects the text.
        )NNNFT)get_line_atr  r  	groupdictr  r   r  r  r  r   r  r  r  r  
cursorRectunitedcontainsr  )ro   r  r<  r  r  r  
break_loopr  r  r   rn   r  line_start_position
start_rectend_rectbounding_rects                   rt   r:  z CodeEditor.get_pattern_cursor_at  st    -T
 ,%%d+ 	E"5??#4#:#:#<= 
U!#U!3JE3 "33K@F''(@(@A*0//*;'&&':U'B'-'8'8:!%!8J&&':S'@'-'8'8:#v6H$.$5$5h$?M %--k:#E#**+>+F+1+<+<>%)
/2 7	: D&  rv   c                 P   |j                  dd      }|d   dk(  r|dd }|j                  d      rB| j                  $t        j                  | j                  |dd       }n|j                  dd      }|j                  d      rt        j
                  |      }t        j                  t        j                  | j                              }t        j                  |      r+t        j                  |      st        j                  ||      }| j                  j                  |       |S )	z9Format uri to conform to absolute or relative file paths.zfile://r   r  r  Nz^/r  z~/)rH  r  r   r  r  
expanduserdirnameabspathrA  isdirisfilesig_file_uri_preprocessedr]  )ro   urir  rJ  s       rt   _preprocess_file_urizCodeEditor._preprocess_file_uri  s    Ir*9#2JE D!((4!:!:E!"IFdD1D!NN5)E++ckk$--8999W::e$%0&&++E2rv   c                    | j                  |      }|rt        j                  t        |            s| j                  s3t        j                  t        t        j                               d| _        | j                  |      }|j                  t        j                         | j                  d       | j                  d|| j                   | j                   t"        j$                         yy)z<Check if goto definition can be applied and apply highlight.T
ctrl_clickrr  r  ru  F)rs  rS   r~  rO   r0  r!   setOverrideCursorr   r   PointingHandCursorr  ra  r   rb  r  r  r   r   SingleUnderline)ro   r  r  r  s       rt   r  z(CodeEditor._handle_goto_definition_event  s    $
--nT.BC((..wr7L7L/MN(,%++C0FMM+556''5$$f!%!6!6 $ 5 5 / ? ?	 % A
 rv   c                 0   | j                  |      \  }}}|r|r|r|| _        || _        | j                  }|dv r?| j	                  |      }t        j                  |      st        t        j                        }| j                  d       | j                  d|||t        j                         | j                  s3t        j                   t#        t$        j&                               d| _        | j(                  j+                  |       y|| _        || _        y)z6Check if go to uri can be applied and apply highlight.r~  rR  rS  TF)r  r   r   r   rP  r  rM  r   rW   COLOR_ERROR_2r  r  r   rV  r0  r!   rT  r   r   rU  sig_uri_foundr]  )ro   r  r  r  r  r  r  s          rt   r
  z!CodeEditor._handle_goto_uri_event  s    $($7$7$<!\6<F+.D(,8D)))Eh11,?zz%("=#>#>?E''5$$f!& % / ? ?	 % A ((..B1124(,%##L1+.D(,8D)rv   c                 $   | j                   }|}|dv rr| j                  |      }t        j                  |      r4t	        j
                  |      r| j                  j                  |dd       nt        |      }t        |       n{|dv r<d|v r|j                  d      sd|z   }t        |      }t        j                  |       n;|dv r6|j                  dd      }|j                  d	      rR|d
d }t        | j                         }|j#                  d|j#                  d            }	|	rt%        |	      dz   |z   }nid}nf|j                  d      sd|vr|}
|j                  d      r|d
d }
d|
z   }n3|j                  d      r	d|d
d z   }n|j                  d      rd|d
d z   }|r!t        |      }t        j                  |       n8t'        j(                  | t+        d      t+        d      t&        j,                         | j/                          |S )z1Go to url from cursor and defined hover patterns.r~  r   )r  r  r  zmailto:)issuer~   z/issues/)zgh-zbb-zgl-r   Nupstreamoriginzgh:r  zhttps://github.com/zgl:zhttps://gitlab.com/zbb:zhttps://bitbucket.org/InformationzWThis file is not part of a local repository or upstream/origin remotes are not defined!)r   rP  r  rM  rR   is_text_filerf  r]  r[   r]   r  r   r   openUrlrH  r^   rA  r   r_   r#   rJ  r)   Okr  )ro   rO  r  full_urir  qurirepo_urlr  remotesremoterepo_and_issues              rt   go_to_uri_from_cursorz CodeEditor.go_to_uri_from_cursor0  s   **(?--c2Ezz% X%:%:5%A%%**5!Q7 !5!O#cz#..";$s?>D$$T*I{{3
3H~~34QR)$--8 ZX1FG,V4zAFJH#H&#S.!)>>%(%-ab\N0>A&08AB<?&3hqrlBH~ ((.''m$ A BNN 	rv   c                 N   |y|| j                         j                         k\  ry| j                         }|j                  |       |j	                         j                         |j	                         j                         |j	                         j                         z   dz
  f}|S )z/
        Get line range from position.
        Nrh  )r  characterCountr  r  r  r  r>  )ro   r  r  
line_ranges       rt   rk  zCodeEditor.line_rangej  s     t}}5577"8$lln--/lln--/--/02345
 rv   c                 &   t               s| j                         sy| j                         j                         }| j                  }|| _        | j
                  ry| j                  |      yfd} ||      ry| j                         }|j                  d          | j                  r| j                  |      rT| j                  y| j                  | j                  | j                  d         k7  rd| _
        y| j                  d| _
        n || j                        sy|j                  d          |j                  d   t        j                         |j                         }|j                         }t!        |t#        |      d       }|dkD  ry|j                  d   |z
         |j                  d   t        j                         |j%                          d   | _        | j                         j                         | _        |S y)z
        Strip trailing spaces if needed.

        Remove trailing whitespace on leaving a non-string line containing it.
        Return the number of removed spaces.
        r   Nc                 6    | yd   | cxk  xr d   k  S c S )zCheck if pos is in last line.Fr   rh  r   )r  rk  s    rt   pos_in_linez5CodeEditor.strip_trailing_spaces.<locals>.pos_in_line  s)    {a=C8:a=8888rv   rh  rV  )r+   hasFocusr  r  r<  r>  rk  r  r?  r}  r=  r;  r   r  r`  r:  r`   r%  r;  )	ro   current_positionr<  rn  r  r  r-  N_striprk  s	           @rt   rh  z CodeEditor.strip_trailing_spacesz  s    $%==???,557**-__]3
	9 '( ":a=)44>>>0$$,''//$"7"7":;< )-%..J$(D!T667:a=):a=&11	3 ""$ !c%jk!23Q;z!}w67z!}*557%%'(21D%!%!2!;!;!=DNrv   c                 (    | j                  d       y)z%Move up current line or selected textFafter_current_lineN#_CodeEditor__move_line_or_selectionr  s    rt   r  zCodeEditor.move_line_up  s    %%%?rv   c                 (    | j                  d       y)z'Move down current line or selected textTrs  Nru  r  s    rt   r  zCodeEditor.move_line_down  s    %%%>rv   c                    | j                         }| j                  j                  d      }|j                         dz   }|j	                         j                         }||j                  v r"|j                  |   }|r|j                  |       |rq|j                         dz   }|j	                         j                         j                         }||j                  v r|j                  |   }|r|j                  |       n|j	                         }d}| j                         r| j                         \  \  }}	}
|
|k7  rd}|j                         dz
  |z
  }t        t        |j                  |               }|j                  }t        |      dkD  rP|D ]K  }|j                  }| j                         j!                  |      }||v s3||   }|s;|j                  |       M | j#                  |       y )Nr:   rh  r  r   rs  )r  r   r   r  r  r  folding_statustoggle_fold_triggerrj  rz  r  r  r  r%  beginr  r  +_TextEditBaseWidget__move_line_or_selection)ro   rt  r  r  fold_start_liner  fold_statusr  r  r)   r  enclosing_regionsry  regions                 rt   __move_line_or_selectionz#CodeEditor.__move_line_or_selection  s   "7 ,,.2##%m:::'66GK11%8$002Q6OLLN'')..0E-">">>+::?K!55e< LLNEF%%'$($@$@$B"%/1 O3F#//1A5>O !'t**?;(= !> +99N$%)/ EF&,llO MMO==oNE&.8&4_&E&)==eDE 	881 	9 	3rv   c                    | j                   j                          |j                         }|| _        |j	                         t
        j                  z  }|j	                         t
        j                  z  }|r,| j                  j                  |       |j                          y|r"| j                  |      r|j                          y| j                         rt        j                  | |       y| j                  r$|r"| j!                  |      r|j                          y| j"                  r| j%                          n1| j'                  |      s | j)                         s| j+                          t        j                  | |       y)z'Underline words when pressing <CONTROL>N)r   rn   r  r   r   r   AltModifierr  sig_alt_mouse_movedr]  r  r
  rj  rL   mouseMoveEventrM  r  r0  r  rv  r  r  )ro   r  r  altr   s        rt   r  zCodeEditor.mouseMoveEvent  s$    	  &&(iikoo"..0 2#5#55$$))%0LLN**3/!!#--dE:((T11#6  668..s3 ==?!!#))$6rv   c                 `    t         t        |   |       | j                  j	                          y)a  
        Extends setPlainText to emit the new_text_set signal.

        :param txt: The new text to set.
        :param mime_type: Associated mimetype. Setting the mime will update the
                          pygments lexer.
        :param encoding: text encoding
        N)r  r|   r  new_text_setr]  )ro   r  r  s     rt   r  zCodeEditor.setPlainText%  s&     	j$,S1 rv   c                     | j                   j                          | j                          t        t        |   |       yzExtend Qt methodN)sig_focus_changedr]  r  r  r|   focusOutEventr  s     rt   r  zCodeEditor.focusOutEvent1  s0    ##%224j$-e4rv   c                 |    t        | dd      }| j                  j                  |       t        t        |   |       y )NrP  F)r  r  r]  r  r|   focusInEvent)ro   r  rP  r  s      rt   r  zCodeEditor.focusInEvent7  s7    $T+?G##(();<j$,U3rv   c                     | j                   j                          | j                          t        j                  | |       yr  )sig_leave_outr]  r  rL   
leaveEventr  s     rt   r  zCodeEditor.leaveEvent<  s0    !224%%dE2rv   c                    | j                          |j                         t        j                  z  }|j                         t        j                  z  }|j                         }|j                         t        j                  k(  | _        |j                         t        j                  k(  r[|rYt        j                  | |       | j                  |      }| j                  }|r| j                  |       y| j                  |       y|j                         t        j                  k(  r|r| j                  j!                  |       yt        j                  | |       y)r  N)r  r   r   r  r  r  button
LeftButtonr1  rL   mousePressEventr  r   rh  r  sig_alt_left_mouse_pressedr]  )ro   r  r   r  r  r  rO  s          rt   r  zCodeEditor.mousePressEventB  s     2#5#55oo"..0iik*/,,.BMM*I'<<>R]]*t..tU;++C0F//C**3/11&9\\^r}},++007..tU;rv   c                     |j                         t        j                  k(  rd| _        | j	                          t        j                  | |       y)r  FN)r  r   r  r1  rP  rL   mouseReleaseEventr  s     rt   r  zCodeEditor.mouseReleaseEventX  s8    <<>R]]*.3D+!!#,,T59rv   c                    | j                         }| j                  j                  |       | j                  j                  |       | j                  j                  | j                         xr t        du       | j                  j                  | j                         xr t        du       | j                  j                  | j                                | j                  j                  | j                                | j                  j                  | j                                | j                  j                  | j                                | j                  j                  | j                                | j                  j                  | j                                | j                   j                  | j"                         t%        j&                  ddd      }| j(                  j+                  t-        d      j/                  |j1                                      | j2                  }| j5                  |j7                               |_        |j;                         }|r| j<                  j                  d       n| j<                  j                  d       | j?                         }tA        |jC                               }tE        |      dk(  r8|jG                  tH        jJ                         tA        |jC                               }| jL                  j                  | jO                         jQ                                | jR                  j                  | jO                         jU                                | jV                  }| jY                         r| jZ                  }|j]                  |j_                                |ja                          y)	zReimplement Qt methodNr#  r  r   r  TFr   )1rj  r  r  r  r  r>  r  r  r  r  r  r  r  r  r  r  r  rM  r,   r   r  setTextr)   r  r  r  get_line_number_atr  line_number_cursor'get_function_definition_from_first_liner  r  rO   r`  r%  ra  r   rb  r  r  r)  r  r-  r  
isReadOnlyr  popup	globalPosr  )	ro   r  nonempty_selectionr  r  r  r  r  r  s	            rt   contextMenuEventzCodeEditor.contextMenuEvent`  s   !335##$67""#56$$// 1E080D	F!!,,T\\^ .B-5T-A	C''(A(A(CD((33D4M4M4OP!!,,T-F-F-HI**4+D+D+FG!!,,T-F-F-HI$$//0I0I0KL&&t'D'DEHHE
	
 	""1/$117$$&2(	)
 &&$($;$;EIIK$H!??A!!,,T2!!,,U3 "f1134t9>MM+556!&"5"5"78D##DMMO$C$C$EF##DMMO$C$C$EFyy??%%D

5??$%rv   c                     | j                   r;d| _         t        j                          | j                  d       d| _        d| _        yy)z<Restore the cursor and extra selections of this code editor.FrR  N)r0  r!   restoreOverrideCursorr  r   r   r  s    rt   r  z0CodeEditor._restore_editor_cursor_and_selections  sB      $)D!..0''5+/D(,0D) !rv   c                    t         j                  d       t        |j                               }|r&t         j                  d       |j	                          yt         j                  d       t        j                  | |       y)zn
        Reimplemented Qt method.

        Inform Qt about the types of data that the widget accepts.
        zdragEnterEvent was receivedz0Let the parent widget handle this dragEnterEventz-Call TextEditBaseWidget dragEnterEvent methodN)rj  rp  r\   r  r  rL   dragEnterEvent)ro   r  all_urlss      rt   r  zCodeEditor.dragEnterEvent  sX     	23 01LLKLLLNLLHI--dE:rv   c                    t         j                  d       t        |j                               r&t         j                  d       |j	                          yt         j                  d       t        j                  | |       y)zV
        Reimplemented Qt method.

        Unpack dropped data and handle it.
        zdropEvent was receivedz!Let the parent widget handle thisz(Call TextEditBaseWidget dropEvent methodN)rj  rp  r\   r  r  rL   	dropEventr  s     rt   r  zCodeEditor.dropEvent  sS     	-.()LL<=LLNLLCD((u5rv   c                     | j                  |       t        j                  | |       | j                  j	                  |       y)z:Overrides paint event to update the list of visible blocksN)update_visible_blocksrL   
paintEventr8  r]  r  s     rt   r  zCodeEditor.paintEvent  s2    ""5)%%dE2% rv   c                    g | j                   dd | j                         }|j                         }t        | j	                  |      j                  | j                               j                               }|t        | j                  |      j                               z   }| j                         }|j                         r||k  }|sy|j                         r!| j                   j                  ||dz   |f       |j                         }|}|t        | j                  |      j                               z   }|j                         }|j                         ryy)z0Update the list of visible blocks/lines positionNrh  )r7  r  r  intr  r  r  r  r  r  r  r  rj   r  )ro   r  r  r  r  r  ebottom_bottomvisibles           rt   r  z CodeEditor.update_visible_blocks  s   #%a &&('')$,,U3>> ""%#%)s411%8??ABBmmo.G %%,,c;q=%-HIJJLEC3t55e<CCEFFF++-K mmorv   c                    | j                   r| j                  }t        | j                               }|j	                         }|j                  t        j                         |j                  |       |j                  |       | j                  D ]4  \  }}}t        |      s|j                  d|| j                         |       6 yy)z#Draw a line on top of a define cellr  N)r  r   r   viewportpensetStyler   	SolidLinesetBrushsetPenvisible_blocksrN   drawLinerT  )ro   cell_line_colorpainterr  r  r  r  s          rt   r9  z$CodeEditor._draw_editor_cell_divider  s    ''"00Ot}}/G++-CLL&LL)NN3+/+>+> @'[%!%($$QTZZ\3?@ (rv   c                     | j                   S )aH  
        Returns the list of visible blocks.

        Each element in the list is a tuple made up of the line top position,
        the line number (already 1 based), and the QTextBlock itself.

        :return: A list of tuple(top position, line number, block)
        :rtype: List of tuple(int, int, QtGui.QTextBlock)
        )r7  r  s    rt   r  zCodeEditor.visible_blocks  s     $$$rv   c                      yr  r   r  s    rt   	is_editorzCodeEditor.is_editor  s    rv   c                    | j                         j                         j                         }||k7  ry|| j                         j                         k7  ry| j                  }|j                         r| j                         j                         }| j                  |      }| j                  |      }t        |       | _        t        | t        d      t        j                  d      |j                         | _        | j                  j%                  | j"                         | j                  j'                  | j"                         | j                  j)                  |       yy)z'Show the menu for generating docstring.Nr  TextFileIconr  )r  r  r  r  r  ,get_function_definition_from_below_last_liner@  bottomRightr  mapToGlobalr1   menu_docstringrZ   r)   rU   r  write_docstringr  	addActionsetActiveActionr  )ro   r2  r(  r  r  ru  s         rt   popup_docstringzCodeEditor.popup_docstring  s   OO%++-224		!t(1133&&>>@OO%113E007E$$U+E"3D"9D$1a,-CHH^4L 00%2D! ))$*?*?@//0E0EF%%e, Arv   c                       j                         j                         j                          j                         j                         t	               }|j                  d fd       y)zShow context menu for docstring.

        This method is called after typing '''. After typing ''', this function
        waits 300ms. If there was no input for 300ms, show the context menu.
        r   c                  (    j                         S rg   )r  )r  r  ro   s   rt   r   z4CodeEditor.delayed_popup_docstring.<locals>.<lambda>  s    d&:&:9c&J rv   N)r  r  r  r  r   
singleShot)ro   timerr  r  s   ` @@rt   delayed_popup_docstringz"CodeEditor.delayed_popup_docstring  sP     OO%++-224	oo((*JKrv   c                     || _         y)z
        Set the current active project root path.

        Parameters
        ----------
        root_path: str or None, optional
            Path to current project root path. Default is None.
        N)r   )ro   	root_paths     rt   set_current_project_pathz#CodeEditor.set_current_project_path  s     %.!rv   c                     |j                  d      }|syt        |      D ]  \  }}|s	|j                         r|c S  t        |      S )z(Count the number of leading empty cells.T)keependsr   )r  r  r  r%  )ro   r  r  r  r  s        rt   count_leading_empty_linesz$CodeEditor.count_leading_empty_lines%  sL    . ' 	GAtDLLN	 5zrv   c                     t               }| j                  |      }	 |j                  |      }d|z  |z   S # t        $ r |cY S w xY w)z&Transform IPython code to python code.r  )r   r  transform_cellSyntaxError)ro   r  tmnumber_empty_liness       rt   r  zCodeEditor.ipython_to_python/  sY    !!;;DA	$$T*D ((4//  	K	s   6 AAc                 `    t        |      }|j                  d      xs |j                  d      S )zb
        Returns whether the specified unicode character is a letter or a
        number.
        LN)r   r  )ro   r  cats      rt   rG  zCodeEditor.is_letter_or_number9  s*    
 tn~~c"9cnnS&99rv   rg   )TF))TNFNNFTFTTr   Tr   TTTTTTT)r!  FFTFTTz    r  NNr   FFFTTFFFF)F)TT)FFFr  )r   r   r   )r   )T)TFN(j  __name__
__module____qualname____doc__r   r  r  r!  Fortran77SH	FortranSHIdlSHDiffSH	GetTextSHNsisSHHtmlSHYamlSHCppSHOpenCLSHr$  
MarkdownSHr   r   r  r  r  rm   r  r   r   r8  r   r   r   sig_repaint_breakpointsr  sig_debug_stopsig_debug_startsig_breakpoints_savedstrsig_filename_changedr  rf  r  r  r  r  r  r  r  r  r  rg  r  r  r  r   r  r  r   r  r  r  r  rG  r  r  rc  objectr\  rZ  rF  r  rY  rN  r  r  sig_will_insert_texttupler&  r  r*  r.  rw  r  r  sig_save_requestedr   r  rv  r   r  r  r  r5  r  r  r  r	  r  r  propertyr   rY  r   r`  rp  rm  rr  r  r  rH   r4   DOCUMENT_DID_OPENro  ry   DOCUMENT_SYMBOLr  rI   r  r  r  DOCUMENT_DID_CHANGErn  DOCUMENT_PUBLISH_DIAGNOSTICSr  r   r  r  r  r]  rJ  r_  r  r  DOCUMENT_COMPLETIONr  r/  COMPLETION_RESOLVEr3  r7  DOCUMENT_SIGNATUREr<  rN  DOCUMENT_CURSOR_EVENTrP  DOCUMENT_HOVERr  r]  DOCUMENT_DEFINITIONr  rh  r  DOCUMENT_FORMATTINGrl  DOCUMENT_RANGE_FORMATTINGrk  r  r  r  r  r  r  DOCUMENT_FOLDING_RANGEr  r  r  r$  DOCUMENT_DID_SAVEr  DOCUMENT_DID_CLOSEr  r  r  r  r1  r@  r2  r3  r7  r8  r9  r  r"  r5  r4  r6  r  r  r  r  r/  r0  r,  r.  r-  r+  r  r  r  r  r  r  r  r"  r%  r?  r4  r6  r  r?  rE  rG  rI  rP  r    SkipCharactersrV  r  r  r  r  r  r   rV  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r   r   r&  r*  r  r  r  r  r;  r<  r  r  rj   r  r  r$  r  r  r  r  r1  re  r;  r  r   r   r  rv  rd  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r/  r  r  r  r  r  r.  r  r  r  r  r3  r  r  rI  rK  r  r  rY  r_  rs  rt  ru  rv  rw  ry  r{  r}  r  r  r  r  r  ro  r  r  r  r:  rP  r  r
  rh  rk  rh  r  r  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r9  r  r  r  r  r  r  r  rG  __classcell__)r  s   @rt   r|   r|   |   sB   ;2;;$BLL#& 	2;;$ 	bnnc*	
 	BLL#& 	# 	B 	BLL#& 	C  	B 	C  	$ 	2;;% 	"**c" 	R]]C(" 	B#I( "% )%  "! [!G IM$h$hSFB'NhO"H!#;"Hc3,!$<hO%x8L!8XN"(c"2#;L#D\  Y'O i( "(!4 !- HM   &d| 8L &,Cd%;"
 #)f"5 %S$/ #4L !' 3KM &s '-S#t&<# #H "#; !'ue 4 !+ xH xH '-h# &,X" x  1F
+"1' R!"!:x23 	B7@   "&"""&" %+/+/78&*/2!%#',0,0-1$(#',!&&+'+"' $#'"'+,!%"(,.3#(%*&*!,1.3!&$)Ss(n 
#t_B B32&,/*b+ *<<$&(&(X 3CCD E #334( 5("5, %99! ! D #@@A5 B51,#/%	HH &,G(V 3GGH I( #778aL 9aLF 3FFG
 H
 #667B 8B$ 3FFG
 H
 #667'J 8'JV 3IIJ K 3BBC
 D
 #223!F 4!FJ 
V3GGH I 0 #778: 9:4# 3GGH  I D 3MMN5 O5n #7780 90* #==>0 ?0*R$l
 ;+
 3JJK L #::;+ <+8H$7" 3EE(-// *==$&&>-$ *
6++)#$%.
&8,/-),%3C,,';R*"%
A 8565548%8,$!F
"
%> -1"-"<"<N, 
V$ $	%&& 6:'+T$(&5&E&E, AE-14*.,;,K,K92&l CH%**<X&/#<* $B*J
 
V- -*
7,0	6, - (. 
Vc! c!J8 
V	* 	* 
V+ +
 
V
% 
% 
V
% 
% 
VC C
.3'9&"S4j%&3(3(6/+.& 0"d'R($<L&(PD& :< @>D" @E$(B @E$(3j 
V . 
V' '4.4& :D 
V 8434	 ++>"2r
##"&##4,
,26F+P$L8.*Zx?2BA$-
7)!V4&B8t IV@?/3b%7N
!54
3<,:1f1; 6 !.*@ 
% 
%-.
L	.0: :rv   r|   c                       e Zd Zd Zd Zy)
TestWidgetc           	      $   t        j                  | |       t        |       | _        | j                  j	                  dddt        dd      dd       | j                  | j                         | j                  t        j                  d             y )NTFzCourier New
   Zenburn)r  r  r  rA  rI  r   spyder)
r$   r   r|   r  rY  r   	addWidgetsetWindowIconrU   r  )ro   rj  s     rt   r   zTestWidget.__init__F  st    4( &  T4%&+M2&>-1	 	! 	K 	t{{#388H-.rv   c           	          | j                   j                  |       | j                  t        d      dt	        j
                  |      dt	        j                  |      d       | j                   j                          y )NEditorz - z (ry  )r  r  setWindowTitler)   r  basenamerJ  r  )ro   rA  s     rt   loadzTestWidget.loadO  sY    &&x0ak.1ll8.D.1kk(.CE 	F 	  "rv   N)r  r  r  r   r  r   rv   rt   r	  r	  E  s    /#rv   r	  c                     ddl m}  |d      }t        d       }|j                          |j	                  |        |j                  dd       t        j                  |j                                y )Nr   )qapplicationrU  )	test_timei  i  )	spyder.utils.qthelpersr  r	  showr  r  r  exitr8  )r  r  appwins       rt   testr  W  sM    3

#C
T
CHHJHHUOJJsCHHSYY[rv   __main__rh  )NNT)r  unicodedatar   loggingrw   r  os.pathpathr  r  r  r  r  r`  r   IPython.core.inputtransformer2r   packaging.versionr   qtpyr   qtpy.compatr   qtpy.QtCorer	   r
   r   r   r   r   r   r   r   
qtpy.QtGuir   r   r   r   r   r   r   r   r   r   r   r   r   r   r    qtpy.QtWidgetsr!   r"   r#   r$   r%   spyder_kernels.utils.dochelpersr&   three_merger'   spyder.api.panelr(   spyder.config.baser)   r*   r+   spyder.config.managerr,   $spyder.plugins.editor.api.decorationr-    spyder.plugins.editor.extensionsr.   r/   r0   r1   r2   r3   spyder.plugins.completion.apir4   r5   r6   spyder.plugins.editor.panelsr7   r8   r9   r:   r;   r<   r=   r>   "spyder.plugins.editor.utils.editorr?   r@   rA   $spyder.plugins.editor.utils.debuggerrB   %spyder.plugins.editor.utils.kill_ringrC   %spyder.plugins.editor.utils.languagesrD   rE   "spyder.plugins.editor.panels.utilsrF   rG   $spyder.plugins.completion.decoratorsrH   rI   rJ   &spyder.plugins.editor.widgets.gotolinerK   "spyder.plugins.editor.widgets.baserL   "spyder.plugins.outlineexplorer.apirM   r  rN   spyder.py3compatrO   rP   rQ   spyder.utilsrR   rS   spyder.utils.clipboard_helperrT   spyder.utils.icon_managerrU   rV   r   spyder.utils.paletterW   rX   r  rY   rZ   r[   r\   r]   spyder.utils.vcsr^   r_   spyder.utils.qstringhelpersr`   r  	nbconvertra   r  r  	getLoggerr  rj  r  r  r  ry   r|   r	  r  r%  argvr  __file__r   rv   rt   <module>rG     s   !   	   	  
  . = #  #- - -6 6 6 6 6( ( 2  # G G & ?A A? ?: : :
C C @ < O,& & A A@ F F - : ) 1 => > ; 66 
		8	$  RZZ	2==9 $ BW:# BW: BW:Pn# #$ z
388}qK Cp  Hs   6
H HH