public
Description: My Gedit plugins ;)
Homepage:
Clone URL: git://github.com/caironoleto/my-gedit-plugins.git
my-gedit-plugins / autocomplete.pyc
100644 77 lines (77 sloc) 18.985 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
³ò
b´çIc@sêddkZddkZddkZdZdZdZdZdZdZdZ d Z
ei eei ei BƒZei eei ei BƒZei eei ei BƒZd
Zd Zd eifd „ƒYZdeifd„ƒYZdS(iÿÿÿÿNs@?[a-zA-Z0-9_$]+s;@?[a-zA-Z0-9_$]+(?:(?:://|::|->|:|/|@|\.)@?[a-zA-Z0-9_$]+)+s+(?:@?[a-zA-Z0-9_$]+(?:://|::|->|:|/|@|\.))+ii2iis._>:s s> tTipcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s0Tooltip-like window for displaying a completion.cCs»tii|tiƒ|i|ƒ|idƒ|iƒiti}|i ti|ƒti
ƒ|_ ti ƒ}|idƒ|i |i ƒti ƒ}|i |ƒ|i |ƒdS(Nii(tgtktWindowt__init__t WINDOW_POPUPtset_transient_fortset_border_widtht rc_get_stylettextt STATE_NORMALt modify_bgtLabeltlabeltEventBoxtadd(tselftparenttbgt inner_boxt outer_box((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR2s      cCs|ii|ƒdS(s!Set the label's font description.N(R t modify_font(Rt font_desc((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytset_font_descriptionCscCs'|iiƒ\}}|d|dfS(sGet the size of the window.i(R t size_request(Rtwidththeight((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytget_sizeHscCs$|iddƒ|ii|ƒdS(s)Set the label text and resize the window.iN(tresizeR tset_text(RR((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyRNscCs |iiƒS(sReturn the label text.(R tget_text(R((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyRTs(t__name__t
__module__t__doc__RRRRR(((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR.s     tAutocompleteWordsPlugincBsõeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z
d „Z d
„Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zdd„Zd„Zd„Zdd„ZRS(s.Automatically complete words with the tab key.cCs\tii|ƒd|_d|_d|_d|_h|_g|_ d|_
d|_ dS(NtAutocompleteWordsPluginIDi( tgedittPluginRtNonet
completiontid_namettiptwindowtwordstdictionary_wordstlast_typed_linetregex_completion(R((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR^s       cCsÓ||_t|ƒ|_g}xFdD]>}t|d|iddƒƒ}|i|i||ƒƒq%W|i|i|ƒx!|i ƒD]}|i
|ƒq‡Wx.|i ƒD] }|i |ƒ|i |ƒq«WdS(sActivate plugin.s tab-addeds tab-removedt
on_window_t-t_N(s tab-addeds tab-removed(R)RR(tgetattrtreplacetappendtconnecttset_dataR't get_viewst connect_viewt get_documentstconnect_documenttscan(RR)tl_idstsignaltmethodtviewtdoc((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytactivateks    cCs|iƒtS(s)Hide the completion tip and return False.(thide_tiptFalse(R((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytcancel~s
cCs‰|iiƒ}|io\|i|iƒƒ}|iƒ}x$td|iƒD]}|iƒqMW|i||ƒn|i |i
ƒdS(sComplete the current word.iN( R)tget_active_documentR-tget_iter_at_markt
get_inserttcopytranget backward_chartdeletetinsert_at_cursorR&(RR?tinserttstartti((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytcomplete„s
 cCsfg}xFdD]>}t|d|iddƒƒ}|i|i||ƒƒq W|i|i|ƒdS(sConnect to document's signals.send-user-actiontloadedt on_document_R/R0N(send-user-actionRP(R1R2R3R4R5R'(RR?R;R<R=((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR9‘s cCsfg}xFdD]>}t|d|iddƒƒ}|i|i||ƒƒq W|i|i|ƒdS(sConnect to view's signals.sfocus-out-eventskey-press-eventton_view_R/R0N(sfocus-out-eventskey-press-event(R1R2R3R4R5R'(RR>R;R<R=((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR7šs cCsš|iƒ|g|iƒ|iƒ}xQ|D]I}|i|iƒ}x|D]}|i|ƒqMW|i|idƒq.Wd|_d|_ h|_
dS(sDeactivate plugin.N( RAR6R8tget_dataR't
disconnectR5R%R(R)R*(RR)twidgetstwidgetR;tl_id((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyt
deactivate£s
  cCs|iiƒd|_dS(sHide the completion tip.N(R(thideR%R&(R((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyRA³s cCsà|i|iƒƒ}|i|iƒjo|i|ƒn’|iƒo„t|i|iƒ|i ƒt
ƒƒdjoVt i |i ƒƒo<|iƒo+t i |i ƒƒp|i|ƒqÅqÉqÍn|iƒ|_dS(sScan document for words.i'N(RERFR,tget_lineR:RItlenRtget_start_itert get_end_iterRBtRE_SIMPLE_WORD_SYNTAXtmatchtget_char(RR?tcurrent_position((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyton_document_end_user_action¹s; cGs|i|ƒdS(sScan document for words.N(R:(RR?targs((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyton_document_loadedÌscCs'|iƒ}|i|ƒ|iƒdS(sHide the completion tip.N(t
get_bufferR:RA(RR>teventR?((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyton_view_focus_out_eventÑs  cCs7d}xB|D]:}|tjo|tti|ƒƒ7}q |d7}q Wd}xB|D]:}|tjo|tti|ƒƒ7}qX|d7}qXWt|ƒt|ƒ}|djo(xItd|ƒD]}|d7}qÉWn%x!td|ƒD]}|d7}qñW||jodSn||jodSndSdS(sHThis is the comparing function for the alternative words to autocompletett9it iÿÿÿÿiN(tAUTOCOMPLETE_BREAKStstrtindexR[RH(Rtxtytx1taty1tdRN((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyt len_compareØs2     cCsKd}xL|D]D}|tjo'|ttdƒti|ƒƒ7}q ||7}q Wd}xL|D]D}|tjo'|ttdƒti|ƒƒ7}qb||7}qbWt|ƒt|ƒ}|djo(xItd|ƒD]}|d7}qÝWn%x!td|ƒD]}|d7}qW||jodSn||jodSndSdS(sHThis is the comparing function for the alternative words to autocompleteRhRjiiÿÿÿÿiN(RktchrtordRmR[RH(RRnRoRpRqRrRsRN((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytlen_compare___alphaSomething÷s2 ' '   cCst|ƒ}|djogSnt|ƒtjogSnd}|d}t||ƒd}xto||dt!|dt!joMx;|djo-||dt!|dt!jo|d8}qŒW|d7}Pqc|dt!||dt!joU|}t||ƒd}||jo*|d7}||jo|d8}PqFqvqc||jo|}t||ƒd}qcPqcWtƒ}xu||jog|dt!||dt!joH||i|ƒo&|||jo|i||ƒn|d7}q‡W|S(sFilters the list of wordsiii(R[t"MIN_CHARACTERS_BEFORE_AUTOCOMPLETEtinttTruetlistt
startswithR3(Rtlist_to_filtertreference_itemtlist_to_filter_lentlist_to_filter_starttlist_to_filter_endtlist_to_filter_searchtnew_list((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytstartswith_filtersF  
,
 
 
   ,%cCsv|pgSnt|ƒtjogSntƒ}x<|D]4}|i|ƒo||jo|i|ƒq:q:W|S(sFilters the list of words(R[RxR{R|R3(RR}R~Rƒtitem((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytstartswith_filter_linearCs  cCs„tƒ}titiƒƒ}x_|D]W}ti|ƒ o@||jo3|i|td|tdƒ}|i|ƒq%q%W|S(Nii( R{R?RERFtRE_COMPOUND_WORD_SYNTAXR_R2t TIP_EMPHASISR3(RR}R~RƒRaR…t emph_item((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytsimple_contains_filterVs "cCsÎtƒ}d}xr|D]j}|djo |djp|djo3|djo&|d|iƒ|iƒd7}q||7}qWxC|D];}ti|ƒ o$ti||ƒo|i|ƒq‹q‹W|S(NRhRqtztAtZt[t](R{tlowertupperR‡R_tretfindallR3(RR}R~Rƒtreference_item_case_insensitivetcR…((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytre_contains_filter_s 4&$c CsÉ|itii@o|iƒSn|itii@o|idjo|iƒSntii|iƒ}|djo2|i d jo|iƒSn|i ƒt }nt }tii|iƒdjo3|i d jo|iƒSn|idƒt Sntii|iƒdjo3|i d jo|iƒSn|idƒt Sn|iƒ}|i|iƒƒ}|idjodtii|iƒdjo/|iƒ}|i|iƒƒ}|iƒqá|p|iƒSqán|iƒiƒ}|o!|i|d|dt ƒ}ni|iƒ} xD| iƒp6| iƒtid | iƒƒo| iƒPq*q*W|i| |t ƒ}|iƒ} x| iƒosti|i| |t ƒƒ}
t|
ƒdjo3t|
dƒt|i| |t ƒƒjoq’q’| iƒPq’W|i| |t ƒ} |p| |i7} n| iƒ} t } xº| t jo¬t } | iƒoPnxtdtdƒD]x}| iƒt i|i| | t ƒƒ}
t|
ƒdjo7t|
dƒt|i| | t ƒƒjo t } PqŽqŽWqUWx%tdtdƒD]}| iƒq#W|i| |t ƒ}|p||i7}n|i!|i"|ƒ}|i#|i$ƒ|i%||ƒ}|}|}|pG|i!|i"| ƒ}|i#|i$ƒ|i%|| ƒ}|}| }n|idjoH|itii@o4|i&|i"|ƒ}|}d
}t|ƒ|_'n
d|_'d |_(d
}d}xc|D][}|i(p||_(|t)7}n |t*7}||d }|d7}|t+joPqrqrWtii|iƒdjo|iƒn|i(d jo!|iƒ|ot Sq,t Sn|i(t|ƒ|_ ti,}|i-|ƒ}|i.||i/|i0ƒ\}}|i1|i2||ƒ\}}|i3|i4ƒ||ƒ|ot Snt Sd S( s2Display a completion or complete the current word.t/tTabtDowntUpi€t BackSpaceiis\sRhs
N(5tstateRtgdkt CONTROL_MASKRCt MOD1_MASKtstringt keyval_nametkeyvalR&R%RORzRBtselect_alternativeReRERFRItget_selection_boundsRRGtis_startR’R_R`t forward_charR^R“R[RHtMAX_COMPOSITION_TOKEN_SIZEt$RE_BEGINNING_OF_COMPOUND_WORD_SYNTAXR„R+tsortRttaggressive_filterR–R-t complete_wordtMARKERtSPACEStMAX_SUGGESTIONStTEXT_WINDOW_TEXTtget_iter_locationtbuffer_to_window_coordsRnRottranslate_coordinatesR)tshow_tiptrstrip(RR>Rftkeytcomplete_key_pressedR?RLtselection_iterst
regex_wordRMt
match_listtincomplete_simple_wordtstart_compoundt match_successRNtincomplete_compound_wordtcompound_word_alternativest alternativest
incompletetsimple_word_alternativestwords_containing_regextdisplay_stringtalternatives_countertwordR)trectRnRo((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyton_view_key_press_eventlsì$ 

    !  


  ?
   
?
$  
 

 
 !c Csót|ƒ}|tjogSnt|ƒtjo|Sng}xš|D]’}t|ƒ}||}x=ttƒD]/}||jot||i|ƒƒ}qrqrW|||d |jo||||d g7}qIqIW|i|iƒ|S(Ni( R[Rxt!MAX_SUGGESTIONS_BEFORE_USE_BREAKSR{RktminRmR©Rt( Rtinitial_alternativesRÀt
cursor_postfiltered_alternativesR…t break_postitem_endt separator((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyRªs$   
   !cCsX|iƒiƒ}|iƒ}|ii|ƒ|i|iƒƒ|i|iƒƒdS(s%Connect the document and view in tab.N(tget_viewtget_pango_contexttget_font_descriptionR(RR9t get_documentR7(RR)ttabtcontextR((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyton_window_tab_added0s
 cCs4|iƒ}||ijo|ii|ƒndS(sRemove document's word set.N(RÓR*tpop(RR)RÔR?((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyton_window_tab_removed:s t ALL_WORDScCs|i|iƒŒ}|djoFtti|ƒƒ|i|<|i|iti|ƒƒ|i|<n[|djo tti|ƒƒ|i|<n.|djo tti|ƒƒ|i|<ntgƒ|_ x'|ii
ƒD]}|i i |ƒqáWt |i ƒ|_ |i i ƒdS(sScan document for new words.RÙt SIMPLE_WORDStCOMPOUND_WORDSN(Rt
get_boundst frozensetR‡R“R*tunionR^tsetR+tvaluestupdateR{R©(RR?t what_to_scanRRÅ((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR:As *    cCsY|iiƒ\}}|ii||d||dƒ|ii|ƒ|iiƒdS(s7Show a completion tip in the main window's coordinates.i0N(R)t get_positionR(tmoveRtshow_all(RRRnRotroot_xtroot_y((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR³Ts#cCsèd}|i}x˜|iiƒditƒD]z}|it|ƒo`|djoE||ittƒ7}|i ƒt
|ƒ|_ |i dƒ|_q¦||7}q,q,Wt
|ƒdjo|ii |i dƒƒn |iƒtS(sQRefresh the alternative word list when 'Tab' is pressed and a completion is done.Rhs
s
i(R«R(Rt
splitlinesRzR|R­R2R¬tstripR[R&RR´RA(RRÃtlocal_complete_wordt current_line((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pytrefresh_tip_on_complete\s  
cCs |iiƒd}d}d}t}|itƒ}t|ƒdjotSnxˆ|D]€}|djo
|}n|djo›|t|idjot}|i ||i tt
ƒƒ}|i ||i t
tƒƒ}|i ƒt|iƒt|i ƒ|_ |i ƒ|_Pqn|djo¨|t|idjoŒ|djot}|i ||i tt
ƒƒ}|i ||i t
tƒƒ}|i ƒt|iƒt|i ƒ|_ |i ƒ|_PqÐn|}qVW|p|djox|i ||i tt
ƒƒ}|i ||i t
tƒƒ}|i ƒt|iƒt|i ƒ|_ |i ƒ|_n|djox|i ||i t
tƒƒ}|i ||i tt
ƒƒ}|i ƒt|iƒt|i ƒ|_ |i ƒ|_qïn|ii |idƒƒtS(sYMakes all the necessary modifications when an alternative word is selected from the list.s
RhiR™RšN(R(RR%RBRèRzR[R¬R«R2R­RéR&RR´(Rt directionRÃt previous_linet
first_linet marker_movedt display_linesRë((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR£osR 
 )  %) 
 ) )N(RRR RR@RCROR9R7RXRARbRdRgRtRwR„R†RŠR–RÇRªRÖRØR:R³RìR%R£(((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pyR!Zs4          -  © 
   (R#RR’tSIMPLE_WORD_SYNTAXtCOMPOUND_WORD_SYNTAXt!BEGINNING_OF_COMPOUND_WORD_SYNTAXR§R®RÈRxRktcompiletUNICODEt MULTILINER^R‡R¨R­R¬RRR$R!(((s7/home/caironoleto/.gnome2/gedit/plugins/autocomplete.pys<module>s"   ,