123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664(*
* lTerm_vi.ml
* ------------
* Copyright : (c) 2020, ZAN DoYe <zandoye@gmail.com>
* Licence : BSD3
*
* This file is a part of Lambda-Term.
*)moduleConcurrent=structmoduleThread=structincludeLwtletrun=Lwt_unix.run[@@ocaml.warning"-3"]letsleep=Lwt_unix.sleependmoduleMsgBox=structincludeLwt_mvarletget=Lwt_mvar.takeletcreate=Lwt_mvar.create_emptyendendmoduleQuery=struct(*
(* left right *)
| Left of int (* h *)
| Right of int (* l *)
| Right_nl of int (* l, including newline *)
| Line_FirstChar of int (* 0 *)
| Line_FirstNonBlank of int (* ^ *)
| Line_LastChar of int (* $ *)
| Line_LastChar_nl of int (* $ *)
| Line_LastNonBlank of int (* g_ *)
| Line_LastNonBlank_nl of int (* g_ *)
(* up down *)
| Upward of int (* k *)
| Downward of int (* j *)
| GotoLine of int (* gg or G *)
| GotoLine_first (* gg *)
| GotoLine_last (* G *)
(* word *)
| Word of int (* w *)
| WORD of int (* W *)
| Word_end of int (* e *)
| WORD_end of int (* E *)
| Word_back of int (* b *)
| WORD_back of int (* B *)
| Word_back_end of int (* ge *)
| WORD_back_end of int (* gE *)
(* line *)
| Line
(* occurrence *)
| Occurrence_inline of string
| Occurrence_inline_back of string
| Occurrence_inline_till of string
| Occurrence_inline_till_back of string
(* text object *)
| Sentence_backword of int (* ( *)
| Sentence_forward of int (* ) *)
| Paragraph_backward of int (* { *)
| Paragraph_forward of int (* } *)
(* text object selection *)
| Word_include of int (* aw *)
| Word_inner of int (* iw *)
| WORD_include of int (* aW *)
| WORD_inner of int (* iW *)
| Sentence_include of int (* as *)
| Sentence_inner of int (* is *)
| Paragraph_include of int (* ap *)
| Paragraph_inner of int (* ip *)
| Parenthesis_include of int (* a( a) *)
| Parenthesis_inner of int (* i( i) *)
| Bracket_include of int (* a[ a] *)
| Bracket_inner of int (* i[ i] *)
| AngleBracket_include of int (* a< a> *)
| AngleBracket_inner of int (* i< i> *)
| Brace_include of int (* a{ a} *)
| Brace_inner of int (* i{ i} *)
| Quote_include of (string * int)
| Quote_inner of (string * int)
(* match *)
| Match
*)letleftnctx=(* h *)letn=max0ninletedit=Zed_edit.editctxinletlines=Zed_edit.lineseditandline_idx=Zed_edit.linectxinletline_len=Zed_lines.line_lengthlinesline_idxinletcolumn=Zed_edit.columnctxinletdest=(column-n)|>max0|>minline_leninletpositon=Zed_edit.positionctxinletdelta=column-destin(positon-delta,delta)letright?(newline=false)nctx=(* l *)letn=max0ninletedit=Zed_edit.editctxinletlines=Zed_edit.lineseditandline_idx=Zed_edit.linectxinletline_len=max0@@letlen=Zed_lines.line_lengthlinesline_idxinifnewlinethenlenelselen-1inletcolumn=Zed_edit.columnctxinletdest=(column+n)|>max0|>minline_leninletpositon=Zed_edit.positionctxinletdelta=dest-columnin(positon+delta,delta)letline_FirstChar_nctx=(* 0 *)letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditandline_idx=Zed_edit.linectxinletstart=Zed_lines.line_startlinesline_idxinletcolumn=Zed_edit.columnctxin(start,column-start)letline_LastChar?(newline=false)nctx=(* ^ *)letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditandline_idx=Zed_edit.linectxinletcount=Zed_lines.countlinesinletline_idx=ifn>1thenmincount@@line_idx+(n-1)elseline_idxinletstop=Zed_lines.line_stoplinesline_idxinifnewlinethenstopelsemax0(stop-1)openCamomileLibraryDefault.Camomileletget_category?(nl_as_sp=false)uchar=ifuchar=Zed_utf8.extract"\n"0&&nl_as_spthen`ZselseUCharInfo.general_categoryucharletget_boundarymulti_linectx=letedit=Zed_edit.editctxinifmulti_linethen(0,Zed_rope.length(Zed_edit.textedit))elseletlines=Zed_edit.lineseditandline_idx=Zed_edit.linectxin(Zed_lines.line_startlinesline_idx,Zed_lines.line_stoplinesline_idx)letis_space=function|`Cc|`Zs|`Zl|`Zp|`Mn->true|_->falseletis_not_spacec=not(is_spacec)letcategory_equalc1c2=matchc1,c2with|`Ll,`Lu|`Lu,`Ll->true|_->c1=c2letcategory_equal_blankc1c2=letb1=is_spacec1andb2=is_spacec2inb1=b2letnext_category?(nl_as_sp=true)?(is_equal=category_equal)~pos~stoptext=letstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletzip=Zed_rope.Zip.make_ftextposinletrecskip_currzippos=ifpos<stopthenletzchar,zip=Zed_rope.Zip.nextzipinletcategory=get_category~nl_as_sp(Zed_char.corezchar)inifis_equalcategorystart_categorythenskip_currzip(pos+1)elseposelseposinskip_currzipposletprev_category?(nl_as_sp=true)?(is_equal=category_equal)~pos~starttext=letstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletzip=Zed_rope.Zip.make_ftextposinletrecskip_currzippos=ifpos>startthenletzchar,zip=Zed_rope.Zip.prevzipinletcategory=get_category~nl_as_sp(Zed_char.corezchar)inifis_equalcategorystart_categorythenskip_currzip(pos-1)elseposelseposin(skip_currzippos)-1letgoto_linectxindex=letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletindex=minindex(Zed_lines.countlines)inZed_lines.line_startlinesindexletnext_linectxdelta=letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletlines=Zed_edit.lineseditinletindex=Zed_edit.linectxinletcursor=Zed_edit.cursorctxinletcount=Zed_lines.countlinesinifindex=Zed_lines.countlinesthenZed_rope.lengthtext-1elsebeginletstop=ifindex+delta>=countthenZed_rope.lengthtextelseZed_lines.line_startlines(index+delta+1)-1inletwanted_idx=Zed_lines.get_idx_by_widthlines(mincount(index+delta))(Zed_cursor.get_wanted_columncursor)inmax(Zed_lines.line_startlines(index+delta))(minwanted_idx(stop-1))endletprev_linectxdelta=letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletcursor=Zed_edit.cursorctxinletindex=Zed_cursor.get_linecursorinifindex-delta<0then0elseletstop=Zed_lines.line_startlines(index-delta+1)-1inletwanted_idx=Zed_lines.get_idx_by_widthlines(index-delta)(Zed_cursor.get_wanted_columncursor)inmax(Zed_lines.line_startlines(index-delta))(minwanted_idx(stop-1))letnext_word'?(multi_line=true)~next_category~pos~stoptext=letnl_as_sp=multi_lineinletstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletnext=next_category~nl_as_sp~pos~stoptextinifis_spacestart_categorythennext(* currently at a space, just skip spaces *)elseifnext<stopthen(* skip potential subsequent spaces after skip current word*)letzchar=Zed_rope.gettextnextinletcore=Zed_char.corezcharinifis_space(get_category~nl_as_spcore)then(* skip subsequent spaces *)next_category~nl_as_sp~pos:next~stoptextelsenextelsestopletnext_word?multi_line~pos~stoptext=letnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equalinnext_word'?multi_line~next_category~pos~stoptextletnext_WORD?multi_line~pos~stoptext=letnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equal_blankinnext_word'?multi_line~next_category~pos~stoptextletline_FirstNonBlank_nctx=(* ^ *)letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletlines=Zed_edit.lineseditandline_idx=Zed_edit.linectxinletline_len=Zed_lines.line_lengthlinesline_idxinletstart,stop=get_boundaryfalsectxinifline_len>0thenifis_space(get_category(Zed_char.core(Zed_rope.gettextstart)))thenmin(stop-1)(next_word~multi_line:false~pos:start~stoptext)elsestartelse0letprev_word'?(multi_line=true)~prev_category~pos~starttext=ifpos<=startthenstartelseletnl_as_sp=multi_lineinletstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreandbefore_start=letzchar=Zed_rope.gettext(pos-1)inletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletprev=prev_category~nl_as_sp~pos~starttextin1+ifcategory_equalstart_categorybefore_startthenifis_spacestart_categorythenprev_category~nl_as_sp~pos:prev~starttextelseprevelseifis_spacebefore_startthenletprev=prev_category~nl_as_sp~pos:prev~starttextinifprev<=startthenprevelseprev_category~nl_as_sp~pos:prev~starttextelseprev_category~nl_as_sp~pos:prev~starttextletprev_word?multi_line~pos~starttext=letprev_category~nl_as_sp=prev_category~nl_as_sp~is_equal:category_equalinprev_word'?multi_line~prev_category~pos~starttextletprev_WORD?multi_line~pos~starttext=letprev_category~nl_as_sp=prev_category~nl_as_sp~is_equal:category_equal_blankinprev_word'?multi_line~prev_category~pos~starttextletnext_word_end'?(multi_line=true)~next_category~pos~stoptext=letpos=ifpos>=(stop-1)thenstopelseletnl_as_sp=multi_lineinletstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreandafter_start=letzchar=Zed_rope.gettext(pos+1)inletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletnext=next_category~nl_as_sp~pos~stoptextinifnext>=stopthenstopelseifcategory_equalstart_categoryafter_start&&is_not_spacestart_categorythennextelseletnext=next_category~nl_as_sp~pos:next~stoptextinifnext>=stopthenstopelseifis_spacestart_category||is_not_spaceafter_startthennextelsenext_category~nl_as_sp~pos:next~stoptextinmax0@@pos-1letnext_word_end?multi_line~pos~stoptext=letnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equalinnext_word_end'?multi_line~next_category~pos~stoptextletnext_WORD_end?multi_line~pos~stoptext=letnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equal_blankinnext_word_end'?multi_line~next_category~pos~stoptextletprev_word_end'?(multi_line=true)~prev_category~pos~starttext=ifpos<=startthenstartelseletnl_as_sp=multi_lineinletstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletprev=prev_category~nl_as_sp~pos~starttextinifprev<=startthenstartelseifis_spacestart_categorythenprevelseletbefore_category=letzchar=Zed_rope.gettextprevinletcore=Zed_char.corezcharinget_category~nl_as_spcoreinifis_spacebefore_categorythenprev_category~nl_as_sp~pos:prev~starttextelseprevletprev_word_end?multi_line~pos~starttext=letprev_category~nl_as_sp=prev_category~nl_as_sp~is_equal:category_equalinprev_word_end'?multi_line~prev_category~pos~starttextletprev_WORD_end?multi_line~pos~starttext=letprev_category~nl_as_sp=prev_category~nl_as_sp~is_equal:category_equal_blankinprev_word_end'?multi_line~prev_category~pos~starttextletoccurrence_char~pos~stopchrtext=tryletzip=Zed_rope.Zip.make_ftextposinletnext=Zed_rope.Zip.find_f(func->Zed_char.comparechrc=0)zipinletnext_pos=Zed_rope.Zip.offsetnextinifnext_pos<stopthenSomenext_poselseNonewith_->Noneletoccurrence_char_back~pos~startchrtext=tryletzip=Zed_rope.Zip.make_ftextposinletprev=Zed_rope.Zip.find_b(func->Zed_char.comparechrc=0)zipinletprev_pos=Zed_rope.Zip.offsetprevinifprev_pos>startthenSome(prev_pos-1)elseNonewith_->Noneletoccurrence~pos~stop~cmptext=tryletzip=Zed_rope.Zip.make_ftextposinletnext=Zed_rope.Zip.find_fcmpzipinletnext_pos=Zed_rope.Zip.offsetnextinifnext_pos<stopthenSome(next_pos,Zed_rope.gettextnext_pos)elseNonewith_->Noneletoccurrence_back~pos~start~cmptext=tryletzip=Zed_rope.Zip.make_ftextposinletprev=Zed_rope.Zip.find_bcmpzipinletprev_pos=Zed_rope.Zip.offsetprevinifprev_pos>startthenSome(prev_pos-1,Zed_rope.gettext(prev_pos-1))elseNonewith_->Noneletoccurrence_pare_raw~pos~level~start~stoppairtext=letleft,right=pairinletrecfind_leftlevelpos=ifpos>=starttheniflevel>0thenmatchoccurrence_char_back~pos~startlefttextwith|Somepos->find_left(level-1)(pos-1)|None->NoneelseSome(pos+1)elseNoneinletrecfind_rightlevelpos=ifpos<stoptheniflevel>0thenmatchoccurrence_char~pos~stoprighttextwith|Somepos->find_right(level-1)(pos-1)|None->NoneelseSome(pos-1)elseNoneiniflevel>0thenmatchfind_leftlevel(pos+1)with|Someleft->(matchfind_rightlevelposwith|Someright->Some(left,right)|None->None)|None->NoneelseNoneletoccurrence_pare~pos~level~start~stoppairtext=letleft,right=pairinletequalab=Zed_char.compareab=0inletcmpc=equalcleft||equalcrightinletrecfind_leftlevelpos=iflevel>0thenifpos>=startthenmatchoccurrence_back~pos~start~cmptextwith|Some(pos,c)->ifequalcleftthenfind_left(level-1)(pos-1)elsefind_left(level+1)(pos-1)|None->NoneelseNoneelseSome(pos+1)inletrecfind_rightlevelpos=iflevel>0thenifpos<stopthenmatchoccurrence~pos~stop~cmptextwith|Some(pos,c)->ifequalcrightthenfind_right(level-1)(pos+1)elsefind_right(level+1)(pos+1)|None->NoneelseNoneelseSome(pos-1)iniflevel>0&&pos>=start&&pos<stopthenletinit_pos=ifequal(Zed_rope.gettextpos)leftthenpos+1elseifequal(Zed_rope.gettextpos)rightthenposelsepos+1inmatchfind_leftlevelinit_poswith|Someleft->(matchfind_right1(left+1)with|Someright->Some(left,right)|None->None)|None->NoneelseNoneletitem_match~start~stoppostext=matchZed_rope.gettextpos|>Zed_char.to_utf8with|"("->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"(",Zed_char.of_utf8")")textwith|Some(_,right)->Someright|None->None)|")"->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"(",Zed_char.of_utf8")")textwith|Some(left,_)->Someleft|None->None)|"["->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"[",Zed_char.of_utf8"]")textwith|Some(_,right)->Someright|None->None)|"]"->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"[",Zed_char.of_utf8"]")textwith|Some(left,_)->Someleft|None->None)|"<"->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"<",Zed_char.of_utf8">")textwith|Some(_,right)->Someright|None->None)|">"->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"<",Zed_char.of_utf8">")textwith|Some(left,_)->Someleft|None->None)|"{"->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"{",Zed_char.of_utf8"}")textwith|Some(_,right)->Someright|None->None)|"}"->(matchoccurrence_pare~pos~level:1~start~stop(Zed_char.of_utf8"{",Zed_char.of_utf8"}")textwith|Some(left,_)->Someleft|None->None)|_->Noneletinclude_word'?(multi_line=true)~next_category~pos~stoptext=ifZed_rope.lengthtext=0thenNoneelseifpos>=stopthenNoneelseletnl_as_sp=multi_lineinletstart_category=letzchar=Zed_rope.gettextposinletcore=Zed_char.corezcharinget_category~nl_as_spcoreinletpos_begin=ifis_spacestart_categorythenletnext=next_category~nl_as_sp~pos~stoptextinifnext<stopthenSomenextelseNoneelseletprev=prev_category~nl_as_sp~pos~start:0textinifprev>=pos-1thenSomeposelseSome(prev+1)inmatchpos_beginwith|Somepos_begin->letpos_end=next_word'~multi_line~next_category~pos:pos_begin~stoptext-1inSome(pos_begin,pos_end)|None->Noneletinclude_word?multi_line~pos~stoptext=letnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equalininclude_word'?multi_line~next_category~pos~stoptextletinclude_WORD?multi_line~pos~stoptext=letnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equal_blankininclude_word'?multi_line~next_category~pos~stoptextletinner_word'?(multi_line=true)~prev_category~next_category~pos~stoptext=ifZed_rope.lengthtext=0thenNoneelseletnl_as_sp=multi_lineinletpos_begin=ifpos=0then0elseprev_category~nl_as_sp~pos~start:0text+1andpos_end=next_category~nl_as_sp~pos~stoptext-1inSome(pos_begin,pos_end)letinner_word?multi_line~pos~stoptext=letprev_category~nl_as_sp=prev_category~nl_as_sp~is_equal:category_equalandnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equalininner_word'?multi_line~prev_category~next_category~pos~stoptextletinner_WORD?multi_line~pos~stoptext=letprev_category~nl_as_sp=prev_category~nl_as_sp~is_equal:category_equal_blankandnext_category~nl_as_sp=next_category~nl_as_sp~is_equal:category_equal_blankininner_word'?multi_line~prev_category~next_category~pos~stoptextendmoduleVi=Mew_vi.Core.Make(Concurrent)includeViletof_lterm_code:LTerm_key.code->Mew_vi.Key.code=function|Charchr->Char(Zed_utf8.escaped_charchr)|Enter->Enter|Escape->Escape|Tab->Tab|Up->Up|Down->Down|Left->Left|Right->Right|F1->F1|F2->F2|F3->F3|F4->F4|F5->F5|F6->F6|F7->F7|F8->F8|F9->F9|F10->F10|F11->F11|F12->F12|Next_page->Next_page|Prev_page->Prev_page|Home->Home|End->End|Insert->Insert|Delete->Delete|Backspace->Backspaceletof_vi_code:Mew_vi.Key.code->LTerm_key.code=function|Charbin->Char(Zed_utf8.extractbin0)|Enter->Enter|Escape->Escape|Tab->Tab|Up->Up|Down->Down|Left->Left|Right->Right|F1->F1|F2->F2|F3->F3|F4->F4|F5->F5|F6->F6|F7->F7|F8->F8|F9->F9|F10->F10|F11->F11|F12->F12|Next_page->Next_page|Prev_page->Prev_page|Home->Home|End->End|Insert->Insert|Delete->Delete|Backspace->Backspaceletof_lterm_keylterm_key={Mew_vi.Key.control=lterm_key.LTerm_key.control;meta=lterm_key.meta;shift=lterm_key.shift;code=of_lterm_codelterm_key.code;}letof_vi_keyvi_key={LTerm_key.control=vi_key.Mew_vi.Key.control;meta=vi_key.meta;shift=vi_key.shift;code=of_vi_codevi_key.code;}openLTerm_read_line_baseopenLwtletperformvi_editctxexecaction=letlist_makeelmn=letreccreateaccn=ifn>0thencreate(elm::acc)(n-1)elseaccincreate[]ninletlist_dupelmn=letreccreateaccn=ifn>0thencreate(elm::acc)(n-1)elseaccincreate[]n|>List.concatinletdelete~register?(line=false)?boundarystartlen=letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinleteot=Zed_rope.lengthtextinletlines=Zed_edit.lineseditinletboundary_start,boundary_end=matchboundarywith|Some(b,e)->b,e|None->0,eotinlet_ori_start,_ori_len,_ori_stop=start,len,start+leninletstart,len,stop=letstart=maxboundary_start_ori_startinletstop=minboundary_end_ori_stopinletlen=stop-startinstart,len,stopiniflen>0thenletend_pos=ifstop>=eotthenletend_pos=max0@@start-1inifeot>0thenif(=)(Zed_char.core(Zed_rope.gettextend_pos))(Zed_utf8.extract"\n"0)thenmax0@@end_pos-1elseend_poselseend_poselseif(=)(Zed_char.core(Zed_rope.gettextstop))(Zed_utf8.extract"\n"0)thenmax(start-1)Zed_lines.(line_startlines(line_indexlinesstart))elsestartinletcontent=letstr=Zed_rope.subtextstartlen|>Zed_rope.to_string|>Zed_string.to_utf8iniflinethenVi.Interpret.Register.LinestrelseVi.Interpret.Register.Seqstrinvi_edit#set_registerregistercontent;vi_edit#set_register"\""content;letdel_len=ifline&&stop<eotthenlen+1elseleninexec[Edit(Zed(Zed_edit.Gotostart));Edit(Zed(Zed_edit.Kill_next_charsdel_len));Edit(Zed(Zed_edit.Gotoend_pos))]elsereturn(ContinueLoop[])inletchange~register?(line=false)?boundarystartlen=letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinleteot=Zed_rope.lengthtextinletboundary_start,boundary_end=matchboundarywith|Some(b,e)->b,e|None->0,eotinlet_ori_start,_ori_len,_ori_stop=start,len,start+leninletstart,len,_stop=letstart=maxboundary_start_ori_startinletstop=minboundary_end_ori_stopinletlen=stop-startinstart,len,stopiniflen>0thenletcontent=letstr=Zed_rope.subtextstartlen|>Zed_rope.to_string|>Zed_string.to_utf8iniflinethenVi.Interpret.Register.LinestrelseVi.Interpret.Register.Seqstrinvi_edit#set_registerregistercontent;vi_edit#set_register"\""content;exec[Edit(Zed(Zed_edit.Gotostart));Edit(Zed(Zed_edit.Kill_next_charslen));Edit(Zed(Zed_edit.Gotostart))]elsereturn(ContinueLoop[])inletyank~register?(line=false)startlen=letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletcontent=letstr=Zed_rope.subtextstartlen|>Zed_rope.to_string|>Zed_string.to_utf8iniflinethenVi.Interpret.Register.LinestrelseVi.Interpret.Register.Seqstrinvi_edit#set_registerregistercontent;vi_edit#set_register"\""content;Zed_edit.copy_sequencectxstartlen;return(ContinueLoop[])inletsetup_pos()=letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinlettext_len=Zed_rope.lengthtextin(iftext_len>0thenletstep=ifpos>=text_lenthenpos-1elseposinletstep=if(=)(Zed_char.core(Zed_rope.gettextstep))(Zed_utf8.extract"\n"0)thenmax0@@step-1elsestepinexec[Edit(Zed(Zed_edit.Gotostep))]elseexec[Edit(Zed(Zed_edit.Goto_bol))])inletpare_includepairlevelaction=lettext=Zed_edit.text(Zed_edit.editctx)inletpos=Zed_edit.positionctxinletstart=0andstop=Zed_rope.lengthtextin(matchQuery.occurrence_pare~pos~level~start~stoppairtextwith|Some(left,right)->actionleft(right+1-left)|None->return(ContinueLoop[]))inletpare_innerpairlevelaction=lettext=Zed_edit.text(Zed_edit.editctx)inletpos=Zed_edit.positionctxinletstart=0andstop=Zed_rope.lengthtextin(matchQuery.occurrence_pare~pos~level~start~stoppairtextwith|Some(left,right)->action(left+1)(right-(left+1))|None->return(ContinueLoop[]))inmatchactionwith|Vi_action.Insert(insert,count)->(matchinsertwith|Newline_below_s->exec@@(Edit(Zed(Zed_edit.Goto_eol)))::(list_make(Edit(Zed(Zed_edit.Newline)))count)|Newline_above_s->exec@@list_dup[Edit(Zed(Zed_edit.Goto_bol));Edit(Zed(Zed_edit.Newline));Edit(Zed(Zed_edit.Prev_line));]count|_->return(ContinueLoop[]))|Motion(motion,count)->(matchmotionwith|Left->letrecleftn=ifn>0thenletpos,_delta=Query.leftnctxinexec(list_make(Edit(Zed(Zed_edit.Gotopos)))1)>>=(function|Result_asr->returnr|ContinueLoop_->left(n-1))elsereturn(ContinueLoop[])inleftcount|Right->letrecrightn=ifn>0thenletpos,_delta=Query.rightnctxinexec(list_make(Edit(Zed(Zed_edit.Gotopos)))1)>>=(function|Result_asr->returnr|ContinueLoop_->right(n-1))elsereturn(ContinueLoop[])inrightcount|Right_nl->letnewline=trueinletrecrightn=ifn>0thenletpos,_delta=Query.right~newlinenctxinexec(list_make(Edit(Zed(Zed_edit.Gotopos)))1)>>=(function|Result_asr->returnr|ContinueLoop_->right(n-1))elsereturn(ContinueLoop[])inrightcount|Upward->letpos=Query.prev_linectxcountinexec[Edit(Zed(Zed_edit.Set_pospos))]|Downward->letpos=Query.next_linectxcountinexec[Edit(Zed(Zed_edit.Set_pospos))]|Word->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletrecnext_wordn=letpos=Zed_edit.positionctxinifn>0&&pos<stopthenletnext=min(stop-1)(Query.next_word~pos~stoptext)inexec[Edit(Zed(Zed_edit.Gotonext))]>>=(function|Result_asr->returnr|ContinueLoop_->next_word(n-1))elsereturn(ContinueLoop[])innext_wordcount|WORD->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletrecnext_wordn=letpos=Zed_edit.positionctxinifn>0&&pos<stopthenletnext=min(stop-1)(Query.next_WORD~pos~stoptext)inexec[Edit(Zed(Zed_edit.Gotonext))]>>=(function|Result_asr->returnr|ContinueLoop_->next_word(n-1))elsereturn(ContinueLoop[])innext_wordcount|Word_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletrecprev_wordn=letpos=min(stop-1)(Zed_edit.positionctx)inifn>0&&pos>startthenletprev=maxstart(Query.prev_word~pos~starttext)inexec(list_make(Edit(Zed(Zed_edit.Gotoprev)))1)>>=(function|Result_asr->returnr|ContinueLoop_->prev_word(n-1))elsereturn(ContinueLoop[])inprev_wordcount|WORD_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletrecprev_wordn=letpos=min(stop-1)(Zed_edit.positionctx)inifn>0&&pos>startthenletprev=maxstart(Query.prev_WORD~pos~starttext)inexec[Edit(Zed(Zed_edit.Gotoprev))]>>=(function|Result_asr->returnr|ContinueLoop_->prev_word(n-1))elsereturn(ContinueLoop[])inprev_wordcount|Word_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletrecnext_wordn=letpos=Zed_edit.positionctxinifn>0&&pos<stopthenletnext=min(stop-1)(Query.next_word_end~pos~stoptext)inexec[Edit(Zed(Zed_edit.Gotonext))]>>=(function|Result_asr->returnr|ContinueLoop_->next_word(n-1))elsereturn(ContinueLoop[])innext_wordcount|WORD_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletrecnext_wordn=letpos=Zed_edit.positionctxinifn>0&&pos<stopthenletnext=min(stop-1)(Query.next_WORD_end~pos~stoptext)inexec[Edit(Zed(Zed_edit.Gotonext))]>>=(function|Result_asr->returnr|ContinueLoop_->next_word(n-1))elsereturn(ContinueLoop[])innext_wordcount|Word_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletrecprev_wordn=letpos=min(stop-1)(Zed_edit.positionctx)inifn>0&&pos>startthenletprev=maxstart(Query.prev_word_end~pos~starttext)inexec[Edit(Zed(Zed_edit.Gotoprev))]>>=(function|Result_asr->returnr|ContinueLoop_->prev_word(n-1))elsereturn(ContinueLoop[])inprev_wordcount|WORD_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletrecprev_wordn=letpos=min(stop-1)(Zed_edit.positionctx)inifn>0&&pos>startthenletprev=maxstart(Query.prev_WORD_end~pos~starttext)inexec[Edit(Zed(Zed_edit.Gotoprev))]>>=(function|Result_asr->returnr|ContinueLoop_->prev_word(n-1))elsereturn(ContinueLoop[])inprev_wordcount|Line_FirstChar->exec(list_make(Edit(ZedZed_edit.Goto_bol))count)|Line_FirstNonBlank->letnonblank=Query.line_FirstNonBlank1ctxinexec[Edit(Zed(Zed_edit.Gotononblank))]|Line_LastChar->letreclastCharn=ifn>0thenletpos=Query.line_LastCharnctxinexec[Edit(Zed(Zed_edit.Gotopos))]>>=(function|Result_asr->returnr|ContinueLoop_->lastChar(n-1))elsereturn(ContinueLoop[])inlastCharcount|Line_LastChar_nl->letnewline=trueinletreclastCharn=ifn>0thenletpos=Query.line_LastChar~newlinenctxinexec[Edit(Zed(Zed_edit.Gotopos))]>>=(function|Result_asr->returnr|ContinueLoop_->lastChar(n-1))elsereturn(ContinueLoop[])inlastCharcount|GotoLine->letpos=Query.goto_linectxcountinexec[Edit(Zed(Zed_edit.Set_pospos))]|GotoLine_first->exec[Edit(Zed(Zed_edit.Goto_bot))]|GotoLine_last->exec[Edit(Zed(Zed_edit.Goto_eot));Edit(Zed(Zed_edit.Prev_char))]|Occurrence_inlinechr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somepos->exec[Edit(Zed(Zed_edit.Gotopos))]|None->return(ContinueLoop[]))|Occurrence_inline_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos-1)countwith|Somepos->exec[Edit(Zed(Zed_edit.Gotopos))]|None->return(ContinueLoop[]))|Occurrence_inline_tillchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somepos->exec[Edit(Zed(Zed_edit.Goto(pos-1)))]|None->return(ContinueLoop[]))|Occurrence_inline_till_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos-1)countwith|Somepos->exec[Edit(Zed(Zed_edit.Goto(pos+1)))]|None->return(ContinueLoop[]))|Match->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.item_match~start:0~stoppostextwith|Somepos->exec[Edit(Zed(Zed_edit.Gotopos))]|None->return(ContinueLoop[]))|_->return(ContinueLoop[]))|Delete(register,motion,count)->letdelete=delete~registerin(matchmotionwith|Left->letpos,delta=Query.leftcountctxindeleteposdelta|Right->letnewline=trueinletpos,delta=Query.right~newlinecountctxinletpos=pos-deltaindeleteposdelta|Right_nl->letnewline=trueinletpos,delta=Query.right~newlinecountctxinletpos=pos-deltainexec[Edit(Zed(Zed_edit.Gotopos));Edit(Zed(Zed_edit.Kill_next_charsdelta));]|Upward->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletdest=max0(line-count)inletline_delta=line-destinifline_delta>0thenletpos_start=Zed_lines.line_startlinesdestandpos_end=Zed_lines.line_stoplineslineinletpos_delta=pos_end-pos_startindelete~line:truepos_startpos_deltaelsereturn(ContinueLoop[])|Downward->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline_count=Zed_lines.countlinesinletline=Zed_edit.linectxinletdest=minline_count(line+count)inletline_delta=dest-lineinifline_delta>0thenletpos_start=Zed_lines.line_startlineslineandpos_end=Zed_lines.line_stoplinesdestinletpos_end=ifdest<line_countthenpos_end+1elsepos_endinletpos_delta=pos_end-pos_startindelete~line:truepos_startpos_deltaelsereturn(ContinueLoop[])|Line->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline_count=Zed_lines.countlinesinletline=Zed_edit.linectxinletdest=minline_count(line+count-1)inletpos_start=Zed_lines.line_startlineslineandpos_end=Zed_lines.line_stoplinesdestinletpos_delta=pos_end-pos_startindelete~line:truepos_startpos_delta|Word->letpos=Zed_edit.positionctxinletedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_word~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos-posindeleteposdelta|WORD->letpos=Zed_edit.positionctxinletedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_WORD~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos-posindeleteposdelta|Word_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=maxstart(Query.prev_word~pos~starttext)inprev_wordprev(n-1)elseposinletprev_pos=prev_wordposcountinletdelta=pos-prev_posindeleteprev_posdelta|WORD_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=maxstart(Query.prev_WORD~pos~starttext)inprev_wordprev(n-1)elseposinletprev_pos=prev_wordposcountinletdelta=pos-prev_posindeleteprev_posdelta|Word_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletpos=Zed_edit.positionctxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_word_end~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos+1-posindeleteposdelta|WORD_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletpos=Zed_edit.positionctxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_WORD_end~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos+1-posindeleteposdelta|Word_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinifZed_rope.lengthtext<=0thenreturn(ContinueLoop[])elseletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=(Query.prev_word_end~pos~starttext)inprev_wordprev(n-1)elseposinletdest=prev_wordposcountinletdelta=pos-dest+1indeletedestdelta|WORD_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinifZed_rope.lengthtext<=0thenreturn(ContinueLoop[])elseletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=(Query.prev_WORD_end~pos~starttext)inprev_wordprev(n-1)elseposinletdest=prev_wordposcountinletdelta=pos-dest+1indeletedestdelta|Line_FirstChar->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletpos=Zed_edit.positionctxinletstart=Zed_lines.line_startlineslineindeletestart(pos-start)|Line_FirstNonBlank->letpos=Zed_edit.positionctxinletnonblank=Query.line_FirstNonBlank1ctxin(ifnonblank<posthendeletenonblank(pos-nonblank)elsedeletepos(nonblank-pos))|Line_LastChar->letpos=Zed_edit.positionctxinletnext=Query.line_LastCharcountctxindeletepos(next+1-pos)|Line_LastChar_nl->letnewline=trueinletpos=Zed_edit.positionctxinletnext=Query.line_LastChar~newlinecountctxindeletepos(next+1-pos)|Parenthesis_include->pare_includeZed_char.(of_utf8"(",of_utf8")")countdelete|Parenthesis_inner->pare_innerZed_char.(of_utf8"(",of_utf8")")countdelete|Bracket_include->pare_includeZed_char.(of_utf8"[",of_utf8"]")countdelete|Bracket_inner->pare_innerZed_char.(of_utf8"[",of_utf8"]")countdelete|AngleBracket_include->pare_includeZed_char.(of_utf8"<",of_utf8">")countdelete|AngleBracket_inner->pare_innerZed_char.(of_utf8"<",of_utf8">")countdelete|Brace_include->pare_includeZed_char.(of_utf8"{",of_utf8"}")countdelete|Brace_inner->pare_innerZed_char.(of_utf8"{",of_utf8"}")countdelete|Occurrence_inlinechr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somepos->letstart=Zed_edit.positionctxinletdelta=pos+1-startindeletestartdelta|None->return(ContinueLoop[]))|Occurrence_inline_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos-1)countwith|Somepos->letstop=Zed_edit.positionctxinletdelta=stop-posindeleteposdelta|None->return(ContinueLoop[]))|Occurrence_inline_tillchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos+1)countwith|Somedest->deletepos(dest-pos)|None->return(ContinueLoop[]))|Occurrence_inline_till_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somedest->delete(dest+1)(pos-1-dest)|None->return(ContinueLoop[]))|Match->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.item_match~start:0~stoppostextwith|Somedest->(ifdest>posthendeletepos(dest+1-pos)elsedeletedest(pos+1-dest))|None->return(ContinueLoop[]))|Word_include->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletmove_nposn=letrecmove_nposn=ifn>=1thenmatchQuery.include_word~stop~postextwith|Some(_word_begin,word_end)->move_n(word_end+1)(n-1)|None->pos-1elsepos-1inifn>=1thenmatchQuery.include_word~stop~postextwith|Some(word_begin,word_end)->letword_end=move_n(word_end+1)(n-1)inSome(word_begin,word_end)|None->NoneelseNonein(matchmove_nposcountwith|Some(word_begin,word_end)->deleteword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|WORD_include->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletmove_nposn=letrecmove_nposn=ifn>=1thenmatchQuery.include_WORD~stop~postextwith|Some(_word_begin,word_end)->move_n(word_end+1)(n-1)|None->poselsepos-1inifn>=1thenmatchQuery.include_WORD~stop~postextwith|Some(word_begin,word_end)->letword_end=move_n(word_end+1)(n-1)inSome(word_begin,word_end)|None->NoneelseNonein(matchmove_nposcountwith|Some(word_begin,word_end)->deleteword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|Word_inner->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.inner_word~pos~stoptextwith|Some(word_begin,word_end)->deleteword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|WORD_inner->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.inner_WORD~pos~stoptextwith|Some(word_begin,word_end)->deleteword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|Quote_innerchr->letquote=Zed_char.of_utf8chrinpare_inner(quote,quote)1delete|Quote_includechr->letquote=Zed_char.of_utf8chrinpare_include(quote,quote)countdelete|_->return(ContinueLoop[]))|Change(register,motion,count)->letchange=change~registerin(matchmotionwith|Left->letpos,delta=Query.leftcountctxinchangeposdelta|Right->letnewline=trueinletpos,delta=Query.right~newlinecountctxinletpos=pos-deltainchangeposdelta|Right_nl->letnewline=trueinletpos,delta=Query.right~newlinecountctxinletpos=pos-deltainexec[Edit(Zed(Zed_edit.Gotopos));Edit(Zed(Zed_edit.Kill_next_charsdelta));]|Upward->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletdest=max0(line-count)inletline_delta=line-destinifline_delta>0thenletpos_start=Zed_lines.line_startlinesdestandpos_end=Zed_lines.line_stoplineslineinletpos_delta=pos_end-pos_startinchange~line:truepos_startpos_deltaelsereturn(ContinueLoop[])|Downward->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline_count=Zed_lines.countlinesinletline=Zed_edit.linectxinletdest=minline_count(line+count)inletline_delta=dest-lineinifline_delta>0thenletpos_start=Zed_lines.line_startlineslineandpos_end=Zed_lines.line_stoplinesdestinletpos_end=ifdest<line_countthenpos_end+1elsepos_endinletpos_delta=pos_end-pos_startinchange~line:truepos_startpos_deltaelsereturn(ContinueLoop[])|Word->letpos=Zed_edit.positionctxinletedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_word~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos-posinchangeposdelta|WORD->letpos=Zed_edit.positionctxinletedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_WORD~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos-posinchangeposdelta|Word_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=maxstart(Query.prev_word~pos~starttext)inprev_wordprev(n-1)elseposinletprev_pos=prev_wordposcountinletdelta=pos-prev_posinchangeprev_posdelta|WORD_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=maxstart(Query.prev_WORD~pos~starttext)inprev_wordprev(n-1)elseposinletprev_pos=prev_wordposcountinletdelta=pos-prev_posinchangeprev_posdelta|Word_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletpos=Zed_edit.positionctxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_word_end~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos+1-posinchangeposdelta|WORD_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletpos=Zed_edit.positionctxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_WORD_end~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos+1-posinchangeposdelta|Word_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinifZed_rope.lengthtext<=0thenreturn(ContinueLoop[])elseletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=(Query.prev_word_end~pos~starttext)inprev_wordprev(n-1)elseposinletdest=prev_wordposcountinletdelta=pos-dest+1inchangedestdelta|WORD_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinifZed_rope.lengthtext<=0thenreturn(ContinueLoop[])elseletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=(Query.prev_WORD_end~pos~starttext)inprev_wordprev(n-1)elseposinletdest=prev_wordposcountinletdelta=pos-dest+1inchangedestdelta|Line_FirstChar->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletpos=Zed_edit.positionctxinletstart=Zed_lines.line_startlineslineinchangestart(pos-start)|Line_FirstNonBlank->letpos=Zed_edit.positionctxinletnonblank=Query.line_FirstNonBlank1ctxin(ifnonblank<posthenchangenonblank(pos-nonblank)elsechangepos(nonblank-pos))|Line_LastChar->letpos=Zed_edit.positionctxinletnext=Query.line_LastCharcountctxinchangepos(next+1-pos)|Line_LastChar_nl->letnewline=trueinletpos=Zed_edit.positionctxinletnext=Query.line_LastChar~newlinecountctxinchangepos(next+1-pos)|Parenthesis_include->pare_includeZed_char.(of_utf8"(",of_utf8")")countchange|Parenthesis_inner->pare_innerZed_char.(of_utf8"(",of_utf8")")countchange|Bracket_include->pare_includeZed_char.(of_utf8"[",of_utf8"]")countchange|Bracket_inner->pare_innerZed_char.(of_utf8"[",of_utf8"]")countchange|AngleBracket_include->pare_includeZed_char.(of_utf8"<",of_utf8">")countchange|AngleBracket_inner->pare_innerZed_char.(of_utf8"<",of_utf8">")countchange|Brace_include->pare_includeZed_char.(of_utf8"{",of_utf8"}")countchange|Brace_inner->pare_innerZed_char.(of_utf8"{",of_utf8"}")countchange|Occurrence_inlinechr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somepos->letstart=Zed_edit.positionctxinletdelta=pos+1-startinchangestartdelta|None->return(ContinueLoop[]))|Occurrence_inline_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos-1)countwith|Somepos->letstop=Zed_edit.positionctxinletdelta=stop-posinchangeposdelta|None->return(ContinueLoop[]))|Occurrence_inline_tillchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos+1)countwith|Somedest->changepos(dest-pos)|None->return(ContinueLoop[]))|Occurrence_inline_till_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somedest->change(dest+1)(pos-1-dest)|None->return(ContinueLoop[]))|Match->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.item_match~start:0~stoppostextwith|Somedest->(ifdest>posthenchangepos(dest+1-pos)elsechangedest(pos+1-dest))|None->return(ContinueLoop[]))|Word_include->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletmove_nposn=letrecmove_nposn=ifn>=1thenmatchQuery.include_word~stop~postextwith|Some(_word_begin,word_end)->move_n(word_end+1)(n-1)|None->pos-1elsepos-1inifn>=1thenmatchQuery.include_word~stop~postextwith|Some(word_begin,word_end)->letword_end=move_n(word_end+1)(n-1)inSome(word_begin,word_end)|None->NoneelseNonein(matchmove_nposcountwith|Some(word_begin,word_end)->changeword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|WORD_include->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletmove_nposn=letrecmove_nposn=ifn>=1thenmatchQuery.include_WORD~stop~postextwith|Some(_word_begin,word_end)->move_n(word_end+1)(n-1)|None->poselsepos-1inifn>=1thenmatchQuery.include_WORD~stop~postextwith|Some(word_begin,word_end)->letword_end=move_n(word_end+1)(n-1)inSome(word_begin,word_end)|None->NoneelseNonein(matchmove_nposcountwith|Some(word_begin,word_end)->changeword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|Word_inner->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.inner_word~pos~stoptextwith|Some(word_begin,word_end)->changeword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|WORD_inner->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.inner_WORD~pos~stoptextwith|Some(word_begin,word_end)->changeword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|Quote_innerchr->letquote=Zed_char.of_utf8chrinpare_inner(quote,quote)1change|Quote_includechr->letquote=Zed_char.of_utf8chrinpare_include(quote,quote)countchange|_->return(ContinueLoop[]))|Yank(register,motion,count)->letyank=yank~registerin(matchmotionwith|Left->letpos,delta=Query.leftcountctxinyankposdelta|Right->letnewline=trueinletpos,delta=Query.right~newlinecountctxinletpos=pos-deltainyankposdelta|Right_nl->letnewline=trueinletpos,delta=Query.right~newlinecountctxinletpos=pos-deltainyankposdelta|Upward->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletdest=max0(line-count)inletline_delta=line-destinifline_delta>0thenletpos_start=Zed_lines.line_startlinesdestandpos_end=Zed_lines.line_stoplineslineinletpos_delta=pos_end-pos_startinyank~line:truepos_startpos_deltaelsereturn(ContinueLoop[])|Downward->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline_count=Zed_lines.countlinesinletline=Zed_edit.linectxinletdest=minline_count(line+count)inletline_delta=dest-lineinifline_delta>0thenletpos_start=Zed_lines.line_startlineslineandpos_end=Zed_lines.line_stoplinesdestinletpos_end=ifdest<line_countthenpos_end+1elsepos_endinletpos_delta=pos_end-pos_startinyank~line:truepos_startpos_deltaelsereturn(ContinueLoop[])|Line->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline_count=Zed_lines.countlinesinletline=Zed_edit.linectxinletdest=minline_count(line+count-1)inletpos_start=Zed_lines.line_startlineslineandpos_end=Zed_lines.line_stoplinesdestinletpos_delta=pos_end-pos_startinyank~line:truepos_startpos_delta|Word->letpos=Zed_edit.positionctxinletedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_word~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos-posinyankposdelta|WORD->letpos=Zed_edit.positionctxinletedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=ifcount>1thenQuery.get_boundarytruectxelseQuery.get_boundaryfalsectxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_WORD~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos-posinyankposdelta|Word_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=maxstart(Query.prev_word~pos~starttext)inprev_wordprev(n-1)elseposinletprev_pos=prev_wordposcountinletdelta=pos-prev_posinyankprev_posdelta|WORD_back->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=maxstart(Query.prev_WORD~pos~starttext)inprev_wordprev(n-1)elseposinletprev_pos=prev_wordposcountinletdelta=pos-prev_posinyankprev_posdelta|Word_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletpos=Zed_edit.positionctxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_word_end~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos+1-posinyankposdelta|WORD_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinlet_start,stop=Query.get_boundarytruectxinletpos=Zed_edit.positionctxinletrecnext_wordposn=ifn>0&&pos<stopthenletnext=(Query.next_WORD_end~pos~stoptext)innext_wordnext(n-1)elseposinletnext_pos=next_wordposcountinletdelta=next_pos+1-posinyankposdelta|Word_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinifZed_rope.lengthtext<=0thenreturn(ContinueLoop[])elseletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=(Query.prev_word_end~pos~starttext)inprev_wordprev(n-1)elseposinletdest=prev_wordposcountinletdelta=pos-dest+1inyankdestdelta|WORD_back_end->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinifZed_rope.lengthtext<=0thenreturn(ContinueLoop[])elseletstart,stop=Query.get_boundarytruectxinletpos=min(stop-1)(Zed_edit.positionctx)inletrecprev_wordposn=ifn>0&&pos>startthenletprev=(Query.prev_WORD_end~pos~starttext)inprev_wordprev(n-1)elseposinletdest=prev_wordposcountinletdelta=pos-dest+1inyankdestdelta|Line_FirstChar->letedit=Zed_edit.editctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletpos=Zed_edit.positionctxinletstart=Zed_lines.line_startlineslineinyankstart(pos-start)|Line_FirstNonBlank->letpos=Zed_edit.positionctxinletnonblank=Query.line_FirstNonBlank1ctxinifnonblank<posthenyanknonblank(pos-nonblank)elseyanknonblank(pos-nonblank)|Line_LastChar->letpos=Zed_edit.positionctxinletnext=Query.line_LastCharcountctxinyankpos(next+1-pos)|Line_LastChar_nl->letnewline=trueinletpos=Zed_edit.positionctxinletnext=Query.line_LastChar~newlinecountctxinyankpos(next+1-pos)|Parenthesis_include->pare_includeZed_char.(of_utf8"(",of_utf8")")countyank|Parenthesis_inner->pare_innerZed_char.(of_utf8"(",of_utf8")")countyank|Bracket_include->pare_includeZed_char.(of_utf8"[",of_utf8"]")countyank|Bracket_inner->pare_innerZed_char.(of_utf8"[",of_utf8"]")countyank|AngleBracket_include->pare_includeZed_char.(of_utf8"<",of_utf8">")countyank|AngleBracket_inner->pare_innerZed_char.(of_utf8"<",of_utf8">")countyank|Brace_include->pare_includeZed_char.(of_utf8"{",of_utf8"}")countyank|Brace_inner->pare_innerZed_char.(of_utf8"{",of_utf8"}")countyank|Occurrence_inlinechr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somepos->letstart=Zed_edit.positionctxinletdelta=pos+1-startinyankstartdelta|None->return(ContinueLoop[]))|Occurrence_inline_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctx+1inletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos-1)countwith|Somepos->letstop=Zed_edit.positionctxinletdelta=stop-posinyankposdelta|None->return(ContinueLoop[]))|Occurrence_inline_tillchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstop=Zed_lines.line_stoplineslineinletrecquery_nchrposn=ifn<1thenNoneelseletnext=Query.occurrence_char~pos~stopchrtextinifn=1thennextelsematchnextwith|Somenext->query_nchr(next+1)(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)(pos+1)countwith|Somedest->yankpos(dest-pos)|None->return(ContinueLoop[]))|Occurrence_inline_till_backchr->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletlines=Zed_edit.lineseditinletline=Zed_edit.linectxinletstart=Zed_lines.line_startlineslineinletrecquery_nchrposn=ifn<1thenNoneelseletprev=Query.occurrence_char_back~pos~startchrtextinifn=1thenprevelsematchprevwith|Someprev->query_nchrprev(n-1)|None->Nonein(matchquery_n(Zed_char.of_utf8chr)poscountwith|Somedest->yank(dest+1)(pos-1-dest)|None->return(ContinueLoop[]))|Match->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.item_match~start:0~stoppostextwith|Somedest->ifdest>posthenyankpos(dest+1-pos)elseyankdest(pos+1-dest)|None->return(ContinueLoop[]))|Word_include->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextinletmove_nposn=letrecmove_nposn=ifn>=1thenmatchQuery.include_word~stop~postextwith|Some(_word_begin,word_end)->move_n(word_end+1)(n-1)|None->pos-1elsepos-1inifn>=1thenmatchQuery.include_word~stop~postextwith|Some(word_begin,word_end)->letword_end=move_n(word_end+1)(n-1)inSome(word_begin,word_end)|None->NoneelseNonein(matchmove_nposcountwith|Some(word_begin,word_end)->Zed_edit.copy_sequencectxword_begin(word_end+1-word_begin);return(ContinueLoop[])|None->return(ContinueLoop[]))|WORD_include->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextinletmove_nposn=letrecmove_nposn=ifn>=1thenmatchQuery.include_WORD~stop~postextwith|Some(_word_begin,word_end)->move_n(word_end+1)(n-1)|None->poselsepos-1inifn>=1thenmatchQuery.include_WORD~stop~postextwith|Some(word_begin,word_end)->letword_end=move_n(word_end+1)(n-1)inSome(word_begin,word_end)|None->NoneelseNonein(matchmove_nposcountwith|Some(word_begin,word_end)->yankword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|Word_inner->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.inner_word~pos~stoptextwith|Some(word_begin,word_end)->yankword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|WORD_inner->letedit=Zed_edit.editctxinlettext=Zed_edit.texteditinletpos=Zed_edit.positionctxinletstop=Zed_rope.lengthtextin(matchQuery.inner_WORD~pos~stoptextwith|Some(word_begin,word_end)->yankword_begin(word_end+1-word_begin)|None->return(ContinueLoop[]))|Quote_innerchr->letquote=Zed_char.of_utf8chrinpare_inner(quote,quote)1yank|Quote_includechr->letquote=Zed_char.of_utf8chrinpare_include(quote,quote)countyank|_->return(ContinueLoop[]))|Undocount->exec@@list_dup[Edit(Zed(Zed_edit.Undo));]count>>=(funr->setup_pos()>>=fun_->returnr)|Paste_before(register,count)->letaction_paste=letopenVi.Interpret.Registerinmatchvi_edit#get_registerregisterwith|Some(Seqstr)->[Edit(Zed(Zed_edit.Insert_str(Zed_string.of_utf8str)));Edit(Zed(Zed_edit.Prev_char));]|Some(Linestr)->[Edit(Zed(Zed_edit.Goto_bol));Edit(Zed(Zed_edit.Insert_str(Zed_string.of_utf8(str^"\n"))));Edit(Zed(Zed_edit.Prev_line));Edit(Zed(Zed_edit.Goto_eol));Edit(Zed(Zed_edit.Prev_char));]|None->[]inexec@@list_dupaction_pastecount|Paste_after(register,count)->letaction_paste=letopenVi.Interpret.Registerinmatchvi_edit#get_registerregisterwith|Some(Seqstr)->letactions=[Edit(Zed(Zed_edit.Insert_str(Zed_string.of_utf8str)));Edit(Zed(Zed_edit.Prev_char));]inifZed_edit.at_eolctxthenactionselseEdit(Zed(Zed_edit.Next_char))::actions|Some(Linestr)->[Edit(Zed(Zed_edit.Goto_eol));Edit(Zed(Zed_edit.Insert_str(Zed_string.of_utf8("\n"^(String.substr0(String.lengthstr))))));Edit(Zed(Zed_edit.Goto_eol));Edit(Zed(Zed_edit.Prev_char));]|None->[]inexec@@list_dupaction_pastecount|Joincount->exec@@(list_make(Edit(Zed(Zed_edit.Join_line)))count)|DeleteSelectedregister->letdelete=delete~registerinletedit=Zed_edit.editctxinifZed_edit.get_selectioneditthenleta=Zed_edit.positionctxandb=Zed_cursor.get_position(Zed_edit.markedit)inleta=minabandb=maxabindeletea(b+1-a)elsereturn(ContinueLoop[])|YankSelectedregister->letyank=yank~registerinletedit=Zed_edit.editctxinifZed_edit.get_selectioneditthenleta=Zed_edit.positionctxandb=Zed_cursor.get_position(Zed_edit.markedit)inleta=minabandb=maxabinyanka(b+1-a)elsereturn(ContinueLoop[])|ChangeModemode->letedit=Zed_edit.editctxin(matchmodewith|Insert->Zed_edit.set_selectioneditfalse|Normal->Zed_edit.set_selectioneditfalse|Visual->Zed_edit.set_markctx|Commandline->Zed_edit.set_selectioneditfalse);return(ContinueLoop[])