netrw.vim 547 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673
  1. " netrw.vim: Handles file transfer and remote directory listing across
  2. " AUTOLOAD SECTION
  3. " Date: Aug 16, 2021
  4. " Version: 171
  5. " Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
  6. " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
  7. " Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
  8. " Permission is hereby granted to use and distribute this code,
  9. " with or without modifications, provided that this copyright
  10. " notice is copied with it. Like anything else that's free,
  11. " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
  12. " *as is* and come with no warranty of any kind, either
  13. " expressed or implied. By using this plugin, you agree that
  14. " in no event will the copyright holder be liable for any damages
  15. " resulting from the use of this software.
  16. "
  17. " Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
  18. " code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
  19. "
  20. "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
  21. "
  22. " But be doers of the Word, and not only hearers, deluding your own selves {{{1
  23. " (James 1:22 RSV)
  24. " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  25. " Load Once: {{{1
  26. if &cp || exists("g:loaded_netrw")
  27. finish
  28. endif
  29. " Check that vim has patches that netrw requires.
  30. " Patches needed for v7.4: 1557, and 213.
  31. " (netrw will benefit from vim's having patch#656, too)
  32. let s:needspatches=[1557,213]
  33. if exists("s:needspatches")
  34. for ptch in s:needspatches
  35. if v:version < 704 || (v:version == 704 && !has("patch".ptch))
  36. if !exists("s:needpatch{ptch}")
  37. unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
  38. endif
  39. let s:needpatch{ptch}= 1
  40. finish
  41. endif
  42. endfor
  43. endif
  44. let g:loaded_netrw = "v171"
  45. if !exists("s:NOTE")
  46. let s:NOTE = 0
  47. let s:WARNING = 1
  48. let s:ERROR = 2
  49. endif
  50. let s:keepcpo= &cpo
  51. setl cpo&vim
  52. "DechoFuncName 1
  53. "DechoRemOn
  54. "call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
  55. " ======================
  56. " Netrw Variables: {{{1
  57. " ======================
  58. " ---------------------------------------------------------------------
  59. " netrw#ErrorMsg: {{{2
  60. " 0=note = s:NOTE
  61. " 1=warning = s:WARNING
  62. " 2=error = s:ERROR
  63. " Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
  64. " netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
  65. " (this function can optionally take a list of messages)
  66. " Dec 2, 2019 : max errnum currently is 106
  67. fun! netrw#ErrorMsg(level,msg,errnum)
  68. " call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
  69. if a:level < g:netrw_errorlvl
  70. " call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
  71. return
  72. endif
  73. if a:level == 1
  74. let level= "**warning** (netrw) "
  75. elseif a:level == 2
  76. let level= "**error** (netrw) "
  77. else
  78. let level= "**note** (netrw) "
  79. endif
  80. " call Decho("level=".level,'~'.expand("<slnum>"))
  81. if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
  82. " use popup window
  83. if type(a:msg) == 3
  84. let msg = [level]+a:msg
  85. else
  86. let msg= level.a:msg
  87. endif
  88. let s:popuperr_id = popup_atcursor(msg,{})
  89. let s:popuperr_text= ""
  90. elseif g:netrw_use_errorwindow
  91. " (default) netrw creates a one-line window to show error/warning
  92. " messages (reliably displayed)
  93. " record current window number
  94. let s:winBeforeErr= winnr()
  95. " call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
  96. " getting messages out reliably is just plain difficult!
  97. " This attempt splits the current window, creating a one line window.
  98. if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
  99. " call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
  100. exe bufwinnr("NetrwMessage")."wincmd w"
  101. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  102. setl ma noro
  103. if type(a:msg) == 3
  104. for msg in a:msg
  105. NetrwKeepj call setline(line("$")+1,level.msg)
  106. endfor
  107. else
  108. NetrwKeepj call setline(line("$")+1,level.a:msg)
  109. endif
  110. NetrwKeepj $
  111. else
  112. " call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
  113. bo 1split
  114. sil! call s:NetrwEnew()
  115. sil! NetrwKeepj call s:NetrwOptionsSafe(1)
  116. setl bt=nofile
  117. NetrwKeepj file NetrwMessage
  118. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  119. setl ma noro
  120. if type(a:msg) == 3
  121. for msg in a:msg
  122. NetrwKeepj call setline(line("$")+1,level.msg)
  123. endfor
  124. else
  125. NetrwKeepj call setline(line("$"),level.a:msg)
  126. endif
  127. NetrwKeepj $
  128. endif
  129. " call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
  130. if &fo !~ '[ta]'
  131. syn clear
  132. syn match netrwMesgNote "^\*\*note\*\*"
  133. syn match netrwMesgWarning "^\*\*warning\*\*"
  134. syn match netrwMesgError "^\*\*error\*\*"
  135. hi link netrwMesgWarning WarningMsg
  136. hi link netrwMesgError Error
  137. endif
  138. " call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
  139. setl ro nomod noma bh=wipe
  140. else
  141. " (optional) netrw will show messages using echomsg. Even if the
  142. " message doesn't appear, at least it'll be recallable via :messages
  143. " redraw!
  144. if a:level == s:WARNING
  145. echohl WarningMsg
  146. elseif a:level == s:ERROR
  147. echohl Error
  148. endif
  149. if type(a:msg) == 3
  150. for msg in a:msg
  151. unsilent echomsg level.msg
  152. endfor
  153. else
  154. unsilent echomsg level.a:msg
  155. endif
  156. " call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
  157. echohl None
  158. endif
  159. " call Dret("netrw#ErrorMsg")
  160. endfun
  161. " ---------------------------------------------------------------------
  162. " s:NetrwInit: initializes variables if they haven't been defined {{{2
  163. " Loosely, varname = value.
  164. fun s:NetrwInit(varname,value)
  165. " call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
  166. if !exists(a:varname)
  167. if type(a:value) == 0
  168. exe "let ".a:varname."=".a:value
  169. elseif type(a:value) == 1 && a:value =~ '^[{[]'
  170. exe "let ".a:varname."=".a:value
  171. elseif type(a:value) == 1
  172. exe "let ".a:varname."="."'".a:value."'"
  173. else
  174. exe "let ".a:varname."=".a:value
  175. endif
  176. endif
  177. endfun
  178. " ---------------------------------------------------------------------
  179. " Netrw Constants: {{{2
  180. call s:NetrwInit("g:netrw_dirhistcnt",0)
  181. if !exists("s:LONGLIST")
  182. call s:NetrwInit("s:THINLIST",0)
  183. call s:NetrwInit("s:LONGLIST",1)
  184. call s:NetrwInit("s:WIDELIST",2)
  185. call s:NetrwInit("s:TREELIST",3)
  186. call s:NetrwInit("s:MAXLIST" ,4)
  187. endif
  188. " ---------------------------------------------------------------------
  189. " Default option values: {{{2
  190. let g:netrw_localcopycmdopt = ""
  191. let g:netrw_localcopydircmdopt = ""
  192. let g:netrw_localmkdiropt = ""
  193. let g:netrw_localmovecmdopt = ""
  194. let g:netrw_localrmdiropt = ""
  195. " ---------------------------------------------------------------------
  196. " Default values for netrw's global protocol variables {{{2
  197. if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
  198. call s:NetrwInit("g:netrw_use_errorwindow",2)
  199. else
  200. call s:NetrwInit("g:netrw_use_errorwindow",1)
  201. endif
  202. if !exists("g:netrw_dav_cmd")
  203. if executable("cadaver")
  204. let g:netrw_dav_cmd = "cadaver"
  205. elseif executable("curl")
  206. let g:netrw_dav_cmd = "curl"
  207. else
  208. let g:netrw_dav_cmd = ""
  209. endif
  210. endif
  211. if !exists("g:netrw_fetch_cmd")
  212. if executable("fetch")
  213. let g:netrw_fetch_cmd = "fetch -o"
  214. else
  215. let g:netrw_fetch_cmd = ""
  216. endif
  217. endif
  218. if !exists("g:netrw_file_cmd")
  219. if executable("elinks")
  220. call s:NetrwInit("g:netrw_file_cmd","elinks")
  221. elseif executable("links")
  222. call s:NetrwInit("g:netrw_file_cmd","links")
  223. endif
  224. endif
  225. if !exists("g:netrw_ftp_cmd")
  226. let g:netrw_ftp_cmd = "ftp"
  227. endif
  228. let s:netrw_ftp_cmd= g:netrw_ftp_cmd
  229. if !exists("g:netrw_ftp_options")
  230. let g:netrw_ftp_options= "-i -n"
  231. endif
  232. if !exists("g:netrw_http_cmd")
  233. if executable("wget")
  234. let g:netrw_http_cmd = "wget"
  235. call s:NetrwInit("g:netrw_http_xcmd","-q -O")
  236. elseif executable("curl")
  237. let g:netrw_http_cmd = "curl"
  238. call s:NetrwInit("g:netrw_http_xcmd","-L -o")
  239. elseif executable("elinks")
  240. let g:netrw_http_cmd = "elinks"
  241. call s:NetrwInit("g:netrw_http_xcmd","-source >")
  242. elseif executable("fetch")
  243. let g:netrw_http_cmd = "fetch"
  244. call s:NetrwInit("g:netrw_http_xcmd","-o")
  245. elseif executable("links")
  246. let g:netrw_http_cmd = "links"
  247. call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
  248. else
  249. let g:netrw_http_cmd = ""
  250. endif
  251. endif
  252. call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
  253. call s:NetrwInit("g:netrw_keepj","keepj")
  254. call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
  255. call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
  256. call s:NetrwInit("g:netrw_rsync_sep", "/")
  257. if !exists("g:netrw_scp_cmd")
  258. if executable("scp")
  259. call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
  260. elseif executable("pscp")
  261. if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
  262. call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
  263. else
  264. call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
  265. endif
  266. else
  267. call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
  268. endif
  269. endif
  270. call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
  271. call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
  272. if (has("win32") || has("win95") || has("win64") || has("win16"))
  273. \ && exists("g:netrw_use_nt_rcp")
  274. \ && g:netrw_use_nt_rcp
  275. \ && executable( $SystemRoot .'/system32/rcp.exe')
  276. let s:netrw_has_nt_rcp = 1
  277. let s:netrw_rcpmode = '-b'
  278. else
  279. let s:netrw_has_nt_rcp = 0
  280. let s:netrw_rcpmode = ''
  281. endif
  282. " ---------------------------------------------------------------------
  283. " Default values for netrw's global variables {{{2
  284. " Cygwin Detection ------- {{{3
  285. if !exists("g:netrw_cygwin")
  286. if has("win32") || has("win95") || has("win64") || has("win16")
  287. if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
  288. let g:netrw_cygwin= 1
  289. else
  290. let g:netrw_cygwin= 0
  291. endif
  292. else
  293. let g:netrw_cygwin= 0
  294. endif
  295. endif
  296. " Default values - a-c ---------- {{{3
  297. call s:NetrwInit("g:netrw_alto" , &sb)
  298. call s:NetrwInit("g:netrw_altv" , &spr)
  299. call s:NetrwInit("g:netrw_banner" , 1)
  300. call s:NetrwInit("g:netrw_browse_split", 0)
  301. call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
  302. call s:NetrwInit("g:netrw_chgwin" , -1)
  303. call s:NetrwInit("g:netrw_clipboard" , 1)
  304. call s:NetrwInit("g:netrw_compress" , "gzip")
  305. call s:NetrwInit("g:netrw_ctags" , "ctags")
  306. if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
  307. call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
  308. let g:netrw_cursor= g:netrw_cursorline
  309. endif
  310. call s:NetrwInit("g:netrw_cursor" , 2)
  311. let s:netrw_usercul = &cursorline
  312. let s:netrw_usercuc = &cursorcolumn
  313. "call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
  314. call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
  315. " Default values - d-g ---------- {{{3
  316. call s:NetrwInit("s:didstarstar",0)
  317. call s:NetrwInit("g:netrw_dirhistcnt" , 0)
  318. call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
  319. call s:NetrwInit("g:netrw_dirhistmax" , 10)
  320. call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
  321. call s:NetrwInit("g:netrw_fastbrowse" , 1)
  322. call s:NetrwInit("g:netrw_ftp_browse_reject", '^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$')
  323. if !exists("g:netrw_ftp_list_cmd")
  324. if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
  325. let g:netrw_ftp_list_cmd = "ls -lF"
  326. let g:netrw_ftp_timelist_cmd = "ls -tlF"
  327. let g:netrw_ftp_sizelist_cmd = "ls -slF"
  328. else
  329. let g:netrw_ftp_list_cmd = "dir"
  330. let g:netrw_ftp_timelist_cmd = "dir"
  331. let g:netrw_ftp_sizelist_cmd = "dir"
  332. endif
  333. endif
  334. call s:NetrwInit("g:netrw_ftpmode",'binary')
  335. " Default values - h-lh ---------- {{{3
  336. call s:NetrwInit("g:netrw_hide",1)
  337. if !exists("g:netrw_ignorenetrc")
  338. if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
  339. let g:netrw_ignorenetrc= 1
  340. else
  341. let g:netrw_ignorenetrc= 0
  342. endif
  343. endif
  344. call s:NetrwInit("g:netrw_keepdir",1)
  345. if !exists("g:netrw_list_cmd")
  346. if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
  347. if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
  348. " provide a pscp-based listing command
  349. let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
  350. endif
  351. if exists("g:netrw_list_cmd_options")
  352. let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
  353. else
  354. let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
  355. endif
  356. elseif executable(g:netrw_ssh_cmd)
  357. " provide a scp-based default listing command
  358. if exists("g:netrw_list_cmd_options")
  359. let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
  360. else
  361. let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
  362. endif
  363. else
  364. " call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
  365. let g:netrw_list_cmd= ""
  366. endif
  367. endif
  368. call s:NetrwInit("g:netrw_list_hide","")
  369. " Default values - lh-lz ---------- {{{3
  370. if exists("g:netrw_local_copycmd")
  371. let g:netrw_localcopycmd= g:netrw_local_copycmd
  372. call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
  373. endif
  374. if !exists("g:netrw_localcmdshell")
  375. let g:netrw_localcmdshell= ""
  376. endif
  377. if !exists("g:netrw_localcopycmd")
  378. if has("win32") || has("win95") || has("win64") || has("win16")
  379. if g:netrw_cygwin
  380. let g:netrw_localcopycmd= "cp"
  381. else
  382. let g:netrw_localcopycmd = expand("$COMSPEC")
  383. let g:netrw_localcopycmdopt= " /c copy"
  384. endif
  385. elseif has("unix") || has("macunix")
  386. let g:netrw_localcopycmd= "cp"
  387. else
  388. let g:netrw_localcopycmd= ""
  389. endif
  390. endif
  391. if !exists("g:netrw_localcopydircmd")
  392. if has("win32") || has("win95") || has("win64") || has("win16")
  393. if g:netrw_cygwin
  394. let g:netrw_localcopydircmd = "cp"
  395. let g:netrw_localcopydircmdopt= " -R"
  396. else
  397. let g:netrw_localcopydircmd = expand("$COMSPEC")
  398. let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
  399. endif
  400. elseif has("unix")
  401. let g:netrw_localcopydircmd = "cp"
  402. let g:netrw_localcopydircmdopt= " -R"
  403. elseif has("macunix")
  404. let g:netrw_localcopydircmd = "cp"
  405. let g:netrw_localcopydircmdopt= " -R"
  406. else
  407. let g:netrw_localcopydircmd= ""
  408. endif
  409. endif
  410. if exists("g:netrw_local_mkdir")
  411. let g:netrw_localmkdir= g:netrw_local_mkdir
  412. call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
  413. endif
  414. if has("win32") || has("win95") || has("win64") || has("win16")
  415. if g:netrw_cygwin
  416. call s:NetrwInit("g:netrw_localmkdir","mkdir")
  417. else
  418. let g:netrw_localmkdir = expand("$COMSPEC")
  419. let g:netrw_localmkdiropt= " /c mkdir"
  420. endif
  421. else
  422. call s:NetrwInit("g:netrw_localmkdir","mkdir")
  423. endif
  424. call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
  425. if exists("g:netrw_local_movecmd")
  426. let g:netrw_localmovecmd= g:netrw_local_movecmd
  427. call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
  428. endif
  429. if !exists("g:netrw_localmovecmd")
  430. if has("win32") || has("win95") || has("win64") || has("win16")
  431. if g:netrw_cygwin
  432. let g:netrw_localmovecmd= "mv"
  433. else
  434. let g:netrw_localmovecmd = expand("$COMSPEC")
  435. let g:netrw_localmovecmdopt= " /c move"
  436. endif
  437. elseif has("unix") || has("macunix")
  438. let g:netrw_localmovecmd= "mv"
  439. else
  440. let g:netrw_localmovecmd= ""
  441. endif
  442. endif
  443. " following serves as an example for how to insert a version&patch specific test
  444. "if v:version < 704 || (v:version == 704 && !has("patch1107"))
  445. "endif
  446. call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
  447. " sanity checks
  448. if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
  449. let g:netrw_liststyle= s:THINLIST
  450. endif
  451. if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
  452. let g:netrw_list_cmd= g:netrw_list_cmd." -l"
  453. endif
  454. " Default values - m-r ---------- {{{3
  455. call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
  456. call s:NetrwInit("g:netrw_maxfilenamelen", 32)
  457. call s:NetrwInit("g:netrw_menu" , 1)
  458. call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
  459. call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
  460. call s:NetrwInit("g:netrw_retmap" , 0)
  461. if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
  462. call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
  463. elseif has("win32") || has("win95") || has("win64") || has("win16")
  464. call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
  465. else
  466. call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
  467. endif
  468. call s:NetrwInit("g:netrw_preview" , 0)
  469. call s:NetrwInit("g:netrw_scpport" , "-P")
  470. call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
  471. call s:NetrwInit("g:netrw_sshport" , "-p")
  472. call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
  473. call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
  474. call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
  475. call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
  476. " Default values - q-s ---------- {{{3
  477. call s:NetrwInit("g:netrw_quickhelp",0)
  478. let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
  479. \ "(create new) %:file d:directory",
  480. \ "(windows split&open) o:horz v:vert p:preview",
  481. \ "i:style qf:file info O:obtain r:reverse",
  482. \ "(marks) mf:mark file mt:set target mm:move mc:copy",
  483. \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
  484. \ "(history) qb:list u:go up U:go down",
  485. \ "(targets) mt:target Tb:use bookmark Th:use history"]
  486. " g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
  487. call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
  488. if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
  489. call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
  490. else
  491. call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
  492. endif
  493. call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
  494. call s:NetrwInit("g:netrw_sort_options" , "")
  495. call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
  496. if !exists("g:netrw_sort_sequence")
  497. if has("unix")
  498. let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
  499. else
  500. let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
  501. endif
  502. endif
  503. call s:NetrwInit("g:netrw_special_syntax" , 0)
  504. call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
  505. call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
  506. call s:NetrwInit("g:netrw_use_noswf" , 1)
  507. call s:NetrwInit("g:netrw_sizestyle" ,"b")
  508. " Default values - t-w ---------- {{{3
  509. call s:NetrwInit("g:netrw_timefmt","%c")
  510. if !exists("g:netrw_xstrlen")
  511. if exists("g:Align_xstrlen")
  512. let g:netrw_xstrlen= g:Align_xstrlen
  513. elseif exists("g:drawit_xstrlen")
  514. let g:netrw_xstrlen= g:drawit_xstrlen
  515. elseif &enc == "latin1" || !has("multi_byte")
  516. let g:netrw_xstrlen= 0
  517. else
  518. let g:netrw_xstrlen= 1
  519. endif
  520. endif
  521. call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
  522. call s:NetrwInit("g:netrw_win95ftp",1)
  523. call s:NetrwInit("g:netrw_winsize",50)
  524. call s:NetrwInit("g:netrw_wiw",1)
  525. if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
  526. " ---------------------------------------------------------------------
  527. " Default values for netrw's script variables: {{{2
  528. call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
  529. if has("win32") || has("win95") || has("win64") || has("win16")
  530. call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
  531. else
  532. call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
  533. endif
  534. call s:NetrwInit("g:netrw_menu_escape",'.&? \')
  535. call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
  536. call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
  537. if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
  538. let s:treedepthstring= "│ "
  539. else
  540. let s:treedepthstring= "| "
  541. endif
  542. call s:NetrwInit("s:netrw_posn",'{}')
  543. " BufEnter event ignored by decho when following variable is true
  544. " Has a side effect that doau BufReadPost doesn't work, so
  545. " files read by network transfer aren't appropriately highlighted.
  546. "let g:decho_bufenter = 1 "Decho
  547. " ======================
  548. " Netrw Initialization: {{{1
  549. " ======================
  550. if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
  551. " call Decho("installed beval events",'~'.expand("<slnum>"))
  552. let &l:bexpr = "netrw#BalloonHelp()"
  553. " call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
  554. au FileType netrw setl beval
  555. au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
  556. au VimEnter * let s:initbeval= &beval
  557. "else " Decho
  558. " if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
  559. " if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
  560. " if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
  561. " if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
  562. " if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
  563. " if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists","~".expand("<slnum>")) | endif
  564. endif
  565. au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
  566. if g:netrw_keepj =~# "keepj"
  567. com! -nargs=* NetrwKeepj keepj <args>
  568. else
  569. let g:netrw_keepj= ""
  570. com! -nargs=* NetrwKeepj <args>
  571. endif
  572. " ==============================
  573. " Netrw Utility Functions: {{{1
  574. " ==============================
  575. " ---------------------------------------------------------------------
  576. " netrw#BalloonHelp: {{{2
  577. if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
  578. " call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
  579. fun! netrw#BalloonHelp()
  580. if &ft != "netrw"
  581. return ""
  582. endif
  583. if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
  584. " popup error window is still showing
  585. " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
  586. if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
  587. " text under mouse hasn't changed; only close window when it changes
  588. call popup_close(s:popuperr_id)
  589. unlet s:popuperr_text
  590. else
  591. let s:popuperr_text= v:beval_text
  592. endif
  593. let mesg= ""
  594. elseif !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
  595. let mesg= ""
  596. elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
  597. let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
  598. elseif getline(v:beval_lnum) =~ '^"\s*/'
  599. let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
  600. elseif v:beval_text == "Sorted" || v:beval_text == "by"
  601. let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
  602. elseif v:beval_text == "Sort" || v:beval_text == "sequence"
  603. let mesg = "S: edit sorting sequence"
  604. elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
  605. let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
  606. elseif v:beval_text == "Quick" || v:beval_text == "Help"
  607. let mesg = "Help: press <F1>"
  608. elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
  609. let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
  610. else
  611. let mesg= ""
  612. endif
  613. return mesg
  614. endfun
  615. "else " Decho
  616. " if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
  617. " if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
  618. " if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
  619. " if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
  620. " if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists","~".expand("<slnum>")) |endif
  621. endif
  622. " ------------------------------------------------------------------------
  623. " netrw#Explore: launch the local browser in the directory of the current file {{{2
  624. " indx: == -1: Nexplore
  625. " == -2: Pexplore
  626. " == +: this is overloaded:
  627. " * If Nexplore/Pexplore is in use, then this refers to the
  628. " indx'th item in the w:netrw_explore_list[] of items which
  629. " matched the */pattern **/pattern *//pattern **//pattern
  630. " * If Hexplore or Vexplore, then this will override
  631. " g:netrw_winsize to specify the qty of rows or columns the
  632. " newly split window should have.
  633. " dosplit==0: the window will be split iff the current file has been modified and hidden not set
  634. " dosplit==1: the window will be split before running the local browser
  635. " style == 0: Explore style == 1: Explore!
  636. " == 2: Hexplore style == 3: Hexplore!
  637. " == 4: Vexplore style == 5: Vexplore!
  638. " == 6: Texplore
  639. fun! netrw#Explore(indx,dosplit,style,...)
  640. " call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
  641. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  642. if !exists("b:netrw_curdir")
  643. let b:netrw_curdir= getcwd()
  644. " call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
  645. endif
  646. " record current file for Rexplore's benefit
  647. if &ft != "netrw"
  648. let w:netrw_rexfile= expand("%:p")
  649. endif
  650. " record current directory
  651. let curdir = simplify(b:netrw_curdir)
  652. let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
  653. if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
  654. let curdir= substitute(curdir,'\','/','g')
  655. endif
  656. " call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
  657. " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
  658. " will end up with backslashes here. Solution: strip off backslashes that precede white space and
  659. " try Explore again.
  660. if a:0 > 0
  661. " call Decho('considering retry: a:1<'.a:1.'>: '.
  662. \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
  663. \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
  664. \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
  665. \ '~'.expand("<slnum>"))
  666. if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
  667. " call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
  668. call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
  669. " call Dret("netrw#Explore : returning from retry")
  670. return
  671. " else " Decho
  672. " call Decho("retry not needed",'~'.expand("<slnum>"))
  673. endif
  674. endif
  675. " save registers
  676. sil! let keepregslash= @/
  677. " if dosplit
  678. " -or- file has been modified AND file not hidden when abandoned
  679. " -or- Texplore used
  680. if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
  681. " call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
  682. call s:SaveWinVars()
  683. let winsz= g:netrw_winsize
  684. if a:indx > 0
  685. let winsz= a:indx
  686. endif
  687. if a:style == 0 " Explore, Sexplore
  688. " call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
  689. let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
  690. if winsz == 0|let winsz= ""|endif
  691. exe "noswapfile ".winsz."wincmd s"
  692. " call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
  693. elseif a:style == 1 "Explore!, Sexplore!
  694. " call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
  695. let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
  696. if winsz == 0|let winsz= ""|endif
  697. exe "keepalt noswapfile ".winsz."wincmd v"
  698. " call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
  699. elseif a:style == 2 " Hexplore
  700. " call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
  701. let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
  702. if winsz == 0|let winsz= ""|endif
  703. exe "keepalt noswapfile bel ".winsz."wincmd s"
  704. " call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
  705. elseif a:style == 3 " Hexplore!
  706. " call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
  707. let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
  708. if winsz == 0|let winsz= ""|endif
  709. exe "keepalt noswapfile abo ".winsz."wincmd s"
  710. " call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
  711. elseif a:style == 4 " Vexplore
  712. " call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
  713. let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
  714. if winsz == 0|let winsz= ""|endif
  715. exe "keepalt noswapfile lefta ".winsz."wincmd v"
  716. " call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
  717. elseif a:style == 5 " Vexplore!
  718. " call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
  719. let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
  720. if winsz == 0|let winsz= ""|endif
  721. exe "keepalt noswapfile rightb ".winsz."wincmd v"
  722. " call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
  723. elseif a:style == 6 " Texplore
  724. call s:SaveBufVars()
  725. " call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
  726. exe "keepalt tabnew ".fnameescape(curdir)
  727. " call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
  728. call s:RestoreBufVars()
  729. endif
  730. call s:RestoreWinVars()
  731. " else " Decho
  732. " call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
  733. endif
  734. NetrwKeepj norm! 0
  735. if a:0 > 0
  736. " call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
  737. if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
  738. " call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
  739. let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
  740. " call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
  741. elseif a:1 == '.'
  742. " call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
  743. let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
  744. if dirname !~ '/$'
  745. let dirname= dirname."/"
  746. endif
  747. " call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
  748. elseif a:1 =~ '\$'
  749. " call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
  750. let dirname= simplify(expand(a:1))
  751. " call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
  752. elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
  753. " call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
  754. let dirname= simplify(a:1)
  755. " call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
  756. else
  757. " call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
  758. let dirname= a:1
  759. endif
  760. else
  761. " clear explore
  762. " call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
  763. call s:NetrwClearExplore()
  764. " call Dret("netrw#Explore : cleared list")
  765. return
  766. endif
  767. " call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
  768. if dirname =~ '\.\./\=$'
  769. let dirname= simplify(fnamemodify(dirname,':p:h'))
  770. elseif dirname =~ '\.\.' || dirname == '.'
  771. let dirname= simplify(fnamemodify(dirname,':p'))
  772. endif
  773. " call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
  774. if dirname =~ '^\*//'
  775. " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
  776. " call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
  777. let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
  778. let starpat= 1
  779. " call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
  780. if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
  781. elseif dirname =~ '^\*\*//'
  782. " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
  783. " call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
  784. let pattern= substitute(dirname,'^\*\*//','','')
  785. let starpat= 2
  786. " call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
  787. elseif dirname =~ '/\*\*/'
  788. " handle .../**/.../filepat
  789. " call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
  790. let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
  791. if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
  792. let b:netrw_curdir = prefixdir
  793. else
  794. let b:netrw_curdir= getcwd().'/'.prefixdir
  795. endif
  796. let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
  797. let starpat= 4
  798. " call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
  799. " call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
  800. elseif dirname =~ '^\*/'
  801. " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
  802. let starpat= 3
  803. " call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
  804. elseif dirname=~ '^\*\*/'
  805. " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
  806. let starpat= 4
  807. " call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
  808. else
  809. let starpat= 0
  810. " call Decho("case starpat=0: default",'~'.expand("<slnum>"))
  811. endif
  812. if starpat == 0 && a:indx >= 0
  813. " [Explore Hexplore Vexplore Sexplore] [dirname]
  814. " call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
  815. if dirname == ""
  816. let dirname= curfiledir
  817. " call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
  818. endif
  819. if dirname =~# '^scp://' || dirname =~ '^ftp://'
  820. call netrw#Nread(2,dirname)
  821. else
  822. if dirname == ""
  823. let dirname= getcwd()
  824. elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
  825. " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
  826. " depending on whether backslashes have been converted to forward slashes by earlier code).
  827. if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
  828. let dirname= b:netrw_curdir."/".dirname
  829. endif
  830. elseif dirname !~ '^/'
  831. let dirname= b:netrw_curdir."/".dirname
  832. endif
  833. " call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
  834. call netrw#LocalBrowseCheck(dirname)
  835. " call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
  836. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  837. endif
  838. if exists("w:netrw_bannercnt")
  839. " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
  840. " If one wants to return the same place in the netrw window, use :Rex instead.
  841. exe w:netrw_bannercnt
  842. endif
  843. " call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
  844. " ---------------------------------------------------------------------
  845. " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
  846. " if has("win32") || has("win95") || has("win64") || has("win16")
  847. " NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
  848. " else
  849. " NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
  850. " endif
  851. " ---------------------------------------------------------------------
  852. " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
  853. " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
  854. " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
  855. " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
  856. elseif a:indx <= 0
  857. " Nexplore, Pexplore, Explore: handle starpat
  858. " call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
  859. if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
  860. " call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
  861. let s:didstarstar= 1
  862. nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
  863. nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
  864. endif
  865. if has("path_extra")
  866. " call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
  867. if !exists("w:netrw_explore_indx")
  868. let w:netrw_explore_indx= 0
  869. endif
  870. let indx = a:indx
  871. " call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
  872. if indx == -1
  873. " Nexplore
  874. " call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
  875. if !exists("w:netrw_explore_list") " sanity check
  876. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
  877. sil! let @/ = keepregslash
  878. " call Dret("netrw#Explore")
  879. return
  880. endif
  881. let indx= w:netrw_explore_indx
  882. if indx < 0 | let indx= 0 | endif
  883. if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
  884. let curfile= w:netrw_explore_list[indx]
  885. " call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
  886. while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
  887. let indx= indx + 1
  888. " call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
  889. endwhile
  890. if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
  891. " call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
  892. elseif indx == -2
  893. " Pexplore
  894. " call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
  895. if !exists("w:netrw_explore_list") " sanity check
  896. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
  897. sil! let @/ = keepregslash
  898. " call Dret("netrw#Explore")
  899. return
  900. endif
  901. let indx= w:netrw_explore_indx
  902. if indx < 0 | let indx= 0 | endif
  903. if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
  904. let curfile= w:netrw_explore_list[indx]
  905. " call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
  906. while indx >= 0 && curfile == w:netrw_explore_list[indx]
  907. let indx= indx - 1
  908. " call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
  909. endwhile
  910. if indx < 0 | let indx= 0 | endif
  911. " call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
  912. else
  913. " Explore -- initialize
  914. " build list of files to Explore with Nexplore/Pexplore
  915. " call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
  916. NetrwKeepj keepalt call s:NetrwClearExplore()
  917. let w:netrw_explore_indx= 0
  918. if !exists("b:netrw_curdir")
  919. let b:netrw_curdir= getcwd()
  920. endif
  921. " call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  922. " switch on starpat to build the w:netrw_explore_list of files
  923. if starpat == 1
  924. " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
  925. " call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
  926. " call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
  927. try
  928. exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
  929. catch /^Vim\%((\a\+)\)\=:E480/
  930. keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
  931. " call Dret("netrw#Explore : unable to find pattern<".pattern.">")
  932. return
  933. endtry
  934. let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
  935. if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
  936. elseif starpat == 2
  937. " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
  938. " call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
  939. " call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
  940. try
  941. exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
  942. catch /^Vim\%((\a\+)\)\=:E480/
  943. keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
  944. if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
  945. sil! let @/ = keepregslash
  946. " call Dret("netrw#Explore : no files matched pattern")
  947. return
  948. endtry
  949. let s:netrw_curdir = b:netrw_curdir
  950. let w:netrw_explore_list = getqflist()
  951. let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
  952. if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
  953. elseif starpat == 3
  954. " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
  955. " call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
  956. let filepat= substitute(dirname,'^\*/','','')
  957. let filepat= substitute(filepat,'^[%#<]','\\&','')
  958. " call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  959. " call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
  960. let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
  961. if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
  962. elseif starpat == 4
  963. " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
  964. " call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
  965. let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
  966. if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
  967. endif " switch on starpat to build w:netrw_explore_list
  968. let w:netrw_explore_listlen = len(w:netrw_explore_list)
  969. " call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
  970. " call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
  971. if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
  972. keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
  973. sil! let @/ = keepregslash
  974. " call Dret("netrw#Explore : no files matched")
  975. return
  976. endif
  977. endif " if indx ... endif
  978. " NetrwStatusLine support - for exploring support
  979. let w:netrw_explore_indx= indx
  980. " call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
  981. " wrap the indx around, but issue a note
  982. if indx >= w:netrw_explore_listlen || indx < 0
  983. " call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
  984. let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
  985. let w:netrw_explore_indx= indx
  986. keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
  987. endif
  988. exe "let dirfile= w:netrw_explore_list[".indx."]"
  989. " call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
  990. let newdir= substitute(dirfile,'/[^/]*$','','e')
  991. " call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
  992. " call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
  993. call netrw#LocalBrowseCheck(newdir)
  994. if !exists("w:netrw_liststyle")
  995. let w:netrw_liststyle= g:netrw_liststyle
  996. endif
  997. if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
  998. keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
  999. else
  1000. keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
  1001. endif
  1002. let w:netrw_explore_mtchcnt = indx + 1
  1003. let w:netrw_explore_bufnr = bufnr("%")
  1004. let w:netrw_explore_line = line(".")
  1005. keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
  1006. " call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
  1007. else
  1008. " call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
  1009. if !exists("g:netrw_quiet")
  1010. keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
  1011. endif
  1012. sil! let @/ = keepregslash
  1013. " call Dret("netrw#Explore : missing +path_extra")
  1014. return
  1015. endif
  1016. else
  1017. " call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
  1018. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
  1019. sil! unlet w:netrw_treedict
  1020. sil! unlet w:netrw_treetop
  1021. endif
  1022. let newdir= dirname
  1023. if !exists("b:netrw_curdir")
  1024. NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
  1025. else
  1026. NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
  1027. endif
  1028. endif
  1029. " visual display of **/ **// */ Exploration files
  1030. " call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
  1031. " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
  1032. if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
  1033. " call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
  1034. if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
  1035. " only update match list when current directory isn't the same as before
  1036. " call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
  1037. let s:explore_prvdir = b:netrw_curdir
  1038. let s:explore_match = ""
  1039. let dirlen = strlen(b:netrw_curdir)
  1040. if b:netrw_curdir !~ '/$'
  1041. let dirlen= dirlen + 1
  1042. endif
  1043. let prvfname= ""
  1044. for fname in w:netrw_explore_list
  1045. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  1046. if fname =~ '^'.b:netrw_curdir
  1047. if s:explore_match == ""
  1048. let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
  1049. else
  1050. let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
  1051. endif
  1052. elseif fname !~ '^/' && fname != prvfname
  1053. if s:explore_match == ""
  1054. let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
  1055. else
  1056. let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
  1057. endif
  1058. endif
  1059. let prvfname= fname
  1060. endfor
  1061. " call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
  1062. if has("syntax") && exists("g:syntax_on") && g:syntax_on
  1063. exe "2match netrwMarkFile /".s:explore_match."/"
  1064. endif
  1065. endif
  1066. echo "<s-up>==Pexplore <s-down>==Nexplore"
  1067. else
  1068. 2match none
  1069. if exists("s:explore_match") | unlet s:explore_match | endif
  1070. if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
  1071. echo " "
  1072. " call Decho("cleared explore match list",'~'.expand("<slnum>"))
  1073. endif
  1074. " since Explore may be used to initialize netrw's browser,
  1075. " there's no danger of a late FocusGained event on initialization.
  1076. " Consequently, set s:netrw_events to 2.
  1077. let s:netrw_events= 2
  1078. sil! let @/ = keepregslash
  1079. " call Dret("netrw#Explore : @/<".@/.">")
  1080. endfun
  1081. " ---------------------------------------------------------------------
  1082. " netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
  1083. fun! netrw#Lexplore(count,rightside,...)
  1084. " call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
  1085. let curwin= winnr()
  1086. if a:0 > 0 && a:1 != ""
  1087. " if a netrw window is already on the left-side of the tab
  1088. " and a directory has been specified, explore with that
  1089. " directory.
  1090. " call Decho("case has input argument(s) (a:1<".a:1.">)")
  1091. let a1 = expand(a:1)
  1092. " call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
  1093. exe "1wincmd w"
  1094. if &ft == "netrw"
  1095. " call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
  1096. exe "Explore ".fnameescape(a1)
  1097. exe curwin."wincmd w"
  1098. if exists("t:netrw_lexposn")
  1099. " call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
  1100. unlet t:netrw_lexposn
  1101. endif
  1102. " call Dret("netrw#Lexplore")
  1103. return
  1104. endif
  1105. exe curwin."wincmd w"
  1106. else
  1107. let a1= ""
  1108. " call Decho("no input arguments")
  1109. endif
  1110. if exists("t:netrw_lexbufnr")
  1111. " check if t:netrw_lexbufnr refers to a netrw window
  1112. let lexwinnr = bufwinnr(t:netrw_lexbufnr)
  1113. " call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
  1114. else
  1115. let lexwinnr= 0
  1116. " call Decho("t:netrw_lexbufnr doesn't exist")
  1117. endif
  1118. " call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
  1119. if lexwinnr > 0
  1120. " close down netrw explorer window
  1121. " call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
  1122. exe lexwinnr."wincmd w"
  1123. let g:netrw_winsize = -winwidth(0)
  1124. let t:netrw_lexposn = winsaveview()
  1125. " call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
  1126. " call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
  1127. close
  1128. if lexwinnr < curwin
  1129. let curwin= curwin - 1
  1130. endif
  1131. if lexwinnr != curwin
  1132. exe curwin."wincmd w"
  1133. endif
  1134. unlet t:netrw_lexbufnr
  1135. " call Decho("unlet t:netrw_lexbufnr")
  1136. else
  1137. " open netrw explorer window
  1138. " call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
  1139. exe "1wincmd w"
  1140. let keep_altv = g:netrw_altv
  1141. let g:netrw_altv = 0
  1142. if a:count != 0
  1143. let netrw_winsize = g:netrw_winsize
  1144. let g:netrw_winsize = a:count
  1145. endif
  1146. let curfile= expand("%")
  1147. " call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
  1148. exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
  1149. " call Decho("new buf#".bufnr("%")." win#".winnr())
  1150. if a:0 > 0 && a1 != ""
  1151. " call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
  1152. call netrw#Explore(0,0,0,a1)
  1153. exe "Explore ".fnameescape(a1)
  1154. elseif curfile =~ '^\a\{3,}://'
  1155. " call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
  1156. call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
  1157. else
  1158. " call Decho("case 3: Explore .",'~'.expand("<slnum>"))
  1159. call netrw#Explore(0,0,0,".")
  1160. endif
  1161. if a:count != 0
  1162. let g:netrw_winsize = netrw_winsize
  1163. endif
  1164. setlocal winfixwidth
  1165. let g:netrw_altv = keep_altv
  1166. let t:netrw_lexbufnr = bufnr("%")
  1167. " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
  1168. " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
  1169. " effort to mis-use :Lex is warranted.
  1170. set bh=wipe
  1171. " call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
  1172. " call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
  1173. if exists("t:netrw_lexposn")
  1174. " call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
  1175. " call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
  1176. call winrestview(t:netrw_lexposn)
  1177. unlet t:netrw_lexposn
  1178. endif
  1179. endif
  1180. " set up default window for editing via <cr>
  1181. if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
  1182. if a:rightside
  1183. let g:netrw_chgwin= 1
  1184. else
  1185. let g:netrw_chgwin= 2
  1186. endif
  1187. " call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
  1188. endif
  1189. " call Dret("netrw#Lexplore")
  1190. endfun
  1191. " ---------------------------------------------------------------------
  1192. " netrw#Clean: remove netrw {{{2
  1193. " supports :NetrwClean -- remove netrw from first directory on runtimepath
  1194. " :NetrwClean! -- remove netrw from all directories on runtimepath
  1195. fun! netrw#Clean(sys)
  1196. " call Dfunc("netrw#Clean(sys=".a:sys.")")
  1197. if a:sys
  1198. let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
  1199. else
  1200. let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
  1201. endif
  1202. " call Decho("choice=".choice,'~'.expand("<slnum>"))
  1203. let diddel= 0
  1204. let diddir= ""
  1205. if choice == 1
  1206. for dir in split(&rtp,',')
  1207. if filereadable(dir."/plugin/netrwPlugin.vim")
  1208. " call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
  1209. if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
  1210. if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
  1211. if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
  1212. if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
  1213. if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
  1214. if s:NetrwDelete(dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif
  1215. let diddir= dir
  1216. let diddel= diddel + 1
  1217. if !a:sys|break|endif
  1218. endif
  1219. endfor
  1220. endif
  1221. echohl WarningMsg
  1222. if diddel == 0
  1223. echomsg "netrw is either not installed or not removable"
  1224. elseif diddel == 1
  1225. echomsg "removed one copy of netrw from <".diddir.">"
  1226. else
  1227. echomsg "removed ".diddel." copies of netrw"
  1228. endif
  1229. echohl None
  1230. " call Dret("netrw#Clean")
  1231. endfun
  1232. " ---------------------------------------------------------------------
  1233. " netrw#MakeTgt: make a target out of the directory name provided {{{2
  1234. fun! netrw#MakeTgt(dname)
  1235. " call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
  1236. " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
  1237. let svpos = winsaveview()
  1238. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  1239. let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
  1240. " call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
  1241. if s:netrwmftgt_islocal
  1242. let netrwmftgt= simplify(a:dname)
  1243. else
  1244. let netrwmftgt= a:dname
  1245. endif
  1246. if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
  1247. " re-selected target, so just clear it
  1248. unlet s:netrwmftgt s:netrwmftgt_islocal
  1249. else
  1250. let s:netrwmftgt= netrwmftgt
  1251. endif
  1252. if g:netrw_fastbrowse <= 1
  1253. call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
  1254. endif
  1255. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
  1256. call winrestview(svpos)
  1257. " call Dret("netrw#MakeTgt")
  1258. endfun
  1259. " ---------------------------------------------------------------------
  1260. " netrw#Obtain: {{{2
  1261. " netrw#Obtain(islocal,fname[,tgtdirectory])
  1262. " islocal=0 obtain from remote source
  1263. " =1 obtain from local source
  1264. " fname : a filename or a list of filenames
  1265. " tgtdir : optional place where files are to go (not present, uses getcwd())
  1266. fun! netrw#Obtain(islocal,fname,...)
  1267. " call Dfunc("netrw#Obtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
  1268. " NetrwStatusLine support - for obtaining support
  1269. if type(a:fname) == 1
  1270. let fnamelist= [ a:fname ]
  1271. elseif type(a:fname) == 3
  1272. let fnamelist= a:fname
  1273. else
  1274. call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
  1275. " call Dret("netrw#Obtain")
  1276. return
  1277. endif
  1278. " call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
  1279. if a:0 > 0
  1280. let tgtdir= a:1
  1281. else
  1282. let tgtdir= getcwd()
  1283. endif
  1284. " call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
  1285. if exists("b:netrw_islocal") && b:netrw_islocal
  1286. " obtain a file from local b:netrw_curdir to (local) tgtdir
  1287. " call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
  1288. if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
  1289. let topath= s:ComposePath(tgtdir,"")
  1290. if (has("win32") || has("win95") || has("win64") || has("win16"))
  1291. " transfer files one at time
  1292. " call Decho("transfer files one at a time",'~'.expand("<slnum>"))
  1293. for fname in fnamelist
  1294. " call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
  1295. call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
  1296. if v:shell_error != 0
  1297. call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
  1298. " call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
  1299. return
  1300. endif
  1301. endfor
  1302. else
  1303. " transfer files with one command
  1304. " call Decho("transfer files with one command",'~'.expand("<slnum>"))
  1305. let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
  1306. " call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
  1307. call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
  1308. if v:shell_error != 0
  1309. call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
  1310. " call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
  1311. return
  1312. endif
  1313. endif
  1314. elseif !exists("b:netrw_curdir")
  1315. call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
  1316. else
  1317. call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
  1318. endif
  1319. else
  1320. " obtain files from remote b:netrw_curdir to local tgtdir
  1321. " call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
  1322. if type(a:fname) == 1
  1323. call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
  1324. endif
  1325. call s:NetrwMethod(b:netrw_curdir)
  1326. if b:netrw_method == 4
  1327. " obtain file using scp
  1328. " call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
  1329. if exists("g:netrw_port") && g:netrw_port != ""
  1330. let useport= " ".g:netrw_scpport." ".g:netrw_port
  1331. else
  1332. let useport= ""
  1333. endif
  1334. if b:netrw_fname =~ '/'
  1335. let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
  1336. else
  1337. let path= ""
  1338. endif
  1339. let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
  1340. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".filelist." ".s:ShellEscape(tgtdir,1))
  1341. elseif b:netrw_method == 2
  1342. " obtain file using ftp + .netrc
  1343. " call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
  1344. call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
  1345. let tmpbufnr= bufnr("%")
  1346. setl ff=unix
  1347. if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
  1348. NetrwKeepj put =g:netrw_ftpmode
  1349. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1350. endif
  1351. if exists("b:netrw_fname") && b:netrw_fname != ""
  1352. call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
  1353. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1354. endif
  1355. if exists("g:netrw_ftpextracmd")
  1356. NetrwKeepj put =g:netrw_ftpextracmd
  1357. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1358. endif
  1359. for fname in fnamelist
  1360. call setline(line("$")+1,'get "'.fname.'"')
  1361. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1362. endfor
  1363. if exists("g:netrw_port") && g:netrw_port != ""
  1364. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
  1365. else
  1366. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
  1367. endif
  1368. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  1369. if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
  1370. let debugkeep= &debug
  1371. setl debug=msg
  1372. call netrw#ErrorMsg(s:ERROR,getline(1),4)
  1373. let &debug= debugkeep
  1374. endif
  1375. elseif b:netrw_method == 3
  1376. " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
  1377. " call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
  1378. call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
  1379. let tmpbufnr= bufnr("%")
  1380. setl ff=unix
  1381. if exists("g:netrw_port") && g:netrw_port != ""
  1382. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  1383. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1384. else
  1385. NetrwKeepj put ='open '.g:netrw_machine
  1386. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1387. endif
  1388. if exists("g:netrw_uid") && g:netrw_uid != ""
  1389. if exists("g:netrw_ftp") && g:netrw_ftp == 1
  1390. NetrwKeepj put =g:netrw_uid
  1391. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1392. if exists("s:netrw_passwd") && s:netrw_passwd != ""
  1393. NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
  1394. endif
  1395. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1396. elseif exists("s:netrw_passwd")
  1397. NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
  1398. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1399. endif
  1400. endif
  1401. if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
  1402. NetrwKeepj put =g:netrw_ftpmode
  1403. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1404. endif
  1405. if exists("b:netrw_fname") && b:netrw_fname != ""
  1406. NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
  1407. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1408. endif
  1409. if exists("g:netrw_ftpextracmd")
  1410. NetrwKeepj put =g:netrw_ftpextracmd
  1411. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1412. endif
  1413. if exists("g:netrw_ftpextracmd")
  1414. NetrwKeepj put =g:netrw_ftpextracmd
  1415. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1416. endif
  1417. for fname in fnamelist
  1418. NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
  1419. endfor
  1420. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  1421. " perform ftp:
  1422. " -i : turns off interactive prompting from ftp
  1423. " -n unix : DON'T use <.netrc>, even though it exists
  1424. " -n win32: quit being obnoxious about password
  1425. " Note: using "_dd to delete to the black hole register; avoids messing up @@
  1426. NetrwKeepj norm! 1G"_dd
  1427. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
  1428. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  1429. if getline(1) !~ "^$"
  1430. " call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
  1431. if !exists("g:netrw_quiet")
  1432. NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
  1433. endif
  1434. endif
  1435. elseif b:netrw_method == 9
  1436. " obtain file using sftp
  1437. " call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
  1438. if a:fname =~ '/'
  1439. let localfile= substitute(a:fname,'^.*/','','')
  1440. else
  1441. let localfile= a:fname
  1442. endif
  1443. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1).s:ShellEscape(localfile)." ".s:ShellEscape(tgtdir))
  1444. elseif !exists("b:netrw_method") || b:netrw_method < 0
  1445. " probably a badly formed url; protocol not recognized
  1446. " call Dret("netrw#Obtain : unsupported method")
  1447. return
  1448. else
  1449. " protocol recognized but not supported for Obtain (yet?)
  1450. if !exists("g:netrw_quiet")
  1451. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
  1452. endif
  1453. " call Dret("netrw#Obtain : current protocol not supported for obtaining file")
  1454. return
  1455. endif
  1456. " restore status line
  1457. if type(a:fname) == 1 && exists("s:netrw_users_stl")
  1458. NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
  1459. endif
  1460. endif
  1461. " cleanup
  1462. if exists("tmpbufnr")
  1463. if bufnr("%") != tmpbufnr
  1464. exe tmpbufnr."bw!"
  1465. else
  1466. q!
  1467. endif
  1468. endif
  1469. " call Dret("netrw#Obtain")
  1470. endfun
  1471. " ---------------------------------------------------------------------
  1472. " netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
  1473. fun! netrw#Nread(mode,fname)
  1474. " call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
  1475. let svpos= winsaveview()
  1476. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  1477. call netrw#NetRead(a:mode,a:fname)
  1478. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  1479. call winrestview(svpos)
  1480. if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
  1481. if exists("w:netrw_bannercnt")
  1482. " start with cursor just after the banner
  1483. exe w:netrw_bannercnt
  1484. endif
  1485. endif
  1486. " call Dret("netrw#Nread")
  1487. endfun
  1488. " ------------------------------------------------------------------------
  1489. " s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
  1490. " Options get restored by s:NetrwOptionsRestore()
  1491. "
  1492. " Option handling:
  1493. " * save user's options (s:NetrwOptionsSave)
  1494. " * set netrw-safe options (s:NetrwOptionsSafe)
  1495. " - change an option only when user option != safe option (s:netrwSetSafeSetting)
  1496. " * restore user's options (s:netrwOPtionsRestore)
  1497. " - restore a user option when != safe option (s:NetrwRestoreSetting)
  1498. " vt: (variable type) normally its either "w:" or "s:"
  1499. fun! s:NetrwOptionsSave(vt)
  1500. " call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
  1501. " call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
  1502. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt." hid=".&hid,'~'.expand("<slnum>"))
  1503. " call Decho("(s:NetrwOptionsSave) lines=".&lines)
  1504. if !exists("{a:vt}netrw_optionsave")
  1505. let {a:vt}netrw_optionsave= 1
  1506. else
  1507. " call Dret("s:NetrwOptionsSave : options already saved")
  1508. return
  1509. endif
  1510. " call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
  1511. " Save current settings and current directory
  1512. " call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
  1513. let s:yykeep = @@
  1514. if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
  1515. let {a:vt}netrw_aikeep = &l:ai
  1516. let {a:vt}netrw_awkeep = &l:aw
  1517. let {a:vt}netrw_bhkeep = &l:bh
  1518. let {a:vt}netrw_blkeep = &l:bl
  1519. let {a:vt}netrw_btkeep = &l:bt
  1520. let {a:vt}netrw_bombkeep = &l:bomb
  1521. let {a:vt}netrw_cedit = &cedit
  1522. let {a:vt}netrw_cikeep = &l:ci
  1523. let {a:vt}netrw_cinkeep = &l:cin
  1524. let {a:vt}netrw_cinokeep = &l:cino
  1525. let {a:vt}netrw_comkeep = &l:com
  1526. let {a:vt}netrw_cpokeep = &l:cpo
  1527. let {a:vt}netrw_cuckeep = &l:cuc
  1528. let {a:vt}netrw_culkeep = &l:cul
  1529. " call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
  1530. let {a:vt}netrw_diffkeep = &l:diff
  1531. let {a:vt}netrw_fenkeep = &l:fen
  1532. if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
  1533. let {a:vt}netrw_ffkeep = &l:ff
  1534. endif
  1535. let {a:vt}netrw_fokeep = &l:fo " formatoptions
  1536. let {a:vt}netrw_gdkeep = &l:gd " gdefault
  1537. let {a:vt}netrw_gokeep = &l:go " guioptions
  1538. let {a:vt}netrw_hidkeep = &l:hidden
  1539. let {a:vt}netrw_imkeep = &l:im
  1540. let {a:vt}netrw_iskkeep = &l:isk
  1541. let {a:vt}netrw_lines = &lines
  1542. let {a:vt}netrw_lskeep = &l:ls
  1543. let {a:vt}netrw_makeep = &l:ma
  1544. let {a:vt}netrw_magickeep = &l:magic
  1545. let {a:vt}netrw_modkeep = &l:mod
  1546. let {a:vt}netrw_nukeep = &l:nu
  1547. let {a:vt}netrw_rnukeep = &l:rnu
  1548. let {a:vt}netrw_repkeep = &l:report
  1549. let {a:vt}netrw_rokeep = &l:ro
  1550. let {a:vt}netrw_selkeep = &l:sel
  1551. let {a:vt}netrw_spellkeep = &l:spell
  1552. if !g:netrw_use_noswf
  1553. let {a:vt}netrw_swfkeep = &l:swf
  1554. endif
  1555. let {a:vt}netrw_tskeep = &l:ts
  1556. let {a:vt}netrw_twkeep = &l:tw " textwidth
  1557. let {a:vt}netrw_wigkeep = &l:wig " wildignore
  1558. let {a:vt}netrw_wrapkeep = &l:wrap
  1559. let {a:vt}netrw_writekeep = &l:write
  1560. " save a few selected netrw-related variables
  1561. " call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
  1562. if g:netrw_keepdir
  1563. let {a:vt}netrw_dirkeep = getcwd()
  1564. " call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
  1565. endif
  1566. sil! let {a:vt}netrw_slashkeep= @/
  1567. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
  1568. " call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
  1569. endfun
  1570. " ---------------------------------------------------------------------
  1571. " s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
  1572. " Use s:NetrwSaveOptions() to save user settings
  1573. " Use s:NetrwOptionsRestore() to restore user settings
  1574. fun! s:NetrwOptionsSafe(islocal)
  1575. " call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
  1576. " call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
  1577. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  1578. if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
  1579. call s:NetrwSetSafeSetting("&l:ai",0)
  1580. call s:NetrwSetSafeSetting("&l:aw",0)
  1581. call s:NetrwSetSafeSetting("&l:bl",0)
  1582. call s:NetrwSetSafeSetting("&l:bomb",0)
  1583. if a:islocal
  1584. call s:NetrwSetSafeSetting("&l:bt","nofile")
  1585. else
  1586. call s:NetrwSetSafeSetting("&l:bt","acwrite")
  1587. endif
  1588. call s:NetrwSetSafeSetting("&l:ci",0)
  1589. call s:NetrwSetSafeSetting("&l:cin",0)
  1590. if g:netrw_fastbrowse > a:islocal
  1591. call s:NetrwSetSafeSetting("&l:bh","hide")
  1592. else
  1593. call s:NetrwSetSafeSetting("&l:bh","delete")
  1594. endif
  1595. call s:NetrwSetSafeSetting("&l:cino","")
  1596. call s:NetrwSetSafeSetting("&l:com","")
  1597. if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
  1598. if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
  1599. setl fo=nroql2
  1600. " call s:NetrwSetSafeSetting("&go","begmr")
  1601. if &go =~ '\ca' | call s:NetrwSetSafeSetting("&go",substitute(&go,'\ca','','g')) | endif
  1602. call s:NetrwSetSafeSetting("&l:hid",0)
  1603. call s:NetrwSetSafeSetting("&l:im",0)
  1604. setl isk+=@ isk+=* isk+=/
  1605. call s:NetrwSetSafeSetting("&l:magic",1)
  1606. if g:netrw_use_noswf
  1607. call s:NetrwSetSafeSetting("swf",0)
  1608. endif
  1609. call s:NetrwSetSafeSetting("&l:report",10000)
  1610. call s:NetrwSetSafeSetting("&l:sel","inclusive")
  1611. call s:NetrwSetSafeSetting("&l:spell",0)
  1612. call s:NetrwSetSafeSetting("&l:tw",0)
  1613. call s:NetrwSetSafeSetting("&l:wig","")
  1614. setl cedit&
  1615. " set up cuc and cul based on g:netrw_cursor and listing style
  1616. " COMBAK -- cuc cul related
  1617. call s:NetrwCursor(0)
  1618. " allow the user to override safe options
  1619. " call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
  1620. if &ft == "netrw"
  1621. " call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
  1622. keepalt NetrwKeepj doau FileType netrw
  1623. endif
  1624. " call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
  1625. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  1626. " call Dret("s:NetrwOptionsSafe")
  1627. endfun
  1628. " ---------------------------------------------------------------------
  1629. " s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
  1630. fun! s:NetrwOptionsRestore(vt)
  1631. " call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
  1632. " call Decho("(s:NetrwOptionsRestore) lines=".&lines)
  1633. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
  1634. if !exists("{a:vt}netrw_optionsave")
  1635. " call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
  1636. " call Decho("..doing filetype detect anyway")
  1637. filetype detect
  1638. " call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
  1639. " call Decho("..ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  1640. " call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
  1641. return
  1642. endif
  1643. unlet {a:vt}netrw_optionsave
  1644. if exists("+acd")
  1645. if exists("{a:vt}netrw_acdkeep")
  1646. " call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
  1647. let curdir = getcwd()
  1648. let &l:acd = {a:vt}netrw_acdkeep
  1649. unlet {a:vt}netrw_acdkeep
  1650. if &l:acd
  1651. call s:NetrwLcd(curdir)
  1652. endif
  1653. endif
  1654. endif
  1655. " call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
  1656. call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
  1657. call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
  1658. call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
  1659. call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
  1660. call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
  1661. " call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
  1662. call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
  1663. call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
  1664. call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
  1665. call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
  1666. call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
  1667. " call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
  1668. call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
  1669. call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
  1670. call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
  1671. if exists("g:netrw_ffkeep") && g:netrw_ffkeep
  1672. call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
  1673. endif
  1674. " call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
  1675. call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
  1676. call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
  1677. call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&l:go")
  1678. call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
  1679. " call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
  1680. call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
  1681. call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
  1682. " call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
  1683. call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
  1684. " call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
  1685. call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
  1686. call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
  1687. call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
  1688. call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
  1689. call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
  1690. " call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
  1691. call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
  1692. call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
  1693. call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
  1694. call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
  1695. " call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
  1696. call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
  1697. call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
  1698. call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
  1699. call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
  1700. call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
  1701. " call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
  1702. call s:NetrwRestoreSetting("s:yykeep","@@")
  1703. " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
  1704. " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
  1705. " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
  1706. call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
  1707. if exists("{a:vt}netrw_swfkeep")
  1708. if &directory == ""
  1709. " user hasn't specified a swapfile directory;
  1710. " netrw will temporarily set the swapfile directory
  1711. " to the current directory as returned by getcwd().
  1712. let &l:directory= getcwd()
  1713. sil! let &l:swf = {a:vt}netrw_swfkeep
  1714. setl directory=
  1715. unlet {a:vt}netrw_swfkeep
  1716. elseif &l:swf != {a:vt}netrw_swfkeep
  1717. if !g:netrw_use_noswf
  1718. " following line causes a Press ENTER in windows -- can't seem to work around it!!!
  1719. sil! let &l:swf= {a:vt}netrw_swfkeep
  1720. endif
  1721. unlet {a:vt}netrw_swfkeep
  1722. endif
  1723. endif
  1724. if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
  1725. let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
  1726. if exists("{a:vt}netrw_dirkeep")
  1727. call s:NetrwLcd(dirkeep)
  1728. unlet {a:vt}netrw_dirkeep
  1729. endif
  1730. endif
  1731. call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
  1732. " call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
  1733. " call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
  1734. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  1735. " call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
  1736. " call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
  1737. " Moved the filetype detect here from NetrwGetFile() because remote files
  1738. " were having their filetype detect-generated settings overwritten by
  1739. " NetrwOptionRestore.
  1740. if &ft != "netrw"
  1741. " call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
  1742. filetype detect
  1743. " call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
  1744. endif
  1745. " call Decho("(s:NetrwOptionsRestore) lines=".&lines)
  1746. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
  1747. " call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
  1748. endfun
  1749. " ---------------------------------------------------------------------
  1750. " s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
  1751. " but only when the options' value and the safe setting differ
  1752. " Doing this means that netrw will not come up as having changed a
  1753. " setting last when it really didn't actually change it.
  1754. "
  1755. " Called from s:NetrwOptionsSafe
  1756. " ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
  1757. fun! s:NetrwSetSafeSetting(setting,safesetting)
  1758. " call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
  1759. if a:setting =~ '^&'
  1760. " call Decho("fyi: a:setting starts with &")
  1761. exe "let settingval= ".a:setting
  1762. " call Decho("fyi: settingval<".settingval.">")
  1763. if settingval != a:safesetting
  1764. " call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
  1765. if type(a:safesetting) == 0
  1766. exe "let ".a:setting."=".a:safesetting
  1767. elseif type(a:safesetting) == 1
  1768. exe "let ".a:setting."= '".a:safesetting."'"
  1769. else
  1770. call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
  1771. endif
  1772. endif
  1773. endif
  1774. " call Dret("s:NetrwSetSafeSetting")
  1775. endfun
  1776. " ------------------------------------------------------------------------
  1777. " s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
  1778. " but only if the setting value differs from the associated keepvar.
  1779. " Doing this means that netrw will not come up as having changed a
  1780. " setting last when it really didn't actually change it.
  1781. "
  1782. " Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
  1783. " keepvars are set up by s:NetrwOptionsSave
  1784. fun! s:NetrwRestoreSetting(keepvar,setting)
  1785. """ call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
  1786. " typically called from s:NetrwOptionsRestore
  1787. " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
  1788. " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
  1789. " Restores option (but only if different) from a:keepvar
  1790. if exists(a:keepvar)
  1791. exe "let keepvarval= ".a:keepvar
  1792. exe "let setting= ".a:setting
  1793. "" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
  1794. "" call Decho("fyi: keepvarval=".keepvarval)
  1795. "" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
  1796. if setting != keepvarval
  1797. "" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
  1798. if type(a:setting) == 0
  1799. exe "let ".a:setting."= ".keepvarval
  1800. elseif type(a:setting) == 1
  1801. exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
  1802. else
  1803. call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
  1804. endif
  1805. endif
  1806. exe "unlet ".a:keepvar
  1807. endif
  1808. "" call Dret("s:NetrwRestoreSetting")
  1809. endfun
  1810. " ---------------------------------------------------------------------
  1811. " NetrwStatusLine: {{{2
  1812. fun! NetrwStatusLine()
  1813. " vvv NetrwStatusLine() debugging vvv
  1814. " let g:stlmsg=""
  1815. " if !exists("w:netrw_explore_bufnr")
  1816. " let g:stlmsg="!X<explore_bufnr>"
  1817. " elseif w:netrw_explore_bufnr != bufnr("%")
  1818. " let g:stlmsg="explore_bufnr!=".bufnr("%")
  1819. " endif
  1820. " if !exists("w:netrw_explore_line")
  1821. " let g:stlmsg=" !X<explore_line>"
  1822. " elseif w:netrw_explore_line != line(".")
  1823. " let g:stlmsg=" explore_line!={line(.)<".line(".").">"
  1824. " endif
  1825. " if !exists("w:netrw_explore_list")
  1826. " let g:stlmsg=" !X<explore_list>"
  1827. " endif
  1828. " ^^^ NetrwStatusLine() debugging ^^^
  1829. if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
  1830. " restore user's status line
  1831. let &stl = s:netrw_users_stl
  1832. let &laststatus = s:netrw_users_ls
  1833. if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
  1834. if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
  1835. return ""
  1836. else
  1837. return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
  1838. endif
  1839. endfun
  1840. " ===============================
  1841. " Netrw Transfer Functions: {{{1
  1842. " ===============================
  1843. " ------------------------------------------------------------------------
  1844. " netrw#NetRead: responsible for reading a file over the net {{{2
  1845. " mode: =0 read remote file and insert before current line
  1846. " =1 read remote file and insert after current line
  1847. " =2 replace with remote file
  1848. " =3 obtain file, but leave in temporary format
  1849. fun! netrw#NetRead(mode,...)
  1850. " call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
  1851. " NetRead: save options {{{3
  1852. call s:NetrwOptionsSave("w:")
  1853. call s:NetrwOptionsSafe(0)
  1854. call s:RestoreCursorline()
  1855. " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
  1856. " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
  1857. setl bl
  1858. " call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
  1859. " NetRead: interpret mode into a readcmd {{{3
  1860. if a:mode == 0 " read remote file before current line
  1861. let readcmd = "0r"
  1862. elseif a:mode == 1 " read file after current line
  1863. let readcmd = "r"
  1864. elseif a:mode == 2 " replace with remote file
  1865. let readcmd = "%r"
  1866. elseif a:mode == 3 " skip read of file (leave as temporary)
  1867. let readcmd = "t"
  1868. else
  1869. exe a:mode
  1870. let readcmd = "r"
  1871. endif
  1872. let ichoice = (a:0 == 0)? 0 : 1
  1873. " call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
  1874. " NetRead: get temporary filename {{{3
  1875. let tmpfile= s:GetTempfile("")
  1876. if tmpfile == ""
  1877. " call Dret("netrw#NetRead : unable to get a tempfile!")
  1878. return
  1879. endif
  1880. while ichoice <= a:0
  1881. " attempt to repeat with previous host-file-etc
  1882. if exists("b:netrw_lastfile") && a:0 == 0
  1883. " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
  1884. let choice = b:netrw_lastfile
  1885. let ichoice= ichoice + 1
  1886. else
  1887. exe "let choice= a:" . ichoice
  1888. " call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
  1889. if match(choice,"?") == 0
  1890. " give help
  1891. echomsg 'NetRead Usage:'
  1892. echomsg ':Nread machine:path uses rcp'
  1893. echomsg ':Nread "machine path" uses ftp with <.netrc>'
  1894. echomsg ':Nread "machine id password path" uses ftp'
  1895. echomsg ':Nread dav://machine[:port]/path uses cadaver'
  1896. echomsg ':Nread fetch://machine/path uses fetch'
  1897. echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
  1898. echomsg ':Nread http://[user@]machine/path uses http wget'
  1899. echomsg ':Nread file:///path uses elinks'
  1900. echomsg ':Nread https://[user@]machine/path uses http wget'
  1901. echomsg ':Nread rcp://[user@]machine/path uses rcp'
  1902. echomsg ':Nread rsync://machine[:port]/path uses rsync'
  1903. echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
  1904. echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
  1905. sleep 4
  1906. break
  1907. elseif match(choice,'^"') != -1
  1908. " Reconstruct Choice if choice starts with '"'
  1909. " call Decho("reconstructing choice",'~'.expand("<slnum>"))
  1910. if match(choice,'"$') != -1
  1911. " case "..."
  1912. let choice= strpart(choice,1,strlen(choice)-2)
  1913. else
  1914. " case "... ... ..."
  1915. let choice = strpart(choice,1,strlen(choice)-1)
  1916. let wholechoice = ""
  1917. while match(choice,'"$') == -1
  1918. let wholechoice = wholechoice . " " . choice
  1919. let ichoice = ichoice + 1
  1920. if ichoice > a:0
  1921. if !exists("g:netrw_quiet")
  1922. call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
  1923. endif
  1924. " call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
  1925. return
  1926. endif
  1927. let choice= a:{ichoice}
  1928. endwhile
  1929. let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
  1930. endif
  1931. endif
  1932. endif
  1933. " call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
  1934. let ichoice= ichoice + 1
  1935. " NetRead: Determine method of read (ftp, rcp, etc) {{{3
  1936. call s:NetrwMethod(choice)
  1937. if !exists("b:netrw_method") || b:netrw_method < 0
  1938. " call Dret("netrw#NetRead : unsupported method")
  1939. return
  1940. endif
  1941. let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
  1942. " Check whether or not NetrwBrowse() should be handling this request
  1943. " call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">",'~'.expand("<slnum>"))
  1944. if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
  1945. " call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
  1946. NetrwKeepj call s:NetrwBrowse(0,choice)
  1947. " call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
  1948. return
  1949. endif
  1950. " ============
  1951. " NetRead: Perform Protocol-Based Read {{{3
  1952. " ===========================
  1953. if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
  1954. echo "(netrw) Processing your read request..."
  1955. endif
  1956. ".........................................
  1957. " NetRead: (rcp) NetRead Method #1 {{{3
  1958. if b:netrw_method == 1 " read with rcp
  1959. " call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
  1960. " ER: nothing done with g:netrw_uid yet?
  1961. " ER: on Win2K" rcp machine[.user]:file tmpfile
  1962. " ER: when machine contains '.' adding .user is required (use $USERNAME)
  1963. " ER: the tmpfile is full path: rcp sees C:\... as host C
  1964. if s:netrw_has_nt_rcp == 1
  1965. if exists("g:netrw_uid") && ( g:netrw_uid != "" )
  1966. let uid_machine = g:netrw_machine .'.'. g:netrw_uid
  1967. else
  1968. " Any way needed it machine contains a '.'
  1969. let uid_machine = g:netrw_machine .'.'. $USERNAME
  1970. endif
  1971. else
  1972. if exists("g:netrw_uid") && ( g:netrw_uid != "" )
  1973. let uid_machine = g:netrw_uid .'@'. g:netrw_machine
  1974. else
  1975. let uid_machine = g:netrw_machine
  1976. endif
  1977. endif
  1978. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
  1979. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  1980. let b:netrw_lastfile = choice
  1981. ".........................................
  1982. " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
  1983. elseif b:netrw_method == 2 " read with ftp + <.netrc>
  1984. " call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
  1985. let netrw_fname= b:netrw_fname
  1986. NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
  1987. let filtbuf= bufnr("%")
  1988. setl ff=unix
  1989. NetrwKeepj put =g:netrw_ftpmode
  1990. " call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
  1991. if exists("g:netrw_ftpextracmd")
  1992. NetrwKeepj put =g:netrw_ftpextracmd
  1993. " call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
  1994. endif
  1995. call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
  1996. " call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
  1997. if exists("g:netrw_port") && g:netrw_port != ""
  1998. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
  1999. else
  2000. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
  2001. endif
  2002. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  2003. if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
  2004. let debugkeep = &debug
  2005. setl debug=msg
  2006. NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
  2007. let &debug = debugkeep
  2008. endif
  2009. call s:SaveBufVars()
  2010. keepj bd!
  2011. if bufname("%") == "" && getline("$") == "" && line('$') == 1
  2012. " needed when one sources a file in a nolbl setting window via ftp
  2013. q!
  2014. endif
  2015. call s:RestoreBufVars()
  2016. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2017. let b:netrw_lastfile = choice
  2018. ".........................................
  2019. " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
  2020. elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
  2021. " Construct execution string (four lines) which will be passed through filter
  2022. " call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
  2023. let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
  2024. NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
  2025. let filtbuf= bufnr("%")
  2026. setl ff=unix
  2027. if exists("g:netrw_port") && g:netrw_port != ""
  2028. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  2029. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2030. else
  2031. NetrwKeepj put ='open '.g:netrw_machine
  2032. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2033. endif
  2034. if exists("g:netrw_uid") && g:netrw_uid != ""
  2035. if exists("g:netrw_ftp") && g:netrw_ftp == 1
  2036. NetrwKeepj put =g:netrw_uid
  2037. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2038. if exists("s:netrw_passwd")
  2039. NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
  2040. endif
  2041. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2042. elseif exists("s:netrw_passwd")
  2043. NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
  2044. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2045. endif
  2046. endif
  2047. if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
  2048. NetrwKeepj put =g:netrw_ftpmode
  2049. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2050. endif
  2051. if exists("g:netrw_ftpextracmd")
  2052. NetrwKeepj put =g:netrw_ftpextracmd
  2053. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2054. endif
  2055. NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
  2056. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2057. " perform ftp:
  2058. " -i : turns off interactive prompting from ftp
  2059. " -n unix : DON'T use <.netrc>, even though it exists
  2060. " -n win32: quit being obnoxious about password
  2061. NetrwKeepj norm! 1G"_dd
  2062. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
  2063. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  2064. if getline(1) !~ "^$"
  2065. " call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
  2066. if !exists("g:netrw_quiet")
  2067. call netrw#ErrorMsg(s:ERROR,getline(1),5)
  2068. endif
  2069. endif
  2070. call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
  2071. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2072. let b:netrw_lastfile = choice
  2073. ".........................................
  2074. " NetRead: (scp) NetRead Method #4 {{{3
  2075. elseif b:netrw_method == 4 " read with scp
  2076. " call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
  2077. if exists("g:netrw_port") && g:netrw_port != ""
  2078. let useport= " ".g:netrw_scpport." ".g:netrw_port
  2079. else
  2080. let useport= ""
  2081. endif
  2082. " 'C' in 'C:\path\to\file' is handled as hostname on windows.
  2083. " This is workaround to avoid mis-handle windows local-path:
  2084. if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
  2085. let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
  2086. else
  2087. let tmpfile_get = tmpfile
  2088. endif
  2089. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".s:ShellEscape(tmpfile_get,1))
  2090. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2091. let b:netrw_lastfile = choice
  2092. ".........................................
  2093. " NetRead: (http) NetRead Method #5 (wget) {{{3
  2094. elseif b:netrw_method == 5
  2095. " call Decho("read via http (method #5)",'~'.expand("<slnum>"))
  2096. if g:netrw_http_cmd == ""
  2097. if !exists("g:netrw_quiet")
  2098. call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
  2099. endif
  2100. " call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
  2101. return
  2102. endif
  2103. if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
  2104. " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
  2105. " call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
  2106. if exists("g:netrw_http_xcmd")
  2107. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".s:ShellEscape(tmpfile,1))
  2108. else
  2109. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
  2110. endif
  2111. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2112. else
  2113. " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
  2114. " call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
  2115. let netrw_html= substitute(b:netrw_fname,"#.*$","","")
  2116. let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
  2117. " call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
  2118. " call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
  2119. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
  2120. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2121. " call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
  2122. exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
  2123. endif
  2124. let b:netrw_lastfile = choice
  2125. " call Decho("setl ro",'~'.expand("<slnum>"))
  2126. setl ro nomod
  2127. ".........................................
  2128. " NetRead: (dav) NetRead Method #6 {{{3
  2129. elseif b:netrw_method == 6
  2130. " call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
  2131. if !executable(g:netrw_dav_cmd)
  2132. call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
  2133. " call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
  2134. return
  2135. endif
  2136. if g:netrw_dav_cmd =~ "curl"
  2137. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".s:ShellEscape("dav://".g:netrw_machine.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
  2138. else
  2139. " Construct execution string (four lines) which will be passed through filter
  2140. let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
  2141. new
  2142. setl ff=unix
  2143. if exists("g:netrw_port") && g:netrw_port != ""
  2144. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  2145. else
  2146. NetrwKeepj put ='open '.g:netrw_machine
  2147. endif
  2148. if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
  2149. NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
  2150. endif
  2151. NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
  2152. NetrwKeepj put ='quit'
  2153. " perform cadaver operation:
  2154. NetrwKeepj norm! 1G"_dd
  2155. call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
  2156. keepj bd!
  2157. endif
  2158. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2159. let b:netrw_lastfile = choice
  2160. ".........................................
  2161. " NetRead: (rsync) NetRead Method #7 {{{3
  2162. elseif b:netrw_method == 7
  2163. " call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
  2164. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
  2165. let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
  2166. let b:netrw_lastfile = choice
  2167. ".........................................
  2168. " NetRead: (fetch) NetRead Method #8 {{{3
  2169. " fetch://[user@]host[:http]/path
  2170. elseif b:netrw_method == 8
  2171. " call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
  2172. if g:netrw_fetch_cmd == ""
  2173. if !exists("g:netrw_quiet")
  2174. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
  2175. endif
  2176. " call Dret("NetRead")
  2177. return
  2178. endif
  2179. if exists("g:netrw_option") && g:netrw_option =~ ":https\="
  2180. let netrw_option= "http"
  2181. else
  2182. let netrw_option= "ftp"
  2183. endif
  2184. " call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
  2185. if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
  2186. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
  2187. else
  2188. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
  2189. endif
  2190. let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
  2191. let b:netrw_lastfile = choice
  2192. " call Decho("setl ro",'~'.expand("<slnum>"))
  2193. setl ro nomod
  2194. ".........................................
  2195. " NetRead: (sftp) NetRead Method #9 {{{3
  2196. elseif b:netrw_method == 9
  2197. " call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
  2198. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
  2199. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2200. let b:netrw_lastfile = choice
  2201. ".........................................
  2202. " NetRead: (file) NetRead Method #10 {{{3
  2203. elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
  2204. " " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
  2205. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
  2206. let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
  2207. let b:netrw_lastfile = choice
  2208. ".........................................
  2209. " NetRead: Complain {{{3
  2210. else
  2211. call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
  2212. endif
  2213. endwhile
  2214. " NetRead: cleanup {{{3
  2215. if exists("b:netrw_method")
  2216. " call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
  2217. unlet b:netrw_method
  2218. unlet b:netrw_fname
  2219. endif
  2220. if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
  2221. " call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
  2222. NetrwKeepj call s:NetrwDelete(tmpfile)
  2223. endif
  2224. NetrwKeepj call s:NetrwOptionsRestore("w:")
  2225. " call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
  2226. endfun
  2227. " ------------------------------------------------------------------------
  2228. " netrw#NetWrite: responsible for writing a file over the net {{{2
  2229. fun! netrw#NetWrite(...) range
  2230. " call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
  2231. " NetWrite: option handling {{{3
  2232. let mod= 0
  2233. call s:NetrwOptionsSave("w:")
  2234. call s:NetrwOptionsSafe(0)
  2235. " NetWrite: Get Temporary Filename {{{3
  2236. let tmpfile= s:GetTempfile("")
  2237. if tmpfile == ""
  2238. " call Dret("netrw#NetWrite : unable to get a tempfile!")
  2239. return
  2240. endif
  2241. if a:0 == 0
  2242. let ichoice = 0
  2243. else
  2244. let ichoice = 1
  2245. endif
  2246. let curbufname= expand("%")
  2247. " call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
  2248. if &binary
  2249. " For binary writes, always write entire file.
  2250. " (line numbers don't really make sense for that).
  2251. " Also supports the writing of tar and zip files.
  2252. " call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
  2253. exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
  2254. elseif g:netrw_cygwin
  2255. " write (selected portion of) file to temporary
  2256. let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
  2257. " call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile),'~'.expand("<slnum>"))
  2258. exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
  2259. else
  2260. " write (selected portion of) file to temporary
  2261. " call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
  2262. exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
  2263. endif
  2264. if curbufname == ""
  2265. " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
  2266. " on the temporary file's name. Deletion of the temporary file during
  2267. " cleanup then causes an error message.
  2268. 0file!
  2269. endif
  2270. " NetWrite: while choice loop: {{{3
  2271. while ichoice <= a:0
  2272. " Process arguments: {{{4
  2273. " attempt to repeat with previous host-file-etc
  2274. if exists("b:netrw_lastfile") && a:0 == 0
  2275. " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
  2276. let choice = b:netrw_lastfile
  2277. let ichoice= ichoice + 1
  2278. else
  2279. exe "let choice= a:" . ichoice
  2280. " Reconstruct Choice when choice starts with '"'
  2281. if match(choice,"?") == 0
  2282. echomsg 'NetWrite Usage:"'
  2283. echomsg ':Nwrite machine:path uses rcp'
  2284. echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
  2285. echomsg ':Nwrite "machine id password path" uses ftp'
  2286. echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
  2287. echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
  2288. echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
  2289. echomsg ':Nwrite rcp://machine/path uses rcp'
  2290. echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
  2291. echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
  2292. echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
  2293. sleep 4
  2294. break
  2295. elseif match(choice,"^\"") != -1
  2296. if match(choice,"\"$") != -1
  2297. " case "..."
  2298. let choice=strpart(choice,1,strlen(choice)-2)
  2299. else
  2300. " case "... ... ..."
  2301. let choice = strpart(choice,1,strlen(choice)-1)
  2302. let wholechoice = ""
  2303. while match(choice,"\"$") == -1
  2304. let wholechoice= wholechoice . " " . choice
  2305. let ichoice = ichoice + 1
  2306. if choice > a:0
  2307. if !exists("g:netrw_quiet")
  2308. call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
  2309. endif
  2310. " call Dret("netrw#NetWrite")
  2311. return
  2312. endif
  2313. let choice= a:{ichoice}
  2314. endwhile
  2315. let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
  2316. endif
  2317. endif
  2318. endif
  2319. let ichoice= ichoice + 1
  2320. " call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
  2321. " Determine method of write (ftp, rcp, etc) {{{4
  2322. NetrwKeepj call s:NetrwMethod(choice)
  2323. if !exists("b:netrw_method") || b:netrw_method < 0
  2324. " call Dfunc("netrw#NetWrite : unsupported method")
  2325. return
  2326. endif
  2327. " =============
  2328. " NetWrite: Perform Protocol-Based Write {{{3
  2329. " ============================
  2330. if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
  2331. echo "(netrw) Processing your write request..."
  2332. " call Decho("Processing your write request...",'~'.expand("<slnum>"))
  2333. endif
  2334. ".........................................
  2335. " NetWrite: (rcp) NetWrite Method #1 {{{3
  2336. if b:netrw_method == 1
  2337. " call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
  2338. if s:netrw_has_nt_rcp == 1
  2339. if exists("g:netrw_uid") && ( g:netrw_uid != "" )
  2340. let uid_machine = g:netrw_machine .'.'. g:netrw_uid
  2341. else
  2342. let uid_machine = g:netrw_machine .'.'. $USERNAME
  2343. endif
  2344. else
  2345. if exists("g:netrw_uid") && ( g:netrw_uid != "" )
  2346. let uid_machine = g:netrw_uid .'@'. g:netrw_machine
  2347. else
  2348. let uid_machine = g:netrw_machine
  2349. endif
  2350. endif
  2351. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1))
  2352. let b:netrw_lastfile = choice
  2353. ".........................................
  2354. " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
  2355. elseif b:netrw_method == 2
  2356. " call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
  2357. let netrw_fname = b:netrw_fname
  2358. " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
  2359. let bhkeep = &l:bh
  2360. let curbuf = bufnr("%")
  2361. setl bh=hide
  2362. keepj keepalt enew
  2363. " call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
  2364. setl ff=unix
  2365. NetrwKeepj put =g:netrw_ftpmode
  2366. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  2367. if exists("g:netrw_ftpextracmd")
  2368. NetrwKeepj put =g:netrw_ftpextracmd
  2369. " call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
  2370. endif
  2371. NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
  2372. " call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
  2373. if exists("g:netrw_port") && g:netrw_port != ""
  2374. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
  2375. else
  2376. " call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
  2377. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
  2378. endif
  2379. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  2380. if getline(1) !~ "^$"
  2381. if !exists("g:netrw_quiet")
  2382. NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
  2383. endif
  2384. let mod=1
  2385. endif
  2386. " remove enew buffer (quietly)
  2387. let filtbuf= bufnr("%")
  2388. exe curbuf."b!"
  2389. let &l:bh = bhkeep
  2390. exe filtbuf."bw!"
  2391. let b:netrw_lastfile = choice
  2392. ".........................................
  2393. " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
  2394. elseif b:netrw_method == 3
  2395. " Construct execution string (three or more lines) which will be passed through filter
  2396. " call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
  2397. let netrw_fname = b:netrw_fname
  2398. let bhkeep = &l:bh
  2399. " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
  2400. let curbuf = bufnr("%")
  2401. setl bh=hide
  2402. keepj keepalt enew
  2403. setl ff=unix
  2404. if exists("g:netrw_port") && g:netrw_port != ""
  2405. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  2406. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2407. else
  2408. NetrwKeepj put ='open '.g:netrw_machine
  2409. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2410. endif
  2411. if exists("g:netrw_uid") && g:netrw_uid != ""
  2412. if exists("g:netrw_ftp") && g:netrw_ftp == 1
  2413. NetrwKeepj put =g:netrw_uid
  2414. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2415. if exists("s:netrw_passwd") && s:netrw_passwd != ""
  2416. NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
  2417. endif
  2418. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2419. elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
  2420. NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
  2421. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2422. endif
  2423. endif
  2424. NetrwKeepj put =g:netrw_ftpmode
  2425. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  2426. if exists("g:netrw_ftpextracmd")
  2427. NetrwKeepj put =g:netrw_ftpextracmd
  2428. " call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
  2429. endif
  2430. NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
  2431. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2432. " save choice/id/password for future use
  2433. let b:netrw_lastfile = choice
  2434. " perform ftp:
  2435. " -i : turns off interactive prompting from ftp
  2436. " -n unix : DON'T use <.netrc>, even though it exists
  2437. " -n win32: quit being obnoxious about password
  2438. NetrwKeepj norm! 1G"_dd
  2439. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
  2440. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  2441. if getline(1) !~ "^$"
  2442. if !exists("g:netrw_quiet")
  2443. call netrw#ErrorMsg(s:ERROR,getline(1),15)
  2444. endif
  2445. let mod=1
  2446. endif
  2447. " remove enew buffer (quietly)
  2448. let filtbuf= bufnr("%")
  2449. exe curbuf."b!"
  2450. let &l:bh= bhkeep
  2451. exe filtbuf."bw!"
  2452. ".........................................
  2453. " NetWrite: (scp) NetWrite Method #4 {{{3
  2454. elseif b:netrw_method == 4
  2455. " call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
  2456. if exists("g:netrw_port") && g:netrw_port != ""
  2457. let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
  2458. else
  2459. let useport= ""
  2460. endif
  2461. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
  2462. let b:netrw_lastfile = choice
  2463. ".........................................
  2464. " NetWrite: (http) NetWrite Method #5 {{{3
  2465. elseif b:netrw_method == 5
  2466. " call Decho("write via http (method #5)",'~'.expand("<slnum>"))
  2467. let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
  2468. if executable(curl)
  2469. let url= g:netrw_choice
  2470. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(url,1) )
  2471. elseif !exists("g:netrw_quiet")
  2472. call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
  2473. endif
  2474. ".........................................
  2475. " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
  2476. elseif b:netrw_method == 6
  2477. " call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
  2478. " Construct execution string (four lines) which will be passed through filter
  2479. let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
  2480. let bhkeep = &l:bh
  2481. " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
  2482. let curbuf = bufnr("%")
  2483. setl bh=hide
  2484. keepj keepalt enew
  2485. setl ff=unix
  2486. if exists("g:netrw_port") && g:netrw_port != ""
  2487. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  2488. else
  2489. NetrwKeepj put ='open '.g:netrw_machine
  2490. endif
  2491. if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
  2492. NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
  2493. endif
  2494. NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
  2495. " perform cadaver operation:
  2496. NetrwKeepj norm! 1G"_dd
  2497. call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
  2498. " remove enew buffer (quietly)
  2499. let filtbuf= bufnr("%")
  2500. exe curbuf."b!"
  2501. let &l:bh = bhkeep
  2502. exe filtbuf."bw!"
  2503. let b:netrw_lastfile = choice
  2504. ".........................................
  2505. " NetWrite: (rsync) NetWrite Method #7 {{{3
  2506. elseif b:netrw_method == 7
  2507. " call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
  2508. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1))
  2509. let b:netrw_lastfile = choice
  2510. ".........................................
  2511. " NetWrite: (sftp) NetWrite Method #9 {{{3
  2512. elseif b:netrw_method == 9
  2513. " call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
  2514. let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
  2515. if exists("g:netrw_uid") && ( g:netrw_uid != "" )
  2516. let uid_machine = g:netrw_uid .'@'. g:netrw_machine
  2517. else
  2518. let uid_machine = g:netrw_machine
  2519. endif
  2520. " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
  2521. let bhkeep = &l:bh
  2522. let curbuf = bufnr("%")
  2523. setl bh=hide
  2524. keepj keepalt enew
  2525. setl ff=unix
  2526. call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
  2527. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  2528. let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
  2529. call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
  2530. let filtbuf= bufnr("%")
  2531. exe curbuf."b!"
  2532. let &l:bh = bhkeep
  2533. exe filtbuf."bw!"
  2534. let b:netrw_lastfile = choice
  2535. ".........................................
  2536. " NetWrite: Complain {{{3
  2537. else
  2538. call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
  2539. let leavemod= 1
  2540. endif
  2541. endwhile
  2542. " NetWrite: Cleanup: {{{3
  2543. " call Decho("cleanup",'~'.expand("<slnum>"))
  2544. if s:FileReadable(tmpfile)
  2545. " call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
  2546. call s:NetrwDelete(tmpfile)
  2547. endif
  2548. call s:NetrwOptionsRestore("w:")
  2549. if a:firstline == 1 && a:lastline == line("$")
  2550. " restore modifiability; usually equivalent to set nomod
  2551. let &mod= mod
  2552. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  2553. elseif !exists("leavemod")
  2554. " indicate that the buffer has not been modified since last written
  2555. " call Decho("set nomod",'~'.expand("<slnum>"))
  2556. setl nomod
  2557. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  2558. endif
  2559. " call Dret("netrw#NetWrite")
  2560. endfun
  2561. " ---------------------------------------------------------------------
  2562. " netrw#NetSource: source a remotely hosted vim script {{{2
  2563. " uses NetRead to get a copy of the file into a temporarily file,
  2564. " then sources that file,
  2565. " then removes that file.
  2566. fun! netrw#NetSource(...)
  2567. " call Dfunc("netrw#NetSource() a:0=".a:0)
  2568. if a:0 > 0 && a:1 == '?'
  2569. " give help
  2570. echomsg 'NetSource Usage:'
  2571. echomsg ':Nsource dav://machine[:port]/path uses cadaver'
  2572. echomsg ':Nsource fetch://machine/path uses fetch'
  2573. echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
  2574. echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
  2575. echomsg ':Nsource rcp://[user@]machine/path uses rcp'
  2576. echomsg ':Nsource rsync://machine[:port]/path uses rsync'
  2577. echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
  2578. echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
  2579. sleep 4
  2580. else
  2581. let i= 1
  2582. while i <= a:0
  2583. call netrw#NetRead(3,a:{i})
  2584. " call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
  2585. if s:FileReadable(s:netrw_tmpfile)
  2586. " call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
  2587. exe "so ".fnameescape(s:netrw_tmpfile)
  2588. " call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
  2589. if delete(s:netrw_tmpfile)
  2590. call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
  2591. endif
  2592. unlet s:netrw_tmpfile
  2593. else
  2594. call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
  2595. endif
  2596. let i= i + 1
  2597. endwhile
  2598. endif
  2599. " call Dret("netrw#NetSource")
  2600. endfun
  2601. " ---------------------------------------------------------------------
  2602. " netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
  2603. " (implements the :Ntree command)
  2604. fun! netrw#SetTreetop(iscmd,...)
  2605. " call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
  2606. " call Decho("w:netrw_treetop<".w:netrw_treetop.">")
  2607. " iscmd==0: netrw#SetTreetop called using gn mapping
  2608. " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
  2609. " call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
  2610. " clear out the current tree
  2611. if exists("w:netrw_treetop")
  2612. " call Decho("clearing out current tree",'~'.expand("<slnum>"))
  2613. let inittreetop= w:netrw_treetop
  2614. unlet w:netrw_treetop
  2615. endif
  2616. if exists("w:netrw_treedict")
  2617. " call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
  2618. unlet w:netrw_treedict
  2619. endif
  2620. " call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
  2621. if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
  2622. let treedir = s:NetrwTreePath(inittreetop)
  2623. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  2624. else
  2625. if isdirectory(s:NetrwFile(a:1))
  2626. " call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
  2627. let treedir = a:1
  2628. let s:netrw_treetop = treedir
  2629. elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
  2630. let treedir = b:netrw_curdir."/".a:1
  2631. let s:netrw_treetop = treedir
  2632. " call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
  2633. else
  2634. " normally the cursor is left in the message window.
  2635. " However, here this results in the directory being listed in the message window, which is not wanted.
  2636. let netrwbuf= bufnr("%")
  2637. call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
  2638. exe bufwinnr(netrwbuf)."wincmd w"
  2639. let treedir = "."
  2640. let s:netrw_treetop = getcwd()
  2641. endif
  2642. endif
  2643. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  2644. " determine if treedir is remote or local
  2645. let islocal= expand("%") !~ '^\a\{3,}://'
  2646. " call Decho("islocal=".islocal,'~'.expand("<slnum>"))
  2647. " browse the resulting directory
  2648. if islocal
  2649. call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
  2650. else
  2651. call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
  2652. endif
  2653. " call Dret("netrw#SetTreetop")
  2654. endfun
  2655. " ===========================================
  2656. " s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
  2657. " readcmd == %r : replace buffer with newly read file
  2658. " == 0r : read file at top of buffer
  2659. " == r : read file after current line
  2660. " == t : leave file in temporary form (ie. don't read into buffer)
  2661. fun! s:NetrwGetFile(readcmd, tfile, method)
  2662. " call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
  2663. " readcmd=='t': simply do nothing
  2664. if a:readcmd == 't'
  2665. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  2666. " call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
  2667. return
  2668. endif
  2669. " get name of remote filename (ie. url and all)
  2670. let rfile= bufname("%")
  2671. " call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
  2672. if exists("*NetReadFixup")
  2673. " for the use of NetReadFixup (not otherwise used internally)
  2674. let line2= line("$")
  2675. endif
  2676. if a:readcmd[0] == '%'
  2677. " get file into buffer
  2678. " call Decho("get file into buffer",'~'.expand("<slnum>"))
  2679. " rename the current buffer to the temp file (ie. tfile)
  2680. if g:netrw_cygwin
  2681. let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
  2682. else
  2683. let tfile= a:tfile
  2684. endif
  2685. call s:NetrwBufRename(tfile)
  2686. " edit temporary file (ie. read the temporary file in)
  2687. if rfile =~ '\.zip$'
  2688. " call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
  2689. call zip#Browse(tfile)
  2690. elseif rfile =~ '\.tar$'
  2691. " call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
  2692. call tar#Browse(tfile)
  2693. elseif rfile =~ '\.tar\.gz$'
  2694. " call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
  2695. call tar#Browse(tfile)
  2696. elseif rfile =~ '\.tar\.bz2$'
  2697. " call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
  2698. call tar#Browse(tfile)
  2699. elseif rfile =~ '\.tar\.xz$'
  2700. " call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
  2701. call tar#Browse(tfile)
  2702. elseif rfile =~ '\.txz$'
  2703. " call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
  2704. call tar#Browse(tfile)
  2705. else
  2706. " call Decho("edit temporary file",'~'.expand("<slnum>"))
  2707. NetrwKeepj e!
  2708. endif
  2709. " rename buffer back to remote filename
  2710. call s:NetrwBufRename(rfile)
  2711. " Detect filetype of local version of remote file.
  2712. " Note that isk must not include a "/" for scripts.vim
  2713. " to process this detection correctly.
  2714. " call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
  2715. let iskkeep= &l:isk
  2716. setl isk-=/
  2717. let &l:isk= iskkeep
  2718. " call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
  2719. let line1 = 1
  2720. let line2 = line("$")
  2721. elseif !&ma
  2722. " attempting to read a file after the current line in the file, but the buffer is not modifiable
  2723. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
  2724. " call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
  2725. return
  2726. elseif s:FileReadable(a:tfile)
  2727. " read file after current line
  2728. " call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
  2729. let curline = line(".")
  2730. let lastline= line("$")
  2731. " call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
  2732. exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
  2733. let line1= curline + 1
  2734. let line2= line("$") - lastline + 1
  2735. else
  2736. " not readable
  2737. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  2738. " call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
  2739. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
  2740. " call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
  2741. return
  2742. endif
  2743. " User-provided (ie. optional) fix-it-up command
  2744. if exists("*NetReadFixup")
  2745. " call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
  2746. NetrwKeepj call NetReadFixup(a:method, line1, line2)
  2747. " else " Decho
  2748. " call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
  2749. endif
  2750. if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
  2751. " update the Buffers menu
  2752. NetrwKeepj call s:UpdateBuffersMenu()
  2753. endif
  2754. " call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
  2755. " make sure file is being displayed
  2756. " redraw!
  2757. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  2758. " call Dret("NetrwGetFile")
  2759. endfun
  2760. " ------------------------------------------------------------------------
  2761. " s:NetrwMethod: determine method of transfer {{{2
  2762. " Input:
  2763. " choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
  2764. " Output:
  2765. " b:netrw_method= 1: rcp
  2766. " 2: ftp + <.netrc>
  2767. " 3: ftp + machine, id, password, and [path]filename
  2768. " 4: scp
  2769. " 5: http[s] (wget)
  2770. " 6: dav
  2771. " 7: rsync
  2772. " 8: fetch
  2773. " 9: sftp
  2774. " 10: file
  2775. " g:netrw_machine= hostname
  2776. " b:netrw_fname = filename
  2777. " g:netrw_port = optional port number (for ftp)
  2778. " g:netrw_choice = copy of input url (choice)
  2779. fun! s:NetrwMethod(choice)
  2780. " call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
  2781. " sanity check: choice should have at least three slashes in it
  2782. if strlen(substitute(a:choice,'[^/]','','g')) < 3
  2783. call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
  2784. let b:netrw_method = -1
  2785. " call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
  2786. return
  2787. endif
  2788. " record current g:netrw_machine, if any
  2789. " curmachine used if protocol == ftp and no .netrc
  2790. if exists("g:netrw_machine")
  2791. let curmachine= g:netrw_machine
  2792. " call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
  2793. else
  2794. let curmachine= "N O T A HOST"
  2795. endif
  2796. if exists("g:netrw_port")
  2797. let netrw_port= g:netrw_port
  2798. endif
  2799. " insure that netrw_ftp_cmd starts off every method determination
  2800. " with the current g:netrw_ftp_cmd
  2801. let s:netrw_ftp_cmd= g:netrw_ftp_cmd
  2802. " initialization
  2803. let b:netrw_method = 0
  2804. let g:netrw_machine = ""
  2805. let b:netrw_fname = ""
  2806. let g:netrw_port = ""
  2807. let g:netrw_choice = a:choice
  2808. " Patterns:
  2809. " mipf : a:machine a:id password filename Use ftp
  2810. " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
  2811. " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
  2812. " rcpurm : rcp://[user@]host/filename Use rcp
  2813. " rcphf : [user@]host:filename Use rcp
  2814. " scpurm : scp://[user@]host[[#:]port]/filename Use scp
  2815. " httpurm : http[s]://[user@]host/filename Use wget
  2816. " davurm : dav[s]://host[:port]/path Use cadaver/curl
  2817. " rsyncurm : rsync://host[:port]/path Use rsync
  2818. " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
  2819. " sftpurm : sftp://[user@]host/filename Use scp
  2820. " fileurm : file://[user@]host/filename Use elinks or links
  2821. let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
  2822. let mf = '^\(\S\+\)\s\+\(\S\+\)$'
  2823. let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
  2824. let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
  2825. let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
  2826. let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
  2827. let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
  2828. let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
  2829. let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
  2830. let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
  2831. let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
  2832. let fileurm = '^file\=://\(.*\)$'
  2833. " call Decho("determine method:",'~'.expand("<slnum>"))
  2834. " Determine Method
  2835. " Method#1: rcp://user@hostname/...path-to-file {{{3
  2836. if match(a:choice,rcpurm) == 0
  2837. " call Decho("rcp://...",'~'.expand("<slnum>"))
  2838. let b:netrw_method = 1
  2839. let userid = substitute(a:choice,rcpurm,'\1',"")
  2840. let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
  2841. let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
  2842. if userid != ""
  2843. let g:netrw_uid= userid
  2844. endif
  2845. " Method#4: scp://user@hostname/...path-to-file {{{3
  2846. elseif match(a:choice,scpurm) == 0
  2847. " call Decho("scp://...",'~'.expand("<slnum>"))
  2848. let b:netrw_method = 4
  2849. let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
  2850. let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
  2851. let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
  2852. " Method#5: http[s]://user@hostname/...path-to-file {{{3
  2853. elseif match(a:choice,httpurm) == 0
  2854. " call Decho("http[s]://...",'~'.expand("<slnum>"))
  2855. let b:netrw_method = 5
  2856. let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
  2857. let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
  2858. let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
  2859. " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
  2860. elseif match(a:choice,davurm) == 0
  2861. " call Decho("dav://...",'~'.expand("<slnum>"))
  2862. let b:netrw_method= 6
  2863. if a:choice =~ 'davs:'
  2864. let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
  2865. else
  2866. let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
  2867. endif
  2868. let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
  2869. " Method#7: rsync://user@hostname/...path-to-file {{{3
  2870. elseif match(a:choice,rsyncurm) == 0
  2871. " call Decho("rsync://...",'~'.expand("<slnum>"))
  2872. let b:netrw_method = 7
  2873. let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
  2874. let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
  2875. " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
  2876. elseif match(a:choice,ftpurm) == 0
  2877. " call Decho("ftp://...",'~'.expand("<slnum>"))
  2878. let userid = substitute(a:choice,ftpurm,'\2',"")
  2879. let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
  2880. let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
  2881. let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
  2882. " call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
  2883. if userid != ""
  2884. let g:netrw_uid= userid
  2885. endif
  2886. if curmachine != g:netrw_machine
  2887. if exists("s:netrw_hup[".g:netrw_machine."]")
  2888. call NetUserPass("ftp:".g:netrw_machine)
  2889. elseif exists("s:netrw_passwd")
  2890. " if there's a change in hostname, require password re-entry
  2891. unlet s:netrw_passwd
  2892. endif
  2893. if exists("netrw_port")
  2894. unlet netrw_port
  2895. endif
  2896. endif
  2897. if exists("g:netrw_uid") && exists("s:netrw_passwd")
  2898. let b:netrw_method = 3
  2899. else
  2900. let host= substitute(g:netrw_machine,'\..*$','','')
  2901. if exists("s:netrw_hup[host]")
  2902. call NetUserPass("ftp:".host)
  2903. elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
  2904. " call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
  2905. " call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
  2906. if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
  2907. let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
  2908. " call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
  2909. endif
  2910. let b:netrw_method= 2
  2911. elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
  2912. " call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
  2913. let b:netrw_method= 2
  2914. else
  2915. if !exists("g:netrw_uid") || g:netrw_uid == ""
  2916. call NetUserPass()
  2917. elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
  2918. call NetUserPass(g:netrw_uid)
  2919. " else just use current g:netrw_uid and s:netrw_passwd
  2920. endif
  2921. let b:netrw_method= 3
  2922. endif
  2923. endif
  2924. " Method#8: fetch {{{3
  2925. elseif match(a:choice,fetchurm) == 0
  2926. " call Decho("fetch://...",'~'.expand("<slnum>"))
  2927. let b:netrw_method = 8
  2928. let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
  2929. let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
  2930. let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
  2931. let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
  2932. " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
  2933. elseif match(a:choice,mipf) == 0
  2934. " call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
  2935. let b:netrw_method = 3
  2936. let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
  2937. let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
  2938. let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
  2939. let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
  2940. call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
  2941. " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
  2942. elseif match(a:choice,mf) == 0
  2943. " call Decho("(ftp) host file",'~'.expand("<slnum>"))
  2944. if exists("g:netrw_uid") && exists("s:netrw_passwd")
  2945. let b:netrw_method = 3
  2946. let g:netrw_machine = substitute(a:choice,mf,'\1',"")
  2947. let b:netrw_fname = substitute(a:choice,mf,'\2',"")
  2948. elseif s:FileReadable(expand("$HOME/.netrc"))
  2949. let b:netrw_method = 2
  2950. let g:netrw_machine = substitute(a:choice,mf,'\1',"")
  2951. let b:netrw_fname = substitute(a:choice,mf,'\2',"")
  2952. endif
  2953. " Method#9: sftp://user@hostname/...path-to-file {{{3
  2954. elseif match(a:choice,sftpurm) == 0
  2955. " call Decho("sftp://...",'~'.expand("<slnum>"))
  2956. let b:netrw_method = 9
  2957. let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
  2958. let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
  2959. " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
  2960. elseif match(a:choice,rcphf) == 0
  2961. " call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
  2962. let b:netrw_method = 1
  2963. let userid = substitute(a:choice,rcphf,'\2',"")
  2964. let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
  2965. let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
  2966. " call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
  2967. " call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
  2968. " call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
  2969. " call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
  2970. if userid != ""
  2971. let g:netrw_uid= userid
  2972. endif
  2973. " Method#10: file://user@hostname/...path-to-file {{{3
  2974. elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
  2975. " call Decho("http[s]://...",'~'.expand("<slnum>"))
  2976. let b:netrw_method = 10
  2977. let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
  2978. " call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
  2979. " Cannot Determine Method {{{3
  2980. else
  2981. if !exists("g:netrw_quiet")
  2982. call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
  2983. endif
  2984. let b:netrw_method = -1
  2985. endif
  2986. "}}}3
  2987. if g:netrw_port != ""
  2988. " remove any leading [:#] from port number
  2989. let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
  2990. elseif exists("netrw_port")
  2991. " retain port number as implicit for subsequent ftp operations
  2992. let g:netrw_port= netrw_port
  2993. endif
  2994. " call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
  2995. " call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
  2996. " call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
  2997. " call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
  2998. " if exists("g:netrw_uid") "Decho
  2999. " call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
  3000. " endif "Decho
  3001. " if exists("s:netrw_passwd") "Decho
  3002. " call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
  3003. " endif "Decho
  3004. " call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
  3005. " call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
  3006. endfun
  3007. " ------------------------------------------------------------------------
  3008. " NetReadFixup: this sort of function is typically written by the user {{{2
  3009. " to handle extra junk that their system's ftp dumps
  3010. " into the transfer. This function is provided as an
  3011. " example and as a fix for a Windows 95 problem: in my
  3012. " experience, win95's ftp always dumped four blank lines
  3013. " at the end of the transfer.
  3014. if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
  3015. fun! NetReadFixup(method, line1, line2)
  3016. " call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
  3017. " sanity checks -- attempt to convert inputs to integers
  3018. let method = a:method + 0
  3019. let line1 = a:line1 + 0
  3020. let line2 = a:line2 + 0
  3021. if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
  3022. " call Dret("NetReadFixup")
  3023. return
  3024. endif
  3025. if method == 3 " ftp (no <.netrc>)
  3026. let fourblanklines= line2 - 3
  3027. if fourblanklines >= line1
  3028. exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
  3029. call histdel("/",-1)
  3030. endif
  3031. endif
  3032. " call Dret("NetReadFixup")
  3033. endfun
  3034. endif
  3035. " ---------------------------------------------------------------------
  3036. " NetUserPass: set username and password for subsequent ftp transfer {{{2
  3037. " Usage: :call NetUserPass() -- will prompt for userid and password
  3038. " :call NetUserPass("uid") -- will prompt for password
  3039. " :call NetUserPass("uid","password") -- sets global userid and password
  3040. " :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
  3041. " :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
  3042. fun! NetUserPass(...)
  3043. " call Dfunc("NetUserPass() a:0=".a:0)
  3044. if !exists('s:netrw_hup')
  3045. let s:netrw_hup= {}
  3046. endif
  3047. if a:0 == 0
  3048. " case: no input arguments
  3049. " change host and username if not previously entered; get new password
  3050. if !exists("g:netrw_machine")
  3051. let g:netrw_machine= input('Enter hostname: ')
  3052. endif
  3053. if !exists("g:netrw_uid") || g:netrw_uid == ""
  3054. " get username (user-id) via prompt
  3055. let g:netrw_uid= input('Enter username: ')
  3056. endif
  3057. " get password via prompting
  3058. let s:netrw_passwd= inputsecret("Enter Password: ")
  3059. " set up hup database
  3060. let host = substitute(g:netrw_machine,'\..*$','','')
  3061. if !exists('s:netrw_hup[host]')
  3062. let s:netrw_hup[host]= {}
  3063. endif
  3064. let s:netrw_hup[host].uid = g:netrw_uid
  3065. let s:netrw_hup[host].passwd = s:netrw_passwd
  3066. elseif a:0 == 1
  3067. " case: one input argument
  3068. if a:1 =~ '^ftp:'
  3069. " get host from ftp:... url
  3070. " access userid and password from hup (host-user-passwd) dictionary
  3071. " call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
  3072. let host = substitute(a:1,'^ftp:','','')
  3073. let host = substitute(host,'\..*','','')
  3074. if exists("s:netrw_hup[host]")
  3075. let g:netrw_uid = s:netrw_hup[host].uid
  3076. let s:netrw_passwd = s:netrw_hup[host].passwd
  3077. " call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
  3078. " call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
  3079. else
  3080. let g:netrw_uid = input("Enter UserId: ")
  3081. let s:netrw_passwd = inputsecret("Enter Password: ")
  3082. endif
  3083. else
  3084. " case: one input argument, not an url. Using it as a new user-id.
  3085. " call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)",'~'.expand("<slnum>"))
  3086. if exists("g:netrw_machine")
  3087. if g:netrw_machine =~ '[0-9.]\+'
  3088. let host= g:netrw_machine
  3089. else
  3090. let host= substitute(g:netrw_machine,'\..*$','','')
  3091. endif
  3092. else
  3093. let g:netrw_machine= input('Enter hostname: ')
  3094. endif
  3095. let g:netrw_uid = a:1
  3096. " call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
  3097. if exists("g:netrw_passwd")
  3098. " ask for password if one not previously entered
  3099. let s:netrw_passwd= g:netrw_passwd
  3100. else
  3101. let s:netrw_passwd = inputsecret("Enter Password: ")
  3102. endif
  3103. endif
  3104. " call Decho("host<".host.">",'~'.expand("<slnum>"))
  3105. if exists("host")
  3106. if !exists('s:netrw_hup[host]')
  3107. let s:netrw_hup[host]= {}
  3108. endif
  3109. let s:netrw_hup[host].uid = g:netrw_uid
  3110. let s:netrw_hup[host].passwd = s:netrw_passwd
  3111. endif
  3112. elseif a:0 == 2
  3113. let g:netrw_uid = a:1
  3114. let s:netrw_passwd = a:2
  3115. elseif a:0 == 3
  3116. " enter hostname, user-id, and password into the hup dictionary
  3117. let host = substitute(a:1,'^\a\+:','','')
  3118. let host = substitute(host,'\..*$','','')
  3119. if !exists('s:netrw_hup[host]')
  3120. let s:netrw_hup[host]= {}
  3121. endif
  3122. let s:netrw_hup[host].uid = a:2
  3123. let s:netrw_hup[host].passwd = a:3
  3124. let g:netrw_uid = s:netrw_hup[host].uid
  3125. let s:netrw_passwd = s:netrw_hup[host].passwd
  3126. " call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
  3127. " call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
  3128. endif
  3129. " call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
  3130. endfun
  3131. " =================================
  3132. " Shared Browsing Support: {{{1
  3133. " =================================
  3134. " ---------------------------------------------------------------------
  3135. " s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
  3136. fun! s:ExplorePatHls(pattern)
  3137. " call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
  3138. let repat= substitute(a:pattern,'^**/\{1,2}','','')
  3139. " call Decho("repat<".repat.">",'~'.expand("<slnum>"))
  3140. let repat= escape(repat,'][.\')
  3141. " call Decho("repat<".repat.">",'~'.expand("<slnum>"))
  3142. let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
  3143. " call Dret("s:ExplorePatHls repat<".repat.">")
  3144. return repat
  3145. endfun
  3146. " ---------------------------------------------------------------------
  3147. " s:NetrwBookHistHandler: {{{2
  3148. " 0: (user: <mb>) bookmark current directory
  3149. " 1: (user: <gb>) change to the bookmarked directory
  3150. " 2: (user: <qb>) list bookmarks
  3151. " 3: (browsing) records current directory history
  3152. " 4: (user: <u>) go up (previous) directory, using history
  3153. " 5: (user: <U>) go down (next) directory, using history
  3154. " 6: (user: <mB>) delete bookmark
  3155. fun! s:NetrwBookHistHandler(chg,curdir)
  3156. " call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhistcnt." histmax=".g:netrw_dirhistmax)
  3157. if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
  3158. " " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
  3159. return
  3160. endif
  3161. let ykeep = @@
  3162. let curbufnr = bufnr("%")
  3163. if a:chg == 0
  3164. " bookmark the current directory
  3165. " call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
  3166. if exists("s:netrwmarkfilelist_{curbufnr}")
  3167. call s:NetrwBookmark(0)
  3168. echo "bookmarked marked files"
  3169. else
  3170. call s:MakeBookmark(a:curdir)
  3171. echo "bookmarked the current directory"
  3172. endif
  3173. elseif a:chg == 1
  3174. " change to the bookmarked directory
  3175. " call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
  3176. if exists("g:netrw_bookmarklist[v:count-1]")
  3177. " call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
  3178. exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
  3179. else
  3180. echomsg "Sorry, bookmark#".v:count." doesn't exist!"
  3181. endif
  3182. elseif a:chg == 2
  3183. " redraw!
  3184. let didwork= 0
  3185. " list user's bookmarks
  3186. " call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
  3187. if exists("g:netrw_bookmarklist")
  3188. " call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
  3189. let cnt= 1
  3190. for bmd in g:netrw_bookmarklist
  3191. " call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
  3192. echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
  3193. let didwork = 1
  3194. let cnt = cnt + 1
  3195. endfor
  3196. endif
  3197. " list directory history
  3198. " Note: history is saved only when PerformListing is done;
  3199. " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
  3200. let cnt = g:netrw_dirhistcnt
  3201. let first = 1
  3202. let histcnt = 0
  3203. if g:netrw_dirhistmax > 0
  3204. while ( first || cnt != g:netrw_dirhistcnt )
  3205. " call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
  3206. if exists("g:netrw_dirhist_{cnt}")
  3207. " call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
  3208. echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
  3209. let didwork= 1
  3210. endif
  3211. let histcnt = histcnt + 1
  3212. let first = 0
  3213. let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
  3214. if cnt < 0
  3215. let cnt= cnt + g:netrw_dirhistmax
  3216. endif
  3217. endwhile
  3218. else
  3219. let g:netrw_dirhistcnt= 0
  3220. endif
  3221. if didwork
  3222. call inputsave()|call input("Press <cr> to continue")|call inputrestore()
  3223. endif
  3224. elseif a:chg == 3
  3225. " saves most recently visited directories (when they differ)
  3226. " call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
  3227. if !exists("g:netrw_dirhistcnt") || !exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") || g:netrw_dirhist_{g:netrw_dirhistcnt} != a:curdir
  3228. if g:netrw_dirhistmax > 0
  3229. let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
  3230. let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
  3231. endif
  3232. " call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
  3233. endif
  3234. elseif a:chg == 4
  3235. " u: change to the previous directory stored on the history list
  3236. " call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
  3237. if g:netrw_dirhistmax > 0
  3238. let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
  3239. if g:netrw_dirhistcnt < 0
  3240. let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
  3241. endif
  3242. else
  3243. let g:netrw_dirhistcnt= 0
  3244. endif
  3245. if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
  3246. " call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
  3247. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
  3248. setl ma noro
  3249. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  3250. sil! NetrwKeepj %d _
  3251. setl nomod
  3252. " call Decho("setl nomod",'~'.expand("<slnum>"))
  3253. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  3254. endif
  3255. " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
  3256. exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
  3257. else
  3258. if g:netrw_dirhistmax > 0
  3259. let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
  3260. else
  3261. let g:netrw_dirhistcnt= 0
  3262. endif
  3263. echo "Sorry, no predecessor directory exists yet"
  3264. endif
  3265. elseif a:chg == 5
  3266. " U: change to the subsequent directory stored on the history list
  3267. " call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
  3268. if g:netrw_dirhistmax > 0
  3269. let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
  3270. if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
  3271. " call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
  3272. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
  3273. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  3274. setl ma noro
  3275. sil! NetrwKeepj %d _
  3276. " call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
  3277. " call Decho("setl nomod",'~'.expand("<slnum>"))
  3278. setl nomod
  3279. " call Decho("(set nomod) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  3280. endif
  3281. " call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
  3282. exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
  3283. else
  3284. let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
  3285. if g:netrw_dirhistcnt < 0
  3286. let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
  3287. endif
  3288. echo "Sorry, no successor directory exists yet"
  3289. endif
  3290. else
  3291. let g:netrw_dirhistcnt= 0
  3292. echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
  3293. endif
  3294. elseif a:chg == 6
  3295. " call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
  3296. if exists("s:netrwmarkfilelist_{curbufnr}")
  3297. call s:NetrwBookmark(1)
  3298. echo "removed marked files from bookmarks"
  3299. else
  3300. " delete the v:count'th bookmark
  3301. let iremove = v:count
  3302. let dremove = g:netrw_bookmarklist[iremove - 1]
  3303. " call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
  3304. call s:MergeBookmarks()
  3305. " call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
  3306. NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
  3307. echo "removed ".dremove." from g:netrw_bookmarklist"
  3308. " call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
  3309. endif
  3310. " call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
  3311. endif
  3312. call s:NetrwBookmarkMenu()
  3313. call s:NetrwTgtMenu()
  3314. let @@= ykeep
  3315. " call Dret("s:NetrwBookHistHandler")
  3316. endfun
  3317. " ---------------------------------------------------------------------
  3318. " s:NetrwBookHistRead: this function reads bookmarks and history {{{2
  3319. " Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
  3320. " Sister function: s:NetrwBookHistSave()
  3321. fun! s:NetrwBookHistRead()
  3322. " call Dfunc("s:NetrwBookHistRead()")
  3323. if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
  3324. " call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
  3325. return
  3326. endif
  3327. let ykeep= @@
  3328. " read bookmarks
  3329. if !exists("s:netrw_initbookhist")
  3330. let home = s:NetrwHome()
  3331. let savefile= home."/.netrwbook"
  3332. if filereadable(s:NetrwFile(savefile))
  3333. " call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
  3334. exe "keepalt NetrwKeepj so ".savefile
  3335. endif
  3336. " read history
  3337. if g:netrw_dirhistmax > 0
  3338. let savefile= home."/.netrwhist"
  3339. if filereadable(s:NetrwFile(savefile))
  3340. " call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
  3341. exe "keepalt NetrwKeepj so ".savefile
  3342. endif
  3343. let s:netrw_initbookhist= 1
  3344. au VimLeave * call s:NetrwBookHistSave()
  3345. endif
  3346. endif
  3347. let @@= ykeep
  3348. " call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
  3349. " call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
  3350. " call Dret("s:NetrwBookHistRead")
  3351. endfun
  3352. " ---------------------------------------------------------------------
  3353. " s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
  3354. " Sister function: s:NetrwBookHistRead()
  3355. " I used to do this via viminfo but that appears to
  3356. " be unreliable for long-term storage
  3357. " If g:netrw_dirhistmax is <= 0, no history or bookmarks
  3358. " will be saved.
  3359. " (s:NetrwBookHistHandler(3,...) used to record history)
  3360. fun! s:NetrwBookHistSave()
  3361. " call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
  3362. if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
  3363. " call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
  3364. return
  3365. endif
  3366. let savefile= s:NetrwHome()."/.netrwhist"
  3367. " call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
  3368. 1split
  3369. " setting up a new buffer which will become .netrwhist
  3370. call s:NetrwEnew()
  3371. " call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
  3372. if g:netrw_use_noswf
  3373. setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
  3374. else
  3375. setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
  3376. endif
  3377. setl nocin noai noci magic nospell nohid wig= noaw
  3378. setl ma noro write
  3379. if exists("+acd") | setl noacd | endif
  3380. sil! NetrwKeepj keepalt %d _
  3381. " rename enew'd file: .netrwhist -- no attempt to merge
  3382. " record dirhistmax and current dirhistcnt
  3383. " save history
  3384. " call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
  3385. sil! keepalt file .netrwhist
  3386. call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
  3387. call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
  3388. if g:netrw_dirhistmax > 0
  3389. let lastline = line("$")
  3390. let cnt = g:netrw_dirhistcnt
  3391. let first = 1
  3392. while ( first || cnt != g:netrw_dirhistcnt )
  3393. let lastline= lastline + 1
  3394. if exists("g:netrw_dirhist_{cnt}")
  3395. call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
  3396. " call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
  3397. endif
  3398. let first = 0
  3399. let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
  3400. if cnt < 0
  3401. let cnt= cnt + g:netrw_dirhistmax
  3402. endif
  3403. endwhile
  3404. exe "sil! w! ".savefile
  3405. " call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
  3406. endif
  3407. " save bookmarks
  3408. sil NetrwKeepj %d _
  3409. if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
  3410. " call Decho("saving bookmarks",'~'.expand("<slnum>"))
  3411. " merge and write .netrwbook
  3412. let savefile= s:NetrwHome()."/.netrwbook"
  3413. if filereadable(s:NetrwFile(savefile))
  3414. let booklist= deepcopy(g:netrw_bookmarklist)
  3415. exe "sil NetrwKeepj keepalt so ".savefile
  3416. for bdm in booklist
  3417. if index(g:netrw_bookmarklist,bdm) == -1
  3418. call add(g:netrw_bookmarklist,bdm)
  3419. endif
  3420. endfor
  3421. call sort(g:netrw_bookmarklist)
  3422. endif
  3423. " construct and save .netrwbook
  3424. call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
  3425. exe "sil! w! ".savefile
  3426. " call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
  3427. endif
  3428. " cleanup -- remove buffer used to construct history
  3429. let bgone= bufnr("%")
  3430. q!
  3431. exe "keepalt ".bgone."bwipe!"
  3432. " call Dret("s:NetrwBookHistSave")
  3433. endfun
  3434. " ---------------------------------------------------------------------
  3435. " s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
  3436. " list of the contents of a local or remote directory. It is assumed that the
  3437. " g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
  3438. " with the requested remote hostname first.
  3439. " Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
  3440. fun! s:NetrwBrowse(islocal,dirname)
  3441. if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
  3442. " call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
  3443. " call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
  3444. " call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3445. " call Dredir("ls!","s:NetrwBrowse")
  3446. " save alternate-file's filename if w:netrw_rexlocal doesn't exist
  3447. " This is useful when one edits a local file, then :e ., then :Rex
  3448. if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
  3449. let w:netrw_rexfile= bufname("#")
  3450. " call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
  3451. endif
  3452. " s:NetrwBrowse : initialize history {{{3
  3453. if !exists("s:netrw_initbookhist")
  3454. NetrwKeepj call s:NetrwBookHistRead()
  3455. endif
  3456. " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
  3457. if a:dirname !~ '^\a\{3,}://'
  3458. let dirname= simplify(a:dirname)
  3459. " call Decho("simplified dirname<".dirname.">")
  3460. else
  3461. let dirname= a:dirname
  3462. endif
  3463. " repoint t:netrw_lexbufnr if appropriate
  3464. if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
  3465. " call Decho("set repointlexbufnr to true!")
  3466. let repointlexbufnr= 1
  3467. endif
  3468. " s:NetrwBrowse : sanity checks: {{{3
  3469. if exists("s:netrw_skipbrowse")
  3470. unlet s:netrw_skipbrowse
  3471. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">",'~'.expand("<slnum>"))
  3472. " call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
  3473. return
  3474. endif
  3475. if !exists("*shellescape")
  3476. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
  3477. " call Dret("s:NetrwBrowse : missing shellescape()")
  3478. return
  3479. endif
  3480. if !exists("*fnameescape")
  3481. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
  3482. " call Dret("s:NetrwBrowse : missing fnameescape()")
  3483. return
  3484. endif
  3485. " s:NetrwBrowse : save options: {{{3
  3486. call s:NetrwOptionsSave("w:")
  3487. " s:NetrwBrowse : re-instate any marked files {{{3
  3488. if has("syntax") && exists("g:syntax_on") && g:syntax_on
  3489. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  3490. " call Decho("clearing marked files",'~'.expand("<slnum>"))
  3491. exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
  3492. endif
  3493. endif
  3494. if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
  3495. " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
  3496. " call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
  3497. " call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
  3498. if s:NetrwLcd(dirname)
  3499. " call Dret("s:NetrwBrowse : lcd failure")
  3500. return
  3501. endif
  3502. " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
  3503. " call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
  3504. elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
  3505. " s:NetrwBrowse : remote regular file handler {{{3
  3506. " call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
  3507. if bufname(dirname) != ""
  3508. " call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
  3509. exe "NetrwKeepj b ".bufname(dirname)
  3510. else
  3511. " attempt transfer of remote regular file
  3512. " call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
  3513. " remove any filetype indicator from end of dirname, except for the
  3514. " "this is a directory" indicator (/).
  3515. " There shouldn't be one of those here, anyway.
  3516. let path= substitute(dirname,'[*=@|]\r\=$','','e')
  3517. " call Decho("new path<".path.">",'~'.expand("<slnum>"))
  3518. call s:RemotePathAnalysis(dirname)
  3519. " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
  3520. call s:NetrwEnew(dirname)
  3521. call s:NetrwOptionsSafe(a:islocal)
  3522. setl ma noro
  3523. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  3524. let b:netrw_curdir = dirname
  3525. let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
  3526. call s:NetrwBufRename(url)
  3527. exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
  3528. sil call netrw#NetRead(2,url)
  3529. " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
  3530. " call Decho("url<".url.">",'~'.expand("<slnum>"))
  3531. " call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
  3532. " call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
  3533. if s:path =~ '.bz2'
  3534. exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
  3535. elseif s:path =~ '.gz'
  3536. exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
  3537. elseif s:path =~ '.gz'
  3538. exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
  3539. else
  3540. exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
  3541. endif
  3542. endif
  3543. " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
  3544. call s:SetBufWinVars()
  3545. call s:NetrwOptionsRestore("w:")
  3546. " call Decho("setl ma nomod",'~'.expand("<slnum>"))
  3547. setl ma nomod noro
  3548. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  3549. " call Dret("s:NetrwBrowse : file<".s:fname.">")
  3550. return
  3551. endif
  3552. " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
  3553. call s:UseBufWinVars()
  3554. " set up some variables {{{3
  3555. let b:netrw_browser_active = 1
  3556. let dirname = dirname
  3557. let s:last_sort_by = g:netrw_sort_by
  3558. " set up menu {{{3
  3559. NetrwKeepj call s:NetrwMenu(1)
  3560. " get/set-up buffer {{{3
  3561. " call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
  3562. let svpos = winsaveview()
  3563. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  3564. let reusing= s:NetrwGetBuffer(a:islocal,dirname)
  3565. " maintain markfile highlighting
  3566. if has("syntax") && exists("g:syntax_on") && g:syntax_on
  3567. if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
  3568. " " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
  3569. " " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
  3570. exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
  3571. else
  3572. " " call Decho("2match none",'~'.expand("<slnum>"))
  3573. 2match none
  3574. endif
  3575. endif
  3576. if reusing && line("$") > 1
  3577. call s:NetrwOptionsRestore("w:")
  3578. " call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
  3579. setl noma nomod nowrap
  3580. " call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  3581. " call Dret("s:NetrwBrowse : re-using not-cleared buffer")
  3582. return
  3583. endif
  3584. " set b:netrw_curdir to the new directory name {{{3
  3585. " call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
  3586. let b:netrw_curdir= dirname
  3587. if b:netrw_curdir =~ '[/\\]$'
  3588. let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
  3589. endif
  3590. if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
  3591. let b:netrw_curdir= b:netrw_curdir."/"
  3592. endif
  3593. if b:netrw_curdir == ''
  3594. if has("amiga")
  3595. " On the Amiga, the empty string connotes the current directory
  3596. let b:netrw_curdir= getcwd()
  3597. else
  3598. " under unix, when the root directory is encountered, the result
  3599. " from the preceding substitute is an empty string.
  3600. let b:netrw_curdir= '/'
  3601. endif
  3602. endif
  3603. if !a:islocal && b:netrw_curdir !~ '/$'
  3604. let b:netrw_curdir= b:netrw_curdir.'/'
  3605. endif
  3606. " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  3607. " ------------
  3608. " (local only) {{{3
  3609. " ------------
  3610. if a:islocal
  3611. " call Decho("local only:",'~'.expand("<slnum>"))
  3612. " Set up ShellCmdPost handling. Append current buffer to browselist
  3613. call s:LocalFastBrowser()
  3614. " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
  3615. if !g:netrw_keepdir
  3616. " call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
  3617. " call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
  3618. if !exists("&l:acd") || !&l:acd
  3619. if s:NetrwLcd(b:netrw_curdir)
  3620. " call Dret("s:NetrwBrowse : lcd failure")
  3621. return
  3622. endif
  3623. endif
  3624. endif
  3625. " --------------------------------
  3626. " remote handling: {{{3
  3627. " --------------------------------
  3628. else
  3629. " call Decho("remote only:",'~'.expand("<slnum>"))
  3630. " analyze dirname and g:netrw_list_cmd {{{3
  3631. " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
  3632. if dirname =~# "^NetrwTreeListing\>"
  3633. let dirname= b:netrw_curdir
  3634. " call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
  3635. elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
  3636. let dirname= substitute(b:netrw_curdir,'\\','/','g')
  3637. if dirname !~ '/$'
  3638. let dirname= dirname.'/'
  3639. endif
  3640. let b:netrw_curdir = dirname
  3641. " call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
  3642. else
  3643. let dirname = substitute(dirname,'\\','/','g')
  3644. " call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
  3645. endif
  3646. let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
  3647. if dirname !~ dirpat
  3648. if !exists("g:netrw_quiet")
  3649. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
  3650. endif
  3651. NetrwKeepj call s:NetrwOptionsRestore("w:")
  3652. " call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
  3653. setl noma nomod nowrap
  3654. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  3655. " call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
  3656. return
  3657. endif
  3658. let b:netrw_curdir= dirname
  3659. " call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
  3660. endif " (additional remote handling)
  3661. " -------------------------------
  3662. " Perform Directory Listing: {{{3
  3663. " -------------------------------
  3664. NetrwKeepj call s:NetrwMaps(a:islocal)
  3665. NetrwKeepj call s:NetrwCommands(a:islocal)
  3666. NetrwKeepj call s:PerformListing(a:islocal)
  3667. " restore option(s)
  3668. call s:NetrwOptionsRestore("w:")
  3669. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3670. " If there is a rexposn: restore position with rexposn
  3671. " Otherwise : set rexposn
  3672. if exists("s:rexposn_".bufnr("%"))
  3673. " call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
  3674. NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
  3675. if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
  3676. NetrwKeepj exe w:netrw_bannercnt
  3677. endif
  3678. else
  3679. NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
  3680. endif
  3681. if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
  3682. let &l:bexpr= "netrw#BalloonHelp()"
  3683. " call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
  3684. setl beval
  3685. endif
  3686. " repoint t:netrw_lexbufnr if appropriate
  3687. if exists("repointlexbufnr")
  3688. let t:netrw_lexbufnr= bufnr("%")
  3689. " call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
  3690. endif
  3691. " restore position
  3692. if reusing
  3693. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  3694. call winrestview(svpos)
  3695. endif
  3696. " The s:LocalBrowseRefresh() function is called by an autocmd
  3697. " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
  3698. " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
  3699. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3700. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  3701. " call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
  3702. return
  3703. endfun
  3704. " ---------------------------------------------------------------------
  3705. " s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
  3706. " may not apply correctly; ie. netrw's idea of the current directory may
  3707. " differ from vim's. This function insures that netrw's idea of the current
  3708. " directory is used.
  3709. " Returns a path to the file specified by a:fname
  3710. fun! s:NetrwFile(fname)
  3711. " "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
  3712. " "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
  3713. " "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
  3714. " "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
  3715. " "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
  3716. " clean up any leading treedepthstring
  3717. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  3718. let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
  3719. " "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
  3720. else
  3721. let fname= a:fname
  3722. endif
  3723. if g:netrw_keepdir
  3724. " vim's idea of the current directory possibly may differ from netrw's
  3725. if !exists("b:netrw_curdir")
  3726. let b:netrw_curdir= getcwd()
  3727. endif
  3728. if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
  3729. if fname =~ '^\' || fname =~ '^\a:\'
  3730. " windows, but full path given
  3731. let ret= fname
  3732. " "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
  3733. else
  3734. " windows, relative path given
  3735. let ret= s:ComposePath(b:netrw_curdir,fname)
  3736. " "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
  3737. endif
  3738. elseif fname =~ '^/'
  3739. " not windows, full path given
  3740. let ret= fname
  3741. " "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
  3742. else
  3743. " not windows, relative path given
  3744. let ret= s:ComposePath(b:netrw_curdir,fname)
  3745. " "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
  3746. endif
  3747. else
  3748. " vim and netrw agree on the current directory
  3749. let ret= fname
  3750. " "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
  3751. " "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
  3752. " "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
  3753. endif
  3754. " "" call Dret("s:NetrwFile ".ret)
  3755. return ret
  3756. endfun
  3757. " ---------------------------------------------------------------------
  3758. " s:NetrwFileInfo: supports qf (query for file information) {{{2
  3759. fun! s:NetrwFileInfo(islocal,fname)
  3760. " call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
  3761. let ykeep= @@
  3762. if a:islocal
  3763. let lsopt= "-lsad"
  3764. if g:netrw_sizestyle =~# 'H'
  3765. let lsopt= "-lsadh"
  3766. elseif g:netrw_sizestyle =~# 'h'
  3767. let lsopt= "-lsadh --si"
  3768. endif
  3769. " call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
  3770. if (has("unix") || has("macunix")) && executable("/bin/ls")
  3771. if getline(".") == "../"
  3772. echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
  3773. " call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
  3774. elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
  3775. echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
  3776. " call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
  3777. elseif exists("b:netrw_curdir")
  3778. echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
  3779. " call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
  3780. else
  3781. " call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
  3782. echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
  3783. " call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
  3784. endif
  3785. else
  3786. " use vim functions to return information about file below cursor
  3787. " call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
  3788. if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
  3789. let fname= substitute(a:fname,".$","","")
  3790. else
  3791. let fname= a:fname
  3792. endif
  3793. let t = getftime(s:NetrwFile(fname))
  3794. let sz = getfsize(s:NetrwFile(fname))
  3795. if g:netrw_sizestyle =~# "[hH]"
  3796. let sz= s:NetrwHumanReadable(sz)
  3797. endif
  3798. echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
  3799. " call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
  3800. endif
  3801. else
  3802. echo "sorry, \"qf\" not supported yet for remote files"
  3803. endif
  3804. let @@= ykeep
  3805. " call Dret("s:NetrwFileInfo")
  3806. endfun
  3807. " ---------------------------------------------------------------------
  3808. " s:NetrwFullPath: returns the full path to a directory and/or file {{{2
  3809. fun! s:NetrwFullPath(filename)
  3810. " " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
  3811. let filename= a:filename
  3812. if filename !~ '^/'
  3813. let filename= resolve(getcwd().'/'.filename)
  3814. endif
  3815. if filename != "/" && filename =~ '/$'
  3816. let filename= substitute(filename,'/$','','')
  3817. endif
  3818. " " call Dret("s:NetrwFullPath <".filename.">")
  3819. return filename
  3820. endfun
  3821. " ---------------------------------------------------------------------
  3822. " s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
  3823. " returns 0=cleared buffer
  3824. " 1=re-used buffer (buffer not cleared)
  3825. " Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
  3826. fun! s:NetrwGetBuffer(islocal,dirname)
  3827. " call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
  3828. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." hid=".&hid,'~'.expand("<slnum>"))
  3829. " call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
  3830. " call Dredir("ls!","s:NetrwGetBuffer")
  3831. let dirname= a:dirname
  3832. " re-use buffer if possible {{{3
  3833. " call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
  3834. if !exists("s:netrwbuf")
  3835. " call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
  3836. let s:netrwbuf= {}
  3837. endif
  3838. " call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
  3839. " call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
  3840. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  3841. let bufnum = -1
  3842. if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
  3843. if has_key(s:netrwbuf,"NetrwTreeListing")
  3844. let bufnum= s:netrwbuf["NetrwTreeListing"]
  3845. else
  3846. let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
  3847. endif
  3848. " call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
  3849. if !bufexists(bufnum)
  3850. call remove(s:netrwbuf,"NetrwTreeListing"])
  3851. let bufnum= -1
  3852. endif
  3853. elseif bufnr("NetrwTreeListing") != -1
  3854. let bufnum= bufnr("NetrwTreeListing")
  3855. " call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
  3856. else
  3857. " call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
  3858. let bufnum= -1
  3859. endif
  3860. elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
  3861. let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
  3862. " call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
  3863. if !bufexists(bufnum)
  3864. call remove(s:netrwbuf,s:NetrwFullPath(dirname))
  3865. let bufnum= -1
  3866. endif
  3867. else
  3868. " call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
  3869. let bufnum= -1
  3870. endif
  3871. " call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
  3872. " hijack the current buffer
  3873. " IF the buffer already has the desired name
  3874. " AND it is empty
  3875. let curbuf = bufname("%")
  3876. if curbuf == '.'
  3877. let curbuf = getcwd()
  3878. endif
  3879. " call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
  3880. " call Decho("deciding if netrw may hijack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
  3881. " call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
  3882. " call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
  3883. " call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
  3884. " call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
  3885. if dirname == curbuf && line("$") == 1 && getline("%") == ""
  3886. " call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
  3887. return 0
  3888. else " DEBUG
  3889. " call Decho("..did NOT hijack buffer",'~'.expand("<slnum>"))
  3890. endif
  3891. " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
  3892. " get enew buffer and name it -or- re-use buffer {{{3
  3893. if bufnum < 0 " get enew buffer and name it
  3894. " call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)",'~'.expand("<slnum>"))
  3895. call s:NetrwEnew(dirname)
  3896. " call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
  3897. " name the buffer
  3898. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  3899. " Got enew buffer; transform into a NetrwTreeListing
  3900. " call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
  3901. let w:netrw_treebufnr = bufnr("%")
  3902. call s:NetrwBufRename("NetrwTreeListing")
  3903. if g:netrw_use_noswf
  3904. setl nobl bt=nofile noswf
  3905. else
  3906. setl nobl bt=nofile
  3907. endif
  3908. nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
  3909. nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
  3910. nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
  3911. nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
  3912. " call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
  3913. else
  3914. call s:NetrwBufRename(dirname)
  3915. " enter the new buffer into the s:netrwbuf dictionary
  3916. let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
  3917. " call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
  3918. " call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
  3919. endif
  3920. " call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
  3921. else " Re-use the buffer
  3922. " call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
  3923. let eikeep= &ei
  3924. setl ei=all
  3925. if getline(2) =~# '^" Netrw Directory Listing'
  3926. " call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
  3927. exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
  3928. else
  3929. " call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
  3930. exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
  3931. endif
  3932. " call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
  3933. if bufname("%") == '.'
  3934. call s:NetrwBufRename(getcwd())
  3935. endif
  3936. let &ei= eikeep
  3937. if line("$") <= 1 && getline(1) == ""
  3938. " empty buffer
  3939. NetrwKeepj call s:NetrwListSettings(a:islocal)
  3940. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  3941. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3942. " call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
  3943. return 0
  3944. elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
  3945. " call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
  3946. NetrwKeepj call s:NetrwListSettings(a:islocal)
  3947. sil NetrwKeepj %d _
  3948. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  3949. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3950. " call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
  3951. return 0
  3952. elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  3953. " call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
  3954. " call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  3955. setl ma
  3956. sil NetrwKeepj %d _
  3957. NetrwKeepj call s:NetrwListSettings(a:islocal)
  3958. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  3959. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3960. " call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
  3961. return 0
  3962. else
  3963. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  3964. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3965. " call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
  3966. return 1
  3967. endif
  3968. endif
  3969. " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
  3970. " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
  3971. " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
  3972. " med 1 D H
  3973. " fast 2 H H
  3974. " call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--",'~'.expand("<slnum>"))
  3975. let fname= expand("%")
  3976. NetrwKeepj call s:NetrwListSettings(a:islocal)
  3977. call s:NetrwBufRename(fname)
  3978. " delete all lines from buffer {{{3
  3979. " call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
  3980. " call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  3981. sil! keepalt NetrwKeepj %d _
  3982. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  3983. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  3984. " call Dret("s:NetrwGetBuffer 0<cleared buffer>")
  3985. return 0
  3986. endfun
  3987. " ---------------------------------------------------------------------
  3988. " s:NetrwGetcwd: get the current directory. {{{2
  3989. " Change backslashes to forward slashes, if any.
  3990. " If doesc is true, escape certain troublesome characters
  3991. fun! s:NetrwGetcwd(doesc)
  3992. " call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
  3993. let curdir= substitute(getcwd(),'\\','/','ge')
  3994. if curdir !~ '[\/]$'
  3995. let curdir= curdir.'/'
  3996. endif
  3997. if a:doesc
  3998. let curdir= fnameescape(curdir)
  3999. endif
  4000. " call Dret("NetrwGetcwd <".curdir.">")
  4001. return curdir
  4002. endfun
  4003. " ---------------------------------------------------------------------
  4004. " s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
  4005. fun! s:NetrwGetWord()
  4006. " call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
  4007. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  4008. let keepsol= &l:sol
  4009. setl nosol
  4010. call s:UseBufWinVars()
  4011. " insure that w:netrw_liststyle is set up
  4012. if !exists("w:netrw_liststyle")
  4013. if exists("g:netrw_liststyle")
  4014. let w:netrw_liststyle= g:netrw_liststyle
  4015. else
  4016. let w:netrw_liststyle= s:THINLIST
  4017. endif
  4018. " call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
  4019. endif
  4020. if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
  4021. " Active Banner support
  4022. " call Decho("active banner handling",'~'.expand("<slnum>"))
  4023. NetrwKeepj norm! 0
  4024. let dirname= "./"
  4025. let curline= getline('.')
  4026. if curline =~# '"\s*Sorted by\s'
  4027. NetrwKeepj norm! "_s
  4028. let s:netrw_skipbrowse= 1
  4029. echo 'Pressing "s" also works'
  4030. elseif curline =~# '"\s*Sort sequence:'
  4031. let s:netrw_skipbrowse= 1
  4032. echo 'Press "S" to edit sorting sequence'
  4033. elseif curline =~# '"\s*Quick Help:'
  4034. NetrwKeepj norm! ?
  4035. let s:netrw_skipbrowse= 1
  4036. elseif curline =~# '"\s*\%(Hiding\|Showing\):'
  4037. NetrwKeepj norm! a
  4038. let s:netrw_skipbrowse= 1
  4039. echo 'Pressing "a" also works'
  4040. elseif line("$") > w:netrw_bannercnt
  4041. exe 'sil NetrwKeepj '.w:netrw_bannercnt
  4042. endif
  4043. elseif w:netrw_liststyle == s:THINLIST
  4044. " call Decho("thin column handling",'~'.expand("<slnum>"))
  4045. NetrwKeepj norm! 0
  4046. let dirname= substitute(getline('.'),'\t -->.*$','','')
  4047. elseif w:netrw_liststyle == s:LONGLIST
  4048. " call Decho("long column handling",'~'.expand("<slnum>"))
  4049. NetrwKeepj norm! 0
  4050. let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
  4051. elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  4052. " call Decho("treelist handling",'~'.expand("<slnum>"))
  4053. let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
  4054. let dirname= substitute(dirname,'\t -->.*$','','')
  4055. else
  4056. " call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
  4057. let dirname= getline('.')
  4058. if !exists("b:netrw_cpf")
  4059. let b:netrw_cpf= 0
  4060. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
  4061. call histdel("/",-1)
  4062. " "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
  4063. endif
  4064. " call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
  4065. let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
  4066. " call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
  4067. " call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
  4068. if filestart == 0
  4069. NetrwKeepj norm! 0ma
  4070. else
  4071. call cursor(line("."),filestart+1)
  4072. NetrwKeepj norm! ma
  4073. endif
  4074. let rega= @a
  4075. let eofname= filestart + b:netrw_cpf + 1
  4076. if eofname <= col("$")
  4077. call cursor(line("."),filestart+b:netrw_cpf+1)
  4078. NetrwKeepj norm! "ay`a
  4079. else
  4080. NetrwKeepj norm! "ay$
  4081. endif
  4082. let dirname = @a
  4083. let @a = rega
  4084. " call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
  4085. let dirname= substitute(dirname,'\s\+$','','e')
  4086. " call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
  4087. endif
  4088. " symlinks are indicated by a trailing "@". Remove it before further processing.
  4089. let dirname= substitute(dirname,"@$","","")
  4090. " executables are indicated by a trailing "*". Remove it before further processing.
  4091. let dirname= substitute(dirname,"\*$","","")
  4092. let &l:sol= keepsol
  4093. " call Dret("s:NetrwGetWord <".dirname.">")
  4094. return dirname
  4095. endfun
  4096. " ---------------------------------------------------------------------
  4097. " s:NetrwListSettings: make standard settings for making a netrw listing {{{2
  4098. " g:netrw_bufsettings will be used after the listing is produced.
  4099. " Called by s:NetrwGetBuffer()
  4100. fun! s:NetrwListSettings(islocal)
  4101. " call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
  4102. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  4103. let fname= bufname("%")
  4104. " " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
  4105. " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
  4106. setl bt=nofile nobl ma nonu nowrap noro nornu
  4107. call s:NetrwBufRename(fname)
  4108. if g:netrw_use_noswf
  4109. setl noswf
  4110. endif
  4111. " call Dredir("ls!","s:NetrwListSettings")
  4112. " call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
  4113. exe "setl ts=".(g:netrw_maxfilenamelen+1)
  4114. setl isk+=.,~,-
  4115. if g:netrw_fastbrowse > a:islocal
  4116. setl bh=hide
  4117. else
  4118. setl bh=delete
  4119. endif
  4120. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  4121. " call Dret("s:NetrwListSettings")
  4122. endfun
  4123. " ---------------------------------------------------------------------
  4124. " s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
  4125. " islocal=0: remote browsing
  4126. " =1: local browsing
  4127. fun! s:NetrwListStyle(islocal)
  4128. " call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
  4129. let ykeep = @@
  4130. let fname = s:NetrwGetWord()
  4131. if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
  4132. let svpos = winsaveview()
  4133. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  4134. let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
  4135. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  4136. " call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
  4137. " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
  4138. " repoint t:netrw_lexbufnr if appropriate
  4139. if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
  4140. " call Decho("set repointlexbufnr to true!")
  4141. let repointlexbufnr= 1
  4142. endif
  4143. if w:netrw_liststyle == s:THINLIST
  4144. " use one column listing
  4145. " call Decho("use one column list",'~'.expand("<slnum>"))
  4146. let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
  4147. elseif w:netrw_liststyle == s:LONGLIST
  4148. " use long list
  4149. " call Decho("use long list",'~'.expand("<slnum>"))
  4150. let g:netrw_list_cmd = g:netrw_list_cmd." -l"
  4151. elseif w:netrw_liststyle == s:WIDELIST
  4152. " give wide list
  4153. " call Decho("use wide list",'~'.expand("<slnum>"))
  4154. let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
  4155. elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  4156. " call Decho("use tree list",'~'.expand("<slnum>"))
  4157. let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
  4158. else
  4159. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
  4160. let g:netrw_liststyle = s:THINLIST
  4161. let w:netrw_liststyle = g:netrw_liststyle
  4162. let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
  4163. endif
  4164. setl ma noro
  4165. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  4166. " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
  4167. " call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  4168. sil! NetrwKeepj %d _
  4169. " following prevents tree listing buffer from being marked "modified"
  4170. " call Decho("setl nomod",'~'.expand("<slnum>"))
  4171. setl nomod
  4172. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  4173. " refresh the listing
  4174. " call Decho("refresh the listing",'~'.expand("<slnum>"))
  4175. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  4176. NetrwKeepj call s:NetrwCursor(0)
  4177. " repoint t:netrw_lexbufnr if appropriate
  4178. if exists("repointlexbufnr")
  4179. let t:netrw_lexbufnr= bufnr("%")
  4180. " call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
  4181. endif
  4182. " restore position; keep cursor on the filename
  4183. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  4184. NetrwKeepj call winrestview(svpos)
  4185. let @@= ykeep
  4186. " call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
  4187. endfun
  4188. " ---------------------------------------------------------------------
  4189. " s:NetrwBannerCtrl: toggles the display of the banner {{{2
  4190. fun! s:NetrwBannerCtrl(islocal)
  4191. " call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
  4192. let ykeep= @@
  4193. " toggle the banner (enable/suppress)
  4194. let g:netrw_banner= !g:netrw_banner
  4195. " refresh the listing
  4196. let svpos= winsaveview()
  4197. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  4198. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  4199. " keep cursor on the filename
  4200. if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
  4201. let fname= s:NetrwGetWord()
  4202. sil NetrwKeepj $
  4203. let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
  4204. " " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
  4205. if result <= 0 && exists("w:netrw_bannercnt")
  4206. exe "NetrwKeepj ".w:netrw_bannercnt
  4207. endif
  4208. endif
  4209. let @@= ykeep
  4210. " call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
  4211. endfun
  4212. " ---------------------------------------------------------------------
  4213. " s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
  4214. "
  4215. " No bang: enters files/directories into Netrw's bookmark system
  4216. " No argument and in netrw buffer:
  4217. " if there are marked files: bookmark marked files
  4218. " otherwise : bookmark file/directory under cursor
  4219. " No argument and not in netrw buffer: bookmarks current open file
  4220. " Has arguments: globs them individually and bookmarks them
  4221. "
  4222. " With bang: deletes files/directories from Netrw's bookmark system
  4223. fun! s:NetrwBookmark(del,...)
  4224. " call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
  4225. if a:0 == 0
  4226. if &ft == "netrw"
  4227. let curbufnr = bufnr("%")
  4228. if exists("s:netrwmarkfilelist_{curbufnr}")
  4229. " for every filename in the marked list
  4230. " call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
  4231. let svpos = winsaveview()
  4232. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  4233. let islocal= expand("%") !~ '^\a\{3,}://'
  4234. for fname in s:netrwmarkfilelist_{curbufnr}
  4235. if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
  4236. endfor
  4237. let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
  4238. call s:NetrwUnmarkList(curbufnr,curdir)
  4239. NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
  4240. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  4241. NetrwKeepj call winrestview(svpos)
  4242. else
  4243. let fname= s:NetrwGetWord()
  4244. if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
  4245. endif
  4246. else
  4247. " bookmark currently open file
  4248. " call Decho("bookmark currently open file",'~'.expand("<slnum>"))
  4249. let fname= expand("%")
  4250. if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
  4251. endif
  4252. else
  4253. " bookmark specified files
  4254. " attempts to infer if working remote or local
  4255. " by deciding if the current file begins with an url
  4256. " Globbing cannot be done remotely.
  4257. let islocal= expand("%") !~ '^\a\{3,}://'
  4258. " call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
  4259. let i = 1
  4260. while i <= a:0
  4261. if islocal
  4262. if v:version > 704 || (v:version == 704 && has("patch656"))
  4263. let mbfiles= glob(fnameescape(a:{i}),0,1,1)
  4264. else
  4265. let mbfiles= glob(fnameescape(a:{i}),0,1)
  4266. endif
  4267. else
  4268. let mbfiles= [a:{i}]
  4269. endif
  4270. " call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
  4271. for mbfile in mbfiles
  4272. " call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
  4273. if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
  4274. endfor
  4275. let i= i + 1
  4276. endwhile
  4277. endif
  4278. " update the menu
  4279. call s:NetrwBookmarkMenu()
  4280. " call Dret("s:NetrwBookmark")
  4281. endfun
  4282. " ---------------------------------------------------------------------
  4283. " s:NetrwBookmarkMenu: Uses menu priorities {{{2
  4284. " .2.[cnt] for bookmarks, and
  4285. " .3.[cnt] for history
  4286. " (see s:NetrwMenu())
  4287. fun! s:NetrwBookmarkMenu()
  4288. if !exists("s:netrw_menucnt")
  4289. return
  4290. endif
  4291. " call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
  4292. " the following test assures that gvim is running, has menus available, and has menus enabled.
  4293. if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
  4294. if exists("g:NetrwTopLvlMenu")
  4295. " call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
  4296. exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
  4297. exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
  4298. endif
  4299. if !exists("s:netrw_initbookhist")
  4300. call s:NetrwBookHistRead()
  4301. endif
  4302. " show bookmarked places
  4303. if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
  4304. let cnt= 1
  4305. for bmd in g:netrw_bookmarklist
  4306. " call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
  4307. let bmd= escape(bmd,g:netrw_menu_escape)
  4308. " show bookmarks for goto menu
  4309. exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
  4310. " show bookmarks for deletion menu
  4311. exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.bmd.' '.cnt."mB"
  4312. let cnt= cnt + 1
  4313. endfor
  4314. endif
  4315. " show directory browsing history
  4316. if g:netrw_dirhistmax > 0
  4317. let cnt = g:netrw_dirhistcnt
  4318. let first = 1
  4319. let histcnt = 0
  4320. while ( first || cnt != g:netrw_dirhistcnt )
  4321. let histcnt = histcnt + 1
  4322. let priority = g:netrw_dirhistcnt + histcnt
  4323. if exists("g:netrw_dirhist_{cnt}")
  4324. let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
  4325. " call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
  4326. exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
  4327. endif
  4328. let first = 0
  4329. let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
  4330. if cnt < 0
  4331. let cnt= cnt + g:netrw_dirhistmax
  4332. endif
  4333. endwhile
  4334. endif
  4335. endif
  4336. " call Dret("NetrwBookmarkMenu")
  4337. endfun
  4338. " ---------------------------------------------------------------------
  4339. " s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
  4340. " directory and a new directory name. Also, if the
  4341. " "new directory name" is actually a file,
  4342. " NetrwBrowseChgDir() edits the file.
  4343. fun! s:NetrwBrowseChgDir(islocal,newdir,...)
  4344. " call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
  4345. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  4346. let ykeep= @@
  4347. if !exists("b:netrw_curdir")
  4348. " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
  4349. " and the current window is the NetrwMessage window.
  4350. let @@= ykeep
  4351. " call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
  4352. " call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
  4353. " call Dredir("ls!","s:NetrwBrowseChgDir")
  4354. " call Dret("s:NetrwBrowseChgDir")
  4355. return
  4356. endif
  4357. " call Decho("b:netrw_curdir<".b:netrw_curdir.">")
  4358. " NetrwBrowseChgDir; save options and initialize {{{3
  4359. " call Decho("saving options",'~'.expand("<slnum>"))
  4360. call s:SavePosn(s:netrw_posn)
  4361. NetrwKeepj call s:NetrwOptionsSave("s:")
  4362. NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
  4363. if (has("win32") || has("win95") || has("win64") || has("win16"))
  4364. let dirname = substitute(b:netrw_curdir,'\\','/','ge')
  4365. else
  4366. let dirname = b:netrw_curdir
  4367. endif
  4368. let newdir = a:newdir
  4369. let dolockout = 0
  4370. let dorestore = 1
  4371. " call Decho("win#".winnr(),'~'.expand("<slnum>"))
  4372. " call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
  4373. " call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
  4374. " ignore <cr>s when done in the banner
  4375. " call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
  4376. if g:netrw_banner
  4377. " call Decho("win#".winnr()." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
  4378. if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
  4379. if getline(".") =~# 'Quick Help'
  4380. " call Decho("#1: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  4381. let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
  4382. " call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  4383. setl ma noro nowrap
  4384. NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
  4385. setl noma nomod nowrap
  4386. NetrwKeepj call s:NetrwOptionsRestore("s:")
  4387. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  4388. endif
  4389. endif
  4390. " else " Decho
  4391. " call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
  4392. endif
  4393. " set up o/s-dependent directory recognition pattern
  4394. if has("amiga")
  4395. let dirpat= '[\/:]$'
  4396. else
  4397. let dirpat= '[\/]$'
  4398. endif
  4399. " call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
  4400. if dirname !~ dirpat
  4401. " apparently vim is "recognizing" that it is in a directory and
  4402. " is removing the trailing "/". Bad idea, so let's put it back.
  4403. let dirname= dirname.'/'
  4404. " call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
  4405. endif
  4406. " call Decho("[newdir<".newdir."> ".((newdir =~ dirpat)? "=~" : "!~")." dirpat<".dirpat.">] && [islocal=".a:islocal."] && [newdir is ".(isdirectory(s:NetrwFile(newdir))? "" : "not ")."a directory]",'~'.expand("<slnum>"))
  4407. if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
  4408. " ------------------------------
  4409. " NetrwBrowseChgDir: edit a file {{{3
  4410. " ------------------------------
  4411. " call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
  4412. " save position for benefit of Rexplore
  4413. let s:rexposn_{bufnr("%")}= winsaveview()
  4414. " call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
  4415. " call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
  4416. " call Decho("edit-a-file: w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')." w:netrw_treedict:".(exists("w:netrw_treedict")? "exists" : 'n/a')." newdir<".newdir.">",'~'.expand("<slnum>"))
  4417. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
  4418. " call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
  4419. " call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
  4420. " let newdir = s:NetrwTreePath(s:netrw_treetop)
  4421. " call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
  4422. let dirname= s:NetrwTreeDir(a:islocal)
  4423. "COMBAK : not working for a symlink -- but what about a regular file? a directory?
  4424. " call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
  4425. " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
  4426. if dirname =~ '/$'
  4427. let dirname= dirname.newdir
  4428. else
  4429. let dirname= dirname."/".newdir
  4430. endif
  4431. " call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
  4432. " call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
  4433. elseif newdir =~ '^\(/\|\a:\)'
  4434. " call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
  4435. let dirname= newdir
  4436. else
  4437. let dirname= s:ComposePath(dirname,newdir)
  4438. endif
  4439. " call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
  4440. " this lets netrw#BrowseX avoid the edit
  4441. if a:0 < 1
  4442. " call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
  4443. NetrwKeepj call s:NetrwOptionsRestore("s:")
  4444. let curdir= b:netrw_curdir
  4445. if !exists("s:didsplit")
  4446. " " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
  4447. if type(g:netrw_browse_split) == 3
  4448. " open file in server
  4449. " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
  4450. " call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
  4451. call s:NetrwServerEdit(a:islocal,dirname)
  4452. " call Dret("s:NetrwBrowseChgDir")
  4453. return
  4454. elseif g:netrw_browse_split == 1
  4455. " horizontally splitting the window first
  4456. " call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
  4457. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
  4458. exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
  4459. if !&ea
  4460. keepalt wincmd _
  4461. endif
  4462. call s:SetRexDir(a:islocal,curdir)
  4463. elseif g:netrw_browse_split == 2
  4464. " vertically splitting the window first
  4465. " call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
  4466. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
  4467. exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
  4468. if !&ea
  4469. keepalt wincmd |
  4470. endif
  4471. call s:SetRexDir(a:islocal,curdir)
  4472. elseif g:netrw_browse_split == 3
  4473. " open file in new tab
  4474. " call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
  4475. keepalt tabnew
  4476. if !exists("b:netrw_curdir")
  4477. let b:netrw_curdir= getcwd()
  4478. endif
  4479. call s:SetRexDir(a:islocal,curdir)
  4480. elseif g:netrw_browse_split == 4
  4481. " act like "P" (ie. open previous window)
  4482. " call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
  4483. if s:NetrwPrevWinOpen(2) == 3
  4484. let @@= ykeep
  4485. " call Dret("s:NetrwBrowseChgDir")
  4486. return
  4487. endif
  4488. call s:SetRexDir(a:islocal,curdir)
  4489. else
  4490. " handling a file, didn't split, so remove menu
  4491. " call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
  4492. call s:NetrwMenu(0)
  4493. " optional change to window
  4494. if g:netrw_chgwin >= 1
  4495. " call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
  4496. if winnr("$")+1 == g:netrw_chgwin
  4497. " if g:netrw_chgwin is set to one more than the last window, then
  4498. " vertically split the last window to make that window available.
  4499. let curwin= winnr()
  4500. exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
  4501. vs
  4502. exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
  4503. endif
  4504. exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
  4505. endif
  4506. call s:SetRexDir(a:islocal,curdir)
  4507. endif
  4508. endif
  4509. " the point where netrw actually edits the (local) file
  4510. " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
  4511. " no keepalt to support :e # to return to a directory listing
  4512. if !&mod
  4513. " if e the new file would fail due to &mod, then don't change any of the flags
  4514. let dolockout= 1
  4515. endif
  4516. if a:islocal
  4517. " call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
  4518. " some like c-^ to return to the last edited file
  4519. " others like c-^ to return to the netrw buffer
  4520. " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
  4521. " so emit error E37 instead.
  4522. if exists("g:netrw_altfile") && g:netrw_altfile
  4523. exe "NetrwKeepj keepalt e ".fnameescape(dirname)
  4524. else
  4525. exe "NetrwKeepj e ".fnameescape(dirname)
  4526. endif
  4527. " call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
  4528. " COMBAK -- cuc cul related
  4529. call s:NetrwCursor(1)
  4530. if &hidden || &bufhidden == "hide"
  4531. " file came from vim's hidden storage. Don't "restore" options with it.
  4532. let dorestore= 0
  4533. endif
  4534. else
  4535. " call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
  4536. endif
  4537. " handle g:Netrw_funcref -- call external-to-netrw functions
  4538. " This code will handle g:Netrw_funcref as an individual function reference
  4539. " or as a list of function references. It will ignore anything that's not
  4540. " a function reference. See :help Funcref for information about function references.
  4541. if exists("g:Netrw_funcref")
  4542. " call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
  4543. if type(g:Netrw_funcref) == 2
  4544. " call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
  4545. NetrwKeepj call g:Netrw_funcref()
  4546. elseif type(g:Netrw_funcref) == 3
  4547. " call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
  4548. for Fncref in g:Netrw_funcref
  4549. if type(Fncref) == 2
  4550. NetrwKeepj call Fncref()
  4551. endif
  4552. endfor
  4553. endif
  4554. endif
  4555. endif
  4556. elseif newdir =~ '^/'
  4557. " ----------------------------------------------------
  4558. " NetrwBrowseChgDir: just go to the new directory spec {{{3
  4559. " ----------------------------------------------------
  4560. " call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
  4561. let dirname = newdir
  4562. NetrwKeepj call s:SetRexDir(a:islocal,dirname)
  4563. NetrwKeepj call s:NetrwOptionsRestore("s:")
  4564. norm! m`
  4565. elseif newdir == './'
  4566. " ---------------------------------------------
  4567. " NetrwBrowseChgDir: refresh the directory list {{{3
  4568. " ---------------------------------------------
  4569. " call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
  4570. NetrwKeepj call s:SetRexDir(a:islocal,dirname)
  4571. norm! m`
  4572. elseif newdir == '../'
  4573. " --------------------------------------
  4574. " NetrwBrowseChgDir: go up one directory {{{3
  4575. " --------------------------------------
  4576. " call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
  4577. if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
  4578. " force a refresh
  4579. " call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  4580. " call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
  4581. setl noro ma
  4582. NetrwKeepj %d _
  4583. endif
  4584. if has("amiga")
  4585. " amiga
  4586. " call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
  4587. if a:islocal
  4588. let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
  4589. let dirname= substitute(dirname,'/$','','')
  4590. else
  4591. let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
  4592. endif
  4593. " call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
  4594. elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
  4595. " windows
  4596. if a:islocal
  4597. let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
  4598. if dirname == ""
  4599. let dirname= '/'
  4600. endif
  4601. else
  4602. let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
  4603. endif
  4604. if dirname =~ '^\a:$'
  4605. let dirname= dirname.'/'
  4606. endif
  4607. " call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
  4608. else
  4609. " unix or cygwin
  4610. " call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
  4611. if a:islocal
  4612. let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
  4613. if dirname == ""
  4614. let dirname= '/'
  4615. endif
  4616. else
  4617. let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
  4618. endif
  4619. " call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
  4620. endif
  4621. NetrwKeepj call s:SetRexDir(a:islocal,dirname)
  4622. norm! m`
  4623. elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
  4624. " --------------------------------------
  4625. " NetrwBrowseChgDir: Handle Tree Listing {{{3
  4626. " --------------------------------------
  4627. " call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
  4628. " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
  4629. " call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
  4630. setl noro ma
  4631. if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
  4632. " call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
  4633. NetrwKeepj %d _
  4634. endif
  4635. let treedir = s:NetrwTreeDir(a:islocal)
  4636. " call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
  4637. let s:treecurpos = winsaveview()
  4638. let haskey = 0
  4639. " call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
  4640. " search treedict for tree dir as-is
  4641. " call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
  4642. if has_key(w:netrw_treedict,treedir)
  4643. " call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
  4644. let haskey= 1
  4645. else
  4646. " call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
  4647. endif
  4648. " search treedict for treedir with a [/@] appended
  4649. " call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
  4650. if !haskey && treedir !~ '[/@]$'
  4651. if has_key(w:netrw_treedict,treedir."/")
  4652. let treedir= treedir."/"
  4653. " call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
  4654. let haskey = 1
  4655. else
  4656. " call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
  4657. endif
  4658. endif
  4659. " search treedict for treedir with any trailing / elided
  4660. " call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
  4661. if !haskey && treedir =~ '/$'
  4662. let treedir= substitute(treedir,'/$','','')
  4663. if has_key(w:netrw_treedict,treedir)
  4664. " call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
  4665. let haskey = 1
  4666. else
  4667. " call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
  4668. endif
  4669. endif
  4670. " call Decho("haskey=".haskey,'~'.expand("<slnum>"))
  4671. if haskey
  4672. " close tree listing for selected subdirectory
  4673. " call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
  4674. call remove(w:netrw_treedict,treedir)
  4675. " call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
  4676. " call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
  4677. let dirname= w:netrw_treetop
  4678. else
  4679. " go down one directory
  4680. let dirname= substitute(treedir,'/*$','/','')
  4681. " call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
  4682. " call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
  4683. endif
  4684. NetrwKeepj call s:SetRexDir(a:islocal,dirname)
  4685. " call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
  4686. let s:treeforceredraw = 1
  4687. else
  4688. " ----------------------------------------
  4689. " NetrwBrowseChgDir: Go down one directory {{{3
  4690. " ----------------------------------------
  4691. let dirname = s:ComposePath(dirname,newdir)
  4692. " call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
  4693. NetrwKeepj call s:SetRexDir(a:islocal,dirname)
  4694. norm! m`
  4695. endif
  4696. " --------------------------------------
  4697. " NetrwBrowseChgDir: Restore and Cleanup {{{3
  4698. " --------------------------------------
  4699. if dorestore
  4700. " dorestore is zero'd when a local file was hidden or bufhidden;
  4701. " in such a case, we want to keep whatever settings it may have.
  4702. " call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
  4703. NetrwKeepj call s:NetrwOptionsRestore("s:")
  4704. " else " Decho
  4705. " call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
  4706. endif
  4707. if dolockout && dorestore
  4708. " call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
  4709. if filewritable(dirname)
  4710. " call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
  4711. " call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
  4712. setl ma noro nomod
  4713. " call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  4714. else
  4715. " call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
  4716. " call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
  4717. setl ma ro nomod
  4718. " call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  4719. endif
  4720. endif
  4721. call s:RestorePosn(s:netrw_posn)
  4722. let @@= ykeep
  4723. " call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
  4724. return dirname
  4725. endfun
  4726. " ---------------------------------------------------------------------
  4727. " s:NetrwBrowseUpDir: implements the "-" mappings {{{2
  4728. " for thin, long, and wide: cursor placed just after banner
  4729. " for tree, keeps cursor on current filename
  4730. fun! s:NetrwBrowseUpDir(islocal)
  4731. " call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
  4732. if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
  4733. " this test needed because occasionally this function seems to be incorrectly called
  4734. " when multiple leftmouse clicks are taken when atop the one line help in the banner.
  4735. " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
  4736. " directories.
  4737. " call Dret("s:NetrwBrowseUpDir : cursor not in file area")
  4738. return
  4739. endif
  4740. norm! 0
  4741. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
  4742. " call Decho("case: treestyle",'~'.expand("<slnum>"))
  4743. let curline= getline(".")
  4744. let swwline= winline() - 1
  4745. if exists("w:netrw_treetop")
  4746. let b:netrw_curdir= w:netrw_treetop
  4747. elseif exists("b:netrw_curdir")
  4748. let w:netrw_treetop= b:netrw_curdir
  4749. else
  4750. let w:netrw_treetop= getcwd()
  4751. let b:netrw_curdir = w:netrw_treetop
  4752. endif
  4753. let curfile = getline(".")
  4754. let curpath = s:NetrwTreePath(w:netrw_treetop)
  4755. if a:islocal
  4756. call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
  4757. else
  4758. call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
  4759. endif
  4760. " call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
  4761. " call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
  4762. if w:netrw_treetop == '/'
  4763. keepj call search('^\M'.curfile,"w")
  4764. elseif curfile == '../'
  4765. keepj call search('^\M'.curfile,"wb")
  4766. else
  4767. " call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
  4768. while 1
  4769. keepj call search('^\M'.s:treedepthstring.curfile,"wb")
  4770. let treepath= s:NetrwTreePath(w:netrw_treetop)
  4771. " call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
  4772. if treepath == curpath
  4773. break
  4774. endif
  4775. endwhile
  4776. endif
  4777. else
  4778. " call Decho("case: not treestyle",'~'.expand("<slnum>"))
  4779. call s:SavePosn(s:netrw_posn)
  4780. if exists("b:netrw_curdir")
  4781. let curdir= b:netrw_curdir
  4782. else
  4783. let curdir= expand(getcwd())
  4784. endif
  4785. if a:islocal
  4786. call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
  4787. else
  4788. call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
  4789. endif
  4790. call s:RestorePosn(s:netrw_posn)
  4791. let curdir= substitute(curdir,'^.*[\/]','','')
  4792. call search('\<'.curdir.'/','wc')
  4793. endif
  4794. " call Dret("s:NetrwBrowseUpDir")
  4795. endfun
  4796. " ---------------------------------------------------------------------
  4797. " netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
  4798. " given filename; typically this means given their extension.
  4799. " 0=local, 1=remote
  4800. fun! netrw#BrowseX(fname,remote)
  4801. let use_ctrlo= 1
  4802. " call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
  4803. if a:remote == 0 && isdirectory(a:fname)
  4804. " if its really just a local directory, then do a "gf" instead
  4805. " call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
  4806. " call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
  4807. exe "e ".a:fname
  4808. " call Dret("netrw#BrowseX")
  4809. return
  4810. elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
  4811. " remote directory, not a webpage access, looks like an attempt to do a directory listing
  4812. " call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
  4813. " call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
  4814. " call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
  4815. " call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
  4816. norm! gf
  4817. " call Dret("netrw#BrowseX")
  4818. return
  4819. endif
  4820. " call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
  4821. if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
  4822. let remote = a:remote
  4823. else
  4824. let remote = 0
  4825. endif
  4826. let ykeep = @@
  4827. let screenposn = winsaveview()
  4828. " call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
  4829. " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
  4830. let awkeep = &aw
  4831. set noaw
  4832. " special core dump handler
  4833. if a:fname =~ '/core\(\.\d\+\)\=$'
  4834. if exists("g:Netrw_corehandler")
  4835. if type(g:Netrw_corehandler) == 2
  4836. " g:Netrw_corehandler is a function reference (see :help Funcref)
  4837. " call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
  4838. call g:Netrw_corehandler(s:NetrwFile(a:fname))
  4839. elseif type(g:Netrw_corehandler) == 3
  4840. " g:Netrw_corehandler is a List of function references (see :help Funcref)
  4841. " call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
  4842. for Fncref in g:Netrw_corehandler
  4843. if type(FncRef) == 2
  4844. call FncRef(a:fname)
  4845. endif
  4846. endfor
  4847. endif
  4848. " call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
  4849. call winrestview(screenposn)
  4850. let @@= ykeep
  4851. let &aw= awkeep
  4852. " call Dret("netrw#BrowseX : coredump handler invoked")
  4853. return
  4854. endif
  4855. endif
  4856. " set up the filename
  4857. " (lower case the extension, make a local copy of a remote file)
  4858. let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
  4859. if has("win32") || has("win95") || has("win64") || has("win16")
  4860. let exten= substitute(exten,'^.*$','\L&\E','')
  4861. endif
  4862. if exten =~ "[\\/]"
  4863. let exten= ""
  4864. endif
  4865. " call Decho("exten<".exten.">",'~'.expand("<slnum>"))
  4866. if remote == 1
  4867. " create a local copy
  4868. " call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
  4869. setl bh=delete
  4870. call netrw#NetRead(3,a:fname)
  4871. " attempt to rename tempfile
  4872. let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
  4873. let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
  4874. " call Decho("basename<".basename.">",'~'.expand("<slnum>"))
  4875. " call Decho("newname <".newname.">",'~'.expand("<slnum>"))
  4876. if s:netrw_tmpfile != newname && newname != ""
  4877. if rename(s:netrw_tmpfile,newname) == 0
  4878. " renaming succeeded
  4879. " call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
  4880. let fname= newname
  4881. else
  4882. " renaming failed
  4883. " call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
  4884. let fname= s:netrw_tmpfile
  4885. endif
  4886. else
  4887. let fname= s:netrw_tmpfile
  4888. endif
  4889. else
  4890. " call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
  4891. let fname= a:fname
  4892. " special ~ handler for local
  4893. if fname =~ '^\~' && expand("$HOME") != ""
  4894. " call Decho('invoking special ~ handler','~'.expand("<slnum>"))
  4895. let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
  4896. endif
  4897. endif
  4898. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  4899. " call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
  4900. " set up redirection (avoids browser messages)
  4901. " by default, g:netrw_suppress_gx_mesg is true
  4902. if g:netrw_suppress_gx_mesg
  4903. if &srr =~ "%s"
  4904. if (has("win32") || has("win95") || has("win64") || has("win16"))
  4905. let redir= substitute(&srr,"%s","nul","")
  4906. else
  4907. let redir= substitute(&srr,"%s","/dev/null","")
  4908. endif
  4909. elseif (has("win32") || has("win95") || has("win64") || has("win16"))
  4910. let redir= &srr . "nul"
  4911. else
  4912. let redir= &srr . "/dev/null"
  4913. endif
  4914. endif
  4915. " call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
  4916. " extract any viewing options. Assumes that they're set apart by spaces.
  4917. if exists("g:netrw_browsex_viewer")
  4918. " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
  4919. if g:netrw_browsex_viewer =~ '\s'
  4920. let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
  4921. let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
  4922. let oviewer = ''
  4923. let cnt = 1
  4924. while !executable(viewer) && viewer != oviewer
  4925. let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
  4926. let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
  4927. let cnt = cnt + 1
  4928. let oviewer = viewer
  4929. " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
  4930. endwhile
  4931. else
  4932. let viewer = g:netrw_browsex_viewer
  4933. let viewopt = ""
  4934. endif
  4935. " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
  4936. endif
  4937. " execute the file handler
  4938. " call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
  4939. if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
  4940. " call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
  4941. let ret= netrwFileHandlers#Invoke(exten,fname)
  4942. elseif exists("g:netrw_browsex_viewer") && executable(viewer)
  4943. " call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
  4944. call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
  4945. let ret= v:shell_error
  4946. elseif has("win32") || has("win64")
  4947. " call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
  4948. if executable("start")
  4949. call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
  4950. elseif executable("rundll32")
  4951. call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
  4952. else
  4953. call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
  4954. endif
  4955. let ret= v:shell_error
  4956. elseif has("win32unix")
  4957. let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
  4958. " call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
  4959. if executable("start")
  4960. " call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
  4961. call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
  4962. elseif executable("rundll32")
  4963. " call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
  4964. call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
  4965. elseif executable("cygstart")
  4966. " call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
  4967. call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
  4968. else
  4969. call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
  4970. endif
  4971. let ret= v:shell_error
  4972. elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
  4973. " call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
  4974. if a:fname =~ '^https\=://'
  4975. " atril does not appear to understand how to handle html -- so use gvim to edit the document
  4976. let use_ctrlo= 0
  4977. " call Decho("fname<".fname.">")
  4978. " call Decho("a:fname<".a:fname.">")
  4979. call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
  4980. else
  4981. call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
  4982. endif
  4983. let ret= v:shell_error
  4984. elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
  4985. " call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
  4986. call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
  4987. let ret= v:shell_error
  4988. elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
  4989. " call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
  4990. call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
  4991. let ret= v:shell_error
  4992. elseif has("unix") && executable("xdg-open")
  4993. " call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
  4994. call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
  4995. let ret= v:shell_error
  4996. elseif has("macunix") && executable("open")
  4997. " call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
  4998. call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
  4999. let ret= v:shell_error
  5000. else
  5001. " netrwFileHandlers#Invoke() always returns 0
  5002. " call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
  5003. let ret= netrwFileHandlers#Invoke(exten,fname)
  5004. endif
  5005. " if unsuccessful, attempt netrwFileHandlers#Invoke()
  5006. if ret
  5007. " call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
  5008. let ret= netrwFileHandlers#Invoke(exten,fname)
  5009. endif
  5010. " restoring redraw! after external file handlers
  5011. redraw!
  5012. " cleanup: remove temporary file,
  5013. " delete current buffer if success with handler,
  5014. " return to prior buffer (directory listing)
  5015. " Feb 12, 2008: had to de-activiate removal of
  5016. " temporary file because it wasn't getting seen.
  5017. " if remote == 1 && fname != a:fname
  5018. "" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
  5019. " call s:NetrwDelete(fname)
  5020. " endif
  5021. if remote == 1
  5022. setl bh=delete bt=nofile
  5023. if g:netrw_use_noswf
  5024. setl noswf
  5025. endif
  5026. if use_ctrlo
  5027. exe "sil! NetrwKeepj norm! \<c-o>"
  5028. endif
  5029. endif
  5030. " call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
  5031. call winrestview(screenposn)
  5032. let @@ = ykeep
  5033. let &aw= awkeep
  5034. " call Dret("netrw#BrowseX")
  5035. endfun
  5036. " ---------------------------------------------------------------------
  5037. " netrw#GX: gets word under cursor for gx support {{{2
  5038. " See also: netrw#BrowseXVis
  5039. " netrw#BrowseX
  5040. fun! netrw#GX()
  5041. " call Dfunc("netrw#GX()")
  5042. if &ft == "netrw"
  5043. let fname= s:NetrwGetWord()
  5044. else
  5045. let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
  5046. endif
  5047. " call Dret("netrw#GX <".fname.">")
  5048. return fname
  5049. endfun
  5050. " ---------------------------------------------------------------------
  5051. " netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
  5052. fun! netrw#BrowseXVis()
  5053. " call Dfunc("netrw#BrowseXVis()")
  5054. let akeep = @a
  5055. norm! gv"ay
  5056. let gxfile= @a
  5057. let @a = akeep
  5058. call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
  5059. " call Dret("netrw#BrowseXVis")
  5060. endfun
  5061. " ---------------------------------------------------------------------
  5062. " s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
  5063. " Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
  5064. " to become an unlisted buffer, so in that case don't bwipe it.
  5065. fun! s:NetrwBufRename(newname)
  5066. " call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
  5067. " call Dredir("ls!","s:NetrwBufRename (before rename)")
  5068. let oldbufname= bufname(bufnr("%"))
  5069. " call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
  5070. if oldbufname != a:newname
  5071. " call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
  5072. let b:junk= 1
  5073. " call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
  5074. exe 'sil! keepj keepalt file '.fnameescape(a:newname)
  5075. " call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
  5076. let oldbufnr= bufnr(oldbufname)
  5077. " call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
  5078. " call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
  5079. if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
  5080. " call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
  5081. exe "bwipe! ".oldbufnr
  5082. " else " Decho
  5083. " call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
  5084. " call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
  5085. " call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
  5086. " call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
  5087. endif
  5088. " call Dredir("ls!","s:NetrwBufRename (after rename)")
  5089. " else " Decho
  5090. " call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
  5091. endif
  5092. " call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
  5093. endfun
  5094. " ---------------------------------------------------------------------
  5095. " netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
  5096. fun! netrw#CheckIfRemote(...)
  5097. " call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
  5098. if a:0 > 0
  5099. let curfile= a:1
  5100. else
  5101. let curfile= expand("%")
  5102. endif
  5103. " Ignore terminal buffers
  5104. if &buftype ==# 'terminal'
  5105. return 0
  5106. endif
  5107. " call Decho("curfile<".curfile.">")
  5108. if curfile =~ '^\a\{3,}://'
  5109. " call Dret("netrw#CheckIfRemote 1")
  5110. return 1
  5111. else
  5112. " call Dret("netrw#CheckIfRemote 0")
  5113. return 0
  5114. endif
  5115. endfun
  5116. " ---------------------------------------------------------------------
  5117. " s:NetrwChgPerm: (implements "gp") change file permission {{{2
  5118. fun! s:NetrwChgPerm(islocal,curdir)
  5119. " call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
  5120. let ykeep = @@
  5121. call inputsave()
  5122. let newperm= input("Enter new permission: ")
  5123. call inputrestore()
  5124. let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
  5125. let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
  5126. " call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
  5127. call system(chgperm)
  5128. if v:shell_error != 0
  5129. NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
  5130. endif
  5131. if a:islocal
  5132. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  5133. endif
  5134. let @@= ykeep
  5135. " call Dret("s:NetrwChgPerm")
  5136. endfun
  5137. " ---------------------------------------------------------------------
  5138. " s:CheckIfKde: checks if kdeinit is running {{{2
  5139. " Returns 0: kdeinit not running
  5140. " 1: kdeinit is running
  5141. fun! s:CheckIfKde()
  5142. " call Dfunc("s:CheckIfKde()")
  5143. " seems kde systems often have gnome-open due to dependencies, even though
  5144. " gnome-open's subsidiary display tools are largely absent. Kde systems
  5145. " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
  5146. if !exists("s:haskdeinit")
  5147. if has("unix") && executable("ps") && !has("win32unix")
  5148. let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
  5149. if v:shell_error
  5150. let s:haskdeinit = 0
  5151. endif
  5152. else
  5153. let s:haskdeinit= 0
  5154. endif
  5155. " call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
  5156. endif
  5157. " call Dret("s:CheckIfKde ".s:haskdeinit)
  5158. return s:haskdeinit
  5159. endfun
  5160. " ---------------------------------------------------------------------
  5161. " s:NetrwClearExplore: clear explore variables (if any) {{{2
  5162. fun! s:NetrwClearExplore()
  5163. " call Dfunc("s:NetrwClearExplore()")
  5164. 2match none
  5165. if exists("s:explore_match") |unlet s:explore_match |endif
  5166. if exists("s:explore_indx") |unlet s:explore_indx |endif
  5167. if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
  5168. if exists("s:dirstarstar") |unlet s:dirstarstar |endif
  5169. if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
  5170. if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
  5171. if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
  5172. if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
  5173. if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
  5174. " redraw!
  5175. echo " "
  5176. echo " "
  5177. " call Dret("s:NetrwClearExplore")
  5178. endfun
  5179. " ---------------------------------------------------------------------
  5180. " s:NetrwExploreListUniq: {{{2
  5181. fun! s:NetrwExploreListUniq(explist)
  5182. " call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
  5183. " this assumes that the list is already sorted
  5184. let newexplist= []
  5185. for member in a:explist
  5186. if !exists("uniqmember") || member != uniqmember
  5187. let uniqmember = member
  5188. let newexplist = newexplist + [ member ]
  5189. endif
  5190. endfor
  5191. " call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
  5192. return newexplist
  5193. endfun
  5194. " ---------------------------------------------------------------------
  5195. " s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
  5196. fun! s:NetrwForceChgDir(islocal,newdir)
  5197. " call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
  5198. let ykeep= @@
  5199. if a:newdir !~ '/$'
  5200. " ok, looks like force is needed to get directory-style treatment
  5201. if a:newdir =~ '@$'
  5202. let newdir= substitute(a:newdir,'@$','/','')
  5203. elseif a:newdir =~ '[*=|\\]$'
  5204. let newdir= substitute(a:newdir,'.$','/','')
  5205. else
  5206. let newdir= a:newdir.'/'
  5207. endif
  5208. " call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
  5209. else
  5210. " should already be getting treatment as a directory
  5211. let newdir= a:newdir
  5212. endif
  5213. let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
  5214. call s:NetrwBrowse(a:islocal,newdir)
  5215. let @@= ykeep
  5216. " call Dret("s:NetrwForceChgDir")
  5217. endfun
  5218. " ---------------------------------------------------------------------
  5219. " s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
  5220. " direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
  5221. " expr : this is the expression to follow the directory. Will use s:ComposePath()
  5222. " pare =1: remove the current directory from the resulting glob() filelist
  5223. " =0: leave the current directory in the resulting glob() filelist
  5224. fun! s:NetrwGlob(direntry,expr,pare)
  5225. " call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
  5226. if netrw#CheckIfRemote()
  5227. keepalt 1sp
  5228. keepalt enew
  5229. let keep_liststyle = w:netrw_liststyle
  5230. let w:netrw_liststyle = s:THINLIST
  5231. if s:NetrwRemoteListing() == 0
  5232. keepj keepalt %s@/@@
  5233. let filelist= getline(1,$)
  5234. q!
  5235. else
  5236. " remote listing error -- leave treedict unchanged
  5237. let filelist= w:netrw_treedict[a:direntry]
  5238. endif
  5239. let w:netrw_liststyle= keep_liststyle
  5240. elseif v:version > 704 || (v:version == 704 && has("patch656"))
  5241. let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
  5242. if a:pare
  5243. let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
  5244. endif
  5245. else
  5246. let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
  5247. if a:pare
  5248. let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
  5249. endif
  5250. endif
  5251. " call Dret("s:NetrwGlob ".string(filelist))
  5252. return filelist
  5253. endfun
  5254. " ---------------------------------------------------------------------
  5255. " s:NetrwForceFile: (gf support) Force treatment as a file {{{2
  5256. fun! s:NetrwForceFile(islocal,newfile)
  5257. " call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
  5258. if a:newfile =~ '[/@*=|\\]$'
  5259. let newfile= substitute(a:newfile,'.$','','')
  5260. else
  5261. let newfile= a:newfile
  5262. endif
  5263. if a:islocal
  5264. call s:NetrwBrowseChgDir(a:islocal,newfile)
  5265. else
  5266. call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
  5267. endif
  5268. " call Dret("s:NetrwForceFile")
  5269. endfun
  5270. " ---------------------------------------------------------------------
  5271. " s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
  5272. " and switches the hiding mode. The actual hiding is done by
  5273. " s:NetrwListHide().
  5274. " g:netrw_hide= 0: show all
  5275. " 1: show not-hidden files
  5276. " 2: show hidden files only
  5277. fun! s:NetrwHide(islocal)
  5278. " call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
  5279. let ykeep= @@
  5280. let svpos= winsaveview()
  5281. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5282. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  5283. " call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
  5284. " call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
  5285. " hide the files in the markfile list
  5286. for fname in s:netrwmarkfilelist_{bufnr("%")}
  5287. " call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
  5288. if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
  5289. " remove fname from hiding list
  5290. let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
  5291. let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
  5292. let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
  5293. " call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
  5294. else
  5295. " append fname to hiding list
  5296. if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
  5297. let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
  5298. else
  5299. let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
  5300. endif
  5301. " call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
  5302. endif
  5303. endfor
  5304. NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
  5305. let g:netrw_hide= 1
  5306. else
  5307. " switch between show-all/show-not-hidden/show-hidden
  5308. let g:netrw_hide=(g:netrw_hide+1)%3
  5309. exe "NetrwKeepj norm! 0"
  5310. if g:netrw_hide && g:netrw_list_hide == ""
  5311. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
  5312. let @@= ykeep
  5313. " call Dret("NetrwHide")
  5314. return
  5315. endif
  5316. endif
  5317. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  5318. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5319. NetrwKeepj call winrestview(svpos)
  5320. let @@= ykeep
  5321. " call Dret("NetrwHide")
  5322. endfun
  5323. " ---------------------------------------------------------------------
  5324. " s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
  5325. fun! s:NetrwHideEdit(islocal)
  5326. " call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
  5327. let ykeep= @@
  5328. " save current cursor position
  5329. let svpos= winsaveview()
  5330. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5331. " get new hiding list from user
  5332. call inputsave()
  5333. let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
  5334. call inputrestore()
  5335. let g:netrw_list_hide= newhide
  5336. " call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
  5337. " refresh the listing
  5338. sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
  5339. " restore cursor position
  5340. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5341. call winrestview(svpos)
  5342. let @@= ykeep
  5343. " call Dret("NetrwHideEdit")
  5344. endfun
  5345. " ---------------------------------------------------------------------
  5346. " s:NetrwHidden: invoked by "gh" {{{2
  5347. fun! s:NetrwHidden(islocal)
  5348. " call Dfunc("s:NetrwHidden()")
  5349. let ykeep= @@
  5350. " save current position
  5351. let svpos = winsaveview()
  5352. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5353. if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
  5354. " remove .file pattern from hiding list
  5355. " call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
  5356. let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
  5357. elseif s:Strlen(g:netrw_list_hide) >= 1
  5358. " call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
  5359. let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
  5360. else
  5361. " call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
  5362. let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
  5363. endif
  5364. if g:netrw_list_hide =~ '^,'
  5365. let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
  5366. endif
  5367. " refresh screen and return to saved position
  5368. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  5369. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5370. NetrwKeepj call winrestview(svpos)
  5371. let @@= ykeep
  5372. " call Dret("s:NetrwHidden")
  5373. endfun
  5374. " ---------------------------------------------------------------------
  5375. " s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
  5376. fun! s:NetrwHome()
  5377. if exists("g:netrw_home")
  5378. let home= expand(g:netrw_home)
  5379. else
  5380. let home = stdpath('data')
  5381. endif
  5382. " insure that the home directory exists
  5383. if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
  5384. " call Decho("insure that the home<".home."> directory exists")
  5385. if exists("g:netrw_mkdir")
  5386. " call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
  5387. call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
  5388. else
  5389. " call Decho("mkdir(".home.")")
  5390. call mkdir(home)
  5391. endif
  5392. endif
  5393. let g:netrw_home= home
  5394. return home
  5395. endfun
  5396. " ---------------------------------------------------------------------
  5397. " s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
  5398. fun! s:NetrwLeftmouse(islocal)
  5399. if exists("s:netrwdrag")
  5400. return
  5401. endif
  5402. if &ft != "netrw"
  5403. return
  5404. endif
  5405. " call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
  5406. let ykeep= @@
  5407. " check if the status bar was clicked on instead of a file/directory name
  5408. while getchar(0) != 0
  5409. "clear the input stream
  5410. endwhile
  5411. call feedkeys("\<LeftMouse>")
  5412. let c = getchar()
  5413. let mouse_lnum = v:mouse_lnum
  5414. let wlastline = line('w$')
  5415. let lastline = line('$')
  5416. " call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
  5417. " call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
  5418. if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
  5419. " appears to be a status bar leftmouse click
  5420. let @@= ykeep
  5421. " call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
  5422. return
  5423. endif
  5424. " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
  5425. " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar
  5426. " without this test when its disabled.
  5427. " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
  5428. " call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
  5429. if v:mouse_col > virtcol('.')
  5430. let @@= ykeep
  5431. " call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
  5432. return
  5433. endif
  5434. if a:islocal
  5435. if exists("b:netrw_curdir")
  5436. NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
  5437. endif
  5438. else
  5439. if exists("b:netrw_curdir")
  5440. NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
  5441. endif
  5442. endif
  5443. let @@= ykeep
  5444. " call Dret("s:NetrwLeftmouse")
  5445. endfun
  5446. " ---------------------------------------------------------------------
  5447. " s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
  5448. fun! s:NetrwCLeftmouse(islocal)
  5449. if &ft != "netrw"
  5450. return
  5451. endif
  5452. " call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
  5453. call s:NetrwMarkFileTgt(a:islocal)
  5454. " call Dret("s:NetrwCLeftmouse")
  5455. endfun
  5456. " ---------------------------------------------------------------------
  5457. " s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
  5458. " a:islocal=0 : <c-r> not used, remote
  5459. " a:islocal=1 : <c-r> not used, local
  5460. " a:islocal=2 : <c-r> used, remote
  5461. " a:islocal=3 : <c-r> used, local
  5462. fun! s:NetrwServerEdit(islocal,fname)
  5463. " call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
  5464. let islocal = a:islocal%2 " =0: remote =1: local
  5465. let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
  5466. " call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
  5467. if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
  5468. " handle directories in the local window -- not in the remote vim server
  5469. " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
  5470. " call Decho("handling directory in client window",'~'.expand("<slnum>"))
  5471. let g:netrw_browse_split= 0
  5472. if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
  5473. let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
  5474. unlet s:netrw_browse_split_{winnr()}
  5475. endif
  5476. call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
  5477. " call Dret("s:NetrwServerEdit")
  5478. return
  5479. endif
  5480. " call Decho("handling file in server window",'~'.expand("<slnum>"))
  5481. if has("clientserver") && executable("gvim")
  5482. " call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
  5483. if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
  5484. " call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
  5485. let srvrname = g:netrw_browse_split[0]
  5486. let tabnum = g:netrw_browse_split[1]
  5487. let winnum = g:netrw_browse_split[2]
  5488. if serverlist() !~ '\<'.srvrname.'\>'
  5489. " call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
  5490. if !ctrlr
  5491. " user must have closed the server window and the user did not use <c-r>, but
  5492. " used something like <cr>.
  5493. " call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
  5494. if exists("g:netrw_browse_split")
  5495. unlet g:netrw_browse_split
  5496. endif
  5497. let g:netrw_browse_split= 0
  5498. if exists("s:netrw_browse_split_".winnr())
  5499. let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
  5500. endif
  5501. call s:NetrwBrowseChgDir(islocal,a:fname)
  5502. " call Dret("s:NetrwServerEdit")
  5503. return
  5504. elseif has("win32") && executable("start")
  5505. " start up remote netrw server under windows
  5506. " call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
  5507. call system("start gvim --servername ".srvrname)
  5508. else
  5509. " start up remote netrw server under linux
  5510. " call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
  5511. call system("gvim --servername ".srvrname)
  5512. endif
  5513. endif
  5514. " call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
  5515. call remote_send(srvrname,":tabn ".tabnum."\<cr>")
  5516. call remote_send(srvrname,":".winnum."wincmd w\<cr>")
  5517. call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
  5518. else
  5519. if serverlist() !~ '\<'.g:netrw_servername.'\>'
  5520. if !ctrlr
  5521. " call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
  5522. if exists("g:netrw_browse_split")
  5523. unlet g:netrw_browse_split
  5524. endif
  5525. let g:netrw_browse_split= 0
  5526. call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
  5527. " call Dret("s:NetrwServerEdit")
  5528. return
  5529. else
  5530. " call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
  5531. if has("win32") && executable("start")
  5532. " start up remote netrw server under windows
  5533. " call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
  5534. call system("start gvim --servername ".g:netrw_servername)
  5535. else
  5536. " start up remote netrw server under linux
  5537. " call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
  5538. call system("gvim --servername ".g:netrw_servername)
  5539. endif
  5540. endif
  5541. endif
  5542. while 1
  5543. try
  5544. " call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
  5545. call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
  5546. break
  5547. catch /^Vim\%((\a\+)\)\=:E241/
  5548. sleep 200m
  5549. endtry
  5550. endwhile
  5551. if exists("g:netrw_browse_split")
  5552. if type(g:netrw_browse_split) != 3
  5553. let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
  5554. endif
  5555. unlet g:netrw_browse_split
  5556. endif
  5557. let g:netrw_browse_split= [g:netrw_servername,1,1]
  5558. endif
  5559. else
  5560. call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
  5561. endif
  5562. " call Dret("s:NetrwServerEdit")
  5563. endfun
  5564. " ---------------------------------------------------------------------
  5565. " s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
  5566. fun! s:NetrwSLeftmouse(islocal)
  5567. if &ft != "netrw"
  5568. return
  5569. endif
  5570. " call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
  5571. let s:ngw= s:NetrwGetWord()
  5572. call s:NetrwMarkFile(a:islocal,s:ngw)
  5573. " call Dret("s:NetrwSLeftmouse")
  5574. endfun
  5575. " ---------------------------------------------------------------------
  5576. " s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
  5577. " Used to mark multiple files.
  5578. fun! s:NetrwSLeftdrag(islocal)
  5579. " call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
  5580. if !exists("s:netrwdrag")
  5581. let s:netrwdrag = winnr()
  5582. if a:islocal
  5583. nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
  5584. else
  5585. nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
  5586. endif
  5587. endif
  5588. let ngw = s:NetrwGetWord()
  5589. if !exists("s:ngw") || s:ngw != ngw
  5590. call s:NetrwMarkFile(a:islocal,ngw)
  5591. endif
  5592. let s:ngw= ngw
  5593. " call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
  5594. endfun
  5595. " ---------------------------------------------------------------------
  5596. " s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
  5597. fun! s:NetrwSLeftrelease(islocal)
  5598. " call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
  5599. if exists("s:netrwdrag")
  5600. nunmap <s-leftrelease>
  5601. let ngw = s:NetrwGetWord()
  5602. if !exists("s:ngw") || s:ngw != ngw
  5603. call s:NetrwMarkFile(a:islocal,ngw)
  5604. endif
  5605. if exists("s:ngw")
  5606. unlet s:ngw
  5607. endif
  5608. unlet s:netrwdrag
  5609. endif
  5610. " call Dret("s:NetrwSLeftrelease")
  5611. endfun
  5612. " ---------------------------------------------------------------------
  5613. " s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
  5614. " comma-separated patterns given in g:netrw_list_hide
  5615. fun! s:NetrwListHide()
  5616. " call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
  5617. " call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
  5618. let ykeep= @@
  5619. " find a character not in the "hide" string to use as a separator for :g and :v commands
  5620. " How-it-works: take the hiding command, convert it into a range.
  5621. " Duplicate characters don't matter.
  5622. " Remove all such characters from the '/~@#...890' string.
  5623. " Use the first character left as a separator character.
  5624. " call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
  5625. let listhide= g:netrw_list_hide
  5626. let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
  5627. " call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
  5628. while listhide != ""
  5629. if listhide =~ ','
  5630. let hide = substitute(listhide,',.*$','','e')
  5631. let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
  5632. else
  5633. let hide = listhide
  5634. let listhide = ""
  5635. endif
  5636. " call Decho("..extracted pattern from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
  5637. if g:netrw_sort_by =~ '^[ts]'
  5638. if hide =~ '^\^'
  5639. " call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
  5640. let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
  5641. elseif hide =~ '^\\(\^'
  5642. let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
  5643. endif
  5644. " call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
  5645. endif
  5646. " Prune the list by hiding any files which match
  5647. " call Decho("..prune the list by hiding any files which ".((g:netrw_hide == 1)? "" : "don't")."match hide<".hide.">")
  5648. if g:netrw_hide == 1
  5649. " call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
  5650. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
  5651. elseif g:netrw_hide == 2
  5652. " call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
  5653. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
  5654. endif
  5655. " call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
  5656. endwhile
  5657. if g:netrw_hide == 2
  5658. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
  5659. " call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
  5660. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
  5661. " call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
  5662. endif
  5663. " remove any blank lines that have somehow remained.
  5664. " This seems to happen under Windows.
  5665. exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
  5666. let @@= ykeep
  5667. " call Dret("s:NetrwListHide")
  5668. endfun
  5669. " ---------------------------------------------------------------------
  5670. " s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
  5671. " implements the "d" mapping.
  5672. fun! s:NetrwMakeDir(usrhost)
  5673. " call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
  5674. let ykeep= @@
  5675. " get name of new directory from user. A bare <CR> will skip.
  5676. " if its currently a directory, also request will be skipped, but with
  5677. " a message.
  5678. call inputsave()
  5679. let newdirname= input("Please give directory name: ")
  5680. call inputrestore()
  5681. " call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
  5682. if newdirname == ""
  5683. let @@= ykeep
  5684. " call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
  5685. return
  5686. endif
  5687. if a:usrhost == ""
  5688. " call Decho("local mkdir",'~'.expand("<slnum>"))
  5689. " Local mkdir:
  5690. " sanity checks
  5691. let fullnewdir= b:netrw_curdir.'/'.newdirname
  5692. " call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
  5693. if isdirectory(s:NetrwFile(fullnewdir))
  5694. if !exists("g:netrw_quiet")
  5695. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
  5696. endif
  5697. let @@= ykeep
  5698. " call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
  5699. return
  5700. endif
  5701. if s:FileReadable(fullnewdir)
  5702. if !exists("g:netrw_quiet")
  5703. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
  5704. endif
  5705. let @@= ykeep
  5706. " call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
  5707. return
  5708. endif
  5709. " requested new local directory is neither a pre-existing file or
  5710. " directory, so make it!
  5711. if exists("*mkdir")
  5712. if has("unix")
  5713. call mkdir(fullnewdir,"p",xor(0777, system("umask")))
  5714. else
  5715. call mkdir(fullnewdir,"p")
  5716. endif
  5717. else
  5718. let netrw_origdir= s:NetrwGetcwd(1)
  5719. if s:NetrwLcd(b:netrw_curdir)
  5720. " call Dret("s:NetrwMakeDir : lcd failure")
  5721. return
  5722. endif
  5723. " call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
  5724. call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
  5725. if v:shell_error != 0
  5726. let @@= ykeep
  5727. call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
  5728. " call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
  5729. return
  5730. endif
  5731. if !g:netrw_keepdir
  5732. " call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
  5733. if s:NetrwLcd(netrw_origdir)
  5734. " call Dret("s:NetrwBrowse : lcd failure")
  5735. return
  5736. endif
  5737. endif
  5738. endif
  5739. if v:shell_error == 0
  5740. " refresh listing
  5741. " call Decho("refresh listing",'~'.expand("<slnum>"))
  5742. let svpos= winsaveview()
  5743. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5744. call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
  5745. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5746. call winrestview(svpos)
  5747. elseif !exists("g:netrw_quiet")
  5748. call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
  5749. endif
  5750. " redraw!
  5751. elseif !exists("b:netrw_method") || b:netrw_method == 4
  5752. " Remote mkdir: using ssh
  5753. " call Decho("remote mkdir",'~'.expand("<slnum>"))
  5754. let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
  5755. let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
  5756. call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
  5757. if v:shell_error == 0
  5758. " refresh listing
  5759. let svpos= winsaveview()
  5760. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5761. NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
  5762. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5763. NetrwKeepj call winrestview(svpos)
  5764. elseif !exists("g:netrw_quiet")
  5765. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
  5766. endif
  5767. " redraw!
  5768. elseif b:netrw_method == 2
  5769. " Remote mkdir: using ftp+.netrc
  5770. let svpos= winsaveview()
  5771. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5772. " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  5773. if exists("b:netrw_fname")
  5774. " call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
  5775. let remotepath= b:netrw_fname
  5776. else
  5777. let remotepath= ""
  5778. endif
  5779. call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
  5780. NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
  5781. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5782. NetrwKeepj call winrestview(svpos)
  5783. elseif b:netrw_method == 3
  5784. " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
  5785. let svpos= winsaveview()
  5786. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5787. " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  5788. if exists("b:netrw_fname")
  5789. " call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
  5790. let remotepath= b:netrw_fname
  5791. else
  5792. let remotepath= ""
  5793. endif
  5794. call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
  5795. NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
  5796. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  5797. NetrwKeepj call winrestview(svpos)
  5798. endif
  5799. let @@= ykeep
  5800. " call Dret("s:NetrwMakeDir")
  5801. endfun
  5802. " ---------------------------------------------------------------------
  5803. " s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
  5804. fun! s:TreeSqueezeDir(islocal)
  5805. " call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
  5806. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
  5807. " its a tree-listing style
  5808. let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
  5809. let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
  5810. let depth = strchars(substitute(curdepth,' ','','g'))
  5811. let srch = -1
  5812. " call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
  5813. " call Decho("depth =".depth,'~'.expand("<slnum>"))
  5814. " call Decho("stopline#".stopline,'~'.expand("<slnum>"))
  5815. " call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
  5816. if depth >= 2
  5817. NetrwKeepj norm! 0
  5818. let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
  5819. let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
  5820. " call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
  5821. " call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
  5822. elseif depth == 1
  5823. NetrwKeepj norm! 0
  5824. let treedepthchr= substitute(s:treedepthstring,' ','','')
  5825. let srch = search('^[^'.treedepthchr.']','bW',stopline)
  5826. " call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
  5827. endif
  5828. if srch > 0
  5829. " call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
  5830. call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
  5831. exe srch
  5832. endif
  5833. endif
  5834. " call Dret("s:TreeSqueezeDir")
  5835. endfun
  5836. " ---------------------------------------------------------------------
  5837. " s:NetrwMaps: {{{2
  5838. fun! s:NetrwMaps(islocal)
  5839. " call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
  5840. " mouse <Plug> maps: {{{3
  5841. if g:netrw_mousemaps && g:netrw_retmap
  5842. " call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
  5843. if !hasmapto("<Plug>NetrwReturn")
  5844. if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
  5845. " call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
  5846. nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
  5847. elseif maparg("<c-leftmouse>","n") == ""
  5848. " call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
  5849. nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
  5850. endif
  5851. endif
  5852. nno <silent> <Plug>NetrwReturn :Rexplore<cr>
  5853. " call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
  5854. endif
  5855. " generate default <Plug> maps {{{3
  5856. if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
  5857. if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
  5858. if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
  5859. if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
  5860. if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
  5861. if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
  5862. if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
  5863. if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
  5864. if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
  5865. if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
  5866. if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
  5867. if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
  5868. " ---------------------------------------------------------------------
  5869. " if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
  5870. " if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
  5871. " if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
  5872. " if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
  5873. " if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
  5874. " if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
  5875. " if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
  5876. " if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
  5877. " if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
  5878. " if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
  5879. " if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
  5880. " if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
  5881. " if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
  5882. " if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
  5883. " if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
  5884. " if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
  5885. " if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
  5886. " if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
  5887. " if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
  5888. " if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
  5889. " if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
  5890. " if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
  5891. " if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
  5892. " if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
  5893. " if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
  5894. " if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
  5895. " if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
  5896. " if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
  5897. " if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
  5898. " if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
  5899. " if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
  5900. " if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
  5901. " if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
  5902. " if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
  5903. " if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
  5904. " if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
  5905. " if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
  5906. " if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
  5907. " if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
  5908. " if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
  5909. " if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
  5910. " if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
  5911. " if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
  5912. " if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
  5913. " if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
  5914. " if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
  5915. " if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
  5916. if a:islocal
  5917. " call Decho("make local maps",'~'.expand("<slnum>"))
  5918. " local normal-mode maps {{{3
  5919. nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
  5920. nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
  5921. nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
  5922. nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
  5923. nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
  5924. nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
  5925. nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
  5926. nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
  5927. nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
  5928. nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
  5929. nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
  5930. " ---------------------------------------------------------------------
  5931. nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
  5932. nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
  5933. nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
  5934. nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
  5935. nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
  5936. nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
  5937. nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
  5938. nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
  5939. nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
  5940. nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
  5941. nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
  5942. nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
  5943. nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
  5944. nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
  5945. nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
  5946. nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
  5947. nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
  5948. nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
  5949. nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
  5950. nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
  5951. nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
  5952. nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
  5953. nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
  5954. nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
  5955. nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
  5956. nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
  5957. nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
  5958. nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
  5959. nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
  5960. nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
  5961. nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
  5962. nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
  5963. nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
  5964. nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
  5965. nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
  5966. nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
  5967. nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
  5968. nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
  5969. nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
  5970. nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
  5971. nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
  5972. nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
  5973. nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
  5974. nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
  5975. nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
  5976. nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
  5977. nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
  5978. nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
  5979. if !hasmapto('<Plug>NetrwHideEdit')
  5980. nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
  5981. endif
  5982. nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
  5983. if !hasmapto('<Plug>NetrwRefresh')
  5984. nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
  5985. endif
  5986. nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
  5987. if s:didstarstar || !mapcheck("<s-down>","n")
  5988. nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
  5989. endif
  5990. if s:didstarstar || !mapcheck("<s-up>","n")
  5991. nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
  5992. endif
  5993. if !hasmapto('<Plug>NetrwTreeSqueeze')
  5994. nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
  5995. endif
  5996. nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
  5997. let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
  5998. if g:netrw_mousemaps == 1
  5999. nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
  6000. nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
  6001. nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
  6002. nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
  6003. nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
  6004. nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
  6005. imap <buffer> <leftmouse> <Plug>ILeftmouse
  6006. imap <buffer> <middlemouse> <Plug>IMiddlemouse
  6007. nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
  6008. nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
  6009. nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
  6010. nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
  6011. nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
  6012. nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
  6013. exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
  6014. exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
  6015. endif
  6016. exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
  6017. exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
  6018. exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
  6019. exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
  6020. exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
  6021. exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
  6022. exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
  6023. nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
  6024. " support user-specified maps
  6025. call netrw#UserMaps(1)
  6026. else
  6027. " remote normal-mode maps {{{3
  6028. " call Decho("make remote maps",'~'.expand("<slnum>"))
  6029. call s:RemotePathAnalysis(b:netrw_curdir)
  6030. nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
  6031. nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
  6032. nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
  6033. nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
  6034. nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
  6035. nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
  6036. nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
  6037. nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
  6038. nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
  6039. nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
  6040. nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
  6041. " ---------------------------------------------------------------------
  6042. nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
  6043. nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
  6044. nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
  6045. nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
  6046. nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
  6047. nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
  6048. nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
  6049. nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
  6050. nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
  6051. nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
  6052. nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
  6053. nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
  6054. nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
  6055. nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
  6056. nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
  6057. nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
  6058. nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
  6059. nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
  6060. nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
  6061. nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
  6062. nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
  6063. nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
  6064. nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
  6065. nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
  6066. nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
  6067. nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
  6068. nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
  6069. nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
  6070. nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
  6071. nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
  6072. nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
  6073. nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
  6074. nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
  6075. nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
  6076. nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
  6077. nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
  6078. nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
  6079. nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
  6080. nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
  6081. nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
  6082. nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
  6083. nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
  6084. nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
  6085. nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
  6086. nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
  6087. nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
  6088. if !hasmapto('<Plug>NetrwHideEdit')
  6089. nmap <buffer> <c-h> <Plug>NetrwHideEdit
  6090. endif
  6091. nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
  6092. if !hasmapto('<Plug>NetrwRefresh')
  6093. nmap <buffer> <c-l> <Plug>NetrwRefresh
  6094. endif
  6095. if !hasmapto('<Plug>NetrwTreeSqueeze')
  6096. nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
  6097. endif
  6098. nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
  6099. let mapsafepath = escape(s:path, s:netrw_map_escape)
  6100. let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
  6101. nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
  6102. if g:netrw_mousemaps == 1
  6103. nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
  6104. nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
  6105. nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
  6106. nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
  6107. nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
  6108. nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
  6109. nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
  6110. nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
  6111. nmap <middlemouse> <Plug>NetrwMiddlemouse
  6112. nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
  6113. nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
  6114. nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
  6115. imap <buffer> <leftmouse> <Plug>ILeftmouse
  6116. imap <buffer> <middlemouse> <Plug>IMiddlemouse
  6117. imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
  6118. exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6119. exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6120. endif
  6121. exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6122. exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
  6123. exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6124. exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6125. exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6126. exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6127. exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
  6128. nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
  6129. " support user-specified maps
  6130. call netrw#UserMaps(0)
  6131. endif " }}}3
  6132. " call Dret("s:NetrwMaps")
  6133. endfun
  6134. " ---------------------------------------------------------------------
  6135. " s:NetrwCommands: set up commands {{{2
  6136. " If -buffer, the command is only available from within netrw buffers
  6137. " Otherwise, the command is available from any window, so long as netrw
  6138. " has been used at least once in the session.
  6139. fun! s:NetrwCommands(islocal)
  6140. " call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
  6141. com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
  6142. com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
  6143. com! Rexplore if exists("w:netrw_rexlocal")|call s:NetrwRexplore(w:netrw_rexlocal,exists("w:netrw_rexdir")? w:netrw_rexdir : ".")|else|call netrw#ErrorMsg(s:WARNING,"win#".winnr()." not a former netrw window",79)|endif
  6144. if a:islocal
  6145. com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
  6146. else
  6147. com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
  6148. endif
  6149. com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
  6150. " call Dret("s:NetrwCommands")
  6151. endfun
  6152. " ---------------------------------------------------------------------
  6153. " s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
  6154. " glob()ing only works with local files
  6155. fun! s:NetrwMarkFiles(islocal,...)
  6156. " call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
  6157. let curdir = s:NetrwGetCurdir(a:islocal)
  6158. let i = 1
  6159. while i <= a:0
  6160. if a:islocal
  6161. if v:version > 704 || (v:version == 704 && has("patch656"))
  6162. let mffiles= glob(a:{i},0,1,1)
  6163. else
  6164. let mffiles= glob(a:{i},0,1)
  6165. endif
  6166. else
  6167. let mffiles= [a:{i}]
  6168. endif
  6169. " call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
  6170. for mffile in mffiles
  6171. " call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
  6172. call s:NetrwMarkFile(a:islocal,mffile)
  6173. endfor
  6174. let i= i + 1
  6175. endwhile
  6176. " call Dret("s:NetrwMarkFiles")
  6177. endfun
  6178. " ---------------------------------------------------------------------
  6179. " s:NetrwMarkTarget: implements :MT (mark target) {{{2
  6180. fun! s:NetrwMarkTarget(...)
  6181. " call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
  6182. if a:0 == 0 || (a:0 == 1 && a:1 == "")
  6183. let curdir = s:NetrwGetCurdir(1)
  6184. let tgt = b:netrw_curdir
  6185. else
  6186. let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
  6187. let tgt = a:1
  6188. endif
  6189. " call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
  6190. let s:netrwmftgt = tgt
  6191. let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
  6192. let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
  6193. let svpos = winsaveview()
  6194. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6195. call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
  6196. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6197. call winrestview(svpos)
  6198. " call Dret("s:NetrwMarkTarget")
  6199. endfun
  6200. " ---------------------------------------------------------------------
  6201. " s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
  6202. " mark and unmark files. If a markfile list exists,
  6203. " then the rename and delete functions will use it instead
  6204. " of whatever may happen to be under the cursor at that
  6205. " moment. When the mouse and gui are available,
  6206. " shift-leftmouse may also be used to mark files.
  6207. "
  6208. " Creates two lists
  6209. " s:netrwmarkfilelist -- holds complete paths to all marked files
  6210. " s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
  6211. "
  6212. " Creates a marked file match string
  6213. " s:netrwmarfilemtch_# -- used with 2match to display marked files
  6214. "
  6215. " Creates a buffer version of islocal
  6216. " b:netrw_islocal
  6217. fun! s:NetrwMarkFile(islocal,fname)
  6218. " call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
  6219. " call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
  6220. " sanity check
  6221. if empty(a:fname)
  6222. " call Dret("s:NetrwMarkFile : empty fname")
  6223. return
  6224. endif
  6225. let curdir = s:NetrwGetCurdir(a:islocal)
  6226. let ykeep = @@
  6227. let curbufnr= bufnr("%")
  6228. if a:fname =~ '^\a'
  6229. let leader= '\<'
  6230. else
  6231. let leader= ''
  6232. endif
  6233. if a:fname =~ '\a$'
  6234. let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
  6235. else
  6236. let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
  6237. endif
  6238. if exists("s:netrwmarkfilelist_".curbufnr)
  6239. " markfile list pre-exists
  6240. " call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
  6241. " call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
  6242. " call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
  6243. let b:netrw_islocal= a:islocal
  6244. if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
  6245. " append filename to buffer's markfilelist
  6246. " call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
  6247. call add(s:netrwmarkfilelist_{curbufnr},a:fname)
  6248. let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
  6249. else
  6250. " remove filename from buffer's markfilelist
  6251. " call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
  6252. call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
  6253. if s:netrwmarkfilelist_{curbufnr} == []
  6254. " local markfilelist is empty; remove it entirely
  6255. " call Decho("markfile list now empty",'~'.expand("<slnum>"))
  6256. call s:NetrwUnmarkList(curbufnr,curdir)
  6257. else
  6258. " rebuild match list to display markings correctly
  6259. " call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
  6260. let s:netrwmarkfilemtch_{curbufnr}= ""
  6261. let first = 1
  6262. for fname in s:netrwmarkfilelist_{curbufnr}
  6263. if first
  6264. let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
  6265. else
  6266. let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
  6267. endif
  6268. let first= 0
  6269. endfor
  6270. " call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
  6271. endif
  6272. endif
  6273. else
  6274. " initialize new markfilelist
  6275. " call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
  6276. " call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
  6277. let s:netrwmarkfilelist_{curbufnr}= []
  6278. call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
  6279. " call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
  6280. " build initial markfile matching pattern
  6281. if a:fname =~ '/$'
  6282. let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
  6283. else
  6284. let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
  6285. endif
  6286. " call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
  6287. endif
  6288. " handle global markfilelist
  6289. if exists("s:netrwmarkfilelist")
  6290. let dname= s:ComposePath(b:netrw_curdir,a:fname)
  6291. if index(s:netrwmarkfilelist,dname) == -1
  6292. " append new filename to global markfilelist
  6293. call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
  6294. " call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
  6295. else
  6296. " remove new filename from global markfilelist
  6297. " call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
  6298. " call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
  6299. call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
  6300. " call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
  6301. if s:netrwmarkfilelist == []
  6302. " call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
  6303. unlet s:netrwmarkfilelist
  6304. endif
  6305. endif
  6306. else
  6307. " initialize new global-directory markfilelist
  6308. let s:netrwmarkfilelist= []
  6309. call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
  6310. " call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
  6311. endif
  6312. " set up 2match'ing to netrwmarkfilemtch_# list
  6313. if has("syntax") && exists("g:syntax_on") && g:syntax_on
  6314. if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
  6315. " " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
  6316. if exists("g:did_drchip_netrwlist_syntax")
  6317. exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
  6318. endif
  6319. else
  6320. " " call Decho("2match none",'~'.expand("<slnum>"))
  6321. 2match none
  6322. endif
  6323. endif
  6324. let @@= ykeep
  6325. " call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
  6326. " call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)")
  6327. endfun
  6328. " ---------------------------------------------------------------------
  6329. " s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
  6330. " mA: move the argument list to marked file list (tomflist=1)
  6331. " Uses the global marked file list
  6332. fun! s:NetrwMarkFileArgList(islocal,tomflist)
  6333. " call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
  6334. let svpos = winsaveview()
  6335. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6336. let curdir = s:NetrwGetCurdir(a:islocal)
  6337. let curbufnr = bufnr("%")
  6338. if a:tomflist
  6339. " mA: move argument list to marked file list
  6340. while argc()
  6341. let fname= argv(0)
  6342. " call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
  6343. exe "argdel ".fnameescape(fname)
  6344. call s:NetrwMarkFile(a:islocal,fname)
  6345. endwhile
  6346. else
  6347. " ma: move marked file list to argument list
  6348. if exists("s:netrwmarkfilelist")
  6349. " for every filename in the marked list
  6350. for fname in s:netrwmarkfilelist
  6351. " call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
  6352. exe "argadd ".fnameescape(fname)
  6353. endfor " for every file in the marked list
  6354. " unmark list and refresh
  6355. call s:NetrwUnmarkList(curbufnr,curdir)
  6356. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6357. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6358. NetrwKeepj call winrestview(svpos)
  6359. endif
  6360. endif
  6361. " call Dret("s:NetrwMarkFileArgList")
  6362. endfun
  6363. " ---------------------------------------------------------------------
  6364. " s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
  6365. " compress/decompress files using the programs
  6366. " in g:netrw_compress and g:netrw_uncompress,
  6367. " using g:netrw_compress_suffix to know which to
  6368. " do. By default:
  6369. " g:netrw_compress = "gzip"
  6370. " g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
  6371. fun! s:NetrwMarkFileCompress(islocal)
  6372. " call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
  6373. let svpos = winsaveview()
  6374. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6375. let curdir = s:NetrwGetCurdir(a:islocal)
  6376. let curbufnr = bufnr("%")
  6377. " sanity check
  6378. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  6379. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  6380. " call Dret("s:NetrwMarkFileCompress")
  6381. return
  6382. endif
  6383. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  6384. if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
  6385. " for every filename in the marked list
  6386. for fname in s:netrwmarkfilelist_{curbufnr}
  6387. let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
  6388. " call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
  6389. if exists("g:netrw_decompress['".sfx."']")
  6390. " fname has a suffix indicating that its compressed; apply associated decompression routine
  6391. let exe= g:netrw_decompress[sfx]
  6392. " call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
  6393. let exe= netrw#WinPath(exe)
  6394. if a:islocal
  6395. if g:netrw_keepdir
  6396. let fname= s:ShellEscape(s:ComposePath(curdir,fname))
  6397. endif
  6398. call system(exe." ".fname)
  6399. if v:shell_error
  6400. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
  6401. endif
  6402. else
  6403. let fname= s:ShellEscape(b:netrw_curdir.fname,1)
  6404. NetrwKeepj call s:RemoteSystem(exe." ".fname)
  6405. endif
  6406. endif
  6407. unlet sfx
  6408. if exists("exe")
  6409. unlet exe
  6410. elseif a:islocal
  6411. " fname not a compressed file, so compress it
  6412. call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
  6413. if v:shell_error
  6414. call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
  6415. endif
  6416. else
  6417. " fname not a compressed file, so compress it
  6418. NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
  6419. endif
  6420. endfor " for every file in the marked list
  6421. call s:NetrwUnmarkList(curbufnr,curdir)
  6422. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6423. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6424. NetrwKeepj call winrestview(svpos)
  6425. endif
  6426. " call Dret("s:NetrwMarkFileCompress")
  6427. endfun
  6428. " ---------------------------------------------------------------------
  6429. " s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
  6430. " If no marked files, then set up directory as the
  6431. " target. Currently does not support copying entire
  6432. " directories. Uses the local-buffer marked file list.
  6433. " Returns 1=success (used by NetrwMarkFileMove())
  6434. " 0=failure
  6435. fun! s:NetrwMarkFileCopy(islocal,...)
  6436. " call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
  6437. let curdir = s:NetrwGetCurdir(a:islocal)
  6438. let curbufnr = bufnr("%")
  6439. if b:netrw_curdir !~ '/$'
  6440. if !exists("b:netrw_curdir")
  6441. let b:netrw_curdir= curdir
  6442. endif
  6443. let b:netrw_curdir= b:netrw_curdir."/"
  6444. endif
  6445. " sanity check
  6446. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  6447. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  6448. " call Dret("s:NetrwMarkFileCopy")
  6449. return
  6450. endif
  6451. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  6452. if !exists("s:netrwmftgt")
  6453. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
  6454. " call Dret("s:NetrwMarkFileCopy 0")
  6455. return 0
  6456. endif
  6457. " call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  6458. if a:islocal && s:netrwmftgt_islocal
  6459. " Copy marked files, local directory to local directory
  6460. " call Decho("copy from local to local",'~'.expand("<slnum>"))
  6461. if !executable(g:netrw_localcopycmd)
  6462. call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
  6463. " call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
  6464. return
  6465. endif
  6466. " copy marked files while within the same directory (ie. allow renaming)
  6467. if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
  6468. if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
  6469. " only one marked file
  6470. " call Decho("case: only one marked file",'~'.expand("<slnum>"))
  6471. let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
  6472. let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
  6473. elseif a:0 == 1
  6474. " call Decho("case: handling one input argument",'~'.expand("<slnum>"))
  6475. " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
  6476. let args = s:ShellEscape(b:netrw_curdir.a:1)
  6477. let oldname = a:1
  6478. else
  6479. " copy multiple marked files inside the same directory
  6480. " call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
  6481. let s:recursive= 1
  6482. for oldname in s:netrwmarkfilelist_{bufnr("%")}
  6483. let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
  6484. if ret == 0
  6485. break
  6486. endif
  6487. endfor
  6488. unlet s:recursive
  6489. call s:NetrwUnmarkList(curbufnr,curdir)
  6490. " call Dret("s:NetrwMarkFileCopy ".ret)
  6491. return ret
  6492. endif
  6493. call inputsave()
  6494. let newname= input("Copy ".oldname." to : ",oldname,"file")
  6495. call inputrestore()
  6496. if newname == ""
  6497. " call Dret("s:NetrwMarkFileCopy 0")
  6498. return 0
  6499. endif
  6500. let args= s:ShellEscape(oldname)
  6501. let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
  6502. else
  6503. let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
  6504. let tgt = s:ShellEscape(s:netrwmftgt)
  6505. endif
  6506. if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
  6507. let args= substitute(args,'/','\\','g')
  6508. let tgt = substitute(tgt, '/','\\','g')
  6509. endif
  6510. if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
  6511. if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
  6512. if args =~ '//'|let args= substitute(args,'//','/','g')|endif
  6513. if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
  6514. " call Decho("args <".args.">",'~'.expand("<slnum>"))
  6515. " call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
  6516. if isdirectory(s:NetrwFile(args))
  6517. " call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
  6518. let copycmd= g:netrw_localcopydircmd
  6519. " call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
  6520. if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
  6521. " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
  6522. " contents to a target. One must append the source directory name to the target to get xcopy to
  6523. " do the right thing.
  6524. let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
  6525. " call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
  6526. endif
  6527. else
  6528. let copycmd= g:netrw_localcopycmd
  6529. endif
  6530. if g:netrw_localcopycmd =~ '\s'
  6531. let copycmd = substitute(copycmd,'\s.*$','','')
  6532. let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
  6533. let copycmd = netrw#WinPath(copycmd).copycmdargs
  6534. else
  6535. let copycmd = netrw#WinPath(copycmd)
  6536. endif
  6537. " call Decho("args <".args.">",'~'.expand("<slnum>"))
  6538. " call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
  6539. " call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
  6540. " call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
  6541. call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
  6542. if v:shell_error != 0
  6543. if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
  6544. call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
  6545. else
  6546. call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
  6547. endif
  6548. " call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
  6549. return 0
  6550. endif
  6551. elseif a:islocal && !s:netrwmftgt_islocal
  6552. " Copy marked files, local directory to remote directory
  6553. " call Decho("copy from local to remote",'~'.expand("<slnum>"))
  6554. NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
  6555. elseif !a:islocal && s:netrwmftgt_islocal
  6556. " Copy marked files, remote directory to local directory
  6557. " call Decho("copy from remote to local",'~'.expand("<slnum>"))
  6558. NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
  6559. elseif !a:islocal && !s:netrwmftgt_islocal
  6560. " Copy marked files, remote directory to remote directory
  6561. " call Decho("copy from remote to remote",'~'.expand("<slnum>"))
  6562. let curdir = getcwd()
  6563. let tmpdir = s:GetTempfile("")
  6564. if tmpdir !~ '/'
  6565. let tmpdir= curdir."/".tmpdir
  6566. endif
  6567. if exists("*mkdir")
  6568. call mkdir(tmpdir)
  6569. else
  6570. call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
  6571. if v:shell_error != 0
  6572. call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
  6573. " call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
  6574. return
  6575. endif
  6576. endif
  6577. if isdirectory(s:NetrwFile(tmpdir))
  6578. if s:NetrwLcd(tmpdir)
  6579. " call Dret("s:NetrwMarkFileCopy : lcd failure")
  6580. return
  6581. endif
  6582. NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
  6583. let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
  6584. NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
  6585. if getcwd() == tmpdir
  6586. for fname in s:netrwmarkfilelist_{bufnr('%')}
  6587. NetrwKeepj call s:NetrwDelete(fname)
  6588. endfor
  6589. if s:NetrwLcd(curdir)
  6590. " call Dret("s:NetrwMarkFileCopy : lcd failure")
  6591. return
  6592. endif
  6593. if delete(tmpdir,"d")
  6594. call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
  6595. endif
  6596. else
  6597. if s:NetrwLcd(curdir)
  6598. " call Dret("s:NetrwMarkFileCopy : lcd failure")
  6599. return
  6600. endif
  6601. endif
  6602. endif
  6603. endif
  6604. " -------
  6605. " cleanup
  6606. " -------
  6607. " call Decho("cleanup",'~'.expand("<slnum>"))
  6608. " remove markings from local buffer
  6609. call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
  6610. " call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
  6611. " call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
  6612. " call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
  6613. " call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
  6614. " call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
  6615. " call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
  6616. if exists("s:recursive")
  6617. " call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
  6618. else
  6619. " call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
  6620. endif
  6621. " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
  6622. if g:netrw_fastbrowse <= 1
  6623. NetrwKeepj call s:LocalBrowseRefresh()
  6624. else
  6625. " refresh local and targets for fast browsing
  6626. if !exists("s:recursive")
  6627. " remove markings from local buffer
  6628. " call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
  6629. NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
  6630. endif
  6631. " refresh buffers
  6632. if s:netrwmftgt_islocal
  6633. " call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
  6634. NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
  6635. endif
  6636. if a:islocal && s:netrwmftgt != curdir
  6637. " call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
  6638. NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
  6639. endif
  6640. endif
  6641. " call Dret("s:NetrwMarkFileCopy 1")
  6642. return 1
  6643. endfun
  6644. " ---------------------------------------------------------------------
  6645. " s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
  6646. " invoke vim's diff mode on the marked files.
  6647. " Either two or three files can be so handled.
  6648. " Uses the global marked file list.
  6649. fun! s:NetrwMarkFileDiff(islocal)
  6650. " call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
  6651. let curbufnr= bufnr("%")
  6652. " sanity check
  6653. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  6654. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  6655. " call Dret("s:NetrwMarkFileDiff")
  6656. return
  6657. endif
  6658. let curdir= s:NetrwGetCurdir(a:islocal)
  6659. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  6660. if exists("s:netrwmarkfilelist_{".curbufnr."}")
  6661. let cnt = 0
  6662. for fname in s:netrwmarkfilelist
  6663. let cnt= cnt + 1
  6664. if cnt == 1
  6665. " call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
  6666. exe "NetrwKeepj e ".fnameescape(fname)
  6667. diffthis
  6668. elseif cnt == 2 || cnt == 3
  6669. vsplit
  6670. wincmd l
  6671. " call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
  6672. exe "NetrwKeepj e ".fnameescape(fname)
  6673. diffthis
  6674. else
  6675. break
  6676. endif
  6677. endfor
  6678. call s:NetrwUnmarkList(curbufnr,curdir)
  6679. endif
  6680. " call Dret("s:NetrwMarkFileDiff")
  6681. endfun
  6682. " ---------------------------------------------------------------------
  6683. " s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
  6684. " Uses global markfilelist
  6685. fun! s:NetrwMarkFileEdit(islocal)
  6686. " call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
  6687. let curdir = s:NetrwGetCurdir(a:islocal)
  6688. let curbufnr = bufnr("%")
  6689. " sanity check
  6690. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  6691. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  6692. " call Dret("s:NetrwMarkFileEdit")
  6693. return
  6694. endif
  6695. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  6696. if exists("s:netrwmarkfilelist_{curbufnr}")
  6697. call s:SetRexDir(a:islocal,curdir)
  6698. let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
  6699. " unmark markedfile list
  6700. " call s:NetrwUnmarkList(curbufnr,curdir)
  6701. call s:NetrwUnmarkAll()
  6702. " call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
  6703. exe "sil args ".flist
  6704. endif
  6705. echo "(use :bn, :bp to navigate files; :Rex to return)"
  6706. " call Dret("s:NetrwMarkFileEdit")
  6707. endfun
  6708. " ---------------------------------------------------------------------
  6709. " s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
  6710. fun! s:NetrwMarkFileQFEL(islocal,qfel)
  6711. " call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
  6712. call s:NetrwUnmarkAll()
  6713. let curbufnr= bufnr("%")
  6714. if !empty(a:qfel)
  6715. for entry in a:qfel
  6716. let bufnmbr= entry["bufnr"]
  6717. " call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
  6718. if !exists("s:netrwmarkfilelist_{curbufnr}")
  6719. " call Decho("case: no marked file list",'~'.expand("<slnum>"))
  6720. call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
  6721. elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
  6722. " s:NetrwMarkFile will remove duplicate entries from the marked file list.
  6723. " So, this test lets two or more hits on the same pattern to be ignored.
  6724. " call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
  6725. call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
  6726. else
  6727. " call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
  6728. endif
  6729. endfor
  6730. echo "(use me to edit marked files)"
  6731. else
  6732. call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
  6733. endif
  6734. " call Dret("s:NetrwMarkFileQFEL")
  6735. endfun
  6736. " ---------------------------------------------------------------------
  6737. " s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
  6738. " mx enbloc=0: Uses the local marked-file list, applies command to each file individually
  6739. " mX enbloc=1: Uses the global marked-file list, applies command to entire list
  6740. fun! s:NetrwMarkFileExe(islocal,enbloc)
  6741. " call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
  6742. let svpos = winsaveview()
  6743. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6744. let curdir = s:NetrwGetCurdir(a:islocal)
  6745. let curbufnr = bufnr("%")
  6746. if a:enbloc == 0
  6747. " individually apply command to files, one at a time
  6748. " sanity check
  6749. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  6750. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  6751. " call Dret("s:NetrwMarkFileExe")
  6752. return
  6753. endif
  6754. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  6755. if exists("s:netrwmarkfilelist_{curbufnr}")
  6756. " get the command
  6757. call inputsave()
  6758. let cmd= input("Enter command: ","","file")
  6759. call inputrestore()
  6760. " call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
  6761. if cmd == ""
  6762. " call Dret("s:NetrwMarkFileExe : early exit, empty command")
  6763. return
  6764. endif
  6765. " apply command to marked files, individually. Substitute: filename -> %
  6766. " If no %, then append a space and the filename to the command
  6767. for fname in s:netrwmarkfilelist_{curbufnr}
  6768. if a:islocal
  6769. if g:netrw_keepdir
  6770. let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
  6771. endif
  6772. else
  6773. let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
  6774. endif
  6775. if cmd =~ '%'
  6776. let xcmd= substitute(cmd,'%',fname,'g')
  6777. else
  6778. let xcmd= cmd.' '.fname
  6779. endif
  6780. if a:islocal
  6781. " call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
  6782. let ret= system(xcmd)
  6783. else
  6784. " call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
  6785. let ret= s:RemoteSystem(xcmd)
  6786. endif
  6787. if v:shell_error < 0
  6788. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
  6789. break
  6790. else
  6791. echo ret
  6792. endif
  6793. endfor
  6794. " unmark marked file list
  6795. call s:NetrwUnmarkList(curbufnr,curdir)
  6796. " refresh the listing
  6797. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6798. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6799. NetrwKeepj call winrestview(svpos)
  6800. else
  6801. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
  6802. endif
  6803. else " apply command to global list of files, en bloc
  6804. call inputsave()
  6805. let cmd= input("Enter command: ","","file")
  6806. call inputrestore()
  6807. " call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
  6808. if cmd == ""
  6809. " call Dret("s:NetrwMarkFileExe : early exit, empty command")
  6810. return
  6811. endif
  6812. if cmd =~ '%'
  6813. let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
  6814. else
  6815. let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
  6816. endif
  6817. if a:islocal
  6818. call system(cmd)
  6819. if v:shell_error < 0
  6820. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
  6821. endif
  6822. else
  6823. let ret= s:RemoteSystem(cmd)
  6824. endif
  6825. call s:NetrwUnmarkAll()
  6826. " refresh the listing
  6827. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6828. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6829. NetrwKeepj call winrestview(svpos)
  6830. endif
  6831. " call Dret("s:NetrwMarkFileExe")
  6832. endfun
  6833. " ---------------------------------------------------------------------
  6834. " s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
  6835. " as the marked file(s) (toggles suffix presence)
  6836. " Uses the local marked file list.
  6837. fun! s:NetrwMarkHideSfx(islocal)
  6838. " call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
  6839. let svpos = winsaveview()
  6840. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6841. let curbufnr = bufnr("%")
  6842. " s:netrwmarkfilelist_{curbufnr}: the List of marked files
  6843. if exists("s:netrwmarkfilelist_{curbufnr}")
  6844. for fname in s:netrwmarkfilelist_{curbufnr}
  6845. " call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
  6846. " construct suffix pattern
  6847. if fname =~ '\.'
  6848. let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
  6849. else
  6850. let sfxpat= '^\%(\%(\.\)\@!.\)*$'
  6851. endif
  6852. " determine if its in the hiding list or not
  6853. let inhidelist= 0
  6854. if g:netrw_list_hide != ""
  6855. let itemnum = 0
  6856. let hidelist= split(g:netrw_list_hide,',')
  6857. for hidepat in hidelist
  6858. if sfxpat == hidepat
  6859. let inhidelist= 1
  6860. break
  6861. endif
  6862. let itemnum= itemnum + 1
  6863. endfor
  6864. endif
  6865. " call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
  6866. if inhidelist
  6867. " remove sfxpat from list
  6868. call remove(hidelist,itemnum)
  6869. let g:netrw_list_hide= join(hidelist,",")
  6870. elseif g:netrw_list_hide != ""
  6871. " append sfxpat to non-empty list
  6872. let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
  6873. else
  6874. " set hiding list to sfxpat
  6875. let g:netrw_list_hide= sfxpat
  6876. endif
  6877. endfor
  6878. " refresh the listing
  6879. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6880. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6881. NetrwKeepj call winrestview(svpos)
  6882. else
  6883. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
  6884. endif
  6885. " call Dret("s:NetrwMarkHideSfx")
  6886. endfun
  6887. " ---------------------------------------------------------------------
  6888. " s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
  6889. " Uses the local marked-file list.
  6890. fun! s:NetrwMarkFileVimCmd(islocal)
  6891. " call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
  6892. let svpos = winsaveview()
  6893. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6894. let curdir = s:NetrwGetCurdir(a:islocal)
  6895. let curbufnr = bufnr("%")
  6896. " sanity check
  6897. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  6898. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  6899. " call Dret("s:NetrwMarkFileVimCmd")
  6900. return
  6901. endif
  6902. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  6903. if exists("s:netrwmarkfilelist_{curbufnr}")
  6904. " get the command
  6905. call inputsave()
  6906. let cmd= input("Enter vim command: ","","file")
  6907. call inputrestore()
  6908. " call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
  6909. if cmd == ""
  6910. " " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
  6911. return
  6912. endif
  6913. " apply command to marked files. Substitute: filename -> %
  6914. " If no %, then append a space and the filename to the command
  6915. for fname in s:netrwmarkfilelist_{curbufnr}
  6916. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  6917. if a:islocal
  6918. 1split
  6919. exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
  6920. " call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
  6921. exe cmd
  6922. exe "sil! keepalt wq!"
  6923. else
  6924. " call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
  6925. echo "sorry, \"mv\" not supported yet for remote files"
  6926. endif
  6927. endfor
  6928. " unmark marked file list
  6929. call s:NetrwUnmarkList(curbufnr,curdir)
  6930. " refresh the listing
  6931. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6932. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6933. NetrwKeepj call winrestview(svpos)
  6934. else
  6935. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
  6936. endif
  6937. " call Dret("s:NetrwMarkFileVimCmd")
  6938. endfun
  6939. " ---------------------------------------------------------------------
  6940. " s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
  6941. " as the marked file(s) (toggles suffix presence)
  6942. " Uses the local marked file list.
  6943. fun! s:NetrwMarkHideSfx(islocal)
  6944. " call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
  6945. let svpos = winsaveview()
  6946. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6947. let curbufnr = bufnr("%")
  6948. " s:netrwmarkfilelist_{curbufnr}: the List of marked files
  6949. if exists("s:netrwmarkfilelist_{curbufnr}")
  6950. for fname in s:netrwmarkfilelist_{curbufnr}
  6951. " call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
  6952. " construct suffix pattern
  6953. if fname =~ '\.'
  6954. let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
  6955. else
  6956. let sfxpat= '^\%(\%(\.\)\@!.\)*$'
  6957. endif
  6958. " determine if its in the hiding list or not
  6959. let inhidelist= 0
  6960. if g:netrw_list_hide != ""
  6961. let itemnum = 0
  6962. let hidelist= split(g:netrw_list_hide,',')
  6963. for hidepat in hidelist
  6964. if sfxpat == hidepat
  6965. let inhidelist= 1
  6966. break
  6967. endif
  6968. let itemnum= itemnum + 1
  6969. endfor
  6970. endif
  6971. " call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
  6972. if inhidelist
  6973. " remove sfxpat from list
  6974. call remove(hidelist,itemnum)
  6975. let g:netrw_list_hide= join(hidelist,",")
  6976. elseif g:netrw_list_hide != ""
  6977. " append sfxpat to non-empty list
  6978. let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
  6979. else
  6980. " set hiding list to sfxpat
  6981. let g:netrw_list_hide= sfxpat
  6982. endif
  6983. endfor
  6984. " refresh the listing
  6985. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  6986. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  6987. NetrwKeepj call winrestview(svpos)
  6988. else
  6989. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
  6990. endif
  6991. " call Dret("s:NetrwMarkHideSfx")
  6992. endfun
  6993. " ---------------------------------------------------------------------
  6994. " s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
  6995. " Uses the global markfilelist
  6996. fun! s:NetrwMarkFileGrep(islocal)
  6997. " call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
  6998. let svpos = winsaveview()
  6999. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7000. let curbufnr = bufnr("%")
  7001. let curdir = s:NetrwGetCurdir(a:islocal)
  7002. if exists("s:netrwmarkfilelist")
  7003. " call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
  7004. let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
  7005. " call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
  7006. call s:NetrwUnmarkAll()
  7007. else
  7008. " call Decho('no marked files, using "*"','~'.expand("<slnum>"))
  7009. let netrwmarkfilelist= "*"
  7010. endif
  7011. " ask user for pattern
  7012. " call Decho("ask user for search pattern",'~'.expand("<slnum>"))
  7013. call inputsave()
  7014. let pat= input("Enter pattern: ","")
  7015. call inputrestore()
  7016. let patbang = ""
  7017. if pat =~ '^!'
  7018. let patbang = "!"
  7019. let pat = strpart(pat,2)
  7020. endif
  7021. if pat =~ '^\i'
  7022. let pat = escape(pat,'/')
  7023. let pat = '/'.pat.'/'
  7024. else
  7025. let nonisi = pat[0]
  7026. endif
  7027. " use vimgrep for both local and remote
  7028. " call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
  7029. try
  7030. exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
  7031. catch /^Vim\%((\a\+)\)\=:E480/
  7032. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
  7033. " call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
  7034. return
  7035. endtry
  7036. echo "(use :cn, :cp to navigate, :Rex to return)"
  7037. 2match none
  7038. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7039. NetrwKeepj call winrestview(svpos)
  7040. if exists("nonisi")
  7041. " original, user-supplied pattern did not begin with a character from isident
  7042. " call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
  7043. if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
  7044. call s:NetrwMarkFileQFEL(a:islocal,getqflist())
  7045. endif
  7046. endif
  7047. " call Dret("s:NetrwMarkFileGrep")
  7048. endfun
  7049. " ---------------------------------------------------------------------
  7050. " s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
  7051. " uses the global marked file list
  7052. " s:netrwmfloc= 0: target directory is remote
  7053. " = 1: target directory is local
  7054. fun! s:NetrwMarkFileMove(islocal)
  7055. " call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
  7056. let curdir = s:NetrwGetCurdir(a:islocal)
  7057. let curbufnr = bufnr("%")
  7058. " sanity check
  7059. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  7060. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  7061. " call Dret("s:NetrwMarkFileMove")
  7062. return
  7063. endif
  7064. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  7065. if !exists("s:netrwmftgt")
  7066. NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
  7067. " call Dret("s:NetrwMarkFileCopy 0")
  7068. return 0
  7069. endif
  7070. " call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7071. if a:islocal && s:netrwmftgt_islocal
  7072. " move: local -> local
  7073. " call Decho("move from local to local",'~'.expand("<slnum>"))
  7074. " call Decho("local to local move",'~'.expand("<slnum>"))
  7075. if !executable(g:netrw_localmovecmd)
  7076. call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
  7077. " call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
  7078. return
  7079. endif
  7080. let tgt = s:ShellEscape(s:netrwmftgt)
  7081. " call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
  7082. if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
  7083. let tgt= substitute(tgt, '/','\\','g')
  7084. " call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
  7085. if g:netrw_localmovecmd =~ '\s'
  7086. let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
  7087. let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
  7088. let movecmd = netrw#WinPath(movecmd).movecmdargs
  7089. " call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
  7090. else
  7091. let movecmd = netrw#WinPath(movecmd)
  7092. " call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
  7093. endif
  7094. else
  7095. let movecmd = netrw#WinPath(g:netrw_localmovecmd)
  7096. " call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
  7097. endif
  7098. for fname in s:netrwmarkfilelist_{bufnr("%")}
  7099. if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
  7100. let fname= substitute(fname,'/','\\','g')
  7101. endif
  7102. " call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
  7103. let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
  7104. if v:shell_error != 0
  7105. if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
  7106. call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
  7107. else
  7108. call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
  7109. endif
  7110. break
  7111. endif
  7112. endfor
  7113. elseif a:islocal && !s:netrwmftgt_islocal
  7114. " move: local -> remote
  7115. " call Decho("move from local to remote",'~'.expand("<slnum>"))
  7116. " call Decho("copy",'~'.expand("<slnum>"))
  7117. let mflist= s:netrwmarkfilelist_{bufnr("%")}
  7118. NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
  7119. " call Decho("remove",'~'.expand("<slnum>"))
  7120. for fname in mflist
  7121. let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
  7122. let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
  7123. endfor
  7124. unlet mflist
  7125. elseif !a:islocal && s:netrwmftgt_islocal
  7126. " move: remote -> local
  7127. " call Decho("move from remote to local",'~'.expand("<slnum>"))
  7128. " call Decho("copy",'~'.expand("<slnum>"))
  7129. let mflist= s:netrwmarkfilelist_{bufnr("%")}
  7130. NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
  7131. " call Decho("remove",'~'.expand("<slnum>"))
  7132. for fname in mflist
  7133. let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
  7134. let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
  7135. endfor
  7136. unlet mflist
  7137. elseif !a:islocal && !s:netrwmftgt_islocal
  7138. " move: remote -> remote
  7139. " call Decho("move from remote to remote",'~'.expand("<slnum>"))
  7140. " call Decho("copy",'~'.expand("<slnum>"))
  7141. let mflist= s:netrwmarkfilelist_{bufnr("%")}
  7142. NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
  7143. " call Decho("remove",'~'.expand("<slnum>"))
  7144. for fname in mflist
  7145. let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
  7146. let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
  7147. endfor
  7148. unlet mflist
  7149. endif
  7150. " -------
  7151. " cleanup
  7152. " -------
  7153. " call Decho("cleanup",'~'.expand("<slnum>"))
  7154. " remove markings from local buffer
  7155. call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
  7156. " refresh buffers
  7157. if !s:netrwmftgt_islocal
  7158. " call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7159. NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
  7160. endif
  7161. if a:islocal
  7162. " call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  7163. NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
  7164. endif
  7165. if g:netrw_fastbrowse <= 1
  7166. " call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
  7167. NetrwKeepj call s:LocalBrowseRefresh()
  7168. endif
  7169. " call Dret("s:NetrwMarkFileMove")
  7170. endfun
  7171. " ---------------------------------------------------------------------
  7172. " s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
  7173. " using the hardcopy command. Local marked-file list only.
  7174. fun! s:NetrwMarkFilePrint(islocal)
  7175. " call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
  7176. let curbufnr= bufnr("%")
  7177. " sanity check
  7178. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  7179. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  7180. " call Dret("s:NetrwMarkFilePrint")
  7181. return
  7182. endif
  7183. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  7184. let curdir= s:NetrwGetCurdir(a:islocal)
  7185. if exists("s:netrwmarkfilelist_{curbufnr}")
  7186. let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
  7187. call s:NetrwUnmarkList(curbufnr,curdir)
  7188. for fname in netrwmarkfilelist
  7189. if a:islocal
  7190. if g:netrw_keepdir
  7191. let fname= s:ComposePath(curdir,fname)
  7192. endif
  7193. else
  7194. let fname= curdir.fname
  7195. endif
  7196. 1split
  7197. " the autocmds will handle both local and remote files
  7198. " call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
  7199. exe "sil NetrwKeepj e ".fnameescape(fname)
  7200. " call Decho("hardcopy",'~'.expand("<slnum>"))
  7201. hardcopy
  7202. q
  7203. endfor
  7204. 2match none
  7205. endif
  7206. " call Dret("s:NetrwMarkFilePrint")
  7207. endfun
  7208. " ---------------------------------------------------------------------
  7209. " s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
  7210. " files when given a regexp (for which a prompt is
  7211. " issued) (matches to name of files).
  7212. fun! s:NetrwMarkFileRegexp(islocal)
  7213. " call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
  7214. " get the regular expression
  7215. call inputsave()
  7216. let regexp= input("Enter regexp: ","","file")
  7217. call inputrestore()
  7218. if a:islocal
  7219. let curdir= s:NetrwGetCurdir(a:islocal)
  7220. " call Decho("curdir<".fnameescape(curdir).">")
  7221. " get the matching list of files using local glob()
  7222. " call Decho("handle local regexp",'~'.expand("<slnum>"))
  7223. let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
  7224. if v:version > 704 || (v:version == 704 && has("patch656"))
  7225. let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
  7226. else
  7227. let files = glob(s:ComposePath(dirname,regexp),0,0)
  7228. let filelist= split(files,"\n")
  7229. endif
  7230. " call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
  7231. " mark the list of files
  7232. for fname in filelist
  7233. if fname =~ '^'.fnameescape(curdir)
  7234. " call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
  7235. NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
  7236. else
  7237. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  7238. NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
  7239. endif
  7240. endfor
  7241. else
  7242. " call Decho("handle remote regexp",'~'.expand("<slnum>"))
  7243. " convert displayed listing into a filelist
  7244. let eikeep = &ei
  7245. let areg = @a
  7246. sil NetrwKeepj %y a
  7247. setl ei=all ma
  7248. " call Decho("setl ei=all ma",'~'.expand("<slnum>"))
  7249. 1split
  7250. NetrwKeepj call s:NetrwEnew()
  7251. NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
  7252. sil NetrwKeepj norm! "ap
  7253. NetrwKeepj 2
  7254. let bannercnt= search('^" =====','W')
  7255. exe "sil NetrwKeepj 1,".bannercnt."d"
  7256. setl bt=nofile
  7257. if g:netrw_liststyle == s:LONGLIST
  7258. sil NetrwKeepj %s/\s\{2,}\S.*$//e
  7259. call histdel("/",-1)
  7260. elseif g:netrw_liststyle == s:WIDELIST
  7261. sil NetrwKeepj %s/\s\{2,}/\r/ge
  7262. call histdel("/",-1)
  7263. elseif g:netrw_liststyle == s:TREELIST
  7264. exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
  7265. sil! NetrwKeepj g/^ .*$/d
  7266. call histdel("/",-1)
  7267. call histdel("/",-1)
  7268. endif
  7269. " convert regexp into the more usual glob-style format
  7270. let regexp= substitute(regexp,'\*','.*','g')
  7271. " call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
  7272. exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
  7273. call histdel("/",-1)
  7274. let filelist= getline(1,line("$"))
  7275. q!
  7276. for filename in filelist
  7277. NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
  7278. endfor
  7279. unlet filelist
  7280. let @a = areg
  7281. let &ei = eikeep
  7282. endif
  7283. echo " (use me to edit marked files)"
  7284. " call Dret("s:NetrwMarkFileRegexp")
  7285. endfun
  7286. " ---------------------------------------------------------------------
  7287. " s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
  7288. " Uses the local marked file list.
  7289. fun! s:NetrwMarkFileSource(islocal)
  7290. " call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
  7291. let curbufnr= bufnr("%")
  7292. " sanity check
  7293. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  7294. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  7295. " call Dret("s:NetrwMarkFileSource")
  7296. return
  7297. endif
  7298. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  7299. let curdir= s:NetrwGetCurdir(a:islocal)
  7300. if exists("s:netrwmarkfilelist_{curbufnr}")
  7301. let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
  7302. call s:NetrwUnmarkList(curbufnr,curdir)
  7303. for fname in netrwmarkfilelist
  7304. if a:islocal
  7305. if g:netrw_keepdir
  7306. let fname= s:ComposePath(curdir,fname)
  7307. endif
  7308. else
  7309. let fname= curdir.fname
  7310. endif
  7311. " the autocmds will handle sourcing both local and remote files
  7312. " call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
  7313. exe "so ".fnameescape(fname)
  7314. endfor
  7315. 2match none
  7316. endif
  7317. " call Dret("s:NetrwMarkFileSource")
  7318. endfun
  7319. " ---------------------------------------------------------------------
  7320. " s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
  7321. " Uses the global markfilelist
  7322. fun! s:NetrwMarkFileTag(islocal)
  7323. " call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
  7324. let svpos = winsaveview()
  7325. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7326. let curdir = s:NetrwGetCurdir(a:islocal)
  7327. let curbufnr = bufnr("%")
  7328. " sanity check
  7329. if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
  7330. NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
  7331. " call Dret("s:NetrwMarkFileTag")
  7332. return
  7333. endif
  7334. " call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
  7335. if exists("s:netrwmarkfilelist")
  7336. " call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
  7337. let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
  7338. call s:NetrwUnmarkAll()
  7339. if a:islocal
  7340. " call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
  7341. call system(g:netrw_ctags." ".netrwmarkfilelist)
  7342. if v:shell_error
  7343. call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
  7344. endif
  7345. else
  7346. let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
  7347. call netrw#Obtain(a:islocal,"tags")
  7348. let curdir= b:netrw_curdir
  7349. 1split
  7350. NetrwKeepj e tags
  7351. let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
  7352. " call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
  7353. exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
  7354. call histdel("/",-1)
  7355. wq!
  7356. endif
  7357. 2match none
  7358. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  7359. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7360. call winrestview(svpos)
  7361. endif
  7362. " call Dret("s:NetrwMarkFileTag")
  7363. endfun
  7364. " ---------------------------------------------------------------------
  7365. " s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
  7366. " Sets up two variables,
  7367. " s:netrwmftgt : holds the target directory
  7368. " s:netrwmftgt_islocal : 0=target directory is remote
  7369. " 1=target directory is local
  7370. fun! s:NetrwMarkFileTgt(islocal)
  7371. " call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
  7372. let svpos = winsaveview()
  7373. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7374. let curdir = s:NetrwGetCurdir(a:islocal)
  7375. let hadtgt = exists("s:netrwmftgt")
  7376. if !exists("w:netrw_bannercnt")
  7377. let w:netrw_bannercnt= b:netrw_bannercnt
  7378. endif
  7379. " set up target
  7380. if line(".") < w:netrw_bannercnt
  7381. " call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
  7382. " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
  7383. if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
  7384. " call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
  7385. unlet s:netrwmftgt s:netrwmftgt_islocal
  7386. if g:netrw_fastbrowse <= 1
  7387. call s:LocalBrowseRefresh()
  7388. endif
  7389. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  7390. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7391. call winrestview(svpos)
  7392. " call Dret("s:NetrwMarkFileTgt : removed target")
  7393. return
  7394. else
  7395. let s:netrwmftgt= b:netrw_curdir
  7396. " call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7397. endif
  7398. else
  7399. " get word under cursor.
  7400. " * If directory, use it for the target.
  7401. " * If file, use b:netrw_curdir for the target
  7402. " call Decho("get word under cursor",'~'.expand("<slnum>"))
  7403. let curword= s:NetrwGetWord()
  7404. let tgtdir = s:ComposePath(curdir,curword)
  7405. if a:islocal && isdirectory(s:NetrwFile(tgtdir))
  7406. let s:netrwmftgt = tgtdir
  7407. " call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7408. elseif !a:islocal && tgtdir =~ '/$'
  7409. let s:netrwmftgt = tgtdir
  7410. " call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7411. else
  7412. let s:netrwmftgt = curdir
  7413. " call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7414. endif
  7415. endif
  7416. if a:islocal
  7417. " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
  7418. let s:netrwmftgt= simplify(s:netrwmftgt)
  7419. " call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  7420. endif
  7421. if g:netrw_cygwin
  7422. let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
  7423. let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
  7424. endif
  7425. let s:netrwmftgt_islocal= a:islocal
  7426. " need to do refresh so that the banner will be updated
  7427. " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
  7428. if g:netrw_fastbrowse <= 1
  7429. " call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
  7430. call s:LocalBrowseRefresh()
  7431. endif
  7432. " call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  7433. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  7434. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
  7435. else
  7436. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  7437. endif
  7438. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7439. call winrestview(svpos)
  7440. if !hadtgt
  7441. sil! NetrwKeepj norm! j
  7442. endif
  7443. " call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
  7444. " call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
  7445. " call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
  7446. endfun
  7447. " ---------------------------------------------------------------------
  7448. " s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
  7449. fun! s:NetrwGetCurdir(islocal)
  7450. " call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
  7451. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  7452. let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
  7453. " call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
  7454. elseif !exists("b:netrw_curdir")
  7455. let b:netrw_curdir= getcwd()
  7456. " call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
  7457. endif
  7458. " call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
  7459. if b:netrw_curdir !~ '\<\a\{3,}://'
  7460. let curdir= b:netrw_curdir
  7461. " call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
  7462. if g:netrw_keepdir == 0
  7463. call s:NetrwLcd(curdir)
  7464. endif
  7465. endif
  7466. " call Dret("s:NetrwGetCurdir <".curdir.">")
  7467. return b:netrw_curdir
  7468. endfun
  7469. " ---------------------------------------------------------------------
  7470. " s:NetrwOpenFile: query user for a filename and open it {{{2
  7471. fun! s:NetrwOpenFile(islocal)
  7472. " call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
  7473. let ykeep= @@
  7474. call inputsave()
  7475. let fname= input("Enter filename: ")
  7476. call inputrestore()
  7477. " call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
  7478. " determine if Lexplore is in use
  7479. if exists("t:netrw_lexbufnr")
  7480. " check if t:netrw_lexbufnr refers to a netrw window
  7481. " call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
  7482. let lexwinnr = bufwinnr(t:netrw_lexbufnr)
  7483. if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
  7484. " call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
  7485. exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
  7486. exe "NetrwKeepj e ".fnameescape(fname)
  7487. let @@= ykeep
  7488. " call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
  7489. endif
  7490. endif
  7491. " Does the filename contain a path?
  7492. if fname !~ '[/\\]'
  7493. if exists("b:netrw_curdir")
  7494. if exists("g:netrw_quiet")
  7495. let netrw_quiet_keep = g:netrw_quiet
  7496. endif
  7497. let g:netrw_quiet = 1
  7498. " save position for benefit of Rexplore
  7499. let s:rexposn_{bufnr("%")}= winsaveview()
  7500. " call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
  7501. if b:netrw_curdir =~ '/$'
  7502. exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
  7503. else
  7504. exe "e ".fnameescape(b:netrw_curdir."/".fname)
  7505. endif
  7506. if exists("netrw_quiet_keep")
  7507. let g:netrw_quiet= netrw_quiet_keep
  7508. else
  7509. unlet g:netrw_quiet
  7510. endif
  7511. endif
  7512. else
  7513. exe "NetrwKeepj e ".fnameescape(fname)
  7514. endif
  7515. let @@= ykeep
  7516. " call Dret("s:NetrwOpenFile")
  7517. endfun
  7518. " ---------------------------------------------------------------------
  7519. " netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
  7520. " For the mapping to this function be made via
  7521. " netrwPlugin, you'll need to have had
  7522. " g:netrw_usetab set to non-zero.
  7523. fun! netrw#Shrink()
  7524. " call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
  7525. let curwin = winnr()
  7526. let wiwkeep = &wiw
  7527. set wiw=1
  7528. if &ft == "netrw"
  7529. if winwidth(0) > g:netrw_wiw
  7530. let t:netrw_winwidth= winwidth(0)
  7531. exe "vert resize ".g:netrw_wiw
  7532. wincmd l
  7533. if winnr() == curwin
  7534. wincmd h
  7535. endif
  7536. " call Decho("vert resize 0",'~'.expand("<slnum>"))
  7537. else
  7538. exe "vert resize ".t:netrw_winwidth
  7539. " call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
  7540. endif
  7541. elseif exists("t:netrw_lexbufnr")
  7542. exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
  7543. if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
  7544. let t:netrw_winwidth= winwidth(0)
  7545. exe "vert resize ".g:netrw_wiw
  7546. wincmd l
  7547. if winnr() == curwin
  7548. wincmd h
  7549. endif
  7550. " call Decho("vert resize 0",'~'.expand("<slnum>"))
  7551. elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
  7552. exe "vert resize ".t:netrw_winwidth
  7553. " call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
  7554. else
  7555. call netrw#Lexplore(0,0)
  7556. endif
  7557. else
  7558. call netrw#Lexplore(0,0)
  7559. endif
  7560. let wiw= wiwkeep
  7561. " call Dret("netrw#Shrink")
  7562. endfun
  7563. " ---------------------------------------------------------------------
  7564. " s:NetSortSequence: allows user to edit the sorting sequence {{{2
  7565. fun! s:NetSortSequence(islocal)
  7566. " call Dfunc("NetSortSequence(islocal=".a:islocal.")")
  7567. let ykeep= @@
  7568. let svpos= winsaveview()
  7569. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7570. call inputsave()
  7571. let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
  7572. call inputrestore()
  7573. " refresh the listing
  7574. let g:netrw_sort_sequence= newsortseq
  7575. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  7576. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7577. NetrwKeepj call winrestview(svpos)
  7578. let @@= ykeep
  7579. " call Dret("NetSortSequence")
  7580. endfun
  7581. " ---------------------------------------------------------------------
  7582. " s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
  7583. " User access provided by the <mF> mapping. (see :help netrw-mF)
  7584. " Used by many MarkFile functions.
  7585. fun! s:NetrwUnmarkList(curbufnr,curdir)
  7586. " call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
  7587. " remove all files in local marked-file list from global list
  7588. if exists("s:netrwmarkfilelist")
  7589. for mfile in s:netrwmarkfilelist_{a:curbufnr}
  7590. let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
  7591. let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
  7592. call remove(s:netrwmarkfilelist,idx) " remove from global list
  7593. endfor
  7594. if s:netrwmarkfilelist == []
  7595. unlet s:netrwmarkfilelist
  7596. endif
  7597. " getting rid of the local marked-file lists is easy
  7598. unlet s:netrwmarkfilelist_{a:curbufnr}
  7599. endif
  7600. if exists("s:netrwmarkfilemtch_{a:curbufnr}")
  7601. unlet s:netrwmarkfilemtch_{a:curbufnr}
  7602. endif
  7603. 2match none
  7604. " call Dret("s:NetrwUnmarkList")
  7605. endfun
  7606. " ---------------------------------------------------------------------
  7607. " s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
  7608. fun! s:NetrwUnmarkAll()
  7609. " call Dfunc("s:NetrwUnmarkAll()")
  7610. if exists("s:netrwmarkfilelist")
  7611. unlet s:netrwmarkfilelist
  7612. endif
  7613. sil call s:NetrwUnmarkAll2()
  7614. 2match none
  7615. " call Dret("s:NetrwUnmarkAll")
  7616. endfun
  7617. " ---------------------------------------------------------------------
  7618. " s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
  7619. fun! s:NetrwUnmarkAll2()
  7620. " call Dfunc("s:NetrwUnmarkAll2()")
  7621. redir => netrwmarkfilelist_let
  7622. let
  7623. redir END
  7624. let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
  7625. call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
  7626. call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
  7627. for flist in netrwmarkfilelist_list
  7628. let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
  7629. unlet s:netrwmarkfilelist_{curbufnr}
  7630. unlet s:netrwmarkfilemtch_{curbufnr}
  7631. endfor
  7632. " call Dret("s:NetrwUnmarkAll2")
  7633. endfun
  7634. " ---------------------------------------------------------------------
  7635. " s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
  7636. "
  7637. " Marked files are in two types of lists:
  7638. " s:netrwmarkfilelist -- holds complete paths to all marked files
  7639. " s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
  7640. "
  7641. " Marked files suitable for use with 2match are in:
  7642. " s:netrwmarkfilemtch_# -- used with 2match to display marked files
  7643. fun! s:NetrwUnMarkFile(islocal)
  7644. " call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
  7645. let svpos = winsaveview()
  7646. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7647. let curbufnr = bufnr("%")
  7648. " unmark marked file list
  7649. " (although I expect s:NetrwUpload() to do it, I'm just making sure)
  7650. if exists("s:netrwmarkfilelist")
  7651. " " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
  7652. unlet s:netrwmarkfilelist
  7653. endif
  7654. let ibuf= 1
  7655. while ibuf < bufnr("$")
  7656. if exists("s:netrwmarkfilelist_".ibuf)
  7657. unlet s:netrwmarkfilelist_{ibuf}
  7658. unlet s:netrwmarkfilemtch_{ibuf}
  7659. endif
  7660. let ibuf = ibuf + 1
  7661. endwhile
  7662. 2match none
  7663. " call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  7664. "call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  7665. call winrestview(svpos)
  7666. " call Dret("s:NetrwUnMarkFile")
  7667. endfun
  7668. " ---------------------------------------------------------------------
  7669. " s:NetrwMenu: generates the menu for gvim and netrw {{{2
  7670. fun! s:NetrwMenu(domenu)
  7671. if !exists("g:NetrwMenuPriority")
  7672. let g:NetrwMenuPriority= 80
  7673. endif
  7674. if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
  7675. " call Dfunc("NetrwMenu(domenu=".a:domenu.")")
  7676. if !exists("s:netrw_menu_enabled") && a:domenu
  7677. " call Decho("initialize menu",'~'.expand("<slnum>"))
  7678. let s:netrw_menu_enabled= 1
  7679. exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
  7680. exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
  7681. exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
  7682. exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
  7683. if g:netrw_dirhistmax > 0
  7684. exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
  7685. exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
  7686. exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
  7687. exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
  7688. else
  7689. exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
  7690. endif
  7691. exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
  7692. exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
  7693. exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
  7694. exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
  7695. exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
  7696. exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
  7697. exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
  7698. exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
  7699. exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
  7700. exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
  7701. exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
  7702. exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
  7703. exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
  7704. exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
  7705. exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
  7706. exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
  7707. exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
  7708. exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
  7709. exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
  7710. exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
  7711. exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
  7712. exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
  7713. exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
  7714. exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
  7715. exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
  7716. exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
  7717. exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
  7718. exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
  7719. exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
  7720. exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
  7721. exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
  7722. exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
  7723. exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
  7724. exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
  7725. exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
  7726. exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
  7727. exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
  7728. exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
  7729. exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
  7730. exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
  7731. exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
  7732. exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
  7733. exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
  7734. exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
  7735. exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
  7736. exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
  7737. exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
  7738. exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
  7739. exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
  7740. exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
  7741. exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
  7742. exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
  7743. exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
  7744. exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
  7745. exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
  7746. let s:netrw_menucnt= 28
  7747. call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
  7748. call s:NetrwTgtMenu() " let bookmarks and history be easy targets
  7749. elseif !a:domenu
  7750. let s:netrwcnt = 0
  7751. let curwin = winnr()
  7752. windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
  7753. exe curwin."wincmd w"
  7754. if s:netrwcnt <= 1
  7755. " call Decho("clear menus",'~'.expand("<slnum>"))
  7756. exe 'sil! unmenu '.g:NetrwTopLvlMenu
  7757. " call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
  7758. sil! unlet s:netrw_menu_enabled
  7759. endif
  7760. endif
  7761. " call Dret("NetrwMenu")
  7762. return
  7763. endif
  7764. endfun
  7765. " ---------------------------------------------------------------------
  7766. " s:NetrwObtain: obtain file under cursor or from markfile list {{{2
  7767. " Used by the O maps (as <SID>NetrwObtain())
  7768. fun! s:NetrwObtain(islocal)
  7769. " call Dfunc("NetrwObtain(islocal=".a:islocal.")")
  7770. let ykeep= @@
  7771. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  7772. let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
  7773. call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
  7774. call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
  7775. else
  7776. call netrw#Obtain(a:islocal,s:NetrwGetWord())
  7777. endif
  7778. let @@= ykeep
  7779. " call Dret("NetrwObtain")
  7780. endfun
  7781. " ---------------------------------------------------------------------
  7782. " s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
  7783. " If there's only one window, then the window will first be split.
  7784. " Returns:
  7785. " choice = 0 : didn't have to choose
  7786. " choice = 1 : saved modified file in window first
  7787. " choice = 2 : didn't save modified file, opened window
  7788. " choice = 3 : cancel open
  7789. fun! s:NetrwPrevWinOpen(islocal)
  7790. " call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
  7791. let ykeep= @@
  7792. " grab a copy of the b:netrw_curdir to pass it along to newly split windows
  7793. let curdir = b:netrw_curdir
  7794. " get last window number and the word currently under the cursor
  7795. let origwin = winnr()
  7796. let lastwinnr = winnr("$")
  7797. let curword = s:NetrwGetWord()
  7798. let choice = 0
  7799. let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it
  7800. let s:treedir = s:NetrwTreeDir(a:islocal)
  7801. let curdir = s:treedir
  7802. " call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
  7803. let didsplit = 0
  7804. if lastwinnr == 1
  7805. " if only one window, open a new one first
  7806. " call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
  7807. " g:netrw_preview=0: preview window shown in a horizontally split window
  7808. " g:netrw_preview=1: preview window shown in a vertically split window
  7809. if g:netrw_preview
  7810. " vertically split preview window
  7811. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
  7812. " call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
  7813. exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
  7814. else
  7815. " horizontally split preview window
  7816. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
  7817. " call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
  7818. exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
  7819. endif
  7820. let didsplit = 1
  7821. " call Decho("did split",'~'.expand("<slnum>"))
  7822. else
  7823. NetrwKeepj call s:SaveBufVars()
  7824. let eikeep= &ei
  7825. setl ei=all
  7826. wincmd p
  7827. " call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
  7828. " prevwinnr: the window number of the "prev" window
  7829. " prevbufnr: the buffer number of the buffer in the "prev" window
  7830. " bnrcnt : the qty of windows open on the "prev" buffer
  7831. let prevwinnr = winnr()
  7832. let prevbufnr = bufnr("%")
  7833. let prevbufname = bufname("%")
  7834. let prevmod = &mod
  7835. let bnrcnt = 0
  7836. NetrwKeepj call s:RestoreBufVars()
  7837. " call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
  7838. " if the previous window's buffer has been changed (ie. its modified flag is set),
  7839. " and it doesn't appear in any other extant window, then ask the
  7840. " user if s/he wants to abandon modifications therein.
  7841. if prevmod
  7842. " call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
  7843. windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
  7844. " call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
  7845. exe prevwinnr."wincmd w"
  7846. if bnrcnt == 1 && &hidden == 0
  7847. " only one copy of the modified buffer in a window, and
  7848. " hidden not set, so overwriting will lose the modified file. Ask first...
  7849. let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
  7850. " call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
  7851. let &ei= eikeep
  7852. if choice == 1
  7853. " Yes -- write file & then browse
  7854. let v:errmsg= ""
  7855. sil w
  7856. if v:errmsg != ""
  7857. call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
  7858. exe origwin."wincmd w"
  7859. let &ei = eikeep
  7860. let @@ = ykeep
  7861. " call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
  7862. return choice
  7863. endif
  7864. elseif choice == 2
  7865. " No -- don't worry about changed file, just browse anyway
  7866. " call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
  7867. echomsg "**note** changes to ".prevbufname." abandoned"
  7868. else
  7869. " Cancel -- don't do this
  7870. " call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
  7871. exe origwin."wincmd w"
  7872. let &ei= eikeep
  7873. let @@ = ykeep
  7874. " call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
  7875. return choice
  7876. endif
  7877. endif
  7878. endif
  7879. let &ei= eikeep
  7880. endif
  7881. " restore b:netrw_curdir (window split/enew may have lost it)
  7882. let b:netrw_curdir= curdir
  7883. if a:islocal < 2
  7884. if a:islocal
  7885. call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
  7886. else
  7887. call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
  7888. endif
  7889. endif
  7890. let @@= ykeep
  7891. " call Dret("s:NetrwPrevWinOpen ".choice)
  7892. return choice
  7893. endfun
  7894. " ---------------------------------------------------------------------
  7895. " s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
  7896. " Always assumed to be local -> remote
  7897. " call s:NetrwUpload(filename, target)
  7898. " call s:NetrwUpload(filename, target, fromdirectory)
  7899. fun! s:NetrwUpload(fname,tgt,...)
  7900. " call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
  7901. if a:tgt =~ '^\a\{3,}://'
  7902. let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
  7903. else
  7904. let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
  7905. endif
  7906. " call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
  7907. if a:0 > 0
  7908. let fromdir= a:1
  7909. else
  7910. let fromdir= getcwd()
  7911. endif
  7912. " call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
  7913. if type(a:fname) == 1
  7914. " handle uploading a single file using NetWrite
  7915. " call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
  7916. 1split
  7917. " call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
  7918. exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
  7919. " call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
  7920. if a:tgt =~ '/$'
  7921. let wfname= substitute(a:fname,'^.*/','','')
  7922. " call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
  7923. exe "w! ".fnameescape(a:tgt.wfname)
  7924. else
  7925. " call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
  7926. exe "w ".fnameescape(a:tgt)
  7927. " call Decho("done writing local->remote",'~'.expand("<slnum>"))
  7928. endif
  7929. q!
  7930. elseif type(a:fname) == 3
  7931. " handle uploading a list of files via scp
  7932. " call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
  7933. let curdir= getcwd()
  7934. if a:tgt =~ '^scp:'
  7935. if s:NetrwLcd(fromdir)
  7936. " call Dret("s:NetrwUpload : lcd failure")
  7937. return
  7938. endif
  7939. let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
  7940. let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
  7941. if exists("g:netrw_port") && g:netrw_port != ""
  7942. let useport= " ".g:netrw_scpport." ".g:netrw_port
  7943. else
  7944. let useport= ""
  7945. endif
  7946. let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
  7947. let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
  7948. call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
  7949. if s:NetrwLcd(curdir)
  7950. " call Dret("s:NetrwUpload : lcd failure")
  7951. return
  7952. endif
  7953. elseif a:tgt =~ '^ftp:'
  7954. call s:NetrwMethod(a:tgt)
  7955. if b:netrw_method == 2
  7956. " handle uploading a list of files via ftp+.netrc
  7957. let netrw_fname = b:netrw_fname
  7958. sil NetrwKeepj new
  7959. " call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
  7960. NetrwKeepj put =g:netrw_ftpmode
  7961. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  7962. if exists("g:netrw_ftpextracmd")
  7963. NetrwKeepj put =g:netrw_ftpextracmd
  7964. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  7965. endif
  7966. NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
  7967. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  7968. if tgtdir == ""
  7969. let tgtdir= '/'
  7970. endif
  7971. NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
  7972. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  7973. for fname in a:fname
  7974. NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
  7975. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  7976. endfor
  7977. if exists("g:netrw_port") && g:netrw_port != ""
  7978. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
  7979. else
  7980. " call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
  7981. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
  7982. endif
  7983. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  7984. sil NetrwKeepj g/Local directory now/d
  7985. call histdel("/",-1)
  7986. if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
  7987. call netrw#ErrorMsg(s:ERROR,getline(1),14)
  7988. else
  7989. bw!|q
  7990. endif
  7991. elseif b:netrw_method == 3
  7992. " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
  7993. let netrw_fname= b:netrw_fname
  7994. NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
  7995. let tmpbufnr= bufnr("%")
  7996. setl ff=unix
  7997. if exists("g:netrw_port") && g:netrw_port != ""
  7998. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  7999. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8000. else
  8001. NetrwKeepj put ='open '.g:netrw_machine
  8002. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8003. endif
  8004. if exists("g:netrw_uid") && g:netrw_uid != ""
  8005. if exists("g:netrw_ftp") && g:netrw_ftp == 1
  8006. NetrwKeepj put =g:netrw_uid
  8007. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8008. if exists("s:netrw_passwd")
  8009. NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
  8010. endif
  8011. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8012. elseif exists("s:netrw_passwd")
  8013. NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
  8014. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8015. endif
  8016. endif
  8017. NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
  8018. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8019. if exists("b:netrw_fname") && b:netrw_fname != ""
  8020. NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
  8021. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8022. endif
  8023. if exists("g:netrw_ftpextracmd")
  8024. NetrwKeepj put =g:netrw_ftpextracmd
  8025. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8026. endif
  8027. for fname in a:fname
  8028. NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
  8029. " call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
  8030. endfor
  8031. " perform ftp:
  8032. " -i : turns off interactive prompting from ftp
  8033. " -n unix : DON'T use <.netrc>, even though it exists
  8034. " -n win32: quit being obnoxious about password
  8035. NetrwKeepj norm! 1G"_dd
  8036. call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
  8037. " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
  8038. sil NetrwKeepj g/Local directory now/d
  8039. call histdel("/",-1)
  8040. if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
  8041. let debugkeep= &debug
  8042. setl debug=msg
  8043. call netrw#ErrorMsg(s:ERROR,getline(1),15)
  8044. let &debug = debugkeep
  8045. let mod = 1
  8046. else
  8047. bw!|q
  8048. endif
  8049. elseif !exists("b:netrw_method") || b:netrw_method < 0
  8050. " call Dret("s:#NetrwUpload : unsupported method")
  8051. return
  8052. endif
  8053. else
  8054. call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
  8055. endif
  8056. endif
  8057. " call Dret("s:NetrwUpload")
  8058. endfun
  8059. " ---------------------------------------------------------------------
  8060. " s:NetrwPreview: supports netrw's "p" map {{{2
  8061. fun! s:NetrwPreview(path) range
  8062. " call Dfunc("NetrwPreview(path<".a:path.">)")
  8063. " call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
  8064. " call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
  8065. let ykeep= @@
  8066. NetrwKeepj call s:NetrwOptionsSave("s:")
  8067. if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
  8068. NetrwKeepj call s:NetrwOptionsSafe(1)
  8069. else
  8070. NetrwKeepj call s:NetrwOptionsSafe(0)
  8071. endif
  8072. if has("quickfix")
  8073. " call Decho("has quickfix",'~'.expand("<slnum>"))
  8074. if !isdirectory(s:NetrwFile(a:path))
  8075. " call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
  8076. if g:netrw_preview
  8077. " vertical split
  8078. let pvhkeep = &pvh
  8079. let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
  8080. let &pvh = winwidth(0) - winsz
  8081. " call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
  8082. else
  8083. " horizontal split
  8084. let pvhkeep = &pvh
  8085. let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
  8086. let &pvh = winheight(0) - winsz
  8087. " call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
  8088. endif
  8089. " g:netrw_preview g:netrw_alto
  8090. " 1 : vert 1: top -- preview window is vertically split off and on the left
  8091. " 1 : vert 0: bot -- preview window is vertically split off and on the right
  8092. " 0 : 1: top -- preview window is horizontally split off and on the top
  8093. " 0 : 0: bot -- preview window is horizontally split off and on the bottom
  8094. "
  8095. " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
  8096. " the BufEnter event set up in netrwPlugin.vim
  8097. " call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
  8098. let eikeep = &ei
  8099. set ei=BufEnter
  8100. exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
  8101. let &ei= eikeep
  8102. " call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
  8103. if exists("pvhkeep")
  8104. let &pvh= pvhkeep
  8105. endif
  8106. elseif !exists("g:netrw_quiet")
  8107. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
  8108. endif
  8109. elseif !exists("g:netrw_quiet")
  8110. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
  8111. endif
  8112. NetrwKeepj call s:NetrwOptionsRestore("s:")
  8113. let @@= ykeep
  8114. " call Dret("NetrwPreview")
  8115. endfun
  8116. " ---------------------------------------------------------------------
  8117. " s:NetrwRefresh: {{{2
  8118. fun! s:NetrwRefresh(islocal,dirname)
  8119. " call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
  8120. " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
  8121. setl ma noro
  8122. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  8123. " call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  8124. let ykeep = @@
  8125. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  8126. if !exists("w:netrw_treetop")
  8127. if exists("b:netrw_curdir")
  8128. let w:netrw_treetop= b:netrw_curdir
  8129. else
  8130. let w:netrw_treetop= getcwd()
  8131. endif
  8132. endif
  8133. NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
  8134. endif
  8135. " save the cursor position before refresh.
  8136. let screenposn = winsaveview()
  8137. " call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
  8138. " call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
  8139. " call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
  8140. sil! NetrwKeepj %d _
  8141. if a:islocal
  8142. NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
  8143. else
  8144. NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
  8145. endif
  8146. " restore position
  8147. " call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
  8148. NetrwKeepj call winrestview(screenposn)
  8149. " restore file marks
  8150. if has("syntax") && exists("g:syntax_on") && g:syntax_on
  8151. if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
  8152. " " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
  8153. exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
  8154. else
  8155. " " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
  8156. 2match none
  8157. endif
  8158. endif
  8159. " restore
  8160. let @@= ykeep
  8161. " call Dret("s:NetrwRefresh")
  8162. endfun
  8163. " ---------------------------------------------------------------------
  8164. " s:NetrwRefreshDir: refreshes a directory by name {{{2
  8165. " Called by NetrwMarkFileCopy()
  8166. " Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
  8167. fun! s:NetrwRefreshDir(islocal,dirname)
  8168. " call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
  8169. if g:netrw_fastbrowse == 0
  8170. " slowest mode (keep buffers refreshed, local or remote)
  8171. " call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
  8172. let tgtwin= bufwinnr(a:dirname)
  8173. " call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
  8174. if tgtwin > 0
  8175. " tgtwin is being displayed, so refresh it
  8176. let curwin= winnr()
  8177. " call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
  8178. exe tgtwin."wincmd w"
  8179. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  8180. exe curwin."wincmd w"
  8181. elseif bufnr(a:dirname) > 0
  8182. let bn= bufnr(a:dirname)
  8183. " call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
  8184. exe "sil keepj bd ".bn
  8185. endif
  8186. elseif g:netrw_fastbrowse <= 1
  8187. " call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
  8188. NetrwKeepj call s:LocalBrowseRefresh()
  8189. endif
  8190. " call Dret("s:NetrwRefreshDir")
  8191. endfun
  8192. " ---------------------------------------------------------------------
  8193. " s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
  8194. " window number to do its editing in.
  8195. " Supports [count]C where the count, if present, is used to specify
  8196. " a window to use for editing via the <cr> mapping.
  8197. fun! s:NetrwSetChgwin(...)
  8198. " call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
  8199. if a:0 > 0
  8200. " call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
  8201. if a:1 == "" " :NetrwC win#
  8202. let g:netrw_chgwin= winnr()
  8203. else " :NetrwC
  8204. let g:netrw_chgwin= a:1
  8205. endif
  8206. elseif v:count > 0 " [count]C
  8207. let g:netrw_chgwin= v:count
  8208. else " C
  8209. let g:netrw_chgwin= winnr()
  8210. endif
  8211. echo "editing window now set to window#".g:netrw_chgwin
  8212. " call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
  8213. endfun
  8214. " ---------------------------------------------------------------------
  8215. " s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
  8216. " What this function does is to compute a priority for the patterns
  8217. " in the g:netrw_sort_sequence. It applies a substitute to any
  8218. " "files" that satisfy each pattern, putting the priority / in
  8219. " front. An "*" pattern handles the default priority.
  8220. fun! s:NetrwSetSort()
  8221. " call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
  8222. let ykeep= @@
  8223. if w:netrw_liststyle == s:LONGLIST
  8224. let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
  8225. else
  8226. let seqlist = g:netrw_sort_sequence
  8227. endif
  8228. " sanity check -- insure that * appears somewhere
  8229. if seqlist == ""
  8230. let seqlist= '*'
  8231. elseif seqlist !~ '\*'
  8232. let seqlist= seqlist.',*'
  8233. endif
  8234. let priority = 1
  8235. while seqlist != ""
  8236. if seqlist =~ ','
  8237. let seq = substitute(seqlist,',.*$','','e')
  8238. let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
  8239. else
  8240. let seq = seqlist
  8241. let seqlist = ""
  8242. endif
  8243. if priority < 10
  8244. let spriority= "00".priority.g:netrw_sepchr
  8245. elseif priority < 100
  8246. let spriority= "0".priority.g:netrw_sepchr
  8247. else
  8248. let spriority= priority.g:netrw_sepchr
  8249. endif
  8250. " call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
  8251. " sanity check
  8252. if w:netrw_bannercnt > line("$")
  8253. " apparently no files were left after a Hiding pattern was used
  8254. " call Dret("SetSort : no files left after hiding")
  8255. return
  8256. endif
  8257. if seq == '*'
  8258. let starpriority= spriority
  8259. else
  8260. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
  8261. call histdel("/",-1)
  8262. " sometimes multiple sorting patterns will match the same file or directory.
  8263. " The following substitute is intended to remove the excess matches.
  8264. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
  8265. NetrwKeepj call histdel("/",-1)
  8266. endif
  8267. let priority = priority + 1
  8268. endwhile
  8269. if exists("starpriority")
  8270. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
  8271. NetrwKeepj call histdel("/",-1)
  8272. endif
  8273. " Following line associated with priority -- items that satisfy a priority
  8274. " pattern get prefixed by ###/ which permits easy sorting by priority.
  8275. " Sometimes files can satisfy multiple priority patterns -- only the latest
  8276. " priority pattern needs to be retained. So, at this point, these excess
  8277. " priority prefixes need to be removed, but not directories that happen to
  8278. " be just digits themselves.
  8279. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
  8280. NetrwKeepj call histdel("/",-1)
  8281. let @@= ykeep
  8282. " call Dret("SetSort")
  8283. endfun
  8284. " ---------------------------------------------------------------------
  8285. " s:NetrwSetTgt: sets the target to the specified choice index {{{2
  8286. " Implements [count]Tb (bookhist<b>)
  8287. " [count]Th (bookhist<h>)
  8288. " See :help netrw-qb for how to make the choice.
  8289. fun! s:NetrwSetTgt(islocal,bookhist,choice)
  8290. " call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
  8291. if a:bookhist == 'b'
  8292. " supports choosing a bookmark as a target using a qb-generated list
  8293. let choice= a:choice - 1
  8294. if exists("g:netrw_bookmarklist[".choice."]")
  8295. call netrw#MakeTgt(g:netrw_bookmarklist[choice])
  8296. else
  8297. echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
  8298. endif
  8299. elseif a:bookhist == 'h'
  8300. " supports choosing a history stack entry as a target using a qb-generated list
  8301. let choice= (a:choice % g:netrw_dirhistmax) + 1
  8302. if exists("g:netrw_dirhist_".choice)
  8303. let histentry = g:netrw_dirhist_{choice}
  8304. call netrw#MakeTgt(histentry)
  8305. else
  8306. echomsg "Sorry, history#".a:choice." not available!"
  8307. endif
  8308. endif
  8309. " refresh the display
  8310. if !exists("b:netrw_curdir")
  8311. let b:netrw_curdir= getcwd()
  8312. endif
  8313. call s:NetrwRefresh(a:islocal,b:netrw_curdir)
  8314. " call Dret("s:NetrwSetTgt")
  8315. endfun
  8316. " =====================================================================
  8317. " s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
  8318. fun! s:NetrwSortStyle(islocal)
  8319. " call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
  8320. NetrwKeepj call s:NetrwSaveWordPosn()
  8321. let svpos= winsaveview()
  8322. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  8323. let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
  8324. NetrwKeepj norm! 0
  8325. NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  8326. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  8327. NetrwKeepj call winrestview(svpos)
  8328. " call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
  8329. endfun
  8330. " ---------------------------------------------------------------------
  8331. " s:NetrwSplit: mode {{{2
  8332. " =0 : net and o
  8333. " =1 : net and t
  8334. " =2 : net and v
  8335. " =3 : local and o
  8336. " =4 : local and t
  8337. " =5 : local and v
  8338. fun! s:NetrwSplit(mode)
  8339. " call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
  8340. let ykeep= @@
  8341. call s:SaveWinVars()
  8342. if a:mode == 0
  8343. " remote and o
  8344. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
  8345. if winsz == 0|let winsz= ""|endif
  8346. " call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
  8347. exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
  8348. let s:didsplit= 1
  8349. NetrwKeepj call s:RestoreWinVars()
  8350. NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
  8351. unlet s:didsplit
  8352. elseif a:mode == 1
  8353. " remote and t
  8354. let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
  8355. " call Decho("tabnew",'~'.expand("<slnum>"))
  8356. tabnew
  8357. let s:didsplit= 1
  8358. NetrwKeepj call s:RestoreWinVars()
  8359. NetrwKeepj call s:NetrwBrowse(0,newdir)
  8360. unlet s:didsplit
  8361. elseif a:mode == 2
  8362. " remote and v
  8363. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
  8364. if winsz == 0|let winsz= ""|endif
  8365. " call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
  8366. exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
  8367. let s:didsplit= 1
  8368. NetrwKeepj call s:RestoreWinVars()
  8369. NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
  8370. unlet s:didsplit
  8371. elseif a:mode == 3
  8372. " local and o
  8373. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
  8374. if winsz == 0|let winsz= ""|endif
  8375. " call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
  8376. exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
  8377. let s:didsplit= 1
  8378. NetrwKeepj call s:RestoreWinVars()
  8379. NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
  8380. unlet s:didsplit
  8381. elseif a:mode == 4
  8382. " local and t
  8383. let cursorword = s:NetrwGetWord()
  8384. let eikeep = &ei
  8385. let netrw_winnr = winnr()
  8386. let netrw_line = line(".")
  8387. let netrw_col = virtcol(".")
  8388. NetrwKeepj norm! H0
  8389. let netrw_hline = line(".")
  8390. setl ei=all
  8391. exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
  8392. exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
  8393. let &ei = eikeep
  8394. let netrw_curdir = s:NetrwTreeDir(0)
  8395. " call Decho("tabnew",'~'.expand("<slnum>"))
  8396. tabnew
  8397. let b:netrw_curdir = netrw_curdir
  8398. let s:didsplit = 1
  8399. NetrwKeepj call s:RestoreWinVars()
  8400. NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
  8401. if &ft == "netrw"
  8402. setl ei=all
  8403. exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
  8404. exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
  8405. let &ei= eikeep
  8406. endif
  8407. unlet s:didsplit
  8408. elseif a:mode == 5
  8409. " local and v
  8410. let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
  8411. if winsz == 0|let winsz= ""|endif
  8412. " call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
  8413. exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
  8414. let s:didsplit= 1
  8415. NetrwKeepj call s:RestoreWinVars()
  8416. NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
  8417. unlet s:didsplit
  8418. else
  8419. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
  8420. endif
  8421. let @@= ykeep
  8422. " call Dret("s:NetrwSplit")
  8423. endfun
  8424. " ---------------------------------------------------------------------
  8425. " s:NetrwTgtMenu: {{{2
  8426. fun! s:NetrwTgtMenu()
  8427. if !exists("s:netrw_menucnt")
  8428. return
  8429. endif
  8430. " call Dfunc("s:NetrwTgtMenu()")
  8431. " the following test assures that gvim is running, has menus available, and has menus enabled.
  8432. if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
  8433. if exists("g:NetrwTopLvlMenu")
  8434. " call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
  8435. exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
  8436. endif
  8437. if !exists("s:netrw_initbookhist")
  8438. call s:NetrwBookHistRead()
  8439. endif
  8440. " try to cull duplicate entries
  8441. let tgtdict={}
  8442. " target bookmarked places
  8443. if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
  8444. " call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
  8445. let cnt= 1
  8446. for bmd in g:netrw_bookmarklist
  8447. if has_key(tgtdict,bmd)
  8448. let cnt= cnt + 1
  8449. continue
  8450. endif
  8451. let tgtdict[bmd]= cnt
  8452. let ebmd= escape(bmd,g:netrw_menu_escape)
  8453. " show bookmarks for goto menu
  8454. " call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
  8455. exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
  8456. let cnt= cnt + 1
  8457. endfor
  8458. endif
  8459. " target directory browsing history
  8460. if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
  8461. " call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
  8462. let histcnt = 1
  8463. while histcnt <= g:netrw_dirhistmax
  8464. let priority = g:netrw_dirhistcnt + histcnt
  8465. if exists("g:netrw_dirhist_{histcnt}")
  8466. let histentry = g:netrw_dirhist_{histcnt}
  8467. if has_key(tgtdict,histentry)
  8468. let histcnt = histcnt + 1
  8469. continue
  8470. endif
  8471. let tgtdict[histentry] = histcnt
  8472. let ehistentry = escape(histentry,g:netrw_menu_escape)
  8473. " call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
  8474. exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
  8475. endif
  8476. let histcnt = histcnt + 1
  8477. endwhile
  8478. endif
  8479. endif
  8480. " call Dret("s:NetrwTgtMenu")
  8481. endfun
  8482. " ---------------------------------------------------------------------
  8483. " s:NetrwTreeDir: determine tree directory given current cursor position {{{2
  8484. " (full path directory with trailing slash returned)
  8485. fun! s:NetrwTreeDir(islocal)
  8486. " call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
  8487. " call Decho("Determine tree directory given current cursor position")
  8488. " call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
  8489. " call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
  8490. " call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
  8491. " call Decho("current line<".getline(".").">")
  8492. if exists("s:treedir") && exists("s:prevwinopen")
  8493. " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
  8494. " call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
  8495. let treedir= s:treedir
  8496. unlet s:treedir
  8497. unlet s:prevwinopen
  8498. " call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
  8499. return treedir
  8500. endif
  8501. if exists("s:prevwinopen")
  8502. unlet s:prevwinopen
  8503. endif
  8504. if !exists("b:netrw_curdir") || b:netrw_curdir == ""
  8505. let b:netrw_curdir= getcwd()
  8506. endif
  8507. let treedir = b:netrw_curdir
  8508. " call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
  8509. let s:treecurpos= winsaveview()
  8510. " call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
  8511. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  8512. " call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
  8513. " call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
  8514. " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
  8515. let curline= substitute(getline('.'),"\t -->.*$",'','')
  8516. if curline =~ '/$'
  8517. " call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
  8518. let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
  8519. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  8520. elseif curline =~ '@$'
  8521. " call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
  8522. let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
  8523. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  8524. else
  8525. " call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
  8526. let treedir= ""
  8527. endif
  8528. " detect user attempting to close treeroot
  8529. " call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
  8530. " call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
  8531. " call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
  8532. if curline !~ '^'.s:treedepthstring && getline('.') != '..'
  8533. " call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
  8534. " now force a refresh
  8535. " call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  8536. sil! NetrwKeepj %d _
  8537. " call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
  8538. return b:netrw_curdir
  8539. " else " Decho
  8540. " call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
  8541. endif
  8542. " call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
  8543. let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
  8544. " call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
  8545. " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
  8546. " if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
  8547. " let newdir = w:netrw_treetop.'/'.potentialdir
  8548. " " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
  8549. " let treedir = s:NetrwTreePath(newdir)
  8550. " let w:netrw_treetop = newdir
  8551. " " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
  8552. " else
  8553. " call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
  8554. let treedir = s:NetrwTreePath(w:netrw_treetop)
  8555. " endif
  8556. endif
  8557. " sanity maintenance: keep those //s away...
  8558. let treedir= substitute(treedir,'//$','/','')
  8559. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  8560. " call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
  8561. return treedir
  8562. endfun
  8563. " ---------------------------------------------------------------------
  8564. " s:NetrwTreeDisplay: recursive tree display {{{2
  8565. fun! s:NetrwTreeDisplay(dir,depth)
  8566. " call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
  8567. " insure that there are no folds
  8568. setl nofen
  8569. " install ../ and shortdir
  8570. if a:depth == ""
  8571. call setline(line("$")+1,'../')
  8572. " call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
  8573. endif
  8574. if a:dir =~ '^\a\{3,}://'
  8575. if a:dir == w:netrw_treetop
  8576. let shortdir= a:dir
  8577. else
  8578. let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
  8579. endif
  8580. call setline(line("$")+1,a:depth.shortdir)
  8581. else
  8582. let shortdir= substitute(a:dir,'^.*/','','e')
  8583. call setline(line("$")+1,a:depth.shortdir.'/')
  8584. endif
  8585. " call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
  8586. " append a / to dir if its missing one
  8587. let dir= a:dir
  8588. " display subtrees (if any)
  8589. let depth= s:treedepthstring.a:depth
  8590. " call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
  8591. " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
  8592. if g:netrw_hide == 1
  8593. " hide given patterns
  8594. let listhide= split(g:netrw_list_hide,',')
  8595. " call Decho("listhide=".string(listhide))
  8596. for pat in listhide
  8597. call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
  8598. endfor
  8599. elseif g:netrw_hide == 2
  8600. " show given patterns (only)
  8601. let listhide= split(g:netrw_list_hide,',')
  8602. " call Decho("listhide=".string(listhide))
  8603. let entries=[]
  8604. for entry in w:netrw_treedict[dir]
  8605. for pat in listhide
  8606. if entry =~ pat
  8607. call add(entries,entry)
  8608. break
  8609. endif
  8610. endfor
  8611. endfor
  8612. let w:netrw_treedict[dir]= entries
  8613. endif
  8614. if depth != ""
  8615. " always remove "." and ".." entries when there's depth
  8616. call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
  8617. call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
  8618. endif
  8619. " call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
  8620. for entry in w:netrw_treedict[dir]
  8621. if dir =~ '/$'
  8622. let direntry= substitute(dir.entry,'[@/]$','','e')
  8623. else
  8624. let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
  8625. endif
  8626. " call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
  8627. if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
  8628. " call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
  8629. NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
  8630. elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
  8631. " call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
  8632. NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
  8633. elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
  8634. " call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
  8635. NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
  8636. else
  8637. " call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
  8638. sil! NetrwKeepj call setline(line("$")+1,depth.entry)
  8639. endif
  8640. endfor
  8641. " call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
  8642. " call Dret("NetrwTreeDisplay")
  8643. endfun
  8644. " ---------------------------------------------------------------------
  8645. " s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
  8646. fun! s:NetrwRefreshTreeDict(dir)
  8647. " call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
  8648. if !exists("w:netrw_treedict")
  8649. " call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
  8650. return
  8651. endif
  8652. for entry in w:netrw_treedict[a:dir]
  8653. let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
  8654. " call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
  8655. if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
  8656. " call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
  8657. NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
  8658. let liststar = s:NetrwGlob(direntry,'*',1)
  8659. let listdotstar = s:NetrwGlob(direntry,'.*',1)
  8660. let w:netrw_treedict[direntry] = liststar + listdotstar
  8661. " call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
  8662. elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
  8663. " call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
  8664. NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
  8665. let liststar = s:NetrwGlob(direntry.'/','*',1)
  8666. let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
  8667. let w:netrw_treedict[direntry]= liststar + listdotstar
  8668. " call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
  8669. elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
  8670. " call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
  8671. NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
  8672. let liststar = s:NetrwGlob(direntry.'/','*',1)
  8673. let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
  8674. " call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
  8675. else
  8676. " call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
  8677. endif
  8678. endfor
  8679. " call Dret("s:NetrwRefreshTreeDict")
  8680. endfun
  8681. " ---------------------------------------------------------------------
  8682. " s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
  8683. " Called by s:PerformListing()
  8684. fun! s:NetrwTreeListing(dirname)
  8685. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  8686. " call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
  8687. " call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
  8688. " call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
  8689. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  8690. " update the treetop
  8691. if !exists("w:netrw_treetop")
  8692. " call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
  8693. let w:netrw_treetop= a:dirname
  8694. let s:netrw_treetop= w:netrw_treetop
  8695. " call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
  8696. elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
  8697. " call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
  8698. let w:netrw_treetop= a:dirname
  8699. let s:netrw_treetop= w:netrw_treetop
  8700. " call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
  8701. endif
  8702. if exists("w:netrw_treetop")
  8703. let s:netrw_treetop= w:netrw_treetop
  8704. else
  8705. let w:netrw_treetop= getcwd()
  8706. let s:netrw_treetop= w:netrw_treetop
  8707. endif
  8708. if !exists("w:netrw_treedict")
  8709. " insure that we have a treedict, albeit empty
  8710. " call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
  8711. let w:netrw_treedict= {}
  8712. endif
  8713. " update the dictionary for the current directory
  8714. " call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
  8715. " call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
  8716. exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
  8717. let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
  8718. " call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
  8719. exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
  8720. " if past banner, record word
  8721. if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
  8722. let fname= expand("<cword>")
  8723. else
  8724. let fname= ""
  8725. endif
  8726. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  8727. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  8728. " display from treetop on down
  8729. " call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
  8730. NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
  8731. " call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
  8732. " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
  8733. while getline(1) =~ '^\s*$' && byte2line(1) > 0
  8734. " call Decho("deleting blank line",'~'.expand("<slnum>"))
  8735. 1d
  8736. endwhile
  8737. exe "setl ".g:netrw_bufsettings
  8738. " call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
  8739. return
  8740. endif
  8741. endfun
  8742. " ---------------------------------------------------------------------
  8743. " s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
  8744. " Normally, treetop is w:netrw_treetop, but a
  8745. " user of the function ( netrw#SetTreetop() )
  8746. " wipes that out prior to calling this function
  8747. fun! s:NetrwTreePath(treetop)
  8748. " call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
  8749. if line(".") < w:netrw_bannercnt + 2
  8750. let treedir= a:treetop
  8751. if treedir !~ '/$'
  8752. let treedir= treedir.'/'
  8753. endif
  8754. " call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
  8755. return treedir
  8756. endif
  8757. let svpos = winsaveview()
  8758. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  8759. let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
  8760. " call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
  8761. let depth = substitute(depth,'^'.s:treedepthstring,'','')
  8762. " call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
  8763. let curline= getline('.')
  8764. " call Decho("curline<".curline.'>','~'.expand("<slnum>"))
  8765. if curline =~ '/$'
  8766. " call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
  8767. let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
  8768. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  8769. elseif curline =~ '@\s\+-->'
  8770. " call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
  8771. let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
  8772. let treedir= substitute(treedir,'@\s\+-->.*$','','e')
  8773. " call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
  8774. else
  8775. " call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
  8776. let treedir= ""
  8777. endif
  8778. " construct treedir by searching backwards at correct depth
  8779. " call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
  8780. " call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
  8781. while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
  8782. let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
  8783. let treedir= dirname.treedir
  8784. let depth = substitute(depth,'^'.s:treedepthstring,'','')
  8785. " call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
  8786. endwhile
  8787. " call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
  8788. if a:treetop =~ '/$'
  8789. let treedir= a:treetop.treedir
  8790. else
  8791. let treedir= a:treetop.'/'.treedir
  8792. endif
  8793. " call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
  8794. let treedir= substitute(treedir,'//$','/','')
  8795. " call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
  8796. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
  8797. call winrestview(svpos)
  8798. " call Dret("s:NetrwTreePath <".treedir.">")
  8799. return treedir
  8800. endfun
  8801. " ---------------------------------------------------------------------
  8802. " s:NetrwWideListing: {{{2
  8803. fun! s:NetrwWideListing()
  8804. if w:netrw_liststyle == s:WIDELIST
  8805. " call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
  8806. " look for longest filename (cpf=characters per filename)
  8807. " cpf: characters per filename
  8808. " fpl: filenames per line
  8809. " fpc: filenames per column
  8810. setl ma noro
  8811. let keepa= @a
  8812. " call Decho("setl ma noro",'~'.expand("<slnum>"))
  8813. let b:netrw_cpf= 0
  8814. if line("$") >= w:netrw_bannercnt
  8815. " determine the maximum filename size; use that to set cpf
  8816. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
  8817. NetrwKeepj call histdel("/",-1)
  8818. else
  8819. let @a= keepa
  8820. " call Dret("NetrwWideListing")
  8821. return
  8822. endif
  8823. " allow for two spaces to separate columns
  8824. let b:netrw_cpf= b:netrw_cpf + 2
  8825. " call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
  8826. " determine qty files per line (fpl)
  8827. let w:netrw_fpl= winwidth(0)/b:netrw_cpf
  8828. if w:netrw_fpl <= 0
  8829. let w:netrw_fpl= 1
  8830. endif
  8831. " call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
  8832. " make wide display
  8833. " fpc: files per column of wide listing
  8834. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
  8835. NetrwKeepj call histdel("/",-1)
  8836. let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
  8837. let newcolstart = w:netrw_bannercnt + fpc
  8838. let newcolend = newcolstart + fpc - 1
  8839. " call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
  8840. while line("$") >= newcolstart
  8841. if newcolend > line("$") | let newcolend= line("$") | endif
  8842. let newcolqty= newcolend - newcolstart
  8843. exe newcolstart
  8844. " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
  8845. if newcolqty == 0
  8846. exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
  8847. else
  8848. exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
  8849. endif
  8850. exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
  8851. exe 'sil! NetrwKeepj '.w:netrw_bannercnt
  8852. endwhile
  8853. exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
  8854. NetrwKeepj call histdel("/",-1)
  8855. exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
  8856. exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
  8857. " call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
  8858. exe "setl ".g:netrw_bufsettings
  8859. let @a= keepa
  8860. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  8861. " call Dret("NetrwWideListing")
  8862. return
  8863. else
  8864. if hasmapto("w","n")
  8865. sil! nunmap <buffer> w
  8866. endif
  8867. if hasmapto("b","n")
  8868. sil! nunmap <buffer> b
  8869. endif
  8870. endif
  8871. endfun
  8872. " ---------------------------------------------------------------------
  8873. " s:PerformListing: {{{2
  8874. fun! s:PerformListing(islocal)
  8875. " call Dfunc("s:PerformListing(islocal=".a:islocal.")")
  8876. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
  8877. " call Decho("settings: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)"." ei<".&ei.">",'~'.expand("<slnum>"))
  8878. sil! NetrwKeepj %d _
  8879. " call DechoBuf(bufnr("%"))
  8880. " set up syntax highlighting {{{3
  8881. " call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
  8882. sil! setl ft=netrw
  8883. NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
  8884. setl noro ma
  8885. " call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
  8886. " if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
  8887. " call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
  8888. " endif " Decho
  8889. " call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
  8890. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
  8891. " force a refresh for tree listings
  8892. " call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
  8893. sil! NetrwKeepj %d _
  8894. endif
  8895. " save current directory on directory history list
  8896. NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
  8897. " Set up the banner {{{3
  8898. if g:netrw_banner
  8899. " call Decho("--set up banner",'~'.expand("<slnum>"))
  8900. NetrwKeepj call setline(1,'" ============================================================================')
  8901. if exists("g:netrw_pchk")
  8902. " this undocumented option allows pchk to run with different versions of netrw without causing spurious
  8903. " failure detections.
  8904. NetrwKeepj call setline(2,'" Netrw Directory Listing')
  8905. else
  8906. NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
  8907. endif
  8908. if exists("g:netrw_pchk")
  8909. let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
  8910. else
  8911. let curdir= b:netrw_curdir
  8912. endif
  8913. if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
  8914. NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
  8915. else
  8916. NetrwKeepj call setline(3,'" '.curdir)
  8917. endif
  8918. let w:netrw_bannercnt= 3
  8919. NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
  8920. else
  8921. " call Decho("--no banner",'~'.expand("<slnum>"))
  8922. NetrwKeepj 1
  8923. let w:netrw_bannercnt= 1
  8924. endif
  8925. " call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
  8926. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
  8927. " construct sortby string: [name|time|size|exten] [reversed]
  8928. let sortby= g:netrw_sort_by
  8929. if g:netrw_sort_direction =~# "^r"
  8930. let sortby= sortby." reversed"
  8931. endif
  8932. " Sorted by... {{{3
  8933. if g:netrw_banner
  8934. " call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
  8935. if g:netrw_sort_by =~# "^n"
  8936. " call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
  8937. " sorted by name (also includes the sorting sequence in the banner)
  8938. NetrwKeepj put ='\" Sorted by '.sortby
  8939. NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
  8940. let w:netrw_bannercnt= w:netrw_bannercnt + 2
  8941. else
  8942. " call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
  8943. " sorted by time, size, exten
  8944. NetrwKeepj put ='\" Sorted by '.sortby
  8945. let w:netrw_bannercnt= w:netrw_bannercnt + 1
  8946. endif
  8947. exe "sil! NetrwKeepj ".w:netrw_bannercnt
  8948. " else " Decho
  8949. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  8950. endif
  8951. " show copy/move target, if any {{{3
  8952. if g:netrw_banner
  8953. if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
  8954. " call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
  8955. NetrwKeepj put =''
  8956. if s:netrwmftgt_islocal
  8957. sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
  8958. else
  8959. sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
  8960. endif
  8961. let w:netrw_bannercnt= w:netrw_bannercnt + 1
  8962. else
  8963. " call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
  8964. endif
  8965. exe "sil! NetrwKeepj ".w:netrw_bannercnt
  8966. endif
  8967. " Hiding... -or- Showing... {{{3
  8968. if g:netrw_banner
  8969. " call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
  8970. if g:netrw_list_hide != "" && g:netrw_hide
  8971. if g:netrw_hide == 1
  8972. NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
  8973. else
  8974. NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
  8975. endif
  8976. let w:netrw_bannercnt= w:netrw_bannercnt + 1
  8977. endif
  8978. exe "NetrwKeepj ".w:netrw_bannercnt
  8979. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  8980. let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
  8981. " call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
  8982. NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
  8983. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  8984. NetrwKeepj put ='\" =============================================================================='
  8985. let w:netrw_bannercnt= w:netrw_bannercnt + 2
  8986. " else " Decho
  8987. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  8988. endif
  8989. " bannercnt should index the line just after the banner
  8990. if g:netrw_banner
  8991. let w:netrw_bannercnt= w:netrw_bannercnt + 1
  8992. exe "sil! NetrwKeepj ".w:netrw_bannercnt
  8993. " call Decho("--w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"),'~'.expand("<slnum>"))
  8994. " else " Decho
  8995. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  8996. endif
  8997. " get list of files
  8998. " call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
  8999. if a:islocal
  9000. NetrwKeepj call s:LocalListing()
  9001. else " remote
  9002. NetrwKeepj let badresult= s:NetrwRemoteListing()
  9003. if badresult
  9004. " call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
  9005. " call Dret("s:PerformListing : error detected by NetrwRemoteListing")
  9006. return
  9007. endif
  9008. endif
  9009. " manipulate the directory listing (hide, sort) {{{3
  9010. if !exists("w:netrw_bannercnt")
  9011. let w:netrw_bannercnt= 0
  9012. endif
  9013. " call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
  9014. " call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
  9015. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  9016. if !g:netrw_banner || line("$") >= w:netrw_bannercnt
  9017. " call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
  9018. " call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
  9019. if g:netrw_hide && g:netrw_list_hide != ""
  9020. NetrwKeepj call s:NetrwListHide()
  9021. endif
  9022. if !g:netrw_banner || line("$") >= w:netrw_bannercnt
  9023. " call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
  9024. if g:netrw_sort_by =~# "^n"
  9025. " sort by name
  9026. " call Decho("sort by name",'~'.expand("<slnum>"))
  9027. NetrwKeepj call s:NetrwSetSort()
  9028. if !g:netrw_banner || w:netrw_bannercnt < line("$")
  9029. " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  9030. if g:netrw_sort_direction =~# 'n'
  9031. " name: sort by name of file
  9032. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
  9033. else
  9034. " reverse direction sorting
  9035. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
  9036. endif
  9037. endif
  9038. " remove priority pattern prefix
  9039. " call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
  9040. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
  9041. NetrwKeepj call histdel("/",-1)
  9042. elseif g:netrw_sort_by =~# "^ext"
  9043. " exten: sort by extension
  9044. " The histdel(...,-1) calls remove the last search from the search history
  9045. " call Decho("sort by extension",'~'.expand("<slnum>"))
  9046. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
  9047. NetrwKeepj call histdel("/",-1)
  9048. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
  9049. NetrwKeepj call histdel("/",-1)
  9050. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
  9051. NetrwKeepj call histdel("/",-1)
  9052. if !g:netrw_banner || w:netrw_bannercnt < line("$")
  9053. " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  9054. if g:netrw_sort_direction =~# 'n'
  9055. " normal direction sorting
  9056. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
  9057. else
  9058. " reverse direction sorting
  9059. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
  9060. endif
  9061. endif
  9062. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
  9063. NetrwKeepj call histdel("/",-1)
  9064. elseif a:islocal
  9065. if !g:netrw_banner || w:netrw_bannercnt < line("$")
  9066. " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
  9067. if g:netrw_sort_direction =~# 'n'
  9068. " call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
  9069. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
  9070. else
  9071. " call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
  9072. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
  9073. endif
  9074. " call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
  9075. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
  9076. NetrwKeepj call histdel("/",-1)
  9077. endif
  9078. endif
  9079. elseif g:netrw_sort_direction =~# 'r'
  9080. " call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
  9081. if !g:netrw_banner || w:netrw_bannercnt < line('$')
  9082. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
  9083. call histdel("/",-1)
  9084. endif
  9085. endif
  9086. endif
  9087. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  9088. " convert to wide/tree listing {{{3
  9089. " call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
  9090. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#1)",'~'.expand("<slnum>"))
  9091. NetrwKeepj call s:NetrwWideListing()
  9092. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)",'~'.expand("<slnum>"))
  9093. NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
  9094. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
  9095. " resolve symbolic links if local and (thin or tree)
  9096. if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
  9097. " call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
  9098. sil! g/@$/call s:ShowLink()
  9099. endif
  9100. if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
  9101. " place cursor on the top-left corner of the file listing
  9102. " call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
  9103. exe 'sil! '.w:netrw_bannercnt
  9104. sil! NetrwKeepj norm! 0
  9105. " call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
  9106. else
  9107. " call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
  9108. " call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
  9109. " call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
  9110. " call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
  9111. endif
  9112. " record previous current directory
  9113. let w:netrw_prvdir= b:netrw_curdir
  9114. " call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
  9115. " save certain window-oriented variables into buffer-oriented variables {{{3
  9116. " call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
  9117. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#4)",'~'.expand("<slnum>"))
  9118. NetrwKeepj call s:SetBufWinVars()
  9119. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
  9120. NetrwKeepj call s:NetrwOptionsRestore("w:")
  9121. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
  9122. " set display to netrw display settings
  9123. " call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
  9124. exe "setl ".g:netrw_bufsettings
  9125. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
  9126. if g:netrw_liststyle == s:LONGLIST
  9127. " call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
  9128. exe "setl ts=".(g:netrw_maxfilenamelen+1)
  9129. endif
  9130. " call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
  9131. " call DechoBuf(bufnr("%"))
  9132. if exists("s:treecurpos")
  9133. " call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
  9134. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#8)",'~'.expand("<slnum>"))
  9135. " call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
  9136. NetrwKeepj call winrestview(s:treecurpos)
  9137. unlet s:treecurpos
  9138. endif
  9139. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)",'~'.expand("<slnum>"))
  9140. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
  9141. " call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
  9142. endfun
  9143. " ---------------------------------------------------------------------
  9144. " s:SetupNetrwStatusLine: {{{2
  9145. fun! s:SetupNetrwStatusLine(statline)
  9146. " call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
  9147. if !exists("s:netrw_setup_statline")
  9148. let s:netrw_setup_statline= 1
  9149. " call Decho("do first-time status line setup",'~'.expand("<slnum>"))
  9150. if !exists("s:netrw_users_stl")
  9151. let s:netrw_users_stl= &stl
  9152. endif
  9153. if !exists("s:netrw_users_ls")
  9154. let s:netrw_users_ls= &laststatus
  9155. endif
  9156. " set up User9 highlighting as needed
  9157. let keepa= @a
  9158. redir @a
  9159. try
  9160. hi User9
  9161. catch /^Vim\%((\a\{3,})\)\=:E411/
  9162. if &bg == "dark"
  9163. hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
  9164. else
  9165. hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
  9166. endif
  9167. endtry
  9168. redir END
  9169. let @a= keepa
  9170. endif
  9171. " set up status line (may use User9 highlighting)
  9172. " insure that windows have a statusline
  9173. " make sure statusline is displayed
  9174. let &stl=a:statline
  9175. setl laststatus=2
  9176. " call Decho("stl=".&stl,'~'.expand("<slnum>"))
  9177. redraw
  9178. " call Dret("SetupNetrwStatusLine : stl=".&stl)
  9179. endfun
  9180. " =========================================
  9181. " Remote Directory Browsing Support: {{{1
  9182. " =========================================
  9183. " ---------------------------------------------------------------------
  9184. " s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
  9185. " This function assumes that a long listing will be received. Size, time,
  9186. " and reverse sorts will be requested of the server but not otherwise
  9187. " enforced here.
  9188. fun! s:NetrwRemoteFtpCmd(path,listcmd)
  9189. " call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) w:netrw_method=".(exists("w:netrw_method")? w:netrw_method : (exists("b:netrw_method")? b:netrw_method : "???")))
  9190. " call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
  9191. " sanity check: {{{3
  9192. if !exists("w:netrw_method")
  9193. if exists("b:netrw_method")
  9194. let w:netrw_method= b:netrw_method
  9195. else
  9196. call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
  9197. " call Dret("NetrwRemoteFtpCmd")
  9198. return
  9199. endif
  9200. endif
  9201. " WinXX ftp uses unix style input, so set ff to unix " {{{3
  9202. let ffkeep= &ff
  9203. setl ma ff=unix noro
  9204. " call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
  9205. " clear off any older non-banner lines " {{{3
  9206. " note that w:netrw_bannercnt indexes the line after the banner
  9207. " call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
  9208. exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
  9209. ".........................................
  9210. if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
  9211. " ftp + <.netrc>: Method #2
  9212. if a:path != ""
  9213. NetrwKeepj put ='cd \"'.a:path.'\"'
  9214. endif
  9215. if exists("g:netrw_ftpextracmd")
  9216. NetrwKeepj put =g:netrw_ftpextracmd
  9217. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  9218. endif
  9219. NetrwKeepj call setline(line("$")+1,a:listcmd)
  9220. " exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
  9221. if exists("g:netrw_port") && g:netrw_port != ""
  9222. " call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
  9223. exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1)
  9224. else
  9225. " call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
  9226. exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)
  9227. endif
  9228. ".........................................
  9229. elseif w:netrw_method == 3 " {{{3
  9230. " ftp + machine,id,passwd,filename: Method #3
  9231. setl ff=unix
  9232. if exists("g:netrw_port") && g:netrw_port != ""
  9233. NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
  9234. else
  9235. NetrwKeepj put ='open '.g:netrw_machine
  9236. endif
  9237. " handle userid and password
  9238. let host= substitute(g:netrw_machine,'\..*$','','')
  9239. " call Decho("host<".host.">",'~'.expand("<slnum>"))
  9240. if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
  9241. call NetUserPass("ftp:".host)
  9242. endif
  9243. if exists("g:netrw_uid") && g:netrw_uid != ""
  9244. if exists("g:netrw_ftp") && g:netrw_ftp == 1
  9245. NetrwKeepj put =g:netrw_uid
  9246. if exists("s:netrw_passwd") && s:netrw_passwd != ""
  9247. NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
  9248. endif
  9249. elseif exists("s:netrw_passwd")
  9250. NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
  9251. endif
  9252. endif
  9253. if a:path != ""
  9254. NetrwKeepj put ='cd \"'.a:path.'\"'
  9255. endif
  9256. if exists("g:netrw_ftpextracmd")
  9257. NetrwKeepj put =g:netrw_ftpextracmd
  9258. " call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
  9259. endif
  9260. NetrwKeepj call setline(line("$")+1,a:listcmd)
  9261. " perform ftp:
  9262. " -i : turns off interactive prompting from ftp
  9263. " -n unix : DON'T use <.netrc>, even though it exists
  9264. " -n win32: quit being obnoxious about password
  9265. if exists("w:netrw_bannercnt")
  9266. " exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
  9267. call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
  9268. " else " Decho
  9269. " call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
  9270. " g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
  9271. endif
  9272. ".........................................
  9273. elseif w:netrw_method == 9 " {{{3
  9274. " sftp username@machine: Method #9
  9275. " s:netrw_sftp_cmd
  9276. setl ff=unix
  9277. " restore settings
  9278. let &ff= ffkeep
  9279. " call Dret("NetrwRemoteFtpCmd")
  9280. return
  9281. ".........................................
  9282. else " {{{3
  9283. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
  9284. endif
  9285. " cleanup for Windows " {{{3
  9286. if has("win32") || has("win95") || has("win64") || has("win16")
  9287. sil! NetrwKeepj %s/\r$//e
  9288. NetrwKeepj call histdel("/",-1)
  9289. endif
  9290. if a:listcmd == "dir"
  9291. " infer directory/link based on the file permission string
  9292. sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
  9293. sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
  9294. NetrwKeepj call histdel("/",-1)
  9295. NetrwKeepj call histdel("/",-1)
  9296. if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
  9297. exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
  9298. NetrwKeepj call histdel("/",-1)
  9299. endif
  9300. endif
  9301. " ftp's listing doesn't seem to include ./ or ../ " {{{3
  9302. if !search('^\.\/$\|\s\.\/$','wn')
  9303. exe 'NetrwKeepj '.w:netrw_bannercnt
  9304. NetrwKeepj put ='./'
  9305. endif
  9306. if !search('^\.\.\/$\|\s\.\.\/$','wn')
  9307. exe 'NetrwKeepj '.w:netrw_bannercnt
  9308. NetrwKeepj put ='../'
  9309. endif
  9310. " restore settings " {{{3
  9311. let &ff= ffkeep
  9312. " call Dret("NetrwRemoteFtpCmd")
  9313. endfun
  9314. " ---------------------------------------------------------------------
  9315. " s:NetrwRemoteListing: {{{2
  9316. fun! s:NetrwRemoteListing()
  9317. " call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
  9318. if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
  9319. let w:netrw_bannercnt= s:bannercnt
  9320. endif
  9321. if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
  9322. let w:netrw_bannercnt= s:bannercnt
  9323. endif
  9324. call s:RemotePathAnalysis(b:netrw_curdir)
  9325. " sanity check:
  9326. if exists("b:netrw_method") && b:netrw_method =~ '[235]'
  9327. " call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
  9328. if !executable("ftp")
  9329. " call Decho("ftp is not executable",'~'.expand("<slnum>"))
  9330. if !exists("g:netrw_quiet")
  9331. call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
  9332. endif
  9333. call s:NetrwOptionsRestore("w:")
  9334. " call Dret("s:NetrwRemoteListing -1")
  9335. return -1
  9336. endif
  9337. elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
  9338. " call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
  9339. if !exists("g:netrw_quiet")
  9340. if g:netrw_list_cmd == ""
  9341. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your g:netrw_list_cmd is empty; perhaps ".g:netrw_ssh_cmd." is not executable on your system",47)
  9342. else
  9343. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
  9344. endif
  9345. endif
  9346. NetrwKeepj call s:NetrwOptionsRestore("w:")
  9347. " call Dret("s:NetrwRemoteListing -1")
  9348. return -1
  9349. endif " (remote handling sanity check)
  9350. " call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
  9351. if exists("b:netrw_method")
  9352. " call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
  9353. let w:netrw_method= b:netrw_method
  9354. endif
  9355. if s:method == "ftp"
  9356. " use ftp to get remote file listing {{{3
  9357. " call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
  9358. let s:method = "ftp"
  9359. let listcmd = g:netrw_ftp_list_cmd
  9360. if g:netrw_sort_by =~# '^t'
  9361. let listcmd= g:netrw_ftp_timelist_cmd
  9362. elseif g:netrw_sort_by =~# '^s'
  9363. let listcmd= g:netrw_ftp_sizelist_cmd
  9364. endif
  9365. " call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
  9366. call s:NetrwRemoteFtpCmd(s:path,listcmd)
  9367. " exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
  9368. " report on missing file or directory messages
  9369. if search('[Nn]o such file or directory\|Failed to change directory')
  9370. let mesg= getline(".")
  9371. if exists("w:netrw_bannercnt")
  9372. setl ma
  9373. exe w:netrw_bannercnt.",$d _"
  9374. setl noma
  9375. endif
  9376. NetrwKeepj call s:NetrwOptionsRestore("w:")
  9377. call netrw#ErrorMsg(s:WARNING,mesg,96)
  9378. " call Dret("s:NetrwRemoteListing : -1")
  9379. return -1
  9380. endif
  9381. if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
  9382. " shorten the listing
  9383. " call Decho("generate short listing",'~'.expand("<slnum>"))
  9384. exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
  9385. " cleanup
  9386. if g:netrw_ftp_browse_reject != ""
  9387. exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
  9388. NetrwKeepj call histdel("/",-1)
  9389. endif
  9390. sil! NetrwKeepj %s/\r$//e
  9391. NetrwKeepj call histdel("/",-1)
  9392. " if there's no ../ listed, then put ../ in
  9393. let line1= line(".")
  9394. exe "sil! NetrwKeepj ".w:netrw_bannercnt
  9395. let line2= search('\.\.\/\%(\s\|$\)','cnW')
  9396. " call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
  9397. if line2 == 0
  9398. " call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
  9399. sil! NetrwKeepj put='../'
  9400. endif
  9401. exe "sil! NetrwKeepj ".line1
  9402. sil! NetrwKeepj norm! 0
  9403. " call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
  9404. if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
  9405. " call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
  9406. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
  9407. NetrwKeepj call histdel("/",-1)
  9408. else " normal ftp cleanup
  9409. " call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
  9410. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
  9411. exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
  9412. exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
  9413. NetrwKeepj call histdel("/",-1)
  9414. NetrwKeepj call histdel("/",-1)
  9415. NetrwKeepj call histdel("/",-1)
  9416. endif
  9417. endif
  9418. else
  9419. " use ssh to get remote file listing {{{3
  9420. " call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
  9421. let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
  9422. " call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
  9423. if g:netrw_scp_cmd =~ '^pscp'
  9424. " call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
  9425. exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
  9426. " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
  9427. sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
  9428. sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
  9429. sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
  9430. NetrwKeepj call histdel("/",-1)
  9431. NetrwKeepj call histdel("/",-1)
  9432. NetrwKeepj call histdel("/",-1)
  9433. if g:netrw_liststyle != s:LONGLIST
  9434. sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
  9435. NetrwKeepj call histdel("/",-1)
  9436. endif
  9437. else
  9438. if s:path == ""
  9439. " call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
  9440. exe "NetrwKeepj keepalt r! ".listcmd
  9441. else
  9442. " call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
  9443. exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
  9444. " call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
  9445. endif
  9446. endif
  9447. " cleanup
  9448. if g:netrw_ssh_browse_reject != ""
  9449. " call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
  9450. exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
  9451. NetrwKeepj call histdel("/",-1)
  9452. endif
  9453. endif
  9454. if w:netrw_liststyle == s:LONGLIST
  9455. " do a long listing; these substitutions need to be done prior to sorting {{{3
  9456. " call Decho("fix long listing:",'~'.expand("<slnum>"))
  9457. if s:method == "ftp"
  9458. " cleanup
  9459. exe "sil! NetrwKeepj ".w:netrw_bannercnt
  9460. while getline('.') =~# g:netrw_ftp_browse_reject
  9461. sil! NetrwKeepj d
  9462. endwhile
  9463. " if there's no ../ listed, then put ../ in
  9464. let line1= line(".")
  9465. sil! NetrwKeepj 1
  9466. sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
  9467. let line2= line(".")
  9468. if line2 == 0
  9469. if b:netrw_curdir != '/'
  9470. exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
  9471. endif
  9472. endif
  9473. exe "sil! NetrwKeepj ".line1
  9474. sil! NetrwKeepj norm! 0
  9475. endif
  9476. if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
  9477. " call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
  9478. exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/'
  9479. elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
  9480. " call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
  9481. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
  9482. exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
  9483. exe 'sil NetrwKeepj '.w:netrw_bannercnt
  9484. NetrwKeepj call histdel("/",-1)
  9485. NetrwKeepj call histdel("/",-1)
  9486. NetrwKeepj call histdel("/",-1)
  9487. endif
  9488. endif
  9489. " if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
  9490. " exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
  9491. " endif " Decho
  9492. " call Dret("s:NetrwRemoteListing 0")
  9493. return 0
  9494. endfun
  9495. " ---------------------------------------------------------------------
  9496. " s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
  9497. fun! s:NetrwRemoteRm(usrhost,path) range
  9498. " call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
  9499. " call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
  9500. let svpos= winsaveview()
  9501. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  9502. let all= 0
  9503. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  9504. " remove all marked files
  9505. " call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
  9506. for fname in s:netrwmarkfilelist_{bufnr("%")}
  9507. let ok= s:NetrwRemoteRmFile(a:path,fname,all)
  9508. if ok =~# 'q\%[uit]'
  9509. break
  9510. elseif ok =~# 'a\%[ll]'
  9511. let all= 1
  9512. endif
  9513. endfor
  9514. call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
  9515. else
  9516. " remove files specified by range
  9517. " call Decho("remove files specified by range",'~'.expand("<slnum>"))
  9518. " preparation for removing multiple files/directories
  9519. let keepsol = &l:sol
  9520. setl nosol
  9521. let ctr = a:firstline
  9522. " remove multiple files and directories
  9523. while ctr <= a:lastline
  9524. exe "NetrwKeepj ".ctr
  9525. let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
  9526. if ok =~# 'q\%[uit]'
  9527. break
  9528. elseif ok =~# 'a\%[ll]'
  9529. let all= 1
  9530. endif
  9531. let ctr= ctr + 1
  9532. endwhile
  9533. let &l:sol = keepsol
  9534. endif
  9535. " refresh the (remote) directory listing
  9536. " call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
  9537. NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
  9538. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  9539. NetrwKeepj call winrestview(svpos)
  9540. " call Dret("s:NetrwRemoteRm")
  9541. endfun
  9542. " ---------------------------------------------------------------------
  9543. " s:NetrwRemoteRmFile: {{{2
  9544. fun! s:NetrwRemoteRmFile(path,rmfile,all)
  9545. " call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
  9546. let all= a:all
  9547. let ok = ""
  9548. if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
  9549. " attempt to remove file
  9550. " call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
  9551. if !all
  9552. echohl Statement
  9553. " call Decho("case all=0:",'~'.expand("<slnum>"))
  9554. call inputsave()
  9555. let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
  9556. call inputrestore()
  9557. echohl NONE
  9558. if ok == ""
  9559. let ok="no"
  9560. endif
  9561. let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
  9562. if ok =~# 'a\%[ll]'
  9563. let all= 1
  9564. endif
  9565. endif
  9566. if all || ok =~# 'y\%[es]' || ok == ""
  9567. " call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""),'~'.expand("<slnum>"))
  9568. if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
  9569. " call Decho("case ftp:",'~'.expand("<slnum>"))
  9570. let path= a:path
  9571. if path =~ '^\a\{3,}://'
  9572. let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
  9573. endif
  9574. sil! NetrwKeepj .,$d _
  9575. call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
  9576. else
  9577. " call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
  9578. let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
  9579. " call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
  9580. if !exists("b:netrw_curdir")
  9581. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
  9582. let ok="q"
  9583. else
  9584. let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
  9585. " call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
  9586. " call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
  9587. " call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
  9588. if remotedir != ""
  9589. let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
  9590. else
  9591. let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
  9592. endif
  9593. " call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
  9594. let ret= system(netrw_rm_cmd)
  9595. if v:shell_error != 0
  9596. if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
  9597. call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
  9598. else
  9599. call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
  9600. endif
  9601. elseif ret != 0
  9602. call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
  9603. endif
  9604. " call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
  9605. endif
  9606. endif
  9607. elseif ok =~# 'q\%[uit]'
  9608. " call Decho("ok==".ok,'~'.expand("<slnum>"))
  9609. endif
  9610. else
  9611. " attempt to remove directory
  9612. " call Decho("attempt to remove directory",'~'.expand("<slnum>"))
  9613. if !all
  9614. call inputsave()
  9615. let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
  9616. call inputrestore()
  9617. if ok == ""
  9618. let ok="no"
  9619. endif
  9620. let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
  9621. if ok =~# 'a\%[ll]'
  9622. let all= 1
  9623. endif
  9624. endif
  9625. if all || ok =~# 'y\%[es]' || ok == ""
  9626. if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
  9627. NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
  9628. else
  9629. let rmfile = substitute(a:path.a:rmfile,'/$','','')
  9630. let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
  9631. " call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
  9632. let ret= system(netrw_rmdir_cmd)
  9633. " call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
  9634. if v:shell_error != 0
  9635. " call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
  9636. let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
  9637. " call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
  9638. let ret= system(netrw_rmf_cmd)
  9639. " call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
  9640. if v:shell_error != 0 && !exists("g:netrw_quiet")
  9641. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
  9642. endif
  9643. endif
  9644. endif
  9645. elseif ok =~# 'q\%[uit]'
  9646. " call Decho("ok==".ok,'~'.expand("<slnum>"))
  9647. endif
  9648. endif
  9649. " call Dret("s:NetrwRemoteRmFile ".ok)
  9650. return ok
  9651. endfun
  9652. " ---------------------------------------------------------------------
  9653. " s:NetrwRemoteRename: rename a remote file or directory {{{2
  9654. fun! s:NetrwRemoteRename(usrhost,path) range
  9655. " call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
  9656. " preparation for removing multiple files/directories
  9657. let svpos = winsaveview()
  9658. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  9659. let ctr = a:firstline
  9660. let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
  9661. " rename files given by the markfilelist
  9662. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  9663. for oldname in s:netrwmarkfilelist_{bufnr("%")}
  9664. " call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
  9665. if exists("subfrom")
  9666. let newname= substitute(oldname,subfrom,subto,'')
  9667. " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
  9668. else
  9669. call inputsave()
  9670. let newname= input("Moving ".oldname." to : ",oldname)
  9671. call inputrestore()
  9672. if newname =~ '^s/'
  9673. let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
  9674. let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
  9675. let newname = substitute(oldname,subfrom,subto,'')
  9676. " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
  9677. endif
  9678. endif
  9679. if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
  9680. NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
  9681. else
  9682. let oldname= s:ShellEscape(a:path.oldname)
  9683. let newname= s:ShellEscape(a:path.newname)
  9684. " call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
  9685. let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
  9686. endif
  9687. endfor
  9688. call s:NetrwUnMarkFile(1)
  9689. else
  9690. " attempt to rename files/directories
  9691. let keepsol= &l:sol
  9692. setl nosol
  9693. while ctr <= a:lastline
  9694. exe "NetrwKeepj ".ctr
  9695. let oldname= s:NetrwGetWord()
  9696. " call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
  9697. call inputsave()
  9698. let newname= input("Moving ".oldname." to : ",oldname)
  9699. call inputrestore()
  9700. if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
  9701. call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
  9702. else
  9703. let oldname= s:ShellEscape(a:path.oldname)
  9704. let newname= s:ShellEscape(a:path.newname)
  9705. " call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
  9706. let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
  9707. endif
  9708. let ctr= ctr + 1
  9709. endwhile
  9710. let &l:sol= keepsol
  9711. endif
  9712. " refresh the directory
  9713. NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
  9714. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  9715. NetrwKeepj call winrestview(svpos)
  9716. " call Dret("NetrwRemoteRename")
  9717. endfun
  9718. " ==========================================
  9719. " Local Directory Browsing Support: {{{1
  9720. " ==========================================
  9721. " ---------------------------------------------------------------------
  9722. " netrw#FileUrlEdit: handles editing file://* files {{{2
  9723. " Should accept: file://localhost/etc/fstab
  9724. " file:///etc/fstab
  9725. " file:///c:/WINDOWS/clock.avi
  9726. " file:///c|/WINDOWS/clock.avi
  9727. " file://localhost/c:/WINDOWS/clock.avi
  9728. " file://localhost/c|/WINDOWS/clock.avi
  9729. " file://c:/foo.txt
  9730. " file:///c:/foo.txt
  9731. " and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
  9732. fun! netrw#FileUrlEdit(fname)
  9733. " call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
  9734. let fname = a:fname
  9735. if fname =~ '^file://localhost/'
  9736. " call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
  9737. let fname= substitute(fname,'^file://localhost/','file:///','')
  9738. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  9739. endif
  9740. if (has("win32") || has("win95") || has("win64") || has("win16"))
  9741. if fname =~ '^file:///\=\a[|:]/'
  9742. " call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
  9743. let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
  9744. " call Decho("fname<".fname.">",'~'.expand("<slnum>"))
  9745. endif
  9746. endif
  9747. let fname2396 = netrw#RFC2396(fname)
  9748. let fname2396e= fnameescape(fname2396)
  9749. let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
  9750. if (has("win32") || has("win95") || has("win64") || has("win16"))
  9751. " call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
  9752. if plainfname =~ '^/\+\a:'
  9753. " call Decho('removing leading "/"s','~'.expand("<slnum>"))
  9754. let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
  9755. endif
  9756. endif
  9757. " call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
  9758. " call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
  9759. exe "sil doau BufReadPre ".fname2396e
  9760. exe 'NetrwKeepj keepalt edit '.plainfname
  9761. exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
  9762. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  9763. " call Dret("netrw#FileUrlEdit")
  9764. exe "sil doau BufReadPost ".fname2396e
  9765. endfun
  9766. " ---------------------------------------------------------------------
  9767. " netrw#LocalBrowseCheck: {{{2
  9768. fun! netrw#LocalBrowseCheck(dirname)
  9769. " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
  9770. " and by <cr> when atop a listed file/directory (via a buffer-local map)
  9771. "
  9772. " unfortunate interaction -- split window debugging can't be used here, must use
  9773. " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
  9774. " another call to LocalBrowseCheck() when attempts to write
  9775. " to the DBG buffer are made.
  9776. "
  9777. " The &ft == "netrw" test was installed because the BufEnter event
  9778. " would hit when re-entering netrw windows, creating unexpected
  9779. " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
  9780. " call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
  9781. " call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
  9782. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  9783. " call Dredir("ls!","netrw#LocalBrowseCheck")
  9784. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  9785. " call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
  9786. let ykeep= @@
  9787. if isdirectory(s:NetrwFile(a:dirname))
  9788. " call Decho("is-directory ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")." ft<".&ft."> g:netrw_fastbrowse=".g:netrw_fastbrowse,'~'.expand("<slnum>"))
  9789. if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
  9790. " call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
  9791. " call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
  9792. sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
  9793. elseif &ft == "netrw" && line("$") == 1
  9794. " call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
  9795. sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
  9796. elseif exists("s:treeforceredraw")
  9797. " call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
  9798. unlet s:treeforceredraw
  9799. sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
  9800. endif
  9801. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  9802. " call Dret("netrw#LocalBrowseCheck")
  9803. return
  9804. endif
  9805. " The following code wipes out currently unused netrw buffers
  9806. " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
  9807. " AND IF the listing style is not a tree listing
  9808. if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
  9809. " call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
  9810. let ibuf = 1
  9811. let buflast = bufnr("$")
  9812. while ibuf <= buflast
  9813. if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
  9814. exe "sil! keepj keepalt ".ibuf."bw!"
  9815. endif
  9816. let ibuf= ibuf + 1
  9817. endwhile
  9818. endif
  9819. let @@= ykeep
  9820. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  9821. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  9822. " not a directory, ignore it
  9823. " call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
  9824. endfun
  9825. " ---------------------------------------------------------------------
  9826. " s:LocalBrowseRefresh: this function is called after a user has {{{2
  9827. " performed any shell command. The idea is to cause all local-browsing
  9828. " buffers to be refreshed after a user has executed some shell command,
  9829. " on the chance that s/he removed/created a file/directory with it.
  9830. fun! s:LocalBrowseRefresh()
  9831. " call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
  9832. " call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
  9833. " call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
  9834. " determine which buffers currently reside in a tab
  9835. if !exists("s:netrw_browselist")
  9836. " call Dret("s:LocalBrowseRefresh : browselist is empty")
  9837. return
  9838. endif
  9839. if !exists("w:netrw_bannercnt")
  9840. " call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
  9841. return
  9842. endif
  9843. if exists("s:netrw_events") && s:netrw_events == 1
  9844. " s:LocalFastBrowser gets called (indirectly) from a
  9845. let s:netrw_events= 2
  9846. " call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
  9847. return
  9848. endif
  9849. let itab = 1
  9850. let buftablist = []
  9851. let ykeep = @@
  9852. while itab <= tabpagenr("$")
  9853. let buftablist = buftablist + tabpagebuflist()
  9854. let itab = itab + 1
  9855. sil! tabn
  9856. endwhile
  9857. " call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
  9858. " call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
  9859. " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
  9860. " | refresh any netrw window
  9861. " | wipe out any non-displaying netrw buffer
  9862. let curwinid = win_getid(winnr())
  9863. let ibl = 0
  9864. for ibuf in s:netrw_browselist
  9865. " call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
  9866. if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
  9867. " wipe out any non-displaying netrw buffer
  9868. " (ibuf not shown in a current window AND
  9869. " ibuf not in any tab)
  9870. " call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
  9871. exe "sil! keepj bd ".fnameescape(ibuf)
  9872. call remove(s:netrw_browselist,ibl)
  9873. " call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
  9874. continue
  9875. elseif index(tabpagebuflist(),ibuf) != -1
  9876. " refresh any netrw buffer
  9877. " call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
  9878. exe bufwinnr(ibuf)."wincmd w"
  9879. if getline(".") =~# 'Quick Help'
  9880. " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
  9881. " (counteracts s:NetrwBrowseChgDir()'s incrementing)
  9882. let g:netrw_quickhelp= g:netrw_quickhelp - 1
  9883. endif
  9884. " call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
  9885. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  9886. NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
  9887. endif
  9888. NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
  9889. endif
  9890. let ibl= ibl + 1
  9891. " call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
  9892. endfor
  9893. " call Decho("restore window: win_gotoid(".curwinid.")")
  9894. call win_gotoid(curwinid)
  9895. let @@= ykeep
  9896. " call Dret("s:LocalBrowseRefresh")
  9897. endfun
  9898. " ---------------------------------------------------------------------
  9899. " s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
  9900. "
  9901. " g:netrw_ Directory Is
  9902. " fastbrowse Local Remote
  9903. " slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
  9904. " med 1 D H H=Hiding a buffer implies it may be re-used (fast)
  9905. " fast 2 H H
  9906. "
  9907. " Deleting a buffer means that it will be re-loaded when examined, hence "slow".
  9908. " Hiding a buffer means that it will be re-used when examined, hence "fast".
  9909. " (re-using a buffer may not be as accurate)
  9910. "
  9911. " s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
  9912. " =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
  9913. " BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
  9914. " If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
  9915. " =2: autocmds installed (doesn't ignore any FocusGained events)
  9916. fun! s:LocalFastBrowser()
  9917. " call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
  9918. " call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
  9919. " call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
  9920. " call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
  9921. " initialize browselist, a list of buffer numbers that the local browser has used
  9922. if !exists("s:netrw_browselist")
  9923. " call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
  9924. let s:netrw_browselist= []
  9925. endif
  9926. " append current buffer to fastbrowse list
  9927. if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
  9928. " call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
  9929. call add(s:netrw_browselist,bufnr("%"))
  9930. " call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
  9931. endif
  9932. " enable autocmd events to handle refreshing/removing local browser buffers
  9933. " If local browse buffer is currently showing: refresh it
  9934. " If local browse buffer is currently hidden : wipe it
  9935. " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
  9936. " =1 : medium speed, re-use directory listing for remote only
  9937. " =2 : fast speed, always re-use directory listing when possible
  9938. if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
  9939. let s:netrw_events= 1
  9940. augroup AuNetrwEvent
  9941. au!
  9942. if (has("win32") || has("win95") || has("win64") || has("win16"))
  9943. " call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
  9944. au ShellCmdPost * call s:LocalBrowseRefresh()
  9945. else
  9946. " call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
  9947. au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
  9948. endif
  9949. augroup END
  9950. " user must have changed fastbrowse to its fast setting, so remove
  9951. " the associated autocmd events
  9952. elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
  9953. " call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
  9954. unlet s:netrw_events
  9955. augroup AuNetrwEvent
  9956. au!
  9957. augroup END
  9958. augroup! AuNetrwEvent
  9959. endif
  9960. " call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
  9961. endfun
  9962. " ---------------------------------------------------------------------
  9963. " s:LocalListing: does the job of "ls" for local directories {{{2
  9964. fun! s:LocalListing()
  9965. " call Dfunc("s:LocalListing()")
  9966. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  9967. " call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
  9968. " call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
  9969. " if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
  9970. " if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist",'~'.expand("<slnum>"))|endif
  9971. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  9972. " get the list of files contained in the current directory
  9973. let dirname = b:netrw_curdir
  9974. let dirnamelen = strlen(b:netrw_curdir)
  9975. let filelist = s:NetrwGlob(dirname,"*",0)
  9976. let filelist = filelist + s:NetrwGlob(dirname,".*",0)
  9977. " call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
  9978. if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
  9979. " call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
  9980. elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
  9981. " include ../ in the glob() entry if its missing
  9982. " call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
  9983. let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
  9984. " call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
  9985. endif
  9986. " call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
  9987. " call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
  9988. " call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
  9989. if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
  9990. let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
  9991. let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
  9992. " call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
  9993. " call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
  9994. endif
  9995. " call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
  9996. for filename in filelist
  9997. " call Decho(" ",'~'.expand("<slnum>"))
  9998. " call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
  9999. if getftype(filename) == "link"
  10000. " indicate a symbolic link
  10001. " call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
  10002. let pfile= filename."@"
  10003. elseif getftype(filename) == "socket"
  10004. " indicate a socket
  10005. " call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
  10006. let pfile= filename."="
  10007. elseif getftype(filename) == "fifo"
  10008. " indicate a fifo
  10009. " call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
  10010. let pfile= filename."|"
  10011. elseif isdirectory(s:NetrwFile(filename))
  10012. " indicate a directory
  10013. " call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
  10014. let pfile= filename."/"
  10015. elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
  10016. if (has("win32") || has("win95") || has("win64") || has("win16"))
  10017. if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
  10018. " indicate an executable
  10019. " call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
  10020. let pfile= filename."*"
  10021. else
  10022. " normal file
  10023. let pfile= filename
  10024. endif
  10025. elseif executable(filename)
  10026. " indicate an executable
  10027. " call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
  10028. let pfile= filename."*"
  10029. else
  10030. " normal file
  10031. let pfile= filename
  10032. endif
  10033. else
  10034. " normal file
  10035. let pfile= filename
  10036. endif
  10037. " call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
  10038. if pfile =~ '//$'
  10039. let pfile= substitute(pfile,'//$','/','e')
  10040. " call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
  10041. endif
  10042. let pfile= strpart(pfile,dirnamelen)
  10043. let pfile= substitute(pfile,'^[/\\]','','e')
  10044. " call Decho("filename<".filename.">",'~'.expand("<slnum>"))
  10045. " call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
  10046. if w:netrw_liststyle == s:LONGLIST
  10047. let sz = getfsize(filename)
  10048. let fsz = strpart(" ",1,15-strlen(sz)).sz
  10049. if g:netrw_sizestyle =~# "[hH]"
  10050. let sz= s:NetrwHumanReadable(sz)
  10051. endif
  10052. let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
  10053. let pfile = longfile.sz." ".strftime(g:netrw_timefmt,getftime(filename))
  10054. " call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
  10055. endif
  10056. if g:netrw_sort_by =~# "^t"
  10057. " sort by time (handles time up to 1 quintillion seconds, US)
  10058. " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
  10059. " call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
  10060. " call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
  10061. let t = getftime(filename)
  10062. let ft = strpart("000000000000000000",1,18-strlen(t)).t
  10063. " call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
  10064. let ftpfile= ft.'/'.pfile
  10065. sil! NetrwKeepj put=ftpfile
  10066. elseif g:netrw_sort_by =~ "^s"
  10067. " sort by size (handles file sizes up to 1 quintillion bytes, US)
  10068. " call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
  10069. " call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
  10070. let sz = getfsize(filename)
  10071. if g:netrw_sizestyle =~# "[hH]"
  10072. let sz= s:NetrwHumanReadable(sz)
  10073. endif
  10074. let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
  10075. " call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
  10076. let fszpfile= fsz.'/'.pfile
  10077. sil! NetrwKeepj put =fszpfile
  10078. else
  10079. " sort by name
  10080. " call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
  10081. " call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
  10082. sil! NetrwKeepj put=pfile
  10083. endif
  10084. " call DechoBuf(bufnr("%"),"bufnr(%)")
  10085. endfor
  10086. " cleanup any windows mess at end-of-line
  10087. sil! NetrwKeepj g/^$/d
  10088. sil! NetrwKeepj %s/\r$//e
  10089. call histdel("/",-1)
  10090. " call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
  10091. exe "setl ts=".(g:netrw_maxfilenamelen+1)
  10092. " call Dret("s:LocalListing")
  10093. endfun
  10094. " ---------------------------------------------------------------------
  10095. " s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
  10096. fun! s:NetrwLocalExecute(cmd)
  10097. " call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
  10098. let ykeep= @@
  10099. " sanity check
  10100. if !executable(a:cmd)
  10101. call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
  10102. let @@= ykeep
  10103. " call Dret("s:NetrwLocalExecute")
  10104. return
  10105. endif
  10106. let optargs= input(":!".a:cmd,"","file")
  10107. " call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
  10108. let result= system(a:cmd.optargs)
  10109. " call Decho("result,'~'.expand("<slnum>"))
  10110. " strip any ansi escape sequences off
  10111. let result = substitute(result,"\e\\[[0-9;]*m","","g")
  10112. " show user the result(s)
  10113. echomsg result
  10114. let @@= ykeep
  10115. " call Dret("s:NetrwLocalExecute")
  10116. endfun
  10117. " ---------------------------------------------------------------------
  10118. " s:NetrwLocalRename: rename a local file or directory {{{2
  10119. fun! s:NetrwLocalRename(path) range
  10120. " call Dfunc("NetrwLocalRename(path<".a:path.">)")
  10121. " preparation for removing multiple files/directories
  10122. let ykeep = @@
  10123. let ctr = a:firstline
  10124. let svpos = winsaveview()
  10125. let all = 0
  10126. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  10127. " rename files given by the markfilelist
  10128. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  10129. for oldname in s:netrwmarkfilelist_{bufnr("%")}
  10130. " call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
  10131. if exists("subfrom")
  10132. let newname= substitute(oldname,subfrom,subto,'')
  10133. " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
  10134. else
  10135. call inputsave()
  10136. let newname= input("Moving ".oldname." to : ",oldname,"file")
  10137. call inputrestore()
  10138. if newname =~ ''
  10139. " two ctrl-x's : ignore all of string preceding the ctrl-x's
  10140. let newname = substitute(newname,'^.*','','')
  10141. elseif newname =~ ''
  10142. " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
  10143. let newname = substitute(newname,'[^/]*','','')
  10144. endif
  10145. if newname =~ '^s/'
  10146. let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
  10147. let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
  10148. " call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
  10149. let newname = substitute(oldname,subfrom,subto,'')
  10150. endif
  10151. endif
  10152. if !all && filereadable(newname)
  10153. call inputsave()
  10154. let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
  10155. call inputrestore()
  10156. if response == "all"
  10157. let all= 1
  10158. elseif response != "y" && response != "yes"
  10159. " refresh the directory
  10160. " call Decho("refresh the directory listing",'~'.expand("<slnum>"))
  10161. NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
  10162. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  10163. NetrwKeepj call winrestview(svpos)
  10164. let @@= ykeep
  10165. " call Dret("NetrwLocalRename")
  10166. return
  10167. endif
  10168. endif
  10169. call rename(oldname,newname)
  10170. endfor
  10171. call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
  10172. else
  10173. " attempt to rename files/directories
  10174. while ctr <= a:lastline
  10175. exe "NetrwKeepj ".ctr
  10176. " sanity checks
  10177. if line(".") < w:netrw_bannercnt
  10178. let ctr= ctr + 1
  10179. continue
  10180. endif
  10181. let curword= s:NetrwGetWord()
  10182. if curword == "./" || curword == "../"
  10183. let ctr= ctr + 1
  10184. continue
  10185. endif
  10186. NetrwKeepj norm! 0
  10187. let oldname= s:ComposePath(a:path,curword)
  10188. " call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
  10189. call inputsave()
  10190. let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
  10191. call inputrestore()
  10192. call rename(oldname,newname)
  10193. " call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
  10194. let ctr= ctr + 1
  10195. endwhile
  10196. endif
  10197. " refresh the directory
  10198. " call Decho("refresh the directory listing",'~'.expand("<slnum>"))
  10199. NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
  10200. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  10201. NetrwKeepj call winrestview(svpos)
  10202. let @@= ykeep
  10203. " call Dret("NetrwLocalRename")
  10204. endfun
  10205. " ---------------------------------------------------------------------
  10206. " s:NetrwLocalRm: {{{2
  10207. fun! s:NetrwLocalRm(path) range
  10208. " call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
  10209. " call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
  10210. " preparation for removing multiple files/directories
  10211. let ykeep = @@
  10212. let ret = 0
  10213. let all = 0
  10214. let svpos = winsaveview()
  10215. " call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  10216. if exists("s:netrwmarkfilelist_{bufnr('%')}")
  10217. " remove all marked files
  10218. " call Decho("remove all marked files",'~'.expand("<slnum>"))
  10219. for fname in s:netrwmarkfilelist_{bufnr("%")}
  10220. let ok= s:NetrwLocalRmFile(a:path,fname,all)
  10221. if ok =~# 'q\%[uit]' || ok == "no"
  10222. break
  10223. elseif ok =~# 'a\%[ll]'
  10224. let all= 1
  10225. endif
  10226. endfor
  10227. call s:NetrwUnMarkFile(1)
  10228. else
  10229. " remove (multiple) files and directories
  10230. " call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
  10231. let keepsol= &l:sol
  10232. setl nosol
  10233. let ctr = a:firstline
  10234. while ctr <= a:lastline
  10235. exe "NetrwKeepj ".ctr
  10236. " sanity checks
  10237. if line(".") < w:netrw_bannercnt
  10238. let ctr= ctr + 1
  10239. continue
  10240. endif
  10241. let curword= s:NetrwGetWord()
  10242. if curword == "./" || curword == "../"
  10243. let ctr= ctr + 1
  10244. continue
  10245. endif
  10246. let ok= s:NetrwLocalRmFile(a:path,curword,all)
  10247. if ok =~# 'q\%[uit]' || ok == "no"
  10248. break
  10249. elseif ok =~# 'a\%[ll]'
  10250. let all= 1
  10251. endif
  10252. let ctr= ctr + 1
  10253. endwhile
  10254. let &l:sol= keepsol
  10255. endif
  10256. " refresh the directory
  10257. " call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
  10258. if bufname("%") != "NetrwMessage"
  10259. NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
  10260. " call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
  10261. NetrwKeepj call winrestview(svpos)
  10262. endif
  10263. let @@= ykeep
  10264. " call Dret("s:NetrwLocalRm")
  10265. endfun
  10266. " ---------------------------------------------------------------------
  10267. " s:NetrwLocalRmFile: remove file fname given the path {{{2
  10268. " Give confirmation prompt unless all==1
  10269. fun! s:NetrwLocalRmFile(path,fname,all)
  10270. " call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
  10271. let all= a:all
  10272. let ok = ""
  10273. NetrwKeepj norm! 0
  10274. let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
  10275. " call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
  10276. if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
  10277. " attempt to remove file
  10278. " call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
  10279. if !all
  10280. echohl Statement
  10281. call inputsave()
  10282. let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
  10283. call inputrestore()
  10284. echohl NONE
  10285. if ok == ""
  10286. let ok="no"
  10287. endif
  10288. " call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
  10289. let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
  10290. " call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
  10291. if ok =~# 'a\%[ll]'
  10292. let all= 1
  10293. endif
  10294. endif
  10295. if all || ok =~# 'y\%[es]' || ok == ""
  10296. let ret= s:NetrwDelete(rmfile)
  10297. " call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
  10298. endif
  10299. else
  10300. " attempt to remove directory
  10301. if !all
  10302. echohl Statement
  10303. call inputsave()
  10304. let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
  10305. call inputrestore()
  10306. let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
  10307. if ok == ""
  10308. let ok="no"
  10309. endif
  10310. if ok =~# 'a\%[ll]'
  10311. let all= 1
  10312. endif
  10313. endif
  10314. let rmfile= substitute(rmfile,'[\/]$','','e')
  10315. if all || ok =~# 'y\%[es]' || ok == ""
  10316. if v:version < 704 || (v:version == 704 && !has("patch1107"))
  10317. " " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
  10318. call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
  10319. " " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
  10320. if v:shell_error != 0
  10321. " " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
  10322. let errcode= s:NetrwDelete(rmfile)
  10323. " " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
  10324. if errcode != 0
  10325. if has("unix")
  10326. " " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
  10327. call system("rm ".s:ShellEscape(rmfile))
  10328. if v:shell_error != 0 && !exists("g:netrw_quiet")
  10329. call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
  10330. let ok="no"
  10331. endif
  10332. elseif !exists("g:netrw_quiet")
  10333. call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
  10334. let ok="no"
  10335. endif
  10336. endif
  10337. endif
  10338. else
  10339. if delete(rmfile,"d")
  10340. call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
  10341. endif
  10342. endif
  10343. endif
  10344. endif
  10345. " call Dret("s:NetrwLocalRmFile ".ok)
  10346. return ok
  10347. endfun
  10348. " =====================================================================
  10349. " Support Functions: {{{1
  10350. " ---------------------------------------------------------------------
  10351. " netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
  10352. " 0: marked file list of current buffer
  10353. " 1: marked file target
  10354. fun! netrw#Access(ilist)
  10355. if a:ilist == 0
  10356. if exists("s:netrwmarkfilelist_".bufnr('%'))
  10357. return s:netrwmarkfilelist_{bufnr('%')}
  10358. else
  10359. return "no-list-buf#".bufnr('%')
  10360. endif
  10361. elseif a:ilist == 1
  10362. return s:netrwmftgt
  10363. endif
  10364. endfun
  10365. " ---------------------------------------------------------------------
  10366. " netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
  10367. fun! netrw#Call(funcname,...)
  10368. return call("s:".a:funcname,a:000)
  10369. endfun
  10370. " ---------------------------------------------------------------------
  10371. " netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
  10372. " I expect this function to be used in
  10373. " :PChkAssert netrw#Expose("netrwmarkfilelist")
  10374. " for example.
  10375. fun! netrw#Expose(varname)
  10376. " call Dfunc("netrw#Expose(varname<".a:varname.">)")
  10377. if exists("s:".a:varname)
  10378. exe "let retval= s:".a:varname
  10379. " call Decho("retval=".retval,'~'.expand("<slnum>"))
  10380. if exists("g:netrw_pchk")
  10381. " call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
  10382. if type(retval) == 3
  10383. let retval = copy(retval)
  10384. let i = 0
  10385. while i < len(retval)
  10386. let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
  10387. let i = i + 1
  10388. endwhile
  10389. endif
  10390. " call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
  10391. return string(retval)
  10392. else
  10393. " call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
  10394. endif
  10395. else
  10396. " call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
  10397. let retval= "n/a"
  10398. endif
  10399. " call Dret("netrw#Expose ".string(retval))
  10400. return retval
  10401. endfun
  10402. " ---------------------------------------------------------------------
  10403. " netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
  10404. fun! netrw#Modify(varname,newvalue)
  10405. " call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
  10406. exe "let s:".a:varname."= ".string(a:newvalue)
  10407. " call Dret("netrw#Modify")
  10408. endfun
  10409. " ---------------------------------------------------------------------
  10410. " netrw#RFC2396: converts %xx into characters {{{2
  10411. fun! netrw#RFC2396(fname)
  10412. " call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
  10413. let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
  10414. " call Dret("netrw#RFC2396 ".fname)
  10415. return fname
  10416. endfun
  10417. " ---------------------------------------------------------------------
  10418. " netrw#UserMaps: supports user-specified maps {{{2
  10419. " see :help function()
  10420. "
  10421. " g:Netrw_UserMaps is a List with members such as:
  10422. " [[keymap sequence, function reference],...]
  10423. "
  10424. " The referenced function may return a string,
  10425. " refresh : refresh the display
  10426. " -other- : this string will be executed
  10427. " or it may return a List of strings.
  10428. "
  10429. " Each keymap-sequence will be set up with a nnoremap
  10430. " to invoke netrw#UserMaps(a:islocal).
  10431. " Related functions:
  10432. " netrw#Expose(varname) -- see s:varname variables
  10433. " netrw#Modify(varname,newvalue) -- modify value of s:varname variable
  10434. " netrw#Call(funcname,...) -- call internal netrw function with optional arguments
  10435. fun! netrw#UserMaps(islocal)
  10436. " call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
  10437. " call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
  10438. " set up usermaplist
  10439. if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
  10440. " call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
  10441. for umap in g:Netrw_UserMaps
  10442. " call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
  10443. " call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
  10444. " if umap[0] is a string and umap[1] is a string holding a function name
  10445. if type(umap[0]) == 1 && type(umap[1]) == 1
  10446. " call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
  10447. exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
  10448. else
  10449. call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
  10450. endif
  10451. endfor
  10452. endif
  10453. " call Dret("netrw#UserMaps")
  10454. endfun
  10455. " ---------------------------------------------------------------------
  10456. " netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
  10457. fun! netrw#WinPath(path)
  10458. " call Dfunc("netrw#WinPath(path<".a:path.">)")
  10459. if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
  10460. " remove cygdrive prefix, if present
  10461. let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
  10462. " remove trailing slash (Win95)
  10463. let path = substitute(path, '\(\\\|/\)$', '', 'g')
  10464. " remove escaped spaces
  10465. let path = substitute(path, '\ ', ' ', 'g')
  10466. " convert slashes to backslashes
  10467. let path = substitute(path, '/', '\', 'g')
  10468. else
  10469. let path= a:path
  10470. endif
  10471. " call Dret("netrw#WinPath <".path.">")
  10472. return path
  10473. endfun
  10474. " ---------------------------------------------------------------------
  10475. " s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
  10476. " cb : bl2mf=0 add marked files to buffer list
  10477. " cB : bl2mf=1 use bufferlist to mark files
  10478. " (mnemonic: cb = copy (marked files) to buffer list)
  10479. fun! s:NetrwBadd(islocal,bl2mf)
  10480. " " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
  10481. if a:bl2mf
  10482. " cB: add buffer list to marked files
  10483. redir => bufl
  10484. ls
  10485. redir END
  10486. let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
  10487. for fname in bufl
  10488. call s:NetrwMarkFile(a:islocal,fname)
  10489. endfor
  10490. else
  10491. " cb: add marked files to buffer list
  10492. for fname in s:netrwmarkfilelist_{bufnr("%")}
  10493. " " call Decho("badd ".fname,'~'.expand("<slnum>"))
  10494. exe "badd ".fnameescape(fname)
  10495. endfor
  10496. let curbufnr = bufnr("%")
  10497. let curdir = s:NetrwGetCurdir(a:islocal)
  10498. call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
  10499. endif
  10500. " call Dret("s:NetrwBadd")
  10501. endfun
  10502. " ---------------------------------------------------------------------
  10503. " s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
  10504. fun! s:ComposePath(base,subdir)
  10505. " call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
  10506. if has("amiga")
  10507. " call Decho("amiga",'~'.expand("<slnum>"))
  10508. let ec = a:base[s:Strlen(a:base)-1]
  10509. if ec != '/' && ec != ':'
  10510. let ret = a:base."/" . a:subdir
  10511. else
  10512. let ret = a:base.a:subdir
  10513. endif
  10514. " COMBAK: test on windows with changing to root directory: :e C:/
  10515. elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
  10516. " call Decho("windows",'~'.expand("<slnum>"))
  10517. let ret= a:subdir
  10518. elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
  10519. " call Decho("windows",'~'.expand("<slnum>"))
  10520. if a:base =~ '[/\\]$'
  10521. let ret= a:base.a:subdir
  10522. else
  10523. let ret= a:base.'/'.a:subdir
  10524. endif
  10525. elseif a:base =~ '^\a\{3,}://'
  10526. " call Decho("remote linux/macos",'~'.expand("<slnum>"))
  10527. let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
  10528. let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
  10529. if a:subdir == '../'
  10530. if curpath =~ '[^/]/[^/]\+/$'
  10531. let curpath= substitute(curpath,'[^/]\+/$','','')
  10532. else
  10533. let curpath=""
  10534. endif
  10535. let ret= urlbase.curpath
  10536. else
  10537. let ret= urlbase.curpath.a:subdir
  10538. endif
  10539. " call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
  10540. " call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
  10541. " call Decho("ret<".ret.">",'~'.expand("<slnum>"))
  10542. else
  10543. " call Decho("local linux/macos",'~'.expand("<slnum>"))
  10544. let ret = substitute(a:base."/".a:subdir,"//","/","g")
  10545. if a:base =~ '^//'
  10546. " keeping initial '//' for the benefit of network share listing support
  10547. let ret= '/'.ret
  10548. endif
  10549. let ret= simplify(ret)
  10550. endif
  10551. " call Dret("s:ComposePath ".ret)
  10552. return ret
  10553. endfun
  10554. " ---------------------------------------------------------------------
  10555. " s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
  10556. " Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
  10557. fun! s:DeleteBookmark(fname)
  10558. " call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
  10559. call s:MergeBookmarks()
  10560. if exists("g:netrw_bookmarklist")
  10561. let indx= index(g:netrw_bookmarklist,a:fname)
  10562. if indx == -1
  10563. let indx= 0
  10564. while indx < len(g:netrw_bookmarklist)
  10565. if g:netrw_bookmarklist[indx] =~ a:fname
  10566. call remove(g:netrw_bookmarklist,indx)
  10567. let indx= indx - 1
  10568. endif
  10569. let indx= indx + 1
  10570. endwhile
  10571. else
  10572. " remove exact match
  10573. call remove(g:netrw_bookmarklist,indx)
  10574. endif
  10575. endif
  10576. " call Dret("s:DeleteBookmark")
  10577. endfun
  10578. " ---------------------------------------------------------------------
  10579. " s:FileReadable: o/s independent filereadable {{{2
  10580. fun! s:FileReadable(fname)
  10581. " call Dfunc("s:FileReadable(fname<".a:fname.">)")
  10582. if g:netrw_cygwin
  10583. let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
  10584. else
  10585. let ret= filereadable(s:NetrwFile(a:fname))
  10586. endif
  10587. " call Dret("s:FileReadable ".ret)
  10588. return ret
  10589. endfun
  10590. " ---------------------------------------------------------------------
  10591. " s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
  10592. " Places correct suffix on end of temporary filename,
  10593. " using the suffix provided with fname
  10594. fun! s:GetTempfile(fname)
  10595. " call Dfunc("s:GetTempfile(fname<".a:fname.">)")
  10596. if !exists("b:netrw_tmpfile")
  10597. " get a brand new temporary filename
  10598. let tmpfile= tempname()
  10599. " call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
  10600. let tmpfile= substitute(tmpfile,'\','/','ge')
  10601. " call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
  10602. " sanity check -- does the temporary file's directory exist?
  10603. if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
  10604. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  10605. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
  10606. " call Dret("s:GetTempfile getcwd<".getcwd().">")
  10607. return ""
  10608. endif
  10609. " let netrw#NetSource() know about the tmpfile
  10610. let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
  10611. " call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
  10612. " o/s dependencies
  10613. if g:netrw_cygwin != 0
  10614. let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
  10615. elseif has("win32") || has("win95") || has("win64") || has("win16")
  10616. if !exists("+shellslash") || !&ssl
  10617. let tmpfile = substitute(tmpfile,'/','\','g')
  10618. endif
  10619. else
  10620. let tmpfile = tmpfile
  10621. endif
  10622. let b:netrw_tmpfile= tmpfile
  10623. " call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
  10624. else
  10625. " re-use temporary filename
  10626. let tmpfile= b:netrw_tmpfile
  10627. " call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
  10628. endif
  10629. " use fname's suffix for the temporary file
  10630. if a:fname != ""
  10631. if a:fname =~ '\.[^./]\+$'
  10632. " call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
  10633. if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
  10634. let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
  10635. elseif a:fname =~ '.txz$'
  10636. let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
  10637. else
  10638. let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
  10639. endif
  10640. " call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
  10641. let tmpfile= substitute(tmpfile,'\.tmp$','','e')
  10642. " call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
  10643. let tmpfile .= suffix
  10644. " call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
  10645. let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
  10646. endif
  10647. endif
  10648. " call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  10649. " call Dret("s:GetTempfile <".tmpfile.">")
  10650. return tmpfile
  10651. endfun
  10652. " ---------------------------------------------------------------------
  10653. " s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
  10654. " a correct command for use with a system() call
  10655. fun! s:MakeSshCmd(sshcmd)
  10656. " call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
  10657. if s:user == ""
  10658. let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
  10659. else
  10660. let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
  10661. endif
  10662. if exists("g:netrw_port") && g:netrw_port != ""
  10663. let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
  10664. elseif exists("s:port") && s:port != ""
  10665. let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
  10666. else
  10667. let sshcmd= substitute(sshcmd,"USEPORT ",'','')
  10668. endif
  10669. " call Dret("s:MakeSshCmd <".sshcmd.">")
  10670. return sshcmd
  10671. endfun
  10672. " ---------------------------------------------------------------------
  10673. " s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
  10674. fun! s:MakeBookmark(fname)
  10675. " call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
  10676. if !exists("g:netrw_bookmarklist")
  10677. let g:netrw_bookmarklist= []
  10678. endif
  10679. if index(g:netrw_bookmarklist,a:fname) == -1
  10680. " curdir not currently in g:netrw_bookmarklist, so include it
  10681. if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
  10682. call add(g:netrw_bookmarklist,a:fname.'/')
  10683. elseif a:fname !~ '/'
  10684. call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
  10685. else
  10686. call add(g:netrw_bookmarklist,a:fname)
  10687. endif
  10688. call sort(g:netrw_bookmarklist)
  10689. endif
  10690. " call Dret("s:MakeBookmark")
  10691. endfun
  10692. " ---------------------------------------------------------------------
  10693. " s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
  10694. fun! s:MergeBookmarks()
  10695. " call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
  10696. " get bookmarks from .netrwbook file
  10697. let savefile= s:NetrwHome()."/.netrwbook"
  10698. if filereadable(s:NetrwFile(savefile))
  10699. " call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
  10700. NetrwKeepj call s:NetrwBookHistSave()
  10701. " call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
  10702. NetrwKeepj call delete(savefile)
  10703. endif
  10704. " call Dret("s:MergeBookmarks")
  10705. endfun
  10706. " ---------------------------------------------------------------------
  10707. " s:NetrwBMShow: {{{2
  10708. fun! s:NetrwBMShow()
  10709. " call Dfunc("s:NetrwBMShow()")
  10710. redir => bmshowraw
  10711. menu
  10712. redir END
  10713. let bmshowlist = split(bmshowraw,'\n')
  10714. if bmshowlist != []
  10715. let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
  10716. if bmshowfuncs != []
  10717. let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
  10718. if bmshowfunc =~# '^call.*BMShow()'
  10719. exe "sil! NetrwKeepj ".bmshowfunc
  10720. endif
  10721. endif
  10722. endif
  10723. " call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
  10724. endfun
  10725. " ---------------------------------------------------------------------
  10726. " s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
  10727. fun! s:NetrwCursor(editfile)
  10728. if !exists("w:netrw_liststyle")
  10729. let w:netrw_liststyle= g:netrw_liststyle
  10730. endif
  10731. " call Dfunc("s:NetrwCursor() ft<".&ft."> liststyle=".w:netrw_liststyle." g:netrw_cursor=".g:netrw_cursor." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
  10732. " call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
  10733. if &ft != "netrw"
  10734. " if the current window isn't a netrw directory listing window, then use user cursorline/column
  10735. " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
  10736. " call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
  10737. elseif g:netrw_cursor == 8
  10738. if w:netrw_liststyle == s:WIDELIST
  10739. setl cursorline
  10740. setl cursorcolumn
  10741. else
  10742. setl cursorline
  10743. endif
  10744. elseif g:netrw_cursor == 7
  10745. setl cursorline
  10746. elseif g:netrw_cursor == 6
  10747. if w:netrw_liststyle == s:WIDELIST
  10748. setl cursorline
  10749. endif
  10750. elseif g:netrw_cursor == 4
  10751. " all styles: cursorline, cursorcolumn
  10752. " call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
  10753. setl cursorline
  10754. setl cursorcolumn
  10755. elseif g:netrw_cursor == 3
  10756. " thin-long-tree: cursorline, user's cursorcolumn
  10757. " wide : cursorline, cursorcolumn
  10758. if w:netrw_liststyle == s:WIDELIST
  10759. " call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
  10760. setl cursorline
  10761. setl cursorcolumn
  10762. else
  10763. " call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
  10764. setl cursorline
  10765. endif
  10766. elseif g:netrw_cursor == 2
  10767. " thin-long-tree: cursorline, user's cursorcolumn
  10768. " wide : cursorline, user's cursorcolumn
  10769. " call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
  10770. setl cursorline
  10771. elseif g:netrw_cursor == 1
  10772. " thin-long-tree: user's cursorline, user's cursorcolumn
  10773. " wide : cursorline, user's cursorcolumn
  10774. if w:netrw_liststyle == s:WIDELIST
  10775. " call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
  10776. setl cursorline
  10777. else
  10778. " call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
  10779. endif
  10780. else
  10781. " all styles: user's cursorline, user's cursorcolumn
  10782. " call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
  10783. let &l:cursorline = s:netrw_usercul
  10784. let &l:cursorcolumn = s:netrw_usercuc
  10785. endif
  10786. " call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
  10787. " call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
  10788. endfun
  10789. " ---------------------------------------------------------------------
  10790. " s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
  10791. fun! s:RestoreCursorline()
  10792. " call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
  10793. if exists("s:netrw_usercul")
  10794. let &l:cursorline = s:netrw_usercul
  10795. endif
  10796. if exists("s:netrw_usercuc")
  10797. let &l:cursorcolumn = s:netrw_usercuc
  10798. endif
  10799. " call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
  10800. " call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
  10801. endfun
  10802. " ---------------------------------------------------------------------
  10803. " s:NetrwDelete: Deletes a file. {{{2
  10804. " Uses Steve Hall's idea to insure that Windows paths stay
  10805. " acceptable. No effect on Unix paths.
  10806. " Examples of use: let result= s:NetrwDelete(path)
  10807. fun! s:NetrwDelete(path)
  10808. " call Dfunc("s:NetrwDelete(path<".a:path.">)")
  10809. let path = netrw#WinPath(a:path)
  10810. if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
  10811. if exists("+shellslash")
  10812. let sskeep= &shellslash
  10813. setl noshellslash
  10814. let result = delete(path)
  10815. let &shellslash = sskeep
  10816. else
  10817. " call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
  10818. let result= delete(path)
  10819. endif
  10820. else
  10821. " call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
  10822. let result= delete(path)
  10823. endif
  10824. if result < 0
  10825. NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
  10826. endif
  10827. " call Dret("s:NetrwDelete ".result)
  10828. return result
  10829. endfun
  10830. " ---------------------------------------------------------------------
  10831. " s:NetrwBufRemover: removes a buffer that: {{{2s
  10832. " has buffer-id > 1
  10833. " is unlisted
  10834. " is unnamed
  10835. " does not appear in any window
  10836. fun! s:NetrwBufRemover(bufid)
  10837. " call Dfunc("s:NetrwBufRemover(".a:bufid.")")
  10838. " call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
  10839. " call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
  10840. " call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
  10841. " call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
  10842. if a:bufid > 1 && !buflisted(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
  10843. " call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
  10844. exe "bd! ".a:bufid
  10845. endif
  10846. " call Dret("s:NetrwBufRemover")
  10847. endfun
  10848. " ---------------------------------------------------------------------
  10849. " s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
  10850. fun! s:NetrwEnew(...)
  10851. " call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
  10852. " call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
  10853. " Clean out the last buffer:
  10854. " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
  10855. " If so, delete it.
  10856. call s:NetrwBufRemover(bufnr("$"))
  10857. " grab a function-local-variable copy of buffer variables
  10858. " call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
  10859. if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
  10860. if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
  10861. if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
  10862. if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
  10863. if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
  10864. if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
  10865. if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
  10866. if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
  10867. if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
  10868. if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
  10869. if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
  10870. if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
  10871. if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
  10872. if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
  10873. if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
  10874. if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
  10875. NetrwKeepj call s:NetrwOptionsRestore("w:")
  10876. " call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
  10877. " when tree listing uses file TreeListing... a new buffer is made.
  10878. " Want the old buffer to be unlisted.
  10879. " COMBAK: this causes a problem, see P43
  10880. " setl nobl
  10881. let netrw_keepdiff= &l:diff
  10882. noswapfile NetrwKeepj keepalt enew!
  10883. let &l:diff= netrw_keepdiff
  10884. " call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
  10885. NetrwKeepj call s:NetrwOptionsSave("w:")
  10886. " copy function-local-variables to buffer variable equivalents
  10887. " call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
  10888. if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
  10889. if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
  10890. if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
  10891. if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
  10892. if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
  10893. if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
  10894. if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
  10895. if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
  10896. if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
  10897. if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
  10898. if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
  10899. if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
  10900. if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
  10901. if exists("netrw_method") |let b:netrw_method = netrw_method |endif
  10902. if exists("netrw_option") |let b:netrw_option = netrw_option |endif
  10903. if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
  10904. if a:0 > 0
  10905. let b:netrw_curdir= a:1
  10906. if b:netrw_curdir =~ '/$'
  10907. if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
  10908. setl nobl
  10909. file NetrwTreeListing
  10910. setl nobl bt=nowrite bh=hide
  10911. nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
  10912. nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
  10913. else
  10914. call s:NetrwBufRename(b:netrw_curdir)
  10915. endif
  10916. endif
  10917. endif
  10918. if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
  10919. let &l:bexpr = "netrw#BalloonHelp()"
  10920. endif
  10921. " call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
  10922. endfun
  10923. " ---------------------------------------------------------------------
  10924. " s:NetrwExe: executes a string using "!" {{{2
  10925. fun! s:NetrwExe(cmd)
  10926. " call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
  10927. if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
  10928. " call Decho("using win32:",expand("<slnum>"))
  10929. let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
  10930. set shell& shellcmdflag& shellxquote& shellxescape&
  10931. set shellquote& shellpipe& shellredir& shellslash&
  10932. exe a:cmd
  10933. let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
  10934. else
  10935. " call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
  10936. exe a:cmd
  10937. endif
  10938. if v:shell_error
  10939. call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
  10940. endif
  10941. " call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
  10942. endfun
  10943. " ---------------------------------------------------------------------
  10944. " s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
  10945. fun! s:NetrwInsureWinVars()
  10946. if !exists("w:netrw_liststyle")
  10947. " call Dfunc("s:NetrwInsureWinVars() win#".winnr())
  10948. let curbuf = bufnr("%")
  10949. let curwin = winnr()
  10950. let iwin = 1
  10951. while iwin <= winnr("$")
  10952. exe iwin."wincmd w"
  10953. if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
  10954. " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
  10955. let winvars= w:
  10956. break
  10957. endif
  10958. let iwin= iwin + 1
  10959. endwhile
  10960. exe "keepalt ".curwin."wincmd w"
  10961. if exists("winvars")
  10962. " call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
  10963. for k in keys(winvars)
  10964. let w:{k}= winvars[k]
  10965. endfor
  10966. endif
  10967. " call Dret("s:NetrwInsureWinVars win#".winnr())
  10968. endif
  10969. endfun
  10970. " ---------------------------------------------------------------------
  10971. " s:NetrwLcd: handles changing the (local) directory {{{2
  10972. " Returns: 0=success
  10973. " -1=failed
  10974. fun! s:NetrwLcd(newdir)
  10975. " call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
  10976. " call Decho("changing local directory",'~'.expand("<slnum>"))
  10977. let err472= 0
  10978. try
  10979. exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
  10980. catch /^Vim\%((\a\+)\)\=:E344/
  10981. " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
  10982. " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
  10983. " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
  10984. " forward slashes ('//Foo'), depending on whether backslashes have been converted to
  10985. " forward slashes by earlier code; so check for both.
  10986. if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
  10987. if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
  10988. let dirname = '\'
  10989. exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
  10990. endif
  10991. endif
  10992. catch /^Vim\%((\a\+)\)\=:E472/
  10993. let err472= 1
  10994. endtry
  10995. if err472
  10996. call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
  10997. if exists("w:netrw_prvdir")
  10998. let a:newdir= w:netrw_prvdir
  10999. else
  11000. call s:NetrwOptionsRestore("w:")
  11001. " call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
  11002. exe "setl ".g:netrw_bufsettings
  11003. " call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
  11004. let a:newdir= dirname
  11005. endif
  11006. " call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
  11007. return -1
  11008. endif
  11009. " call Decho("getcwd <".getcwd().">")
  11010. " call Decho("b:netrw_curdir<".b:netrw_curdir.">")
  11011. " call Dret("s:NetrwLcd 0")
  11012. return 0
  11013. endfun
  11014. " ------------------------------------------------------------------------
  11015. " s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
  11016. " changed sorting, etc. Also see s:NetrwRestoreWordPosn().
  11017. fun! s:NetrwSaveWordPosn()
  11018. " call Dfunc("NetrwSaveWordPosn()")
  11019. let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
  11020. " call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
  11021. endfun
  11022. " ---------------------------------------------------------------------
  11023. " s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
  11024. " 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
  11025. fun! s:NetrwHumanReadable(sz)
  11026. " call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
  11027. if g:netrw_sizestyle == 'h'
  11028. if a:sz >= 1000000000
  11029. let sz = printf("%.1f",a:sz/1000000000.0)."g"
  11030. elseif a:sz >= 10000000
  11031. let sz = printf("%d",a:sz/1000000)."m"
  11032. elseif a:sz >= 1000000
  11033. let sz = printf("%.1f",a:sz/1000000.0)."m"
  11034. elseif a:sz >= 10000
  11035. let sz = printf("%d",a:sz/1000)."k"
  11036. elseif a:sz >= 1000
  11037. let sz = printf("%.1f",a:sz/1000.0)."k"
  11038. else
  11039. let sz= a:sz
  11040. endif
  11041. elseif g:netrw_sizestyle == 'H'
  11042. if a:sz >= 1073741824
  11043. let sz = printf("%.1f",a:sz/1073741824.0)."G"
  11044. elseif a:sz >= 10485760
  11045. let sz = printf("%d",a:sz/1048576)."M"
  11046. elseif a:sz >= 1048576
  11047. let sz = printf("%.1f",a:sz/1048576.0)."M"
  11048. elseif a:sz >= 10240
  11049. let sz = printf("%d",a:sz/1024)."K"
  11050. elseif a:sz >= 1024
  11051. let sz = printf("%.1f",a:sz/1024.0)."K"
  11052. else
  11053. let sz= a:sz
  11054. endif
  11055. else
  11056. let sz= a:sz
  11057. endif
  11058. " call Dret("s:NetrwHumanReadable ".sz)
  11059. return sz
  11060. endfun
  11061. " ---------------------------------------------------------------------
  11062. " s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
  11063. " changed sorting, etc. Also see s:NetrwSaveWordPosn().
  11064. fun! s:NetrwRestoreWordPosn()
  11065. " call Dfunc("NetrwRestoreWordPosn()")
  11066. sil! call search(s:netrw_saveword,'w')
  11067. " call Dret("NetrwRestoreWordPosn")
  11068. endfun
  11069. " ---------------------------------------------------------------------
  11070. " s:RestoreBufVars: {{{2
  11071. fun! s:RestoreBufVars()
  11072. " call Dfunc("s:RestoreBufVars()")
  11073. if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
  11074. if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
  11075. if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
  11076. if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
  11077. if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
  11078. if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
  11079. " call Dret("s:RestoreBufVars")
  11080. endfun
  11081. " ---------------------------------------------------------------------
  11082. " s:RemotePathAnalysis: {{{2
  11083. fun! s:RemotePathAnalysis(dirname)
  11084. " call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
  11085. " method :// user @ machine :port /path
  11086. let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
  11087. let s:method = substitute(a:dirname,dirpat,'\1','')
  11088. let s:user = substitute(a:dirname,dirpat,'\3','')
  11089. let s:machine = substitute(a:dirname,dirpat,'\4','')
  11090. let s:port = substitute(a:dirname,dirpat,'\5','')
  11091. let s:path = substitute(a:dirname,dirpat,'\6','')
  11092. let s:fname = substitute(s:path,'^.*/\ze.','','')
  11093. if s:machine =~ '@'
  11094. let dirpat = '^\(.*\)@\(.\{-}\)$'
  11095. let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
  11096. let s:machine = substitute(s:machine,dirpat,'\2','')
  11097. endif
  11098. " call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
  11099. " call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
  11100. " call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
  11101. " call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
  11102. " call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
  11103. " call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
  11104. " call Dret("s:RemotePathAnalysis")
  11105. endfun
  11106. " ---------------------------------------------------------------------
  11107. " s:RemoteSystem: runs a command on a remote host using ssh {{{2
  11108. " Returns status
  11109. " Runs system() on
  11110. " [cd REMOTEDIRPATH;] a:cmd
  11111. " Note that it doesn't do s:ShellEscape(a:cmd)!
  11112. fun! s:RemoteSystem(cmd)
  11113. " call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
  11114. if !executable(g:netrw_ssh_cmd)
  11115. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
  11116. elseif !exists("b:netrw_curdir")
  11117. NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
  11118. else
  11119. let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
  11120. let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
  11121. if remotedir != ""
  11122. let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
  11123. else
  11124. let cmd= cmd.' '
  11125. endif
  11126. let cmd= cmd.a:cmd
  11127. " call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
  11128. let ret= system(cmd)
  11129. endif
  11130. " call Dret("s:RemoteSystem ".ret)
  11131. return ret
  11132. endfun
  11133. " ---------------------------------------------------------------------
  11134. " s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
  11135. fun! s:RestoreWinVars()
  11136. " call Dfunc("s:RestoreWinVars()")
  11137. if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
  11138. if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
  11139. if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
  11140. if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
  11141. if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
  11142. if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
  11143. if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
  11144. if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
  11145. if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
  11146. if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
  11147. if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
  11148. if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
  11149. if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
  11150. if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
  11151. if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
  11152. if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
  11153. if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
  11154. if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
  11155. " call Dret("s:RestoreWinVars")
  11156. endfun
  11157. " ---------------------------------------------------------------------
  11158. " s:Rexplore: implements returning from a buffer to a netrw directory {{{2
  11159. "
  11160. " s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
  11161. " is true) and a command, :Rexplore, which call this function.
  11162. "
  11163. " s:netrw_posn is set up by s:NetrwBrowseChgDir()
  11164. "
  11165. " s:rexposn_BUFNR used to save/restore cursor position
  11166. fun! s:NetrwRexplore(islocal,dirname)
  11167. if exists("s:netrwdrag")
  11168. return
  11169. endif
  11170. " call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir."> win#".winnr())
  11171. " call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
  11172. " call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
  11173. if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
  11174. " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
  11175. " call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
  11176. exe "NetrwKeepj e ".w:netrw_rexfile
  11177. unlet w:netrw_rexfile
  11178. " call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
  11179. return
  11180. " else " Decho
  11181. " call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
  11182. " call Decho("treating as not-netrw-buffer: w:netrw_rexfile<".((exists("w:netrw_rexfile"))? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
  11183. endif
  11184. " ---------------------------
  11185. " :Rex issued while in a file
  11186. " ---------------------------
  11187. " record current file so :Rex can return to it from netrw
  11188. let w:netrw_rexfile= expand("%")
  11189. " call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
  11190. if !exists("w:netrw_rexlocal")
  11191. " call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
  11192. return
  11193. endif
  11194. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  11195. if w:netrw_rexlocal
  11196. NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
  11197. else
  11198. NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
  11199. endif
  11200. if exists("s:initbeval")
  11201. setl beval
  11202. endif
  11203. if exists("s:rexposn_".bufnr("%"))
  11204. " call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
  11205. " restore position in directory listing
  11206. " call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
  11207. NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
  11208. if exists("s:rexposn_".bufnr('%'))
  11209. unlet s:rexposn_{bufnr('%')}
  11210. endif
  11211. else
  11212. " call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
  11213. endif
  11214. if has("syntax") && exists("g:syntax_on") && g:syntax_on
  11215. if exists("s:explore_match")
  11216. exe "2match netrwMarkFile /".s:explore_match."/"
  11217. endif
  11218. endif
  11219. " call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
  11220. " call Dret("s:NetrwRexplore : ft=".&ft)
  11221. endfun
  11222. " ---------------------------------------------------------------------
  11223. " s:SaveBufVars: save selected b: variables to s: variables {{{2
  11224. " use s:RestoreBufVars() to restore b: variables from s: variables
  11225. fun! s:SaveBufVars()
  11226. " call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
  11227. if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
  11228. if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
  11229. if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
  11230. if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
  11231. if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
  11232. if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
  11233. " call Dret("s:SaveBufVars")
  11234. endfun
  11235. " ---------------------------------------------------------------------
  11236. " s:SavePosn: saves position associated with current buffer into a dictionary {{{2
  11237. fun! s:SavePosn(posndict)
  11238. " call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
  11239. if !exists("a:posndict[bufnr('%')]")
  11240. let a:posndict[bufnr("%")]= []
  11241. endif
  11242. " call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
  11243. call add(a:posndict[bufnr("%")],winsaveview())
  11244. " call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
  11245. " call Dret("s:SavePosn posndict")
  11246. return a:posndict
  11247. endfun
  11248. " ---------------------------------------------------------------------
  11249. " s:RestorePosn: restores position associated with current buffer using dictionary {{{2
  11250. fun! s:RestorePosn(posndict)
  11251. " call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
  11252. if exists("a:posndict")
  11253. if has_key(a:posndict,bufnr("%"))
  11254. " call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
  11255. let posnlen= len(a:posndict[bufnr("%")])
  11256. if posnlen > 0
  11257. let posnlen= posnlen - 1
  11258. " call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
  11259. call winrestview(a:posndict[bufnr("%")][posnlen])
  11260. call remove(a:posndict[bufnr("%")],posnlen)
  11261. " call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
  11262. endif
  11263. endif
  11264. endif
  11265. " call Dret("s:RestorePosn")
  11266. endfun
  11267. " ---------------------------------------------------------------------
  11268. " s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
  11269. fun! s:SaveWinVars()
  11270. " call Dfunc("s:SaveWinVars() win#".winnr())
  11271. if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
  11272. if exists("w:netrw_col") |let s:col = w:netrw_col |endif
  11273. if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
  11274. if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
  11275. if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
  11276. if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
  11277. if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
  11278. if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
  11279. if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
  11280. if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
  11281. if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
  11282. if exists("w:netrw_line") |let s:line = w:netrw_line |endif
  11283. if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
  11284. if exists("w:netrw_method") |let s:method = w:netrw_method |endif
  11285. if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
  11286. if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
  11287. if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
  11288. if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
  11289. " call Dret("s:SaveWinVars")
  11290. endfun
  11291. " ---------------------------------------------------------------------
  11292. " s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
  11293. " To allow separate windows to have their own activities, such as
  11294. " Explore **/pattern, several variables have been made window-oriented.
  11295. " However, when the user splits a browser window (ex: ctrl-w s), these
  11296. " variables are not inherited by the new window. SetBufWinVars() and
  11297. " UseBufWinVars() get around that.
  11298. fun! s:SetBufWinVars()
  11299. " call Dfunc("s:SetBufWinVars() win#".winnr())
  11300. if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
  11301. if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
  11302. if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
  11303. if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
  11304. if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
  11305. if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
  11306. if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
  11307. if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
  11308. if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
  11309. if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
  11310. " call Dret("s:SetBufWinVars")
  11311. endfun
  11312. " ---------------------------------------------------------------------
  11313. " s:SetRexDir: set directory for :Rexplore {{{2
  11314. fun! s:SetRexDir(islocal,dirname)
  11315. " call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
  11316. let w:netrw_rexdir = a:dirname
  11317. let w:netrw_rexlocal = a:islocal
  11318. let s:rexposn_{bufnr("%")} = winsaveview()
  11319. " call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
  11320. " call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
  11321. " call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
  11322. " call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
  11323. " call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
  11324. endfun
  11325. " ---------------------------------------------------------------------
  11326. " s:ShowLink: used to modify thin and tree listings to show links {{{2
  11327. fun! s:ShowLink()
  11328. " " call Dfunc("s:ShowLink()")
  11329. " " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
  11330. " " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
  11331. if exists("b:netrw_curdir")
  11332. norm! $?\a
  11333. let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
  11334. let resname = resolve(fname)
  11335. " " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
  11336. " " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
  11337. " " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
  11338. if resname =~ '^\M'.b:netrw_curdir.'/'
  11339. let dirlen = strlen(b:netrw_curdir)
  11340. let resname = strpart(resname,dirlen+1)
  11341. " " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
  11342. endif
  11343. let modline = getline(".")."\t --> ".resname
  11344. " " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
  11345. " " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
  11346. setl noro ma
  11347. call setline(".",modline)
  11348. setl ro noma nomod
  11349. endif
  11350. " " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
  11351. endfun
  11352. " ---------------------------------------------------------------------
  11353. " s:ShowStyle: {{{2
  11354. fun! s:ShowStyle()
  11355. if !exists("w:netrw_liststyle")
  11356. let liststyle= g:netrw_liststyle
  11357. else
  11358. let liststyle= w:netrw_liststyle
  11359. endif
  11360. if liststyle == s:THINLIST
  11361. return s:THINLIST.":thin"
  11362. elseif liststyle == s:LONGLIST
  11363. return s:LONGLIST.":long"
  11364. elseif liststyle == s:WIDELIST
  11365. return s:WIDELIST.":wide"
  11366. elseif liststyle == s:TREELIST
  11367. return s:TREELIST.":tree"
  11368. else
  11369. return 'n/a'
  11370. endif
  11371. endfun
  11372. " ---------------------------------------------------------------------
  11373. " s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
  11374. " Solution from Nicolai Weibull, vim docs (:help strlen()),
  11375. " Tony Mechelynck, and my own invention.
  11376. fun! s:Strlen(x)
  11377. " "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
  11378. if v:version >= 703 && exists("*strdisplaywidth")
  11379. let ret= strdisplaywidth(a:x)
  11380. elseif type(g:Align_xstrlen) == 1
  11381. " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
  11382. exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
  11383. elseif g:Align_xstrlen == 1
  11384. " number of codepoints (Latin a + combining circumflex is two codepoints)
  11385. " (comment from TM, solution from NW)
  11386. let ret= strlen(substitute(a:x,'.','c','g'))
  11387. elseif g:Align_xstrlen == 2
  11388. " number of spacing codepoints (Latin a + combining circumflex is one spacing
  11389. " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
  11390. " (comment from TM, solution from TM)
  11391. let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
  11392. elseif g:Align_xstrlen == 3
  11393. " virtual length (counting, for instance, tabs as anything between 1 and
  11394. " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
  11395. " preceded by lam, one otherwise, etc.)
  11396. " (comment from TM, solution from me)
  11397. let modkeep= &l:mod
  11398. exe "norm! o\<esc>"
  11399. call setline(line("."),a:x)
  11400. let ret= virtcol("$") - 1
  11401. d
  11402. NetrwKeepj norm! k
  11403. let &l:mod= modkeep
  11404. else
  11405. " at least give a decent default
  11406. let ret= strlen(a:x)
  11407. endif
  11408. " "" call Dret("s:Strlen ".ret)
  11409. return ret
  11410. endfun
  11411. " ---------------------------------------------------------------------
  11412. " s:ShellEscape: shellescape(), or special windows handling {{{2
  11413. fun! s:ShellEscape(s, ...)
  11414. if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
  11415. return printf('"%s"', substitute(a:s, '"', '""', 'g'))
  11416. endif
  11417. let f = a:0 > 0 ? a:1 : 0
  11418. return shellescape(a:s, f)
  11419. endfun
  11420. " ---------------------------------------------------------------------
  11421. " s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
  11422. fun! s:TreeListMove(dir)
  11423. " call Dfunc("s:TreeListMove(dir<".a:dir.">)")
  11424. let curline = getline('.')
  11425. let prvline = (line(".") > 1)? getline(line(".")-1) : ''
  11426. let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
  11427. let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
  11428. let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
  11429. let treedepthchr = substitute(s:treedepthstring,' ','','g')
  11430. let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
  11431. " call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
  11432. " call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
  11433. " call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
  11434. " call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
  11435. " call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
  11436. " COMBAK : need to handle when on a directory
  11437. " COMBAK : need to handle ]] and ][. In general, needs work!!!
  11438. if curline !~ '/$'
  11439. if a:dir == '[[' && prvline != ''
  11440. NetrwKeepj norm! 0
  11441. let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
  11442. " call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
  11443. elseif a:dir == '[]' && nxtline != ''
  11444. NetrwKeepj norm! 0
  11445. " call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
  11446. let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
  11447. if nl != 0
  11448. NetrwKeepj norm! k
  11449. else
  11450. NetrwKeepj norm! G
  11451. endif
  11452. " call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
  11453. endif
  11454. endif
  11455. " call Dret("s:TreeListMove")
  11456. endfun
  11457. " ---------------------------------------------------------------------
  11458. " s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
  11459. " The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
  11460. " can't be called except via emenu. But due to locale, that menu line may not be called
  11461. " Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
  11462. fun! s:UpdateBuffersMenu()
  11463. " call Dfunc("s:UpdateBuffersMenu()")
  11464. if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
  11465. try
  11466. sil emenu Buffers.Refresh\ menu
  11467. catch /^Vim\%((\a\+)\)\=:E/
  11468. let v:errmsg= ""
  11469. sil NetrwKeepj call s:NetrwBMShow()
  11470. endtry
  11471. endif
  11472. " call Dret("s:UpdateBuffersMenu")
  11473. endfun
  11474. " ---------------------------------------------------------------------
  11475. " s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
  11476. " Matching function to s:SetBufWinVars()
  11477. fun! s:UseBufWinVars()
  11478. " call Dfunc("s:UseBufWinVars()")
  11479. if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
  11480. if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
  11481. if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
  11482. if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
  11483. if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
  11484. if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
  11485. if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
  11486. if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
  11487. if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
  11488. if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
  11489. " call Dret("s:UseBufWinVars")
  11490. endfun
  11491. " ---------------------------------------------------------------------
  11492. " s:UserMaps: supports user-defined UserMaps {{{2
  11493. " * calls a user-supplied funcref(islocal,curdir)
  11494. " * interprets result
  11495. " See netrw#UserMaps()
  11496. fun! s:UserMaps(islocal,funcname)
  11497. " call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
  11498. if !exists("b:netrw_curdir")
  11499. let b:netrw_curdir= getcwd()
  11500. endif
  11501. let Funcref = function(a:funcname)
  11502. let result = Funcref(a:islocal)
  11503. if type(result) == 1
  11504. " if result from user's funcref is a string...
  11505. " call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
  11506. if result == "refresh"
  11507. " call Decho("refreshing display",'~'.expand("<slnum>"))
  11508. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  11509. elseif result != ""
  11510. " call Decho("executing result<".result.">",'~'.expand("<slnum>"))
  11511. exe result
  11512. endif
  11513. elseif type(result) == 3
  11514. " if result from user's funcref is a List...
  11515. " call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
  11516. for action in result
  11517. if action == "refresh"
  11518. " call Decho("refreshing display",'~'.expand("<slnum>"))
  11519. call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
  11520. elseif action != ""
  11521. " call Decho("executing action<".action.">",'~'.expand("<slnum>"))
  11522. exe action
  11523. endif
  11524. endfor
  11525. endif
  11526. " call Dret("s:UserMaps")
  11527. endfun
  11528. " ==========================
  11529. " Settings Restoration: {{{1
  11530. " ==========================
  11531. let &cpo= s:keepcpo
  11532. unlet s:keepcpo
  11533. " ===============
  11534. " Modelines: {{{1
  11535. " ===============
  11536. " vim:ts=8 fdm=marker