1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662(*
* 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)letget_category?(nl_as_sp=false)uchar=ifuchar=Zed_utf8.extract"\n"0&&nl_as_spthen`ZselseUucp.Gc.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[])