idlwave.el 341 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315
  1. ;; idlwave.el --- IDL editing mode for GNU Emacs
  2. ;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
  4. ;; Carsten Dominik <dominik@science.uva.nl>
  5. ;; Chris Chase <chase@att.com>
  6. ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
  7. ;; Version: 6.1.22
  8. ;; Keywords: languages
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; IDLWAVE enables feature-rich development and interaction with IDL,
  22. ;; the Interactive Data Language. It provides a compelling,
  23. ;; full-featured alternative to the IDLDE development environment
  24. ;; bundled with IDL.
  25. ;; In the remotely distant past, based on pascal.el, though bears
  26. ;; little resemblance to it now.
  27. ;;
  28. ;; Incorporates many ideas, such as abbrevs, action routines, and
  29. ;; continuation line indenting, from wave.el.
  30. ;; wave.el original written by Lubos Pochman, Precision Visuals, Boulder.
  31. ;;
  32. ;; See the mode description ("C-h m" in idlwave-mode or "C-h f idlwave-mode")
  33. ;; for features, key bindings, and info.
  34. ;; Also, Info format documentation is available with `M-x idlwave-info'
  35. ;;
  36. ;; New versions of IDLWAVE, documentation, and more information
  37. ;; available from:
  38. ;; http://github.com/jdtsmith/idlwave
  39. ;;
  40. ;; INSTALLATION
  41. ;; ============
  42. ;;
  43. ;; Follow the instructions in the INSTALL file of the distribution.
  44. ;; In short, put this file on your load path and add the following
  45. ;; lines to your init file:
  46. ;;
  47. ;; (autoload 'idlwave-mode "idlwave" "IDLWAVE Mode" t)
  48. ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
  49. ;; (setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist))
  50. ;;
  51. ;;
  52. ;; SOURCE
  53. ;; ======
  54. ;;
  55. ;; The newest version of this file is available from the maintainer's
  56. ;; Webpage:
  57. ;;
  58. ;; http://github.com/jdtsmith/idlwave
  59. ;;
  60. ;; DOCUMENTATION
  61. ;; =============
  62. ;;
  63. ;; IDLWAVE is documented online in info format. A printable version
  64. ;; of the documentation is available from the maintainers webpage (see
  65. ;; SOURCE).
  66. ;;
  67. ;;
  68. ;; ACKNOWLEDGMENTS
  69. ;; ===============
  70. ;;
  71. ;; Thanks to the following people for their contributions and comments:
  72. ;;
  73. ;; Ulrik Dickow <dickow_at_nbi.dk>
  74. ;; Eric E. Dors <edors_at_lanl.gov>
  75. ;; Stein Vidar H. Haugan <s.v.h.haugan_at_astro.uio.no>
  76. ;; David Huenemoerder <dph_at_space.mit.edu>
  77. ;; Kevin Ivory <Kevin.Ivory_at_linmpi.mpg.de>
  78. ;; Dick Jackson <dick_at_d-jackson.com>
  79. ;; Xuyong Liu <liu_at_stsci.edu>
  80. ;; Simon Marshall <Simon.Marshall_at_esrin.esa.it>
  81. ;; Laurent Mugnier <mugnier_at_onera.fr>
  82. ;; Lubos Pochman <lubos_at_rsinc.com>
  83. ;; Bob Portmann <portmann_at_al.noaa.gov>
  84. ;; Patrick M. Ryan <pat_at_jaameri.gsfc.nasa.gov>
  85. ;; Marty Ryba <ryba_at_ll.mit.edu>
  86. ;; Paul Sorenson <aardvark62_at_msn.com>
  87. ;; Phil Sterne <sterne_at_dublin.llnl.gov>
  88. ;; Phil Williams <williams_at_irc.chmcc.org>
  89. ;;
  90. ;; CUSTOMIZATION:
  91. ;; =============
  92. ;;
  93. ;; IDLWAVE has extensive customize support; to learn about the
  94. ;; variables which control the mode's behavior, use `M-x
  95. ;; idlwave-customize'.
  96. ;;
  97. ;; You can set your own preferred values with Customize, or with Lisp
  98. ;; code in .emacs. For an example of what to put into .emacs, check
  99. ;; the TexInfo documentation or see a complete .emacs available at the
  100. ;; website.
  101. ;;
  102. ;; KNOWN PROBLEMS:
  103. ;; ==============
  104. ;;
  105. ;; IDLWAVE support for the IDL-derived PV-WAVE CL language of Visual
  106. ;; Numerics, Inc. is growing less and less complete as the two
  107. ;; languages grow increasingly apart. The mode probably shouldn't
  108. ;; even have "WAVE" in its title, but it's catchy, and was required
  109. ;; to avoid conflict with the CORBA idl.el mode. Caveat WAVEor.
  110. ;;
  111. ;; Moving the point backwards in conjunction with abbrev expansion
  112. ;; does not work as I would like it, but this is a problem with
  113. ;; emacs abbrev expansion done by the self-insert-command. It ends
  114. ;; up inserting the character that expanded the abbrev after moving
  115. ;; point backward, e.g., "\cl" expanded with a space becomes
  116. ;; "LONG( )" with point before the close paren. This is solved by
  117. ;; using a temporary function in `post-command-hook' - not pretty,
  118. ;; but it works.
  119. ;;
  120. ;; Tabs and spaces are treated equally as whitespace when filling a
  121. ;; comment paragraph. To accomplish this, tabs are permanently
  122. ;; replaced by spaces in the text surrounding the paragraph, which
  123. ;; may be an undesirable side-effect. Replacing tabs with spaces is
  124. ;; limited to comments only and occurs only when a comment
  125. ;; paragraph is filled via `idlwave-fill-paragraph'.
  126. ;;
  127. ;; Muti-statement lines (using "&") on block begin and end lines can
  128. ;; ruin the formatting. For example, multiple end statements on a
  129. ;; line: endif & endif. Using "&" outside of block begin/end lines
  130. ;; should be okay.
  131. ;;
  132. ;; Determining the expression at point for printing and other
  133. ;; examination commands is somewhat rough: currently only fairly
  134. ;; simple entities are found. You can always drag-select or examine
  135. ;; a pre-selected region.
  136. ;;
  137. ;; When forcing completion of method keywords, the initial
  138. ;; query for a method has multiple entries for some methods. Would
  139. ;; be too difficult to fix this hardly used case.
  140. ;;
  141. ;;; Code:
  142. (eval-when-compile (require 'cl))
  143. (require 'idlw-help)
  144. ;; For XEmacs
  145. (unless (fboundp 'line-beginning-position)
  146. (defalias 'line-beginning-position 'point-at-bol))
  147. (unless (fboundp 'line-end-position)
  148. (defalias 'line-end-position 'point-at-eol))
  149. (unless (fboundp 'char-valid-p)
  150. (defalias 'char-valid-p 'characterp))
  151. (unless (fboundp 'match-string-no-properties)
  152. (defalias 'match-string-no-properties 'match-string))
  153. (if (not (fboundp 'cancel-timer))
  154. (condition-case nil
  155. (require 'timer)
  156. (error nil)))
  157. (declare-function idlwave-shell-get-path-info "idlw-shell")
  158. (declare-function idlwave-shell-temp-file "idlw-shell")
  159. (declare-function idlwave-shell-is-running "idlw-shell")
  160. (declare-function widget-value "wid-edit" (widget))
  161. (declare-function comint-dynamic-complete-filename "comint" ())
  162. (defgroup idlwave nil
  163. "Major mode for editing IDL .pro files."
  164. :tag "IDLWAVE"
  165. :link '(url-link :tag "Home Page"
  166. "http://github.com/jdtsmith/idlwave")
  167. :link '(emacs-commentary-link :tag "Commentary in idlw-shell.el"
  168. "idlw-shell.el")
  169. :link '(emacs-commentary-link :tag "Commentary in idlwave.el" "idlwave.el")
  170. :link '(custom-manual "(idlwave)Top")
  171. :prefix "idlwave"
  172. :group 'languages)
  173. ;;; Variables for indentation behavior ---------------------------------------
  174. (defgroup idlwave-code-formatting nil
  175. "Indentation and formatting options for IDLWAVE mode."
  176. :group 'idlwave)
  177. (defcustom idlwave-main-block-indent 2
  178. "Extra indentation for the main block of code.
  179. That is the block between the FUNCTION/PRO statement and the END
  180. statement for that program unit."
  181. :group 'idlwave-code-formatting
  182. :type 'integer)
  183. (defcustom idlwave-block-indent 3
  184. "Extra indentation applied to block lines.
  185. If you change this, you probably also want to change `idlwave-end-offset'."
  186. :group 'idlwave-code-formatting
  187. :type 'integer)
  188. (defcustom idlwave-end-offset -3
  189. "Extra indentation applied to block END lines.
  190. A value equal to negative `idlwave-block-indent' will make END lines
  191. line up with the block BEGIN lines."
  192. :group 'idlwave-code-formatting
  193. :type 'integer)
  194. (defcustom idlwave-continuation-indent 3
  195. "Extra indentation applied to continuation lines.
  196. This extra offset applies to the first of a set of continuation lines.
  197. The following lines receive the same indentation as the first."
  198. :group 'idlwave-code-formatting
  199. :type 'integer)
  200. (defcustom idlwave-max-extra-continuation-indent 40
  201. "Maximum additional indentation for special continuation indent.
  202. Several special indentations are tried to help line up continuation
  203. lines in routine calls or definitions, other statements with
  204. parentheses, or assignment statements. This variable specifies a
  205. maximum amount by which this special indentation can exceed the
  206. standard continuation indentation, otherwise defaulting to a fixed
  207. offset. Set to 0 to effectively disable all special continuation
  208. indentation, or to a large number (like 100) to enable it in all
  209. cases. See also `idlwave-indent-to-open-paren', which can override
  210. this variable."
  211. :group 'idlwave-code-formatting
  212. :type 'integer)
  213. (defcustom idlwave-indent-to-open-paren t
  214. "Non-nil means, indent continuation lines to innermost open parenthesis.
  215. This indentation occurs even if otherwise disallowed by
  216. `idlwave-max-extra-continuation-indent'. Matching parens and the
  217. interleaving args are lined up. Example:
  218. x = function_a(function_b(function_c( a, b, [1,2,3, $
  219. 4,5,6 $
  220. ], $
  221. c, d $
  222. )))
  223. When this variable is nil, paren alignment may still occur, based on
  224. the value of `idlwave-max-extra-continuation-indent', which, if zero,
  225. would yield:
  226. x = function_a(function_b(function_c( a, b, [1,2,3, $
  227. 4,5,6 $
  228. ], $
  229. c, d $
  230. )))"
  231. :group 'idlwave-code-formatting
  232. :type 'boolean)
  233. (defcustom idlwave-indent-parens-nested nil
  234. "Non-nil means, indent continuation lines with parens by nesting
  235. lines at consecutively deeper levels."
  236. :group 'idlwave-code-formatting
  237. :type 'boolean)
  238. (defcustom idlwave-hanging-indent t
  239. "If set non-nil then comment paragraphs are indented under the
  240. hanging indent given by `idlwave-hang-indent-regexp' match in the first line
  241. of the paragraph."
  242. :group 'idlwave-code-formatting
  243. :type 'boolean)
  244. (defcustom idlwave-hang-indent-regexp "- "
  245. "Regular expression matching the position of the hanging indent
  246. in the first line of a comment paragraph. The size of the indent
  247. extends to the end of the match for the regular expression."
  248. :group 'idlwave-code-formatting
  249. :type 'regexp)
  250. (defcustom idlwave-use-last-hang-indent nil
  251. "If non-nil then use last match on line for `idlwave-indent-regexp'."
  252. :group 'idlwave-code-formatting
  253. :type 'boolean)
  254. (defcustom idlwave-fill-comment-line-only t
  255. "If non-nil then auto fill will only operate on comment lines."
  256. :group 'idlwave-code-formatting
  257. :type 'boolean)
  258. (defcustom idlwave-auto-fill-split-string t
  259. "If non-nil then auto fill will split strings with the IDL `+' operator.
  260. When the line end falls within a string, string concatenation with the
  261. `+' operator will be used to distribute a long string over lines.
  262. If nil and a string is split then a terminal beep and warning are issued.
  263. This variable is ignored when `idlwave-fill-comment-line-only' is
  264. non-nil, since in this case code is not auto-filled."
  265. :group 'idlwave-code-formatting
  266. :type 'boolean)
  267. (defcustom idlwave-split-line-string t
  268. "If non-nil then `idlwave-split-line' will split strings with `+'.
  269. When the splitting point of a line falls inside a string, split the string
  270. using the `+' string concatenation operator. If nil and a string is
  271. split then a terminal beep and warning are issued."
  272. :group 'idlwave-code-formatting
  273. :type 'boolean)
  274. (defcustom idlwave-no-change-comment ";;;"
  275. "The indentation of a comment that starts with this regular
  276. expression will not be changed. Note that the indentation of a comment
  277. at the beginning of a line is never changed."
  278. :group 'idlwave-code-formatting
  279. :type 'string)
  280. (defcustom idlwave-begin-line-comment nil
  281. "A comment anchored at the beginning of line.
  282. A comment matching this regular expression will not have its
  283. indentation changed. If nil the default is \"^;\", i.e., any line
  284. beginning with a \";\". Expressions for comments at the beginning of
  285. the line should begin with \"^\"."
  286. :group 'idlwave-code-formatting
  287. :type '(choice (const :tag "Any line beginning with `;'" nil)
  288. 'regexp))
  289. (defcustom idlwave-code-comment ";;[^;]"
  290. "A comment that starts with this regular expression on a line by
  291. itself is indented as if it is a part of IDL code. As a result if
  292. the comment is not preceded by whitespace it is unchanged."
  293. :group 'idlwave-code-formatting
  294. :type 'regexp)
  295. ;; Comments not matching any of the above will be indented as a
  296. ;; right-margin comment, i.e., to a minimum of `comment-column'.
  297. ;;; Routine Info and Completion ---------------------------------------
  298. (defgroup idlwave-routine-info nil
  299. "Routine Info options for IDLWAVE mode."
  300. :group 'idlwave)
  301. (defcustom idlwave-use-library-catalogs t
  302. "Non-nil means search the IDL path for library catalog files.
  303. These files, named .idlwave_catalog, document routine information for
  304. individual directories and libraries of IDL .pro files. Many popular
  305. libraries come with catalog files by default, so leaving this on is
  306. usually a good idea."
  307. :group 'idlwave-routine-info
  308. :type 'boolean)
  309. (defcustom idlwave-init-rinfo-when-idle-after 10
  310. "Seconds of idle time before routine info is automatically initialized.
  311. Initializing the routine info can take a long time, in particular if a
  312. large number of library catalogs are involved. When Emacs is idle for
  313. more than the number of seconds specified by this variable, it starts
  314. the initialization. The process is split into five steps, in order to
  315. keep work interruption as short as possible. If one of the steps
  316. finishes, and no user input has arrived in the mean time, initialization
  317. proceeds immediately to the next step. A good value for this variable
  318. is about 1/3 of the time initialization take in your setup. So if you
  319. have a fast machine and no problems with a slow network connection,
  320. don't hesitate to set this to 2 seconds. A value of 0 means, don't
  321. initialize automatically, but instead wait until routine information is
  322. needed, and initialize then."
  323. :group 'idlwave-routine-info
  324. :type 'number)
  325. (defcustom idlwave-scan-all-buffers-for-routine-info t
  326. "Non-nil means, scan buffers for IDL programs when updating info.
  327. The scanning is done by the command `idlwave-update-routine-info'.
  328. The following values are allowed:
  329. nil Don't scan any buffers.
  330. t Scan all `idlwave-mode' buffers in the current editing session.
  331. `current' Scan only the current buffer, but no other buffers."
  332. :group 'idlwave-routine-info
  333. :type '(choice
  334. (const :tag "No buffer" nil)
  335. (const :tag "All buffers" t)
  336. (const :tag "Current buffer only" current)))
  337. (defcustom idlwave-query-shell-for-routine-info t
  338. "Non-nil means query the shell for info about compiled routines.
  339. Querying the shell is useful to get information about compiled modules,
  340. and it is turned on by default. However, when you have a complete library
  341. scan, this is not necessary."
  342. :group 'idlwave-routine-info
  343. :type 'boolean)
  344. (defcustom idlwave-auto-routine-info-updates
  345. '(find-file save-buffer kill-buffer compile-buffer)
  346. "Controls under what circumstances routine info is updated automatically.
  347. Possible values:
  348. nil Never
  349. t All available
  350. \(...) A list of circumstances. Allowed members are:
  351. find-file Add info for new IDLWAVE buffers.
  352. save-buffer Update buffer info when buffer is saved
  353. kill-buffer Remove buffer info when buffer gets killed
  354. compile-buffer Update shell info after `idlwave-shell-save-and...'"
  355. :group 'idlwave-routine-info
  356. :type '(choice
  357. (const :tag "Never" nil)
  358. (const :tag "As often as possible" t)
  359. (set :tag "Checklist" :greedy t
  360. (const :tag "When visiting a file" find-file)
  361. (const :tag "When saving a buffer" save-buffer)
  362. (const :tag "After a buffer was killed" kill-buffer)
  363. (const :tag "After a buffer was compiled successfully, update shell info" compile-buffer))))
  364. (defcustom idlwave-rinfo-max-source-lines 5
  365. "Maximum number of source files displayed in the Routine Info window.
  366. When an integer, it is the maximum number of source files displayed.
  367. A value of t means to show all source files."
  368. :group 'idlwave-routine-info
  369. :type 'integer)
  370. (defcustom idlwave-library-path nil
  371. "Library path for Windows and MacOS (OS9). Not needed under UNIX.
  372. When selecting the directories to scan for IDL user catalog routine
  373. info, IDLWAVE can, under UNIX, query the shell for the exact search
  374. path \(the value of !PATH). However, under Windows and MacOS
  375. \(pre-OSX), the IDLWAVE shell does not work. In this case, this
  376. variable can be set to specify the paths where IDLWAVE can find PRO
  377. files. The shell will only be asked for a list of paths when this
  378. variable is nil. The value is a list of directories. A directory
  379. preceded by a `+' will be searched recursively. If you set this
  380. variable on a UNIX system, the shell will not be queried. See also
  381. `idlwave-system-directory'."
  382. :group 'idlwave-routine-info
  383. :type '(repeat (directory)))
  384. (defcustom idlwave-system-directory ""
  385. "The IDL system directory for Windows and MacOS. Not needed under
  386. UNIX. Set this to the value of the `!DIR' system variable in IDL.
  387. IDLWAVE uses this to find out which of the library routines belong to
  388. the official system library. All files inside the `lib' subdirectory
  389. are considered system library files - so don't install private stuff
  390. in this directory. On UNIX systems, IDLWAVE queries the shell for the
  391. value of `!DIR'. See also `idlwave-library-path'."
  392. :group 'idlwave-routine-info
  393. :type 'directory)
  394. ;; Configuration files
  395. (defcustom idlwave-config-directory
  396. (locate-user-emacs-file "idlwave" ".idlwave")
  397. "Directory for configuration files and user-library catalog."
  398. :version "24.4" ; added locate-user-emacs-file
  399. :group 'idlwave-routine-info
  400. :type 'file)
  401. (defvar idlwave-user-catalog-file "idlusercat.el")
  402. (defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
  403. (defvar idlwave-path-file "idlpath.el")
  404. (defcustom idlwave-special-lib-alist nil
  405. "Alist of regular expressions matching special library directories.
  406. When listing routine source locations, IDLWAVE gives a short hint where
  407. the file defining the routine is located. By default it lists `SystemLib'
  408. for routines in the system library `!DIR/lib' and `Library' for anything
  409. else. This variable can define additional types. The car of each entry
  410. is a regular expression matching the file name (they normally will match
  411. on the path). The cdr is the string to be used as identifier. Max 10
  412. chars are allowed."
  413. :group 'idlwave-routine-info
  414. :type '(repeat
  415. (cons regexp string)))
  416. (defcustom idlwave-auto-write-paths t
  417. "Write out path (!PATH) and system directory (!DIR) info automatically.
  418. Path info is needed to locate library catalog files. If non-nil,
  419. whenever the path-list changes as a result of shell-query, etc., it is
  420. written to file. Otherwise, the menu option \"Write Paths\" can be
  421. used to force a write."
  422. :group 'idlwave-routine-info
  423. :type 'boolean)
  424. (defgroup idlwave-completion nil
  425. "Completion options for IDLWAVE mode."
  426. :prefix "idlwave"
  427. :group 'idlwave)
  428. (eval-and-compile
  429. (defconst idlwave-tmp
  430. '(choice :tag "by applying the function"
  431. (const upcase)
  432. (const downcase)
  433. (const capitalize)
  434. (const preserve)
  435. (symbol :tag "Other"))))
  436. (defcustom idlwave-completion-case '((routine . upcase)
  437. (keyword . upcase)
  438. (class . preserve)
  439. (method . preserve))
  440. "Association list setting the case of completed words.
  441. This variable determines the case (UPPER/lower/Capitalized...) of
  442. words inserted into the buffer by completion. The preferred case can
  443. be specified separately for routine names, keywords, classes and
  444. methods.
  445. This alist should therefore have entries for `routine' (normal
  446. functions and procedures, i.e. non-methods), `keyword', `class', and
  447. `method'. Plausible values are
  448. upcase upcase whole word, like `BOX_CURSOR'
  449. downcase downcase whole word, like `read_ppm'
  450. capitalize capitalize each part, like `Widget_Control'
  451. preserve preserve case as is, like `IDLgrView'
  452. The value can also be any Emacs Lisp function which transforms the
  453. case of characters in a string.
  454. A value of `preserve' means that the case of the completed word is
  455. identical to the way it was written in the definition statement of the
  456. routine. This was implemented to allow for mixed-case completion, in
  457. particular of object classes and methods.
  458. If a completable word is defined in multiple locations, the meaning of
  459. `preserve' is not unique since the different definitions might be
  460. cased differently. Therefore IDLWAVE always takes the case of the
  461. *first* definition it encounters during routine info collection and
  462. uses the case derived from it consistently.
  463. Note that a lowercase-only string in the buffer will always be completed in
  464. lower case (but see the variable `idlwave-completion-force-default-case').
  465. After changing this variable, you need to either restart Emacs or press
  466. `C-u C-c C-i' to update the internal lists."
  467. :group 'idlwave-completion
  468. :type `(repeat
  469. (cons (symbol :tag "Derive completion case for")
  470. ,idlwave-tmp)))
  471. (defcustom idlwave-completion-force-default-case nil
  472. "Non-nil means, completion will always honor `idlwave-completion-case'.
  473. When nil, only the completion of a mixed case or upper case string
  474. will honor the default settings in `idlwave-completion-case', while
  475. the completion of lower case strings will be completed entirely in
  476. lower case."
  477. :group 'idlwave-completion
  478. :type 'boolean)
  479. (defcustom idlwave-complete-empty-string-as-lower-case nil
  480. "Non-nil means, the empty string is considered downcase for completion.
  481. The case of what is already in the buffer determines the case of completions.
  482. When this variable is non-nil, the empty string is considered to be downcase.
  483. Completing on the empty string then offers downcase versions of the possible
  484. completions."
  485. :group 'idlwave-completion
  486. :type 'boolean)
  487. (defcustom idlwave-buffer-case-takes-precedence nil
  488. "Non-nil means, the case of tokens in buffers dominates over system stuff.
  489. To make this possible, we need to re-case everything each time we update
  490. the routine info from the buffers. This is slow.
  491. The default is to consider the case given in the system and library files
  492. first which makes updating much faster."
  493. :group 'idlwave-completion
  494. :type 'boolean)
  495. (defcustom idlwave-highlight-help-links-in-completion t
  496. "Non-nil means, highlight completions for which system help is available.
  497. Help can then be accessed with mouse-3.
  498. This option is only effective when the online help system is installed."
  499. :group 'idlwave-completion
  500. :type 'boolean)
  501. (defcustom idlwave-support-inheritance t
  502. "Non-nil means, treat inheritance with completion, online help etc.
  503. When nil, IDLWAVE only knows about the native methods and tags of a class,
  504. not about inherited ones."
  505. :group 'idlwave-routine-info
  506. :type 'boolean)
  507. (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
  508. "List of regular expressions for class-driven keyword inheritance.
  509. Keyword inheritance is often tied to class inheritance by \"chaining\"
  510. up the class tree. While it cannot be assumed that the presence of an
  511. _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
  512. certain methods this assumption is almost always true. The methods
  513. for which to assume this can be set here."
  514. :group 'idlwave-routine-info
  515. :type '(repeat (regexp :tag "Match method:")))
  516. (defcustom idlwave-completion-show-classes 1
  517. "Number of classes to show when completing object methods and keywords.
  518. When completing methods or keywords for an object with unknown class,
  519. the *Completions* buffer will show the valid classes for each completion
  520. like this:
  521. MyMethod <Class1,Class2,Class3>
  522. The value of this variable may be nil to inhibit display, or an integer to
  523. indicate the maximum number of classes to display.
  524. On XEmacs, a full list of classes will also be placed into a `help-echo'
  525. property on the completion items, so that the list of classes for the current
  526. item is displayed in the echo area. If the value of this variable is a
  527. negative integer, the `help-echo' property will be suppressed."
  528. :group 'idlwave-completion
  529. :type '(choice (const :tag "Don't show" nil)
  530. (integer :tag "Number of classes shown" 1)))
  531. (defcustom idlwave-completion-fontify-classes t
  532. "Non-nil means, fontify the classes in completions buffer.
  533. This makes it easier to distinguish the completion items from the extra
  534. class info listed. See `idlwave-completion-show-classes'."
  535. :group 'idlwave-completion
  536. :type 'boolean)
  537. (defcustom idlwave-query-class '((method-default . nil)
  538. (keyword-default . nil))
  539. "Association list governing specification of object classes for completion.
  540. When IDLWAVE tries to complete object-oriented methods, it usually
  541. cannot determine the class of a given object from context. In order
  542. to provide the user with a correct list of methods or keywords, it
  543. needs to determine the appropriate class. IDLWAVE has two ways of
  544. doing this (well, three ways if you count the shell... see
  545. `idlwave-shell-query-for-class'):
  546. 1. Combine the items of all available classes which contain this
  547. method for the purpose of completion. So when completing a method,
  548. all methods of all known classes are available, and when completing
  549. a keyword, all keywords allowed for this method in any class are
  550. shown. This behavior is very much like normal completion and is
  551. therefore the default. It works much better than one might think -
  552. only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
  553. become uncomfortably long. See also
  554. `idlwave-completion-show-classes'.
  555. 2. The second possibility is to ask the user on each occasion. To
  556. make this less interruptive, IDLWAVE can store the class as a text
  557. property on the object operator `->'. For a given object in the
  558. source code, class selection will then be needed only once
  559. - for example to complete the method. Keywords to the method can
  560. then be completed directly, because the class is already known.
  561. You will have to turn on the storage of the selected class
  562. explicitly with the variable `idlwave-store-inquired-class'.
  563. This variable allows you to configure IDLWAVE's method and
  564. method-keyword completion behavior. Its value is an alist, which
  565. should contain at least two elements: (method-default . VALUE) and
  566. \(keyword-default . VALUE), where VALUE is either t or nil. These
  567. specify if the class should be found during method and keyword
  568. completion, respectively.
  569. The alist may have additional entries specifying exceptions from the
  570. keyword completion rule for specific methods, like INIT or
  571. GETPROPERTY. In order to turn on class specification for the INIT
  572. method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
  573. :group 'idlwave-completion
  574. :type '(list
  575. (cons (const method-default)
  576. (boolean :tag "Determine class when completing METHODS "))
  577. (cons (const keyword-default)
  578. (boolean :tag "Determine class when completing KEYWORDS "))
  579. (repeat
  580. :tag "Exceptions to defaults"
  581. :inline t
  582. (cons (string :tag "MODULE" :value "")
  583. (boolean :tag "Determine class for this method")))))
  584. (defcustom idlwave-store-inquired-class t
  585. "Non-nil means, store class of a method call as text property on `->'.
  586. IDLWAVE sometimes has to ask the user for the class associated with a
  587. particular object method call. This happens during the commands
  588. `idlwave-routine-info' and `idlwave-complete', depending upon the
  589. value of the variable `idlwave-query-class'.
  590. When you specify a class, this information can be stored as a text
  591. property on the `->' arrow in the source code, so that during the same
  592. editing session, IDLWAVE will not have to ask again. When this
  593. variable is non-nil, IDLWAVE will store and reuse the class information.
  594. The class stored can be checked and removed with `\\[idlwave-routine-info]'
  595. on the arrow.
  596. The default of this variable is nil, since the result of commands then
  597. is more predictable. However, if you know what you are doing, it can
  598. be nice to turn this on.
  599. An arrow which knows the class will be highlighted with
  600. `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
  601. displays (with prefix arg: deletes) the class stored on the arrow
  602. at point."
  603. :group 'idlwave-completion
  604. :type 'boolean)
  605. (defcustom idlwave-class-arrow-face 'bold
  606. "Face to highlight object operator arrows `->' which carry a class property.
  607. When IDLWAVE stores a class name as text property on an object arrow
  608. \(see variable `idlwave-store-inquired-class', it highlights the arrow
  609. with this font in order to remind the user that this arrow is special."
  610. :group 'idlwave-completion
  611. :type 'symbol)
  612. (defcustom idlwave-resize-routine-help-window t
  613. "Non-nil means, resize the Routine-info *Help* window to fit the content."
  614. :group 'idlwave-completion
  615. :type 'boolean)
  616. (defcustom idlwave-keyword-completion-adds-equal t
  617. "Non-nil means, completion automatically adds `=' after completed keywords."
  618. :group 'idlwave-completion
  619. :type 'boolean)
  620. (defcustom idlwave-function-completion-adds-paren t
  621. "Non-nil means, completion automatically adds `(' after completed function.
  622. nil means, don't add anything.
  623. A value of `2' means, also add the closing parenthesis and position cursor
  624. between the two."
  625. :group 'idlwave-completion
  626. :type '(choice (const :tag "Nothing" nil)
  627. (const :tag "(" t)
  628. (const :tag "()" 2)))
  629. (defcustom idlwave-completion-restore-window-configuration t
  630. "Non-nil means, try to restore the window configuration after completion.
  631. When completion is not unique, Emacs displays a list of completions.
  632. This messes up your window configuration. With this variable set, IDLWAVE
  633. restores the old configuration after successful completion."
  634. :group 'idlwave-completion
  635. :type 'boolean)
  636. ;;; Variables for abbrev and action behavior -----------------------------
  637. (defgroup idlwave-abbrev-and-indent-action nil
  638. "IDLWAVE performs actions when expanding abbreviations or indenting lines.
  639. The variables in this group govern this."
  640. :group 'idlwave)
  641. (defcustom idlwave-do-actions nil
  642. "Non-nil means performs actions when indenting.
  643. The actions that can be performed are listed in `idlwave-indent-action-table'."
  644. :group 'idlwave-abbrev-and-indent-action
  645. :type 'boolean)
  646. (defcustom idlwave-abbrev-start-char "\\"
  647. "A single character string used to start abbreviations in abbrev mode.
  648. Possible characters to choose from: ~\\=`%
  649. or even `?'. `.' is not a good choice because it can make structure
  650. field names act like abbrevs in certain circumstances.
  651. Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
  652. must set it directly using `setq' in the init file before idlwave.el
  653. is loaded."
  654. :group 'idlwave-abbrev-and-indent-action
  655. :type 'string)
  656. (defcustom idlwave-surround-by-blank nil
  657. "Non-nil means, enable `idlwave-surround'.
  658. If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
  659. `idlwave-surround'.
  660. See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
  661. Also see the default key bindings for keys using `idlwave-surround'.
  662. Keys are bound and made into actions calling `idlwave-surround' with
  663. `idlwave-action-and-binding'.
  664. See help for `idlwave-action-and-binding' for examples.
  665. Also see help for `idlwave-surround'."
  666. :group 'idlwave-abbrev-and-indent-action
  667. :type 'boolean)
  668. (defcustom idlwave-pad-keyword t
  669. "Non-nil means pad `=' in keywords (routine calls or defs) like assignment.
  670. Whenever `idlwave-surround' is non-nil then this affects how `=' is
  671. padded for keywords and for variables. If t, pad the same as for
  672. assignments. If nil then spaces are removed. With any other value,
  673. spaces are left unchanged."
  674. :group 'idlwave-abbrev-and-indent-action
  675. :type '(choice
  676. (const :tag "Pad like assignments" t)
  677. (const :tag "Remove space near `='" nil)
  678. (other :tag "Keep space near `='" keep)))
  679. (defcustom idlwave-show-block t
  680. "Non-nil means point blinks to block beginning for `idlwave-show-begin'."
  681. :group 'idlwave-abbrev-and-indent-action
  682. :type 'boolean)
  683. (defcustom idlwave-expand-generic-end nil
  684. "Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
  685. :group 'idlwave-abbrev-and-indent-action
  686. :type 'boolean)
  687. (defcustom idlwave-reindent-end t
  688. "Non-nil means re-indent line after END was typed."
  689. :group 'idlwave-abbrev-and-indent-action
  690. :type 'boolean)
  691. (defcustom idlwave-abbrev-move t
  692. "Non-nil means the abbrev hook can move point.
  693. Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
  694. definitions, use the command `list-abbrevs', for abbrevs that move
  695. point. Moving point is useful, for example, to place point between
  696. parentheses of expanded functions.
  697. See `idlwave-check-abbrev'."
  698. :group 'idlwave-abbrev-and-indent-action
  699. :type 'boolean)
  700. (defcustom idlwave-abbrev-change-case nil
  701. "Non-nil means all abbrevs will be forced to either upper or lower case.
  702. If the value t, all expanded abbrevs will be upper case.
  703. If the value is 'down then abbrevs will be forced to lower case.
  704. If nil, the case will not change.
  705. If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
  706. upper case, regardless of this variable."
  707. :group 'idlwave-abbrev-and-indent-action
  708. :type 'boolean)
  709. (defcustom idlwave-reserved-word-upcase nil
  710. "Non-nil means, reserved words will be made upper case via abbrev expansion.
  711. If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
  712. Has effect only if in abbrev-mode."
  713. :group 'idlwave-abbrev-and-indent-action
  714. :type 'boolean)
  715. ;;; Action/Expand Tables.
  716. ;;
  717. ;; The average user may have difficulty modifying this directly. It
  718. ;; can be modified/set in idlwave-mode-hook, but it is easier to use
  719. ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
  720. ;; examples of how to add an action.
  721. ;;
  722. ;; The action table is used by `idlwave-indent-line' whereas both the
  723. ;; action and expand tables are used by `idlwave-indent-and-action'. In
  724. ;; general, the expand table is only used when a line is explicitly
  725. ;; indented. Whereas, in addition to being used when the expand table
  726. ;; is used, the action table is used when a line is indirectly
  727. ;; indented via line splitting, auto-filling or a new line creation.
  728. ;;
  729. ;; Example actions:
  730. ;;
  731. ;; Capitalize system vars
  732. ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
  733. ;;
  734. ;; Capitalize procedure name
  735. ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
  736. ;; '(capitalize-word 1) t)
  737. ;;
  738. ;; Capitalize common block name
  739. ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
  740. ;; '(capitalize-word 1) t)
  741. ;; Capitalize label
  742. ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
  743. ;; '(capitalize-word -1) t)
  744. (defvar idlwave-indent-action-table nil
  745. "Associated array containing action lists of search string (car),
  746. and function as a cdr. This table is used by `idlwave-indent-line'.
  747. See documentation for `idlwave-do-action' for a complete description of
  748. the action lists.
  749. Additions to the table are made with `idlwave-action-and-binding' when a
  750. binding is not requested.
  751. See help on `idlwave-action-and-binding' for examples.")
  752. (defvar idlwave-indent-expand-table nil
  753. "Associated array containing action lists of search string (car),
  754. and function as a cdr. The table is used by the
  755. `idlwave-indent-and-action' function. See documentation for
  756. `idlwave-do-action' for a complete description of the action lists.
  757. Additions to the table are made with `idlwave-action-and-binding' when a
  758. binding is requested.
  759. See help on `idlwave-action-and-binding' for examples.")
  760. ;;; Documentation header and history keyword ---------------------------------
  761. (defgroup idlwave-documentation nil
  762. "Options for documenting IDLWAVE files."
  763. :group 'idlwave)
  764. ;; FIXME: make defcustom?
  765. (defvar idlwave-file-header
  766. (list nil
  767. ";+
  768. ; NAME:
  769. ;
  770. ;
  771. ;
  772. ; PURPOSE:
  773. ;
  774. ;
  775. ;
  776. ; CATEGORY:
  777. ;
  778. ;
  779. ;
  780. ; CALLING SEQUENCE:
  781. ;
  782. ;
  783. ;
  784. ; INPUTS:
  785. ;
  786. ;
  787. ;
  788. ; OPTIONAL INPUTS:
  789. ;
  790. ;
  791. ;
  792. ; KEYWORD PARAMETERS:
  793. ;
  794. ;
  795. ;
  796. ; OUTPUTS:
  797. ;
  798. ;
  799. ;
  800. ; OPTIONAL OUTPUTS:
  801. ;
  802. ;
  803. ;
  804. ; COMMON BLOCKS:
  805. ;
  806. ;
  807. ;
  808. ; SIDE EFFECTS:
  809. ;
  810. ;
  811. ;
  812. ; RESTRICTIONS:
  813. ;
  814. ;
  815. ;
  816. ; PROCEDURE:
  817. ;
  818. ;
  819. ;
  820. ; EXAMPLE:
  821. ;
  822. ;
  823. ;
  824. ; MODIFICATION HISTORY:
  825. ;
  826. ;-
  827. ")
  828. "A list (PATHNAME STRING) specifying the doc-header template to use for
  829. summarizing a file. If PATHNAME is non-nil then this file will be included.
  830. Otherwise STRING is used. If nil, the file summary will be omitted.
  831. For example you might set PATHNAME to the path for the
  832. lib_template.pro file included in the IDL distribution.")
  833. (defcustom idlwave-header-to-beginning-of-file t
  834. "Non-nil means, the documentation header will always be at start of file.
  835. When nil, the header is positioned between the PRO/FUNCTION line of
  836. the current routine and the code, allowing several routine headers in
  837. a file."
  838. :group 'idlwave-documentation
  839. :type 'boolean)
  840. (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
  841. "The hook function used to update the timestamp of a function."
  842. :group 'idlwave-documentation
  843. :type 'function)
  844. (defcustom idlwave-doc-modifications-keyword "HISTORY"
  845. "The modifications keyword to use with the log documentation commands.
  846. A ':' is added to the keyword end.
  847. Inserted by doc-header and used to position logs by doc-modification.
  848. If nil it will not be inserted."
  849. :group 'idlwave-documentation
  850. :type 'string)
  851. (defcustom idlwave-doclib-start "^;+\\+"
  852. "Regexp matching the start of a document library header."
  853. :group 'idlwave-documentation
  854. :type 'regexp)
  855. (defcustom idlwave-doclib-end "^;+-"
  856. "Regexp matching the end of a document library header."
  857. :group 'idlwave-documentation
  858. :type 'regexp)
  859. ;;; External Programs -------------------------------------------------------
  860. (defgroup idlwave-external-programs nil
  861. "Path locations of external commands used by IDLWAVE."
  862. :group 'idlwave)
  863. (defcustom idlwave-shell-explicit-file-name "idl"
  864. "If non-nil, this is the command to run IDL.
  865. Should be an absolute file path or path relative to the current environment
  866. execution search path. If you want to specify command line switches
  867. for the IDL program, use `idlwave-shell-command-line-options'.
  868. I know the name of this variable is badly chosen, but I cannot change
  869. it without compromising backwards-compatibility."
  870. :group 'idlwave-external-programs
  871. :type 'string)
  872. (defcustom idlwave-shell-command-line-options nil
  873. "A list of command line options for calling the IDL program.
  874. Since IDL is executed directly without going through a shell like /bin/sh,
  875. this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
  876. string for each argument. But you may also give a single string which
  877. contains the options whitespace-separated. Emacs will be kind enough to
  878. split it for you."
  879. :type '(choice
  880. string
  881. (repeat (string :value "")))
  882. :group 'idlwave-external-programs)
  883. (defcustom idlwave-help-application "idlhelp"
  884. "The external application providing reference help for programming.
  885. Obsolete, if the IDL Assistant is being used for help."
  886. :group 'idlwave-external-programs
  887. :type 'string)
  888. ;;; Some Shell variables which must be defined here.-----------------------
  889. (defcustom idlwave-shell-debug-modifiers '()
  890. "List of modifiers to be used for the debugging commands.
  891. Will be used to bind debugging commands in the shell buffer and in all
  892. source buffers. These are additional convenience bindings, the debugging
  893. commands are always available with the `C-c C-d' prefix.
  894. If you set this to '(control shift), this means setting a breakpoint will
  895. be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
  896. are `control', `meta', `super', `hyper', `alt', and `shift'."
  897. :group 'idlwave-shell-general-setup
  898. :type '(set :tag "Specify modifiers"
  899. (const control)
  900. (const meta)
  901. (const super)
  902. (const hyper)
  903. (const alt)
  904. (const shift)))
  905. (defcustom idlwave-shell-automatic-start nil
  906. "If non-nil attempt invoke `idlwave-shell' if not already running.
  907. This is checked when an attempt to send a command to an
  908. IDL process is made."
  909. :group 'idlwave-shell-general-setup
  910. :type 'boolean)
  911. ;;; Miscellaneous variables -------------------------------------------------
  912. (defgroup idlwave-misc nil
  913. "Miscellaneous options for IDLWAVE mode."
  914. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  915. :group 'idlwave)
  916. (defcustom idlwave-startup-message t
  917. "Non-nil displays a startup message when `idlwave-mode' is first called."
  918. :group 'idlwave-misc
  919. :type 'boolean)
  920. (defcustom idlwave-default-font-lock-items
  921. '(pros-and-functions batch-files idlwave-idl-keywords label goto
  922. common-blocks class-arrows)
  923. "Items which should be fontified on the default fontification level 2.
  924. IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
  925. is everything and level 2 is specified by this list.
  926. This variable must be set before IDLWAVE gets loaded.
  927. It is a list of symbols; the following symbols are allowed:
  928. pros-and-functions Procedure and Function definitions
  929. batch-files Batch Files
  930. idlwave-idl-keywords IDL Keywords
  931. label Statement Labels
  932. goto Goto Statements
  933. common-blocks Common Blocks
  934. keyword-parameters Keyword Parameters in routine definitions and calls
  935. system-variables System Variables
  936. fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
  937. class-arrows Object Arrows with class property"
  938. :group 'idlwave-misc
  939. :type '(set
  940. :inline t :greedy t
  941. (const :tag "Procedure and Function definitions" pros-and-functions)
  942. (const :tag "Batch Files" batch-files)
  943. (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
  944. (const :tag "Statement Labels" label)
  945. (const :tag "Goto Statements" goto)
  946. (const :tag "Tags in Structure Definition" structtag)
  947. (const :tag "Structure Name" structname)
  948. (const :tag "Common Blocks" common-blocks)
  949. (const :tag "Keyword Parameters" keyword-parameters)
  950. (const :tag "System Variables" system-variables)
  951. (const :tag "FIXME: Warning" fixme)
  952. (const :tag "Object Arrows with class property " class-arrows)))
  953. (defcustom idlwave-mode-hook nil
  954. "Normal hook. Executed when a buffer is put into `idlwave-mode'."
  955. :group 'idlwave-misc
  956. :type 'hook)
  957. (defcustom idlwave-load-hook nil
  958. "Normal hook. Executed when idlwave.el is loaded."
  959. :group 'idlwave-misc
  960. :type 'hook)
  961. (defvar idlwave-experimental nil
  962. "Non-nil means turn on a few experimental features.
  963. This variable is only for the maintainer, to test difficult stuff,
  964. while still distributing stable releases.
  965. As a user, you should not set this to t.")
  966. ;;;
  967. ;;; End customization variables section
  968. ;;;
  969. ;;; Non customization variables
  970. ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
  971. ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
  972. ;;; and Carsten Dominik...
  973. ;; The following are the reserved words in IDL. Maybe we should
  974. ;; highlight some more stuff as well?
  975. ;; Procedure declarations. Fontify keyword plus procedure name.
  976. (defvar idlwave-idl-keywords
  977. ;; To update this regexp, update the list of keywords and
  978. ;; evaluate the form.
  979. ;; (insert
  980. ;; (prin1-to-string
  981. ;; (concat
  982. ;; "\\<\\("
  983. ;; (regexp-opt
  984. ;; '("||" "&&" "and" "or" "xor" "not"
  985. ;; "eq" "ge" "gt" "le" "lt" "ne"
  986. ;; "for" "do" "endfor"
  987. ;; "if" "then" "endif" "else" "endelse"
  988. ;; "case" "of" "endcase"
  989. ;; "switch" "break" "continue" "endswitch"
  990. ;; "begin" "end"
  991. ;; "repeat" "until" "endrep"
  992. ;; "while" "endwhile"
  993. ;; "goto" "return"
  994. ;; "inherits" "mod"
  995. ;; "compile_opt" "forward_function"
  996. ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
  997. ;; "\\)\\>")))
  998. "\\<\\(&&\\|and\\|b\\(egin\\|reak\\)\\|c\\(ase\\|o\\(mpile_opt\\|ntinue\\)\\)\\|do\\|e\\(lse\\|nd\\(case\\|else\\|for\\|if\\|rep\\|switch\\|while\\)?\\|q\\)\\|for\\(ward_function\\)?\\|g\\(oto\\|[et]\\)\\|i\\(f\\|nherits\\)\\|l[et]\\|mod\\|n\\(e\\|ot\\)\\|o\\(n_\\(error\\|ioerror\\)\\|[fr]\\)\\|re\\(peat\\|turn\\)\\|switch\\|then\\|until\\|while\\|xor\\|||\\)\\>")
  999. (let* (;; Procedure declarations. Fontify keyword plus procedure name.
  1000. ;; Function declarations. Fontify keyword plus function name.
  1001. (pros-and-functions
  1002. '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
  1003. (1 font-lock-keyword-face)
  1004. (2 font-lock-function-name-face nil t)))
  1005. ;; Common blocks
  1006. (common-blocks
  1007. '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
  1008. (1 font-lock-keyword-face) ; "common"
  1009. (2 font-lock-constant-face nil t) ; block name
  1010. ("[ \t]*\\(\\sw+\\)[ ,]*"
  1011. ;; Start with point after block name and comma
  1012. (goto-char (match-end 0)) ; needed for XEmacs, could be nil
  1013. nil
  1014. (1 font-lock-variable-name-face) ; variable names
  1015. )))
  1016. ;; Batch files
  1017. (batch-files
  1018. '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
  1019. ;; FIXME warning.
  1020. (fixme
  1021. '("\\<FIXME:" (0 font-lock-warning-face t)))
  1022. ;; Labels
  1023. (label
  1024. '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-constant-face)))
  1025. ;; The goto statement and its label
  1026. (goto
  1027. '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
  1028. (1 font-lock-keyword-face)
  1029. (2 font-lock-constant-face)))
  1030. ;; Tags in structure definitions. Note that this definition
  1031. ;; actually collides with labels, so we have to use the same
  1032. ;; face. It also matches named subscript ranges,
  1033. ;; e.g. vec{bottom:top]. No good way around this.
  1034. (structtag
  1035. '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-constant-face)))
  1036. ;; Structure names
  1037. (structname
  1038. '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
  1039. (2 font-lock-function-name-face)))
  1040. ;; Keyword parameters, like /xlog or ,xrange=[]
  1041. ;; This is anchored to the comma preceding the keyword.
  1042. ;; Treats continuation lines, works only during whole buffer
  1043. ;; fontification. Slow, use it only in fancy fontification.
  1044. (keyword-parameters
  1045. '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
  1046. (6 font-lock-constant-face)))
  1047. ;; System variables start with a bang.
  1048. (system-variables
  1049. '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
  1050. (1 font-lock-variable-name-face)))
  1051. ;; Special and unusual operators (not used because too noisy)
  1052. ;; (special-operators
  1053. ;; '("[<>#]" (0 font-lock-keyword-face)))
  1054. ;; All operators (not used because too noisy)
  1055. ;; (all-operators
  1056. ;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
  1057. ;; Arrows with text property `idlwave-class'
  1058. (class-arrows
  1059. '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
  1060. (defconst idlwave-font-lock-keywords-1
  1061. (list pros-and-functions batch-files)
  1062. "Subdued level highlighting for IDLWAVE mode.")
  1063. (defconst idlwave-font-lock-keywords-2
  1064. (mapcar 'symbol-value idlwave-default-font-lock-items)
  1065. "Medium level highlighting for IDLWAVE mode.")
  1066. (defconst idlwave-font-lock-keywords-3
  1067. (list pros-and-functions
  1068. batch-files
  1069. idlwave-idl-keywords
  1070. label goto
  1071. structtag
  1072. structname
  1073. common-blocks
  1074. keyword-parameters
  1075. system-variables
  1076. class-arrows)
  1077. "Gaudy level highlighting for IDLWAVE mode."))
  1078. (defun idlwave-match-class-arrows (limit)
  1079. ;; Match an object arrow with class property
  1080. (and idlwave-store-inquired-class
  1081. (re-search-forward "->" limit 'limit)
  1082. (get-text-property (match-beginning 0) 'idlwave-class)))
  1083. (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
  1084. "Default expressions to highlight in IDLWAVE mode.")
  1085. (defvar idlwave-font-lock-defaults
  1086. '((idlwave-font-lock-keywords
  1087. idlwave-font-lock-keywords-1
  1088. idlwave-font-lock-keywords-2
  1089. idlwave-font-lock-keywords-3)
  1090. nil t
  1091. ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
  1092. beginning-of-line))
  1093. (put 'idlwave-mode 'font-lock-defaults
  1094. idlwave-font-lock-defaults) ; XEmacs
  1095. (defconst idlwave-comment-line-start-skip "^[ \t]*;"
  1096. "Regexp to match the start of a full-line comment.
  1097. That is the _beginning_ of a line containing a comment delimiter `;' preceded
  1098. only by whitespace.")
  1099. (defconst idlwave-begin-block-reg
  1100. "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
  1101. "Regular expression to find the beginning of a block.
  1102. The case does not matter. The search skips matches in comments.")
  1103. (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
  1104. "Regular expression to find the beginning of a unit.
  1105. The case does not matter.")
  1106. (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
  1107. "Regular expression to find the line that indicates the end of unit.
  1108. This line is the end of buffer or the start of another unit.
  1109. The case does not matter. The search skips matches in comments.")
  1110. (defconst idlwave-continue-line-reg "\\<\\$"
  1111. "Regular expression to match a continued line.")
  1112. (defconst idlwave-end-block-reg
  1113. "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
  1114. "Regular expression to find the end of a block.
  1115. The case does not matter. The search skips matches in comments.")
  1116. (defconst idlwave-block-matches
  1117. '(("pro" . "end")
  1118. ("function" . "end")
  1119. ("case" . "endcase")
  1120. ("else" . "endelse")
  1121. ("for" . "endfor")
  1122. ("then" . "endif")
  1123. ("repeat" . "endrep")
  1124. ("switch" . "endswitch")
  1125. ("while" . "endwhile"))
  1126. "Matches between statements and the corresponding END variant.
  1127. The cars are the reserved words starting a block. If the block really
  1128. begins with BEGIN, the cars are the reserved words before the begin
  1129. which can be used to identify the block type.
  1130. This is used to check for the correct END type, to close blocks and
  1131. to expand generic end statements to their detailed form.")
  1132. (defconst idlwave-block-match-regexp
  1133. "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
  1134. "Regular expression matching reserved words which can stand before
  1135. blocks starting with a BEGIN statement. The matches must have associations
  1136. `idlwave-block-matches'.")
  1137. (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
  1138. "Regular expression matching an IDL identifier.")
  1139. (defconst idlwave-sysvar (concat "!" idlwave-identifier)
  1140. "Regular expression matching IDL system variables.")
  1141. (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
  1142. "Regular expression matching IDL variable names.")
  1143. (defconst idlwave-label (concat idlwave-identifier ":")
  1144. "Regular expression matching IDL labels.")
  1145. (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
  1146. "\\(\\s *" idlwave-identifier "::\\)?"
  1147. ))
  1148. (defconst idlwave-statement-match
  1149. (list
  1150. ;; "endif else" is the only possible "end" that can be
  1151. ;; followed by a statement on the same line.
  1152. '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
  1153. ;; all other "end"s can not be followed by a statement.
  1154. (cons 'end (list idlwave-end-block-reg nil))
  1155. '(if . ("if\\>" "then"))
  1156. '(for . ("for\\>" "do"))
  1157. '(begin . ("begin\\>" nil))
  1158. '(pdef . ("pro\\>\\|function\\>" nil))
  1159. '(while . ("while\\>" "do"))
  1160. '(repeat . ("repeat\\>" "repeat"))
  1161. '(goto . ("goto\\>" nil))
  1162. '(case . ("case\\>" nil))
  1163. '(switch . ("switch\\>" nil))
  1164. (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
  1165. "\\(" idlwave-method-call "\\s *\\)?"
  1166. idlwave-identifier
  1167. "\\s *(") nil))
  1168. (cons 'call (list (concat
  1169. "\\(" idlwave-method-call "\\s *\\)?"
  1170. idlwave-identifier
  1171. "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
  1172. (cons 'assign (list (concat
  1173. "\\(" idlwave-variable "\\) *=") nil)))
  1174. "Associated list of statement matching regular expressions.
  1175. Each regular expression matches the start of an IDL statement.
  1176. The first element of each association is a symbol giving the statement
  1177. type. The associated value is a list. The first element of this list
  1178. is a regular expression matching the start of an IDL statement for
  1179. identifying the statement type. The second element of this list is a
  1180. regular expression for finding a substatement for the type. The
  1181. substatement starts after the end of the found match modulo
  1182. whitespace. If it is nil then the statement has no substatement. The
  1183. list order matters since matching an assignment statement exactly is
  1184. not possible without parsing. Thus assignment statement become just
  1185. the leftover unidentified statements containing an equal sign.")
  1186. ;; FIXME: This var seems to only ever be set, but never actually used!
  1187. (defvar idlwave-fill-function 'auto-fill-function
  1188. "IDL mode auto fill function.")
  1189. (defvar idlwave-comment-indent-function 'comment-indent-function
  1190. "IDL mode comment indent function.")
  1191. ;; Note that this is documented in the v18 manuals as being a string
  1192. ;; of length one rather than a single character.
  1193. ;; The code in this file accepts either format for compatibility.
  1194. (defvar idlwave-comment-indent-char ?\
  1195. "Character to be inserted for IDL comment indentation.
  1196. Normally a space.")
  1197. (defconst idlwave-continuation-char ?$
  1198. "Character which is inserted as a last character on previous line by
  1199. \\[idlwave-split-line] to begin a continuation line. Normally $.")
  1200. (defconst idlwave-mode-version "6.1_em22")
  1201. (defmacro idlwave-keyword-abbrev (&rest args)
  1202. "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
  1203. `(quote (lambda ()
  1204. ,(append '(idlwave-check-abbrev) args))))
  1205. ;; If I take the time I can replace idlwave-keyword-abbrev with
  1206. ;; idlwave-code-abbrev and remove the quoted abbrev check from
  1207. ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
  1208. ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
  1209. ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
  1210. (defmacro idlwave-code-abbrev (&rest args)
  1211. "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
  1212. Specifically, if the abbrev is in a comment or string it is unexpanded.
  1213. Otherwise ARGS forms a list that is evaluated."
  1214. ;; FIXME: it would probably be better to rely on the new :enable-function
  1215. ;; to enforce the "don't expand in comments or strings".
  1216. `(lambda ()
  1217. ,(prin1-to-string args) ;; Puts the code in the doc string
  1218. (if (idlwave-quoted)
  1219. (progn (unexpand-abbrev) nil)
  1220. ,(append args))))
  1221. (autoload 'idlwave-shell "idlw-shell"
  1222. "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
  1223. (autoload 'idlwave-shell-send-command "idlw-shell")
  1224. (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
  1225. "Run `idlwave-shell' and switch back to current window" t)
  1226. (autoload 'idlwave-shell-save-and-run "idlw-shell"
  1227. "Save and run buffer under the shell." t)
  1228. (autoload 'idlwave-shell-break-here "idlw-shell"
  1229. "Set breakpoint in current line." t)
  1230. (autoload 'idlwave-shell-run-region "idlw-shell"
  1231. "Compile and run the region." t)
  1232. (fset 'idlwave-debug-map (make-sparse-keymap))
  1233. (defvar idlwave-mode-map
  1234. (let ((map (make-sparse-keymap)))
  1235. (define-key map "\C-c " 'idlwave-hard-tab)
  1236. (define-key map [(control tab)] 'idlwave-hard-tab)
  1237. ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
  1238. (define-key map "'" 'idlwave-show-matching-quote)
  1239. (define-key map "\"" 'idlwave-show-matching-quote)
  1240. (define-key map "\C-g" 'idlwave-keyboard-quit)
  1241. (define-key map "\C-c;" 'idlwave-toggle-comment-region)
  1242. (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
  1243. (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
  1244. (define-key map "\C-c{" 'idlwave-beginning-of-block)
  1245. (define-key map "\C-c}" 'idlwave-end-of-block)
  1246. (define-key map "\C-c]" 'idlwave-close-block)
  1247. (define-key map [(meta control h)] 'idlwave-mark-subprogram)
  1248. (define-key map "\M-\C-n" 'idlwave-forward-block)
  1249. (define-key map "\M-\C-p" 'idlwave-backward-block)
  1250. (define-key map "\M-\C-d" 'idlwave-down-block)
  1251. (define-key map "\M-\C-u" 'idlwave-backward-up-block)
  1252. (define-key map "\M-\r" 'idlwave-split-line)
  1253. (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
  1254. (define-key map "\C-c\C-p" 'idlwave-previous-statement)
  1255. (define-key map "\C-c\C-n" 'idlwave-next-statement)
  1256. ;; (define-key map "\r" 'idlwave-newline)
  1257. ;; (define-key map "\t" 'idlwave-indent-line)
  1258. (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
  1259. (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
  1260. (define-key map "\M-q" 'idlwave-fill-paragraph)
  1261. (define-key map "\M-s" 'idlwave-edit-in-idlde)
  1262. (define-key map "\C-c\C-h" 'idlwave-doc-header)
  1263. (define-key map "\C-c\C-m" 'idlwave-doc-modification)
  1264. (define-key map "\C-c\C-c" 'idlwave-case)
  1265. (define-key map "\C-c\C-d" 'idlwave-debug-map)
  1266. (when (and (listp idlwave-shell-debug-modifiers)
  1267. (not (equal idlwave-shell-debug-modifiers '())))
  1268. ;; Bind the debug commands also with the special modifiers.
  1269. (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
  1270. (mods-noshift
  1271. (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
  1272. (define-key map
  1273. (vector (append mods-noshift (list (if shift ?C ?c))))
  1274. 'idlwave-shell-save-and-run)
  1275. (define-key map
  1276. (vector (append mods-noshift (list (if shift ?B ?b))))
  1277. 'idlwave-shell-break-here)
  1278. (define-key map
  1279. (vector (append mods-noshift (list (if shift ?E ?e))))
  1280. 'idlwave-shell-run-region)))
  1281. (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
  1282. (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
  1283. (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
  1284. (define-key map "\C-c\C-f" 'idlwave-for)
  1285. ;; (define-key map "\C-c\C-f" 'idlwave-function)
  1286. ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
  1287. (define-key map "\C-c\C-r" 'idlwave-repeat)
  1288. (define-key map "\C-c\C-w" 'idlwave-while)
  1289. (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
  1290. (define-key map "\C-c\C-s" 'idlwave-shell)
  1291. (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
  1292. (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
  1293. (define-key map "\C-c\C-v" 'idlwave-find-module)
  1294. (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
  1295. (define-key map "\C-c?" 'idlwave-routine-info)
  1296. (define-key map "\M-?" 'idlwave-context-help)
  1297. (define-key map [(control meta ?\?)]
  1298. 'idlwave-help-assistant-help-with-topic)
  1299. ;; Pickup both forms of Esc/Meta binding
  1300. (define-key map [(meta tab)] 'idlwave-complete)
  1301. (define-key map [?\e?\t] 'idlwave-complete)
  1302. (define-key map "\M-\C-i" 'idlwave-complete)
  1303. (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
  1304. (define-key map "\C-c=" 'idlwave-resolve)
  1305. (define-key map
  1306. (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
  1307. 'idlwave-mouse-context-help)
  1308. map)
  1309. "Keymap used in IDL mode.")
  1310. (defvar idlwave-mode-syntax-table
  1311. (let ((st (make-syntax-table)))
  1312. (modify-syntax-entry ?+ "." st)
  1313. (modify-syntax-entry ?- "." st)
  1314. (modify-syntax-entry ?* "." st)
  1315. (modify-syntax-entry ?/ "." st)
  1316. (modify-syntax-entry ?^ "." st)
  1317. (modify-syntax-entry ?# "." st)
  1318. (modify-syntax-entry ?= "." st)
  1319. (modify-syntax-entry ?% "." st)
  1320. (modify-syntax-entry ?< "." st)
  1321. (modify-syntax-entry ?> "." st)
  1322. (modify-syntax-entry ?\' "\"" st)
  1323. (modify-syntax-entry ?\" "\"" st)
  1324. (modify-syntax-entry ?\\ "." st)
  1325. (modify-syntax-entry ?_ "_" st)
  1326. (modify-syntax-entry ?{ "(}" st)
  1327. (modify-syntax-entry ?} "){" st)
  1328. (modify-syntax-entry ?$ "_" st)
  1329. (modify-syntax-entry ?. "." st)
  1330. (modify-syntax-entry ?\; "<" st)
  1331. (modify-syntax-entry ?\n ">" st)
  1332. (modify-syntax-entry ?\f ">" st)
  1333. st)
  1334. "Syntax table in use in `idlwave-mode' buffers.")
  1335. (defvar idlwave-find-symbol-syntax-table
  1336. (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
  1337. (modify-syntax-entry ?$ "w" st)
  1338. (modify-syntax-entry ?_ "w" st)
  1339. (modify-syntax-entry ?! "w" st)
  1340. (modify-syntax-entry ?. "w" st)
  1341. st)
  1342. "Syntax table that treats symbol characters as word characters.")
  1343. (defmacro idlwave-with-special-syntax (&rest body)
  1344. "Execute BODY with a different syntax table."
  1345. `(let ((saved-syntax (syntax-table)))
  1346. (unwind-protect
  1347. (progn
  1348. (set-syntax-table idlwave-find-symbol-syntax-table)
  1349. ,@body)
  1350. (set-syntax-table saved-syntax))))
  1351. ;(defmacro idlwave-with-special-syntax1 (&rest body)
  1352. ; "Execute BODY with a different syntax table."
  1353. ; `(let ((saved-syntax (syntax-table)))
  1354. ; (unwind-protect
  1355. ; (progn
  1356. ; (set-syntax-table idlwave-find-symbol-syntax-table)
  1357. ; ,@body)
  1358. ; (set-syntax-table saved-syntax))))
  1359. (defun idlwave-action-and-binding (key cmd &optional select)
  1360. "KEY and CMD are made into a key binding and an indent action.
  1361. KEY is a string - same as for the `define-key' function. CMD is a
  1362. function of no arguments or a list to be evaluated. CMD is bound to
  1363. KEY in `idlwave-mode-map' by defining an anonymous function calling
  1364. `self-insert-command' followed by CMD. If KEY contains more than one
  1365. character a binding will only be set if SELECT is 'both.
  1366. \(KEY . CMD) is also placed in the `idlwave-indent-expand-table',
  1367. replacing any previous value for KEY. If a binding is not set then it
  1368. will instead be placed in `idlwave-indent-action-table'.
  1369. If the optional argument SELECT is nil then an action and binding are
  1370. created. If SELECT is 'noaction, then a binding is always set and no
  1371. action is created. If SELECT is 'both then an action and binding
  1372. will both be created even if KEY contains more than one character.
  1373. Otherwise, if SELECT is non-nil then only an action is created.
  1374. Some examples:
  1375. No spaces before and 1 after a comma
  1376. (idlwave-action-and-binding \",\" \\='(idlwave-surround 0 1))
  1377. A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
  1378. (idlwave-action-and-binding \"=\" \\='(idlwave-expand-equal -1 -1))
  1379. Capitalize system variables - action only
  1380. (idlwave-action-and-binding idlwave-sysvar \\='(capitalize-word 1) t)"
  1381. (if (not (equal select 'noaction))
  1382. ;; Add action
  1383. (let* ((table (if select 'idlwave-indent-action-table
  1384. 'idlwave-indent-expand-table))
  1385. (table-key (regexp-quote key))
  1386. (cell (assoc table-key (eval table))))
  1387. (if cell
  1388. ;; Replace action command
  1389. (setcdr cell cmd)
  1390. ;; New action
  1391. (set table (append (eval table) (list (cons table-key cmd)))))))
  1392. ;; Make key binding for action
  1393. (if (or (and (null select) (= (length key) 1))
  1394. (equal select 'noaction)
  1395. (equal select 'both))
  1396. (define-key idlwave-mode-map key
  1397. `(lambda ()
  1398. (interactive)
  1399. (self-insert-command 1)
  1400. ,(if (listp cmd) cmd (list cmd))))))
  1401. ;; Set action and key bindings.
  1402. ;; See description of the function `idlwave-action-and-binding'.
  1403. ;; Automatically add spaces for the following characters
  1404. ;; Actions for & are complicated by &&
  1405. (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
  1406. ;; Automatically add spaces to equal sign if not keyword. This needs
  1407. ;; to go ahead of > and <, so >= and <= will be treated correctly
  1408. (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
  1409. ;; Actions for > and < are complicated by >=, <=, and ->...
  1410. (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
  1411. (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
  1412. (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
  1413. ;;;
  1414. ;;; Abbrev Section
  1415. ;;;
  1416. ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
  1417. ;;; space is inserted (this is the space typed by the user to expanded
  1418. ;;; the abbrev).
  1419. ;;;
  1420. (defvar idlwave-mode-abbrev-table nil
  1421. "Abbreviation table used for IDLWAVE mode.")
  1422. (define-abbrev-table 'idlwave-mode-abbrev-table ())
  1423. (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
  1424. "Define-abbrev with backward compatibility.
  1425. If NOPREFIX is non-nil, don't prepend prefix character. Installs into
  1426. `idlwave-mode-abbrev-table' unless TABLE is non-nil."
  1427. (let ((abbrevs-changed nil) ;; mask the current value to avoid save
  1428. (args (list (or table idlwave-mode-abbrev-table)
  1429. (if noprefix name (concat idlwave-abbrev-start-char name))
  1430. expansion
  1431. hook)))
  1432. (condition-case nil
  1433. (apply 'define-abbrev (append args '(0 t)))
  1434. (error (apply 'define-abbrev args)))))
  1435. (condition-case nil
  1436. (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
  1437. "w" idlwave-mode-syntax-table)
  1438. (error nil))
  1439. ;;
  1440. ;; Templates
  1441. ;;
  1442. (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
  1443. (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
  1444. (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
  1445. (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
  1446. (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
  1447. (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
  1448. (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
  1449. (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
  1450. (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
  1451. ;;
  1452. ;; Keywords, system functions, conversion routines
  1453. ;;
  1454. (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
  1455. (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
  1456. (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
  1457. (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
  1458. (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
  1459. (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
  1460. (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
  1461. (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
  1462. (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
  1463. (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
  1464. (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
  1465. (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
  1466. (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
  1467. (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
  1468. (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
  1469. (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
  1470. (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
  1471. (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
  1472. (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
  1473. (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
  1474. (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
  1475. (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
  1476. (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
  1477. (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
  1478. (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
  1479. (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
  1480. (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
  1481. (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
  1482. (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
  1483. (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
  1484. (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
  1485. (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
  1486. (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
  1487. (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
  1488. (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
  1489. (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
  1490. (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
  1491. (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
  1492. (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
  1493. (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
  1494. (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
  1495. (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
  1496. (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
  1497. (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
  1498. (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
  1499. (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
  1500. (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
  1501. (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
  1502. (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
  1503. (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
  1504. (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
  1505. (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
  1506. (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
  1507. (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
  1508. (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
  1509. (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
  1510. ;; This section is reserved words only. (From IDL user manual)
  1511. ;;
  1512. (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
  1513. (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
  1514. (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
  1515. (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
  1516. (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
  1517. (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
  1518. (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
  1519. (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
  1520. (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
  1521. (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
  1522. (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
  1523. (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
  1524. (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
  1525. (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
  1526. (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
  1527. (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
  1528. (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
  1529. (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
  1530. (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
  1531. (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
  1532. (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
  1533. (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
  1534. (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
  1535. (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
  1536. (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
  1537. (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
  1538. (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
  1539. (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
  1540. (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
  1541. (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
  1542. (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
  1543. (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
  1544. (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
  1545. (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
  1546. (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
  1547. (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
  1548. (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
  1549. (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
  1550. (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
  1551. (defvar imenu-create-index-function)
  1552. (defvar extract-index-name-function)
  1553. (defvar prev-index-position-function)
  1554. (defvar imenu-extract-index-name-function)
  1555. (defvar imenu-prev-index-position-function)
  1556. ;; defined later - so just make the compiler hush
  1557. (defvar idlwave-mode-menu)
  1558. (defvar idlwave-mode-debug-menu)
  1559. ;;;###autoload
  1560. (define-derived-mode idlwave-mode prog-mode "IDLWAVE"
  1561. "Major mode for editing IDL source files (version 6.1_em22).
  1562. The main features of this mode are
  1563. 1. Indentation and Formatting
  1564. --------------------------
  1565. Like other Emacs programming modes, C-j inserts a newline and indents.
  1566. TAB is used for explicit indentation of the current line.
  1567. To start a continuation line, use \\[idlwave-split-line]. This
  1568. function can also be used in the middle of a line to split the line
  1569. at that point. When used inside a long constant string, the string
  1570. is split at that point with the `+' concatenation operator.
  1571. Comments are indented as follows:
  1572. `;;;' Indentation remains unchanged.
  1573. `;;' Indent like the surrounding code
  1574. `;' Indent to a minimum column.
  1575. The indentation of comments starting in column 0 is never changed.
  1576. Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
  1577. comment. The indentation of the second line of the paragraph
  1578. relative to the first will be retained. Use
  1579. \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
  1580. comments. When the variable `idlwave-fill-comment-line-only' is
  1581. nil, code can also be auto-filled and auto-indented.
  1582. To convert pre-existing IDL code to your formatting style, mark the
  1583. entire buffer with \\[mark-whole-buffer] and execute
  1584. \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
  1585. again followed by \\[indent-region] (`indent-region').
  1586. 2. Routine Info
  1587. ------------
  1588. IDLWAVE displays information about the calling sequence and the
  1589. accepted keyword parameters of a procedure or function with
  1590. \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
  1591. source file of a module. These commands know about system
  1592. routines, all routines in idlwave-mode buffers and (when the
  1593. idlwave-shell is active) about all modules currently compiled under
  1594. this shell. It also makes use of pre-compiled or custom-scanned
  1595. user and library catalogs many popular libraries ship with by
  1596. default. Use \\[idlwave-update-routine-info] to update this
  1597. information, which is also used for completion (see item 4).
  1598. 3. Online IDL Help
  1599. ---------------
  1600. \\[idlwave-context-help] displays the IDL documentation relevant
  1601. for the system variable, keyword, or routines at point. A single
  1602. key stroke gets you directly to the right place in the docs. See
  1603. the manual to configure where and how the HTML help is displayed.
  1604. 4. Completion
  1605. ----------
  1606. \\[idlwave-complete] completes the names of procedures, functions
  1607. class names, keyword parameters, system variables and tags, class
  1608. tags, structure tags, filenames and much more. It is context
  1609. sensitive and figures out what is expected at point. Lower case
  1610. strings are completed in lower case, other strings in mixed or
  1611. upper case.
  1612. 5. Code Templates and Abbreviations
  1613. --------------------------------
  1614. Many Abbreviations are predefined to expand to code fragments and templates.
  1615. The abbreviations start generally with a `\\'. Some examples:
  1616. \\pr PROCEDURE template
  1617. \\fu FUNCTION template
  1618. \\c CASE statement template
  1619. \\sw SWITCH statement template
  1620. \\f FOR loop template
  1621. \\r REPEAT Loop template
  1622. \\w WHILE loop template
  1623. \\i IF statement template
  1624. \\elif IF-ELSE statement template
  1625. \\b BEGIN
  1626. For a full list, use \\[idlwave-list-abbrevs]. Some templates also
  1627. have direct keybindings - see the list of keybindings below.
  1628. \\[idlwave-doc-header] inserts a documentation header at the
  1629. beginning of the current program unit (pro, function or main).
  1630. Change log entries can be added to the current program unit with
  1631. \\[idlwave-doc-modification].
  1632. 6. Automatic Case Conversion
  1633. -------------------------
  1634. The case of reserved words and some abbrevs is controlled by
  1635. `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
  1636. 7. Automatic END completion
  1637. ------------------------
  1638. If the variable `idlwave-expand-generic-end' is non-nil, each END typed
  1639. will be converted to the specific version, like ENDIF, ENDFOR, etc.
  1640. 8. Hooks
  1641. -----
  1642. Loading idlwave.el runs `idlwave-load-hook'.
  1643. Turning on `idlwave-mode' runs `idlwave-mode-hook'.
  1644. 9. Documentation and Customization
  1645. -------------------------------
  1646. Info documentation for this package is available. Use
  1647. \\[idlwave-info] to display (complain to your sysadmin if that does
  1648. not work). For Postscript, PDF, and HTML versions of the
  1649. documentation, check IDLWAVE's homepage at URL
  1650. `http://github.com/jdtsmith/idlwave'.
  1651. IDLWAVE has customize support - see the group `idlwave'.
  1652. 10.Keybindings
  1653. -----------
  1654. Here is a list of all keybindings of this mode.
  1655. If some of the key bindings below show with ??, use \\[describe-key]
  1656. followed by the key sequence to see what the key sequence does.
  1657. \\{idlwave-mode-map}"
  1658. :abbrev-table idlwave-mode-abbrev-table
  1659. (if idlwave-startup-message
  1660. (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
  1661. (setq idlwave-startup-message nil)
  1662. (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
  1663. (set (make-local-variable idlwave-comment-indent-function)
  1664. #'idlwave-comment-hook)
  1665. (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
  1666. (set (make-local-variable 'comment-start) ";")
  1667. (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
  1668. (set (make-local-variable 'abbrev-all-caps) t)
  1669. (set (make-local-variable 'indent-tabs-mode) nil)
  1670. (set (make-local-variable 'completion-ignore-case) t)
  1671. (when (featurep 'easymenu)
  1672. (easy-menu-add idlwave-mode-menu idlwave-mode-map)
  1673. (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
  1674. (setq abbrev-mode t)
  1675. (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
  1676. (setq comment-end "")
  1677. (set (make-local-variable 'comment-multi-line) nil)
  1678. (set (make-local-variable 'paragraph-separate)
  1679. "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
  1680. (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
  1681. (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
  1682. (set (make-local-variable 'parse-sexp-ignore-comments) t)
  1683. ;; ChangeLog
  1684. (set (make-local-variable 'add-log-current-defun-function)
  1685. 'idlwave-current-routine-fullname)
  1686. ;; Set tag table list to use IDLTAGS as file name.
  1687. (if (boundp 'tag-table-alist)
  1688. (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
  1689. ;; Font-lock additions
  1690. ;; Following line is for Emacs - XEmacs uses the corresponding property
  1691. ;; on the `idlwave-mode' symbol.
  1692. (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
  1693. (set (make-local-variable 'font-lock-mark-block-function)
  1694. 'idlwave-mark-subprogram)
  1695. (set (make-local-variable 'font-lock-fontify-region-function)
  1696. 'idlwave-font-lock-fontify-region)
  1697. ;; Imenu setup
  1698. (set (make-local-variable 'imenu-create-index-function)
  1699. 'imenu-default-create-index-function)
  1700. (set (make-local-variable 'imenu-extract-index-name-function)
  1701. 'idlwave-unit-name)
  1702. (set (make-local-variable 'imenu-prev-index-position-function)
  1703. 'idlwave-prev-index-position)
  1704. ;; HideShow setup
  1705. (add-to-list 'hs-special-modes-alist
  1706. (list 'idlwave-mode
  1707. idlwave-begin-block-reg
  1708. idlwave-end-block-reg
  1709. ";"
  1710. 'idlwave-forward-block nil))
  1711. ;; Make a local post-command-hook and add our hook to it
  1712. ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
  1713. ;; (make-local-hook 'post-command-hook)
  1714. (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
  1715. ;; Make local hooks for buffer updates
  1716. ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
  1717. ;; (make-local-hook 'kill-buffer-hook)
  1718. (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
  1719. ;; (make-local-hook 'after-save-hook)
  1720. (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
  1721. (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
  1722. ;; Setup directories and file, if necessary
  1723. (idlwave-setup)
  1724. ;; Update the routine info with info about current buffer?
  1725. (idlwave-new-buffer-update)
  1726. ;; Check help location
  1727. (idlwave-help-check-locations))
  1728. (defvar idlwave-setup-done nil)
  1729. (defun idlwave-setup ()
  1730. (unless idlwave-setup-done
  1731. (if (not (file-directory-p idlwave-config-directory))
  1732. (make-directory idlwave-config-directory))
  1733. (setq
  1734. idlwave-user-catalog-file (expand-file-name
  1735. idlwave-user-catalog-file
  1736. idlwave-config-directory)
  1737. idlwave-xml-system-rinfo-converted-file
  1738. (expand-file-name
  1739. idlwave-xml-system-rinfo-converted-file
  1740. idlwave-config-directory)
  1741. idlwave-path-file (expand-file-name
  1742. idlwave-path-file
  1743. idlwave-config-directory))
  1744. (idlwave-read-paths) ; we may need these early
  1745. (setq idlwave-setup-done t)))
  1746. (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
  1747. "Fontify continuation lines correctly."
  1748. (let (pos)
  1749. (save-excursion
  1750. (goto-char beg)
  1751. (forward-line -1)
  1752. (when (setq pos (idlwave-is-continuation-line))
  1753. (goto-char pos)
  1754. (idlwave-beginning-of-statement)
  1755. (setq beg (point)))))
  1756. (font-lock-default-fontify-region beg end verbose))
  1757. ;;
  1758. ;; Code Formatting ----------------------------------------------------
  1759. ;;
  1760. (defun idlwave-hard-tab ()
  1761. "Insert TAB in buffer in current position."
  1762. (interactive)
  1763. (insert "\t"))
  1764. ;;; This stuff is experimental
  1765. (defvar idlwave-command-hook nil
  1766. "If non-nil, a list that can be evaluated using `eval'.
  1767. It is evaluated in the lisp function `idlwave-command-hook' which is
  1768. placed in `post-command-hook'.")
  1769. (defun idlwave-command-hook ()
  1770. "Command run after every command.
  1771. Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
  1772. sets the variable to zero afterwards."
  1773. (and idlwave-command-hook
  1774. (listp idlwave-command-hook)
  1775. (condition-case nil
  1776. (eval idlwave-command-hook)
  1777. (error nil)))
  1778. (setq idlwave-command-hook nil))
  1779. ;;; End experiment
  1780. ;; It would be better to use expand.el for better abbrev handling and
  1781. ;; versatility.
  1782. (defun idlwave-check-abbrev (arg &optional reserved)
  1783. "Reverse abbrev expansion if in comment or string.
  1784. Argument ARG is the number of characters to move point
  1785. backward if `idlwave-abbrev-move' is non-nil.
  1786. If optional argument RESERVED is non-nil then the expansion
  1787. consists of reserved words, which will be capitalized if
  1788. `idlwave-reserved-word-upcase' is non-nil.
  1789. Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
  1790. is non-nil, unless its value is `down' in which case the abbrev will be
  1791. made into all lowercase.
  1792. Returns non-nil if abbrev is left expanded."
  1793. (if (idlwave-quoted)
  1794. (progn (unexpand-abbrev)
  1795. nil)
  1796. (if (and reserved idlwave-reserved-word-upcase)
  1797. (upcase-region last-abbrev-location (point))
  1798. (cond
  1799. ((equal idlwave-abbrev-change-case 'down)
  1800. (downcase-region last-abbrev-location (point)))
  1801. (idlwave-abbrev-change-case
  1802. (upcase-region last-abbrev-location (point)))))
  1803. (if (and idlwave-abbrev-move (> arg 0))
  1804. (if (boundp 'post-command-hook)
  1805. (setq idlwave-command-hook (list 'backward-char (1+ arg)))
  1806. (backward-char arg)))
  1807. t))
  1808. (defun idlwave-in-comment ()
  1809. "Return t if point is inside a comment, nil otherwise."
  1810. (save-excursion
  1811. (let ((here (point)))
  1812. (and (idlwave-goto-comment) (> here (point))))))
  1813. (defun idlwave-goto-comment ()
  1814. "Move to start of comment delimiter on current line.
  1815. Moves to end of line if there is no comment delimiter.
  1816. Ignores comment delimiters in strings.
  1817. Returns point if comment found and nil otherwise."
  1818. (let ((eos (point-at-eol))
  1819. (data (match-data))
  1820. found)
  1821. ;; Look for first comment delimiter not in a string
  1822. (beginning-of-line)
  1823. (setq found (search-forward comment-start eos 'lim))
  1824. (while (and found (idlwave-in-quote))
  1825. (setq found (search-forward comment-start eos 'lim)))
  1826. (store-match-data data)
  1827. (and found (not (idlwave-in-quote))
  1828. (progn
  1829. (backward-char 1)
  1830. (point)))))
  1831. (defun idlwave-region-active-p ()
  1832. "Should we operate on an active region?"
  1833. (if (fboundp 'use-region-p)
  1834. (use-region-p)
  1835. (region-active-p)))
  1836. (defun idlwave-show-matching-quote ()
  1837. "Insert quote and show matching quote if this is end of a string."
  1838. (interactive)
  1839. (let ((bq (idlwave-in-quote))
  1840. (inq last-command-event))
  1841. (if (and bq (not (idlwave-in-comment)))
  1842. (let ((delim (char-after bq)))
  1843. (insert inq)
  1844. (if (eq inq delim)
  1845. (save-excursion
  1846. (goto-char bq)
  1847. (sit-for 1))))
  1848. ;; Not the end of a string
  1849. (insert inq))))
  1850. (defun idlwave-show-begin-check ()
  1851. "Ensure that the previous word was a token before `idlwave-show-begin'.
  1852. An END token must be preceded by whitespace."
  1853. (if (not (idlwave-quoted))
  1854. (if
  1855. (save-excursion
  1856. (backward-word 1)
  1857. (backward-char 1)
  1858. (looking-at "[ \t\n\f]"))
  1859. (idlwave-show-begin))))
  1860. (defun idlwave-show-begin ()
  1861. "Find the start of current block and blinks to it for a second.
  1862. Also checks if the correct END statement has been used."
  1863. ;; All end statements are reserved words
  1864. ;; Re-indent end line
  1865. ;;(insert-char ?\ 1) ;; So indent, etc. work well
  1866. ;;(backward-char 1)
  1867. (let* ((pos (point-marker))
  1868. (last-abbrev-marker (copy-marker last-abbrev-location))
  1869. (eol-pos (point-at-eol))
  1870. begin-pos end-pos end end1 )
  1871. (if idlwave-reindent-end (idlwave-indent-line))
  1872. (setq last-abbrev-location (marker-position last-abbrev-marker))
  1873. (when (and (idlwave-check-abbrev 0 t)
  1874. idlwave-show-block)
  1875. (save-excursion
  1876. ;; Move inside current block
  1877. (goto-char last-abbrev-marker)
  1878. (idlwave-block-jump-out -1 'nomark)
  1879. (setq begin-pos (point))
  1880. (idlwave-block-jump-out 1 'nomark)
  1881. (setq end-pos (point))
  1882. (if (> end-pos eol-pos)
  1883. (setq end-pos pos))
  1884. (goto-char end-pos)
  1885. (setq end (buffer-substring
  1886. (progn
  1887. (skip-chars-backward "a-zA-Z")
  1888. (point))
  1889. end-pos))
  1890. (goto-char begin-pos)
  1891. (when (setq end1 (cdr (idlwave-block-master)))
  1892. (cond
  1893. ((null end1)) ; no-operation
  1894. ((string= (downcase end) (downcase end1))
  1895. (sit-for 1))
  1896. ((string= (downcase end) "end")
  1897. ;; A generic end
  1898. (if idlwave-expand-generic-end
  1899. (save-excursion
  1900. (goto-char pos)
  1901. (backward-char 3)
  1902. (insert (if (string= end "END") (upcase end1) end1))
  1903. (delete-char 3)))
  1904. (sit-for 1))
  1905. (t
  1906. (beep)
  1907. (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
  1908. end1 end)
  1909. (sit-for 1))))))))
  1910. ;;(delete-char 1))
  1911. (defun idlwave-block-master ()
  1912. (let ((case-fold-search t))
  1913. (save-excursion
  1914. (cond
  1915. ((looking-at "pro\\|case\\|switch\\|function\\>")
  1916. (assoc (downcase (match-string 0)) idlwave-block-matches))
  1917. ((looking-at "begin\\>")
  1918. (let ((limit (save-excursion
  1919. (idlwave-beginning-of-statement)
  1920. (point))))
  1921. (cond
  1922. ((re-search-backward ":[ \t]*\\=" limit t)
  1923. ;; seems to be a case thing
  1924. '("begin" . "end"))
  1925. ((re-search-backward idlwave-block-match-regexp limit t)
  1926. (assoc (downcase (match-string 1))
  1927. idlwave-block-matches))
  1928. (t
  1929. ;; Just a normal block
  1930. '("begin" . "end")))))
  1931. (t nil)))))
  1932. (defun idlwave-close-block ()
  1933. "Terminate the current block with the correct END statement."
  1934. (interactive)
  1935. ;; Start new line if we are not in a new line
  1936. (unless (save-excursion
  1937. (skip-chars-backward " \t")
  1938. (bolp))
  1939. (let ((idlwave-show-block nil))
  1940. (newline-and-indent)))
  1941. (let ((last-abbrev-location (point))) ; for upcasing
  1942. (insert "end")
  1943. (idlwave-show-begin)))
  1944. (defun idlwave-custom-ampersand-surround (&optional is-action)
  1945. "Surround &, leaving room for && (which surround as well)."
  1946. (let* ((prev-char (char-after (- (point) 2)))
  1947. (next-char (char-after (point)))
  1948. (amp-left (eq prev-char ?&))
  1949. (amp-right (eq next-char ?&))
  1950. (len (if amp-left 2 1)))
  1951. (unless amp-right ;no need to do it twice, amp-left will catch it.
  1952. (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
  1953. (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
  1954. "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
  1955. (let* ((prev-char (char-after (- (point) 2)))
  1956. (next-char (char-after (point)))
  1957. (method-invoke (and gtr (eq prev-char ?-)))
  1958. (len (if method-invoke 2 1)))
  1959. (unless (eq next-char ?=)
  1960. ;; Key binding: pad only on left, to save for possible >=/<=
  1961. (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
  1962. (defun idlwave-surround (&optional before after length is-action)
  1963. "Surround the LENGTH characters before point with blanks.
  1964. LENGTH defaults to 1.
  1965. Optional arguments BEFORE and AFTER affect the behavior before and
  1966. after the characters (see also description of `idlwave-make-space'):
  1967. nil do nothing
  1968. 0 force no spaces
  1969. integer > 0 force exactly n spaces
  1970. integer < 0 at least |n| spaces
  1971. The function does nothing if any of the following conditions is true:
  1972. - `idlwave-surround-by-blank' is nil
  1973. - the character before point is inside a string or comment"
  1974. (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
  1975. (let ((length (or length 1))) ; establish a default for LENGTH
  1976. (backward-char length)
  1977. (save-restriction
  1978. (let ((here (point)))
  1979. (skip-chars-backward " \t")
  1980. (if (bolp)
  1981. ;; avoid clobbering indent
  1982. (progn
  1983. (move-to-column (idlwave-calculate-indent))
  1984. (if (<= (point) here)
  1985. (narrow-to-region (point) here))
  1986. (goto-char here)))
  1987. (idlwave-make-space before))
  1988. (skip-chars-forward " \t"))
  1989. (forward-char length)
  1990. (idlwave-make-space after)
  1991. ;; Check to see if the line should auto wrap
  1992. (if (and (equal (char-after (1- (point))) ?\ )
  1993. (> (current-column) fill-column))
  1994. (funcall auto-fill-function)))))
  1995. (defun idlwave-make-space (n)
  1996. "Make space at point.
  1997. The space affected is all the spaces and tabs around point.
  1998. If n is non-nil then point is left abs(n) spaces from the beginning of
  1999. the contiguous space.
  2000. The amount of space at point is determined by N.
  2001. If the value of N is:
  2002. nil - do nothing.
  2003. > 0 - exactly N spaces.
  2004. < 0 - a minimum of -N spaces, i.e., do not change if there are
  2005. already -N spaces.
  2006. 0 - no spaces (i.e. remove any existing space)."
  2007. (if (integerp n)
  2008. (let
  2009. ((start-col (progn (skip-chars-backward " \t") (current-column)))
  2010. (left (point))
  2011. (end-col (progn (skip-chars-forward " \t") (current-column))))
  2012. (delete-horizontal-space)
  2013. (cond
  2014. ((> n 0)
  2015. (idlwave-indent-to (+ start-col n))
  2016. (goto-char (+ left n)))
  2017. ((< n 0)
  2018. (idlwave-indent-to end-col (- n))
  2019. (goto-char (- left n)))
  2020. ;; n = 0, done
  2021. ))))
  2022. (defun idlwave-newline ()
  2023. "Insert a newline and indent the current and previous line."
  2024. (interactive)
  2025. ;;
  2026. ;; Handle unterminated single and double quotes
  2027. ;; If not in a comment and in a string then insertion of a newline
  2028. ;; will mean unbalanced quotes.
  2029. ;;
  2030. (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
  2031. (progn (beep)
  2032. (message "Warning: unbalanced quotes?")))
  2033. (newline)
  2034. ;;
  2035. ;; The current line is being split, the cursor should be at the
  2036. ;; beginning of the new line skipping the leading indentation.
  2037. ;;
  2038. ;; The reason we insert the new line before indenting is that the
  2039. ;; indenting could be confused by keywords (e.g. END) on the line
  2040. ;; after the split point. This prevents us from just using
  2041. ;; `indent-for-tab-command' followed by `newline-and-indent'.
  2042. ;;
  2043. (beginning-of-line 0)
  2044. (idlwave-indent-line)
  2045. (forward-line)
  2046. (idlwave-indent-line))
  2047. ;;
  2048. ;; Use global variable 'comment-column' to set parallel comment
  2049. ;;
  2050. ;; Modeled on lisp.el
  2051. ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
  2052. (defun idlwave-comment-hook ()
  2053. "Compute indent for the beginning of the IDL comment delimiter."
  2054. (if (or (looking-at idlwave-no-change-comment)
  2055. (looking-at (or idlwave-begin-line-comment "^;")))
  2056. (current-column)
  2057. (if (looking-at idlwave-code-comment)
  2058. (if (save-excursion (skip-chars-backward " \t") (bolp))
  2059. ;; On line by itself, indent as code
  2060. (let ((tem (idlwave-calculate-indent)))
  2061. (if (listp tem) (car tem) tem))
  2062. ;; after code - do not change
  2063. (current-column))
  2064. (skip-chars-backward " \t")
  2065. (max (if (bolp) 0 (1+ (current-column)))
  2066. comment-column))))
  2067. (defun idlwave-split-line ()
  2068. "Continue line by breaking line at point and indent the lines.
  2069. For a code line insert continuation marker. If the line is a line comment
  2070. then the new line will contain a comment with the same indentation.
  2071. Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
  2072. non-nil."
  2073. (interactive)
  2074. ;; Expand abbreviation, just like normal RET would.
  2075. (and abbrev-mode (expand-abbrev))
  2076. (let (beg)
  2077. (if (not (idlwave-in-comment))
  2078. ;; For code line add continuation.
  2079. ;; Check if splitting a string.
  2080. (progn
  2081. (if (setq beg (idlwave-in-quote))
  2082. (if idlwave-split-line-string
  2083. ;; Split the string.
  2084. (progn (insert (setq beg (char-after beg)) " + "
  2085. idlwave-continuation-char beg)
  2086. (backward-char 1)
  2087. (newline-and-indent)
  2088. (forward-char 1))
  2089. ;; Do not split the string.
  2090. (beep)
  2091. (message "Warning: continuation inside string!!")
  2092. (insert " " idlwave-continuation-char))
  2093. ;; Not splitting a string.
  2094. (if (not (member (char-before) '(?\ ?\t)))
  2095. (insert " "))
  2096. (insert idlwave-continuation-char)
  2097. (newline-and-indent)))
  2098. (indent-new-comment-line))
  2099. ;; Indent previous line
  2100. (setq beg (- (point-max) (point)))
  2101. (forward-line -1)
  2102. (idlwave-indent-line)
  2103. (goto-char (- (point-max) beg))
  2104. ;; Reindent new line
  2105. (idlwave-indent-line)))
  2106. (defun idlwave-beginning-of-subprogram (&optional nomark)
  2107. "Move point to the beginning of the current program unit.
  2108. If NOMARK is non-nil, do not push mark."
  2109. (interactive)
  2110. (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
  2111. (defun idlwave-end-of-subprogram (&optional nomark)
  2112. "Move point to the start of the next program unit.
  2113. If NOMARK is non-nil, do not push mark."
  2114. (interactive)
  2115. (idlwave-end-of-statement)
  2116. (idlwave-find-key idlwave-end-unit-reg 1 nomark))
  2117. (defun idlwave-mark-statement ()
  2118. "Mark current IDL statement."
  2119. (interactive)
  2120. (idlwave-end-of-statement)
  2121. (let ((end (point)))
  2122. (idlwave-beginning-of-statement)
  2123. (push-mark end nil t)))
  2124. (defun idlwave-mark-block ()
  2125. "Mark containing block."
  2126. (interactive)
  2127. (idlwave-end-of-statement)
  2128. (idlwave-backward-up-block -1)
  2129. (idlwave-end-of-statement)
  2130. (let ((end (point)))
  2131. (idlwave-backward-block)
  2132. (idlwave-beginning-of-statement)
  2133. (push-mark end nil t)))
  2134. (defun idlwave-mark-subprogram ()
  2135. "Put mark at beginning of program, point at end.
  2136. The marks are pushed."
  2137. (interactive)
  2138. (idlwave-end-of-statement)
  2139. (idlwave-beginning-of-subprogram)
  2140. (let ((beg (point)))
  2141. (idlwave-forward-block)
  2142. (push-mark beg nil t))
  2143. (exchange-point-and-mark))
  2144. (defun idlwave-backward-up-block (&optional arg)
  2145. "Move to beginning of enclosing block if prefix ARG >= 0.
  2146. If prefix ARG < 0 then move forward to enclosing block end."
  2147. (interactive "p")
  2148. (idlwave-block-jump-out (- arg) 'nomark))
  2149. (defun idlwave-beginning-of-block ()
  2150. "Go to the beginning of the current block."
  2151. (interactive)
  2152. (idlwave-block-jump-out -1 'nomark)
  2153. (forward-word 1))
  2154. (defun idlwave-end-of-block ()
  2155. "Go to the beginning of the current block."
  2156. (interactive)
  2157. (idlwave-block-jump-out 1 'nomark)
  2158. (backward-word 1))
  2159. (defun idlwave-forward-block (&optional arg)
  2160. "Move across next nested block."
  2161. (interactive)
  2162. (let ((arg (or arg 1)))
  2163. (if (idlwave-down-block arg)
  2164. (idlwave-block-jump-out arg 'nomark))))
  2165. (defun idlwave-backward-block ()
  2166. "Move backward across previous nested block."
  2167. (interactive)
  2168. (if (idlwave-down-block -1)
  2169. (idlwave-block-jump-out -1 'nomark)))
  2170. (defun idlwave-down-block (&optional arg)
  2171. "Go down a block.
  2172. With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
  2173. Returns non-nil if successful."
  2174. (interactive "p")
  2175. (let (status)
  2176. (if (< arg 0)
  2177. ;; Backward
  2178. (let ((eos (save-excursion
  2179. (idlwave-block-jump-out -1 'nomark)
  2180. (point))))
  2181. (if (setq status (idlwave-find-key
  2182. idlwave-end-block-reg -1 'nomark eos))
  2183. (idlwave-beginning-of-statement)
  2184. (message "No nested block before beginning of containing block.")))
  2185. ;; Forward
  2186. (let ((eos (save-excursion
  2187. (idlwave-block-jump-out 1 'nomark)
  2188. (point))))
  2189. (if (setq status (idlwave-find-key
  2190. idlwave-begin-block-reg 1 'nomark eos))
  2191. (idlwave-end-of-statement)
  2192. (message "No nested block before end of containing block."))))
  2193. status))
  2194. (defun idlwave-mark-doclib ()
  2195. "Put point at beginning of doc library header, mark at end.
  2196. The marks are pushed."
  2197. (interactive)
  2198. (let (beg
  2199. (here (point)))
  2200. (goto-char (point-max))
  2201. (if (re-search-backward idlwave-doclib-start nil t)
  2202. (progn
  2203. (setq beg (progn (beginning-of-line) (point)))
  2204. (if (re-search-forward idlwave-doclib-end nil t)
  2205. (progn
  2206. (forward-line 1)
  2207. (push-mark beg nil t)
  2208. (message "Could not find end of doc library header.")))
  2209. (message "Could not find doc library header start.")
  2210. (goto-char here)))))
  2211. (defun idlwave-current-routine-fullname ()
  2212. (let ((name (idlwave-current-routine)))
  2213. (idlwave-make-full-name (nth 2 name) (car name))))
  2214. (defun idlwave-current-routine ()
  2215. "Return (NAME TYPE CLASS) of current routine."
  2216. (idlwave-routines)
  2217. (save-excursion
  2218. (idlwave-beginning-of-subprogram 'nomark)
  2219. (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
  2220. (let* ((type (if (string= (downcase (match-string 1)) "pro")
  2221. 'pro 'function))
  2222. (class (idlwave-sintern-class (match-string 3)))
  2223. (name (idlwave-sintern-routine-or-method (match-string 4) class)))
  2224. (list name type class)))))
  2225. (defvar idlwave-shell-prompt-pattern)
  2226. (defun idlwave-beginning-of-statement ()
  2227. "Move to beginning of the current statement.
  2228. Skips back past statement continuations.
  2229. Point is placed at the beginning of the line whether or not this is an
  2230. actual statement."
  2231. (interactive)
  2232. (cond
  2233. ((derived-mode-p 'idlwave-shell-mode)
  2234. (if (re-search-backward idlwave-shell-prompt-pattern nil t)
  2235. (goto-char (match-end 0))))
  2236. (t
  2237. (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
  2238. (idlwave-previous-statement)
  2239. (beginning-of-line)))))
  2240. (defun idlwave-previous-statement ()
  2241. "Move point to beginning of the previous statement.
  2242. Returns t if the current line before moving is the beginning of
  2243. the first non-comment statement in the file, and nil otherwise."
  2244. (interactive)
  2245. (let (first-statement)
  2246. (if (not (= (forward-line -1) 0))
  2247. ;; first line in file
  2248. t
  2249. ;; skip blank lines, label lines, include lines and line comments
  2250. (while (and
  2251. ;; The current statement is the first statement until we
  2252. ;; reach another statement.
  2253. (setq first-statement
  2254. (or
  2255. (looking-at idlwave-comment-line-start-skip)
  2256. (looking-at "[ \t]*$")
  2257. (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
  2258. (looking-at "^@")))
  2259. (= (forward-line -1) 0)))
  2260. ;; skip continuation lines
  2261. (while (and
  2262. (save-excursion
  2263. (forward-line -1)
  2264. (idlwave-is-continuation-line))
  2265. (= (forward-line -1) 0)))
  2266. first-statement)))
  2267. (defun idlwave-end-of-statement ()
  2268. "Move point to the end of the current IDL statement.
  2269. If not in a statement just moves to end of line. Returns position."
  2270. (interactive)
  2271. (while (and (idlwave-is-continuation-line)
  2272. (= (forward-line 1) 0))
  2273. (while (and (idlwave-is-comment-or-empty-line)
  2274. (= (forward-line 1) 0))))
  2275. (end-of-line)
  2276. (point))
  2277. (defun idlwave-end-of-statement0 ()
  2278. "Move point to the end of the current IDL statement.
  2279. If not in a statement just moves to end of line. Returns position."
  2280. (interactive)
  2281. (while (and (idlwave-is-continuation-line)
  2282. (= (forward-line 1) 0)))
  2283. (end-of-line)
  2284. (point))
  2285. (defun idlwave-next-statement ()
  2286. "Move point to beginning of the next IDL statement.
  2287. Returns t if that statement is the last non-comment IDL statement
  2288. in the file, and nil otherwise."
  2289. (interactive)
  2290. (let (last-statement)
  2291. (idlwave-end-of-statement)
  2292. ;; skip blank lines, label lines, include lines and line comments
  2293. (while (and (= (forward-line 1) 0)
  2294. ;; The current statement is the last statement until
  2295. ;; we reach a new statement.
  2296. (setq last-statement
  2297. (or
  2298. (looking-at idlwave-comment-line-start-skip)
  2299. (looking-at "[ \t]*$")
  2300. (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
  2301. (looking-at "^@")))))
  2302. last-statement))
  2303. (defun idlwave-skip-multi-commands (&optional lim)
  2304. "Skip past multiple commands on a line (with `&')."
  2305. (let ((save-point (point)))
  2306. (when (re-search-forward ".*&" lim t)
  2307. (goto-char (match-end 0))
  2308. (if (idlwave-quoted)
  2309. (goto-char save-point)
  2310. (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
  2311. (point)))
  2312. (defun idlwave-skip-label-or-case ()
  2313. "Skip label or case statement element.
  2314. Returns position after label.
  2315. If there is no label point is not moved and nil is returned."
  2316. ;; Case expressions and labels are terminated by a colon.
  2317. ;; So we find the first colon in the line and make sure
  2318. ;; - no `?' is before it (might be a ? b : c)
  2319. ;; - it is not in a comment
  2320. ;; - not in a string constant
  2321. ;; - not in parenthesis (like a[0:3])
  2322. ;; - not followed by another ":" in explicit class, ala a->b::c
  2323. ;; As many in this mode, this function is heuristic and not an exact
  2324. ;; parser.
  2325. (let* ((start (point))
  2326. (eos (save-excursion (idlwave-end-of-statement) (point)))
  2327. (end (idlwave-find-key ":" 1 'nomark eos)))
  2328. (if (and end
  2329. (= (nth 0 (parse-partial-sexp start end)) 0)
  2330. (not (string-match "\\?" (buffer-substring start end)))
  2331. (not (string-match "^::" (buffer-substring end eos))))
  2332. (progn
  2333. (forward-char)
  2334. (point))
  2335. (goto-char start)
  2336. nil)))
  2337. (defun idlwave-start-of-substatement (&optional pre)
  2338. "Move to start of next IDL substatement after point.
  2339. Uses the type of the current IDL statement to determine if the next
  2340. statement is on a new line or is a subpart of the current statement.
  2341. Returns point at start of substatement modulo whitespace.
  2342. If optional argument is non-nil move to beginning of current
  2343. substatement."
  2344. (let ((orig (point))
  2345. (eos (idlwave-end-of-statement))
  2346. (ifnest 0)
  2347. st nst last)
  2348. (idlwave-beginning-of-statement)
  2349. (idlwave-skip-label-or-case)
  2350. (if (< (point) orig)
  2351. (idlwave-skip-multi-commands orig))
  2352. (setq last (point))
  2353. ;; Continue looking for substatements until we are past orig
  2354. (while (and (<= (point) orig) (not (eobp)))
  2355. (setq last (point))
  2356. (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
  2357. (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
  2358. (cond ((and nst
  2359. (idlwave-find-key nst 1 'nomark eos))
  2360. (goto-char (match-end 0)))
  2361. ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
  2362. (setq ifnest (1- ifnest))
  2363. (goto-char (match-end 0)))
  2364. (t (setq ifnest 0)
  2365. (idlwave-next-statement))))
  2366. (if pre (goto-char last))
  2367. ;; If a continuation line starts here, move to next line
  2368. (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
  2369. (beginning-of-line 2))
  2370. (point)))
  2371. (defun idlwave-statement-type ()
  2372. "Return the type of the current IDL statement.
  2373. Uses `idlwave-statement-match' to return a cons of (type . point) with
  2374. point the ending position where the type was determined. Type is the
  2375. association from `idlwave-statement-match', i.e. the cons cell from the
  2376. list not just the type symbol. Returns nil if not an identifiable
  2377. statement."
  2378. (save-excursion
  2379. ;; Skip whitespace within a statement which is spaces, tabs, continuations
  2380. ;; and possibly comments
  2381. (while (looking-at "[ \t]*\\$")
  2382. (forward-line 1))
  2383. (skip-chars-forward " \t")
  2384. (let ((st idlwave-statement-match)
  2385. (case-fold-search t))
  2386. (while (and (not (looking-at (nth 0 (cdr (car st)))))
  2387. (setq st (cdr st))))
  2388. (if st
  2389. (append st (match-end 0))))))
  2390. (defun idlwave-expand-equal (&optional before after is-action)
  2391. "Pad '=' with spaces.
  2392. Two cases: Assignment statement, and keyword assignment.
  2393. Which case is determined using `idlwave-start-of-substatement' and
  2394. `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
  2395. and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
  2396. is treated just like assignment statements. When nil, spaces are
  2397. removed for keyword assignment. Any other value keeps the current space
  2398. around the `='. Limits in for loops are treated as keyword assignment.
  2399. Starting with IDL 6.0, a number of op= assignments are available.
  2400. Since ambiguities of the form:
  2401. r and= b
  2402. rand= b
  2403. can occur, alphanumeric operator assignment will never be pre-padded,
  2404. only post-padded. You must use a space before these to disambiguate
  2405. \(not just for padding, but for proper parsing by IDL too!). Other
  2406. operators, such as ##=, ^=, etc., will be pre-padded.
  2407. IS-ACTION is ignored.
  2408. See `idlwave-surround'."
  2409. (if idlwave-surround-by-blank
  2410. (let
  2411. ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
  2412. (an-ops
  2413. "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
  2414. (len 1))
  2415. (save-excursion
  2416. (let ((case-fold-search t))
  2417. (backward-char)
  2418. (if (or
  2419. (re-search-backward non-an-ops nil t)
  2420. ;; Why doesn't ##? work for both?
  2421. (re-search-backward "\\(#\\)\\=" nil t))
  2422. (setq len (1+ (length (match-string 1))))
  2423. (when (re-search-backward an-ops nil t)
  2424. ;(setq begin nil) ; won't modify begin
  2425. (setq len (1+ (length (match-string 1))))))))
  2426. (if (eq t idlwave-pad-keyword)
  2427. ;; Everything gets padded equally
  2428. (idlwave-surround before after len)
  2429. ;; Treating keywords/for variables specially...
  2430. (let ((st (save-excursion ; To catch "for" variables
  2431. (idlwave-start-of-substatement t)
  2432. (idlwave-statement-type)))
  2433. (what (save-excursion ; To catch keywords
  2434. (skip-chars-backward "= \t")
  2435. (nth 2 (idlwave-where)))))
  2436. (cond ((or (memq what '(function-keyword procedure-keyword))
  2437. (memq (caar st) '(for pdef)))
  2438. (cond
  2439. ((null idlwave-pad-keyword)
  2440. (idlwave-surround 0 0)
  2441. ) ; remove space
  2442. (t))) ; leave any spaces alone
  2443. (t (idlwave-surround before after len))))))))
  2444. (defun idlwave-indent-and-action (&optional arg)
  2445. "Call `idlwave-indent-line' and do expand actions.
  2446. With prefix ARG non-nil, indent the entire sub-statement."
  2447. (interactive "p")
  2448. (save-excursion
  2449. (if (and idlwave-expand-generic-end
  2450. (re-search-backward "\\<\\(end\\)\\s-*\\="
  2451. (max 0 (- (point) 10)) t)
  2452. (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
  2453. (progn (goto-char (match-end 1))
  2454. ;;Expand the END abbreviation, just as RET or Space would have.
  2455. (if abbrev-mode (expand-abbrev)
  2456. (idlwave-show-begin)))))
  2457. (when (and (not arg) current-prefix-arg)
  2458. (setq arg current-prefix-arg)
  2459. (setq current-prefix-arg nil))
  2460. (if arg
  2461. (idlwave-indent-statement)
  2462. (idlwave-indent-line t)))
  2463. (defun idlwave-indent-line (&optional expand)
  2464. "Indent current IDL line as code or as a comment.
  2465. The actions in `idlwave-indent-action-table' are performed.
  2466. If the optional argument EXPAND is non-nil then the actions in
  2467. `idlwave-indent-expand-table' are performed."
  2468. (interactive)
  2469. ;; Move point out of left margin.
  2470. (if (save-excursion
  2471. (skip-chars-backward " \t")
  2472. (bolp))
  2473. (skip-chars-forward " \t"))
  2474. (let ((mloc (point-marker)))
  2475. (save-excursion
  2476. (beginning-of-line)
  2477. (if (looking-at idlwave-comment-line-start-skip)
  2478. ;; Indentation for a line comment
  2479. (progn
  2480. (skip-chars-forward " \t")
  2481. (idlwave-indent-left-margin (idlwave-comment-hook)))
  2482. ;;
  2483. ;; Code Line
  2484. ;;
  2485. ;; Before indenting, run action routines.
  2486. ;;
  2487. (if (and expand idlwave-do-actions)
  2488. (mapc 'idlwave-do-action idlwave-indent-expand-table))
  2489. ;;
  2490. (if idlwave-do-actions
  2491. (mapc 'idlwave-do-action idlwave-indent-action-table))
  2492. ;;
  2493. ;; No longer expand abbrevs on the line. The user can do this
  2494. ;; manually using expand-region-abbrevs.
  2495. ;;
  2496. ;; Indent for code line
  2497. ;;
  2498. (beginning-of-line)
  2499. (if (or
  2500. ;; a label line
  2501. (looking-at (concat "^" idlwave-label "[ \t]*$"))
  2502. ;; a batch command
  2503. (looking-at "^[ \t]*@"))
  2504. ;; leave flush left
  2505. nil
  2506. ;; indent the line
  2507. (idlwave-indent-left-margin (idlwave-calculate-indent)))
  2508. ;; Adjust parallel comment
  2509. (end-of-line)
  2510. (if (idlwave-in-comment)
  2511. ;; Emacs 21 is too smart with fill-column on comment indent
  2512. (let ((fill-column (if (fboundp 'comment-indent-new-line)
  2513. (1- (frame-width))
  2514. fill-column)))
  2515. (indent-for-comment)))))
  2516. (goto-char mloc)
  2517. ;; Get rid of marker
  2518. (set-marker mloc nil)))
  2519. (defun idlwave-do-action (action)
  2520. "Perform an action repeatedly on a line.
  2521. ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
  2522. either a function name to be called with `funcall' or a list to be
  2523. evaluated with `eval'. The action performed by FUNC should leave
  2524. point after the match for REG - otherwise an infinite loop may be
  2525. entered. FUNC is always passed a final argument of 'is-action, so it
  2526. can discriminate between being run as an action, or a key binding."
  2527. (let ((action-key (car action))
  2528. (action-routine (cdr action)))
  2529. (beginning-of-line)
  2530. (while (idlwave-look-at action-key)
  2531. (if (listp action-routine)
  2532. (eval (append action-routine '('is-action)))
  2533. (funcall action-routine 'is-action)))))
  2534. (defun idlwave-indent-to (col &optional min)
  2535. "Indent from point with spaces until column COL.
  2536. Inserts space before markers at point."
  2537. (if (not min) (setq min 0))
  2538. (insert-before-markers
  2539. (make-string (max min (- col (current-column))) ?\ )))
  2540. (defun idlwave-indent-left-margin (col)
  2541. "Indent the current line to column COL.
  2542. Indents such that first non-whitespace character is at column COL
  2543. Inserts spaces before markers at point."
  2544. (save-excursion
  2545. (beginning-of-line)
  2546. (delete-horizontal-space)
  2547. (idlwave-indent-to col)))
  2548. (defun idlwave-indent-subprogram ()
  2549. "Indent program unit which contains point."
  2550. (interactive)
  2551. (save-excursion
  2552. (idlwave-end-of-statement)
  2553. (idlwave-beginning-of-subprogram)
  2554. (let ((beg (point)))
  2555. (idlwave-forward-block)
  2556. (message "Indenting subprogram...")
  2557. (indent-region beg (point) nil))
  2558. (message "Indenting subprogram...done.")))
  2559. (defun idlwave-indent-statement ()
  2560. "Indent current statement, including all continuation lines."
  2561. (interactive)
  2562. (save-excursion
  2563. (idlwave-beginning-of-statement)
  2564. (let ((beg (point)))
  2565. (idlwave-end-of-statement)
  2566. (indent-region beg (point) nil))))
  2567. (defun idlwave-calculate-indent ()
  2568. "Return appropriate indentation for current line as IDL code."
  2569. (save-excursion
  2570. (beginning-of-line)
  2571. (cond
  2572. ;; Check for beginning of unit - main (beginning of buffer), pro, or
  2573. ;; function
  2574. ((idlwave-look-at idlwave-begin-unit-reg)
  2575. 0)
  2576. ;; Check for continuation line
  2577. ((save-excursion
  2578. (and (= (forward-line -1) 0)
  2579. (idlwave-is-continuation-line)))
  2580. (idlwave-calculate-cont-indent))
  2581. ;; calculate indent based on previous and current statements
  2582. (t (let* (beg-prev-pos
  2583. (the-indent
  2584. ;; calculate indent based on previous statement
  2585. (save-excursion
  2586. (cond
  2587. ;; Beginning of file
  2588. ((prog1
  2589. (idlwave-previous-statement)
  2590. (setq beg-prev-pos (point)))
  2591. 0)
  2592. ;; Main block
  2593. ((idlwave-look-at idlwave-begin-unit-reg t)
  2594. (+ (idlwave-current-statement-indent)
  2595. idlwave-main-block-indent))
  2596. ;; Begin block
  2597. ((idlwave-look-at idlwave-begin-block-reg t)
  2598. (+ (idlwave-min-current-statement-indent)
  2599. idlwave-block-indent))
  2600. ;; End Block
  2601. ((idlwave-look-at idlwave-end-block-reg t)
  2602. (progn
  2603. ;; Match to the *beginning* of the block opener
  2604. (goto-char beg-prev-pos)
  2605. (idlwave-block-jump-out -1 'nomark) ; go to begin block
  2606. (idlwave-min-current-statement-indent)))
  2607. ;; idlwave-end-offset
  2608. ;; idlwave-block-indent))
  2609. ;; Default to current indent
  2610. ((idlwave-current-statement-indent))))))
  2611. ;; adjust the indentation based on the current statement
  2612. (cond
  2613. ;; End block
  2614. ((idlwave-look-at idlwave-end-block-reg)
  2615. (+ the-indent idlwave-end-offset))
  2616. (the-indent)))))))
  2617. ;;
  2618. ;; Parentheses indent
  2619. ;;
  2620. (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
  2621. "Calculate the continuation indent inside a paren group.
  2622. Returns a cons-cell with (open . indent), where open is the
  2623. location of the open paren."
  2624. (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
  2625. ;; Found an innermost open paren.
  2626. (when open
  2627. (goto-char open)
  2628. ;; Line up with next word unless this is a closing paren.
  2629. (cons open
  2630. (cond
  2631. ;; Plain Kernighan-style nested indent
  2632. (idlwave-indent-parens-nested
  2633. (+ idlwave-continuation-indent (idlwave-current-indent)))
  2634. ;; This is a closed paren - line up under open paren.
  2635. (close-exp
  2636. (current-column))
  2637. ;; Empty (or just comment) follows -- revert to basic indent
  2638. ((progn
  2639. ;; Skip paren
  2640. (forward-char 1)
  2641. (looking-at "[ \t$]*\\(;.*\\)?$"))
  2642. nil)
  2643. ;; Line up with first word after any blank space
  2644. ((progn
  2645. (skip-chars-forward " \t")
  2646. (current-column))))))))
  2647. (defun idlwave-calculate-cont-indent ()
  2648. "Calculates the IDL continuation indent column from the previous statement.
  2649. Note that here previous statement usually means the beginning of the
  2650. current statement if this statement is a continuation of the previous
  2651. line. Various special types of continuations, including assignments,
  2652. routine definitions, and parenthetical groupings, are treated separately."
  2653. (save-excursion
  2654. (let* ((case-fold-search t)
  2655. (end-reg (progn (beginning-of-line) (point)))
  2656. (beg-last-statement (save-excursion (idlwave-previous-statement)
  2657. (point)))
  2658. (beg-reg (progn (idlwave-start-of-substatement 'pre)
  2659. (if (eq (line-beginning-position) end-reg)
  2660. (goto-char beg-last-statement)
  2661. (point))))
  2662. (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
  2663. idlwave-continuation-indent))
  2664. fancy-nonparen-indent fancy-paren-indent)
  2665. (cond
  2666. ;; Align then with its matching if, etc.
  2667. ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
  2668. ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
  2669. ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
  2670. ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
  2671. "[ \t]*until")
  2672. ("\\<case\\>" . "[ \t]*of")))
  2673. match cont-re)
  2674. (goto-char end-reg)
  2675. (and
  2676. (setq cont-re
  2677. (catch 'exit
  2678. (while (setq match (car matchers))
  2679. (if (looking-at (cdr match))
  2680. (throw 'exit (car match)))
  2681. (setq matchers (cdr matchers)))))
  2682. (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
  2683. (if (looking-at "end") ;; that one's special
  2684. (- (idlwave-current-indent)
  2685. (+ idlwave-block-indent idlwave-end-offset))
  2686. (idlwave-current-indent)))
  2687. ;; Indent in from the previous line for continuing statements
  2688. ((let ((matchers '("\\<then\\>"
  2689. "\\<do\\>"
  2690. "\\<repeat\\>"
  2691. "\\<else\\>"))
  2692. match)
  2693. (catch 'exit
  2694. (goto-char end-reg)
  2695. (if (/= (forward-line -1) 0)
  2696. (throw 'exit nil))
  2697. (while (setq match (car matchers))
  2698. (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
  2699. "\\(;.*\\)?$"))
  2700. (throw 'exit t))
  2701. (setq matchers (cdr matchers)))))
  2702. (+ idlwave-continuation-indent (idlwave-current-indent)))
  2703. ;; Parenthetical indent, either traditional or Kernighan style
  2704. ((setq fancy-paren-indent
  2705. (let* ((end-reg end-reg)
  2706. (close-exp (progn
  2707. (goto-char end-reg)
  2708. (skip-chars-forward " \t")
  2709. (looking-at "\\s)")))
  2710. indent-cons)
  2711. (catch 'loop
  2712. (while (setq indent-cons (idlwave-calculate-paren-indent
  2713. beg-reg end-reg close-exp))
  2714. ;; First permitted containing paren
  2715. (if (or
  2716. idlwave-indent-to-open-paren
  2717. idlwave-indent-parens-nested
  2718. (null (cdr indent-cons))
  2719. (< (- (cdr indent-cons) basic-indent)
  2720. idlwave-max-extra-continuation-indent))
  2721. (throw 'loop (cdr indent-cons)))
  2722. (setq end-reg (car indent-cons))))))
  2723. fancy-paren-indent)
  2724. ;; A continued assignment, or procedure call/definition
  2725. ((and
  2726. (> idlwave-max-extra-continuation-indent 0)
  2727. (setq fancy-nonparen-indent
  2728. (progn
  2729. (goto-char beg-reg)
  2730. (while (idlwave-look-at "&")) ; skip continued statements
  2731. (cond
  2732. ;; A continued Procedure call or definition
  2733. ((progn
  2734. (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
  2735. (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
  2736. (goto-char (match-end 0))
  2737. ;; Comment only, or blank line with "$"? Basic indent.
  2738. (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
  2739. nil
  2740. (current-column)))
  2741. ;; Continued assignment (with =):
  2742. ((catch 'assign ;
  2743. (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
  2744. (goto-char (match-end 0))
  2745. (if (null (idlwave-what-function beg-reg))
  2746. (throw 'assign t))))
  2747. (unless (or
  2748. (idlwave-in-quote)
  2749. (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
  2750. (save-excursion
  2751. (goto-char beg-last-statement)
  2752. (eq (caar (idlwave-statement-type)) 'for)))
  2753. (current-column))))))
  2754. (< (- fancy-nonparen-indent basic-indent)
  2755. idlwave-max-extra-continuation-indent))
  2756. (if fancy-paren-indent ;calculated but disallowed paren indent
  2757. (+ fancy-nonparen-indent idlwave-continuation-indent)
  2758. fancy-nonparen-indent))
  2759. ;; Basic indent, by default
  2760. (t basic-indent)))))
  2761. (defun idlwave-find-key (key-re &optional dir nomark limit)
  2762. "Move to next match of the regular expression KEY-RE.
  2763. Matches inside comments or string constants will be ignored.
  2764. If DIR is negative, the search will be backwards.
  2765. At a successful match, the mark is pushed unless NOMARK is non-nil.
  2766. Searches are limited to LIMIT.
  2767. Searches are case-insensitive and use a special syntax table which
  2768. treats `$' and `_' as word characters.
  2769. Return value is the beginning of the match or (in case of failure) nil."
  2770. (setq dir (or dir 0))
  2771. (let ((case-fold-search t)
  2772. (search-func (if (> dir 0) 're-search-forward 're-search-backward))
  2773. found)
  2774. (idlwave-with-special-syntax
  2775. (save-excursion
  2776. (catch 'exit
  2777. (while (funcall search-func key-re limit t)
  2778. (if (not (idlwave-quoted))
  2779. (throw 'exit (setq found (match-beginning 0)))
  2780. (if (or (and (> dir 0) (eobp))
  2781. (and (< dir 0) (bobp)))
  2782. (throw 'exit nil)))))))
  2783. (if found
  2784. (progn
  2785. (if (not nomark) (push-mark))
  2786. (goto-char found)
  2787. found)
  2788. nil)))
  2789. (defun idlwave-block-jump-out (&optional dir nomark)
  2790. "When optional argument DIR is non-negative, move forward to end of
  2791. current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
  2792. regular expressions. When DIR is negative, move backwards to block beginning.
  2793. Recursively calls itself to skip over nested blocks. DIR defaults to
  2794. forward. Calls `push-mark' unless the optional argument NOMARK is
  2795. non-nil. Movement is limited by the start of program units because of
  2796. possibility of unbalanced blocks."
  2797. (interactive "P")
  2798. (or dir (setq dir 0))
  2799. (let* ((here (point))
  2800. (case-fold-search t)
  2801. (limit (if (>= dir 0) (point-max) (point-min)))
  2802. (block-limit (if (>= dir 0)
  2803. idlwave-begin-block-reg
  2804. idlwave-end-block-reg))
  2805. found
  2806. (block-reg (concat idlwave-begin-block-reg "\\|"
  2807. idlwave-end-block-reg))
  2808. (unit-limit (or (save-excursion
  2809. (if (< dir 0)
  2810. (idlwave-find-key
  2811. idlwave-begin-unit-reg dir t limit)
  2812. (end-of-line)
  2813. (idlwave-find-key
  2814. idlwave-end-unit-reg dir t limit)))
  2815. limit)))
  2816. (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
  2817. (if (setq found (idlwave-find-key block-reg dir t unit-limit))
  2818. (while (and found (looking-at block-limit))
  2819. (if (>= dir 0) (forward-word 1))
  2820. (idlwave-block-jump-out dir t)
  2821. (setq found (idlwave-find-key block-reg dir t unit-limit))))
  2822. (if (not nomark) (push-mark here))
  2823. (if (not found) (goto-char unit-limit)
  2824. (if (>= dir 0) (forward-word 1)))))
  2825. (defun idlwave-min-current-statement-indent (&optional end-reg)
  2826. "The minimum indent in the current statement."
  2827. (idlwave-beginning-of-statement)
  2828. (if (not (idlwave-is-continuation-line))
  2829. (idlwave-current-indent)
  2830. (let ((min (idlwave-current-indent)) comm-or-empty)
  2831. (while (and (= (forward-line 1) 0)
  2832. (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
  2833. (idlwave-is-continuation-line))
  2834. (or (null end-reg) (< (point) end-reg)))
  2835. (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
  2836. (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
  2837. min
  2838. (min min (idlwave-current-indent))))))
  2839. (defun idlwave-current-statement-indent (&optional last-line)
  2840. "Return indentation of the current statement.
  2841. If in a statement, moves to beginning of statement before finding indent."
  2842. (if last-line
  2843. (idlwave-end-of-statement)
  2844. (idlwave-beginning-of-statement))
  2845. (idlwave-current-indent))
  2846. (defun idlwave-current-indent ()
  2847. "Return the column of the indentation of the current line.
  2848. Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
  2849. (save-excursion
  2850. (beginning-of-line)
  2851. (skip-chars-forward " \t")
  2852. ;; if we are at the end of blank line return 0
  2853. (cond ((eolp) 0)
  2854. ((current-column)))))
  2855. (defun idlwave-is-continuation-line ()
  2856. "Test if current line is continuation line.
  2857. Blank or comment-only lines following regular continuation lines (with
  2858. `$') count as continuations too."
  2859. (let (p)
  2860. (save-excursion
  2861. (or
  2862. (idlwave-look-at "\\<\\$")
  2863. (catch 'loop
  2864. (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
  2865. (eq (forward-line -1) 0))
  2866. (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
  2867. (defun idlwave-is-comment-line ()
  2868. "Test if the current line is a comment line."
  2869. (save-excursion
  2870. (beginning-of-line 1)
  2871. (looking-at "[ \t]*;")))
  2872. (defun idlwave-is-comment-or-empty-line ()
  2873. "Test if the current line is a comment line."
  2874. (save-excursion
  2875. (beginning-of-line 1)
  2876. (looking-at "[ \t]*[;\n]")))
  2877. (defun idlwave-look-at (regexp &optional cont beg)
  2878. "Search current line from current point for REGEXP.
  2879. If optional argument CONT is non-nil, searches to the end of
  2880. the current statement.
  2881. If optional arg BEG is non-nil, search starts from the beginning of the
  2882. current statement.
  2883. Ignores matches that end in a comment or inside a string expression.
  2884. Returns point if successful, nil otherwise.
  2885. This function produces unexpected results if REGEXP contains quotes or
  2886. a comment delimiter. The search is case insensitive.
  2887. If successful leaves point after the match, otherwise, does not move point."
  2888. (let ((here (point))
  2889. (case-fold-search t)
  2890. (eos (save-excursion
  2891. (if cont (idlwave-end-of-statement) (end-of-line))
  2892. (point)))
  2893. found)
  2894. (idlwave-with-special-syntax
  2895. (if beg (idlwave-beginning-of-statement))
  2896. (while (and (setq found (re-search-forward regexp eos t))
  2897. (idlwave-quoted))))
  2898. (if (not found) (goto-char here))
  2899. found))
  2900. (defun idlwave-fill-paragraph (&optional nohang)
  2901. "Fill paragraphs in comments.
  2902. A paragraph is made up of all contiguous lines having the same comment
  2903. leader (the leading whitespace before the comment delimiter and the
  2904. comment delimiter). In addition, paragraphs are separated by blank
  2905. line comments. The indentation is given by the hanging indent of the
  2906. first line, otherwise by the minimum indentation of the lines after
  2907. the first line. The indentation of the first line does not change.
  2908. Does not effect code lines. Does not fill comments on the same line
  2909. with code. The hanging indent is given by the end of the first match
  2910. matching `idlwave-hang-indent-regexp' on the paragraph's first line.
  2911. If the optional argument NOHANG is non-nil then the hanging indent is
  2912. ignored."
  2913. (interactive "P")
  2914. ;; check if this is a line comment
  2915. (if (save-excursion
  2916. (beginning-of-line)
  2917. (skip-chars-forward " \t")
  2918. (looking-at comment-start))
  2919. (let
  2920. ((indent 999)
  2921. pre here diff fill-prefix-reg bcl first-indent
  2922. hang start end)
  2923. ;; Change tabs to spaces in the surrounding paragraph.
  2924. ;; The surrounding paragraph will be the largest containing block of
  2925. ;; contiguous line comments. Thus, we may be changing tabs in
  2926. ;; a much larger area than is needed, but this is the easiest
  2927. ;; brute force way to do it.
  2928. ;;
  2929. ;; This has the undesirable side effect of replacing the tabs
  2930. ;; permanently without the user's request or knowledge.
  2931. (save-excursion
  2932. (backward-paragraph)
  2933. (setq start (point)))
  2934. (save-excursion
  2935. (forward-paragraph)
  2936. (setq end (point)))
  2937. (untabify start end)
  2938. ;;
  2939. (setq here (point))
  2940. (beginning-of-line)
  2941. (setq bcl (point))
  2942. (re-search-forward (concat "^[ \t]*" comment-start "+")
  2943. (point-at-eol) t)
  2944. ;; Get the comment leader on the line and its length
  2945. (setq pre (current-column))
  2946. ;; the comment leader is the indentation plus exactly the
  2947. ;; number of consecutive ";".
  2948. (setq fill-prefix-reg
  2949. (concat
  2950. (setq fill-prefix
  2951. (regexp-quote (buffer-substring (point-at-bol) (point))))
  2952. "[^;]"))
  2953. ;; Mark the beginning and end of the paragraph
  2954. (goto-char bcl)
  2955. (while (and (looking-at fill-prefix-reg)
  2956. (not (looking-at paragraph-separate))
  2957. (not (bobp)))
  2958. (forward-line -1))
  2959. ;; Move to first line of paragraph
  2960. (if (/= (point) bcl)
  2961. (forward-line 1))
  2962. (setq start (point))
  2963. (goto-char bcl)
  2964. (while (and (looking-at fill-prefix-reg)
  2965. (not (looking-at paragraph-separate))
  2966. (not (eobp)))
  2967. (forward-line 1))
  2968. (beginning-of-line)
  2969. (if (or (not (looking-at fill-prefix-reg))
  2970. (looking-at paragraph-separate))
  2971. (forward-line -1))
  2972. (end-of-line)
  2973. ;; if at end of buffer add a newline (need this because
  2974. ;; fill-region needs END to be at the beginning of line after
  2975. ;; the paragraph or it will add a line).
  2976. (if (eobp)
  2977. (progn (insert ?\n) (backward-char 1)))
  2978. ;; Set END to the beginning of line after the paragraph
  2979. ;; END is calculated as distance from end of buffer
  2980. (setq end (- (point-max) (point) 1))
  2981. ;;
  2982. ;; Calculate the indentation for the paragraph.
  2983. ;;
  2984. ;; In the following while statements, after one iteration
  2985. ;; point will be at the beginning of a line in which case
  2986. ;; the while will not be executed for the
  2987. ;; the first paragraph line and thus will not affect the
  2988. ;; indentation.
  2989. ;;
  2990. ;; First check to see if indentation is based on hanging indent.
  2991. (if (and (not nohang) idlwave-hanging-indent
  2992. (setq hang
  2993. (save-excursion
  2994. (goto-char start)
  2995. (idlwave-calc-hanging-indent))))
  2996. ;; Adjust lines of paragraph by inserting spaces so that
  2997. ;; each line's indent is at least as great as the hanging
  2998. ;; indent. This is needed for fill-paragraph to work with
  2999. ;; a fill-prefix.
  3000. (progn
  3001. (setq indent hang)
  3002. (beginning-of-line)
  3003. (while (> (point) start)
  3004. (re-search-forward comment-start-skip (point-at-eol) t)
  3005. (if (> (setq diff (- indent (current-column))) 0)
  3006. (progn
  3007. (if (>= here (point))
  3008. ;; adjust the original location for the
  3009. ;; inserted text.
  3010. (setq here (+ here diff)))
  3011. (insert (make-string diff ?\ ))))
  3012. (forward-line -1))
  3013. )
  3014. ;; No hang. Instead find minimum indentation of paragraph
  3015. ;; after first line.
  3016. ;; For the following while statement, since START is at the
  3017. ;; beginning of line and END is at the end of line
  3018. ;; point is greater than START at least once (which would
  3019. ;; be the case for a single line paragraph).
  3020. (while (> (point) start)
  3021. (beginning-of-line)
  3022. (setq indent
  3023. (min indent
  3024. (progn
  3025. (re-search-forward comment-start-skip (point-at-eol) t)
  3026. (current-column))))
  3027. (forward-line -1)))
  3028. (setq fill-prefix (concat fill-prefix
  3029. (make-string (- indent pre)
  3030. ?\ )))
  3031. ;; first-line indent
  3032. (setq first-indent
  3033. (max
  3034. (progn
  3035. (re-search-forward comment-start-skip (point-at-eol) t)
  3036. (current-column))
  3037. indent))
  3038. ;; try to keep point at its original place
  3039. (goto-char here)
  3040. ;; In place of the more modern fill-region-as-paragraph, a hack
  3041. ;; to keep whitespace untouched on the first line within the
  3042. ;; indent length and to preserve any indent on the first line
  3043. ;; (first indent).
  3044. (save-excursion
  3045. (setq diff
  3046. (buffer-substring start (+ start first-indent -1)))
  3047. (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
  3048. (fill-region-as-paragraph
  3049. start
  3050. (- (point-max) end)
  3051. (current-justification)
  3052. nil)
  3053. (delete-region start (+ start first-indent -1))
  3054. (goto-char start)
  3055. (insert diff))
  3056. ;; When we want the point at the beginning of the comment
  3057. ;; body fill-region will put it at the beginning of the line.
  3058. (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
  3059. (setq fill-prefix nil))))
  3060. (defun idlwave-calc-hanging-indent ()
  3061. "Calculate the position of the hanging indent for the comment paragraph.
  3062. The hanging indent position is given by the first match with the
  3063. `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
  3064. non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
  3065. on the line.
  3066. If not found returns nil."
  3067. (if idlwave-use-last-hang-indent
  3068. (save-excursion
  3069. (end-of-line)
  3070. (if (re-search-backward idlwave-hang-indent-regexp (point-at-bol) t)
  3071. (+ (current-column) (length idlwave-hang-indent-regexp))))
  3072. (save-excursion
  3073. (beginning-of-line)
  3074. (if (re-search-forward idlwave-hang-indent-regexp (point-at-eol) t)
  3075. (current-column)))))
  3076. (defun idlwave-auto-fill ()
  3077. "Called to break lines in auto fill mode.
  3078. Only fills non-comment lines if `idlwave-fill-comment-line-only' is
  3079. non-nil. Places a continuation character at the end of the line if
  3080. not in a comment. Splits strings with IDL concatenation operator `+'
  3081. if `idlwave-auto-fill-split-string' is non-nil."
  3082. (if (<= (current-column) fill-column)
  3083. nil ; do not to fill
  3084. (if (or (not idlwave-fill-comment-line-only)
  3085. (save-excursion
  3086. ;; Check for comment line
  3087. (beginning-of-line)
  3088. (looking-at idlwave-comment-line-start-skip)))
  3089. (let (beg)
  3090. (idlwave-indent-line)
  3091. ;; Prevent actions do-auto-fill which calls indent-line-function.
  3092. (let (idlwave-do-actions
  3093. (paragraph-separate ".")
  3094. (fill-nobreak-predicate
  3095. (if (and (idlwave-in-quote)
  3096. idlwave-auto-fill-split-string)
  3097. (lambda () ;; We'll need 5 spaces for " ' + $"
  3098. (<= (- fill-column (current-column)) 5)
  3099. ))))
  3100. (do-auto-fill))
  3101. (save-excursion
  3102. (end-of-line 0)
  3103. ;; Indent the split line
  3104. (idlwave-indent-line))
  3105. (if (save-excursion
  3106. (beginning-of-line)
  3107. (looking-at idlwave-comment-line-start-skip))
  3108. ;; A continued line comment
  3109. ;; We treat continued line comments as part of a comment
  3110. ;; paragraph. So we check for a hanging indent.
  3111. (if idlwave-hanging-indent
  3112. (let ((here (- (point-max) (point)))
  3113. (indent
  3114. (save-excursion
  3115. (forward-line -1)
  3116. (idlwave-calc-hanging-indent))))
  3117. (when indent
  3118. ;; Remove whitespace between comment delimiter and
  3119. ;; text, insert spaces for appropriate indentation.
  3120. (beginning-of-line)
  3121. (re-search-forward comment-start-skip (point-at-eol) t)
  3122. (delete-horizontal-space)
  3123. (idlwave-indent-to indent)
  3124. (goto-char (- (point-max) here)))))
  3125. ;; Split code or comment?
  3126. (if (save-excursion
  3127. (end-of-line 0)
  3128. (idlwave-in-comment))
  3129. ;; Splitting a non-full-line comment.
  3130. ;; Insert the comment delimiter from split line
  3131. (progn
  3132. (save-excursion
  3133. (beginning-of-line)
  3134. (skip-chars-forward " \t")
  3135. ;; Insert blank to keep off beginning of line
  3136. (insert " "
  3137. (save-excursion
  3138. (forward-line -1)
  3139. (buffer-substring (idlwave-goto-comment)
  3140. (progn
  3141. (skip-chars-forward "; ")
  3142. (point))))))
  3143. (idlwave-indent-line))
  3144. ;; Split code line - add continuation character
  3145. (save-excursion
  3146. (end-of-line 0)
  3147. ;; Check to see if we split a string
  3148. (if (and (setq beg (idlwave-in-quote))
  3149. idlwave-auto-fill-split-string)
  3150. ;; Split the string and concatenate.
  3151. ;; The first extra space is for the space
  3152. ;; the line was split. That space was removed.
  3153. (insert " " (char-after beg) " +"))
  3154. (insert " $"))
  3155. (if beg
  3156. (if idlwave-auto-fill-split-string
  3157. ;; Make the second part of continued string
  3158. (save-excursion
  3159. (beginning-of-line)
  3160. (skip-chars-forward " \t")
  3161. (insert (char-after beg)))
  3162. ;; Warning
  3163. (beep)
  3164. (message "Warning: continuation inside a string.")))
  3165. ;; Although do-auto-fill (via indent-new-comment-line) calls
  3166. ;; idlwave-indent-line for the new line, re-indent again
  3167. ;; because of the addition of the continuation character.
  3168. (idlwave-indent-line))
  3169. )))))
  3170. (defun idlwave-auto-fill-mode (arg)
  3171. "Toggle auto-fill mode for IDL mode.
  3172. With arg, turn auto-fill mode on if arg is positive.
  3173. In auto-fill mode, inserting a space at a column beyond `fill-column'
  3174. automatically breaks the line at a previous space."
  3175. (interactive "P")
  3176. (prog1 (set idlwave-fill-function
  3177. (if (if (null arg)
  3178. (not (symbol-value idlwave-fill-function))
  3179. (> (prefix-numeric-value arg) 0))
  3180. 'idlwave-auto-fill
  3181. nil))
  3182. ;; update mode-line
  3183. (set-buffer-modified-p (buffer-modified-p))))
  3184. ;(defun idlwave-fill-routine-call ()
  3185. ; "Fill a routine definition or statement, indenting appropriately."
  3186. ; (let ((where (idlwave-where)))))
  3187. (defun idlwave-doc-header (&optional nomark)
  3188. "Insert a documentation header at the beginning of the unit.
  3189. Inserts the value of the variable `idlwave-file-header'. Sets mark
  3190. before moving to do insertion unless the optional prefix argument
  3191. NOMARK is non-nil."
  3192. (interactive "P")
  3193. (or nomark (push-mark))
  3194. ;; make sure we catch the current line if it begins the unit
  3195. (if idlwave-header-to-beginning-of-file
  3196. (goto-char (point-min))
  3197. (end-of-line)
  3198. (idlwave-beginning-of-subprogram)
  3199. (beginning-of-line)
  3200. ;; skip function or procedure line
  3201. (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
  3202. (progn
  3203. (idlwave-end-of-statement)
  3204. (if (> (forward-line 1) 0) (insert "\n")))))
  3205. (let ((pos (point)))
  3206. (if idlwave-file-header
  3207. (cond ((car idlwave-file-header)
  3208. (insert-file-contents (car idlwave-file-header)))
  3209. ((stringp (car (cdr idlwave-file-header)))
  3210. (insert (car (cdr idlwave-file-header))))))
  3211. (goto-char pos)))
  3212. (defun idlwave-default-insert-timestamp ()
  3213. "Default timestamp insertion function."
  3214. (insert (current-time-string))
  3215. (insert ", " (user-full-name))
  3216. (if (boundp 'user-mail-address)
  3217. (insert " <" user-mail-address ">")
  3218. (insert " <" (user-login-name) "@" (system-name) ">"))
  3219. ;; Remove extra spaces from line
  3220. (idlwave-fill-paragraph)
  3221. ;; Insert a blank line comment to separate from the date entry -
  3222. ;; will keep the entry from flowing onto date line if re-filled.
  3223. (insert "\n;\n;\t\t"))
  3224. (defun idlwave-doc-modification ()
  3225. "Insert a brief modification log at the beginning of the current program.
  3226. Looks for an occurrence of the value of user variable
  3227. `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
  3228. name and places the point for the user to add a log. Before moving, saves
  3229. location on mark ring so that the user can return to previous point."
  3230. (interactive)
  3231. (push-mark)
  3232. (let* (beg end)
  3233. (if (and (or (re-search-backward idlwave-doclib-start nil t)
  3234. (progn
  3235. (goto-char (point-min))
  3236. (re-search-forward idlwave-doclib-start nil t)))
  3237. (setq beg (match-beginning 0))
  3238. (re-search-forward idlwave-doclib-end nil t)
  3239. (setq end (match-end 0)))
  3240. (progn
  3241. (goto-char beg)
  3242. (if (re-search-forward
  3243. (concat idlwave-doc-modifications-keyword ":")
  3244. end t)
  3245. (end-of-line)
  3246. (goto-char end)
  3247. (end-of-line -1)
  3248. (insert "\n" comment-start "\n")
  3249. (insert comment-start " " idlwave-doc-modifications-keyword ":"))
  3250. (insert "\n;\n;\t")
  3251. (run-hooks 'idlwave-timestamp-hook))
  3252. (error "No valid DOCLIB header"))))
  3253. ;; CJC 3/16/93
  3254. ;; Interface to expand-region-abbrevs which did not work when the
  3255. ;; abbrev hook associated with an abbrev moves point backwards
  3256. ;; after abbrev expansion, e.g., as with the abbrev '.n'.
  3257. ;; The original would enter an infinite loop in attempting to expand
  3258. ;; .n (it would continually expand and unexpand the abbrev without expanding
  3259. ;; because the point would keep going back to the beginning of the
  3260. ;; abbrev instead of to the end of the abbrev). We now keep the
  3261. ;; abbrev hook from moving backwards.
  3262. ;;;
  3263. (defun idlwave-expand-region-abbrevs (start end)
  3264. "Expand each abbrev occurrence in the region.
  3265. Calling from a program, arguments are START END."
  3266. (interactive "r")
  3267. (save-excursion
  3268. (goto-char (min start end))
  3269. (let ((idlwave-show-block nil) ;Do not blink
  3270. (idlwave-abbrev-move nil)) ;Do not move
  3271. (expand-region-abbrevs start end 'noquery))))
  3272. (defun idlwave-quoted ()
  3273. "Return t if point is in a comment or quoted string.
  3274. Returns nil otherwise."
  3275. (or (idlwave-in-comment) (idlwave-in-quote)))
  3276. (defun idlwave-in-quote ()
  3277. "Return location of the opening quote
  3278. if point is in a IDL string constant, nil otherwise.
  3279. Ignores comment delimiters on the current line.
  3280. Properly handles nested quotation marks and octal
  3281. constants - a double quote followed by an octal digit."
  3282. ;; Treat an octal inside an apostrophe to be a normal string. Treat a
  3283. ;; double quote followed by an octal digit to be an octal constant
  3284. ;; rather than a string. Therefore, there is no terminating double
  3285. ;; quote.
  3286. (save-excursion
  3287. ;; Because single and double quotes can quote each other we must
  3288. ;; search for the string start from the beginning of line.
  3289. (let* ((start (point))
  3290. (eol (point-at-eol))
  3291. (bq (progn (beginning-of-line) (point)))
  3292. (endq (point))
  3293. (data (match-data))
  3294. delim
  3295. found)
  3296. (while (< endq start)
  3297. ;; Find string start
  3298. ;; Don't find an octal constant beginning with a double quote
  3299. (if (re-search-forward "[\"']" eol 'lim)
  3300. ;; Find the string end.
  3301. ;; In IDL, two consecutive delimiters after the start of a
  3302. ;; string act as an
  3303. ;; escape for the delimiter in the string.
  3304. ;; Two consecutive delimiters alone (i.e., not after the
  3305. ;; start of a string) is the null string.
  3306. (progn
  3307. ;; Move to position after quote
  3308. (goto-char (1+ (match-beginning 0)))
  3309. (setq bq (1- (point)))
  3310. ;; Get the string delimiter
  3311. (setq delim (char-to-string (preceding-char)))
  3312. ;; Check for null string
  3313. (if (looking-at delim)
  3314. (progn (setq endq (point)) (forward-char 1))
  3315. ;; Look for next unpaired delimiter
  3316. (setq found (search-forward delim eol 'lim))
  3317. (while (looking-at delim)
  3318. (forward-char 1)
  3319. (setq found (search-forward delim eol 'lim)))
  3320. (setq endq (if found (1- (point)) (point)))
  3321. ))
  3322. (progn (setq bq (point)) (setq endq (point)))))
  3323. (store-match-data data)
  3324. ;; return string beginning position or nil
  3325. (if (> start bq) bq))))
  3326. (defun idlwave-is-pointer-dereference (&optional limit)
  3327. "Determine if the character after point is a pointer dereference *."
  3328. (and
  3329. (eq (char-after) ?\*)
  3330. (not (idlwave-in-quote))
  3331. (save-excursion
  3332. (forward-char)
  3333. (re-search-backward (concat "\\(" idlwave-idl-keywords
  3334. "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
  3335. ;; Statement templates
  3336. ;; Replace these with a general template function, something like
  3337. ;; expand.el (I think there was also something with a name similar to
  3338. ;; dmacro.el)
  3339. (defun idlwave-template (s1 s2 &optional prompt noindent)
  3340. "Build a template with optional prompt expression.
  3341. Opens a line if point is not followed by a newline modulo intervening
  3342. whitespace. S1 and S2 are strings. S1 is inserted at point followed
  3343. by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
  3344. adjusted according to `idlwave-abbrev-change-case'. If optional
  3345. argument PROMPT is a string then it is displayed as a message in the
  3346. minibuffer. The PROMPT serves as a reminder to the user of an
  3347. expression to enter.
  3348. The lines containing S1 and S2 are reindented using `indent-region'
  3349. unless the optional second argument NOINDENT is non-nil."
  3350. (if (derived-mode-p 'idlwave-shell-mode)
  3351. ;; This is a gross hack to avoid template abbrev expansion
  3352. ;; in the shell. FIXME: This is a dirty hack.
  3353. (if (and (eq this-command 'self-insert-command)
  3354. (equal last-abbrev-location (point)))
  3355. (insert last-abbrev-text)
  3356. (error "No templates in idlwave-shell"))
  3357. (cond ((eq idlwave-abbrev-change-case 'down)
  3358. (setq s1 (downcase s1) s2 (downcase s2)))
  3359. (idlwave-abbrev-change-case
  3360. (setq s1 (upcase s1) s2 (upcase s2))))
  3361. (let ((beg (point-at-bol))
  3362. end)
  3363. (if (not (looking-at "\\s-*\n"))
  3364. (open-line 1))
  3365. (insert s1)
  3366. (save-excursion
  3367. (insert s2)
  3368. (setq end (point)))
  3369. (if (not noindent)
  3370. (indent-region beg end nil))
  3371. (if (stringp prompt)
  3372. (message "%s" prompt)))))
  3373. (defun idlwave-rw-case (string)
  3374. "Make STRING have the case required by `idlwave-reserved-word-upcase'."
  3375. (if idlwave-reserved-word-upcase
  3376. (upcase string)
  3377. string))
  3378. (defun idlwave-elif ()
  3379. "Build skeleton IDL if-else block."
  3380. (interactive)
  3381. (idlwave-template
  3382. (idlwave-rw-case "if")
  3383. (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
  3384. "Condition expression"))
  3385. (defun idlwave-case ()
  3386. "Build skeleton IDL case statement."
  3387. (interactive)
  3388. (idlwave-template
  3389. (idlwave-rw-case "case")
  3390. (idlwave-rw-case " of\n\nendcase")
  3391. "Selector expression"))
  3392. (defun idlwave-switch ()
  3393. "Build skeleton IDL switch statement."
  3394. (interactive)
  3395. (idlwave-template
  3396. (idlwave-rw-case "switch")
  3397. (idlwave-rw-case " of\n\nendswitch")
  3398. "Selector expression"))
  3399. (defun idlwave-for ()
  3400. "Build skeleton IDL loop statement."
  3401. (interactive)
  3402. (idlwave-template
  3403. (idlwave-rw-case "for")
  3404. (idlwave-rw-case " do begin\n\nendfor")
  3405. "Loop expression"))
  3406. (defun idlwave-if ()
  3407. "Build skeleton IDL if statement."
  3408. (interactive)
  3409. (idlwave-template
  3410. (idlwave-rw-case "if")
  3411. (idlwave-rw-case " then begin\n\nendif")
  3412. "Scalar logical expression"))
  3413. (defun idlwave-procedure ()
  3414. (interactive)
  3415. (idlwave-template
  3416. (idlwave-rw-case "pro")
  3417. (idlwave-rw-case "\n\nreturn\nend")
  3418. "Procedure name"))
  3419. (defun idlwave-function ()
  3420. (interactive)
  3421. (idlwave-template
  3422. (idlwave-rw-case "function")
  3423. (idlwave-rw-case "\n\nreturn\nend")
  3424. "Function name"))
  3425. (defun idlwave-repeat ()
  3426. (interactive)
  3427. (idlwave-template
  3428. (idlwave-rw-case "repeat begin\n\nendrep until")
  3429. (idlwave-rw-case "")
  3430. "Exit condition"))
  3431. (defun idlwave-while ()
  3432. (interactive)
  3433. (idlwave-template
  3434. (idlwave-rw-case "while")
  3435. (idlwave-rw-case " do begin\n\nendwhile")
  3436. "Entry condition"))
  3437. (defun idlwave-split-string (string &optional pattern)
  3438. "Return a list of substrings of STRING which are separated by PATTERN.
  3439. If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
  3440. (or pattern
  3441. (setq pattern "[ \f\t\n\r\v]+"))
  3442. (let (parts (start 0))
  3443. (while (string-match pattern string start)
  3444. (setq parts (cons (substring string start (match-beginning 0)) parts)
  3445. start (match-end 0)))
  3446. (nreverse (cons (substring string start) parts))))
  3447. (defun idlwave-replace-string (string replace_string replace_with)
  3448. (let* ((start 0)
  3449. (last (length string))
  3450. (ret_string "")
  3451. end)
  3452. (while (setq end (string-match replace_string string start))
  3453. (setq ret_string
  3454. (concat ret_string (substring string start end) replace_with))
  3455. (setq start (match-end 0)))
  3456. (setq ret_string (concat ret_string (substring string start last)))))
  3457. (defun idlwave-get-buffer-visiting (file)
  3458. ;; Return the buffer currently visiting FILE
  3459. (cond
  3460. ((boundp 'find-file-compare-truenames) ; XEmacs
  3461. (let ((find-file-compare-truenames t))
  3462. (get-file-buffer file)))
  3463. ((fboundp 'find-buffer-visiting) ; Emacs
  3464. (find-buffer-visiting file))
  3465. (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
  3466. (defvar idlwave-outlawed-buffers nil
  3467. "List of buffers pulled up by IDLWAVE for special reasons.
  3468. Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
  3469. (defun idlwave-find-file-noselect (file &optional why)
  3470. ;; Return a buffer visiting file.
  3471. (or (idlwave-get-buffer-visiting file)
  3472. (let ((buf (find-file-noselect file)))
  3473. (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
  3474. buf)))
  3475. (defun idlwave-kill-autoloaded-buffers ()
  3476. "Kill buffers created automatically by IDLWAVE.
  3477. Function prompts for a letter to identify the buffers to kill.
  3478. Possible letters are:
  3479. f Buffers created by the command \\[idlwave-find-module] or mouse
  3480. clicks in the routine info window.
  3481. s Buffers created by the IDLWAVE Shell to display where execution
  3482. stopped or an error was found.
  3483. a Both of the above.
  3484. Buffers containing unsaved changes require confirmation before they are killed."
  3485. (interactive)
  3486. (if (null idlwave-outlawed-buffers)
  3487. (error "No IDLWAVE-created buffers available")
  3488. (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
  3489. (idlwave-count-outlawed-buffers 'find)
  3490. (idlwave-count-outlawed-buffers 'shell)))
  3491. (let ((c (read-char)))
  3492. (cond
  3493. ((member c '(?f ?\C-f))
  3494. (idlwave-do-kill-autoloaded-buffers 'find))
  3495. ((member c '(?s ?\C-s))
  3496. (idlwave-do-kill-autoloaded-buffers 'shell))
  3497. ((member c '(?a ?\C-a))
  3498. (idlwave-do-kill-autoloaded-buffers t))
  3499. (t (error "Abort"))))))
  3500. (defun idlwave-count-outlawed-buffers (tag)
  3501. "How many outlawed buffers have tag TAG?"
  3502. (length (delq nil
  3503. (mapcar
  3504. (lambda (x) (eq (cdr x) tag))
  3505. idlwave-outlawed-buffers))))
  3506. (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
  3507. "Kill all buffers pulled up by IDLWAVE matching REASONS."
  3508. (let* ((list (copy-sequence idlwave-outlawed-buffers))
  3509. (cnt 0)
  3510. entry)
  3511. (while (setq entry (pop list))
  3512. (if (buffer-live-p (car entry))
  3513. (and (or (memq t reasons)
  3514. (memq (cdr entry) reasons))
  3515. (kill-buffer (car entry))
  3516. (incf cnt)
  3517. (setq idlwave-outlawed-buffers
  3518. (delq entry idlwave-outlawed-buffers)))
  3519. (setq idlwave-outlawed-buffers
  3520. (delq entry idlwave-outlawed-buffers))))
  3521. (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
  3522. (defun idlwave-revoke-license-to-kill ()
  3523. "Remove BUFFER from the buffers which may be killed.
  3524. Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
  3525. Intended for `after-save-hook'."
  3526. (let* ((buf (current-buffer))
  3527. (entry (assq buf idlwave-outlawed-buffers)))
  3528. ;; Revoke license
  3529. (if entry
  3530. (setq idlwave-outlawed-buffers
  3531. (delq entry idlwave-outlawed-buffers)))
  3532. ;; Remove this function from the hook.
  3533. (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
  3534. (defvar idlwave-path-alist)
  3535. (defun idlwave-locate-lib-file (file)
  3536. ;; Find FILE on the scanned lib path and return a buffer visiting it
  3537. (let* ((dirs idlwave-path-alist)
  3538. dir efile)
  3539. (catch 'exit
  3540. (while (setq dir (car (pop dirs)))
  3541. (if (file-regular-p
  3542. (setq efile (expand-file-name file dir)))
  3543. (throw 'exit efile))))))
  3544. (defun idlwave-expand-lib-file-name (file)
  3545. ;; Find FILE on the scanned lib path and return a buffer visiting it
  3546. ;; This is for, e.g., finding source with no user catalog
  3547. (cond
  3548. ((null file) nil)
  3549. ((file-name-absolute-p file) file)
  3550. (t (idlwave-locate-lib-file file))))
  3551. (defun idlwave-make-tags ()
  3552. "Create the IDL tags file IDLTAGS in the current directory from
  3553. the list of directories specified in the minibuffer. Directories may be
  3554. for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
  3555. specified top directories are searched if the directory name is prefixed
  3556. by @. Specify @ directories with care, it may take a long, long time if
  3557. you specify /."
  3558. (interactive)
  3559. (let (directory directories cmd append status numdirs dir getsubdirs
  3560. buffer save_buffer files numfiles item errbuf)
  3561. ;;
  3562. ;; Read list of directories
  3563. (setq directory (read-string "Tag Directories: " "."))
  3564. (setq directories (idlwave-split-string directory "[ \t]+"))
  3565. ;;
  3566. ;; Set etags command, vars
  3567. (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
  3568. \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
  3569. \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
  3570. (setq append " ")
  3571. (setq status 0)
  3572. ;;
  3573. ;; For each directory
  3574. (setq numdirs 0)
  3575. (setq dir (nth numdirs directories))
  3576. (while (and dir)
  3577. ;;
  3578. ;; Find the subdirectories
  3579. (if (string-match "^[@]\\(.+\\)$" dir)
  3580. (setq getsubdirs t) (setq getsubdirs nil))
  3581. (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
  3582. (setq dir (expand-file-name dir))
  3583. (if (file-directory-p dir)
  3584. (progn
  3585. (if (and getsubdirs)
  3586. (progn
  3587. (setq buffer (get-buffer-create "*idltags*"))
  3588. (call-process "sh" nil buffer nil "-c"
  3589. (concat "find " dir " -type d -print"))
  3590. (setq save_buffer (current-buffer))
  3591. (set-buffer buffer)
  3592. (setq files (idlwave-split-string
  3593. (idlwave-replace-string
  3594. (buffer-substring 1 (point-max))
  3595. "\n" "/*.pro ")
  3596. "[ \t]+"))
  3597. (set-buffer save_buffer)
  3598. (kill-buffer buffer))
  3599. (setq files (list (concat dir "/*.pro"))))
  3600. ;;
  3601. ;; For each subdirectory
  3602. (setq numfiles 0)
  3603. (setq item (nth numfiles files))
  3604. (while (and item)
  3605. ;;
  3606. ;; Call etags
  3607. (if (not (string-match "^[ \\t]*$" item))
  3608. (progn
  3609. (message "%s" (concat "Tagging " item "..."))
  3610. (setq errbuf (get-buffer-create "*idltags-error*"))
  3611. (setq status (+ status
  3612. (if (eq 0 (call-process
  3613. "sh" nil errbuf nil "-c"
  3614. (concat cmd append item)))
  3615. 0
  3616. 1)))
  3617. ;;
  3618. ;; Append additional tags
  3619. (setq append " --append ")
  3620. (setq numfiles (1+ numfiles))
  3621. (setq item (nth numfiles files)))
  3622. (progn
  3623. (setq numfiles (1+ numfiles))
  3624. (setq item (nth numfiles files))
  3625. )))
  3626. (setq numdirs (1+ numdirs))
  3627. (setq dir (nth numdirs directories)))
  3628. (progn
  3629. (setq numdirs (1+ numdirs))
  3630. (setq dir (nth numdirs directories)))))
  3631. (setq errbuf (get-buffer-create "*idltags-error*"))
  3632. (if (= status 0)
  3633. (kill-buffer errbuf))
  3634. (message "")
  3635. ))
  3636. (defun idlwave-toggle-comment-region (beg end &optional n)
  3637. "Comment the lines in the region if the first non-blank line is
  3638. commented, and conversely, uncomment region. If optional prefix arg
  3639. N is non-nil, then for N positive, add N comment delimiters or for N
  3640. negative, remove N comment delimiters.
  3641. Uses `comment-region' which does not place comment delimiters on
  3642. blank lines."
  3643. (interactive "r\nP")
  3644. (if n
  3645. (comment-region beg end (prefix-numeric-value n))
  3646. (save-excursion
  3647. (goto-char beg)
  3648. (beginning-of-line)
  3649. ;; skip blank lines
  3650. (skip-chars-forward " \t\n")
  3651. (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
  3652. (if (fboundp 'uncomment-region)
  3653. (uncomment-region beg end)
  3654. (comment-region beg end
  3655. (- (length (buffer-substring
  3656. (match-beginning 1)
  3657. (match-end 1))))))
  3658. (comment-region beg end)))))
  3659. ;; ----------------------------------------------------------------------------
  3660. ;; ----------------------------------------------------------------------------
  3661. ;; ----------------------------------------------------------------------------
  3662. ;; ----------------------------------------------------------------------------
  3663. ;;
  3664. ;; Completion and Routine Info
  3665. ;;
  3666. ;; String "intern" functions
  3667. ;; For the completion and routine info function, we want to normalize
  3668. ;; the case of procedure names etc. We do this by "interning" these
  3669. ;; string is a hand-crafted way. Hashes are used to map the downcase
  3670. ;; version of the strings to the cased versions. Most *-sint-*
  3671. ;; variables consist of *two* hashes, a buffer+shell, followed by a
  3672. ;; system hash. The former is re-scanned, and the latter takes case
  3673. ;; precedence.
  3674. ;;
  3675. ;; Since these cased versions are really lisp objects, we can use `eq'
  3676. ;; to search, which is a large performance boost. All new strings
  3677. ;; need to be "sinterned". We do this as early as possible after
  3678. ;; getting these strings from completion or buffer substrings. So
  3679. ;; most of the code can simply assume to deal with "sinterned"
  3680. ;; strings. The only exception is that the functions which scan whole
  3681. ;; buffers for routine information do not intern the grabbed strings.
  3682. ;; This is only done afterwards. Therefore in these functions it is
  3683. ;; *not* safe to assume the strings can be compared with `eq' and be
  3684. ;; fed into the routine assq functions.
  3685. ;; Here we define the hashing functions.
  3686. ;; The variables which hold the hashes.
  3687. (defvar idlwave-sint-routines '(nil))
  3688. (defvar idlwave-sint-keywords '(nil))
  3689. (defvar idlwave-sint-methods '(nil))
  3690. (defvar idlwave-sint-classes '(nil))
  3691. (defvar idlwave-sint-dirs '(nil))
  3692. (defvar idlwave-sint-libnames '(nil))
  3693. (defun idlwave-reset-sintern (&optional what)
  3694. "Reset all sintern hashes."
  3695. ;; Make sure the hash functions are accessible.
  3696. (unless (and (fboundp 'gethash)
  3697. (fboundp 'puthash))
  3698. (require 'cl)
  3699. (or (fboundp 'puthash)
  3700. (defalias 'puthash 'cl-puthash)))
  3701. (let ((entries '((idlwave-sint-routines 1000 10)
  3702. (idlwave-sint-keywords 1000 10)
  3703. (idlwave-sint-methods 100 10)
  3704. (idlwave-sint-classes 10 10))))
  3705. ;; Make sure these are lists
  3706. (loop for entry in entries
  3707. for var = (car entry)
  3708. do (if (not (consp (symbol-value var))) (set var (list nil))))
  3709. ;; Reset the system & library hash
  3710. (when (or (eq what t) (eq what 'syslib)
  3711. (null (cdr idlwave-sint-routines)))
  3712. (loop for entry in entries
  3713. for var = (car entry) for size = (nth 1 entry)
  3714. do (setcdr (symbol-value var)
  3715. (make-hash-table ':size size ':test 'equal)))
  3716. (setq idlwave-sint-dirs nil
  3717. idlwave-sint-libnames nil))
  3718. ;; Reset the buffer & shell hash
  3719. (when (or (eq what t) (eq what 'bufsh)
  3720. (null (car idlwave-sint-routines)))
  3721. (loop for entry in entries
  3722. for var = (car entry) for size = (nth 1 entry)
  3723. do (setcar (symbol-value var)
  3724. (make-hash-table ':size size ':test 'equal))))))
  3725. (defun idlwave-sintern-routine-or-method (name &optional class set)
  3726. (if class
  3727. (idlwave-sintern-method name set)
  3728. (idlwave-sintern-routine name set)))
  3729. (defun idlwave-sintern (stype &rest args)
  3730. (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
  3731. ;;(defmacro idlwave-sintern (type var)
  3732. ;; `(cond ((not (stringp name)) name)
  3733. ;; ((gethash (downcase name) (cdr ,var)))
  3734. ;; ((gethash (downcase name) (car ,var)))
  3735. ;; (set (idlwave-sintern-set name ,type ,var set))
  3736. ;; (name)))
  3737. (defun idlwave-sintern-routine (name &optional set)
  3738. (cond ((not (stringp name)) name)
  3739. ((gethash (downcase name) (cdr idlwave-sint-routines)))
  3740. ((gethash (downcase name) (car idlwave-sint-routines)))
  3741. (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
  3742. (name)))
  3743. (defun idlwave-sintern-keyword (name &optional set)
  3744. (cond ((not (stringp name)) name)
  3745. ((gethash (downcase name) (cdr idlwave-sint-keywords)))
  3746. ((gethash (downcase name) (car idlwave-sint-keywords)))
  3747. (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
  3748. (name)))
  3749. (defun idlwave-sintern-method (name &optional set)
  3750. (cond ((not (stringp name)) name)
  3751. ((gethash (downcase name) (cdr idlwave-sint-methods)))
  3752. ((gethash (downcase name) (car idlwave-sint-methods)))
  3753. (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
  3754. (name)))
  3755. (defun idlwave-sintern-class (name &optional set)
  3756. (cond ((not (stringp name)) name)
  3757. ((gethash (downcase name) (cdr idlwave-sint-classes)))
  3758. ((gethash (downcase name) (car idlwave-sint-classes)))
  3759. (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
  3760. (name)))
  3761. (defun idlwave-sintern-dir (dir &optional set)
  3762. (car (or (member dir idlwave-sint-dirs)
  3763. (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
  3764. (defun idlwave-sintern-libname (name &optional set)
  3765. (car (or (member name idlwave-sint-libnames)
  3766. (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
  3767. (defun idlwave-sintern-set (name type tables set)
  3768. (let* ((func (or (cdr (assq type idlwave-completion-case))
  3769. 'identity))
  3770. (iname (funcall (if (eq func 'preserve) 'identity func) name))
  3771. (table (if (eq set 'sys) (cdr tables) (car tables))))
  3772. (puthash (downcase name) iname table)
  3773. iname))
  3774. (defun idlwave-sintern-keyword-list (kwd-list &optional set)
  3775. "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
  3776. (mapc (lambda(x)
  3777. (setcar x (idlwave-sintern-keyword (car x) set)))
  3778. (cdr kwd-list))
  3779. kwd-list)
  3780. (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
  3781. "Sintern all strings in the rinfo LIST.
  3782. With optional parameter SET: also set new patterns. Probably this
  3783. will always have to be t. If DEFAULT-DIR is passed, it is used as
  3784. the base of the directory."
  3785. (let (entry name type class kwds res source call new)
  3786. (while list
  3787. (setq entry (car list)
  3788. list (cdr list)
  3789. name (car entry)
  3790. type (nth 1 entry)
  3791. class (nth 2 entry)
  3792. source (nth 3 entry)
  3793. call (nth 4 entry)
  3794. kwds (nthcdr 5 entry))
  3795. ;; The class and name
  3796. (if class
  3797. (progn
  3798. (if (symbolp class) (setq class (symbol-name class)))
  3799. (setq class (idlwave-sintern-class class set))
  3800. (setq name (idlwave-sintern-method name set)))
  3801. (setq name (idlwave-sintern-routine name set)))
  3802. ;; The source
  3803. (let ((source-type (car source))
  3804. (source-file (nth 1 source))
  3805. (source-dir (if default-dir
  3806. (file-name-as-directory default-dir)
  3807. (nth 2 source)))
  3808. (source-lib (nth 3 source)))
  3809. (if (stringp source-dir)
  3810. (setq source-dir (idlwave-sintern-dir source-dir set)))
  3811. (if (stringp source-lib)
  3812. (setq source-lib (idlwave-sintern-libname source-lib set)))
  3813. (setq source (list source-type source-file source-dir source-lib)))
  3814. ;; The keywords
  3815. (setq kwds (mapcar (lambda (x)
  3816. (idlwave-sintern-keyword-list x set))
  3817. kwds))
  3818. ;; Build a canonicalized list
  3819. (setq new (nconc (list name type class source call) kwds)
  3820. res (cons new res)))
  3821. (nreverse res)))
  3822. ;; Creating new sintern tables
  3823. (defun idlwave-new-sintern-type (tag)
  3824. "Define a variable and a function to sintern the new type TAG.
  3825. This defines the function `idlwave-sintern-TAG' and the variable
  3826. `idlwave-sint-TAGs'."
  3827. (let* ((name (symbol-name tag))
  3828. (names (concat name "s"))
  3829. (var (intern (concat "idlwave-sint-" names)))
  3830. (func (intern (concat "idlwave-sintern-" name))))
  3831. (set var nil) ; initial value of the association list
  3832. (fset func ; set the function
  3833. `(lambda (name &optional set)
  3834. (cond ((not (stringp name)) name)
  3835. ((cdr (assoc (downcase name) ,var)))
  3836. (set
  3837. (setq ,var (cons (cons (downcase name) name) ,var))
  3838. name)
  3839. (name))))))
  3840. (defun idlwave-reset-sintern-type (tag)
  3841. "Reset the sintern variable associated with TAG."
  3842. (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
  3843. ;;---------------------------------------------------------------------------
  3844. ;; The variables which hold the information
  3845. (defvar idlwave-system-routines nil
  3846. "Holds the routine-info obtained by scanning buffers.")
  3847. (defvar idlwave-buffer-routines nil
  3848. "Holds the routine-info obtained by scanning buffers.")
  3849. (defvar idlwave-compiled-routines nil
  3850. "Holds the routine-info obtained by asking the shell.")
  3851. (defvar idlwave-unresolved-routines nil
  3852. "Holds the unresolved routine-info obtained by asking the shell.")
  3853. (defvar idlwave-user-catalog-routines nil
  3854. "Holds the procedure routine-info from the user scan.")
  3855. (defvar idlwave-library-catalog-routines nil
  3856. "Holds the procedure routine-info from the .idlwave_catalog library files.")
  3857. (defvar idlwave-library-catalog-libname nil
  3858. "Name of library catalog loaded from .idlwave_catalog files.")
  3859. (defvar idlwave-path-alist nil
  3860. "Alist with !PATH directories and zero or more flags if the dir has
  3861. been scanned in a user catalog ('user) or discovered in a library
  3862. catalog \('lib).")
  3863. (defvar idlwave-true-path-alist nil
  3864. "Like `idlwave-path-alist', but with true filenames.")
  3865. (defvar idlwave-routines nil
  3866. "Holds the combined procedure/function/method routine-info.")
  3867. (defvar idlwave-class-alist nil
  3868. "Holds the class names known to IDLWAVE.")
  3869. (defvar idlwave-class-history nil
  3870. "The history of classes selected with the minibuffer.")
  3871. (defvar idlwave-force-class-query nil)
  3872. (defvar idlwave-before-completion-wconf nil
  3873. "The window configuration just before the completion buffer was displayed.")
  3874. (defvar idlwave-last-system-routine-info-cons-cell nil
  3875. "The last cons cell in the system routine info.")
  3876. ;;
  3877. ;; The code to get routine info from different sources.
  3878. (defvar idlwave-system-routines)
  3879. (defvar idlwave-catalog-process nil
  3880. "The background process currently updating the catalog.")
  3881. (defun idlwave-routines ()
  3882. "Provide a list of IDL routines.
  3883. This routine loads the builtin routines on the first call.
  3884. Later it only returns the value of the variable."
  3885. (if (and idlwave-catalog-process
  3886. (processp idlwave-catalog-process))
  3887. (progn
  3888. (cond
  3889. ((equal (process-status idlwave-catalog-process) 'exit)
  3890. (message "updating........")
  3891. (setq idlwave-catalog-process nil)
  3892. (idlwave-update-routine-info '(4)))
  3893. ((equal (process-status idlwave-catalog-process) 'run)
  3894. ;; Keep it running...
  3895. )
  3896. (t
  3897. ;; Something is wrong, get rid of the process
  3898. (message "Problem with catalog process") (beep)
  3899. (condition-case nil
  3900. (kill-process idlwave-catalog-process)
  3901. (error nil))
  3902. (setq idlwave-catalog-process nil)))))
  3903. (or idlwave-routines
  3904. (progn
  3905. (idlwave-update-routine-info)
  3906. ;; return the current value
  3907. idlwave-routines)))
  3908. (defvar idlwave-update-rinfo-hook nil
  3909. "List of functions which should run after a global rinfo update.
  3910. Does not run after automatic updates of buffer or the shell.")
  3911. (defun idlwave-rescan-catalog-directories ()
  3912. "Rescan the previously selected directories. For batch processing."
  3913. (idlwave-update-routine-info '(16)))
  3914. (defun idlwave-rescan-asynchronously ()
  3915. "Dispatch another Emacs instance to update the idlwave catalog.
  3916. After the process finishes normally, the first access to routine info
  3917. will re-read the catalog."
  3918. (interactive)
  3919. (if (processp idlwave-catalog-process)
  3920. (if (eq (process-status idlwave-catalog-process) 'run)
  3921. (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
  3922. (progn
  3923. (condition-case nil
  3924. (kill-process idlwave-catalog-process)
  3925. (error nil))
  3926. (error "Process killed, no new process started"))
  3927. (error "Quit"))
  3928. (condition-case nil
  3929. (kill-process idlwave-catalog-process)
  3930. (error nil))))
  3931. (if (or (not idlwave-user-catalog-file)
  3932. (not (stringp idlwave-user-catalog-file))
  3933. (not (file-regular-p idlwave-user-catalog-file)))
  3934. (error "No catalog has been produced yet"))
  3935. (let* ((emacs (concat invocation-directory invocation-name))
  3936. (args (list "-batch"
  3937. "-l" (expand-file-name "~/.emacs")
  3938. "-l" "idlwave"
  3939. "-f" "idlwave-rescan-catalog-directories"))
  3940. (process (apply 'start-process "idlcat"
  3941. nil emacs args)))
  3942. (setq idlwave-catalog-process process)
  3943. (set-process-sentinel
  3944. process
  3945. (lambda (pro why)
  3946. (when (string-match "finished" why)
  3947. (setq idlwave-routines nil
  3948. idlwave-system-routines nil
  3949. idlwave-catalog-process nil)
  3950. (or (idlwave-start-load-rinfo-timer)
  3951. (idlwave-update-routine-info '(4))))))
  3952. (message "Background job started to update catalog file")))
  3953. ;; Format for all routine info user catalog, library catalogs, etc.:
  3954. ;;
  3955. ;; ("ROUTINE" type class
  3956. ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
  3957. ;; (buffer pro_file dir) | (compiled pro_file dir)
  3958. ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
  3959. ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
  3960. ;;
  3961. ;; DIR will be supplied dynamically while loading library catalogs,
  3962. ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
  3963. ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
  3964. ;; be nil, as can LINK1, etc., if no HTML help is available.
  3965. (defvar idlwave-load-rinfo-idle-timer)
  3966. (defvar idlwave-shell-path-query)
  3967. (defun idlwave-update-routine-info (&optional arg no-concatenate)
  3968. "Update the internal routine-info lists.
  3969. These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
  3970. and by `idlwave-complete' (\\[idlwave-complete]) to provide information
  3971. about individual routines.
  3972. The information can come from 4 sources:
  3973. 1. IDL programs in the current editing session
  3974. 2. Compiled modules in an IDL shell running as Emacs subprocess
  3975. 3. A list which covers the IDL system routines.
  3976. 4. A list which covers the prescanned library files.
  3977. Scans all IDLWAVE-mode buffers of the current editing session (see
  3978. `idlwave-scan-all-buffers-for-routine-info').
  3979. When an IDL shell is running, this command also queries the IDL program
  3980. for currently compiled routines.
  3981. With prefix ARG, also reload the system and library lists.
  3982. With two prefix ARG's, also rescans the chosen user catalog tree.
  3983. With three prefix args, dispatch asynchronous process to do the update.
  3984. If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
  3985. lists, but instead wait for the shell query to complete and
  3986. asynchronously finish updating routine info. This is set
  3987. automatically when called interactively. When you need routine
  3988. information updated immediately, leave NO-CONCATENATE nil."
  3989. (interactive "P\np")
  3990. ;; Stop any idle processing
  3991. (if (or (and (fboundp 'itimerp)
  3992. (itimerp idlwave-load-rinfo-idle-timer))
  3993. (and (fboundp 'timerp)
  3994. (timerp idlwave-load-rinfo-idle-timer)))
  3995. (cancel-timer idlwave-load-rinfo-idle-timer))
  3996. (cond
  3997. ((equal arg '(64))
  3998. ;; Start a background process which updates the catalog.
  3999. (idlwave-rescan-asynchronously))
  4000. ((equal arg '(16))
  4001. ;; Update the user catalog now, and wait for them.
  4002. (idlwave-create-user-catalog-file t))
  4003. (t
  4004. (let* ((load (or arg
  4005. idlwave-buffer-case-takes-precedence
  4006. (null idlwave-routines)))
  4007. ;; The override-idle means, even if the idle timer has done some
  4008. ;; preparing work, load and renormalize everything anyway.
  4009. (override-idle (or arg idlwave-buffer-case-takes-precedence)))
  4010. (setq idlwave-buffer-routines nil
  4011. idlwave-compiled-routines nil
  4012. idlwave-unresolved-routines nil)
  4013. ;; Reset the appropriate hashes
  4014. (if (get 'idlwave-reset-sintern 'done-by-idle)
  4015. ;; reset was already done in idle time, so skip this step now once
  4016. (put 'idlwave-reset-sintern 'done-by-idle nil)
  4017. (idlwave-reset-sintern (cond (load t)
  4018. ((null idlwave-system-routines) t)
  4019. (t 'bufsh))))
  4020. (if idlwave-buffer-case-takes-precedence
  4021. ;; We can safely scan the buffer stuff first
  4022. (progn
  4023. (idlwave-update-buffer-routine-info)
  4024. (and load (idlwave-load-all-rinfo override-idle)))
  4025. ;; We first do the system info, and then the buffers
  4026. (and load (idlwave-load-all-rinfo override-idle))
  4027. (idlwave-update-buffer-routine-info))
  4028. ;; Let's see if there is a shell
  4029. (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
  4030. (idlwave-shell-is-running)))
  4031. (ask-shell (and shell-is-running
  4032. idlwave-query-shell-for-routine-info)))
  4033. ;; Load the library catalogs again, first re-scanning the path
  4034. (when arg
  4035. (if shell-is-running
  4036. (idlwave-shell-send-command idlwave-shell-path-query
  4037. '(progn
  4038. (idlwave-shell-get-path-info)
  4039. (idlwave-scan-library-catalogs))
  4040. 'hide)
  4041. (idlwave-scan-library-catalogs)))
  4042. (if (or (not ask-shell)
  4043. (not no-concatenate))
  4044. ;; 1. If we are not going to ask the shell, we need to do the
  4045. ;; concatenation now.
  4046. ;; 2. When this function is called non-interactively, it
  4047. ;; means that someone needs routine info *now*. The
  4048. ;; shell update causes the concatenation to be
  4049. ;; *delayed*, so not in time for the current command.
  4050. ;; Therefore, we do a concatenation now, even though
  4051. ;; the shell might do it again.
  4052. (idlwave-concatenate-rinfo-lists nil 'run-hooks))
  4053. (when ask-shell
  4054. ;; Ask the shell about the routines it knows of.
  4055. (message "Querying the shell")
  4056. (idlwave-shell-update-routine-info nil t)))))))
  4057. (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
  4058. (defvar idlwave-load-rinfo-idle-timer nil)
  4059. (defun idlwave-start-load-rinfo-timer ()
  4060. (if (or (and (fboundp 'itimerp)
  4061. (itimerp idlwave-load-rinfo-idle-timer))
  4062. (and (fboundp 'timerp)
  4063. (timerp idlwave-load-rinfo-idle-timer)))
  4064. (cancel-timer idlwave-load-rinfo-idle-timer))
  4065. (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
  4066. (setq idlwave-load-rinfo-idle-timer nil)
  4067. (if (and idlwave-init-rinfo-when-idle-after
  4068. (numberp idlwave-init-rinfo-when-idle-after)
  4069. (not (equal 0 idlwave-init-rinfo-when-idle-after))
  4070. (not idlwave-routines))
  4071. (condition-case nil
  4072. (progn
  4073. (setq idlwave-load-rinfo-idle-timer
  4074. (run-with-idle-timer
  4075. idlwave-init-rinfo-when-idle-after
  4076. nil 'idlwave-load-rinfo-next-step)))
  4077. (error nil))))
  4078. ;;------ XML Help routine info system
  4079. (defun idlwave-load-system-routine-info ()
  4080. ;; Load the system routine info from the cached routine info file,
  4081. ;; which, if necessary, will be re-created from the XML file on
  4082. ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
  4083. ;; file distributed with older IDLWAVE versions (<6.0)
  4084. (unless (and (load idlwave-xml-system-rinfo-converted-file
  4085. 'noerror 'nomessage)
  4086. (idlwave-xml-system-routine-info-up-to-date))
  4087. ;; See if we can create it from XML source
  4088. (condition-case nil
  4089. (idlwave-convert-xml-system-routine-info)
  4090. (error
  4091. (unless (load idlwave-xml-system-rinfo-converted-file
  4092. 'noerror 'nomessage)
  4093. (if idlwave-system-routines
  4094. (message
  4095. "Failed to load converted routine info, using old conversion.")
  4096. (message
  4097. "Failed to convert XML routine info, falling back on idlw-rinfo.")
  4098. (if (not (load "idlw-rinfo" 'noerror 'nomessage))
  4099. (message
  4100. "Could not locate any system routine information."))))))))
  4101. (defun idlwave-xml-system-routine-info-up-to-date()
  4102. (let* ((dir (file-name-as-directory
  4103. (expand-file-name "help/online_help" (idlwave-sys-dir))))
  4104. (catalog-file (expand-file-name "idl_catalog.xml" dir)))
  4105. (file-newer-than-file-p ;converted file is newer than catalog
  4106. idlwave-xml-system-rinfo-converted-file
  4107. catalog-file)))
  4108. (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
  4109. (defvar idlwave-system-variables-alist nil
  4110. "Alist of system variables and the associated structure tags.
  4111. Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
  4112. (defvar idlwave-executive-commands-alist nil
  4113. "Alist of system variables and their help files.")
  4114. (defvar idlwave-help-special-topic-words nil)
  4115. (defun idlwave-shorten-syntax (syntax name &optional class)
  4116. ;; From a list of syntax statements, shorten with %s and group with "or"
  4117. (let ((case-fold-search t))
  4118. (mapconcat
  4119. (lambda (x)
  4120. (while (string-match name x)
  4121. (setq x (replace-match "%s" t t x)))
  4122. (if class
  4123. (while (string-match class x)
  4124. (setq x (replace-match "%s" t t x))))
  4125. x)
  4126. (nreverse syntax)
  4127. " or ")))
  4128. (defun idlwave-xml-create-class-method-lists (xml-entry)
  4129. ;; Create a class list entry from the xml parsed list., returning a
  4130. ;; cons of form (class-entry method-entries).
  4131. (let* ((nameblock (nth 1 xml-entry))
  4132. (class (cdr (assq 'name nameblock)))
  4133. (link (cdr (assq 'link nameblock)))
  4134. (params (cddr xml-entry))
  4135. (case-fold-search t)
  4136. class-entry
  4137. method methods-entry extra-kwds
  4138. props get-props set-props init-props inherits
  4139. pelem ptype)
  4140. (while params
  4141. (setq pelem (car params))
  4142. (when (listp pelem)
  4143. (setq ptype (car pelem)
  4144. props (car (cdr pelem)))
  4145. (cond
  4146. ((eq ptype 'SUPERCLASS)
  4147. (let ((pname (cdr (assq 'name props)))
  4148. (plink (cdr (assq 'link props))))
  4149. (unless (and (string= pname "None")
  4150. (string= plink "None"))
  4151. (push pname inherits))))
  4152. ((eq ptype 'PROPERTY)
  4153. (let ((pname (cdr (assq 'name props)))
  4154. (plink (cdr (assq 'link props)))
  4155. (get (string= (cdr (assq 'get props)) "Yes"))
  4156. (set (string= (cdr (assq 'set props)) "Yes"))
  4157. (init (string= (cdr (assq 'init props)) "Yes")))
  4158. (if get (push (list pname plink) get-props))
  4159. (if set (push (list pname plink) set-props))
  4160. (if init (push (list pname plink) init-props))))
  4161. ((eq ptype 'METHOD)
  4162. (setq method (cdr (assq 'name props)))
  4163. (setq extra-kwds ;;Assume all property keywords are gathered already
  4164. (cond
  4165. ((string-match (concat class "::Init") method)
  4166. (put 'init-props 'matched t)
  4167. init-props)
  4168. ((string-match (concat class "::GetProperty") method)
  4169. (put 'get-props 'matched t)
  4170. get-props)
  4171. ((string-match (concat class "::SetProperty") method)
  4172. (put 'set-props 'matched t)
  4173. set-props)
  4174. (t nil)))
  4175. (setq methods-entry
  4176. (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
  4177. methods-entry)))
  4178. (t)))
  4179. (setq params (cdr params)))
  4180. ;;(unless (get 'init-props 'matched)
  4181. ;; (message "Failed to match Init in class %s" class))
  4182. ;;(unless (get 'get-props 'matched)
  4183. ;; (message "Failed to match GetProperty in class %s" class))
  4184. ;;(unless (get 'set-props 'matched)
  4185. ;; (message "Failed to match SetProperty in class %s" class))
  4186. (setq class-entry
  4187. (if inherits
  4188. (list class (append '(inherits) inherits) (list 'link link))
  4189. (list class (list 'link link))))
  4190. (cons class-entry methods-entry)))
  4191. (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
  4192. ;; Create correctly structured list elements from ROUTINE or METHOD
  4193. ;; XML list structures. Return a list of list elements, with more
  4194. ;; than one sub-list possible if a routine can serve as both
  4195. ;; procedure and function (e.g. call_method).
  4196. (let* ((nameblock (nth 1 xml-entry))
  4197. (name (cdr (assq 'name nameblock)))
  4198. (link (cdr (assq 'link nameblock)))
  4199. (params (cddr xml-entry))
  4200. (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
  4201. (case-fold-search t)
  4202. syntax kwd klink pref-list kwds pelem ptype props result type)
  4203. (if class ;; strip out class name from class method name string
  4204. (if (string-match (concat class "::") name)
  4205. (setq name (substring name (match-end 0)))))
  4206. (while params
  4207. (setq pelem (car params))
  4208. (when (listp pelem)
  4209. (setq ptype (car pelem)
  4210. props (car (cdr pelem)))
  4211. (cond
  4212. ((eq ptype 'SYNTAX)
  4213. (setq syntax (cdr (assq 'name props)))
  4214. (if (string-match "-&gt;" syntax)
  4215. (setq syntax (replace-match "->" t nil syntax)))
  4216. (setq type (cdr (assq 'type props)))
  4217. (push syntax
  4218. (aref syntax-vec (cond
  4219. ((string-match "^pro" type) 0)
  4220. ((string-match "^fun" type) 1)
  4221. ((string-match "^exec" type) 2)))))
  4222. ((eq ptype 'KEYWORD)
  4223. (setq kwd (cdr (assq 'name props))
  4224. klink (cdr (assq 'link props)))
  4225. (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
  4226. (progn
  4227. (setq pref-list
  4228. (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
  4229. kwd (substring kwd (match-end 0)))
  4230. (loop for x in pref-list do
  4231. (push (list (concat x kwd) klink) kwds)))
  4232. (push (list kwd klink) kwds)))
  4233. (t))); Do nothing for the others
  4234. (setq params (cdr params)))
  4235. ;; Debug
  4236. ;; (if (and (null (aref syntax-vec 0))
  4237. ;; (null (aref syntax-vec 1))
  4238. ;; (null (aref syntax-vec 2)))
  4239. ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
  4240. ;; (if class
  4241. ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
  4242. ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
  4243. ;; Executive commands are treated specially
  4244. (if (aref syntax-vec 2)
  4245. (cons (substring name 1) link)
  4246. (if extra-kws (setq kwds (nconc kwds extra-kws)))
  4247. (setq kwds (idlwave-rinfo-group-keywords kwds link))
  4248. (loop for idx from 0 to 1 do
  4249. (if (aref syntax-vec idx)
  4250. (push (append (list name (if (eq idx 0) 'pro 'fun)
  4251. class '(system)
  4252. (idlwave-shorten-syntax
  4253. (aref syntax-vec idx) name class))
  4254. kwds) result)))
  4255. result)))
  4256. (defun idlwave-rinfo-group-keywords (kwds master-link)
  4257. ;; Group keywords by link file, as a list with elements
  4258. ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
  4259. (let (kwd link anchor linkfiles block master-elt)
  4260. (while kwds
  4261. (setq kwd (car kwds)
  4262. link (idlwave-split-link-target (nth 1 kwd))
  4263. anchor (cdr link)
  4264. link (car link)
  4265. kwd (car kwd))
  4266. (if (setq block (assoc link linkfiles))
  4267. (push (cons kwd anchor) (cdr block))
  4268. (push (list link (cons kwd anchor)) linkfiles))
  4269. (setq kwds (cdr kwds)))
  4270. ;; Ensure the master link is there
  4271. (if (setq master-elt (assoc master-link linkfiles))
  4272. (if (eq (car linkfiles) master-elt)
  4273. linkfiles
  4274. (cons master-elt (delq master-elt linkfiles)))
  4275. (push (list master-link) linkfiles))))
  4276. (defun idlwave-convert-xml-clean-statement-aliases (aliases)
  4277. ;; Clean up the syntax of routines which are actually aliases by
  4278. ;; removing the "OR" from the statements
  4279. (let (syntax entry)
  4280. (loop for x in aliases do
  4281. (setq entry (assoc x idlwave-system-routines))
  4282. (when entry
  4283. (while (string-match " +or +" (setq syntax (nth 4 entry)))
  4284. (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
  4285. (defun idlwave-convert-xml-clean-routine-aliases (aliases)
  4286. ;; Duplicate and trim original routine aliases from rinfo list
  4287. ;; This if for, e.g. OPENR/OPENW/OPENU
  4288. (let (alias remove-list new parts all-parts)
  4289. (loop for x in aliases do
  4290. (when (setq parts (split-string (cdr x) "/"))
  4291. (setq new (assoc (cdr x) all-parts))
  4292. (unless new
  4293. (setq new (cons (cdr x) parts))
  4294. (push new all-parts))
  4295. (setcdr new (delete (car x) (cdr new)))))
  4296. ;; Add any missing aliases (separate by slashes)
  4297. (loop for x in all-parts do
  4298. (if (cdr x)
  4299. (push (cons (nth 1 x) (car x)) aliases)))
  4300. (loop for x in aliases do
  4301. (when (setq alias (assoc (cdr x) idlwave-system-routines))
  4302. (unless (memq alias remove-list) (push alias remove-list))
  4303. (setq alias (copy-sequence alias))
  4304. (setcar alias (car x))
  4305. (push alias idlwave-system-routines)))
  4306. (loop for x in remove-list do
  4307. (delq x idlwave-system-routines))))
  4308. (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
  4309. ;; Duplicate and trim original routine aliases from rinfo list
  4310. ;; This if for, e.g. !X, !Y, !Z.
  4311. (let (alias remove-list)
  4312. (loop for x in aliases do
  4313. (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
  4314. (unless (memq alias remove-list) (push alias remove-list))
  4315. (setq alias (copy-sequence alias))
  4316. (setcar alias (car x))
  4317. (push alias idlwave-system-variables-alist)))
  4318. (loop for x in remove-list do
  4319. (delq x idlwave-system-variables-alist))))
  4320. (defun idlwave-xml-create-sysvar-alist (xml-entry)
  4321. ;; Create a sysvar list entry from the xml parsed list.
  4322. (let* ((nameblock (nth 1 xml-entry))
  4323. (name (cdr (assq 'name nameblock)))
  4324. (sysvar (substring name (progn (string-match "^ *!" name)
  4325. (match-end 0))))
  4326. (link (cdr (assq 'link nameblock)))
  4327. (params (cddr xml-entry))
  4328. (case-fold-search t)
  4329. pelem ptype props tags)
  4330. (while params
  4331. (setq pelem (car params))
  4332. (when (listp pelem)
  4333. (setq ptype (car pelem)
  4334. props (car (cdr pelem)))
  4335. (cond
  4336. ((eq ptype 'FIELD)
  4337. (push (cons (cdr (assq 'name props))
  4338. (cdr
  4339. (idlwave-split-link-target (cdr (assq 'link props)))))
  4340. tags))))
  4341. (setq params (cdr params)))
  4342. (delq nil
  4343. (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
  4344. (defvar idlwave-xml-routine-info-file nil)
  4345. (defun idlwave-save-routine-info ()
  4346. (if idlwave-xml-routine-info-file
  4347. (with-temp-file idlwave-xml-system-rinfo-converted-file
  4348. (insert
  4349. (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  4350. ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
  4351. ;; Automatically generated from source file:
  4352. ;; " idlwave-xml-routine-info-file "
  4353. ;; on " (current-time-string) "
  4354. ;; Do not edit."))
  4355. (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
  4356. idlwave-xml-routine-info-file))
  4357. (insert "\n(setq idlwave-system-routines\n '")
  4358. (prin1 idlwave-system-routines (current-buffer))
  4359. (insert ")")
  4360. (insert "\n(setq idlwave-system-variables-alist\n '")
  4361. (prin1 idlwave-system-variables-alist (current-buffer))
  4362. (insert ")")
  4363. (insert "\n(setq idlwave-system-class-info\n '")
  4364. (prin1 idlwave-system-class-info (current-buffer))
  4365. (insert ")")
  4366. (insert "\n(setq idlwave-executive-commands-alist\n '")
  4367. (prin1 idlwave-executive-commands-alist (current-buffer))
  4368. (insert ")")
  4369. (insert "\n(setq idlwave-help-special-topic-words\n '")
  4370. (prin1 idlwave-help-special-topic-words (current-buffer))
  4371. (insert ")"))))
  4372. (defun idlwave-convert-xml-system-routine-info ()
  4373. "Convert XML supplied IDL routine info into internal form.
  4374. Cache to disk for quick recovery."
  4375. (interactive)
  4376. (let* ((dir (file-name-as-directory
  4377. (expand-file-name "help/online_help" (idlwave-sys-dir))))
  4378. (catalog-file (expand-file-name "idl_catalog.xml" dir))
  4379. (elem-cnt 0)
  4380. props rinfo msg-cnt elem type nelem class-result alias
  4381. routines routine-aliases statement-aliases sysvar-aliases)
  4382. (if (not (file-exists-p catalog-file))
  4383. (error "No such XML routine info file: %s" catalog-file)
  4384. (if (not (file-readable-p catalog-file))
  4385. (error "Cannot read XML routine info file: %s" catalog-file)))
  4386. (message "Reading XML routine info...")
  4387. (setq rinfo (xml-parse-file catalog-file))
  4388. (message "Reading XML routine info...done")
  4389. (setq rinfo (assq 'CATALOG rinfo))
  4390. (unless rinfo (error "Failed to parse XML routine info"))
  4391. ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
  4392. (setq rinfo (cddr rinfo))
  4393. (setq nelem (length rinfo)
  4394. msg-cnt (/ nelem 20))
  4395. (setq idlwave-xml-routine-info-file nil)
  4396. (message "Converting XML routine info...")
  4397. (setq idlwave-system-routines nil
  4398. idlwave-system-variables-alist nil
  4399. idlwave-system-class-info nil
  4400. idlwave-executive-commands-alist nil
  4401. idlwave-help-special-topic-words nil)
  4402. (while rinfo
  4403. (setq elem (car rinfo)
  4404. rinfo (cdr rinfo))
  4405. (incf elem-cnt)
  4406. (when (listp elem)
  4407. (setq type (car elem)
  4408. props (car (cdr elem)))
  4409. (if (= (mod elem-cnt msg-cnt) 0)
  4410. (message "Converting XML routine info...%2d%%"
  4411. (floor (* elem-cnt 100.0) nelem)))
  4412. (cond
  4413. ((eq type 'ROUTINE)
  4414. (if (setq alias (assq 'alias_to props))
  4415. (push (cons (cdr (assq 'name props)) (cdr alias))
  4416. routine-aliases)
  4417. (setq routines (idlwave-xml-create-rinfo-list elem))
  4418. (if (listp (cdr routines))
  4419. (setq idlwave-system-routines
  4420. (nconc idlwave-system-routines routines))
  4421. ;; a cons cell is an executive commands
  4422. (push routines idlwave-executive-commands-alist))))
  4423. ((eq type 'CLASS)
  4424. (setq class-result (idlwave-xml-create-class-method-lists elem))
  4425. (push (car class-result) idlwave-system-class-info)
  4426. (setq idlwave-system-routines
  4427. (nconc idlwave-system-routines (cdr class-result))))
  4428. ((eq type 'STATEMENT)
  4429. (push (cons (cdr (assq 'name props))
  4430. (cdr (assq 'link props)))
  4431. idlwave-help-special-topic-words)
  4432. ;; Save the links to those which are statement aliases (not routines)
  4433. (if (setq alias (assq 'alias_to props))
  4434. (unless (member (cdr alias) statement-aliases)
  4435. (push (cdr alias) statement-aliases))))
  4436. ((eq type 'SYSVAR)
  4437. (if (setq alias (cdr (assq 'alias_to props)))
  4438. (push (cons (substring (cdr (assq 'name props)) 1)
  4439. (substring alias 1))
  4440. sysvar-aliases)
  4441. (push (idlwave-xml-create-sysvar-alist elem)
  4442. idlwave-system-variables-alist)))
  4443. (t))))
  4444. (idlwave-convert-xml-clean-routine-aliases routine-aliases)
  4445. (idlwave-convert-xml-clean-statement-aliases statement-aliases)
  4446. (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
  4447. (setq idlwave-xml-routine-info-file catalog-file)
  4448. (idlwave-save-routine-info)
  4449. (message "Converting XML routine info...done")))
  4450. ;; ("ROUTINE" type class
  4451. ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
  4452. ;; (buffer pro_file dir) | (compiled pro_file dir)
  4453. ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
  4454. ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
  4455. (defun idlwave-load-rinfo-next-step ()
  4456. (let ((inhibit-quit t)
  4457. (arr idlwave-load-rinfo-steps-done))
  4458. (if (catch 'exit
  4459. (when (not (aref arr 0))
  4460. (message "Loading system routine info in idle time...")
  4461. (idlwave-load-system-routine-info)
  4462. ;;(load "idlw-rinfo" 'noerror 'nomessage)
  4463. (message "Loading system routine info in idle time...done")
  4464. (aset arr 0 t)
  4465. (throw 'exit t))
  4466. (when (not (aref arr 1))
  4467. (message "Normalizing idlwave-system-routines in idle time...")
  4468. (idlwave-reset-sintern t)
  4469. (put 'idlwave-reset-sintern 'done-by-idle t)
  4470. (setq idlwave-system-routines
  4471. (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
  4472. (message "Normalizing idlwave-system-routines in idle time...done")
  4473. (aset arr 1 t)
  4474. (throw 'exit t))
  4475. (when (not (aref arr 2))
  4476. (when (and (stringp idlwave-user-catalog-file)
  4477. (file-regular-p idlwave-user-catalog-file))
  4478. (message "Loading user catalog in idle time...")
  4479. (condition-case nil
  4480. (load-file idlwave-user-catalog-file)
  4481. (error (throw 'exit nil)))
  4482. ;; Check for the old style catalog and warn
  4483. (if (and
  4484. (boundp 'idlwave-library-routines)
  4485. idlwave-library-routines)
  4486. (progn
  4487. (setq idlwave-library-routines nil)
  4488. (ding)
  4489. (message "Outdated user catalog: %s... recreate"
  4490. idlwave-user-catalog-file))
  4491. (message "Loading user catalog in idle time...done")))
  4492. (aset arr 2 t)
  4493. (throw 'exit t))
  4494. (when (not (aref arr 3))
  4495. (when idlwave-user-catalog-routines
  4496. (message "Normalizing user catalog routines in idle time...")
  4497. (setq idlwave-user-catalog-routines
  4498. (idlwave-sintern-rinfo-list
  4499. idlwave-user-catalog-routines 'sys))
  4500. (message
  4501. "Normalizing user catalog routines in idle time...done"))
  4502. (aset arr 3 t)
  4503. (throw 'exit t))
  4504. (when (not (aref arr 4))
  4505. (idlwave-scan-library-catalogs
  4506. "Loading and normalizing library catalogs in idle time...")
  4507. (aset arr 4 t)
  4508. (throw 'exit t))
  4509. (when (not (aref arr 5))
  4510. (message "Finishing initialization in idle time...")
  4511. (idlwave-routines)
  4512. (message "Finishing initialization in idle time...done")
  4513. (aset arr 5 t)
  4514. (throw 'exit nil)))
  4515. ;; restart the timer
  4516. (if (sit-for 1)
  4517. (idlwave-load-rinfo-next-step)
  4518. (setq idlwave-load-rinfo-idle-timer
  4519. (run-with-idle-timer
  4520. idlwave-init-rinfo-when-idle-after
  4521. nil 'idlwave-load-rinfo-next-step))))))
  4522. (defvar idlwave-after-load-rinfo-hook nil)
  4523. (defun idlwave-load-all-rinfo (&optional force)
  4524. ;; Load and case-treat the system, user catalog, and library routine
  4525. ;; info files.
  4526. ;; System
  4527. (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
  4528. ;;(load "idlw-rinfo" 'noerror 'nomessage))
  4529. (idlwave-load-system-routine-info))
  4530. (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
  4531. (message "Normalizing idlwave-system-routines...")
  4532. (setq idlwave-system-routines
  4533. (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
  4534. (message "Normalizing idlwave-system-routines...done"))
  4535. (when idlwave-system-routines
  4536. (setq idlwave-routines (copy-sequence idlwave-system-routines))
  4537. (setq idlwave-last-system-routine-info-cons-cell
  4538. (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
  4539. ;; User catalog
  4540. (when (and (stringp idlwave-user-catalog-file)
  4541. (file-regular-p idlwave-user-catalog-file))
  4542. (condition-case nil
  4543. (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
  4544. (load-file idlwave-user-catalog-file))
  4545. (error nil))
  4546. (when (and
  4547. (boundp 'idlwave-library-routines)
  4548. idlwave-library-routines)
  4549. (setq idlwave-library-routines nil)
  4550. (error "Outdated user catalog: %s... recreate"
  4551. idlwave-user-catalog-file))
  4552. (setq idlwave-true-path-alist nil)
  4553. (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
  4554. (message "Normalizing user catalog routines...")
  4555. (setq idlwave-user-catalog-routines
  4556. (idlwave-sintern-rinfo-list
  4557. idlwave-user-catalog-routines 'sys))
  4558. (message "Normalizing user catalog routines...done")))
  4559. ;; Library catalog
  4560. (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
  4561. (idlwave-scan-library-catalogs
  4562. "Loading and normalizing library catalogs..."))
  4563. (run-hooks 'idlwave-after-load-rinfo-hook))
  4564. (defun idlwave-update-buffer-routine-info ()
  4565. (let (res)
  4566. (cond
  4567. ((eq idlwave-scan-all-buffers-for-routine-info t)
  4568. ;; Scan all buffers, current buffer last
  4569. (message "Scanning all buffers...")
  4570. (setq res (idlwave-get-routine-info-from-buffers
  4571. (reverse (buffer-list)))))
  4572. ((null idlwave-scan-all-buffers-for-routine-info)
  4573. ;; Don't scan any buffers
  4574. (setq res nil))
  4575. (t
  4576. ;; Just scan this buffer
  4577. (if (derived-mode-p 'idlwave-mode)
  4578. (progn
  4579. (message "Scanning current buffer...")
  4580. (setq res (idlwave-get-routine-info-from-buffers
  4581. (list (current-buffer))))))))
  4582. ;; Put the result into the correct variable
  4583. (setq idlwave-buffer-routines
  4584. (idlwave-sintern-rinfo-list res 'set))))
  4585. (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
  4586. "Put the different sources for routine information together."
  4587. ;; The sequence here is important because earlier definitions shadow
  4588. ;; later ones. We assume that if things in the buffers are newer
  4589. ;; then in the shell of the system, they are meant to be different.
  4590. (let ((temp (append idlwave-buffer-routines
  4591. idlwave-compiled-routines
  4592. idlwave-library-catalog-routines
  4593. idlwave-user-catalog-routines)))
  4594. ;; Not actually used for anything?
  4595. (if idlwave-last-system-routine-info-cons-cell
  4596. (setcdr idlwave-last-system-routine-info-cons-cell temp)
  4597. (setq idlwave-last-system-routine-info-cons-cell (cons temp nil))))
  4598. (setq idlwave-class-alist nil)
  4599. ;; Give a message with information about the number of routines we have.
  4600. (unless quiet
  4601. (message
  4602. "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
  4603. (length idlwave-buffer-routines)
  4604. (length idlwave-compiled-routines)
  4605. (length idlwave-library-catalog-routines)
  4606. (length idlwave-user-catalog-routines)
  4607. (length idlwave-system-routines)))
  4608. (if run-hook
  4609. (run-hooks 'idlwave-update-rinfo-hook)))
  4610. (defun idlwave-class-alist ()
  4611. "Return the class alist - make it if necessary."
  4612. (or idlwave-class-alist
  4613. (let (class)
  4614. (loop for x in idlwave-routines do
  4615. (when (and (setq class (nth 2 x))
  4616. (not (assq class idlwave-class-alist)))
  4617. (push (list class) idlwave-class-alist)))
  4618. idlwave-class-alist)))
  4619. ;; Three functions for the hooks
  4620. (defun idlwave-save-buffer-update ()
  4621. (idlwave-update-current-buffer-info 'save-buffer))
  4622. (defun idlwave-kill-buffer-update ()
  4623. (idlwave-update-current-buffer-info 'kill-buffer))
  4624. (defun idlwave-new-buffer-update ()
  4625. (idlwave-update-current-buffer-info 'find-file))
  4626. (defun idlwave-update-current-buffer-info (why)
  4627. "Update `idlwave-routines' for current buffer.
  4628. Can run from `after-save-hook'."
  4629. (when (and (derived-mode-p 'idlwave-mode)
  4630. (or (eq t idlwave-auto-routine-info-updates)
  4631. (memq why idlwave-auto-routine-info-updates))
  4632. idlwave-scan-all-buffers-for-routine-info
  4633. idlwave-routines)
  4634. (condition-case nil
  4635. (let (routines)
  4636. (idlwave-replace-buffer-routine-info
  4637. (buffer-file-name)
  4638. (if (eq why 'kill-buffer)
  4639. nil
  4640. (setq routines
  4641. (idlwave-sintern-rinfo-list
  4642. (idlwave-get-routine-info-from-buffers
  4643. (list (current-buffer))) 'set))))
  4644. (idlwave-concatenate-rinfo-lists 'quiet)
  4645. routines)
  4646. (error nil))))
  4647. (defun idlwave-replace-buffer-routine-info (file new)
  4648. "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
  4649. (let ((list idlwave-buffer-routines)
  4650. found)
  4651. (while list
  4652. ;; The following test uses eq to make sure it works correctly
  4653. ;; when two buffers visit the same file. Then the file names
  4654. ;; will be equal, but not eq.
  4655. (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
  4656. (progn
  4657. (setcar list nil)
  4658. (setq found t))
  4659. (if found
  4660. ;; End of that section reached. Jump.
  4661. (setq list nil)))
  4662. (setq list (cdr list)))
  4663. (setq idlwave-buffer-routines
  4664. (append new (delq nil idlwave-buffer-routines)))))
  4665. ;;----- Scanning buffers -------------------
  4666. (defun idlwave-get-routine-info-from-buffers (buffers)
  4667. "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
  4668. (let (buf routine-lists res)
  4669. (save-excursion
  4670. (while (setq buf (pop buffers))
  4671. (set-buffer buf)
  4672. (if (and (derived-mode-p 'idlwave-mode)
  4673. buffer-file-name)
  4674. ;; yes, this buffer has the right mode.
  4675. (progn (setq res (condition-case nil
  4676. (idlwave-get-buffer-routine-info)
  4677. (error nil)))
  4678. (push res routine-lists)))))
  4679. ;; Concatenate the individual lists and return the result
  4680. (apply 'nconc routine-lists)))
  4681. (defun idlwave-get-buffer-routine-info ()
  4682. "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
  4683. (let* ((case-fold-search t)
  4684. routine-list string entry)
  4685. (save-excursion
  4686. (save-restriction
  4687. (widen)
  4688. (goto-char (point-min))
  4689. (while (re-search-forward
  4690. "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
  4691. (setq string (buffer-substring-no-properties
  4692. (match-beginning 0)
  4693. (progn
  4694. (idlwave-end-of-statement)
  4695. (point))))
  4696. (setq entry (idlwave-parse-definition string))
  4697. (push entry routine-list))))
  4698. routine-list))
  4699. (defvar idlwave-scanning-lib-dir)
  4700. (defvar idlwave-scanning-lib)
  4701. (defun idlwave-parse-definition (string)
  4702. "Parse a module definition."
  4703. (let ((case-fold-search t)
  4704. start name args type keywords class)
  4705. ;; Remove comments
  4706. (while (string-match ";.*" string)
  4707. (setq string (replace-match "" t t string)))
  4708. ;; Remove the continuation line stuff
  4709. (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
  4710. (setq string (replace-match "\\1 " t nil string)))
  4711. (while (string-match "\n" string)
  4712. (setq string (replace-match " " t nil string)))
  4713. ;; Match the name and type.
  4714. (when (string-match
  4715. "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
  4716. (setq start (match-end 0))
  4717. (setq type (downcase (match-string 1 string)))
  4718. (if (match-beginning 3)
  4719. (setq class (match-string 3 string)))
  4720. (setq name (match-string 4 string)))
  4721. ;; Match normal args and keyword args
  4722. (while (string-match
  4723. ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
  4724. string start)
  4725. (setq start (match-end 0))
  4726. (if (match-beginning 3)
  4727. (push (match-string 1 string) keywords)
  4728. (push (match-string 1 string) args)))
  4729. ;; Normalize and sort.
  4730. (setq args (nreverse args))
  4731. (setq keywords (sort keywords (lambda (a b)
  4732. (string< (downcase a) (downcase b)))))
  4733. ;; Make and return the entry
  4734. ;; We don't know which argument are optional, so this information
  4735. ;; will not be contained in the calling sequence.
  4736. (list name
  4737. (if (equal type "pro") 'pro 'fun)
  4738. class
  4739. (cond ((not (boundp 'idlwave-scanning-lib))
  4740. (list 'buffer (buffer-file-name)))
  4741. ; ((string= (downcase (file-name-base))
  4742. ; (downcase name))
  4743. ; (list 'lib))
  4744. ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
  4745. (t (list 'user (file-name-nondirectory (buffer-file-name))
  4746. idlwave-scanning-lib-dir "UserLib")))
  4747. (concat
  4748. (if (string= type "function") "Result = " "")
  4749. (if class "Obj ->[%s::]" "")
  4750. "%s"
  4751. (if args
  4752. (concat
  4753. (if (string= type "function") "(" ", ")
  4754. (mapconcat 'identity args ", ")
  4755. (if (string= type "function") ")" ""))))
  4756. (if keywords
  4757. (cons nil (mapcar 'list keywords)) ;No help file
  4758. nil))))
  4759. ;;----- Scanning the user catalog -------------------
  4760. (defun idlwave-sys-dir ()
  4761. "Return the syslib directory, or a dummy that never matches."
  4762. (cond
  4763. ((and idlwave-system-directory
  4764. (not (string= idlwave-system-directory "")))
  4765. idlwave-system-directory)
  4766. ((getenv "IDL_DIR"))
  4767. (t "@@@@@@@@")))
  4768. (defun idlwave-create-user-catalog-file (&optional arg)
  4769. "Scan all files on selected dirs of IDL search path for routine information.
  4770. A widget checklist will allow you to choose the directories. Write
  4771. the result as a file `idlwave-user-catalog-file'. When this file
  4772. exists, it will be automatically loaded to give routine information
  4773. about library routines. With ARG, just rescan the same directories
  4774. as last time - so no widget will pop up."
  4775. (interactive "P")
  4776. ;; Make sure the file is loaded if it exists.
  4777. (if (and (stringp idlwave-user-catalog-file)
  4778. (file-regular-p idlwave-user-catalog-file))
  4779. (condition-case nil
  4780. (load-file idlwave-user-catalog-file)
  4781. (error nil)))
  4782. ;; Make sure the file name makes sense
  4783. (unless (and (stringp idlwave-user-catalog-file)
  4784. (> (length idlwave-user-catalog-file) 0)
  4785. (file-accessible-directory-p
  4786. (file-name-directory idlwave-user-catalog-file))
  4787. (not (string= "" (file-name-nondirectory
  4788. idlwave-user-catalog-file))))
  4789. (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
  4790. (cond
  4791. ;; Rescan the known directories
  4792. ((and arg idlwave-path-alist
  4793. (consp (car idlwave-path-alist)))
  4794. (idlwave-scan-user-lib-files idlwave-path-alist))
  4795. ;; Expand the directories from library-path and run the widget
  4796. (idlwave-library-path
  4797. (idlwave-display-user-catalog-widget
  4798. (if idlwave-true-path-alist
  4799. ;; Propagate any flags on the existing path-alist
  4800. (mapcar (lambda (x)
  4801. (let ((path-entry (assoc (file-truename x)
  4802. idlwave-true-path-alist)))
  4803. (if path-entry
  4804. (cons x (cdr path-entry))
  4805. (list x))))
  4806. (idlwave-expand-path idlwave-library-path))
  4807. (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
  4808. ;; Ask the shell for the path and then run the widget
  4809. (t
  4810. (message "Asking the shell for IDL path...")
  4811. (require 'idlw-shell)
  4812. (idlwave-shell-send-command idlwave-shell-path-query
  4813. '(idlwave-user-catalog-command-hook nil)
  4814. 'hide))))
  4815. ;; Parse shell path information and select among it.
  4816. (defun idlwave-user-catalog-command-hook (&optional arg)
  4817. ;; Command hook used by `idlwave-create-user-catalog-file'.
  4818. (if arg
  4819. ;; Scan immediately
  4820. (idlwave-scan-user-lib-files idlwave-path-alist)
  4821. ;; Set the path and display the widget
  4822. (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
  4823. (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
  4824. (idlwave-display-user-catalog-widget idlwave-path-alist)))
  4825. (defconst idlwave-user-catalog-widget-help-string
  4826. "This is the front-end to the creation of the IDLWAVE user catalog.
  4827. Please select the directories on IDL's search path from which you
  4828. would like to extract routine information, to be stored in the file:
  4829. %s
  4830. If this is not the correct file, first set variable
  4831. `idlwave-user-catalog-file', and call this command again.
  4832. N.B. Many libraries include pre-scanned catalog files
  4833. \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
  4834. not be scanned. You can scan your own libraries off-line using the
  4835. perl script `idlwave_catalog'.
  4836. After selecting the directories, choose [Scan & Save] to scan the library
  4837. directories and save the routine info.
  4838. \n")
  4839. (defvar idlwave-widget)
  4840. (defvar widget-keymap)
  4841. (defun idlwave-display-user-catalog-widget (dirs-list)
  4842. "Create the widget to select IDL search path directories for scanning."
  4843. (interactive)
  4844. (require 'widget)
  4845. (require 'wid-edit)
  4846. (unless dirs-list
  4847. (error "Don't know IDL's search path"))
  4848. (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
  4849. (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
  4850. (kill-all-local-variables)
  4851. (make-local-variable 'idlwave-widget)
  4852. (widget-insert (format idlwave-user-catalog-widget-help-string
  4853. idlwave-user-catalog-file))
  4854. (widget-create 'push-button
  4855. :notify 'idlwave-widget-scan-user-lib-files
  4856. "Scan & Save")
  4857. (widget-insert " ")
  4858. (widget-create 'push-button
  4859. :notify 'idlwave-delete-user-catalog-file
  4860. "Delete File")
  4861. (widget-insert " ")
  4862. (widget-create 'push-button
  4863. :notify
  4864. (lambda (&rest ignore)
  4865. (let ((path-list (widget-get idlwave-widget :path-dirs)))
  4866. (dolist (x path-list)
  4867. (unless (memq 'lib (cdr x))
  4868. (idlwave-path-alist-add-flag x 'user)))
  4869. (idlwave-display-user-catalog-widget path-list)))
  4870. "Select All Non-Lib")
  4871. (widget-insert " ")
  4872. (widget-create 'push-button
  4873. :notify
  4874. (lambda (&rest ignore)
  4875. (let ((path-list (widget-get idlwave-widget :path-dirs)))
  4876. (dolist (x path-list)
  4877. (idlwave-path-alist-remove-flag x 'user))
  4878. (idlwave-display-user-catalog-widget path-list)))
  4879. "Deselect All")
  4880. (widget-insert " ")
  4881. (widget-create 'push-button
  4882. :notify (lambda (&rest ignore)
  4883. (kill-buffer (current-buffer)))
  4884. "Quit")
  4885. (widget-insert "\n\n")
  4886. (widget-insert "Select Directories: \n")
  4887. (setq idlwave-widget
  4888. (apply 'widget-create
  4889. 'checklist
  4890. :value (delq nil (mapcar (lambda (x)
  4891. (if (memq 'user (cdr x))
  4892. (car x)))
  4893. dirs-list))
  4894. :greedy t
  4895. :tag "List of directories"
  4896. (mapcar (lambda (x)
  4897. (list 'item
  4898. (if (memq 'lib (cdr x))
  4899. (concat "[LIB] " (car x) )
  4900. (car x)))) dirs-list)))
  4901. (widget-put idlwave-widget :path-dirs dirs-list)
  4902. (widget-insert "\n")
  4903. (use-local-map widget-keymap)
  4904. (widget-setup)
  4905. (goto-char (point-min))
  4906. (delete-other-windows))
  4907. (defun idlwave-delete-user-catalog-file (&rest ignore)
  4908. (if (yes-or-no-p
  4909. (format "Delete file %s " idlwave-user-catalog-file))
  4910. (progn
  4911. (delete-file idlwave-user-catalog-file)
  4912. (message "%s has been deleted" idlwave-user-catalog-file))))
  4913. (defun idlwave-widget-scan-user-lib-files (&rest ignore)
  4914. ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
  4915. (let* ((widget idlwave-widget)
  4916. (selected-dirs (widget-value widget))
  4917. (path-alist (widget-get widget :path-dirs))
  4918. (this-path-alist path-alist)
  4919. dir-entry)
  4920. (while (setq dir-entry (pop this-path-alist))
  4921. (if (member
  4922. (if (memq 'lib (cdr dir-entry))
  4923. (concat "[LIB] " (car dir-entry))
  4924. (car dir-entry))
  4925. selected-dirs)
  4926. (idlwave-path-alist-add-flag dir-entry 'user)
  4927. (idlwave-path-alist-remove-flag dir-entry 'user)))
  4928. (idlwave-scan-user-lib-files path-alist)))
  4929. (defvar font-lock-mode)
  4930. (defun idlwave-scan-user-lib-files (path-alist)
  4931. ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
  4932. (let* ((idlwave-scanning-lib t)
  4933. (idlwave-scanning-lib-dir "")
  4934. (idlwave-completion-case nil)
  4935. dirs-alist dir files file)
  4936. (setq idlwave-user-catalog-routines nil
  4937. idlwave-path-alist path-alist ; for library-path instead
  4938. idlwave-true-path-alist nil)
  4939. (if idlwave-auto-write-paths (idlwave-write-paths))
  4940. (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
  4941. (idlwave-mode)
  4942. (setq dirs-alist (reverse path-alist))
  4943. (while (setq dir (pop dirs-alist))
  4944. (when (memq 'user (cdr dir)) ; Has it marked for scan?
  4945. (setq dir (car dir))
  4946. (setq idlwave-scanning-lib-dir dir)
  4947. (when (file-directory-p dir)
  4948. (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
  4949. (while (setq file (pop files))
  4950. (when (file-regular-p file)
  4951. (if (not (file-readable-p file))
  4952. (message "Skipping %s (no read permission)" file)
  4953. (message "Scanning %s..." file)
  4954. (erase-buffer)
  4955. (insert-file-contents file 'visit)
  4956. (setq idlwave-user-catalog-routines
  4957. (append (idlwave-get-routine-info-from-buffers
  4958. (list (current-buffer)))
  4959. idlwave-user-catalog-routines)))))))))
  4960. (message "Creating user catalog file...")
  4961. (kill-buffer "*idlwave-scan.pro*")
  4962. (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
  4963. (with-temp-buffer
  4964. (insert ";; IDLWAVE user catalog file\n")
  4965. (insert (format ";; Created %s\n\n" (current-time-string)))
  4966. ;; Define the routine info list
  4967. (insert "\n(setq idlwave-user-catalog-routines\n '(")
  4968. (let ((standard-output (current-buffer)))
  4969. (mapc (lambda (x)
  4970. (insert "\n ")
  4971. (prin1 x)
  4972. (goto-char (point-max)))
  4973. idlwave-user-catalog-routines))
  4974. (insert (format "))\n\n;;; %s ends here\n"
  4975. (file-name-nondirectory idlwave-user-catalog-file)))
  4976. (write-region nil nil idlwave-user-catalog-file)))
  4977. (message "Creating user catalog file...done")
  4978. (message "Info for %d routines saved in %s"
  4979. (length idlwave-user-catalog-routines)
  4980. idlwave-user-catalog-file)
  4981. (sit-for 2)
  4982. (idlwave-update-routine-info t))
  4983. (defun idlwave-read-paths ()
  4984. (if (and (stringp idlwave-path-file)
  4985. (file-regular-p idlwave-path-file))
  4986. (condition-case nil
  4987. (load idlwave-path-file t t t)
  4988. (error nil))))
  4989. (defun idlwave-write-paths ()
  4990. (interactive)
  4991. (when (and idlwave-path-alist idlwave-system-directory)
  4992. (with-temp-buffer
  4993. (insert ";; IDLWAVE paths\n")
  4994. (insert (format ";; Created %s\n\n" (current-time-string)))
  4995. ;; Define the variable which knows the value of "!DIR"
  4996. (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
  4997. idlwave-system-directory))
  4998. ;; Define the variable which contains a list of all scanned directories
  4999. (insert "\n(setq idlwave-path-alist\n '(")
  5000. (let ((standard-output (current-buffer)))
  5001. (mapc (lambda (x)
  5002. (insert "\n ")
  5003. (prin1 x)
  5004. (goto-char (point-max)))
  5005. idlwave-path-alist))
  5006. (insert "))\n")
  5007. (write-region nil nil idlwave-path-file))))
  5008. (defun idlwave-expand-path (path &optional default-dir)
  5009. ;; Expand parts of path starting with '+' recursively into directory list.
  5010. ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
  5011. (message "Expanding path...")
  5012. (let (path1 dir recursive)
  5013. (while (setq dir (pop path))
  5014. (if (setq recursive (string= (substring dir 0 1) "+"))
  5015. (setq dir (substring dir 1)))
  5016. (if (and recursive
  5017. (not (file-name-absolute-p dir)))
  5018. (setq dir (expand-file-name dir default-dir)))
  5019. (if recursive
  5020. ;; Expand recursively
  5021. (setq path1 (append (idlwave-recursive-directory-list dir) path1))
  5022. ;; Keep unchanged
  5023. (push dir path1)))
  5024. (message "Expanding path...done")
  5025. (nreverse path1)))
  5026. (defun idlwave-recursive-directory-list (dir)
  5027. ;; Return a list of all directories below DIR, including DIR itself
  5028. (let ((path (list dir)) path1 file files)
  5029. (while (setq dir (pop path))
  5030. (when (file-directory-p dir)
  5031. (setq files (nreverse (directory-files dir t "[^.]")))
  5032. (while (setq file (pop files))
  5033. (if (file-directory-p file)
  5034. (push (file-name-as-directory file) path)))
  5035. (push dir path1)))
  5036. path1))
  5037. ;;----- Scanning the library catalogs ------------------
  5038. (defun idlwave-scan-library-catalogs (&optional message-base no-load)
  5039. "Scan for library catalog files (.idlwave_catalog) and ingest.
  5040. All directories on `idlwave-path-alist' (or `idlwave-library-path'
  5041. instead, if present) are searched. Print MESSAGE-BASE along with the
  5042. libraries being loaded, if passed, and skip loading/normalizing if
  5043. NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
  5044. be set to nil to disable library catalog scanning."
  5045. (when idlwave-use-library-catalogs
  5046. (let ((dirs
  5047. (if idlwave-library-path
  5048. (idlwave-expand-path idlwave-library-path)
  5049. (mapcar 'car idlwave-path-alist)))
  5050. (old-libname "")
  5051. dir-entry dir catalog all-routines)
  5052. (if message-base (message message-base))
  5053. (while (setq dir (pop dirs))
  5054. (catch 'continue
  5055. (when (file-readable-p
  5056. (setq catalog (expand-file-name ".idlwave_catalog" dir)))
  5057. (unless no-load
  5058. (setq idlwave-library-catalog-routines nil)
  5059. ;; Load the catalog file
  5060. (condition-case nil
  5061. (load catalog t t t)
  5062. (error (throw 'continue t)))
  5063. (when (and
  5064. message-base
  5065. (not (string= idlwave-library-catalog-libname
  5066. old-libname)))
  5067. (message "%s" (concat message-base
  5068. idlwave-library-catalog-libname))
  5069. (setq old-libname idlwave-library-catalog-libname))
  5070. (when idlwave-library-catalog-routines
  5071. (setq all-routines
  5072. (append
  5073. (idlwave-sintern-rinfo-list
  5074. idlwave-library-catalog-routines 'sys dir)
  5075. all-routines))))
  5076. ;; Add a 'lib flag if on path-alist
  5077. (when (and idlwave-path-alist
  5078. (setq dir-entry (assoc dir idlwave-path-alist)))
  5079. (idlwave-path-alist-add-flag dir-entry 'lib)))))
  5080. (unless no-load (setq idlwave-library-catalog-routines all-routines))
  5081. (if message-base (message (concat message-base "done"))))))
  5082. ;;----- Communicating with the Shell -------------------
  5083. ;; First, here is the idl program which can be used to query IDL for
  5084. ;; defined routines.
  5085. (defconst idlwave-routine-info.pro
  5086. "
  5087. ;; START OF IDLWAVE SUPPORT ROUTINES
  5088. pro idlwave_print_safe,item,limit
  5089. catch,err
  5090. if err ne 0 then begin
  5091. print,'Could not print item.'
  5092. return
  5093. endif
  5094. if n_elements(item) gt limit then $
  5095. print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
  5096. else print,item
  5097. end
  5098. pro idlwave_print_info_entry,name,func=func,separator=sep
  5099. ;; See if it's an object method
  5100. if name eq '' then return
  5101. func = keyword_set(func)
  5102. methsep = strpos(name,'::')
  5103. meth = methsep ne -1
  5104. ;; Get routine info
  5105. pars = routine_info(name,/parameters,functions=func)
  5106. source = routine_info(name,/source,functions=func)
  5107. nargs = pars.num_args
  5108. nkw = pars.num_kw_args
  5109. if nargs gt 0 then args = pars.args
  5110. if nkw gt 0 then kwargs = pars.kw_args
  5111. ;; Trim the class, and make the name
  5112. if meth then begin
  5113. class = strmid(name,0,methsep)
  5114. name = strmid(name,methsep+2,strlen(name)-1)
  5115. if nargs gt 0 then begin
  5116. ;; remove the self argument
  5117. wh = where(args ne 'SELF',nargs)
  5118. if nargs gt 0 then args = args[wh]
  5119. endif
  5120. endif else begin
  5121. ;; No class, just a normal routine.
  5122. class = \"\"
  5123. endelse
  5124. ;; Calling sequence
  5125. cs = \"\"
  5126. if func then cs = 'Result = '
  5127. if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
  5128. cs = cs + '%s'
  5129. if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
  5130. if nargs gt 0 then begin
  5131. for j=0,nargs-1 do begin
  5132. cs = cs + args[j]
  5133. if j lt nargs-1 then cs = cs + ', '
  5134. endfor
  5135. end
  5136. if func then cs = cs + ')'
  5137. ;; Keyword arguments
  5138. kwstring = ''
  5139. if nkw gt 0 then begin
  5140. for j=0,nkw-1 do begin
  5141. kwstring = kwstring + ' ' + kwargs[j]
  5142. endfor
  5143. endif
  5144. ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
  5145. print,ret + ': ' + name + sep + class + sep + source[0].path $
  5146. + sep + cs + sep + kwstring
  5147. end
  5148. pro idlwave_routine_info,file
  5149. on_error,1
  5150. sep = '<@>'
  5151. print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
  5152. all = routine_info()
  5153. fileQ=n_elements(file) ne 0
  5154. if fileQ then file=strtrim(file,2)
  5155. for i=0L,n_elements(all)-1L do begin
  5156. if fileQ then begin
  5157. if (routine_info(all[i],/SOURCE)).path eq file then $
  5158. idlwave_print_info_entry,all[i],separator=sep
  5159. endif else idlwave_print_info_entry,all[i],separator=sep
  5160. endfor
  5161. all = routine_info(/functions)
  5162. for i=0L,n_elements(all)-1L do begin
  5163. if fileQ then begin
  5164. if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
  5165. idlwave_print_info_entry,all[i],separator=sep,/FUNC
  5166. endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
  5167. endfor
  5168. print,'>>>END OF IDLWAVE ROUTINE INFO'
  5169. end
  5170. pro idlwave_get_sysvars
  5171. on_error,1
  5172. catch,error_status
  5173. if error_status ne 0 then begin
  5174. print, 'Cannot get info about system variables'
  5175. endif else begin
  5176. help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
  5177. s = strtrim(strjoin(s,' ',/single),2) ; make one line
  5178. v = strsplit(s,' +',/regex,/extract) ; get variables
  5179. for i=0L,n_elements(v)-1 do begin
  5180. t = [''] ; get tag list
  5181. a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
  5182. print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
  5183. endfor
  5184. endelse
  5185. end
  5186. pro idlwave_get_class_tags, class
  5187. res = execute('tags=tag_names({'+class+'})')
  5188. if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
  5189. end
  5190. ;; END OF IDLWAVE SUPPORT ROUTINES
  5191. "
  5192. "The IDL programs to get info from the shell.")
  5193. (defvar idlwave-idlwave_routine_info-compiled nil
  5194. "Remember if the routine info procedure is already compiled.")
  5195. (defvar idlwave-shell-temp-pro-file)
  5196. (defvar idlwave-shell-temp-rinfo-save-file)
  5197. (defun idlwave-shell-compile-helper-routines (&optional wait)
  5198. (unless (and idlwave-idlwave_routine_info-compiled
  5199. (file-readable-p (idlwave-shell-temp-file 'rinfo)))
  5200. (with-current-buffer (idlwave-find-file-noselect
  5201. (idlwave-shell-temp-file 'pro))
  5202. (erase-buffer)
  5203. (insert idlwave-routine-info.pro)
  5204. (save-buffer 0))
  5205. (idlwave-shell-send-command
  5206. (concat ".run \"" idlwave-shell-temp-pro-file "\"")
  5207. nil 'hide wait)
  5208. (idlwave-shell-send-command
  5209. (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
  5210. (idlwave-shell-temp-file 'rinfo))
  5211. nil 'hide)
  5212. (setq idlwave-idlwave_routine_info-compiled t))
  5213. ;; Restore if necessary. Must use execute to hide lame routine_info
  5214. ;; errors on undefined routine
  5215. (idlwave-shell-send-command
  5216. (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
  5217. idlwave-shell-temp-rinfo-save-file
  5218. idlwave-shell-temp-rinfo-save-file)
  5219. nil 'hide))
  5220. (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
  5221. "Query the shell for routine_info of compiled modules and update the lists."
  5222. ;; Save and compile the procedure. The compiled procedure is then
  5223. ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
  5224. ;; need to test for and possibly RESTORE the procedure each time we
  5225. ;; use it, since the user may have killed or redefined it. In
  5226. ;; particular, .RESET_SESSION will kill all user procedures. If
  5227. ;; FILE is set, only update routine info for routines in that file.
  5228. (idlwave-shell-compile-helper-routines wait)
  5229. ; execute the routine_info procedure, and analyze the output
  5230. (idlwave-shell-send-command
  5231. (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
  5232. `(progn
  5233. (idlwave-shell-routine-info-filter)
  5234. (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
  5235. 'hide wait))
  5236. ;; ---------------------------------------------------------------------------
  5237. ;;
  5238. ;; Completion and displaying routine calling sequences
  5239. (defvar idlwave-completion-help-info nil)
  5240. (defvar idlwave-completion-help-links nil)
  5241. (defvar idlwave-current-obj_new-class nil)
  5242. (defvar idlwave-complete-special nil)
  5243. (defvar method-selector)
  5244. (defvar class-selector)
  5245. (defvar type-selector)
  5246. (defvar super-classes)
  5247. (defun idlwave-complete (&optional arg module class)
  5248. "Complete a function, procedure or keyword name at point.
  5249. This function is smart and figures out what can be completed
  5250. at this point.
  5251. - At the beginning of a statement it completes procedure names.
  5252. - In the middle of a statement it completes function names.
  5253. - After a `(' or `,' in the argument list of a function or procedure,
  5254. it completes a keyword of the relevant function or procedure.
  5255. - In the first arg of `OBJ_NEW', it completes a class name.
  5256. When several completions are possible, a list will be displayed in
  5257. the *Completions* buffer. If this list is too long to fit into the
  5258. window, scrolling can be achieved by repeatedly pressing
  5259. \\[idlwave-complete].
  5260. The function also knows about object methods. When it needs a class
  5261. name, the action depends upon `idlwave-query-class', which see. You
  5262. can force IDLWAVE to ask you for a class name with a
  5263. \\[universal-argument] prefix argument to this command.
  5264. See also the variables `idlwave-keyword-completion-adds-equal' and
  5265. `idlwave-function-completion-adds-paren'.
  5266. The optional ARG can be used to specify the completion type in order
  5267. to override IDLWAVE's idea of what should be completed at point.
  5268. Possible values are:
  5269. 0 <=> query for the completion type
  5270. 1 <=> `procedure'
  5271. 2 <=> `procedure-keyword'
  5272. 3 <=> `function'
  5273. 4 <=> `function-keyword'
  5274. 5 <=> `procedure-method'
  5275. 6 <=> `procedure-method-keyword'
  5276. 7 <=> `function-method'
  5277. 8 <=> `function-method-keyword'
  5278. 9 <=> `class'
  5279. As a special case, the universal argument C-u forces completion of
  5280. function names in places where the default would be a keyword.
  5281. Two prefix argument, C-u C-u, prompts for a regexp by which to limit
  5282. completion.
  5283. For Lisp programmers only:
  5284. When we force a keyword, optional argument MODULE can contain the module name.
  5285. When we force a method or a method keyword, CLASS can specify the class."
  5286. (interactive "P")
  5287. (idlwave-routines)
  5288. (let* ((where-list
  5289. (if (and arg
  5290. (or (and (integerp arg) (not (equal arg '(16))))
  5291. (symbolp arg)))
  5292. (idlwave-make-force-complete-where-list arg module class)
  5293. (idlwave-where)))
  5294. (what (nth 2 where-list))
  5295. (idlwave-force-class-query (equal arg '(4)))
  5296. (completion-regexp-list
  5297. (if (equal arg '(16))
  5298. (list (read-string (concat "Completion Regexp: "))))))
  5299. (if (and module (string-match "::" module))
  5300. (setq class (substring module 0 (match-beginning 0))
  5301. module (substring module (match-end 0))))
  5302. (cond
  5303. ((and (null arg)
  5304. (eq (car-safe last-command) 'idlwave-display-completion-list)
  5305. (get-buffer-window "*Completions*"))
  5306. (setq this-command last-command)
  5307. (idlwave-scroll-completions))
  5308. ;; Complete a filename in quotes
  5309. ((and (idlwave-in-quote)
  5310. (not (eq what 'class)))
  5311. (idlwave-complete-filename))
  5312. ;; Check for any special completion functions
  5313. ((and idlwave-complete-special
  5314. (idlwave-call-special idlwave-complete-special)))
  5315. ((null what)
  5316. (error "Nothing to complete here"))
  5317. ;; Complete a class
  5318. ((eq what 'class)
  5319. (setq idlwave-completion-help-info '(class))
  5320. (idlwave-complete-class))
  5321. ((eq what 'procedure)
  5322. ;; Complete a procedure name
  5323. (let* ((cw-list (nth 3 where-list))
  5324. (class-selector (idlwave-determine-class cw-list 'pro))
  5325. (super-classes (unless (idlwave-explicit-class-listed cw-list)
  5326. (idlwave-all-class-inherits class-selector)))
  5327. (isa (concat "procedure" (if class-selector "-method" "")))
  5328. (type-selector 'pro))
  5329. (setq idlwave-completion-help-info
  5330. (list 'routine nil type-selector class-selector nil super-classes))
  5331. (idlwave-complete-in-buffer
  5332. 'procedure (if class-selector 'method 'routine)
  5333. (idlwave-routines) 'idlwave-selector
  5334. (format "Select a %s name%s"
  5335. isa
  5336. (if class-selector
  5337. (format " (class is %s)"
  5338. (if (eq class-selector t)
  5339. "unknown" class-selector))
  5340. ""))
  5341. isa
  5342. 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
  5343. ((eq what 'function)
  5344. ;; Complete a function name
  5345. (let* ((cw-list (nth 3 where-list))
  5346. (class-selector (idlwave-determine-class cw-list 'fun))
  5347. (super-classes (unless (idlwave-explicit-class-listed cw-list)
  5348. (idlwave-all-class-inherits class-selector)))
  5349. (isa (concat "function" (if class-selector "-method" "")))
  5350. (type-selector 'fun))
  5351. (setq idlwave-completion-help-info
  5352. (list 'routine nil type-selector class-selector nil super-classes))
  5353. (idlwave-complete-in-buffer
  5354. 'function (if class-selector 'method 'routine)
  5355. (idlwave-routines) 'idlwave-selector
  5356. (format "Select a %s name%s"
  5357. isa
  5358. (if class-selector
  5359. (format " (class is %s)"
  5360. (if (eq class-selector t)
  5361. "unknown" class-selector))
  5362. ""))
  5363. isa
  5364. 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
  5365. ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
  5366. (equal arg '(4)))
  5367. (idlwave-complete 3))
  5368. ((eq what 'procedure-keyword)
  5369. ;; Complete a procedure keyword
  5370. (let* ((where (nth 3 where-list))
  5371. (name (car where))
  5372. (method-selector name)
  5373. (type-selector 'pro)
  5374. (class (idlwave-determine-class where 'pro))
  5375. (class-selector class)
  5376. (super-classes (idlwave-all-class-inherits class-selector))
  5377. (isa (format "procedure%s-keyword" (if class "-method" "")))
  5378. (entry (idlwave-best-rinfo-assq
  5379. name 'pro class (idlwave-routines)))
  5380. (system (if entry (eq (car (nth 3 entry)) 'system)))
  5381. (list (idlwave-entry-keywords entry 'do-link)))
  5382. (unless (or entry (eq class t))
  5383. (error "Nothing known about procedure %s"
  5384. (idlwave-make-full-name class name)))
  5385. (setq list (idlwave-fix-keywords name 'pro class list
  5386. super-classes system))
  5387. (unless list (error "No keywords available for procedure %s"
  5388. (idlwave-make-full-name class name)))
  5389. (setq idlwave-completion-help-info
  5390. (list 'keyword name type-selector class-selector entry super-classes))
  5391. (idlwave-complete-in-buffer
  5392. 'keyword 'keyword list nil
  5393. (format "Select keyword for procedure %s%s"
  5394. (idlwave-make-full-name class name)
  5395. (if (or (member '("_EXTRA") list)
  5396. (member '("_REF_EXTRA") list))
  5397. " (note _EXTRA)" ""))
  5398. isa
  5399. 'idlwave-attach-keyword-classes)))
  5400. ((eq what 'function-keyword)
  5401. ;; Complete a function keyword
  5402. (let* ((where (nth 3 where-list))
  5403. (name (car where))
  5404. (method-selector name)
  5405. (type-selector 'fun)
  5406. (class (idlwave-determine-class where 'fun))
  5407. (class-selector class)
  5408. (super-classes (idlwave-all-class-inherits class-selector))
  5409. (isa (format "function%s-keyword" (if class "-method" "")))
  5410. (entry (idlwave-best-rinfo-assq
  5411. name 'fun class (idlwave-routines)))
  5412. (system (if entry (eq (car (nth 3 entry)) 'system)))
  5413. (list (idlwave-entry-keywords entry 'do-link))
  5414. msg-name)
  5415. (unless (or entry (eq class t))
  5416. (error "Nothing known about function %s"
  5417. (idlwave-make-full-name class name)))
  5418. (setq list (idlwave-fix-keywords name 'fun class list
  5419. super-classes system))
  5420. ;; OBJ_NEW: Messages mention the proper Init method
  5421. (setq msg-name (if (and (null class)
  5422. (string= (upcase name) "OBJ_NEW"))
  5423. (concat idlwave-current-obj_new-class
  5424. "::Init (via OBJ_NEW)")
  5425. (idlwave-make-full-name class name)))
  5426. (unless list (error "No keywords available for function %s"
  5427. msg-name))
  5428. (setq idlwave-completion-help-info
  5429. (list 'keyword name type-selector class-selector nil super-classes))
  5430. (idlwave-complete-in-buffer
  5431. 'keyword 'keyword list nil
  5432. (format "Select keyword for function %s%s" msg-name
  5433. (if (or (member '("_EXTRA") list)
  5434. (member '("_REF_EXTRA") list))
  5435. " (note _EXTRA)" ""))
  5436. isa
  5437. 'idlwave-attach-keyword-classes)))
  5438. (t (error "This should not happen (idlwave-complete)")))))
  5439. (defvar idlwave-complete-special nil
  5440. "List of special completion functions.
  5441. These functions are called for each completion. Each function must
  5442. check if its own special completion context is present. If yes, it
  5443. should use `idlwave-complete-in-buffer' to do some completion and
  5444. return t. If such a function returns t, *no further* attempts to
  5445. complete other contexts will be done. If the function returns nil,
  5446. other completions will be tried.")
  5447. (defun idlwave-call-special (functions &rest args)
  5448. (let ((funcs functions)
  5449. fun ret)
  5450. (catch 'exit
  5451. (while (setq fun (pop funcs))
  5452. (if (setq ret (apply fun args))
  5453. (throw 'exit ret)))
  5454. nil)))
  5455. (defun idlwave-make-force-complete-where-list (what &optional module class)
  5456. ;; Return an artificial WHERE specification to force the completion
  5457. ;; routine to complete a specific item independent of context.
  5458. ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
  5459. ;; MODULE and CLASS can be used to specify the routine name and class.
  5460. ;; The class name will also be found in MODULE if that is like "class::mod".
  5461. (let* ((what-list '(("procedure") ("procedure-keyword")
  5462. ("function") ("function-keyword")
  5463. ("procedure-method") ("procedure-method-keyword")
  5464. ("function-method") ("function-method-keyword")
  5465. ("class")))
  5466. (module (idlwave-sintern-routine-or-method module class))
  5467. (class (idlwave-sintern-class class))
  5468. (what (cond
  5469. ((equal what 0)
  5470. (setq what
  5471. (intern (completing-read
  5472. "Complete what? " what-list nil t))))
  5473. ((integerp what)
  5474. (setq what (intern (car (nth (1- what) what-list)))))
  5475. ((and what
  5476. (symbolp what)
  5477. (assoc (symbol-name what) what-list))
  5478. what)
  5479. (t (error "Invalid WHAT"))))
  5480. (nil-list '(nil nil nil nil))
  5481. (class-list (list nil nil (or class t) nil)))
  5482. (cond
  5483. ((eq what 'procedure)
  5484. (list nil-list nil-list 'procedure nil-list nil))
  5485. ((eq what 'procedure-keyword)
  5486. (let* ((class-selector nil)
  5487. (super-classes nil)
  5488. (type-selector 'pro)
  5489. (pro (or module
  5490. (idlwave-completing-read
  5491. "Procedure: " (idlwave-routines) 'idlwave-selector))))
  5492. (setq pro (idlwave-sintern-routine pro))
  5493. (list nil-list nil-list 'procedure-keyword
  5494. (list pro nil nil nil) nil)))
  5495. ((eq what 'function)
  5496. (list nil-list nil-list 'function nil-list nil))
  5497. ((eq what 'function-keyword)
  5498. (let* ((class-selector nil)
  5499. (super-classes nil)
  5500. (type-selector 'fun)
  5501. (func (or module
  5502. (idlwave-completing-read
  5503. "Function: " (idlwave-routines) 'idlwave-selector))))
  5504. (setq func (idlwave-sintern-routine func))
  5505. (list nil-list nil-list 'function-keyword
  5506. (list func nil nil nil) nil)))
  5507. ((eq what 'procedure-method)
  5508. (list nil-list nil-list 'procedure class-list nil))
  5509. ((eq what 'procedure-method-keyword)
  5510. (let* ((class (idlwave-determine-class class-list 'pro))
  5511. (class-selector class)
  5512. (super-classes (idlwave-all-class-inherits class-selector))
  5513. (type-selector 'pro)
  5514. (pro (or module
  5515. (idlwave-completing-read
  5516. (format "Procedure in %s class: " class-selector)
  5517. (idlwave-routines) 'idlwave-selector))))
  5518. (setq pro (idlwave-sintern-method pro))
  5519. (list nil-list nil-list 'procedure-keyword
  5520. (list pro nil class nil) nil)))
  5521. ((eq what 'function-method)
  5522. (list nil-list nil-list 'function class-list nil))
  5523. ((eq what 'function-method-keyword)
  5524. (let* ((class (idlwave-determine-class class-list 'fun))
  5525. (class-selector class)
  5526. (super-classes (idlwave-all-class-inherits class-selector))
  5527. (type-selector 'fun)
  5528. (func (or module
  5529. (idlwave-completing-read
  5530. (format "Function in %s class: " class-selector)
  5531. (idlwave-routines) 'idlwave-selector))))
  5532. (setq func (idlwave-sintern-method func))
  5533. (list nil-list nil-list 'function-keyword
  5534. (list func nil class nil) nil)))
  5535. ((eq what 'class)
  5536. (list nil-list nil-list 'class nil-list nil))
  5537. (t (error "Invalid value for WHAT")))))
  5538. (defun idlwave-completing-read (&rest args)
  5539. ;; Completing read, case insensitive
  5540. (let ((old-value (default-value 'completion-ignore-case)))
  5541. (unwind-protect
  5542. (progn
  5543. (setq-default completion-ignore-case t)
  5544. (apply 'completing-read args))
  5545. (setq-default completion-ignore-case old-value))))
  5546. (defvar idlwave-shell-default-directory)
  5547. (defun idlwave-complete-filename ()
  5548. "Use the comint stuff to complete a file name."
  5549. (require 'comint)
  5550. (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
  5551. (comint-completion-addsuffix nil)
  5552. (default-directory
  5553. (if (and (boundp 'idlwave-shell-default-directory)
  5554. (stringp idlwave-shell-default-directory)
  5555. (file-directory-p idlwave-shell-default-directory))
  5556. idlwave-shell-default-directory
  5557. default-directory)))
  5558. (comint-dynamic-complete-filename)))
  5559. (defun idlwave-make-full-name (class name)
  5560. ;; Make a fully qualified module name including the class name
  5561. (concat (if class (format "%s::" class) "") name))
  5562. (defun idlwave-rinfo-assoc (name type class list)
  5563. "Like `idlwave-rinfo-assq', but sintern strings first."
  5564. (idlwave-rinfo-assq
  5565. (idlwave-sintern-routine-or-method name class)
  5566. type (idlwave-sintern-class class) list))
  5567. (defun idlwave-rinfo-assq (name type class list)
  5568. ;; Works like assq, but also checks type and class
  5569. (catch 'exit
  5570. (let (match)
  5571. (while (setq match (assq name list))
  5572. (and (or (eq type t)
  5573. (eq (nth 1 match) type))
  5574. (eq (nth 2 match) class)
  5575. (throw 'exit match))
  5576. (setq list (cdr (memq match list)))))))
  5577. (defun idlwave-rinfo-assq-any-class (name type class list)
  5578. ;; Return the first matching method on the inheritance list
  5579. (let* ((classes (cons class (idlwave-all-class-inherits class)))
  5580. class rtn)
  5581. (while classes
  5582. (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
  5583. (setq classes nil)))
  5584. rtn))
  5585. (defun idlwave-best-rinfo-assq (name type class list &optional with-file
  5586. keep-system)
  5587. "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
  5588. If WITH-FILE is passed, find the best rinfo entry with a file
  5589. included. If KEEP-SYSTEM is set, don't prune system for compiled
  5590. syslib files."
  5591. (let ((twins (idlwave-routine-twins
  5592. (idlwave-rinfo-assq-any-class name type class list)
  5593. list))
  5594. syslibp)
  5595. (when (> (length twins) 1)
  5596. (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
  5597. (if (and (null keep-system)
  5598. (eq 'system (car (nth 3 (car twins))))
  5599. (setq syslibp (idlwave-any-syslib (cdr twins)))
  5600. (not (equal 1 syslibp)))
  5601. ;; Its a compiled syslib, so we need to remove the system entry
  5602. (setq twins (cdr twins)))
  5603. (if with-file
  5604. (setq twins (delq nil
  5605. (mapcar (lambda (x)
  5606. (if (nth 1 (nth 3 x)) x))
  5607. twins)))))
  5608. (car twins)))
  5609. (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
  5610. keep-system)
  5611. "Like `idlwave-best-rinfo-assq', but sintern strings first."
  5612. (idlwave-best-rinfo-assq
  5613. (idlwave-sintern-routine-or-method name class)
  5614. type (idlwave-sintern-class class) list with-file keep-system))
  5615. (defun idlwave-any-syslib (entries)
  5616. "Does the entry list ENTRIES contain a syslib entry?
  5617. If yes, return the index (>=1)."
  5618. (let (file (cnt 0))
  5619. (catch 'exit
  5620. (while entries
  5621. (incf cnt)
  5622. (setq file (idlwave-routine-source-file (nth 3 (car entries))))
  5623. (if (and file (idlwave-syslib-p file))
  5624. (throw 'exit cnt)
  5625. (setq entries (cdr entries))))
  5626. nil)))
  5627. (defun idlwave-all-assq (key list)
  5628. "Return a list of all associations of Key in LIST."
  5629. (let (rtn elt)
  5630. (while (setq elt (assq key list))
  5631. (push elt rtn)
  5632. (setq list (cdr (memq elt list))))
  5633. (nreverse rtn)))
  5634. (defun idlwave-all-method-classes (method &optional type)
  5635. "Return all classes which have a method METHOD.
  5636. TYPE is 'fun or 'pro.
  5637. When TYPE is not specified, both procedures and functions will be considered."
  5638. (if (null method)
  5639. (mapcar 'car (idlwave-class-alist))
  5640. (let (rtn)
  5641. (mapc (lambda (x)
  5642. (and (nth 2 x)
  5643. (or (not type)
  5644. (eq type (nth 1 x)))
  5645. (push (nth 2 x) rtn)))
  5646. (idlwave-all-assq method (idlwave-routines)))
  5647. (idlwave-uniquify rtn))))
  5648. (defun idlwave-all-method-keyword-classes (method keyword &optional type)
  5649. "Return all classes which have a method METHOD with keyword KEYWORD.
  5650. TYPE is 'fun or 'pro.
  5651. When TYPE is not specified, both procedures and functions will be considered."
  5652. (if (or (null method)
  5653. (null keyword))
  5654. nil
  5655. (let (rtn)
  5656. (mapc (lambda (x)
  5657. (and (nth 2 x) ; non-nil class
  5658. (or (not type) ; correct or unspecified type
  5659. (eq type (nth 1 x)))
  5660. (assoc keyword (idlwave-entry-keywords x))
  5661. (push (nth 2 x) rtn)))
  5662. (idlwave-all-assq method (idlwave-routines)))
  5663. (idlwave-uniquify rtn))))
  5664. (defun idlwave-members-only (list club)
  5665. "Return list of all elements in LIST which are also in CLUB."
  5666. (let (rtn)
  5667. (while list
  5668. (if (member (car list) club)
  5669. (setq rtn (cons (car list) rtn)))
  5670. (setq list (cdr list)))
  5671. (nreverse rtn)))
  5672. (defun idlwave-nonmembers-only (list club)
  5673. "Return list of all elements in LIST which are not in CLUB."
  5674. (let (rtn)
  5675. (while list
  5676. (if (member (car list) club)
  5677. nil
  5678. (setq rtn (cons (car list) rtn)))
  5679. (setq list (cdr list)))
  5680. (nreverse rtn)))
  5681. (defun idlwave-explicit-class-listed (info)
  5682. "Return whether or not the class is listed explicitly, ala a->b::c.
  5683. INFO is as returned by `idlwave-what-function' or `-procedure'."
  5684. (let ((apos (nth 3 info)))
  5685. (if apos
  5686. (save-excursion (goto-char apos)
  5687. (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
  5688. (defvar idlwave-determine-class-special nil
  5689. "List of special functions for determining class.
  5690. Must accept two arguments: `apos' and `info'.")
  5691. (defun idlwave-determine-class (info type)
  5692. ;; Determine the class of a routine call.
  5693. ;; INFO is the `cw-list' structure as returned by idlwave-where.
  5694. ;; The second element in this structure is the class. When nil, we
  5695. ;; return nil. When t, try to get the class from text properties at
  5696. ;; the arrow. When the object is "self", we use the class of the
  5697. ;; current routine. otherwise prompt the user for a class name.
  5698. ;; Also stores the selected class as a text property at the arrow.
  5699. ;; TYPE is 'fun or 'pro.
  5700. (let* ((class (nth 2 info))
  5701. (apos (nth 3 info))
  5702. (nassoc (assoc (if (stringp (car info))
  5703. (upcase (car info))
  5704. (car info))
  5705. idlwave-query-class))
  5706. (dassoc (assq (if (car info) 'keyword-default 'method-default)
  5707. idlwave-query-class))
  5708. (query (cond (nassoc (cdr nassoc))
  5709. (dassoc (cdr dassoc))
  5710. (t t)))
  5711. (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
  5712. (is-self
  5713. (and arrow
  5714. (save-excursion (goto-char apos)
  5715. (forward-word -1)
  5716. (let ((case-fold-search t))
  5717. (looking-at "self\\>")))))
  5718. (force-query idlwave-force-class-query)
  5719. store special-class class-alist)
  5720. (cond
  5721. ((null class) nil)
  5722. ((eq t class)
  5723. ;; There is an object which would like to know its class
  5724. (if (and arrow (get-text-property apos 'idlwave-class)
  5725. idlwave-store-inquired-class
  5726. (not force-query))
  5727. (setq class (get-text-property apos 'idlwave-class)
  5728. class (idlwave-sintern-class class)))
  5729. (if (and (eq t class) is-self)
  5730. (setq class (or (nth 2 (idlwave-current-routine)) class)))
  5731. ;; Before prompting, try any special class determination routines
  5732. (when (and (eq t class)
  5733. idlwave-determine-class-special
  5734. (not force-query))
  5735. (setq special-class
  5736. (idlwave-call-special idlwave-determine-class-special apos))
  5737. (if special-class
  5738. (setq class (idlwave-sintern-class special-class)
  5739. store idlwave-store-inquired-class)))
  5740. ;; Prompt for a class, if we need to
  5741. (when (and (eq class t)
  5742. (or force-query query))
  5743. (setq class-alist
  5744. (mapcar 'list (idlwave-all-method-classes (car info) type)))
  5745. (setq class
  5746. (idlwave-sintern-class
  5747. (cond
  5748. ((and (= (length class-alist) 0) (not force-query))
  5749. (error "No classes available with method %s" (car info)))
  5750. ((and (= (length class-alist) 1) (not force-query))
  5751. (car (car class-alist)))
  5752. (t
  5753. (setq store idlwave-store-inquired-class)
  5754. (idlwave-completing-read
  5755. (format "Class%s: " (if (stringp (car info))
  5756. (format " for %s method %s"
  5757. type (car info))
  5758. ""))
  5759. class-alist nil nil nil 'idlwave-class-history))))))
  5760. ;; Store it, if requested
  5761. (when (and class (not (eq t class)))
  5762. ;; We have a real class here
  5763. (when (and store arrow)
  5764. (condition-case ()
  5765. (add-text-properties
  5766. apos (+ apos 2)
  5767. `(idlwave-class ,class face ,idlwave-class-arrow-face
  5768. rear-nonsticky t))
  5769. (error nil)))
  5770. (setf (nth 2 info) class))
  5771. ;; Return the class
  5772. class)
  5773. ;; Default as fallback
  5774. (t class))))
  5775. (defun idlwave-selector (a)
  5776. (and (eq (nth 1 a) type-selector)
  5777. (or (and (nth 2 a) (eq class-selector t))
  5778. (eq (nth 2 a) class-selector)
  5779. (memq (nth 2 a) super-classes))))
  5780. (defun idlwave-add-file-link-selector (a)
  5781. ;; Record a file link, if any, for the tested names during selection.
  5782. (let ((sel (idlwave-selector a)) file)
  5783. (if (and sel (setq file (idlwave-entry-has-help a)))
  5784. (push (cons (car a) file) idlwave-completion-help-links))
  5785. sel))
  5786. (defun idlwave-where ()
  5787. "Find out where we are.
  5788. The return value is a list with the following stuff:
  5789. \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
  5790. PRO-LIST (PRO POINT CLASS ARROW)
  5791. FUNC-LIST (FUNC POINT CLASS ARROW)
  5792. COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
  5793. CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
  5794. be completed here.
  5795. LAST-CHAR last relevant character before point (non-white non-comment,
  5796. not part of current identifier or leading slash).
  5797. In the lists, we have these meanings:
  5798. PRO: Procedure name
  5799. FUNC: Function name
  5800. POINT: Where is this
  5801. CLASS: What class has the routine (nil=no, t=is method, but class unknown)
  5802. ARROW: Location of the arrow"
  5803. (idlwave-routines)
  5804. (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
  5805. (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
  5806. (func-entry (idlwave-what-function bos))
  5807. (func (car func-entry))
  5808. (func-class (nth 1 func-entry))
  5809. (func-arrow (nth 2 func-entry))
  5810. (func-point (or (nth 3 func-entry) 0))
  5811. (func-level (or (nth 4 func-entry) 0))
  5812. (pro-entry (idlwave-what-procedure bos))
  5813. (pro (car pro-entry))
  5814. (pro-class (nth 1 pro-entry))
  5815. (pro-arrow (nth 2 pro-entry))
  5816. (pro-point (or (nth 3 pro-entry) 0))
  5817. (last-char (idlwave-last-valid-char))
  5818. (case-fold-search t)
  5819. (match-string (buffer-substring bos (point)))
  5820. cw cw-mod cw-arrow cw-class cw-point)
  5821. (if (< func-point pro-point) (setq func nil))
  5822. (cond
  5823. ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
  5824. match-string)
  5825. (setq cw 'class))
  5826. ((string-match
  5827. "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
  5828. (if (> pro-point 0)
  5829. (buffer-substring pro-point (point))
  5830. match-string))
  5831. (setq cw 'procedure cw-class pro-class cw-point pro-point
  5832. cw-arrow pro-arrow))
  5833. ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
  5834. match-string)
  5835. nil)
  5836. ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
  5837. match-string)
  5838. (setq cw 'class))
  5839. ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
  5840. match-string)
  5841. (setq cw 'class))
  5842. ((and func
  5843. (> func-point pro-point)
  5844. (= func-level 1)
  5845. (memq last-char '(?\( ?,)))
  5846. (setq cw 'function-keyword cw-mod func cw-point func-point
  5847. cw-class func-class cw-arrow func-arrow))
  5848. ((and pro (eq last-char ?,))
  5849. (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
  5850. cw-class pro-class cw-arrow pro-arrow))
  5851. ; ((member last-char '(?\' ?\) ?\] ?!))
  5852. ; ;; after these chars, a function makes no sense
  5853. ; ;; FIXME: I am sure there can be more in this list
  5854. ; ;; FIXME: Do we want to do this at all?
  5855. ; nil)
  5856. ;; Everywhere else we try a function.
  5857. (t
  5858. (setq cw 'function)
  5859. (save-excursion
  5860. (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
  5861. (setq cw-arrow (copy-marker (match-beginning 0))
  5862. cw-class (if (match-end 4)
  5863. (idlwave-sintern-class (match-string 4))
  5864. t))))))
  5865. (list (list pro pro-point pro-class pro-arrow)
  5866. (list func func-point func-class func-arrow)
  5867. cw
  5868. (list cw-mod cw-point cw-class cw-arrow)
  5869. last-char)))
  5870. (defun idlwave-this-word (&optional class)
  5871. ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
  5872. (setq class (or class "a-zA-Z0-9$_."))
  5873. (save-excursion
  5874. (buffer-substring
  5875. (progn (skip-chars-backward class) (point))
  5876. (progn (skip-chars-forward class) (point)))))
  5877. (defun idlwave-what-function (&optional bound)
  5878. ;; Find out if point is within the argument list of a function.
  5879. ;; The return value is ("function-name" class arrow-start (point) level).
  5880. ;; Level is 1 on the top level parentheses, higher further down.
  5881. ;; If the optional BOUND is an integer, bound backwards directed
  5882. ;; searches to this point.
  5883. (catch 'exit
  5884. (let (pos
  5885. func-point
  5886. (cnt 0)
  5887. func arrow-start class)
  5888. (idlwave-with-special-syntax
  5889. (save-restriction
  5890. (save-excursion
  5891. (narrow-to-region (max 1 (or bound 0)) (point-max))
  5892. ;; move back out of the current parenthesis
  5893. (while (condition-case nil
  5894. (progn (up-list -1) t)
  5895. (error nil))
  5896. (setq pos (point))
  5897. (incf cnt)
  5898. (when (and (= (following-char) ?\()
  5899. (re-search-backward
  5900. "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
  5901. bound t))
  5902. (setq func (match-string 2)
  5903. func-point (goto-char (match-beginning 2))
  5904. pos func-point)
  5905. (if (re-search-backward
  5906. "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
  5907. (setq arrow-start (copy-marker (match-beginning 0))
  5908. class (or (match-string 2) t)))
  5909. (throw
  5910. 'exit
  5911. (list
  5912. (idlwave-sintern-routine-or-method func class)
  5913. (idlwave-sintern-class class)
  5914. arrow-start func-point cnt)))
  5915. (goto-char pos))
  5916. (throw 'exit nil)))))))
  5917. (defun idlwave-what-procedure (&optional bound)
  5918. ;; Find out if point is within the argument list of a procedure.
  5919. ;; The return value is ("procedure-name" class arrow-pos (point)).
  5920. ;; If the optional BOUND is an integer, bound backwards directed
  5921. ;; searches to this point.
  5922. (let ((pos (point)) pro-point
  5923. pro class arrow-start string)
  5924. (save-excursion
  5925. ;;(idlwave-beginning-of-statement)
  5926. (idlwave-start-of-substatement 'pre)
  5927. (setq string (buffer-substring (point) pos))
  5928. (if (string-match
  5929. "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
  5930. (setq pro (match-string 1 string)
  5931. pro-point (+ (point) (match-beginning 1)))
  5932. (if (and (idlwave-skip-object)
  5933. (setq string (buffer-substring (point) pos))
  5934. (string-match
  5935. "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
  5936. string))
  5937. (setq pro (if (match-beginning 4)
  5938. (match-string 4 string))
  5939. pro-point (if (match-beginning 4)
  5940. (+ (point) (match-beginning 4))
  5941. pos)
  5942. arrow-start (copy-marker (+ (point) (match-beginning 1)))
  5943. class (or (match-string 3 string) t)))))
  5944. (list (idlwave-sintern-routine-or-method pro class)
  5945. (idlwave-sintern-class class)
  5946. arrow-start
  5947. pro-point)))
  5948. (defun idlwave-skip-object ()
  5949. ;; If there is an object at point, move over it and return t.
  5950. (let ((pos (point)))
  5951. (if (catch 'exit
  5952. (save-excursion
  5953. (skip-chars-forward " ") ; white space
  5954. (skip-chars-forward "*") ; de-reference
  5955. (cond
  5956. ((looking-at idlwave-identifier)
  5957. (goto-char (match-end 0)))
  5958. ((eq (following-char) ?\()
  5959. nil)
  5960. (t (throw 'exit nil)))
  5961. (catch 'endwhile
  5962. (while t
  5963. (cond ((eq (following-char) ?.)
  5964. (forward-char 1)
  5965. (if (not (looking-at idlwave-identifier))
  5966. (throw 'exit nil))
  5967. (goto-char (match-end 0)))
  5968. ((memq (following-char) '(?\( ?\[))
  5969. (condition-case nil
  5970. (forward-list 1)
  5971. (error (throw 'exit nil))))
  5972. (t (throw 'endwhile t)))))
  5973. (if (looking-at "[ \t]*->")
  5974. (throw 'exit (setq pos (match-beginning 0)))
  5975. (throw 'exit nil))))
  5976. (goto-char pos)
  5977. nil)))
  5978. (defun idlwave-last-valid-char ()
  5979. "Return the last character before point which is not white or a comment
  5980. and also not part of the current identifier. Since we do this in
  5981. order to identify places where keywords are, we consider the initial
  5982. `/' of a keyword as part of the identifier.
  5983. This function is not general, can only be used for completion stuff."
  5984. (catch 'exit
  5985. (save-excursion
  5986. ;; skip the current identifier
  5987. (skip-chars-backward "a-zA-Z0-9_$")
  5988. ;; also skip a leading slash which might be belong to the keyword
  5989. (if (eq (preceding-char) ?/)
  5990. (backward-char 1))
  5991. ;; FIXME: does not check if this is a valid identifier
  5992. (while t
  5993. (skip-chars-backward " \t")
  5994. (cond
  5995. ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
  5996. ((eq (preceding-char) ?\n)
  5997. (beginning-of-line 0)
  5998. (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
  5999. ;; continuation line
  6000. (goto-char (match-end 1))
  6001. (throw 'exit nil)))
  6002. (t (throw 'exit (preceding-char))))))))
  6003. (defvar idlwave-complete-after-success-form nil
  6004. "A form to evaluate after successful completion.")
  6005. (defvar idlwave-complete-after-success-form-force nil
  6006. "A form to evaluate after completion selection in *Completions* buffer.")
  6007. (defconst idlwave-completion-mark (make-marker)
  6008. "A mark pointing to the beginning of the completion string.")
  6009. (defvar completion-highlight-first-word-only) ;XEmacs.
  6010. (defun idlwave-complete-in-buffer (type stype list selector prompt isa
  6011. &optional prepare-display-function
  6012. special-selector)
  6013. "Perform TYPE completion of word before point against LIST.
  6014. SELECTOR is the PREDICATE argument for the completion function. Show
  6015. PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
  6016. 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
  6017. used only once, for `all-completions', and can be used to, e.g.,
  6018. accumulate information on matching completions."
  6019. (let* ((completion-ignore-case t)
  6020. beg (end (point)) slash part spart completion all-completions
  6021. dpart dcompletion)
  6022. (unless list
  6023. (error (concat prompt ": No completions available")))
  6024. ;; What is already in the buffer?
  6025. (save-excursion
  6026. (skip-chars-backward "a-zA-Z0-9_$")
  6027. (setq slash (eq (preceding-char) ?/)
  6028. beg (point)
  6029. idlwave-complete-after-success-form
  6030. (list 'idlwave-after-successful-completion
  6031. (list 'quote type) slash beg)
  6032. idlwave-complete-after-success-form-force
  6033. (list 'idlwave-after-successful-completion
  6034. (list 'quote type) slash (list 'quote 'force))))
  6035. ;; Try a completion
  6036. (setq part (buffer-substring beg end)
  6037. dpart (downcase part)
  6038. spart (idlwave-sintern stype part)
  6039. completion (try-completion part list selector)
  6040. dcompletion (if (stringp completion) (downcase completion))
  6041. idlwave-completion-help-links nil)
  6042. (cond
  6043. ((null completion)
  6044. ;; nothing available.
  6045. (error (concat prompt ": no completion for \"%s\"") part))
  6046. ((and (not (equal dpart dcompletion))
  6047. (not (eq t completion)))
  6048. ;; We can add something
  6049. (delete-region beg end)
  6050. (insert (if (and (string= part dpart)
  6051. (or (not (string= part ""))
  6052. idlwave-complete-empty-string-as-lower-case)
  6053. (not idlwave-completion-force-default-case))
  6054. dcompletion
  6055. completion))
  6056. (if (eq t (try-completion completion list selector))
  6057. ;; Now this is a unique match
  6058. (idlwave-after-successful-completion type slash beg))
  6059. t)
  6060. ((or (eq completion t)
  6061. (and (= 1 (length (setq all-completions
  6062. (idlwave-uniquify
  6063. (all-completions part list
  6064. (or special-selector
  6065. selector))))))
  6066. (equal dpart dcompletion)))
  6067. ;; This is already complete
  6068. (idlwave-after-successful-completion type slash beg)
  6069. (message "%s is already the complete %s" part isa)
  6070. nil)
  6071. (t
  6072. ;; We cannot add something - offer a list.
  6073. (message "Making completion list...")
  6074. (unless idlwave-completion-help-links ; already set somewhere?
  6075. (mapc (lambda (x) ; Pass link prop through to highlight-linked
  6076. (let ((link (get-text-property 0 'link (car x))))
  6077. (if link
  6078. (push (cons (car x) link)
  6079. idlwave-completion-help-links))))
  6080. list))
  6081. (let* ((list all-completions)
  6082. ;; "complete" means, this is already a valid completion
  6083. (complete (memq spart all-completions))
  6084. (completion-highlight-first-word-only t)) ; XEmacs
  6085. ;; (completion-fixup-function ; Emacs
  6086. ;; (lambda () (and (eq (preceding-char) ?>)
  6087. ;; (re-search-backward " <" beg t)))))
  6088. (setq list (sort list (lambda (a b)
  6089. (string< (downcase a) (downcase b)))))
  6090. (if prepare-display-function
  6091. (setq list (funcall prepare-display-function list)))
  6092. (if (and (string= part dpart)
  6093. (or (not (string= part ""))
  6094. idlwave-complete-empty-string-as-lower-case)
  6095. (not idlwave-completion-force-default-case))
  6096. (setq list (mapcar (lambda (x)
  6097. (if (listp x)
  6098. (setcar x (downcase (car x)))
  6099. (setq x (downcase x)))
  6100. x)
  6101. list)))
  6102. (idlwave-display-completion-list list prompt beg complete))
  6103. t))))
  6104. (defun idlwave-complete-class ()
  6105. "Complete a class at point."
  6106. (interactive)
  6107. ;; Call `idlwave-routines' to make sure the class list will be available
  6108. (idlwave-routines)
  6109. ;; Check for the special case of completing empty string after pro/function
  6110. (if (let ((case-fold-search t))
  6111. (save-excursion
  6112. (and
  6113. (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
  6114. (- (point) 15) t)
  6115. (goto-char (point-min))
  6116. (re-search-forward
  6117. "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
  6118. ;; Yank the full class specification
  6119. (insert (match-string 2))
  6120. ;; Do the completion, using list gathered from `idlwave-routines'
  6121. (idlwave-complete-in-buffer
  6122. 'class 'class (idlwave-class-alist) nil
  6123. "Select a class" "class"
  6124. (lambda (list) ;; Push it to help-links if system help available
  6125. (mapcar (lambda (x)
  6126. (let* ((entry (idlwave-class-info x))
  6127. (link (nth 1 (assq 'link entry))))
  6128. (if link (push (cons x link)
  6129. idlwave-completion-help-links))
  6130. x))
  6131. list)))))
  6132. (defun idlwave-attach-classes (list type show-classes)
  6133. ;; Attach the proper class list to a LIST of completion items.
  6134. ;; TYPE, when 'kwd, shows classes for method keywords, when
  6135. ;; 'class-tag, for class tags, and otherwise for methods.
  6136. ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
  6137. (if (or (null show-classes) ; don't want to see classes
  6138. (null class-selector) ; not a method call
  6139. (and
  6140. (stringp class-selector) ; the class is already known
  6141. (not super-classes))) ; no possibilities for inheritance
  6142. ;; In these cases, we do not have to do anything
  6143. list
  6144. (let* ((do-prop (and (>= show-classes 0)
  6145. (>= emacs-major-version 21)))
  6146. (do-buf (not (= show-classes 0)))
  6147. ;; (do-dots (featurep 'xemacs))
  6148. (do-dots t)
  6149. (inherit (if (and (not (eq type 'class-tag)) super-classes)
  6150. (cons class-selector super-classes)))
  6151. (max (abs show-classes))
  6152. (lmax (if do-dots (apply 'max (mapcar 'length list))))
  6153. classes nclasses class-info space)
  6154. (mapcar
  6155. (lambda (x)
  6156. ;; get the classes
  6157. (if (eq type 'class-tag)
  6158. ;; Just one class for tags
  6159. (setq classes
  6160. (list
  6161. (idlwave-class-or-superclass-with-tag class-selector x)))
  6162. ;; Multiple classes for method or method-keyword
  6163. (setq classes
  6164. (if (eq type 'kwd)
  6165. (idlwave-all-method-keyword-classes
  6166. method-selector x type-selector)
  6167. (idlwave-all-method-classes x type-selector)))
  6168. (if inherit
  6169. (setq classes
  6170. (delq nil
  6171. (mapcar (lambda (x) (if (memq x inherit) x nil))
  6172. classes)))))
  6173. (setq nclasses (length classes))
  6174. ;; Make the separator between item and class-info
  6175. (if do-dots
  6176. (setq space (concat " " (make-string (- lmax (length x)) ?.)))
  6177. (setq space " "))
  6178. (if do-buf
  6179. ;; We do want info in the buffer
  6180. (if (<= nclasses max)
  6181. (setq class-info (concat
  6182. space
  6183. "<" (mapconcat 'identity classes ",") ">"))
  6184. (setq class-info (format "%s<%d classes>" space nclasses)))
  6185. (setq class-info nil))
  6186. (when do-prop
  6187. ;; We do want properties
  6188. (setq x (copy-sequence x))
  6189. (put-text-property 0 (length x)
  6190. 'help-echo (mapconcat 'identity classes " ")
  6191. x))
  6192. (if class-info
  6193. (list x class-info)
  6194. x))
  6195. list))))
  6196. (defun idlwave-attach-method-classes (list)
  6197. ;; Call idlwave-attach-classes with method parameters
  6198. (idlwave-attach-classes list 'method idlwave-completion-show-classes))
  6199. (defun idlwave-attach-keyword-classes (list)
  6200. ;; Call idlwave-attach-classes with keyword parameters
  6201. (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
  6202. (defun idlwave-attach-class-tag-classes (list)
  6203. ;; Call idlwave-attach-classes with class structure tags
  6204. (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
  6205. ;;----------------------------------------------------------------------
  6206. ;;----------------------------------------------------------------------
  6207. ;;----------------------------------------------------------------------
  6208. ;;----------------------------------------------------------------------
  6209. ;;----------------------------------------------------------------------
  6210. (when (featurep 'xemacs)
  6211. (defvar rtn)
  6212. (defun idlwave-pset (item)
  6213. (set 'rtn item)))
  6214. (defun idlwave-popup-select (ev list title &optional sort)
  6215. "Select an item in LIST with a popup menu.
  6216. TITLE is the title to put atop the popup. If SORT is non-nil,
  6217. sort the list before displaying."
  6218. (let ((maxpopup idlwave-max-popup-menu-items)
  6219. rtn menu)
  6220. (cond ((null list))
  6221. ((= 1 (length list))
  6222. (setq rtn (car list)))
  6223. ((featurep 'xemacs)
  6224. (if sort (setq list (sort list (lambda (a b)
  6225. (string< (upcase a) (upcase b))))))
  6226. (setq menu
  6227. (append (list title)
  6228. (mapcar (lambda (x) (vector x (list 'idlwave-pset
  6229. x)))
  6230. list)))
  6231. (setq menu (idlwave-split-menu-xemacs menu maxpopup))
  6232. (let ((resp (get-popup-menu-response menu)))
  6233. (funcall (event-function resp) (event-object resp))))
  6234. (t
  6235. (if sort (setq list (sort list (lambda (a b)
  6236. (string< (upcase a) (upcase b))))))
  6237. (setq menu (cons title
  6238. (list
  6239. (append (list "")
  6240. (mapcar (lambda(x) (cons x x)) list)))))
  6241. (setq menu (idlwave-split-menu-emacs menu maxpopup))
  6242. (setq rtn (x-popup-menu ev menu))))
  6243. rtn))
  6244. (defun idlwave-split-menu-xemacs (menu N)
  6245. "Split the MENU into submenus of maximum length N."
  6246. (if (<= (length menu) (1+ N))
  6247. ;; No splitting needed
  6248. menu
  6249. (let* ((title (car menu))
  6250. (entries (cdr menu))
  6251. (menu (list title))
  6252. (cnt 0)
  6253. (nextmenu nil))
  6254. (while entries
  6255. (while (and entries (< cnt N))
  6256. (setq cnt (1+ cnt)
  6257. nextmenu (cons (car entries) nextmenu)
  6258. entries (cdr entries)))
  6259. (setq nextmenu (nreverse nextmenu))
  6260. (setq nextmenu (cons (format "%s...%s"
  6261. (aref (car nextmenu) 0)
  6262. (aref (nth (1- cnt) nextmenu) 0))
  6263. nextmenu))
  6264. (setq menu (cons nextmenu menu)
  6265. nextmenu nil
  6266. cnt 0))
  6267. (nreverse menu))))
  6268. (defun idlwave-split-menu-emacs (menu N)
  6269. "Split the MENU into submenus of maximum length N."
  6270. (if (<= (length (nth 1 menu)) (1+ N))
  6271. ;; No splitting needed
  6272. menu
  6273. (let* ((title (car menu))
  6274. (entries (cdr (nth 1 menu)))
  6275. (menu nil)
  6276. (cnt 0)
  6277. (nextmenu nil))
  6278. (while entries
  6279. (while (and entries (< cnt N))
  6280. (setq cnt (1+ cnt)
  6281. nextmenu (cons (car entries) nextmenu)
  6282. entries (cdr entries)))
  6283. (setq nextmenu (nreverse nextmenu))
  6284. (prin1 nextmenu)
  6285. (setq nextmenu (cons (format "%s...%s"
  6286. (car (car nextmenu))
  6287. (car (nth (1- cnt) nextmenu)))
  6288. nextmenu))
  6289. (setq menu (cons nextmenu menu)
  6290. nextmenu nil
  6291. cnt 0))
  6292. (setq menu (nreverse menu))
  6293. (setq menu (cons title menu))
  6294. menu)))
  6295. (defvar idlwave-completion-setup-hook nil)
  6296. (defun idlwave-scroll-completions (&optional message)
  6297. "Scroll the completion window on this frame."
  6298. (let ((cwin (get-buffer-window "*Completions*" 'visible))
  6299. (win (selected-window)))
  6300. (unwind-protect
  6301. (progn
  6302. (select-window cwin)
  6303. (condition-case nil
  6304. (scroll-up)
  6305. (error (if (and (listp last-command)
  6306. (nth 2 last-command))
  6307. (progn
  6308. (select-window win)
  6309. (eval idlwave-complete-after-success-form))
  6310. (set-window-start cwin (point-min)))))
  6311. (and message (message "%s" message)))
  6312. (select-window win))))
  6313. (defun idlwave-display-completion-list (list &optional message beg complete)
  6314. "Display the completions in LIST in the completions buffer and echo MESSAGE."
  6315. (unless (and (get-buffer-window "*Completions*")
  6316. (idlwave-local-value 'idlwave-completion-p "*Completions*"))
  6317. (move-marker idlwave-completion-mark beg)
  6318. (setq idlwave-before-completion-wconf (current-window-configuration)))
  6319. (if (featurep 'xemacs)
  6320. (idlwave-display-completion-list-xemacs
  6321. list)
  6322. (idlwave-display-completion-list-emacs list))
  6323. ;; Store a special value in `this-command'. When `idlwave-complete'
  6324. ;; finds this in `last-command', it will scroll the *Completions* buffer.
  6325. (setq this-command (list 'idlwave-display-completion-list message complete))
  6326. ;; Mark the completions buffer as created by cib
  6327. (idlwave-set-local 'idlwave-completion-p t "*Completions*")
  6328. ;; Fontify the classes
  6329. (if (and idlwave-completion-fontify-classes
  6330. (consp (car list)))
  6331. (idlwave-completion-fontify-classes))
  6332. ;; Run the hook
  6333. (run-hooks 'idlwave-completion-setup-hook)
  6334. ;; Display the message
  6335. (message "%s" (or message "Making completion list...done")))
  6336. (defun idlwave-choose (function &rest args)
  6337. "Call FUNCTION as a completion chooser and pass ARGS to it."
  6338. (let ((completion-ignore-case t)) ; install correct value
  6339. (apply function args))
  6340. (if (and (derived-mode-p 'idlwave-shell-mode)
  6341. (boundp 'font-lock-mode)
  6342. (not font-lock-mode))
  6343. ;; For the shell, remove the fontification of the word before point
  6344. (let ((beg (save-excursion
  6345. (skip-chars-backward "a-zA-Z0-9_")
  6346. (point))))
  6347. (remove-text-properties beg (point) '(face nil))))
  6348. (eval idlwave-complete-after-success-form-force))
  6349. (defun idlwave-keyboard-quit ()
  6350. (interactive)
  6351. (unwind-protect
  6352. (if (eq (car-safe last-command) 'idlwave-display-completion-list)
  6353. (idlwave-restore-wconf-after-completion))
  6354. (keyboard-quit)))
  6355. (defun idlwave-restore-wconf-after-completion ()
  6356. "Restore the old (before completion) window configuration."
  6357. (and idlwave-completion-restore-window-configuration
  6358. idlwave-before-completion-wconf
  6359. (set-window-configuration idlwave-before-completion-wconf)))
  6360. (defun idlwave-one-key-select (sym prompt delay)
  6361. "Make the user select an element from the alist in the variable SYM.
  6362. The keys of the alist are expected to be strings. The function returns the
  6363. car of the selected association.
  6364. To do this, PROMPT is displayed and the user must hit a letter key to
  6365. select an entry. If the user does not reply within DELAY seconds, a help
  6366. window with the options is displayed automatically.
  6367. The key which is associated with each option is generated automatically.
  6368. First, the strings are checked for preselected keys, like in \"[P]rint\".
  6369. If these don't exist, a letter in the string is automatically selected."
  6370. (let* ((alist (symbol-value sym))
  6371. (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
  6372. '(fit-window-to-buffer)))
  6373. keys-alist char)
  6374. ;; First check the cache
  6375. (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
  6376. (setq keys-alist (get sym :one-key-alist-cache))
  6377. ;; Need to make new list
  6378. (setq keys-alist (idlwave-make-one-key-alist alist))
  6379. (put sym :one-key-alist-cache keys-alist)
  6380. (put sym :one-key-alist-last alist))
  6381. ;; Display prompt and wait for quick reply
  6382. (message "%s[%s]" prompt
  6383. (mapconcat (lambda(x) (char-to-string (car x)))
  6384. keys-alist ""))
  6385. (if (sit-for delay)
  6386. ;; No quick reply: Show help
  6387. (save-window-excursion
  6388. (with-output-to-temp-buffer "*Completions*"
  6389. (dolist (x keys-alist)
  6390. (princ (nth 1 x))
  6391. (princ "\n")))
  6392. (setq char (read-char)))
  6393. (setq char (read-char)))
  6394. (message nil)
  6395. ;; Return the selected result
  6396. (nth 2 (assoc char keys-alist))))
  6397. ;; Used for, e.g., electric debug super-examine.
  6398. (defun idlwave-make-one-key-alist (alist)
  6399. "Make an alist for single key selection."
  6400. (let ((l alist) keys-alist name start char help
  6401. (cnt 0)
  6402. (case-fold-search nil))
  6403. (while l
  6404. (setq name (car (car l))
  6405. l (cdr l))
  6406. (catch 'exit
  6407. ;; First check if the configuration predetermined a key
  6408. (if (string-match "\\[\\(.\\)\\]" name)
  6409. (progn
  6410. (setq char (string-to-char (downcase (match-string 1 name)))
  6411. help (format "%c: %s" char name)
  6412. keys-alist (cons (list char help name) keys-alist))
  6413. (throw 'exit t)))
  6414. ;; Then check for capital letters
  6415. (setq start 0)
  6416. (while (string-match "[A-Z]" name start)
  6417. (setq start (match-end 0)
  6418. char (string-to-char (downcase (match-string 0 name))))
  6419. (if (not (assoc char keys-alist))
  6420. (progn
  6421. (setq help (format "%c: %s" char
  6422. (replace-match
  6423. (concat "[" (match-string 0 name) "]")
  6424. t t name))
  6425. keys-alist (cons (list char help name) keys-alist))
  6426. (throw 'exit t))))
  6427. ;; Now check for lowercase letters
  6428. (setq start 0)
  6429. (while (string-match "[a-z]" name start)
  6430. (setq start (match-end 0)
  6431. char (string-to-char (match-string 0 name)))
  6432. (if (not (assoc char keys-alist))
  6433. (progn
  6434. (setq help (format "%c: %s" char
  6435. (replace-match
  6436. (concat "[" (match-string 0 name) "]")
  6437. t t name))
  6438. keys-alist (cons (list char help name) keys-alist))
  6439. (throw 'exit t))))
  6440. ;; Bummer, nothing found! Use a stupid number
  6441. (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
  6442. help (format "%c: %s" char name)
  6443. keys-alist (cons (list char help name) keys-alist))))
  6444. (nreverse keys-alist)))
  6445. (defun idlwave-set-local (var value &optional buffer)
  6446. "Set the buffer-local value of VAR in BUFFER to VALUE."
  6447. (with-current-buffer (or buffer (current-buffer))
  6448. (set (make-local-variable var) value)))
  6449. (defun idlwave-local-value (var &optional buffer)
  6450. "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
  6451. (with-current-buffer (or buffer (current-buffer))
  6452. (and (local-variable-p var (current-buffer))
  6453. (symbol-value var))))
  6454. ;; In XEmacs, we can use :activate-callback directly to advice the
  6455. ;; choose functions. We use the private keymap only for the online
  6456. ;; help feature.
  6457. (defvar idlwave-completion-map nil
  6458. "Keymap for `completion-list-mode' with `idlwave-complete'.")
  6459. (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
  6460. (with-output-to-temp-buffer "*Completions*"
  6461. (apply 'display-completion-list list
  6462. ':activate-callback 'idlwave-default-choose-completion
  6463. cl-args))
  6464. (with-current-buffer "*Completions*"
  6465. (use-local-map
  6466. (or idlwave-completion-map
  6467. (setq idlwave-completion-map
  6468. (idlwave-make-modified-completion-map-xemacs
  6469. (current-local-map)))))))
  6470. (defun idlwave-default-choose-completion (&rest args)
  6471. "Execute `default-choose-completion' and then restore the win-conf."
  6472. (apply 'idlwave-choose 'default-choose-completion args))
  6473. (defun idlwave-make-modified-completion-map-xemacs (old-map)
  6474. "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
  6475. (let ((new-map (copy-keymap old-map)))
  6476. (define-key new-map [button3up] 'idlwave-mouse-completion-help)
  6477. (define-key new-map [button3] (lambda ()
  6478. (interactive)
  6479. (setq this-command last-command)))
  6480. new-map))
  6481. ;; In Emacs we also replace keybindings in the completion
  6482. ;; map in order to install our wrappers.
  6483. (defun idlwave-display-completion-list-emacs (list)
  6484. "Display completion list and install the choose wrappers."
  6485. (with-output-to-temp-buffer "*Completions*"
  6486. (display-completion-list list))
  6487. (with-current-buffer "*Completions*"
  6488. (use-local-map
  6489. (or idlwave-completion-map
  6490. (setq idlwave-completion-map
  6491. (idlwave-make-modified-completion-map-emacs
  6492. (current-local-map)))))))
  6493. (defun idlwave-make-modified-completion-map-emacs (old-map)
  6494. "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
  6495. (let ((new-map (copy-keymap old-map)))
  6496. (substitute-key-definition
  6497. 'choose-completion 'idlwave-choose-completion new-map)
  6498. (substitute-key-definition
  6499. 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
  6500. (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
  6501. new-map))
  6502. (defun idlwave-choose-completion (&rest args)
  6503. "Choose the completion that point is in or next to."
  6504. (interactive (list last-nonmenu-event))
  6505. (apply 'idlwave-choose 'choose-completion args))
  6506. (defun idlwave-mouse-choose-completion (&rest args)
  6507. "Click on an alternative in the `*Completions*' buffer to choose it."
  6508. (interactive "e")
  6509. (apply 'idlwave-choose 'mouse-choose-completion args))
  6510. ;;----------------------------------------------------------------------
  6511. ;;----------------------------------------------------------------------
  6512. ;;; ------------------------------------------------------------------------
  6513. ;;; Structure parsing code, and code to manage class info
  6514. ;;
  6515. ;; - Go again over the documentation how to write a completion
  6516. ;; plugin. It is in self.el, but currently still very bad.
  6517. ;; This could be in a separate file in the distribution, or
  6518. ;; in an appendix for the manual.
  6519. (defvar idlwave-struct-skip
  6520. "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
  6521. "Regexp for skipping continued blank or comment-only lines in structures.")
  6522. (defvar idlwave-struct-tag-regexp
  6523. (concat "[{,]" ;leading comma/brace
  6524. idlwave-struct-skip ; 4 groups
  6525. "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
  6526. "[ \t]*:") ; the final colon
  6527. "Regexp for structure tags.")
  6528. (defun idlwave-struct-tags ()
  6529. "Return a list of all tags in the structure defined at point.
  6530. Point is expected just before the opening `{' of the struct definition."
  6531. (save-excursion
  6532. (let* ((borders (idlwave-struct-borders))
  6533. (beg (car borders))
  6534. (end (cdr borders))
  6535. tags)
  6536. (goto-char beg)
  6537. (save-restriction
  6538. (narrow-to-region beg end)
  6539. (while (re-search-forward idlwave-struct-tag-regexp end t)
  6540. ;; Check if we are still on the top level of the structure.
  6541. (if (and (condition-case nil (progn (up-list -1) t) (error nil))
  6542. (= (point) beg))
  6543. (push (match-string-no-properties 5) tags))
  6544. (goto-char (match-end 0))))
  6545. (nreverse tags))))
  6546. (defun idlwave-find-struct-tag (tag)
  6547. "Find a given TAG in the structure defined at point."
  6548. (let* ((borders (idlwave-struct-borders))
  6549. (end (cdr borders))
  6550. (case-fold-search t))
  6551. (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
  6552. end t)))
  6553. (defun idlwave-struct-inherits ()
  6554. "Return a list of all `inherits' names in the struct at point.
  6555. Point is expected just before the opening `{' of the struct definition."
  6556. (save-excursion
  6557. (let* ((borders (idlwave-struct-borders))
  6558. (beg (car borders))
  6559. (end (cdr borders))
  6560. (case-fold-search t)
  6561. names)
  6562. (goto-char beg)
  6563. (save-restriction
  6564. (narrow-to-region beg end)
  6565. (while (re-search-forward
  6566. (concat "[{,]" ;leading comma/brace
  6567. idlwave-struct-skip ; 4 groups
  6568. "inherits" ; The INHERITS tag
  6569. idlwave-struct-skip ; 4 more
  6570. "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
  6571. end t)
  6572. ;; Check if we are still on the top level of the structure.
  6573. (if (and (condition-case nil (progn (up-list -1) t) (error nil))
  6574. (= (point) beg))
  6575. (push (match-string-no-properties 9) names))
  6576. (goto-char (match-end 0))))
  6577. (nreverse names))))
  6578. (defun idlwave-in-structure ()
  6579. "Return t if point is inside an IDL structure definition."
  6580. (let ((beg (point)))
  6581. (save-excursion
  6582. (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
  6583. (if (idlwave-find-structure-definition nil nil 'back)
  6584. (let ((borders (idlwave-struct-borders)))
  6585. (or (= (car borders) (cdr borders)) ;; struct not yet closed...
  6586. (and (> beg (car borders)) (< beg (cdr borders))))))))))
  6587. (defun idlwave-struct-borders ()
  6588. "Return the borders of the {...} after point as a cons cell."
  6589. (let (beg)
  6590. (save-excursion
  6591. (skip-chars-forward "^{")
  6592. (setq beg (point))
  6593. (condition-case nil (forward-list 1)
  6594. (error (goto-char beg)))
  6595. (cons beg (point)))))
  6596. (defun idlwave-find-structure-definition (&optional var name bound)
  6597. "Search forward for a structure definition.
  6598. If VAR is non-nil, search for a structure assigned to variable VAR.
  6599. If NAME is non-nil, search for a named structure NAME, if a string,
  6600. or a generic named structure otherwise. If BOUND is an integer, limit
  6601. the search. If BOUND is the symbol `all', we search first back and
  6602. then forward through the entire file. If BOUND is the symbol `back'
  6603. we search only backward."
  6604. (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
  6605. (case-fold-search t)
  6606. (lim (if (integerp bound) bound nil))
  6607. (re (concat
  6608. (if var
  6609. (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
  6610. "\\(\\)")
  6611. "=" ws "\\({\\)"
  6612. (if name
  6613. (if (stringp name)
  6614. (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
  6615. ;; Just a generic name
  6616. (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
  6617. ""))))
  6618. (if (or (and (or (eq bound 'all) (eq bound 'back))
  6619. (re-search-backward re nil t))
  6620. (and (not (eq bound 'back)) (re-search-forward re lim t)))
  6621. (progn
  6622. (goto-char (match-beginning 3))
  6623. (match-string-no-properties 5)))))
  6624. (defvar idlwave-class-info nil)
  6625. (defvar idlwave-class-reset nil) ; to reset buffer-local classes
  6626. (add-hook 'idlwave-update-rinfo-hook
  6627. (lambda () (setq idlwave-class-reset t)))
  6628. (add-hook 'idlwave-after-load-rinfo-hook
  6629. (lambda () (setq idlwave-class-info nil)))
  6630. (defun idlwave-class-info (class)
  6631. (let (list entry)
  6632. (if idlwave-class-info
  6633. (if idlwave-class-reset
  6634. (setq
  6635. idlwave-class-reset nil
  6636. idlwave-class-info ; Remove any visited in a buffer
  6637. (delq nil (mapcar
  6638. (lambda (x)
  6639. (let ((filebuf
  6640. (idlwave-class-file-or-buffer
  6641. (or (cdr (assq 'found-in x)) (car x)))))
  6642. (if (cdr filebuf)
  6643. nil
  6644. x)))
  6645. idlwave-class-info))))
  6646. ;; Info is nil, put in the system stuff to start.
  6647. (setq idlwave-class-info idlwave-system-class-info)
  6648. (setq list idlwave-class-info)
  6649. (while (setq entry (pop list))
  6650. (idlwave-sintern-class-info entry)))
  6651. (setq class (idlwave-sintern-class class))
  6652. (or (assq class idlwave-class-info)
  6653. (progn (idlwave-scan-class-info class)
  6654. (assq class idlwave-class-info)))))
  6655. (defun idlwave-sintern-class-info (entry)
  6656. "Sintern the class names in a class-info entry."
  6657. (let ((inherits (assq 'inherits entry)))
  6658. (setcar entry (idlwave-sintern-class (car entry) 'set))
  6659. (if inherits
  6660. (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
  6661. (cdr inherits))))))
  6662. (defun idlwave-find-class-definition (class &optional all-hook alt-class)
  6663. "Find class structure definition(s).
  6664. If ALL-HOOK is set, find all named structure definitions in a given
  6665. class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
  6666. set, look for the name__define pro, and inside of it, for the ALT-CLASS
  6667. class/struct definition."
  6668. (let ((case-fold-search t) end-lim name)
  6669. (when (re-search-forward
  6670. (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
  6671. (if all-hook
  6672. (progn
  6673. ;; For everything there
  6674. (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
  6675. (while (setq name
  6676. (idlwave-find-structure-definition nil t end-lim))
  6677. (funcall all-hook name)))
  6678. (idlwave-find-structure-definition nil (or alt-class class))))))
  6679. (defun idlwave-class-file-or-buffer (class)
  6680. "Find buffer visiting CLASS definition."
  6681. (let* ((pro (concat (downcase class) "__define"))
  6682. (file (idlwave-routine-source-file
  6683. (nth 3 (idlwave-rinfo-assoc pro 'pro nil
  6684. (idlwave-routines))))))
  6685. (cons file (if file (idlwave-get-buffer-visiting file)))))
  6686. (defun idlwave-scan-class-info (class)
  6687. "Scan all class and named structure info in the class__define pro."
  6688. (let* ((idlwave-auto-routine-info-updates nil)
  6689. (filebuf (idlwave-class-file-or-buffer class))
  6690. (file (car filebuf))
  6691. (buf (cdr filebuf))
  6692. (class (idlwave-sintern-class class)))
  6693. (if (or
  6694. (not file)
  6695. (and ;; neither a regular file nor a visited buffer
  6696. (not buf)
  6697. (not (file-regular-p file))))
  6698. nil ; Cannot find the file/buffer to get any info
  6699. (save-excursion
  6700. (if buf (set-buffer buf)
  6701. ;; Read the file in temporarily
  6702. (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
  6703. (erase-buffer)
  6704. (unless (derived-mode-p 'idlwave-mode)
  6705. (idlwave-mode))
  6706. (insert-file-contents file))
  6707. (save-excursion
  6708. (goto-char 1)
  6709. (idlwave-find-class-definition class
  6710. ;; Scan all of the structures found there
  6711. (lambda (name)
  6712. (let* ((this-class (idlwave-sintern-class name))
  6713. (entry
  6714. (list this-class
  6715. (cons 'tags (idlwave-struct-tags))
  6716. (cons 'inherits (idlwave-struct-inherits)))))
  6717. (if (not (eq this-class class))
  6718. (setq entry (nconc entry (list (cons 'found-in class)))))
  6719. (idlwave-sintern-class-info entry)
  6720. (push entry idlwave-class-info)))))))))
  6721. (defun idlwave-class-found-in (class)
  6722. "Return the FOUND-IN property of the CLASS."
  6723. (cdr (assq 'found-in (idlwave-class-info class))))
  6724. (defun idlwave-class-tags (class)
  6725. "Return the native tags in CLASS."
  6726. (cdr (assq 'tags (idlwave-class-info class))))
  6727. (defun idlwave-class-inherits (class)
  6728. "Return the direct superclasses of CLASS."
  6729. (cdr (assq 'inherits (idlwave-class-info class))))
  6730. (defun idlwave-all-class-tags (class)
  6731. "Return a list of native and inherited tags in CLASS."
  6732. (condition-case err
  6733. (apply 'append (mapcar 'idlwave-class-tags
  6734. (cons class (idlwave-all-class-inherits class))))
  6735. (error
  6736. (idlwave-class-tag-reset)
  6737. (error "%s" (error-message-string err)))))
  6738. (defun idlwave-all-class-inherits (class)
  6739. "Return a list of all superclasses of CLASS (recursively expanded).
  6740. The list is cached in `idlwave-class-info' for faster access."
  6741. (cond
  6742. ((not idlwave-support-inheritance) nil)
  6743. ((eq class nil) nil)
  6744. ((eq class t) nil)
  6745. (t
  6746. (let ((info (idlwave-class-info class))
  6747. entry)
  6748. (if (setq entry (assq 'all-inherits info))
  6749. (cdr entry)
  6750. ;; Save the depth of inheritance scan to check for circular references
  6751. (let ((inherits (mapcar (lambda (x) (cons x 0))
  6752. (idlwave-class-inherits class)))
  6753. rtn all-inherits cl)
  6754. (while inherits
  6755. (setq cl (pop inherits)
  6756. rtn (cons (car cl) rtn)
  6757. inherits (append (mapcar (lambda (x)
  6758. (cons x (1+ (cdr cl))))
  6759. (idlwave-class-inherits (car cl)))
  6760. inherits))
  6761. (if (> (cdr cl) 999)
  6762. (error
  6763. "Class scan: inheritance depth exceeded. Circular inheritance?")
  6764. ))
  6765. (setq all-inherits (nreverse rtn))
  6766. (nconc info (list (cons 'all-inherits all-inherits)))
  6767. all-inherits))))))
  6768. (defun idlwave-entry-keywords (entry &optional record-link)
  6769. "Return the flat entry keywords alist from routine-info entry.
  6770. If RECORD-LINK is non-nil, the keyword text is copied and a text
  6771. property indicating the link is added."
  6772. (let (kwds)
  6773. (mapc
  6774. (lambda (key-list)
  6775. (let ((file (car key-list)))
  6776. (mapcar (lambda (key-cons)
  6777. (let ((key (car key-cons))
  6778. (link (cdr key-cons)))
  6779. (when (and record-link file)
  6780. (setq key (copy-sequence key))
  6781. (put-text-property
  6782. 0 (length key)
  6783. 'link
  6784. (concat
  6785. file
  6786. (if link
  6787. (concat idlwave-html-link-sep
  6788. (number-to-string link))))
  6789. key))
  6790. (push (list key) kwds)))
  6791. (cdr key-list))))
  6792. (nthcdr 5 entry))
  6793. (nreverse kwds)))
  6794. (defun idlwave-entry-find-keyword (entry keyword)
  6795. "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
  6796. (catch 'exit
  6797. (mapc
  6798. (lambda (key-list)
  6799. (let ((file (car key-list))
  6800. (kwd (assoc keyword (cdr key-list))))
  6801. (when kwd
  6802. (setq kwd (cons (car kwd)
  6803. (if (and file (cdr kwd))
  6804. (concat file
  6805. idlwave-html-link-sep
  6806. (number-to-string (cdr kwd)))
  6807. (cdr kwd))))
  6808. (throw 'exit kwd))))
  6809. (nthcdr 5 entry))))
  6810. ;;==========================================================================
  6811. ;;
  6812. ;; Completing class structure tags. This is a completion plugin.
  6813. ;; The necessary taglist is constructed dynamically
  6814. (defvar idlwave-current-tags-class nil)
  6815. (defvar idlwave-current-class-tags nil)
  6816. (defvar idlwave-current-native-class-tags nil)
  6817. (defvar idlwave-sint-class-tags nil)
  6818. (declare-function idlwave-sintern-class-tag "idlwave" t t)
  6819. (idlwave-new-sintern-type 'class-tag)
  6820. (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
  6821. (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
  6822. (defun idlwave-complete-class-structure-tag ()
  6823. "Complete a structure tag on a `self' argument in an object method."
  6824. (interactive)
  6825. (let ((pos (point))
  6826. (case-fold-search t))
  6827. (if (save-excursion
  6828. ;; Check if the context is right
  6829. (skip-chars-backward "a-zA-Z0-9._$")
  6830. (and (< (point) (- pos 4))
  6831. (looking-at "self\\.")))
  6832. (let* ((class-selector (nth 2 (idlwave-current-routine)))
  6833. (super-classes (idlwave-all-class-inherits class-selector)))
  6834. ;; Check if we are in a class routine
  6835. (unless class-selector
  6836. (error "Not in a method procedure or function"))
  6837. ;; Check if we need to update the "current" class
  6838. (if (not (equal class-selector idlwave-current-tags-class))
  6839. (idlwave-prepare-class-tag-completion class-selector))
  6840. (setq idlwave-completion-help-info
  6841. (list 'idlwave-complete-class-structure-tag-help
  6842. (idlwave-sintern-routine
  6843. (concat class-selector "__define"))
  6844. nil))
  6845. ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
  6846. (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
  6847. (idlwave-complete-in-buffer
  6848. 'class-tag 'class-tag
  6849. idlwave-current-class-tags nil
  6850. (format "Select a tag of class %s" class-selector)
  6851. "class tag"
  6852. 'idlwave-attach-class-tag-classes))
  6853. t) ; return t to skip other completions
  6854. nil)))
  6855. (defun idlwave-class-tag-reset ()
  6856. (setq idlwave-current-tags-class nil))
  6857. (defun idlwave-prepare-class-tag-completion (class)
  6858. "Find and parse the necessary class definitions for class structure tags."
  6859. (setq idlwave-sint-class-tags nil)
  6860. (setq idlwave-current-tags-class class)
  6861. (setq idlwave-current-class-tags
  6862. (mapcar (lambda (x)
  6863. (list (idlwave-sintern-class-tag x 'set)))
  6864. (idlwave-all-class-tags class)))
  6865. (setq idlwave-current-native-class-tags
  6866. (mapcar 'downcase (idlwave-class-tags class))))
  6867. ;===========================================================================
  6868. ;;
  6869. ;; Completing system variables and their structure fields
  6870. ;; This is also a plugin.
  6871. (defvar idlwave-sint-sysvars nil)
  6872. (defvar idlwave-sint-sysvartags nil)
  6873. (declare-function idlwave-sintern-sysvar "idlwave" t t)
  6874. (declare-function idlwave-sintern-sysvartag "idlwave" t t)
  6875. (idlwave-new-sintern-type 'sysvar)
  6876. (idlwave-new-sintern-type 'sysvartag)
  6877. (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
  6878. (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
  6879. (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
  6880. (defun idlwave-complete-sysvar-or-tag ()
  6881. "Complete a system variable."
  6882. (interactive)
  6883. (let ((pos (point))
  6884. (case-fold-search t))
  6885. (cond ((save-excursion
  6886. ;; Check if the context is right for system variable
  6887. (skip-chars-backward "[a-zA-Z0-9_$]")
  6888. (equal (char-before) ?!))
  6889. (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
  6890. (idlwave-complete-in-buffer 'sysvar 'sysvar
  6891. idlwave-system-variables-alist nil
  6892. "Select a system variable"
  6893. "system variable")
  6894. t) ; return t to skip other completions
  6895. ((save-excursion
  6896. ;; Check if the context is right for sysvar tag
  6897. (skip-chars-backward "a-zA-Z0-9_$.")
  6898. (and (equal (char-before) ?!)
  6899. (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
  6900. (<= (match-end 0) pos)))
  6901. ;; Complete a system variable tag
  6902. (let* ((var (idlwave-sintern-sysvar (match-string 1)))
  6903. (entry (assq var idlwave-system-variables-alist))
  6904. (tags (cdr (assq 'tags entry))))
  6905. (or entry (error "!%s is not a known system variable" var))
  6906. (or tags (error "System variable !%s is not a structure" var))
  6907. (setq idlwave-completion-help-info
  6908. (list 'idlwave-complete-sysvar-tag-help var))
  6909. (idlwave-complete-in-buffer 'sysvartag 'sysvartag
  6910. tags nil
  6911. "Select a system variable tag"
  6912. "system variable tag")
  6913. t)) ; return t to skip other completions
  6914. (t nil))))
  6915. (defvar idlw-help-link) ;dynamic variables set by help callback
  6916. (defun idlwave-complete-sysvar-help (mode word)
  6917. (let ((word (or (nth 1 idlwave-completion-help-info) word))
  6918. (entry (assoc word idlwave-system-variables-alist)))
  6919. (cond
  6920. ((eq mode 'test)
  6921. (and (stringp word) entry (nth 1 (assq 'link entry))))
  6922. ((eq mode 'set)
  6923. ;; Setting dynamic!!!
  6924. (if entry (setq idlw-help-link (nth 1 (assq 'link entry)))))
  6925. (t (error "This should not happen")))))
  6926. (defun idlwave-complete-sysvar-tag-help (mode word)
  6927. (let* ((var (nth 1 idlwave-completion-help-info))
  6928. (entry (assoc var idlwave-system-variables-alist))
  6929. (tags (cdr (assq 'tags entry)))
  6930. (main (nth 1 (assq 'link entry)))
  6931. target)
  6932. (cond
  6933. ((eq mode 'test) ; we can at least link the main
  6934. (and (stringp word) entry main))
  6935. ((eq mode 'set)
  6936. (if entry
  6937. (setq idlw-help-link
  6938. (if (setq target (cdr (assoc-string word tags t)))
  6939. (idlwave-substitute-link-target main target)
  6940. main)))) ;; setting dynamic!!!
  6941. (t (error "This should not happen")))))
  6942. (defun idlwave-split-link-target (link)
  6943. "Split a given LINK into link file and anchor."
  6944. (if (string-match idlwave-html-link-sep link)
  6945. (cons (substring link 0 (match-beginning 0))
  6946. (string-to-number (substring link (match-end 0))))))
  6947. (defun idlwave-substitute-link-target (link target)
  6948. "Substitute the TARGET anchor for the given LINK."
  6949. (let (main-base)
  6950. (setq main-base (if (string-match "#" link)
  6951. (substring link 0 (match-beginning 0))
  6952. link))
  6953. (if target
  6954. (concat main-base idlwave-html-link-sep (number-to-string target))
  6955. link)))
  6956. ;; Fake help in the source buffer for class structure tags.
  6957. ;; IDLW-HELP-LINK AND IDLW-HELP-NAME ARE GLOBAL-VARIABLES HERE.
  6958. ;; (from idlwave-do-mouse-completion-help)
  6959. (defvar idlw-help-name)
  6960. (defvar idlw-help-link)
  6961. (defvar idlwave-help-do-class-struct-tag nil)
  6962. (defun idlwave-complete-class-structure-tag-help (mode word)
  6963. (cond
  6964. ((eq mode 'test) ; nothing gets fontified for class tags
  6965. nil)
  6966. ((eq mode 'set)
  6967. (let (class-with found-in)
  6968. (when (setq class-with
  6969. (idlwave-class-or-superclass-with-tag
  6970. idlwave-current-tags-class
  6971. word))
  6972. (if (assq (idlwave-sintern-class class-with)
  6973. idlwave-system-class-info)
  6974. (error "No help available for system class tags"))
  6975. (if (setq found-in (idlwave-class-found-in class-with))
  6976. (setq idlw-help-name (cons (concat found-in "__define") class-with))
  6977. (setq idlw-help-name (concat class-with "__define")))))
  6978. (setq idlw-help-link word
  6979. idlwave-help-do-class-struct-tag t))
  6980. (t (error "This should not happen"))))
  6981. (defun idlwave-class-or-superclass-with-tag (class tag)
  6982. "Find and return the CLASS or one of its superclass with the
  6983. associated TAG, if any."
  6984. (let ((sclasses (cons class (idlwave-all-class-inherits class)))
  6985. cl)
  6986. (catch 'exit
  6987. (while sclasses
  6988. (setq cl (pop sclasses))
  6989. (let ((tags (idlwave-class-tags cl)))
  6990. (while tags
  6991. (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
  6992. (throw 'exit cl))
  6993. (setq tags (cdr tags))))))))
  6994. (defun idlwave-sysvars-reset ()
  6995. (if (and (fboundp 'idlwave-shell-is-running)
  6996. (idlwave-shell-is-running)
  6997. idlwave-idlwave_routine_info-compiled)
  6998. (idlwave-shell-send-command "idlwave_get_sysvars"
  6999. 'idlwave-process-sysvars 'hide)))
  7000. (defun idlwave-process-sysvars ()
  7001. (idlwave-shell-filter-sysvars)
  7002. (setq idlwave-sint-sysvars nil
  7003. idlwave-sint-sysvartags nil)
  7004. (idlwave-sintern-sysvar-alist))
  7005. (defun idlwave-sintern-sysvar-alist ()
  7006. (let ((list idlwave-system-variables-alist) entry tags)
  7007. (while (setq entry (pop list))
  7008. (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
  7009. (setq tags (assq 'tags entry))
  7010. (if tags
  7011. (setcdr tags
  7012. (mapcar (lambda (x)
  7013. (cons (idlwave-sintern-sysvartag (car x) 'set)
  7014. (cdr x)))
  7015. (cdr tags)))))))
  7016. (defvar idlwave-shell-command-output)
  7017. (defun idlwave-shell-filter-sysvars ()
  7018. "Get any new system variables and tags."
  7019. (let ((text idlwave-shell-command-output)
  7020. (start 0)
  7021. (old idlwave-system-variables-alist)
  7022. var tags type name class link old-entry)
  7023. (setq idlwave-system-variables-alist nil)
  7024. (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
  7025. text start)
  7026. (setq start (match-end 0)
  7027. var (match-string 1 text)
  7028. tags (if (match-end 3)
  7029. (idlwave-split-string (match-string 3 text))))
  7030. ;; Maintain old links, if present
  7031. (setq old-entry (assq (idlwave-sintern-sysvar var) old))
  7032. (setq link (assq 'link old-entry))
  7033. (setq idlwave-system-variables-alist
  7034. (cons (list var
  7035. (cons
  7036. 'tags
  7037. (mapcar (lambda (x)
  7038. (cons x
  7039. (cdr (assq
  7040. (idlwave-sintern-sysvartag x)
  7041. (cdr (assq 'tags old-entry))))))
  7042. tags)) link)
  7043. idlwave-system-variables-alist)))
  7044. ;; Keep the old value if query was not successful
  7045. (setq idlwave-system-variables-alist
  7046. (or idlwave-system-variables-alist old))))
  7047. (defun idlwave-completion-fontify-classes ()
  7048. "Goto the *Completions* buffer and fontify the class info."
  7049. (when (featurep 'font-lock)
  7050. (with-current-buffer "*Completions*"
  7051. (save-excursion
  7052. (goto-char (point-min))
  7053. (let ((buffer-read-only nil))
  7054. (while (re-search-forward "\\.*<[^>]+>" nil t)
  7055. (put-text-property (match-beginning 0) (match-end 0)
  7056. 'face 'font-lock-string-face)))))))
  7057. (defun idlwave-uniquify (list)
  7058. (let ((ht (make-hash-table :size (length list) :test 'equal)))
  7059. (delq nil
  7060. (mapcar (lambda (x)
  7061. (unless (gethash x ht)
  7062. (puthash x t ht)
  7063. x))
  7064. list))))
  7065. (defun idlwave-after-successful-completion (type slash &optional verify)
  7066. "Add `=' or `(' after successful completion of keyword and function.
  7067. Restore the pre-completion window configuration if possible."
  7068. (cond
  7069. ((eq type 'procedure)
  7070. nil)
  7071. ((eq type 'function)
  7072. (cond
  7073. ((equal idlwave-function-completion-adds-paren nil) nil)
  7074. ((or (equal idlwave-function-completion-adds-paren t)
  7075. (equal idlwave-function-completion-adds-paren 1))
  7076. (insert "("))
  7077. ((equal idlwave-function-completion-adds-paren 2)
  7078. (insert "()")
  7079. (backward-char 1))
  7080. (t nil)))
  7081. ((eq type 'keyword)
  7082. (if (and idlwave-keyword-completion-adds-equal
  7083. (not slash))
  7084. (progn (insert "=") t)
  7085. nil)))
  7086. ;; Restore the pre-completion window configuration if this is safe.
  7087. (if (or (eq verify 'force) ; force
  7088. (and
  7089. (get-buffer-window "*Completions*") ; visible
  7090. (idlwave-local-value 'idlwave-completion-p
  7091. "*Completions*") ; cib-buffer
  7092. (eq (marker-buffer idlwave-completion-mark)
  7093. (current-buffer)) ; buffer OK
  7094. (equal (marker-position idlwave-completion-mark)
  7095. verify))) ; pos OK
  7096. (idlwave-restore-wconf-after-completion))
  7097. (move-marker idlwave-completion-mark nil)
  7098. (setq idlwave-before-completion-wconf nil))
  7099. (defun idlwave-mouse-context-help (ev &optional arg)
  7100. "Call `idlwave-context-help' on the clicked location."
  7101. (interactive "eP")
  7102. (mouse-set-point ev)
  7103. (idlwave-context-help arg))
  7104. (defvar idlwave-last-context-help-pos nil)
  7105. (defun idlwave-context-help (&optional arg)
  7106. "Display IDL Online Help on context.
  7107. If point is on a keyword, help for that keyword will be shown. If
  7108. point is on a routine name or in the argument list of a routine, help
  7109. for that routine will be displayed. Works for system routines and
  7110. keywords, it pulls up text help. For other routines and keywords,
  7111. visits the source file, finding help in the header (if
  7112. `idlwave-help-source-try-header' is non-nil) or the routine definition
  7113. itself."
  7114. (interactive "P")
  7115. (idlwave-do-context-help arg))
  7116. (defun idlwave-mouse-completion-help (ev)
  7117. "Display online help about the completion at point."
  7118. (interactive "eP")
  7119. ;; Restore last-command for next command, to make
  7120. ;; scrolling/canceling of completions work.
  7121. (setq this-command last-command)
  7122. (idlwave-do-mouse-completion-help ev))
  7123. (defun idlwave-routine-info (&optional arg external)
  7124. "Display a routines calling sequence and list of keywords.
  7125. When point is on the name a function or procedure, or in the argument
  7126. list of a function or procedure, this command displays a help buffer with
  7127. the information. When called with prefix arg, enforce class query.
  7128. When point is on an object operator `->', display the class stored in
  7129. this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
  7130. arg, the class property is cleared out."
  7131. (interactive "P")
  7132. (idlwave-routines)
  7133. (if (string-match "->" (buffer-substring
  7134. (max (point-min) (1- (point)))
  7135. (min (+ 2 (point)) (point-max))))
  7136. ;; Cursor is on an arrow
  7137. (if (get-text-property (point) 'idlwave-class)
  7138. ;; arrow has class property
  7139. (if arg
  7140. ;; Remove property
  7141. (save-excursion
  7142. (backward-char 1)
  7143. (when (looking-at ".?\\(->\\)")
  7144. (remove-text-properties (match-beginning 1) (match-end 1)
  7145. '(idlwave-class nil face nil))
  7146. (message "Class property removed from arrow")))
  7147. ;; Echo class property
  7148. (message "Arrow has text property identifying object to be class %s"
  7149. (get-text-property (point) 'idlwave-class)))
  7150. ;; No property found
  7151. (message "Arrow has no class text property"))
  7152. ;; Not on an arrow...
  7153. (let* ((idlwave-query-class nil)
  7154. (idlwave-force-class-query (equal arg '(4)))
  7155. (module (idlwave-what-module)))
  7156. (if (car module)
  7157. (apply 'idlwave-display-calling-sequence
  7158. (idlwave-fix-module-if-obj_new module))
  7159. (error "Don't know which calling sequence to show")))))
  7160. (defun idlwave-resolve (&optional arg)
  7161. "Call RESOLVE_ROUTINE on the module name at point.
  7162. Like `idlwave-routine-info', this looks for a routine call at point.
  7163. After confirmation in the minibuffer, it will use the shell to issue
  7164. a RESOLVE call for this routine, to attempt to make it defined and its
  7165. routine info available for IDLWAVE. If the routine is a method call,
  7166. both `class__method' and `class__define' will be tried.
  7167. With ARG, enforce query for the class of object methods."
  7168. (interactive "P")
  7169. (let* ((idlwave-query-class nil)
  7170. (idlwave-force-class-query (equal arg '(4)))
  7171. (module (idlwave-what-module))
  7172. (name (idlwave-make-full-name (nth 2 module) (car module)))
  7173. (type (if (eq (nth 1 module) 'pro) "pro" "function"))
  7174. (resolve (read-string "Resolve: " (format "%s %s" type name)))
  7175. (kwd "")
  7176. class)
  7177. (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
  7178. resolve)
  7179. (setq type (match-string 1 resolve)
  7180. class (if (match-beginning 2)
  7181. (match-string 3 resolve)
  7182. nil)
  7183. name (match-string 4 resolve)))
  7184. (if (string= (downcase type) "function")
  7185. (setq kwd ",/is_function"))
  7186. (cond
  7187. ((null class)
  7188. (idlwave-shell-send-command
  7189. (format "resolve_routine,'%s'%s" (downcase name) kwd)
  7190. 'idlwave-update-routine-info
  7191. nil t))
  7192. (t
  7193. (idlwave-shell-send-command
  7194. (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
  7195. (list 'idlwave-shell-send-command
  7196. (format "resolve_routine,'%s__%s'%s"
  7197. (downcase class) (downcase name) kwd)
  7198. '(idlwave-update-routine-info)
  7199. nil t))))))
  7200. (defun idlwave-find-module-this-file ()
  7201. (interactive)
  7202. (idlwave-find-module '(4)))
  7203. (defun idlwave-find-module (&optional arg)
  7204. "Find the source code of an IDL module.
  7205. Works for modules for which IDLWAVE has routine info available.
  7206. The function offers as default the module name `idlwave-routine-info'
  7207. would use. With ARG limit to this buffer. With two prefix ARG's
  7208. force class query for object methods."
  7209. (interactive "P")
  7210. (let* ((idlwave-query-class nil)
  7211. (idlwave-force-class-query (equal arg '(16)))
  7212. (this-buffer (equal arg '(4)))
  7213. (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
  7214. (default (if module
  7215. (concat (idlwave-make-full-name
  7216. (nth 2 module) (car module))
  7217. (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
  7218. "none"))
  7219. (list
  7220. (idlwave-uniquify
  7221. (delq nil
  7222. (mapcar (lambda (x)
  7223. (if (eq 'system (car-safe (nth 3 x)))
  7224. ;; Take out system routines with no source.
  7225. nil
  7226. (list
  7227. (concat (idlwave-make-full-name
  7228. (nth 2 x) (car x))
  7229. (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
  7230. (if this-buffer
  7231. (idlwave-save-buffer-update)
  7232. (idlwave-routines))))))
  7233. (name (idlwave-completing-read
  7234. (if (or (not this-buffer)
  7235. (assoc default list))
  7236. (format "Module (Default %s): " default)
  7237. (format "Module in this file: "))
  7238. list))
  7239. type class)
  7240. (if (string-match "\\`\\s-*\\'" name)
  7241. ;; Nothing, use the default.
  7242. (setq name default))
  7243. (if (string-match "<[fp]>" name)
  7244. (setq type (substring name -2 -1)
  7245. name (substring name 0 -3)))
  7246. (if (string-match "\\(.*\\)::\\(.*\\)" name)
  7247. (setq class (match-string 1 name)
  7248. name (match-string 2 name)))
  7249. (setq name (idlwave-sintern-routine-or-method name class)
  7250. class (idlwave-sintern-class class)
  7251. type (cond ((equal type "f") 'fun)
  7252. ((equal type "p") 'pro)
  7253. (t t)))
  7254. (idlwave-do-find-module name type class nil this-buffer)))
  7255. (defun idlwave-do-find-module (name type class
  7256. &optional force-source this-buffer)
  7257. (let ((name1 (idlwave-make-full-name class name))
  7258. source buf1 entry
  7259. (buf (current-buffer))
  7260. (pos (point))
  7261. file name2)
  7262. (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
  7263. 'WITH-FILE)
  7264. source (or force-source (nth 3 entry))
  7265. name2 (if (nth 2 entry)
  7266. (idlwave-make-full-name (nth 2 entry) name)
  7267. name1))
  7268. (if source
  7269. (setq file (idlwave-routine-source-file source)))
  7270. (unless file ; Try to find it on the path.
  7271. (setq file
  7272. (idlwave-expand-lib-file-name
  7273. (if class
  7274. (format "%s__define.pro" (downcase class))
  7275. (format "%s.pro" (downcase name))))))
  7276. (cond
  7277. ((or (null name) (equal name ""))
  7278. (error "Abort"))
  7279. ((eq (car source) 'system)
  7280. (error "Source code for system routine %s is not available"
  7281. name2))
  7282. ((or (not file) (not (file-regular-p file)))
  7283. (error "Source code for routine %s is not available"
  7284. name2))
  7285. (t
  7286. (when (not this-buffer)
  7287. (setq buf1
  7288. (idlwave-find-file-noselect file 'find))
  7289. (pop-to-buffer buf1 t))
  7290. (goto-char (point-max))
  7291. (let ((case-fold-search t))
  7292. (if (re-search-backward
  7293. (concat "^[ \t]*\\<"
  7294. (cond ((eq type 'fun) "function")
  7295. ((eq type 'pro) "pro")
  7296. (t "\\(pro\\|function\\)"))
  7297. "\\>[ \t]+"
  7298. (regexp-quote (downcase name2))
  7299. "[^a-zA-Z0-9_$]")
  7300. nil t)
  7301. (goto-char (match-beginning 0))
  7302. (pop-to-buffer buf)
  7303. (goto-char pos)
  7304. (error "Could not find routine %s" name2)))))))
  7305. (defun idlwave-what-module ()
  7306. "Return a default module for stuff near point.
  7307. Used by `idlwave-routine-info' and `idlwave-find-module'."
  7308. (idlwave-routines)
  7309. (if (let ((case-fold-search t))
  7310. (save-excursion
  7311. (idlwave-beginning-of-statement)
  7312. (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
  7313. ;; This is a function or procedure definition statement
  7314. ;; We return the defined routine as module.
  7315. (list
  7316. (idlwave-sintern-routine-or-method (match-string-no-properties 4)
  7317. (match-string-no-properties 2))
  7318. (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
  7319. (idlwave-sintern-class (match-string 3)))
  7320. ;; Not a definition statement - analyze precise position.
  7321. (let* ((where (idlwave-where))
  7322. (cw (nth 2 where))
  7323. (pro (car (nth 0 where)))
  7324. (func (car (nth 1 where)))
  7325. (this-word (idlwave-this-word "a-zA-Z0-9$_"))
  7326. (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
  7327. (following-char)))
  7328. )
  7329. (cond
  7330. ((and (eq cw 'procedure)
  7331. (not (equal this-word "")))
  7332. (setq this-word (idlwave-sintern-routine-or-method
  7333. this-word (nth 2 (nth 3 where))))
  7334. (list this-word 'pro
  7335. (idlwave-determine-class
  7336. (cons this-word (cdr (nth 3 where)))
  7337. 'pro)))
  7338. ((and (eq cw 'function)
  7339. (not (equal this-word ""))
  7340. (or (eq next-char ?\() ; exclude arrays, vars.
  7341. (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
  7342. (setq this-word (idlwave-sintern-routine-or-method
  7343. this-word (nth 2 (nth 3 where))))
  7344. (list this-word 'fun
  7345. (idlwave-determine-class
  7346. (cons this-word (cdr (nth 3 where)))
  7347. 'fun)))
  7348. ((and (memq cw '(function-keyword procedure-keyword))
  7349. (not (equal this-word ""))
  7350. (eq next-char ?\()) ; A function!
  7351. (setq this-word (idlwave-sintern-routine this-word))
  7352. (list this-word 'fun nil))
  7353. (func
  7354. (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
  7355. (pro
  7356. (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
  7357. (t nil)))))
  7358. (defun idlwave-what-module-find-class ()
  7359. "Call `idlwave-what-module' and find the inherited class if necessary."
  7360. (let* ((module (idlwave-what-module))
  7361. (class (nth 2 module)))
  7362. (if (and (= (length module) 3)
  7363. (stringp class))
  7364. (list (car module)
  7365. (nth 1 module)
  7366. (apply 'idlwave-find-inherited-class module))
  7367. module)))
  7368. (defun idlwave-find-inherited-class (name type class)
  7369. "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
  7370. (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
  7371. (if entry
  7372. (nth 2 entry)
  7373. class)))
  7374. (defun idlwave-fix-module-if-obj_new (module)
  7375. "Check if MODULE points to obj_new.
  7376. If yes, and if the cursor is in the keyword region, change to the
  7377. appropriate Init method."
  7378. (let* ((name (car module))
  7379. (pos (point))
  7380. (case-fold-search t)
  7381. string)
  7382. (if (and (stringp name)
  7383. (equal (downcase name) "obj_new")
  7384. (save-excursion
  7385. (idlwave-beginning-of-statement)
  7386. (setq string (buffer-substring (point) pos))
  7387. (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
  7388. string)))
  7389. (let ((name "Init")
  7390. (class (match-string 1 string)))
  7391. (setq module (list (idlwave-sintern-method "Init")
  7392. 'fun
  7393. (idlwave-sintern-class class)))))
  7394. module))
  7395. (defun idlwave-fix-keywords (name type class keywords
  7396. &optional super-classes system)
  7397. "Update a list of keywords.
  7398. Translate OBJ_NEW, adding all super-class keywords, or all keywords
  7399. from all classes if CLASS equals t. If SYSTEM is non-nil, don't
  7400. demand _EXTRA in the keyword list."
  7401. (let ((case-fold-search t))
  7402. ;; If this is the OBJ_NEW function, try to figure out the class and use
  7403. ;; the keywords from the corresponding INIT method.
  7404. (if (and (equal (upcase name) "OBJ_NEW")
  7405. (derived-mode-p 'idlwave-mode 'idlwave-shell-mode))
  7406. (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
  7407. (string (buffer-substring bos (point)))
  7408. (case-fold-search t)
  7409. class)
  7410. (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
  7411. string)
  7412. (setq class (idlwave-sintern-class (match-string 1 string)))
  7413. (setq idlwave-current-obj_new-class class)
  7414. (setq keywords
  7415. (append keywords
  7416. (idlwave-entry-keywords
  7417. (idlwave-rinfo-assq
  7418. (idlwave-sintern-method "INIT")
  7419. 'fun
  7420. class
  7421. (idlwave-routines)) 'do-link))))))
  7422. ;; If the class is t, combine all keywords of all methods NAME
  7423. (when (eq class t)
  7424. (mapc (lambda (entry)
  7425. (and
  7426. (nth 2 entry) ; non-nil class
  7427. (eq (nth 1 entry) type) ; correct type
  7428. (setq keywords
  7429. (append keywords
  7430. (idlwave-entry-keywords entry 'do-link)))))
  7431. (idlwave-all-assq name (idlwave-routines)))
  7432. (setq keywords (idlwave-uniquify keywords)))
  7433. ;; If we have inheritance, add all keywords from superclasses, if
  7434. ;; the user indicated that method in `idlwave-keyword-class-inheritance'
  7435. (when (and
  7436. super-classes
  7437. idlwave-keyword-class-inheritance
  7438. (stringp class)
  7439. (or
  7440. system
  7441. (assq (idlwave-sintern-keyword "_extra") keywords)
  7442. (assq (idlwave-sintern-keyword "_ref_extra") keywords))
  7443. ;; Check if one of the keyword-class regexps matches the name
  7444. (let ((regexps idlwave-keyword-class-inheritance) re)
  7445. (catch 'exit
  7446. (while (setq re (pop regexps))
  7447. (if (string-match re name) (throw 'exit t))))))
  7448. (loop for entry in (idlwave-routines) do
  7449. (and (nth 2 entry) ; non-nil class
  7450. (memq (nth 2 entry) super-classes) ; an inherited class
  7451. (eq (nth 1 entry) type) ; correct type
  7452. (eq (car entry) name) ; correct name
  7453. (mapc (lambda (k) (add-to-list 'keywords k))
  7454. (idlwave-entry-keywords entry 'do-link))))
  7455. (setq keywords (idlwave-uniquify keywords)))
  7456. ;; Return the final list
  7457. keywords))
  7458. (defun idlwave-expand-keyword (keyword module)
  7459. "Expand KEYWORD to one of the valid keyword parameters of MODULE.
  7460. KEYWORD may be an exact match or an abbreviation of a keyword.
  7461. If the match is exact, KEYWORD itself is returned, even if there may be other
  7462. keywords of which KEYWORD is an abbreviation. This is necessary because some
  7463. system routines have keywords which are prefixes of other keywords.
  7464. If KEYWORD is an abbreviation of several keywords, a list of all possible
  7465. completions is returned.
  7466. If the abbreviation was unique, the correct keyword is returned.
  7467. If it cannot be a keyword, the function return nil.
  7468. If we do not know about MODULE, just return KEYWORD literally."
  7469. (let* ((name (car module))
  7470. (type (nth 1 module))
  7471. (class (nth 2 module))
  7472. (kwd (idlwave-sintern-keyword keyword))
  7473. (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
  7474. (kwd-alist (idlwave-entry-keywords entry))
  7475. (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
  7476. (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
  7477. (completion-ignore-case t)
  7478. candidates)
  7479. (cond ((assq kwd kwd-alist)
  7480. kwd)
  7481. ((setq candidates (all-completions kwd kwd-alist))
  7482. (if (= (length candidates) 1)
  7483. (car candidates)
  7484. candidates))
  7485. ((and entry extra)
  7486. ;; Inheritance may cause this keyword to be correct
  7487. keyword)
  7488. (entry
  7489. ;; We do know the function, which does not have the keyword.
  7490. nil)
  7491. (t
  7492. ;; We do not know the function, so this just might be a correct
  7493. ;; keyword - return it as it is.
  7494. keyword))))
  7495. (defvar idlwave-rinfo-mouse-map
  7496. (let ((map (make-sparse-keymap)))
  7497. (define-key map
  7498. (if (featurep 'xemacs) [button2] [mouse-2])
  7499. 'idlwave-mouse-active-rinfo)
  7500. (define-key map
  7501. (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
  7502. 'idlwave-mouse-active-rinfo-shift)
  7503. (define-key map
  7504. (if (featurep 'xemacs) [button3] [mouse-3])
  7505. 'idlwave-mouse-active-rinfo-right)
  7506. (define-key map " " 'idlwave-active-rinfo-space)
  7507. (define-key map "q" 'idlwave-quit-help)
  7508. map))
  7509. (defvar idlwave-rinfo-map
  7510. (let ((map (make-sparse-keymap)))
  7511. (define-key map "q" 'idlwave-quit-help)
  7512. map))
  7513. (defvar idlwave-popup-source nil)
  7514. (defvar idlwave-rinfo-marker (make-marker))
  7515. (defun idlwave-quit-help ()
  7516. (interactive)
  7517. (let ((ri-window (get-buffer-window "*Help*"))
  7518. (olh-window (get-buffer-window "*IDLWAVE Help*")))
  7519. (when (and olh-window
  7520. (fboundp 'idlwave-help-quit))
  7521. (select-window olh-window)
  7522. (idlwave-help-quit))
  7523. (when (window-live-p ri-window)
  7524. (delete-window ri-window))))
  7525. (defun idlwave-display-calling-sequence (name type class
  7526. &optional initial-class)
  7527. ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
  7528. (let* ((initial-class (or initial-class class))
  7529. (entry (or (idlwave-best-rinfo-assq name type class
  7530. (idlwave-routines))
  7531. (idlwave-rinfo-assq name type class
  7532. idlwave-unresolved-routines)))
  7533. (name (or (car entry) name))
  7534. (class (or (nth 2 entry) class))
  7535. (superclasses (idlwave-all-class-inherits initial-class))
  7536. (twins (idlwave-routine-twins entry))
  7537. (dtwins (idlwave-study-twins twins))
  7538. (all dtwins)
  7539. (system (eq (car (nth 3 entry)) 'system))
  7540. (calling-seq (nth 4 entry))
  7541. (keywords (idlwave-entry-keywords entry 'do-link))
  7542. (html-file (car (nth 5 entry)))
  7543. (help-echo-kwd
  7544. "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
  7545. (help-echo-use
  7546. "Button2/3: Online Help")
  7547. (help-echo-src
  7548. "Button2: Jump to source and back | Button3: Source in Help window.")
  7549. (help-echo-class
  7550. "Button2: Display info about same method in superclass")
  7551. (col 0)
  7552. (data (list name type class (current-buffer) nil initial-class))
  7553. (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
  7554. (face 'idlwave-help-link)
  7555. beg props win cnt total)
  7556. ;; Fix keywords, but don't add chained super-classes, since these
  7557. ;; are shown separately for that super-class
  7558. (setq keywords (idlwave-fix-keywords name type class keywords))
  7559. (cond
  7560. ((null entry)
  7561. (error "No %s %s known %s" type name
  7562. (if initial-class (concat "in class " initial-class) "")))
  7563. ((or (null name) (equal name ""))
  7564. (error "No function or procedure call at point"))
  7565. ((null calling-seq)
  7566. (error "Calling sequence of %s %s not available" type name))
  7567. (t
  7568. (move-marker idlwave-rinfo-marker (point))
  7569. (with-current-buffer (get-buffer-create "*Help*")
  7570. (use-local-map idlwave-rinfo-map)
  7571. (setq buffer-read-only nil)
  7572. (erase-buffer)
  7573. (set (make-local-variable 'idlwave-popup-source) nil)
  7574. (set (make-local-variable 'idlwave-current-obj_new-class)
  7575. idlwave-current-obj_new-class)
  7576. (when superclasses
  7577. (setq props (list 'mouse-face 'highlight
  7578. km-prop idlwave-rinfo-mouse-map
  7579. 'help-echo help-echo-class
  7580. 'data (cons 'class data)))
  7581. (let ((classes (cons initial-class superclasses)) c)
  7582. (insert "Classes: ")
  7583. (while (setq c (pop classes))
  7584. (insert " ")
  7585. (setq beg (point))
  7586. (insert c)
  7587. (if (equal (downcase c) (downcase class))
  7588. (add-text-properties beg (point) (list 'face 'bold))
  7589. ;; If Method exists in a different class link it
  7590. (if (idlwave-rinfo-assq name type c (idlwave-routines))
  7591. (add-text-properties beg (point) props))))
  7592. (insert "\n")))
  7593. (setq props (list 'mouse-face 'highlight
  7594. km-prop idlwave-rinfo-mouse-map
  7595. 'help-echo help-echo-use
  7596. 'data (cons 'usage data)))
  7597. (if html-file (setq props (append (list 'face face 'link html-file)
  7598. props)))
  7599. (insert "Usage: ")
  7600. (setq beg (point))
  7601. (insert (if class
  7602. (format calling-seq class name class name class name)
  7603. (format calling-seq name name name name))
  7604. "\n")
  7605. (add-text-properties beg (point) props)
  7606. (insert "Keywords:")
  7607. (if (null keywords)
  7608. (insert " No keywords accepted.")
  7609. (setq col 9)
  7610. (mapc
  7611. (lambda (x)
  7612. (if (>= (+ col 1 (length (car x)))
  7613. (window-width))
  7614. (progn
  7615. (insert "\n ")
  7616. (setq col 9)))
  7617. (insert " ")
  7618. (setq beg (point)
  7619. ;; Relevant keywords already have link property attached
  7620. props (list 'mouse-face 'highlight
  7621. km-prop idlwave-rinfo-mouse-map
  7622. 'data (cons 'keyword data)
  7623. 'help-echo help-echo-kwd
  7624. 'keyword (car x)))
  7625. (if system (setq props (append (list 'face face) props)))
  7626. (insert (car x))
  7627. (add-text-properties beg (point) props)
  7628. (setq col (+ col 1 (length (car x)))))
  7629. keywords))
  7630. (setq cnt 1 total (length all))
  7631. ;; Here entry is (key file (list of type-conses))
  7632. (while (setq entry (pop all))
  7633. (setq props (list 'mouse-face 'highlight
  7634. km-prop idlwave-rinfo-mouse-map
  7635. 'help-echo help-echo-src
  7636. 'source (list (car (car (nth 2 entry))) ;type
  7637. (nth 1 entry)
  7638. nil
  7639. (cdr (car (nth 2 entry))))
  7640. 'data (cons 'source data)))
  7641. (idlwave-insert-source-location
  7642. (format "\n%-8s %s"
  7643. (if (equal cnt 1)
  7644. (if (> total 1) "Sources:" "Source:")
  7645. "")
  7646. (if (> total 1) "- " ""))
  7647. entry props)
  7648. (incf cnt)
  7649. (when (and all (> cnt idlwave-rinfo-max-source-lines))
  7650. ;; No more source lines, please
  7651. (insert (format
  7652. "\n Source information truncated to %d entries."
  7653. idlwave-rinfo-max-source-lines))
  7654. (setq all nil)))
  7655. (goto-char (point-min))
  7656. (setq buffer-read-only t))
  7657. (display-buffer "*Help*")
  7658. (if (and (setq win (get-buffer-window "*Help*"))
  7659. idlwave-resize-routine-help-window)
  7660. (progn
  7661. (let ((ww (selected-window)))
  7662. (unwind-protect
  7663. (progn
  7664. (select-window win)
  7665. (enlarge-window (- (/ (frame-height) 2)
  7666. (window-height)))
  7667. (shrink-window-if-larger-than-buffer))
  7668. (select-window ww)))))))))
  7669. (defun idlwave-insert-source-location (prefix entry &optional file-props)
  7670. "Insert a source location into the routine info buffer.
  7671. Start line with PREFIX. If a file name is inserted, add FILE-PROPS
  7672. to it."
  7673. (let* ((key (car entry))
  7674. (file (nth 1 entry))
  7675. (types (nth 2 entry))
  7676. (shell-flag (assq 'compiled types))
  7677. (buffer-flag (assq 'buffer types))
  7678. (user-flag (assq 'user types))
  7679. (lib-flag (assq 'lib types))
  7680. (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
  7681. (and user-flag (idlwave-count-memq 'user types))
  7682. (and lib-flag (idlwave-count-memq 'lib types))
  7683. 1))
  7684. (doflags t)
  7685. beg special)
  7686. (insert prefix)
  7687. (cond
  7688. ((eq key 'system)
  7689. (setq doflags nil)
  7690. (insert "System "))
  7691. ((eq key 'builtin)
  7692. (setq doflags nil)
  7693. (insert "Builtin "))
  7694. ((and (not file) shell-flag)
  7695. (insert "Unresolved"))
  7696. ((null file)
  7697. (insert "ERROR"))
  7698. ((idlwave-syslib-p file)
  7699. (if (string-match "obsolete" (file-name-directory file))
  7700. (insert "Obsolete ")
  7701. (insert "SystemLib ")))
  7702. ;; New special syntax: taken directly from routine-info for
  7703. ;; library catalog routines
  7704. ((setq special (or (cdr lib-flag) (cdr user-flag)))
  7705. (insert (format "%-10s" special)))
  7706. ;; Old special syntax: a matching regexp
  7707. ((setq special (idlwave-special-lib-test file))
  7708. (insert (format "%-10s" special)))
  7709. ;; Catch-all with file
  7710. ((idlwave-lib-p file) (insert "Library "))
  7711. ;; Sanity catch all
  7712. (t (insert "Other ")))
  7713. (when doflags
  7714. (insert (concat
  7715. " ["
  7716. (if lib-flag "L" "-")
  7717. (if user-flag "C" "-")
  7718. (if shell-flag "S" "-")
  7719. (if buffer-flag "B" "-")
  7720. "] ")))
  7721. (when (> ndupl 1)
  7722. (setq beg (point))
  7723. (insert (format "(%dx) " ndupl))
  7724. (add-text-properties beg (point) (list 'face 'bold)))
  7725. (when (and file (not (equal file "")))
  7726. (setq beg (point))
  7727. (insert (apply 'abbreviate-file-name
  7728. (if (featurep 'xemacs) (list file t) (list file))))
  7729. (if file-props
  7730. (add-text-properties beg (point) file-props)))))
  7731. (defun idlwave-special-lib-test (file)
  7732. "Check the path of FILE against the regexps which define special libs.
  7733. Return the name of the special lib if there is a match."
  7734. (let ((alist idlwave-special-lib-alist)
  7735. entry rtn)
  7736. (cond
  7737. ((stringp file)
  7738. (while (setq entry (pop alist))
  7739. (if (string-match (car entry) file)
  7740. (setq rtn (cdr entry)
  7741. alist nil)))
  7742. rtn)
  7743. (t nil))))
  7744. (defun idlwave-mouse-active-rinfo-right (ev)
  7745. (interactive "e")
  7746. (idlwave-mouse-active-rinfo ev 'right))
  7747. (defun idlwave-mouse-active-rinfo-shift (ev)
  7748. (interactive "e")
  7749. (idlwave-mouse-active-rinfo ev nil 'shift))
  7750. (defun idlwave-active-rinfo-space ()
  7751. (interactive)
  7752. (idlwave-mouse-active-rinfo nil 'right))
  7753. (defun idlwave-mouse-active-rinfo (ev &optional right shift)
  7754. "Do the mouse actions in the routine info buffer.
  7755. Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
  7756. was pressed."
  7757. (interactive "e")
  7758. (if ev (mouse-set-point ev))
  7759. (let (data id name type class buf bufwin source link keyword
  7760. word initial-class)
  7761. (setq data (get-text-property (point) 'data)
  7762. source (get-text-property (point) 'source)
  7763. keyword (get-text-property (point) 'keyword)
  7764. link (get-text-property (point) 'link)
  7765. id (car data)
  7766. name (nth 1 data) type (nth 2 data) class (nth 3 data)
  7767. buf (nth 4 data)
  7768. initial-class (nth 6 data)
  7769. word (idlwave-this-word)
  7770. bufwin (get-buffer-window buf t))
  7771. (cond ((eq id 'class) ; Switch class being displayed
  7772. (if (window-live-p bufwin) (select-window bufwin))
  7773. (idlwave-display-calling-sequence
  7774. (idlwave-sintern-method name)
  7775. type (idlwave-sintern-class word)
  7776. initial-class))
  7777. ((eq id 'usage) ; Online help on this routine
  7778. (idlwave-online-help link name type class))
  7779. ((eq id 'source) ; Source in help or buffer
  7780. (if right ; In help
  7781. (let ((idlwave-extra-help-function 'idlwave-help-with-source)
  7782. (idlwave-help-source-try-header nil)
  7783. ;; Fake idlwave-routines so help will find the right entry
  7784. (idlwave-routines
  7785. (list (list name type class source ""))))
  7786. (idlwave-help-get-special-help name type class nil))
  7787. ;; Otherwise just pop to the source
  7788. (setq idlwave-popup-source (not idlwave-popup-source))
  7789. (if idlwave-popup-source
  7790. (condition-case err
  7791. (idlwave-do-find-module name type class source)
  7792. (error
  7793. (setq idlwave-popup-source nil)
  7794. (if (window-live-p bufwin) (select-window bufwin))
  7795. (error (nth 1 err))))
  7796. (if bufwin
  7797. (select-window bufwin)
  7798. (pop-to-buffer buf))
  7799. (goto-char (marker-position idlwave-rinfo-marker)))))
  7800. ((eq id 'keyword)
  7801. (if right
  7802. (idlwave-online-help link name type class keyword)
  7803. (idlwave-rinfo-insert-keyword keyword buf shift))))))
  7804. (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
  7805. "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
  7806. (let ((bwin (get-buffer-window buffer)))
  7807. (if idlwave-complete-empty-string-as-lower-case
  7808. (setq keyword (downcase keyword)))
  7809. (if bwin
  7810. (select-window bwin)
  7811. (pop-to-buffer buffer)
  7812. (setq bwin (get-buffer-window buffer)))
  7813. (if (eq (preceding-char) ?/)
  7814. (insert keyword)
  7815. (unless (save-excursion
  7816. (re-search-backward
  7817. "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
  7818. (min (- (point) 100) (point-min)) t))
  7819. (insert ", "))
  7820. (if shift (insert "/"))
  7821. (insert keyword)
  7822. (if (and (not shift)
  7823. idlwave-keyword-completion-adds-equal)
  7824. (insert "=")))))
  7825. (defun idlwave-list-buffer-load-path-shadows (&optional arg)
  7826. "List the load path shadows of all routines defined in current buffer."
  7827. (interactive "P")
  7828. (idlwave-routines)
  7829. (if (derived-mode-p 'idlwave-mode)
  7830. (idlwave-list-load-path-shadows
  7831. nil (idlwave-update-current-buffer-info 'save-buffer)
  7832. "in current buffer")
  7833. (error "Current buffer is not in idlwave-mode")))
  7834. (defun idlwave-list-shell-load-path-shadows (&optional arg)
  7835. "List the load path shadows of all routines compiled under the shell.
  7836. This is very useful for checking an IDL application. Just compile the
  7837. application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
  7838. routines and update IDLWAVE internal info. Then check for shadowing
  7839. with this command."
  7840. (interactive "P")
  7841. (cond
  7842. ((or (not (fboundp 'idlwave-shell-is-running))
  7843. (not (idlwave-shell-is-running)))
  7844. (error "Shell is not running"))
  7845. ((null idlwave-compiled-routines)
  7846. (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
  7847. (t
  7848. (idlwave-list-load-path-shadows nil idlwave-compiled-routines
  7849. "in the shell"))))
  7850. (defun idlwave-list-all-load-path-shadows (&optional arg)
  7851. "List the load path shadows of all routines known to IDLWAVE."
  7852. (interactive "P")
  7853. (idlwave-list-load-path-shadows nil nil "globally"))
  7854. (defvar idlwave-sort-prefer-buffer-info t
  7855. "Internal variable used to influence `idlwave-routine-twin-compare'.")
  7856. (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
  7857. "List the routines which are defined multiple times.
  7858. Search the information IDLWAVE has about IDL routines for multiple
  7859. definitions.
  7860. When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
  7861. When IDL hits a routine call which is not defined, it will search on
  7862. the load path in order to find a definition. The output of this command
  7863. can be used to detect possible name clashes during this process."
  7864. (idlwave-routines) ; Make sure everything is loaded.
  7865. (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
  7866. (or (y-or-n-p
  7867. "You don't have any user or library catalogs. Continue anyway? ")
  7868. (error "Abort")))
  7869. (let* ((routines (append idlwave-system-routines
  7870. idlwave-compiled-routines
  7871. idlwave-library-catalog-routines
  7872. idlwave-user-catalog-routines
  7873. idlwave-buffer-routines
  7874. nil))
  7875. (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
  7876. (keymap (make-sparse-keymap))
  7877. (props (list 'mouse-face 'highlight
  7878. km-prop keymap
  7879. 'help-echo "Mouse2: Find source"))
  7880. (nroutines (length (or special-routines routines)))
  7881. (step (/ nroutines 100))
  7882. (n 0)
  7883. (cnt 0)
  7884. (idlwave-sort-prefer-buffer-info nil)
  7885. routine twins dtwins twin done props1 lroutines)
  7886. (if special-routines
  7887. ;; Just looking for shadows of a few special routines
  7888. (setq lroutines routines
  7889. routines special-routines))
  7890. (message "Sorting routines...")
  7891. (setq routines (sort routines
  7892. (lambda (a b)
  7893. (string< (downcase (idlwave-make-full-name
  7894. (nth 2 a) (car a)))
  7895. (downcase (idlwave-make-full-name
  7896. (nth 2 b) (car b)))))))
  7897. (message "Sorting routines...done")
  7898. (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
  7899. (lambda (ev)
  7900. (interactive "e")
  7901. (mouse-set-point ev)
  7902. (apply 'idlwave-do-find-module
  7903. (get-text-property (point) 'find-args))))
  7904. (define-key keymap [(return)]
  7905. (lambda ()
  7906. (interactive)
  7907. (apply 'idlwave-do-find-module
  7908. (get-text-property (point) 'find-args))))
  7909. (message "Compiling list...( 0%%)")
  7910. (with-current-buffer (get-buffer-create "*Shadows*")
  7911. (setq buffer-read-only nil)
  7912. (erase-buffer)
  7913. (while (setq routine (pop routines))
  7914. (if (= (mod (setq n (1+ n)) step) 0)
  7915. (message "Compiling list...(%2d%%)" (floor (* n 100.0) nroutines)))
  7916. ;; Get a list of all twins
  7917. (setq twins (idlwave-routine-twins routine (or lroutines routines)))
  7918. (if (memq routine done)
  7919. (setq dtwins nil)
  7920. (setq dtwins (idlwave-study-twins twins)))
  7921. ;; Mark all twins as dealt with
  7922. (setq done (append twins done))
  7923. (when (or (> (length dtwins) 1)
  7924. (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
  7925. (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
  7926. (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
  7927. (incf cnt)
  7928. (insert (format "\n%s%s"
  7929. (idlwave-make-full-name (nth 2 routine)
  7930. (car routine))
  7931. (if (eq (nth 1 routine) 'fun) "()" "")))
  7932. (while (setq twin (pop dtwins))
  7933. (setq props1 (append (list 'find-args
  7934. (list (nth 0 routine)
  7935. (nth 1 routine)
  7936. (nth 2 routine)))
  7937. props))
  7938. (idlwave-insert-source-location "\n - " twin props1))))
  7939. (goto-char (point-min))
  7940. (setq buffer-read-only t))
  7941. (setq loc (or loc ""))
  7942. (if (> cnt 0)
  7943. (progn
  7944. (display-buffer (get-buffer "*Shadows*"))
  7945. (message "%d case%s of shadowing found %s"
  7946. cnt (if (= cnt 1) "" "s") loc))
  7947. (message "No shadowing conflicts found %s" loc))))
  7948. (defun idlwave-print-source (routine)
  7949. (let* ((source (nth 3 routine))
  7950. (stype (car source))
  7951. (sfile (idlwave-routine-source-file source)))
  7952. (if (idlwave-syslib-p sfile) (setq stype 'syslib))
  7953. (if (and (eq stype 'compiled)
  7954. (or (not (stringp sfile))
  7955. (not (string-match "\\S-" sfile))))
  7956. (setq stype 'unresolved))
  7957. (princ (format " %-10s %s\n"
  7958. stype
  7959. (if sfile sfile "No source code available")))))
  7960. (defun idlwave-routine-twins (entry &optional list)
  7961. "Return all twin entries of ENTRY in LIST.
  7962. LIST defaults to `idlwave-routines'.
  7963. Twin entries are those which have the same name, type, and class.
  7964. ENTRY will also be returned, as the first item of this list."
  7965. (let* ((name (car entry))
  7966. (type (nth 1 entry))
  7967. (class (nth 2 entry))
  7968. (candidates (idlwave-all-assq name (or list (idlwave-routines))))
  7969. twins candidate)
  7970. (while (setq candidate (pop candidates))
  7971. (if (and (not (eq candidate entry))
  7972. (eq type (nth 1 candidate))
  7973. (eq class (nth 2 candidate)))
  7974. (push candidate twins)))
  7975. (if (setq candidate (idlwave-rinfo-assq name type class
  7976. idlwave-unresolved-routines))
  7977. (push candidate twins))
  7978. (cons entry (nreverse twins))))
  7979. (defun idlwave-study-twins (entries)
  7980. "Return dangerous twins of first entry in ENTRIES.
  7981. Dangerous twins are routines with same name, but in different files on
  7982. the load path. If a file is in the system library and has an entry in
  7983. the `idlwave-system-routines' list, we omit the latter as
  7984. non-dangerous because many IDL routines are implemented as library
  7985. routines, and may have been scanned."
  7986. (let* ((entry (car entries))
  7987. (idlwave-twin-name (car entry)) ;
  7988. (type (nth 1 entry)) ; Must be bound for
  7989. (idlwave-twin-class (nth 2 entry)) ; idlwave-routine-twin-compare
  7990. (cnt 0)
  7991. source type type-cons file alist syslibp key)
  7992. (while (setq entry (pop entries))
  7993. (incf cnt)
  7994. (setq source (nth 3 entry)
  7995. type (car source)
  7996. type-cons (cons type (nth 3 source))
  7997. file (idlwave-routine-source-file source))
  7998. ;; Make KEY to index entry properly
  7999. (setq key (cond ((eq type 'system) type)
  8000. (file (file-truename file))
  8001. (t 'unresolved)))
  8002. ;; Check for an entry in the system library
  8003. (if (and file
  8004. (not syslibp)
  8005. (idlwave-syslib-p file))
  8006. (setq syslibp t))
  8007. ;; If there's more than one matching entry for the same file, just
  8008. ;; append the type-cons to the type list.
  8009. (if (setq entry (assoc key alist))
  8010. (push type-cons (nth 2 entry))
  8011. (push (list key file (list type-cons)) alist)))
  8012. (setq alist (nreverse alist))
  8013. (when syslibp
  8014. ;; File is in system *library* - remove any 'system entry
  8015. (setq alist (delq (assq 'system alist) alist)))
  8016. ;; If 'system remains and we've scanned the syslib, it's a builtin
  8017. ;; (rather than a !DIR/lib/.pro file bundled as source).
  8018. (when (and (idlwave-syslib-scanned-p)
  8019. (setq entry (assoc 'system alist)))
  8020. (setcar entry 'builtin))
  8021. (sort alist 'idlwave-routine-twin-compare)))
  8022. ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
  8023. ;; (defvar type)
  8024. (defmacro idlwave-xor (a b)
  8025. `(and (or ,a ,b)
  8026. (not (and ,a ,b))))
  8027. (defun idlwave-routine-entry-compare (a b)
  8028. "Compare two routine info entries for sorting.
  8029. This is the general case. It first compares class, names, and type.
  8030. If it turns out that A and B are twins (same name, class, and type),
  8031. calls another routine which compares twins on the basis of their file
  8032. names and path locations."
  8033. (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
  8034. (cond
  8035. ((not (equal (idlwave-downcase-safe class)
  8036. (idlwave-downcase-safe (nth 2 b))))
  8037. ;; Class decides
  8038. (cond ((null (nth 2 b)) nil)
  8039. ((null class) t)
  8040. (t (string< (downcase class) (downcase (nth 2 b))))))
  8041. ((not (equal (downcase name) (downcase (car b))))
  8042. ;; Name decides
  8043. (string< (downcase name) (downcase (car b))))
  8044. ((not (eq type (nth 1 b)))
  8045. ;; Type decides
  8046. (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
  8047. (t
  8048. ;; A and B are twins - so the decision is more complicated.
  8049. ;; Call twin-compare with the proper arguments.
  8050. (idlwave-routine-entry-compare-twins a b)))))
  8051. (defun idlwave-routine-entry-compare-twins (a b)
  8052. "Compare two routine entries, under the assumption that they are twins.
  8053. This basically calls `idlwave-routine-twin-compare' with the correct args."
  8054. (let* ((idlwave-twin-name (car a))
  8055. (type (nth 1 a))
  8056. (idlwave-twin-class (nth 2 a)) ; used in idlwave-routine-twin-compare
  8057. (asrc (nth 3 a))
  8058. (atype (car asrc))
  8059. (bsrc (nth 3 b))
  8060. (btype (car bsrc))
  8061. (afile (idlwave-routine-source-file asrc))
  8062. (bfile (idlwave-routine-source-file bsrc)))
  8063. (idlwave-routine-twin-compare
  8064. (if (stringp afile)
  8065. (list (file-truename afile) afile (list atype))
  8066. (list atype afile (list atype)))
  8067. (if (stringp bfile)
  8068. (list (file-truename bfile) bfile (list btype))
  8069. (list btype bfile (list btype))))))
  8070. ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
  8071. (defvar idlwave-twin-class)
  8072. (defvar idlwave-twin-name)
  8073. (defun idlwave-routine-twin-compare (a b)
  8074. "Compare two routine twin entries for sorting.
  8075. In here, A and B are not normal routine info entries, but special
  8076. lists (KEY FILENAME (TYPES...)).
  8077. This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values."
  8078. (let* (;; Dis-assemble entries
  8079. (akey (car a)) (bkey (car b))
  8080. (afile (nth 1 a)) (bfile (nth 1 b))
  8081. (atypes (nth 2 a)) (btypes (nth 2 b))
  8082. ;; System routines?
  8083. (asysp (memq akey '(builtin system)))
  8084. (bsysp (memq bkey '(builtin system)))
  8085. ;; Compiled routines?
  8086. (acompp (memq 'compiled atypes))
  8087. (bcompp (memq 'compiled btypes))
  8088. ;; Unresolved?
  8089. (aunresp (or (eq akey 'unresolved)
  8090. (and acompp (not afile))))
  8091. (bunresp (or (eq bkey 'unresolved)
  8092. (and bcompp (not bfile))))
  8093. ;; Buffer info available?
  8094. (abufp (memq 'buffer atypes))
  8095. (bbufp (memq 'buffer btypes))
  8096. ;; On search path?
  8097. (tpath-alist (idlwave-true-path-alist))
  8098. (apathp (and (stringp akey)
  8099. (assoc (file-name-directory akey) tpath-alist)))
  8100. (bpathp (and (stringp bkey)
  8101. (assoc (file-name-directory bkey) tpath-alist)))
  8102. ;; How early on search path? High number means early since we
  8103. ;; measure the tail of the path list
  8104. (anpath (length (memq apathp tpath-alist)))
  8105. (bnpath (length (memq bpathp tpath-alist)))
  8106. ;; Look at file names
  8107. (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
  8108. (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
  8109. (fname-re (if idlwave-twin-class
  8110. (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
  8111. (regexp-quote (downcase idlwave-twin-class))
  8112. (regexp-quote (downcase idlwave-twin-name)))
  8113. (format "\\`%s\\.pro" (regexp-quote (downcase idlwave-twin-name)))))
  8114. ;; Is file name derived from the routine name?
  8115. ;; Method file or class definition file?
  8116. (anamep (string-match fname-re aname))
  8117. (adefp (and idlwave-twin-class anamep
  8118. (string= "define" (match-string 1 aname))))
  8119. (bnamep (string-match fname-re bname))
  8120. (bdefp (and idlwave-twin-class bnamep
  8121. (string= "define" (match-string 1 bname)))))
  8122. ;; Now: follow JD's ideas about sorting. Looks really simple now,
  8123. ;; doesn't it? The difficult stuff is hidden above...
  8124. (cond
  8125. ((idlwave-xor asysp bsysp) asysp) ; System entries first
  8126. ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
  8127. ((and idlwave-sort-prefer-buffer-info
  8128. (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
  8129. ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
  8130. ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
  8131. ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
  8132. ((and idlwave-twin-class anamep bnamep ; both file names match ->
  8133. (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
  8134. ((> anpath bnpath) t) ; Who is first on path?
  8135. (t nil)))) ; Default
  8136. (defun idlwave-routine-source-file (source)
  8137. (if (nth 2 source)
  8138. (expand-file-name (nth 1 source) (nth 2 source))
  8139. (nth 1 source)))
  8140. (defun idlwave-downcase-safe (string)
  8141. "Downcase if string, else return unchanged."
  8142. (if (stringp string)
  8143. (downcase string)
  8144. string))
  8145. (defun idlwave-count-eq (elt list)
  8146. "How often is ELT in LIST?"
  8147. (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
  8148. (defun idlwave-count-memq (elt alist)
  8149. "How often is ELT a key in ALIST?"
  8150. (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
  8151. (defun idlwave-syslib-p (file)
  8152. "Non-nil if FILE is in the system library."
  8153. (let* ((true-syslib (file-name-as-directory
  8154. (file-truename
  8155. (expand-file-name "lib" (idlwave-sys-dir)))))
  8156. (true-file (file-truename file)))
  8157. (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
  8158. (defun idlwave-lib-p (file)
  8159. "Non-nil if FILE is in the library."
  8160. (let ((true-dir (file-name-directory (file-truename file))))
  8161. (assoc true-dir (idlwave-true-path-alist))))
  8162. (defun idlwave-path-alist-add-flag (list-entry flag)
  8163. "Add a flag to the path list entry, if not set."
  8164. (let ((flags (cdr list-entry)))
  8165. (add-to-list 'flags flag)
  8166. (setcdr list-entry flags)))
  8167. (defun idlwave-path-alist-remove-flag (list-entry flag)
  8168. "Remove a flag to the path list entry, if set."
  8169. (let ((flags (delq flag (cdr list-entry))))
  8170. (setcdr list-entry flags)))
  8171. (defun idlwave-true-path-alist ()
  8172. "Return `idlwave-path-alist' alist with true-names.
  8173. Info is cached, but relies on the functions setting `idlwave-path-alist'
  8174. to reset the variable `idlwave-true-path-alist' to nil."
  8175. (or idlwave-true-path-alist
  8176. (setq idlwave-true-path-alist
  8177. (mapcar (lambda(x) (cons
  8178. (file-name-as-directory
  8179. (file-truename
  8180. (directory-file-name
  8181. (car x))))
  8182. (cdr x)))
  8183. idlwave-path-alist))))
  8184. (defun idlwave-syslib-scanned-p ()
  8185. "Non-nil if the system lib file !DIR/lib has been scanned."
  8186. (let* ((true-syslib (file-name-as-directory
  8187. (file-truename
  8188. (expand-file-name "lib" (idlwave-sys-dir))))))
  8189. (cdr (assoc true-syslib (idlwave-true-path-alist)))))
  8190. ;; ----------------------------------------------------------------------------
  8191. ;;
  8192. ;; Online Help display
  8193. ;; ----------------------------------------------------------------------------
  8194. ;;
  8195. ;; Additions for use with imenu.el and func-menu.el
  8196. ;; (pop-up a list of IDL units in the current file).
  8197. ;;
  8198. (defun idlwave-prev-index-position ()
  8199. "Search for the previous procedure or function.
  8200. Return nil if not found. For use with imenu.el."
  8201. (save-match-data
  8202. (cond
  8203. ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
  8204. ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
  8205. (t nil))))
  8206. (defun idlwave-unit-name ()
  8207. "Return the unit name.
  8208. Assumes that point is at the beginning of the unit as found by
  8209. `idlwave-prev-index-position'."
  8210. (forward-sexp 2)
  8211. (forward-sexp -1)
  8212. (let ((begin (point)))
  8213. (re-search-forward
  8214. "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
  8215. (if (fboundp 'buffer-substring-no-properties)
  8216. (buffer-substring-no-properties begin (point))
  8217. (buffer-substring begin (point)))))
  8218. (defalias 'idlwave-function-menu
  8219. (condition-case nil
  8220. (progn
  8221. (require 'func-menu)
  8222. 'function-menu)
  8223. (error (condition-case nil
  8224. (progn
  8225. (require 'imenu)
  8226. 'imenu)
  8227. (error nil)))))
  8228. ;; Here we hack func-menu.el in order to support this new mode.
  8229. ;; The latest versions of func-menu.el already have this stuff in, so
  8230. ;; we hack only if it is not already there.
  8231. (when (featurep 'xemacs)
  8232. (eval-after-load "func-menu"
  8233. '(progn
  8234. (or (assq 'idlwave-mode fume-function-name-regexp-alist)
  8235. (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
  8236. (setq fume-function-name-regexp-alist
  8237. (cons '(idlwave-mode . fume-function-name-regexp-idl)
  8238. fume-function-name-regexp-alist)))
  8239. (or (assq 'idlwave-mode fume-find-function-name-method-alist)
  8240. (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
  8241. (setq fume-find-function-name-method-alist
  8242. (cons '(idlwave-mode . fume-find-next-idl-function-name)
  8243. fume-find-function-name-method-alist))))))
  8244. (defun idlwave-edit-in-idlde ()
  8245. "Edit the current file in IDL Development environment."
  8246. (interactive)
  8247. (start-process "idldeclient" nil
  8248. idlwave-shell-explicit-file-name "-c" "-e"
  8249. (buffer-file-name)))
  8250. (defvar idlwave-help-use-assistant)
  8251. (defun idlwave-launch-idlhelp ()
  8252. "Start the IDLhelp application."
  8253. (interactive)
  8254. (if idlwave-help-use-assistant
  8255. (idlwave-help-assistant-raise)
  8256. (start-process "idlhelp" nil idlwave-help-application)))
  8257. ;; Menus - using easymenu.el
  8258. (defvar idlwave-mode-menu-def
  8259. `("IDLWAVE"
  8260. ["PRO/FUNC menu" idlwave-function-menu t]
  8261. ("Motion"
  8262. ["Subprogram Start" idlwave-beginning-of-subprogram t]
  8263. ["Subprogram End" idlwave-end-of-subprogram t]
  8264. ["Block Start" idlwave-beginning-of-block t]
  8265. ["Block End" idlwave-end-of-block t]
  8266. ["Up Block" idlwave-backward-up-block t]
  8267. ["Down Block" idlwave-down-block t]
  8268. ["Skip Block Backward" idlwave-backward-block t]
  8269. ["Skip Block Forward" idlwave-forward-block t])
  8270. ("Mark"
  8271. ["Subprogram" idlwave-mark-subprogram t]
  8272. ["Block" idlwave-mark-block t]
  8273. ["Header" idlwave-mark-doclib t])
  8274. ("Format"
  8275. ["Indent Entire Statement" idlwave-indent-statement
  8276. :active t :keys "C-u \\[indent-for-tab-command]" ]
  8277. ["Indent Subprogram" idlwave-indent-subprogram t]
  8278. ["(Un)Comment Region" idlwave-toggle-comment-region t]
  8279. ["Continue/Split line" idlwave-split-line t]
  8280. "--"
  8281. ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
  8282. :selected (symbol-value idlwave-fill-function)])
  8283. ("Templates"
  8284. ["Procedure" idlwave-procedure t]
  8285. ["Function" idlwave-function t]
  8286. ["Doc Header" idlwave-doc-header t]
  8287. ["Log" idlwave-doc-modification t]
  8288. "--"
  8289. ["Case" idlwave-case t]
  8290. ["For" idlwave-for t]
  8291. ["Repeat" idlwave-repeat t]
  8292. ["While" idlwave-while t]
  8293. "--"
  8294. ["Close Block" idlwave-close-block t])
  8295. ("Completion"
  8296. ["Complete" idlwave-complete t]
  8297. ("Complete Specific"
  8298. ["1 Procedure Name" (idlwave-complete 'procedure) t]
  8299. ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
  8300. "--"
  8301. ["3 Function Name" (idlwave-complete 'function) t]
  8302. ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
  8303. "--"
  8304. ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
  8305. ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
  8306. "--"
  8307. ["7 Function Method Name" (idlwave-complete 'function-method) t]
  8308. ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
  8309. "--"
  8310. ["9 Class Name" idlwave-complete-class t]))
  8311. ("Routine Info"
  8312. ["Show Routine Info" idlwave-routine-info t]
  8313. ["Online Context Help" idlwave-context-help t]
  8314. "--"
  8315. ["Find Routine Source" idlwave-find-module t]
  8316. ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
  8317. "--"
  8318. ["Update Routine Info" idlwave-update-routine-info t]
  8319. ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
  8320. "--"
  8321. "IDL User Catalog"
  8322. ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
  8323. ["Scan Directories" (idlwave-update-routine-info '(16))
  8324. (and idlwave-path-alist (not idlwave-catalog-process))]
  8325. ["Scan Directories &" (idlwave-update-routine-info '(64))
  8326. (and idlwave-path-alist (not idlwave-catalog-process))]
  8327. "--"
  8328. "Routine Shadows"
  8329. ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
  8330. ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
  8331. ["Check Everything" idlwave-list-all-load-path-shadows t])
  8332. ("Misc"
  8333. ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
  8334. "--"
  8335. ["Insert TAB character" idlwave-hard-tab t])
  8336. "--"
  8337. ("External"
  8338. ["Start IDL shell" idlwave-shell t]
  8339. ["Edit file in IDLDE" idlwave-edit-in-idlde t]
  8340. ["Launch IDL Help" idlwave-launch-idlhelp t])
  8341. "--"
  8342. ("Customize"
  8343. ["Browse IDLWAVE Group" idlwave-customize t]
  8344. "--"
  8345. ["Build Full Customize Menu" idlwave-create-customize-menu
  8346. (fboundp 'customize-menu-create)])
  8347. ("Documentation"
  8348. ["Describe Mode" describe-mode t]
  8349. ["Abbreviation List" idlwave-list-abbrevs t]
  8350. "--"
  8351. ["Commentary in idlwave.el" idlwave-show-commentary t]
  8352. ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
  8353. "--"
  8354. ["Info" idlwave-info t]
  8355. "--"
  8356. ["Help with Topic" idlwave-help-assistant-help-with-topic
  8357. idlwave-help-use-assistant]
  8358. ["Launch IDL Help" idlwave-launch-idlhelp t])))
  8359. (defvar idlwave-mode-debug-menu-def
  8360. '("Debug"
  8361. ["Start IDL shell" idlwave-shell t]
  8362. ["Save and .RUN buffer" idlwave-shell-save-and-run
  8363. (and (boundp 'idlwave-shell-automatic-start)
  8364. idlwave-shell-automatic-start)]))
  8365. (if (or (featurep 'easymenu) (load "easymenu" t))
  8366. (progn
  8367. (easy-menu-define idlwave-mode-menu idlwave-mode-map
  8368. "IDL and WAVE CL editing menu"
  8369. idlwave-mode-menu-def)
  8370. (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
  8371. "IDL and WAVE CL editing menu"
  8372. idlwave-mode-debug-menu-def)))
  8373. (defun idlwave-customize ()
  8374. "Call the customize function with `idlwave' as argument."
  8375. (interactive)
  8376. ;; Try to load the code for the shell, so that we can customize it
  8377. ;; as well.
  8378. (or (featurep 'idlw-shell)
  8379. (load "idlw-shell" t))
  8380. (customize-browse 'idlwave))
  8381. (defun idlwave-create-customize-menu ()
  8382. "Create a full customization menu for IDLWAVE, insert it into the menu."
  8383. (interactive)
  8384. (if (fboundp 'customize-menu-create)
  8385. (progn
  8386. ;; Try to load the code for the shell, so that we can customize it
  8387. ;; as well.
  8388. (or (featurep 'idlw-shell)
  8389. (load "idlw-shell" t))
  8390. (easy-menu-change
  8391. '("IDLWAVE") "Customize"
  8392. `(["Browse IDLWAVE group" idlwave-customize t]
  8393. "--"
  8394. ,(customize-menu-create 'idlwave)
  8395. ["Set" Custom-set t]
  8396. ["Save" Custom-save t]
  8397. ["Reset to Current" Custom-reset-current t]
  8398. ["Reset to Saved" Custom-reset-saved t]
  8399. ["Reset to Standard Settings" Custom-reset-standard t]))
  8400. (message "\"IDLWAVE\"-menu now contains full customization menu"))
  8401. (error "Cannot expand menu (outdated version of cus-edit.el)")))
  8402. (defun idlwave-show-commentary ()
  8403. "Use the finder to view the file documentation from `idlwave.el'."
  8404. (interactive)
  8405. (finder-commentary "idlwave.el"))
  8406. (defun idlwave-shell-show-commentary ()
  8407. "Use the finder to view the file documentation from `idlw-shell.el'."
  8408. (interactive)
  8409. (finder-commentary "idlw-shell.el"))
  8410. (defun idlwave-info ()
  8411. "Read documentation for IDLWAVE in the info system."
  8412. (interactive)
  8413. (info "idlwave"))
  8414. (defun idlwave-list-abbrevs (arg)
  8415. "Show the code abbreviations define in IDLWAVE mode.
  8416. This lists all abbrevs where the replacement text differs from the input text.
  8417. These are the ones the users want to learn to speed up their writing.
  8418. The function does *not* list abbrevs which replace a word with itself
  8419. to call a hook. These hooks are used to change the case of words or
  8420. to blink the matching `begin', and the user does not need to know them.
  8421. With arg, list all abbrevs with the corresponding hook.
  8422. This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
  8423. (interactive "P")
  8424. (let ((table (symbol-value 'idlwave-mode-abbrev-table))
  8425. abbrevs
  8426. str rpl func fmt (len-str 0) (len-rpl 0))
  8427. (mapatoms
  8428. (lambda (sym)
  8429. (if (symbol-value sym)
  8430. (progn
  8431. (setq str (symbol-name sym)
  8432. rpl (symbol-value sym)
  8433. func (symbol-function sym))
  8434. (if arg
  8435. (setq func (prin1-to-string func))
  8436. (if (and (listp func) (stringp (nth 2 func)))
  8437. (setq rpl (concat "EVAL: " (nth 2 func))
  8438. func "")
  8439. (setq func "")))
  8440. (if (or arg (not (string= rpl str)))
  8441. (progn
  8442. (setq len-str (max len-str (length str)))
  8443. (setq len-rpl (max len-rpl (length rpl)))
  8444. (setq abbrevs (cons (list str rpl func) abbrevs)))))))
  8445. table)
  8446. ;; sort the list
  8447. (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
  8448. ;; Make the format
  8449. (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
  8450. (with-output-to-temp-buffer "*Help*"
  8451. (if arg
  8452. (progn
  8453. (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
  8454. (princ "=========================================\n\n")
  8455. (princ (format fmt "KEY" "REPLACE" "HOOK"))
  8456. (princ (format fmt "---" "-------" "----")))
  8457. (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
  8458. (princ "================================================\n\n")
  8459. (princ (format fmt "KEY" "ACTION" ""))
  8460. (princ (format fmt "---" "------" "")))
  8461. (dolist (list abbrevs)
  8462. (setq str (car list)
  8463. rpl (nth 1 list)
  8464. func (nth 2 list))
  8465. (princ (format fmt str rpl func)))))
  8466. ;; Make sure each abbreviation uses only one display line
  8467. (with-current-buffer "*Help*"
  8468. (setq truncate-lines t)))
  8469. (declare-function speedbar-add-supported-extension "speedbar" (extension))
  8470. ;; Add .pro files to speedbar for support, if it's loaded
  8471. (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
  8472. ;; Set an idle timer to load the routine info.
  8473. ;; Will only work on systems which support this.
  8474. (or idlwave-routines (idlwave-start-load-rinfo-timer))
  8475. ;; Run the hook
  8476. (run-hooks 'idlwave-load-hook)
  8477. (provide 'idlwave)
  8478. ;;; idlwave.el ends here