idlwave.el 341 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336
  1. ;; idlwave.el --- IDL editing mode for GNU Emacs
  2. ;; Copyright (C) 1999-2012 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://idlwave.org
  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 .emacs 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://idlwave.org
  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://idlwave.org")
  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. (convert-standard-filename "~/.idlwave")
  397. "*Directory for configuration files and user-library catalog."
  398. :group 'idlwave-routine-info
  399. :type 'file)
  400. (defvar idlwave-user-catalog-file "idlusercat.el")
  401. (defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
  402. (defvar idlwave-path-file "idlpath.el")
  403. (defvar idlwave-libinfo-file nil
  404. "*Obsolete variable, no longer used.")
  405. (defcustom idlwave-special-lib-alist nil
  406. "Alist of regular expressions matching special library directories.
  407. When listing routine source locations, IDLWAVE gives a short hint where
  408. the file defining the routine is located. By default it lists `SystemLib'
  409. for routines in the system library `!DIR/lib' and `Library' for anything
  410. else. This variable can define additional types. The car of each entry
  411. is a regular expression matching the file name (they normally will match
  412. on the path). The cdr is the string to be used as identifier. Max 10
  413. chars are allowed."
  414. :group 'idlwave-routine-info
  415. :type '(repeat
  416. (cons regexp string)))
  417. (defcustom idlwave-auto-write-paths t
  418. "Write out path (!PATH) and system directory (!DIR) info automatically.
  419. Path info is needed to locate library catalog files. If non-nil,
  420. whenever the path-list changes as a result of shell-query, etc., it is
  421. written to file. Otherwise, the menu option \"Write Paths\" can be
  422. used to force a write."
  423. :group 'idlwave-routine-info
  424. :type 'boolean)
  425. (defgroup idlwave-completion nil
  426. "Completion options for IDLWAVE mode."
  427. :prefix "idlwave"
  428. :group 'idlwave)
  429. (eval-and-compile
  430. (defconst idlwave-tmp
  431. '(choice :tag "by applying the function"
  432. (const upcase)
  433. (const downcase)
  434. (const capitalize)
  435. (const preserve)
  436. (symbol :tag "Other"))))
  437. (defcustom idlwave-completion-case '((routine . upcase)
  438. (keyword . upcase)
  439. (class . preserve)
  440. (method . preserve))
  441. "Association list setting the case of completed words.
  442. This variable determines the case (UPPER/lower/Capitalized...) of
  443. words inserted into the buffer by completion. The preferred case can
  444. be specified separately for routine names, keywords, classes and
  445. methods.
  446. This alist should therefore have entries for `routine' (normal
  447. functions and procedures, i.e. non-methods), `keyword', `class', and
  448. `method'. Plausible values are
  449. upcase upcase whole word, like `BOX_CURSOR'
  450. downcase downcase whole word, like `read_ppm'
  451. capitalize capitalize each part, like `Widget_Control'
  452. preserve preserve case as is, like `IDLgrView'
  453. The value can also be any Emacs Lisp function which transforms the
  454. case of characters in a string.
  455. A value of `preserve' means that the case of the completed word is
  456. identical to the way it was written in the definition statement of the
  457. routine. This was implemented to allow for mixed-case completion, in
  458. particular of object classes and methods.
  459. If a completable word is defined in multiple locations, the meaning of
  460. `preserve' is not unique since the different definitions might be
  461. cased differently. Therefore IDLWAVE always takes the case of the
  462. *first* definition it encounters during routine info collection and
  463. uses the case derived from it consistently.
  464. Note that a lowercase-only string in the buffer will always be completed in
  465. lower case (but see the variable `idlwave-completion-force-default-case').
  466. After changing this variable, you need to either restart Emacs or press
  467. `C-u C-c C-i' to update the internal lists."
  468. :group 'idlwave-completion
  469. :type `(repeat
  470. (cons (symbol :tag "Derive completion case for")
  471. ,idlwave-tmp)))
  472. (defcustom idlwave-completion-force-default-case nil
  473. "*Non-nil means, completion will always honor `idlwave-completion-case'.
  474. When nil, only the completion of a mixed case or upper case string
  475. will honor the default settings in `idlwave-completion-case', while
  476. the completion of lower case strings will be completed entirely in
  477. lower case."
  478. :group 'idlwave-completion
  479. :type 'boolean)
  480. (defcustom idlwave-complete-empty-string-as-lower-case nil
  481. "*Non-nil means, the empty string is considered downcase for completion.
  482. The case of what is already in the buffer determines the case of completions.
  483. When this variable is non-nil, the empty string is considered to be downcase.
  484. Completing on the empty string then offers downcase versions of the possible
  485. completions."
  486. :group 'idlwave-completion
  487. :type 'boolean)
  488. (defvar idlwave-default-completion-case-is-down nil
  489. "Obsolete variable. See `idlwave-complete-empty-string-as-lower-case' and
  490. `idlwave-completion-case'.")
  491. (defcustom idlwave-buffer-case-takes-precedence nil
  492. "*Non-nil means, the case of tokens in buffers dominates over system stuff.
  493. To make this possible, we need to re-case everything each time we update
  494. the routine info from the buffers. This is slow.
  495. The default is to consider the case given in the system and library files
  496. first which makes updating much faster."
  497. :group 'idlwave-completion
  498. :type 'boolean)
  499. (defcustom idlwave-highlight-help-links-in-completion t
  500. "*Non-nil means, highlight completions for which system help is available.
  501. Help can then be accessed with mouse-3.
  502. This option is only effective when the online help system is installed."
  503. :group 'idlwave-completion
  504. :type 'boolean)
  505. (defcustom idlwave-support-inheritance t
  506. "Non-nil means, treat inheritance with completion, online help etc.
  507. When nil, IDLWAVE only knows about the native methods and tags of a class,
  508. not about inherited ones."
  509. :group 'idlwave-routine-info
  510. :type 'boolean)
  511. (defcustom idlwave-keyword-class-inheritance '("^[gs]etproperty$" "^init$")
  512. "List of regular expressions for class-driven keyword inheritance.
  513. Keyword inheritance is often tied to class inheritance by \"chaining\"
  514. up the class tree. While it cannot be assumed that the presence of an
  515. _EXTRA or _REF_EXTRA symbol guarantees such chaining will occur, for
  516. certain methods this assumption is almost always true. The methods
  517. for which to assume this can be set here."
  518. :group 'idlwave-routine-info
  519. :type '(repeat (regexp :tag "Match method:")))
  520. (defcustom idlwave-completion-show-classes 1
  521. "*Number of classes to show when completing object methods and keywords.
  522. When completing methods or keywords for an object with unknown class,
  523. the *Completions* buffer will show the valid classes for each completion
  524. like this:
  525. MyMethod <Class1,Class2,Class3>
  526. The value of this variable may be nil to inhibit display, or an integer to
  527. indicate the maximum number of classes to display.
  528. On XEmacs, a full list of classes will also be placed into a `help-echo'
  529. property on the completion items, so that the list of classes for the current
  530. item is displayed in the echo area. If the value of this variable is a
  531. negative integer, the `help-echo' property will be suppressed."
  532. :group 'idlwave-completion
  533. :type '(choice (const :tag "Don't show" nil)
  534. (integer :tag "Number of classes shown" 1)))
  535. (defcustom idlwave-completion-fontify-classes t
  536. "*Non-nil means, fontify the classes in completions buffer.
  537. This makes it easier to distinguish the completion items from the extra
  538. class info listed. See `idlwave-completion-show-classes'."
  539. :group 'idlwave-completion
  540. :type 'boolean)
  541. (defcustom idlwave-query-class '((method-default . nil)
  542. (keyword-default . nil))
  543. "Association list governing specification of object classes for completion.
  544. When IDLWAVE tries to complete object-oriented methods, it usually
  545. cannot determine the class of a given object from context. In order
  546. to provide the user with a correct list of methods or keywords, it
  547. needs to determine the appropriate class. IDLWAVE has two ways of
  548. doing this (well, three ways if you count the shell... see
  549. `idlwave-shell-query-for-class'):
  550. 1. Combine the items of all available classes which contain this
  551. method for the purpose of completion. So when completing a method,
  552. all methods of all known classes are available, and when completing
  553. a keyword, all keywords allowed for this method in any class are
  554. shown. This behavior is very much like normal completion and is
  555. therefore the default. It works much better than one might think -
  556. only for the INIT, GETPROPERTY and SETPROPERTY the keyword lists
  557. become uncomfortably long. See also
  558. `idlwave-completion-show-classes'.
  559. 2. The second possibility is to ask the user on each occasion. To
  560. make this less interruptive, IDLWAVE can store the class as a text
  561. property on the object operator `->'. For a given object in the
  562. source code, class selection will then be needed only once
  563. - for example to complete the method. Keywords to the method can
  564. then be completed directly, because the class is already known.
  565. You will have to turn on the storage of the selected class
  566. explicitly with the variable `idlwave-store-inquired-class'.
  567. This variable allows you to configure IDLWAVE's method and
  568. method-keyword completion behavior. Its value is an alist, which
  569. should contain at least two elements: (method-default . VALUE) and
  570. \(keyword-default . VALUE), where VALUE is either t or nil. These
  571. specify if the class should be found during method and keyword
  572. completion, respectively.
  573. The alist may have additional entries specifying exceptions from the
  574. keyword completion rule for specific methods, like INIT or
  575. GETPROPERTY. In order to turn on class specification for the INIT
  576. method, add an entry (\"INIT\" . t). The method name must be ALL-CAPS."
  577. :group 'idlwave-completion
  578. :type '(list
  579. (cons (const method-default)
  580. (boolean :tag "Determine class when completing METHODS "))
  581. (cons (const keyword-default)
  582. (boolean :tag "Determine class when completing KEYWORDS "))
  583. (repeat
  584. :tag "Exceptions to defaults"
  585. :inline t
  586. (cons (string :tag "MODULE" :value "")
  587. (boolean :tag "Determine class for this method")))))
  588. (defcustom idlwave-store-inquired-class t
  589. "*Non-nil means, store class of a method call as text property on `->'.
  590. IDLWAVE sometimes has to ask the user for the class associated with a
  591. particular object method call. This happens during the commands
  592. `idlwave-routine-info' and `idlwave-complete', depending upon the
  593. value of the variable `idlwave-query-class'.
  594. When you specify a class, this information can be stored as a text
  595. property on the `->' arrow in the source code, so that during the same
  596. editing session, IDLWAVE will not have to ask again. When this
  597. variable is non-nil, IDLWAVE will store and reuse the class information.
  598. The class stored can be checked and removed with `\\[idlwave-routine-info]'
  599. on the arrow.
  600. The default of this variable is nil, since the result of commands then
  601. is more predictable. However, if you know what you are doing, it can
  602. be nice to turn this on.
  603. An arrow which knows the class will be highlighted with
  604. `idlwave-class-arrow-face'. The command \\[idlwave-routine-info]
  605. displays (with prefix arg: deletes) the class stored on the arrow
  606. at point."
  607. :group 'idlwave-completion
  608. :type 'boolean)
  609. (defcustom idlwave-class-arrow-face 'bold
  610. "*Face to highlight object operator arrows `->' which carry a class property.
  611. When IDLWAVE stores a class name as text property on an object arrow
  612. \(see variable `idlwave-store-inquired-class', it highlights the arrow
  613. with this font in order to remind the user that this arrow is special."
  614. :group 'idlwave-completion
  615. :type 'symbol)
  616. (defcustom idlwave-resize-routine-help-window t
  617. "*Non-nil means, resize the Routine-info *Help* window to fit the content."
  618. :group 'idlwave-completion
  619. :type 'boolean)
  620. (defcustom idlwave-keyword-completion-adds-equal t
  621. "*Non-nil means, completion automatically adds `=' after completed keywords."
  622. :group 'idlwave-completion
  623. :type 'boolean)
  624. (defcustom idlwave-function-completion-adds-paren t
  625. "*Non-nil means, completion automatically adds `(' after completed function.
  626. nil means, don't add anything.
  627. A value of `2' means, also add the closing parenthesis and position cursor
  628. between the two."
  629. :group 'idlwave-completion
  630. :type '(choice (const :tag "Nothing" nil)
  631. (const :tag "(" t)
  632. (const :tag "()" 2)))
  633. (defcustom idlwave-completion-restore-window-configuration t
  634. "*Non-nil means, try to restore the window configuration after completion.
  635. When completion is not unique, Emacs displays a list of completions.
  636. This messes up your window configuration. With this variable set, IDLWAVE
  637. restores the old configuration after successful completion."
  638. :group 'idlwave-completion
  639. :type 'boolean)
  640. ;;; Variables for abbrev and action behavior -----------------------------
  641. (defgroup idlwave-abbrev-and-indent-action nil
  642. "IDLWAVE performs actions when expanding abbreviations or indenting lines.
  643. The variables in this group govern this."
  644. :group 'idlwave)
  645. (defcustom idlwave-do-actions nil
  646. "*Non-nil means performs actions when indenting.
  647. The actions that can be performed are listed in `idlwave-indent-action-table'."
  648. :group 'idlwave-abbrev-and-indent-action
  649. :type 'boolean)
  650. (defcustom idlwave-abbrev-start-char "\\"
  651. "*A single character string used to start abbreviations in abbrev mode.
  652. Possible characters to chose from: ~`\%
  653. or even '?'. '.' is not a good choice because it can make structure
  654. field names act like abbrevs in certain circumstances.
  655. Changes to this in `idlwave-mode-hook' will have no effect. Instead a user
  656. must set it directly using `setq' in the .emacs file before idlwave.el
  657. is loaded."
  658. :group 'idlwave-abbrev-and-indent-action
  659. :type 'string)
  660. (defcustom idlwave-surround-by-blank nil
  661. "*Non-nil means, enable `idlwave-surround'.
  662. If non-nil, `=',`<',`>',`&',`,', `->' are surrounded with spaces by
  663. `idlwave-surround'.
  664. See help for `idlwave-indent-action-table' for symbols using `idlwave-surround'.
  665. Also see the default key bindings for keys using `idlwave-surround'.
  666. Keys are bound and made into actions calling `idlwave-surround' with
  667. `idlwave-action-and-binding'.
  668. See help for `idlwave-action-and-binding' for examples.
  669. Also see help for `idlwave-surround'."
  670. :group 'idlwave-abbrev-and-indent-action
  671. :type 'boolean)
  672. (defcustom idlwave-pad-keyword t
  673. "*Non-nil means pad '=' in keywords (routine calls or defs) like assignment.
  674. Whenever `idlwave-surround' is non-nil then this affects how '=' is
  675. padded for keywords and for variables. If t, pad the same as for
  676. assignments. If nil then spaces are removed. With any other value,
  677. spaces are left unchanged."
  678. :group 'idlwave-abbrev-and-indent-action
  679. :type '(choice
  680. (const :tag "Pad like assignments" t)
  681. (const :tag "Remove space near `='" nil)
  682. (const :tag "Keep space near `='" 'keep)))
  683. (defcustom idlwave-show-block t
  684. "*Non-nil means point blinks to block beginning for `idlwave-show-begin'."
  685. :group 'idlwave-abbrev-and-indent-action
  686. :type 'boolean)
  687. (defcustom idlwave-expand-generic-end nil
  688. "*Non-nil means expand generic END to ENDIF/ENDELSE/ENDWHILE etc."
  689. :group 'idlwave-abbrev-and-indent-action
  690. :type 'boolean)
  691. (defcustom idlwave-reindent-end t
  692. "*Non-nil means re-indent line after END was typed."
  693. :group 'idlwave-abbrev-and-indent-action
  694. :type 'boolean)
  695. (defcustom idlwave-abbrev-move t
  696. "*Non-nil means the abbrev hook can move point.
  697. Set to nil by `idlwave-expand-region-abbrevs'. To see the abbrev
  698. definitions, use the command `list-abbrevs', for abbrevs that move
  699. point. Moving point is useful, for example, to place point between
  700. parentheses of expanded functions.
  701. See `idlwave-check-abbrev'."
  702. :group 'idlwave-abbrev-and-indent-action
  703. :type 'boolean)
  704. (defcustom idlwave-abbrev-change-case nil
  705. "*Non-nil means all abbrevs will be forced to either upper or lower case.
  706. If the value t, all expanded abbrevs will be upper case.
  707. If the value is 'down then abbrevs will be forced to lower case.
  708. If nil, the case will not change.
  709. If `idlwave-reserved-word-upcase' is non-nil, reserved words will always be
  710. upper case, regardless of this variable."
  711. :group 'idlwave-abbrev-and-indent-action
  712. :type 'boolean)
  713. (defcustom idlwave-reserved-word-upcase nil
  714. "*Non-nil means, reserved words will be made upper case via abbrev expansion.
  715. If nil case of reserved words is controlled by `idlwave-abbrev-change-case'.
  716. Has effect only if in abbrev-mode."
  717. :group 'idlwave-abbrev-and-indent-action
  718. :type 'boolean)
  719. ;;; Action/Expand Tables.
  720. ;;
  721. ;; The average user may have difficulty modifying this directly. It
  722. ;; can be modified/set in idlwave-mode-hook, but it is easier to use
  723. ;; idlwave-action-and-binding. See help for idlwave-action-and-binding for
  724. ;; examples of how to add an action.
  725. ;;
  726. ;; The action table is used by `idlwave-indent-line' whereas both the
  727. ;; action and expand tables are used by `idlwave-indent-and-action'. In
  728. ;; general, the expand table is only used when a line is explicitly
  729. ;; indented. Whereas, in addition to being used when the expand table
  730. ;; is used, the action table is used when a line is indirectly
  731. ;; indented via line splitting, auto-filling or a new line creation.
  732. ;;
  733. ;; Example actions:
  734. ;;
  735. ;; Capitalize system vars
  736. ;; (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)
  737. ;;
  738. ;; Capitalize procedure name
  739. ;; (idlwave-action-and-binding "\\<\\(pro\\|function\\)\\>[ \t]*\\<"
  740. ;; '(capitalize-word 1) t)
  741. ;;
  742. ;; Capitalize common block name
  743. ;; (idlwave-action-and-binding "\\<common\\>[ \t]+\\<"
  744. ;; '(capitalize-word 1) t)
  745. ;; Capitalize label
  746. ;; (idlwave-action-and-binding (concat "^[ \t]*" idlwave-label)
  747. ;; '(capitalize-word -1) t)
  748. (defvar idlwave-indent-action-table nil
  749. "*Associated array containing action lists of search string (car),
  750. and function as a cdr. This table is used by `idlwave-indent-line'.
  751. See documentation for `idlwave-do-action' for a complete description of
  752. the action lists.
  753. Additions to the table are made with `idlwave-action-and-binding' when a
  754. binding is not requested.
  755. See help on `idlwave-action-and-binding' for examples.")
  756. (defvar idlwave-indent-expand-table nil
  757. "*Associated array containing action lists of search string (car),
  758. and function as a cdr. The table is used by the
  759. `idlwave-indent-and-action' function. See documentation for
  760. `idlwave-do-action' for a complete description of the action lists.
  761. Additions to the table are made with `idlwave-action-and-binding' when a
  762. binding is requested.
  763. See help on `idlwave-action-and-binding' for examples.")
  764. ;;; Documentation header and history keyword ---------------------------------
  765. (defgroup idlwave-documentation nil
  766. "Options for documenting IDLWAVE files."
  767. :group 'idlwave)
  768. ;; FIXME: make defcustom?
  769. (defvar idlwave-file-header
  770. (list nil
  771. ";+
  772. ; NAME:
  773. ;
  774. ;
  775. ;
  776. ; PURPOSE:
  777. ;
  778. ;
  779. ;
  780. ; CATEGORY:
  781. ;
  782. ;
  783. ;
  784. ; CALLING SEQUENCE:
  785. ;
  786. ;
  787. ;
  788. ; INPUTS:
  789. ;
  790. ;
  791. ;
  792. ; OPTIONAL INPUTS:
  793. ;
  794. ;
  795. ;
  796. ; KEYWORD PARAMETERS:
  797. ;
  798. ;
  799. ;
  800. ; OUTPUTS:
  801. ;
  802. ;
  803. ;
  804. ; OPTIONAL OUTPUTS:
  805. ;
  806. ;
  807. ;
  808. ; COMMON BLOCKS:
  809. ;
  810. ;
  811. ;
  812. ; SIDE EFFECTS:
  813. ;
  814. ;
  815. ;
  816. ; RESTRICTIONS:
  817. ;
  818. ;
  819. ;
  820. ; PROCEDURE:
  821. ;
  822. ;
  823. ;
  824. ; EXAMPLE:
  825. ;
  826. ;
  827. ;
  828. ; MODIFICATION HISTORY:
  829. ;
  830. ;-
  831. ")
  832. "*A list (PATHNAME STRING) specifying the doc-header template to use for
  833. summarizing a file. If PATHNAME is non-nil then this file will be included.
  834. Otherwise STRING is used. If nil, the file summary will be omitted.
  835. For example you might set PATHNAME to the path for the
  836. lib_template.pro file included in the IDL distribution.")
  837. (defcustom idlwave-header-to-beginning-of-file t
  838. "*Non-nil means, the documentation header will always be at start of file.
  839. When nil, the header is positioned between the PRO/FUNCTION line of
  840. the current routine and the code, allowing several routine headers in
  841. a file."
  842. :group 'idlwave-documentation
  843. :type 'boolean)
  844. (defcustom idlwave-timestamp-hook 'idlwave-default-insert-timestamp
  845. "*The hook function used to update the timestamp of a function."
  846. :group 'idlwave-documentation
  847. :type 'function)
  848. (defcustom idlwave-doc-modifications-keyword "HISTORY"
  849. "*The modifications keyword to use with the log documentation commands.
  850. A ':' is added to the keyword end.
  851. Inserted by doc-header and used to position logs by doc-modification.
  852. If nil it will not be inserted."
  853. :group 'idlwave-documentation
  854. :type 'string)
  855. (defcustom idlwave-doclib-start "^;+\\+"
  856. "*Regexp matching the start of a document library header."
  857. :group 'idlwave-documentation
  858. :type 'regexp)
  859. (defcustom idlwave-doclib-end "^;+-"
  860. "*Regexp matching the end of a document library header."
  861. :group 'idlwave-documentation
  862. :type 'regexp)
  863. ;;; External Programs -------------------------------------------------------
  864. (defgroup idlwave-external-programs nil
  865. "Path locations of external commands used by IDLWAVE."
  866. :group 'idlwave)
  867. (defcustom idlwave-shell-explicit-file-name "idl"
  868. "*If non-nil, this is the command to run IDL.
  869. Should be an absolute file path or path relative to the current environment
  870. execution search path. If you want to specify command line switches
  871. for the IDL program, use `idlwave-shell-command-line-options'.
  872. I know the name of this variable is badly chosen, but I cannot change
  873. it without compromising backwards-compatibility."
  874. :group 'idlwave-external-programs
  875. :type 'string)
  876. (defcustom idlwave-shell-command-line-options nil
  877. "*A list of command line options for calling the IDL program.
  878. Since IDL is executed directly without going through a shell like /bin/sh,
  879. this should be a list of strings like '(\"-rt=file\" \"-nw\") with a separate
  880. string for each argument. But you may also give a single string which
  881. contains the options whitespace-separated. Emacs will be kind enough to
  882. split it for you."
  883. :type '(choice
  884. string
  885. (repeat (string :value "")))
  886. :group 'idlwave-external-programs)
  887. (defcustom idlwave-help-application "idlhelp"
  888. "*The external application providing reference help for programming.
  889. Obsolete, if the IDL Assistant is being used for help."
  890. :group 'idlwave-external-programs
  891. :type 'string)
  892. ;;; Some Shell variables which must be defined here.-----------------------
  893. (defcustom idlwave-shell-debug-modifiers '()
  894. "List of modifiers to be used for the debugging commands.
  895. Will be used to bind debugging commands in the shell buffer and in all
  896. source buffers. These are additional convenience bindings, the debugging
  897. commands are always available with the `C-c C-d' prefix.
  898. If you set this to '(control shift), this means setting a breakpoint will
  899. be on `C-S-b', compiling a source file on `C-S-c' etc. Possible modifiers
  900. are `control', `meta', `super', `hyper', `alt', and `shift'."
  901. :group 'idlwave-shell-general-setup
  902. :type '(set :tag "Specify modifiers"
  903. (const control)
  904. (const meta)
  905. (const super)
  906. (const hyper)
  907. (const alt)
  908. (const shift)))
  909. (defcustom idlwave-shell-automatic-start nil
  910. "*If non-nil attempt invoke `idlwave-shell' if not already running.
  911. This is checked when an attempt to send a command to an
  912. IDL process is made."
  913. :group 'idlwave-shell-general-setup
  914. :type 'boolean)
  915. ;;; Miscellaneous variables -------------------------------------------------
  916. (defgroup idlwave-misc nil
  917. "Miscellaneous options for IDLWAVE mode."
  918. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  919. :group 'idlwave)
  920. (defcustom idlwave-startup-message t
  921. "*Non-nil displays a startup message when `idlwave-mode' is first called."
  922. :group 'idlwave-misc
  923. :type 'boolean)
  924. (defcustom idlwave-default-font-lock-items
  925. '(pros-and-functions batch-files idlwave-idl-keywords label goto
  926. common-blocks class-arrows)
  927. "Items which should be fontified on the default fontification level 2.
  928. IDLWAVE defines 3 levels of fontification. Level 1 is very little, level 3
  929. is everything and level 2 is specified by this list.
  930. This variable must be set before IDLWAVE gets loaded.
  931. It is a list of symbols; the following symbols are allowed:
  932. pros-and-functions Procedure and Function definitions
  933. batch-files Batch Files
  934. idlwave-idl-keywords IDL Keywords
  935. label Statement Labels
  936. goto Goto Statements
  937. common-blocks Common Blocks
  938. keyword-parameters Keyword Parameters in routine definitions and calls
  939. system-variables System Variables
  940. fixme FIXME: Warning in comments (on XEmacs only v. 21.0 and up)
  941. class-arrows Object Arrows with class property"
  942. :group 'idlwave-misc
  943. :type '(set
  944. :inline t :greedy t
  945. (const :tag "Procedure and Function definitions" pros-and-functions)
  946. (const :tag "Batch Files" batch-files)
  947. (const :tag "IDL Keywords (reserved words)" idlwave-idl-keywords)
  948. (const :tag "Statement Labels" label)
  949. (const :tag "Goto Statements" goto)
  950. (const :tag "Tags in Structure Definition" structtag)
  951. (const :tag "Structure Name" structname)
  952. (const :tag "Common Blocks" common-blocks)
  953. (const :tag "Keyword Parameters" keyword-parameters)
  954. (const :tag "System Variables" system-variables)
  955. (const :tag "FIXME: Warning" fixme)
  956. (const :tag "Object Arrows with class property " class-arrows)))
  957. (defcustom idlwave-mode-hook nil
  958. "Normal hook. Executed when a buffer is put into `idlwave-mode'."
  959. :group 'idlwave-misc
  960. :type 'hook)
  961. (defcustom idlwave-load-hook nil
  962. "Normal hook. Executed when idlwave.el is loaded."
  963. :group 'idlwave-misc
  964. :type 'hook)
  965. (defvar idlwave-experimental nil
  966. "Non-nil means turn on a few experimental features.
  967. This variable is only for the maintainer, to test difficult stuff,
  968. while still distributing stable releases.
  969. As a user, you should not set this to t.")
  970. ;;;
  971. ;;; End customization variables section
  972. ;;;
  973. ;;; Non customization variables
  974. ;;; font-lock mode - Additions by Phil Williams, Ulrik Dickow and
  975. ;;; Simon Marshall <simon_at_gnu.ai.mit.edu>
  976. ;;; and Carsten Dominik...
  977. ;; The following are the reserved words in IDL. Maybe we should
  978. ;; highlight some more stuff as well?
  979. ;; Procedure declarations. Fontify keyword plus procedure name.
  980. (defvar idlwave-idl-keywords
  981. ;; To update this regexp, update the list of keywords and
  982. ;; evaluate the form.
  983. ;; (insert
  984. ;; (prin1-to-string
  985. ;; (concat
  986. ;; "\\<\\("
  987. ;; (regexp-opt
  988. ;; '("||" "&&" "and" "or" "xor" "not"
  989. ;; "eq" "ge" "gt" "le" "lt" "ne"
  990. ;; "for" "do" "endfor"
  991. ;; "if" "then" "endif" "else" "endelse"
  992. ;; "case" "of" "endcase"
  993. ;; "switch" "break" "continue" "endswitch"
  994. ;; "begin" "end"
  995. ;; "repeat" "until" "endrep"
  996. ;; "while" "endwhile"
  997. ;; "goto" "return"
  998. ;; "inherits" "mod"
  999. ;; "compile_opt" "forward_function"
  1000. ;; "on_error" "on_ioerror")) ; on_error is not officially reserved
  1001. ;; "\\)\\>")))
  1002. "\\<\\(&&\\|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\\|||\\)\\>")
  1003. (let* (;; Procedure declarations. Fontify keyword plus procedure name.
  1004. ;; Function declarations. Fontify keyword plus function name.
  1005. (pros-and-functions
  1006. '("\\<\\(function\\|pro\\)\\>[ \t]+\\(\\sw+\\(::\\sw+\\)?\\)"
  1007. (1 font-lock-keyword-face)
  1008. (2 font-lock-function-name-face nil t)))
  1009. ;; Common blocks
  1010. (common-blocks
  1011. '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
  1012. (1 font-lock-keyword-face) ; "common"
  1013. (2 font-lock-reference-face nil t) ; block name
  1014. ("[ \t]*\\(\\sw+\\)[ ,]*"
  1015. ;; Start with point after block name and comma
  1016. (goto-char (match-end 0)) ; needed for XEmacs, could be nil
  1017. nil
  1018. (1 font-lock-variable-name-face) ; variable names
  1019. )))
  1020. ;; Batch files
  1021. (batch-files
  1022. '("^[ \t]*\\(@[^ \t\n]+\\)" (1 font-lock-string-face)))
  1023. ;; FIXME warning.
  1024. (fixme
  1025. '("\\<FIXME:" (0 font-lock-warning-face t)))
  1026. ;; Labels
  1027. (label
  1028. '("^[ \t]*\\([a-zA-Z]\\sw*:\\)" (1 font-lock-reference-face)))
  1029. ;; The goto statement and its label
  1030. (goto
  1031. '("\\(goto\\)[ \t]*,[ \t]*\\([a-zA-Z]\\sw*\\)"
  1032. (1 font-lock-keyword-face)
  1033. (2 font-lock-reference-face)))
  1034. ;; Tags in structure definitions. Note that this definition
  1035. ;; actually collides with labels, so we have to use the same
  1036. ;; face. It also matches named subscript ranges,
  1037. ;; e.g. vec{bottom:top]. No good way around this.
  1038. (structtag
  1039. '("\\<\\([a-zA-Z][a-zA-Z0-9_]*:\\)[^:]" (1 font-lock-reference-face)))
  1040. ;; Structure names
  1041. (structname
  1042. '("\\({\\|\\<inherits\\s-\\)\\s-*\\([a-zA-Z][a-zA-Z0-9_]*\\)[},\t \n]"
  1043. (2 font-lock-function-name-face)))
  1044. ;; Keyword parameters, like /xlog or ,xrange=[]
  1045. ;; This is anchored to the comma preceding the keyword.
  1046. ;; Treats continuation lines, works only during whole buffer
  1047. ;; fontification. Slow, use it only in fancy fontification.
  1048. (keyword-parameters
  1049. '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
  1050. (6 font-lock-reference-face)))
  1051. ;; System variables start with a bang.
  1052. (system-variables
  1053. '("\\(![a-zA-Z_0-9]+\\(\\.\\sw+\\)?\\)"
  1054. (1 font-lock-variable-name-face)))
  1055. ;; Special and unusual operators (not used because too noisy)
  1056. ;; (special-operators
  1057. ;; '("[<>#]" (0 font-lock-keyword-face)))
  1058. ;; All operators (not used because too noisy)
  1059. ;; (all-operators
  1060. ;; '("[-*^#+<>/]" (0 font-lock-keyword-face)))
  1061. ;; Arrows with text property `idlwave-class'
  1062. (class-arrows
  1063. '(idlwave-match-class-arrows (0 idlwave-class-arrow-face))))
  1064. (defconst idlwave-font-lock-keywords-1
  1065. (list pros-and-functions batch-files)
  1066. "Subdued level highlighting for IDLWAVE mode.")
  1067. (defconst idlwave-font-lock-keywords-2
  1068. (mapcar 'symbol-value idlwave-default-font-lock-items)
  1069. "Medium level highlighting for IDLWAVE mode.")
  1070. (defconst idlwave-font-lock-keywords-3
  1071. (list pros-and-functions
  1072. batch-files
  1073. idlwave-idl-keywords
  1074. label goto
  1075. structtag
  1076. structname
  1077. common-blocks
  1078. keyword-parameters
  1079. system-variables
  1080. class-arrows)
  1081. "Gaudy level highlighting for IDLWAVE mode."))
  1082. (defun idlwave-match-class-arrows (limit)
  1083. ;; Match an object arrow with class property
  1084. (and idlwave-store-inquired-class
  1085. (re-search-forward "->" limit 'limit)
  1086. (get-text-property (match-beginning 0) 'idlwave-class)))
  1087. (defvar idlwave-font-lock-keywords idlwave-font-lock-keywords-2
  1088. "Default expressions to highlight in IDLWAVE mode.")
  1089. (defvar idlwave-font-lock-defaults
  1090. '((idlwave-font-lock-keywords
  1091. idlwave-font-lock-keywords-1
  1092. idlwave-font-lock-keywords-2
  1093. idlwave-font-lock-keywords-3)
  1094. nil t
  1095. ((?$ . "w") (?_ . "w") (?. . "w") (?| . "w") (?& . "w"))
  1096. beginning-of-line))
  1097. (put 'idlwave-mode 'font-lock-defaults
  1098. idlwave-font-lock-defaults) ; XEmacs
  1099. (defconst idlwave-comment-line-start-skip "^[ \t]*;"
  1100. "Regexp to match the start of a full-line comment.
  1101. That is the _beginning_ of a line containing a comment delimiter `;' preceded
  1102. only by whitespace.")
  1103. (defconst idlwave-begin-block-reg
  1104. "\\<\\(pro\\|function\\|begin\\|case\\|switch\\)\\>"
  1105. "Regular expression to find the beginning of a block.
  1106. The case does not matter. The search skips matches in comments.")
  1107. (defconst idlwave-begin-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\`"
  1108. "Regular expression to find the beginning of a unit.
  1109. The case does not matter.")
  1110. (defconst idlwave-end-unit-reg "^\\s-*\\(pro\\|function\\)\\>\\|\\'"
  1111. "Regular expression to find the line that indicates the end of unit.
  1112. This line is the end of buffer or the start of another unit.
  1113. The case does not matter. The search skips matches in comments.")
  1114. (defconst idlwave-continue-line-reg "\\<\\$"
  1115. "Regular expression to match a continued line.")
  1116. (defconst idlwave-end-block-reg
  1117. "\\<end\\(\\|case\\|switch\\|else\\|for\\|if\\|rep\\|while\\)\\>"
  1118. "Regular expression to find the end of a block.
  1119. The case does not matter. The search skips matches in comments.")
  1120. (defconst idlwave-block-matches
  1121. '(("pro" . "end")
  1122. ("function" . "end")
  1123. ("case" . "endcase")
  1124. ("else" . "endelse")
  1125. ("for" . "endfor")
  1126. ("then" . "endif")
  1127. ("repeat" . "endrep")
  1128. ("switch" . "endswitch")
  1129. ("while" . "endwhile"))
  1130. "Matches between statements and the corresponding END variant.
  1131. The cars are the reserved words starting a block. If the block really
  1132. begins with BEGIN, the cars are the reserved words before the begin
  1133. which can be used to identify the block type.
  1134. This is used to check for the correct END type, to close blocks and
  1135. to expand generic end statements to their detailed form.")
  1136. (defconst idlwave-block-match-regexp
  1137. "\\<\\(else\\|for\\|then\\|repeat\\|while\\)\\>"
  1138. "Regular expression matching reserved words which can stand before
  1139. blocks starting with a BEGIN statement. The matches must have associations
  1140. `idlwave-block-matches'.")
  1141. (defconst idlwave-identifier "[a-zA-Z_][a-zA-Z0-9$_]*"
  1142. "Regular expression matching an IDL identifier.")
  1143. (defconst idlwave-sysvar (concat "!" idlwave-identifier)
  1144. "Regular expression matching IDL system variables.")
  1145. (defconst idlwave-variable (concat idlwave-identifier "\\|" idlwave-sysvar)
  1146. "Regular expression matching IDL variable names.")
  1147. (defconst idlwave-label (concat idlwave-identifier ":")
  1148. "Regular expression matching IDL labels.")
  1149. (defconst idlwave-method-call (concat idlwave-identifier "\\s *->"
  1150. "\\(\\s *" idlwave-identifier "::\\)?"
  1151. ))
  1152. (defconst idlwave-statement-match
  1153. (list
  1154. ;; "endif else" is the only possible "end" that can be
  1155. ;; followed by a statement on the same line.
  1156. '(endelse . ("end\\(\\|if\\)\\s +else" "end\\(\\|if\\)\\s +else"))
  1157. ;; all other "end"s can not be followed by a statement.
  1158. (cons 'end (list idlwave-end-block-reg nil))
  1159. '(if . ("if\\>" "then"))
  1160. '(for . ("for\\>" "do"))
  1161. '(begin . ("begin\\>" nil))
  1162. '(pdef . ("pro\\>\\|function\\>" nil))
  1163. '(while . ("while\\>" "do"))
  1164. '(repeat . ("repeat\\>" "repeat"))
  1165. '(goto . ("goto\\>" nil))
  1166. '(case . ("case\\>" nil))
  1167. '(switch . ("switch\\>" nil))
  1168. (cons 'call (list (concat "\\(" idlwave-variable "\\) *= *"
  1169. "\\(" idlwave-method-call "\\s *\\)?"
  1170. idlwave-identifier
  1171. "\\s *(") nil))
  1172. (cons 'call (list (concat
  1173. "\\(" idlwave-method-call "\\s *\\)?"
  1174. idlwave-identifier
  1175. "\\( *\\($\\|\\$\\)\\|\\s *,\\)") nil))
  1176. (cons 'assign (list (concat
  1177. "\\(" idlwave-variable "\\) *=") nil)))
  1178. "Associated list of statement matching regular expressions.
  1179. Each regular expression matches the start of an IDL statement.
  1180. The first element of each association is a symbol giving the statement
  1181. type. The associated value is a list. The first element of this list
  1182. is a regular expression matching the start of an IDL statement for
  1183. identifying the statement type. The second element of this list is a
  1184. regular expression for finding a substatement for the type. The
  1185. substatement starts after the end of the found match modulo
  1186. whitespace. If it is nil then the statement has no substatement. The
  1187. list order matters since matching an assignment statement exactly is
  1188. not possible without parsing. Thus assignment statement become just
  1189. the leftover unidentified statements containing an equal sign.")
  1190. ;; FIXME: This var seems to only ever be set, but never actually used!
  1191. (defvar idlwave-fill-function 'auto-fill-function
  1192. "IDL mode auto fill function.")
  1193. (defvar idlwave-comment-indent-function 'comment-indent-function
  1194. "IDL mode comment indent function.")
  1195. ;; Note that this is documented in the v18 manuals as being a string
  1196. ;; of length one rather than a single character.
  1197. ;; The code in this file accepts either format for compatibility.
  1198. (defvar idlwave-comment-indent-char ?\
  1199. "Character to be inserted for IDL comment indentation.
  1200. Normally a space.")
  1201. (defconst idlwave-continuation-char ?$
  1202. "Character which is inserted as a last character on previous line by
  1203. \\[idlwave-split-line] to begin a continuation line. Normally $.")
  1204. (defconst idlwave-mode-version "6.1_em22")
  1205. (defmacro idlwave-keyword-abbrev (&rest args)
  1206. "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
  1207. `(quote (lambda ()
  1208. ,(append '(idlwave-check-abbrev) args))))
  1209. ;; If I take the time I can replace idlwave-keyword-abbrev with
  1210. ;; idlwave-code-abbrev and remove the quoted abbrev check from
  1211. ;; idlwave-check-abbrev. Then, e.g, (idlwave-keyword-abbrev 0 t) becomes
  1212. ;; (idlwave-code-abbrev idlwave-check-abbrev 0 t). In fact I should change
  1213. ;; the name of idlwave-check-abbrev to something like idlwave-modify-abbrev.
  1214. (defmacro idlwave-code-abbrev (&rest args)
  1215. "Creates a function for abbrev hooks that ensures abbrevs are not quoted.
  1216. Specifically, if the abbrev is in a comment or string it is unexpanded.
  1217. Otherwise ARGS forms a list that is evaluated."
  1218. ;; FIXME: it would probably be better to rely on the new :enable-function
  1219. ;; to enforce the "don't expand in comments or strings".
  1220. `(lambda ()
  1221. ,(prin1-to-string args) ;; Puts the code in the doc string
  1222. (if (idlwave-quoted)
  1223. (progn (unexpand-abbrev) nil)
  1224. ,(append args))))
  1225. (autoload 'idlwave-shell "idlw-shell"
  1226. "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'." t)
  1227. (autoload 'idlwave-shell-send-command "idlw-shell")
  1228. (autoload 'idlwave-shell-recenter-shell-window "idlw-shell"
  1229. "Run `idlwave-shell' and switch back to current window" t)
  1230. (autoload 'idlwave-shell-save-and-run "idlw-shell"
  1231. "Save and run buffer under the shell." t)
  1232. (autoload 'idlwave-shell-break-here "idlw-shell"
  1233. "Set breakpoint in current line." t)
  1234. (autoload 'idlwave-shell-run-region "idlw-shell"
  1235. "Compile and run the region." t)
  1236. (fset 'idlwave-debug-map (make-sparse-keymap))
  1237. (defvar idlwave-mode-map
  1238. (let ((map (make-sparse-keymap)))
  1239. (define-key map "\C-c " 'idlwave-hard-tab)
  1240. (define-key map [(control tab)] 'idlwave-hard-tab)
  1241. ;;(define-key map "\C-c\C- " 'idlwave-hard-tab)
  1242. (define-key map "'" 'idlwave-show-matching-quote)
  1243. (define-key map "\"" 'idlwave-show-matching-quote)
  1244. (define-key map "\C-g" 'idlwave-keyboard-quit)
  1245. (define-key map "\C-c;" 'idlwave-toggle-comment-region)
  1246. (define-key map "\C-\M-a" 'idlwave-beginning-of-subprogram)
  1247. (define-key map "\C-\M-e" 'idlwave-end-of-subprogram)
  1248. (define-key map "\C-c{" 'idlwave-beginning-of-block)
  1249. (define-key map "\C-c}" 'idlwave-end-of-block)
  1250. (define-key map "\C-c]" 'idlwave-close-block)
  1251. (define-key map [(meta control h)] 'idlwave-mark-subprogram)
  1252. (define-key map "\M-\C-n" 'idlwave-forward-block)
  1253. (define-key map "\M-\C-p" 'idlwave-backward-block)
  1254. (define-key map "\M-\C-d" 'idlwave-down-block)
  1255. (define-key map "\M-\C-u" 'idlwave-backward-up-block)
  1256. (define-key map "\M-\r" 'idlwave-split-line)
  1257. (define-key map "\M-\C-q" 'idlwave-indent-subprogram)
  1258. (define-key map "\C-c\C-p" 'idlwave-previous-statement)
  1259. (define-key map "\C-c\C-n" 'idlwave-next-statement)
  1260. ;; (define-key map "\r" 'idlwave-newline)
  1261. ;; (define-key map "\t" 'idlwave-indent-line)
  1262. (define-key map [(shift iso-lefttab)] 'idlwave-indent-statement)
  1263. (define-key map "\C-c\C-a" 'idlwave-auto-fill-mode)
  1264. (define-key map "\M-q" 'idlwave-fill-paragraph)
  1265. (define-key map "\M-s" 'idlwave-edit-in-idlde)
  1266. (define-key map "\C-c\C-h" 'idlwave-doc-header)
  1267. (define-key map "\C-c\C-m" 'idlwave-doc-modification)
  1268. (define-key map "\C-c\C-c" 'idlwave-case)
  1269. (define-key map "\C-c\C-d" 'idlwave-debug-map)
  1270. (when (and (listp idlwave-shell-debug-modifiers)
  1271. (not (equal idlwave-shell-debug-modifiers '())))
  1272. ;; Bind the debug commands also with the special modifiers.
  1273. (let ((shift (memq 'shift idlwave-shell-debug-modifiers))
  1274. (mods-noshift
  1275. (delq 'shift (copy-sequence idlwave-shell-debug-modifiers))))
  1276. (define-key map
  1277. (vector (append mods-noshift (list (if shift ?C ?c))))
  1278. 'idlwave-shell-save-and-run)
  1279. (define-key map
  1280. (vector (append mods-noshift (list (if shift ?B ?b))))
  1281. 'idlwave-shell-break-here)
  1282. (define-key map
  1283. (vector (append mods-noshift (list (if shift ?E ?e))))
  1284. 'idlwave-shell-run-region)))
  1285. (define-key map "\C-c\C-d\C-c" 'idlwave-shell-save-and-run)
  1286. (define-key map "\C-c\C-d\C-b" 'idlwave-shell-break-here)
  1287. (define-key map "\C-c\C-d\C-e" 'idlwave-shell-run-region)
  1288. (define-key map "\C-c\C-f" 'idlwave-for)
  1289. ;; (define-key map "\C-c\C-f" 'idlwave-function)
  1290. ;; (define-key map "\C-c\C-p" 'idlwave-procedure)
  1291. (define-key map "\C-c\C-r" 'idlwave-repeat)
  1292. (define-key map "\C-c\C-w" 'idlwave-while)
  1293. (define-key map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
  1294. (define-key map "\C-c\C-s" 'idlwave-shell)
  1295. (define-key map "\C-c\C-l" 'idlwave-shell-recenter-shell-window)
  1296. (define-key map "\C-c\C-b" 'idlwave-list-buffer-load-path-shadows)
  1297. (define-key map "\C-c\C-v" 'idlwave-find-module)
  1298. (define-key map "\C-c\C-t" 'idlwave-find-module-this-file)
  1299. (define-key map "\C-c?" 'idlwave-routine-info)
  1300. (define-key map "\M-?" 'idlwave-context-help)
  1301. (define-key map [(control meta ?\?)]
  1302. 'idlwave-help-assistant-help-with-topic)
  1303. ;; Pickup both forms of Esc/Meta binding
  1304. (define-key map [(meta tab)] 'idlwave-complete)
  1305. (define-key map [?\e?\t] 'idlwave-complete)
  1306. (define-key map "\M-\C-i" 'idlwave-complete)
  1307. (define-key map "\C-c\C-i" 'idlwave-update-routine-info)
  1308. (define-key map "\C-c=" 'idlwave-resolve)
  1309. (define-key map
  1310. (if (featurep 'xemacs) [(shift button3)] [(shift mouse-3)])
  1311. 'idlwave-mouse-context-help)
  1312. map)
  1313. "Keymap used in IDL mode.")
  1314. (defvar idlwave-mode-syntax-table
  1315. (let ((st (make-syntax-table)))
  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 ?} "){" st)
  1332. (modify-syntax-entry ?$ "_" st)
  1333. (modify-syntax-entry ?. "." st)
  1334. (modify-syntax-entry ?\; "<" st)
  1335. (modify-syntax-entry ?\n ">" st)
  1336. (modify-syntax-entry ?\f ">" st)
  1337. st)
  1338. "Syntax table in use in `idlwave-mode' buffers.")
  1339. (defvar idlwave-find-symbol-syntax-table
  1340. (let ((st (copy-syntax-table idlwave-mode-syntax-table)))
  1341. (modify-syntax-entry ?$ "w" st)
  1342. (modify-syntax-entry ?_ "w" st)
  1343. (modify-syntax-entry ?! "w" st)
  1344. (modify-syntax-entry ?. "w" st)
  1345. st)
  1346. "Syntax table that treats symbol characters as word characters.")
  1347. (defmacro idlwave-with-special-syntax (&rest body)
  1348. "Execute BODY with a different syntax table."
  1349. `(let ((saved-syntax (syntax-table)))
  1350. (unwind-protect
  1351. (progn
  1352. (set-syntax-table idlwave-find-symbol-syntax-table)
  1353. ,@body)
  1354. (set-syntax-table saved-syntax))))
  1355. ;(defmacro idlwave-with-special-syntax1 (&rest body)
  1356. ; "Execute BODY with a different syntax table."
  1357. ; `(let ((saved-syntax (syntax-table)))
  1358. ; (unwind-protect
  1359. ; (progn
  1360. ; (set-syntax-table idlwave-find-symbol-syntax-table)
  1361. ; ,@body)
  1362. ; (set-syntax-table saved-syntax))))
  1363. (defun idlwave-action-and-binding (key cmd &optional select)
  1364. "KEY and CMD are made into a key binding and an indent action.
  1365. KEY is a string - same as for the `define-key' function. CMD is a
  1366. function of no arguments or a list to be evaluated. CMD is bound to
  1367. KEY in `idlwave-mode-map' by defining an anonymous function calling
  1368. `self-insert-command' followed by CMD. If KEY contains more than one
  1369. character a binding will only be set if SELECT is 'both.
  1370. \(KEY . CMD\) is also placed in the `idlwave-indent-expand-table',
  1371. replacing any previous value for KEY. If a binding is not set then it
  1372. will instead be placed in `idlwave-indent-action-table'.
  1373. If the optional argument SELECT is nil then an action and binding are
  1374. created. If SELECT is 'noaction, then a binding is always set and no
  1375. action is created. If SELECT is 'both then an action and binding
  1376. will both be created even if KEY contains more than one character.
  1377. Otherwise, if SELECT is non-nil then only an action is created.
  1378. Some examples:
  1379. No spaces before and 1 after a comma
  1380. (idlwave-action-and-binding \",\" '(idlwave-surround 0 1))
  1381. A minimum of 1 space before and after `=' (see `idlwave-expand-equal').
  1382. (idlwave-action-and-binding \"=\" '(idlwave-expand-equal -1 -1))
  1383. Capitalize system variables - action only
  1384. (idlwave-action-and-binding idlwave-sysvar '(capitalize-word 1) t)"
  1385. (if (not (equal select 'noaction))
  1386. ;; Add action
  1387. (let* ((table (if select 'idlwave-indent-action-table
  1388. 'idlwave-indent-expand-table))
  1389. (table-key (regexp-quote key))
  1390. (cell (assoc table-key (eval table))))
  1391. (if cell
  1392. ;; Replace action command
  1393. (setcdr cell cmd)
  1394. ;; New action
  1395. (set table (append (eval table) (list (cons table-key cmd)))))))
  1396. ;; Make key binding for action
  1397. (if (or (and (null select) (= (length key) 1))
  1398. (equal select 'noaction)
  1399. (equal select 'both))
  1400. (define-key idlwave-mode-map key
  1401. `(lambda ()
  1402. (interactive)
  1403. (self-insert-command 1)
  1404. ,(if (listp cmd) cmd (list cmd))))))
  1405. ;; Set action and key bindings.
  1406. ;; See description of the function `idlwave-action-and-binding'.
  1407. ;; Automatically add spaces for the following characters
  1408. ;; Actions for & are complicated by &&
  1409. (idlwave-action-and-binding "&" 'idlwave-custom-ampersand-surround)
  1410. ;; Automatically add spaces to equal sign if not keyword. This needs
  1411. ;; to go ahead of > and <, so >= and <= will be treated correctly
  1412. (idlwave-action-and-binding "=" '(idlwave-expand-equal -1 -1))
  1413. ;; Actions for > and < are complicated by >=, <=, and ->...
  1414. (idlwave-action-and-binding "<" '(idlwave-custom-ltgtr-surround nil))
  1415. (idlwave-action-and-binding ">" '(idlwave-custom-ltgtr-surround 'gtr))
  1416. (idlwave-action-and-binding "," '(idlwave-surround 0 -1 1))
  1417. ;;;
  1418. ;;; Abbrev Section
  1419. ;;;
  1420. ;;; When expanding abbrevs and the abbrev hook moves backward, an extra
  1421. ;;; space is inserted (this is the space typed by the user to expanded
  1422. ;;; the abbrev).
  1423. ;;;
  1424. (defvar idlwave-mode-abbrev-table nil
  1425. "Abbreviation table used for IDLWAVE mode.")
  1426. (define-abbrev-table 'idlwave-mode-abbrev-table ())
  1427. (defun idlwave-define-abbrev (name expansion hook &optional noprefix table)
  1428. "Define-abbrev with backward compatibility.
  1429. If NOPREFIX is non-nil, don't prepend prefix character. Installs into
  1430. `idlwave-mode-abbrev-table' unless TABLE is non-nil."
  1431. (let ((abbrevs-changed nil) ;; mask the current value to avoid save
  1432. (args (list (or table idlwave-mode-abbrev-table)
  1433. (if noprefix name (concat idlwave-abbrev-start-char name))
  1434. expansion
  1435. hook)))
  1436. (condition-case nil
  1437. (apply 'define-abbrev (append args '(0 t)))
  1438. (error (apply 'define-abbrev args)))))
  1439. (condition-case nil
  1440. (modify-syntax-entry (string-to-char idlwave-abbrev-start-char)
  1441. "w" idlwave-mode-syntax-table)
  1442. (error nil))
  1443. ;;
  1444. ;; Templates
  1445. ;;
  1446. (idlwave-define-abbrev "c" "" (idlwave-code-abbrev idlwave-case))
  1447. (idlwave-define-abbrev "sw" "" (idlwave-code-abbrev idlwave-switch))
  1448. (idlwave-define-abbrev "f" "" (idlwave-code-abbrev idlwave-for))
  1449. (idlwave-define-abbrev "fu" "" (idlwave-code-abbrev idlwave-function))
  1450. (idlwave-define-abbrev "pr" "" (idlwave-code-abbrev idlwave-procedure))
  1451. (idlwave-define-abbrev "r" "" (idlwave-code-abbrev idlwave-repeat))
  1452. (idlwave-define-abbrev "w" "" (idlwave-code-abbrev idlwave-while))
  1453. (idlwave-define-abbrev "i" "" (idlwave-code-abbrev idlwave-if))
  1454. (idlwave-define-abbrev "elif" "" (idlwave-code-abbrev idlwave-elif))
  1455. ;;
  1456. ;; Keywords, system functions, conversion routines
  1457. ;;
  1458. (idlwave-define-abbrev "ap" "arg_present()" (idlwave-keyword-abbrev 1))
  1459. (idlwave-define-abbrev "b" "begin" (idlwave-keyword-abbrev 0 t))
  1460. (idlwave-define-abbrev "co" "common" (idlwave-keyword-abbrev 0 t))
  1461. (idlwave-define-abbrev "cb" "byte()" (idlwave-keyword-abbrev 1))
  1462. (idlwave-define-abbrev "cx" "fix()" (idlwave-keyword-abbrev 1))
  1463. (idlwave-define-abbrev "cl" "long()" (idlwave-keyword-abbrev 1))
  1464. (idlwave-define-abbrev "cf" "float()" (idlwave-keyword-abbrev 1))
  1465. (idlwave-define-abbrev "cs" "string()" (idlwave-keyword-abbrev 1))
  1466. (idlwave-define-abbrev "cc" "complex()" (idlwave-keyword-abbrev 1))
  1467. (idlwave-define-abbrev "cd" "double()" (idlwave-keyword-abbrev 1))
  1468. (idlwave-define-abbrev "e" "else" (idlwave-keyword-abbrev 0 t))
  1469. (idlwave-define-abbrev "ec" "endcase" 'idlwave-show-begin)
  1470. (idlwave-define-abbrev "es" "endswitch" 'idlwave-show-begin)
  1471. (idlwave-define-abbrev "ee" "endelse" 'idlwave-show-begin)
  1472. (idlwave-define-abbrev "ef" "endfor" 'idlwave-show-begin)
  1473. (idlwave-define-abbrev "ei" "endif else if" 'idlwave-show-begin)
  1474. (idlwave-define-abbrev "el" "endif else" 'idlwave-show-begin)
  1475. (idlwave-define-abbrev "en" "endif" 'idlwave-show-begin)
  1476. (idlwave-define-abbrev "er" "endrep" 'idlwave-show-begin)
  1477. (idlwave-define-abbrev "ew" "endwhile" 'idlwave-show-begin)
  1478. (idlwave-define-abbrev "g" "goto," (idlwave-keyword-abbrev 0 t))
  1479. (idlwave-define-abbrev "h" "help," (idlwave-keyword-abbrev 0))
  1480. (idlwave-define-abbrev "k" "keyword_set()" (idlwave-keyword-abbrev 1))
  1481. (idlwave-define-abbrev "n" "n_elements()" (idlwave-keyword-abbrev 1))
  1482. (idlwave-define-abbrev "on" "on_error," (idlwave-keyword-abbrev 0))
  1483. (idlwave-define-abbrev "oi" "on_ioerror," (idlwave-keyword-abbrev 0 1))
  1484. (idlwave-define-abbrev "ow" "openw," (idlwave-keyword-abbrev 0))
  1485. (idlwave-define-abbrev "or" "openr," (idlwave-keyword-abbrev 0))
  1486. (idlwave-define-abbrev "ou" "openu," (idlwave-keyword-abbrev 0))
  1487. (idlwave-define-abbrev "p" "print," (idlwave-keyword-abbrev 0))
  1488. (idlwave-define-abbrev "pt" "plot," (idlwave-keyword-abbrev 0))
  1489. (idlwave-define-abbrev "re" "read," (idlwave-keyword-abbrev 0))
  1490. (idlwave-define-abbrev "rf" "readf," (idlwave-keyword-abbrev 0))
  1491. (idlwave-define-abbrev "ru" "readu," (idlwave-keyword-abbrev 0))
  1492. (idlwave-define-abbrev "rt" "return" (idlwave-keyword-abbrev 0))
  1493. (idlwave-define-abbrev "sc" "strcompress()" (idlwave-keyword-abbrev 1))
  1494. (idlwave-define-abbrev "sn" "strlen()" (idlwave-keyword-abbrev 1))
  1495. (idlwave-define-abbrev "sl" "strlowcase()" (idlwave-keyword-abbrev 1))
  1496. (idlwave-define-abbrev "su" "strupcase()" (idlwave-keyword-abbrev 1))
  1497. (idlwave-define-abbrev "sm" "strmid()" (idlwave-keyword-abbrev 1))
  1498. (idlwave-define-abbrev "sp" "strpos()" (idlwave-keyword-abbrev 1))
  1499. (idlwave-define-abbrev "st" "strput()" (idlwave-keyword-abbrev 1))
  1500. (idlwave-define-abbrev "sr" "strtrim()" (idlwave-keyword-abbrev 1))
  1501. (idlwave-define-abbrev "t" "then" (idlwave-keyword-abbrev 0 t))
  1502. (idlwave-define-abbrev "u" "until" (idlwave-keyword-abbrev 0 t))
  1503. (idlwave-define-abbrev "wu" "writeu," (idlwave-keyword-abbrev 0))
  1504. (idlwave-define-abbrev "iap" "if arg_present() then" (idlwave-keyword-abbrev 6))
  1505. (idlwave-define-abbrev "ik" "if keyword_set() then" (idlwave-keyword-abbrev 6))
  1506. (idlwave-define-abbrev "ine" "if n_elements() eq 0 then" (idlwave-keyword-abbrev 11))
  1507. (idlwave-define-abbrev "inn" "if n_elements() ne 0 then" (idlwave-keyword-abbrev 11))
  1508. (idlwave-define-abbrev "np" "n_params()" (idlwave-keyword-abbrev 0))
  1509. (idlwave-define-abbrev "s" "size()" (idlwave-keyword-abbrev 1))
  1510. (idlwave-define-abbrev "wi" "widget_info()" (idlwave-keyword-abbrev 1))
  1511. (idlwave-define-abbrev "wc" "widget_control," (idlwave-keyword-abbrev 0))
  1512. (idlwave-define-abbrev "pv" "ptr_valid()" (idlwave-keyword-abbrev 1))
  1513. (idlwave-define-abbrev "ipv" "if ptr_valid() then" (idlwave-keyword-abbrev 6))
  1514. ;; This section is reserved words only. (From IDL user manual)
  1515. ;;
  1516. (idlwave-define-abbrev "and" "and" (idlwave-keyword-abbrev 0 t) t)
  1517. (idlwave-define-abbrev "begin" "begin" (idlwave-keyword-abbrev 0 t) t)
  1518. (idlwave-define-abbrev "break" "break" (idlwave-keyword-abbrev 0 t) t)
  1519. (idlwave-define-abbrev "case" "case" (idlwave-keyword-abbrev 0 t) t)
  1520. (idlwave-define-abbrev "common" "common" (idlwave-keyword-abbrev 0 t) t)
  1521. (idlwave-define-abbrev "continue" "continue" (idlwave-keyword-abbrev 0 t) t)
  1522. (idlwave-define-abbrev "do" "do" (idlwave-keyword-abbrev 0 t) t)
  1523. (idlwave-define-abbrev "else" "else" (idlwave-keyword-abbrev 0 t) t)
  1524. (idlwave-define-abbrev "end" "end" 'idlwave-show-begin-check t)
  1525. (idlwave-define-abbrev "endcase" "endcase" 'idlwave-show-begin-check t)
  1526. (idlwave-define-abbrev "endelse" "endelse" 'idlwave-show-begin-check t)
  1527. (idlwave-define-abbrev "endfor" "endfor" 'idlwave-show-begin-check t)
  1528. (idlwave-define-abbrev "endif" "endif" 'idlwave-show-begin-check t)
  1529. (idlwave-define-abbrev "endrep" "endrep" 'idlwave-show-begin-check t)
  1530. (idlwave-define-abbrev "endswitch" "endswitch" 'idlwave-show-begin-check t)
  1531. (idlwave-define-abbrev "endwhi" "endwhi" 'idlwave-show-begin-check t)
  1532. (idlwave-define-abbrev "endwhile" "endwhile" 'idlwave-show-begin-check t)
  1533. (idlwave-define-abbrev "eq" "eq" (idlwave-keyword-abbrev 0 t) t)
  1534. (idlwave-define-abbrev "for" "for" (idlwave-keyword-abbrev 0 t) t)
  1535. (idlwave-define-abbrev "function" "function" (idlwave-keyword-abbrev 0 t) t)
  1536. (idlwave-define-abbrev "ge" "ge" (idlwave-keyword-abbrev 0 t) t)
  1537. (idlwave-define-abbrev "goto" "goto" (idlwave-keyword-abbrev 0 t) t)
  1538. (idlwave-define-abbrev "gt" "gt" (idlwave-keyword-abbrev 0 t) t)
  1539. (idlwave-define-abbrev "if" "if" (idlwave-keyword-abbrev 0 t) t)
  1540. (idlwave-define-abbrev "le" "le" (idlwave-keyword-abbrev 0 t) t)
  1541. (idlwave-define-abbrev "lt" "lt" (idlwave-keyword-abbrev 0 t) t)
  1542. (idlwave-define-abbrev "mod" "mod" (idlwave-keyword-abbrev 0 t) t)
  1543. (idlwave-define-abbrev "ne" "ne" (idlwave-keyword-abbrev 0 t) t)
  1544. (idlwave-define-abbrev "not" "not" (idlwave-keyword-abbrev 0 t) t)
  1545. (idlwave-define-abbrev "of" "of" (idlwave-keyword-abbrev 0 t) t)
  1546. (idlwave-define-abbrev "on_ioerror" "on_ioerror" (idlwave-keyword-abbrev 0 t) t)
  1547. (idlwave-define-abbrev "or" "or" (idlwave-keyword-abbrev 0 t) t)
  1548. (idlwave-define-abbrev "pro" "pro" (idlwave-keyword-abbrev 0 t) t)
  1549. (idlwave-define-abbrev "repeat" "repeat" (idlwave-keyword-abbrev 0 t) t)
  1550. (idlwave-define-abbrev "switch" "switch" (idlwave-keyword-abbrev 0 t) t)
  1551. (idlwave-define-abbrev "then" "then" (idlwave-keyword-abbrev 0 t) t)
  1552. (idlwave-define-abbrev "until" "until" (idlwave-keyword-abbrev 0 t) t)
  1553. (idlwave-define-abbrev "while" "while" (idlwave-keyword-abbrev 0 t) t)
  1554. (idlwave-define-abbrev "xor" "xor" (idlwave-keyword-abbrev 0 t) t)
  1555. (defvar imenu-create-index-function)
  1556. (defvar extract-index-name-function)
  1557. (defvar prev-index-position-function)
  1558. (defvar imenu-extract-index-name-function)
  1559. (defvar imenu-prev-index-position-function)
  1560. ;; defined later - so just make the compiler hush
  1561. (defvar idlwave-mode-menu)
  1562. (defvar idlwave-mode-debug-menu)
  1563. ;;;###autoload
  1564. (define-derived-mode idlwave-mode prog-mode "IDLWAVE"
  1565. "Major mode for editing IDL source files (version 6.1_em22).
  1566. The main features of this mode are
  1567. 1. Indentation and Formatting
  1568. --------------------------
  1569. Like other Emacs programming modes, C-j inserts a newline and indents.
  1570. TAB is used for explicit indentation of the current line.
  1571. To start a continuation line, use \\[idlwave-split-line]. This
  1572. function can also be used in the middle of a line to split the line
  1573. at that point. When used inside a long constant string, the string
  1574. is split at that point with the `+' concatenation operator.
  1575. Comments are indented as follows:
  1576. `;;;' Indentation remains unchanged.
  1577. `;;' Indent like the surrounding code
  1578. `;' Indent to a minimum column.
  1579. The indentation of comments starting in column 0 is never changed.
  1580. Use \\[idlwave-fill-paragraph] to refill a paragraph inside a
  1581. comment. The indentation of the second line of the paragraph
  1582. relative to the first will be retained. Use
  1583. \\[idlwave-auto-fill-mode] to toggle auto-fill mode for these
  1584. comments. When the variable `idlwave-fill-comment-line-only' is
  1585. nil, code can also be auto-filled and auto-indented.
  1586. To convert pre-existing IDL code to your formatting style, mark the
  1587. entire buffer with \\[mark-whole-buffer] and execute
  1588. \\[idlwave-expand-region-abbrevs]. Then mark the entire buffer
  1589. again followed by \\[indent-region] (`indent-region').
  1590. 2. Routine Info
  1591. ------------
  1592. IDLWAVE displays information about the calling sequence and the
  1593. accepted keyword parameters of a procedure or function with
  1594. \\[idlwave-routine-info]. \\[idlwave-find-module] jumps to the
  1595. source file of a module. These commands know about system
  1596. routines, all routines in idlwave-mode buffers and (when the
  1597. idlwave-shell is active) about all modules currently compiled under
  1598. this shell. It also makes use of pre-compiled or custom-scanned
  1599. user and library catalogs many popular libraries ship with by
  1600. default. Use \\[idlwave-update-routine-info] to update this
  1601. information, which is also used for completion (see item 4).
  1602. 3. Online IDL Help
  1603. ---------------
  1604. \\[idlwave-context-help] displays the IDL documentation relevant
  1605. for the system variable, keyword, or routines at point. A single
  1606. key stroke gets you directly to the right place in the docs. See
  1607. the manual to configure where and how the HTML help is displayed.
  1608. 4. Completion
  1609. ----------
  1610. \\[idlwave-complete] completes the names of procedures, functions
  1611. class names, keyword parameters, system variables and tags, class
  1612. tags, structure tags, filenames and much more. It is context
  1613. sensitive and figures out what is expected at point. Lower case
  1614. strings are completed in lower case, other strings in mixed or
  1615. upper case.
  1616. 5. Code Templates and Abbreviations
  1617. --------------------------------
  1618. Many Abbreviations are predefined to expand to code fragments and templates.
  1619. The abbreviations start generally with a `\\`. Some examples:
  1620. \\pr PROCEDURE template
  1621. \\fu FUNCTION template
  1622. \\c CASE statement template
  1623. \\sw SWITCH statement template
  1624. \\f FOR loop template
  1625. \\r REPEAT Loop template
  1626. \\w WHILE loop template
  1627. \\i IF statement template
  1628. \\elif IF-ELSE statement template
  1629. \\b BEGIN
  1630. For a full list, use \\[idlwave-list-abbrevs]. Some templates also
  1631. have direct keybindings - see the list of keybindings below.
  1632. \\[idlwave-doc-header] inserts a documentation header at the
  1633. beginning of the current program unit (pro, function or main).
  1634. Change log entries can be added to the current program unit with
  1635. \\[idlwave-doc-modification].
  1636. 6. Automatic Case Conversion
  1637. -------------------------
  1638. The case of reserved words and some abbrevs is controlled by
  1639. `idlwave-reserved-word-upcase' and `idlwave-abbrev-change-case'.
  1640. 7. Automatic END completion
  1641. ------------------------
  1642. If the variable `idlwave-expand-generic-end' is non-nil, each END typed
  1643. will be converted to the specific version, like ENDIF, ENDFOR, etc.
  1644. 8. Hooks
  1645. -----
  1646. Loading idlwave.el runs `idlwave-load-hook'.
  1647. Turning on `idlwave-mode' runs `idlwave-mode-hook'.
  1648. 9. Documentation and Customization
  1649. -------------------------------
  1650. Info documentation for this package is available. Use
  1651. \\[idlwave-info] to display (complain to your sysadmin if that does
  1652. not work). For Postscript, PDF, and HTML versions of the
  1653. documentation, check IDLWAVE's homepage at URL `http://idlwave.org'.
  1654. IDLWAVE has customize support - see the group `idlwave'.
  1655. 10.Keybindings
  1656. -----------
  1657. Here is a list of all keybindings of this mode.
  1658. If some of the key bindings below show with ??, use \\[describe-key]
  1659. followed by the key sequence to see what the key sequence does.
  1660. \\{idlwave-mode-map}"
  1661. :abbrev-table idlwave-mode-abbrev-table
  1662. (if idlwave-startup-message
  1663. (message "Emacs IDLWAVE mode version %s." idlwave-mode-version))
  1664. (setq idlwave-startup-message nil)
  1665. (set (make-local-variable 'indent-line-function) 'idlwave-indent-and-action)
  1666. (set (make-local-variable idlwave-comment-indent-function)
  1667. #'idlwave-comment-hook)
  1668. (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
  1669. (set (make-local-variable 'comment-start) ";")
  1670. (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
  1671. (set (make-local-variable 'abbrev-all-caps) t)
  1672. (set (make-local-variable 'indent-tabs-mode) nil)
  1673. (set (make-local-variable 'completion-ignore-case) t)
  1674. (when (featurep 'easymenu)
  1675. (easy-menu-add idlwave-mode-menu idlwave-mode-map)
  1676. (easy-menu-add idlwave-mode-debug-menu idlwave-mode-map))
  1677. (setq abbrev-mode t)
  1678. (set (make-local-variable idlwave-fill-function) 'idlwave-auto-fill)
  1679. (setq comment-end "")
  1680. (set (make-local-variable 'comment-multi-line) nil)
  1681. (set (make-local-variable 'paragraph-separate)
  1682. "[ \t\f]*$\\|[ \t]*;+[ \t]*$\\|;+[+=-_*]+$")
  1683. (set (make-local-variable 'paragraph-start) "[ \t\f]\\|[ \t]*;+[ \t]")
  1684. (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
  1685. (set (make-local-variable 'parse-sexp-ignore-comments) t)
  1686. ;; ChangeLog
  1687. (set (make-local-variable 'add-log-current-defun-function)
  1688. 'idlwave-current-routine-fullname)
  1689. ;; Set tag table list to use IDLTAGS as file name.
  1690. (if (boundp 'tag-table-alist)
  1691. (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
  1692. ;; Font-lock additions
  1693. ;; Following line is for Emacs - XEmacs uses the corresponding property
  1694. ;; on the `idlwave-mode' symbol.
  1695. (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
  1696. (set (make-local-variable 'font-lock-mark-block-function)
  1697. 'idlwave-mark-subprogram)
  1698. (set (make-local-variable 'font-lock-fontify-region-function)
  1699. 'idlwave-font-lock-fontify-region)
  1700. ;; Imenu setup
  1701. (set (make-local-variable 'imenu-create-index-function)
  1702. 'imenu-default-create-index-function)
  1703. (set (make-local-variable 'imenu-extract-index-name-function)
  1704. 'idlwave-unit-name)
  1705. (set (make-local-variable 'imenu-prev-index-position-function)
  1706. 'idlwave-prev-index-position)
  1707. ;; HideShow setup
  1708. (add-to-list 'hs-special-modes-alist
  1709. (list 'idlwave-mode
  1710. idlwave-begin-block-reg
  1711. idlwave-end-block-reg
  1712. ";"
  1713. 'idlwave-forward-block nil))
  1714. ;; Make a local post-command-hook and add our hook to it
  1715. ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
  1716. ;; (make-local-hook 'post-command-hook)
  1717. (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
  1718. ;; Make local hooks for buffer updates
  1719. ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
  1720. ;; (make-local-hook 'kill-buffer-hook)
  1721. (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
  1722. ;; (make-local-hook 'after-save-hook)
  1723. (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
  1724. (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
  1725. ;; Setup directories and file, if necessary
  1726. (idlwave-setup)
  1727. ;; Update the routine info with info about current buffer?
  1728. (idlwave-new-buffer-update)
  1729. ;; Check help location
  1730. (idlwave-help-check-locations))
  1731. (defvar idlwave-setup-done nil)
  1732. (defun idlwave-setup ()
  1733. (unless idlwave-setup-done
  1734. (if (not (file-directory-p idlwave-config-directory))
  1735. (make-directory idlwave-config-directory))
  1736. (setq
  1737. idlwave-user-catalog-file (expand-file-name
  1738. idlwave-user-catalog-file
  1739. idlwave-config-directory)
  1740. idlwave-xml-system-rinfo-converted-file
  1741. (expand-file-name
  1742. idlwave-xml-system-rinfo-converted-file
  1743. idlwave-config-directory)
  1744. idlwave-path-file (expand-file-name
  1745. idlwave-path-file
  1746. idlwave-config-directory))
  1747. (idlwave-read-paths) ; we may need these early
  1748. (setq idlwave-setup-done t)))
  1749. (defun idlwave-font-lock-fontify-region (beg end &optional verbose)
  1750. "Fontify continuation lines correctly."
  1751. (let (pos)
  1752. (save-excursion
  1753. (goto-char beg)
  1754. (forward-line -1)
  1755. (when (setq pos (idlwave-is-continuation-line))
  1756. (goto-char pos)
  1757. (idlwave-beginning-of-statement)
  1758. (setq beg (point)))))
  1759. (font-lock-default-fontify-region beg end verbose))
  1760. ;;
  1761. ;; Code Formatting ----------------------------------------------------
  1762. ;;
  1763. (defun idlwave-hard-tab ()
  1764. "Insert TAB in buffer in current position."
  1765. (interactive)
  1766. (insert "\t"))
  1767. ;;; This stuff is experimental
  1768. (defvar idlwave-command-hook nil
  1769. "If non-nil, a list that can be evaluated using `eval'.
  1770. It is evaluated in the lisp function `idlwave-command-hook' which is
  1771. placed in `post-command-hook'.")
  1772. (defun idlwave-command-hook ()
  1773. "Command run after every command.
  1774. Evaluates a non-nil value of the *variable* `idlwave-command-hook' and
  1775. sets the variable to zero afterwards."
  1776. (and idlwave-command-hook
  1777. (listp idlwave-command-hook)
  1778. (condition-case nil
  1779. (eval idlwave-command-hook)
  1780. (error nil)))
  1781. (setq idlwave-command-hook nil))
  1782. ;;; End experiment
  1783. ;; It would be better to use expand.el for better abbrev handling and
  1784. ;; versatility.
  1785. (defun idlwave-check-abbrev (arg &optional reserved)
  1786. "Reverse abbrev expansion if in comment or string.
  1787. Argument ARG is the number of characters to move point
  1788. backward if `idlwave-abbrev-move' is non-nil.
  1789. If optional argument RESERVED is non-nil then the expansion
  1790. consists of reserved words, which will be capitalized if
  1791. `idlwave-reserved-word-upcase' is non-nil.
  1792. Otherwise, the abbrev will be capitalized if `idlwave-abbrev-change-case'
  1793. is non-nil, unless its value is \`down in which case the abbrev will be
  1794. made into all lowercase.
  1795. Returns non-nil if abbrev is left expanded."
  1796. (if (idlwave-quoted)
  1797. (progn (unexpand-abbrev)
  1798. nil)
  1799. (if (and reserved idlwave-reserved-word-upcase)
  1800. (upcase-region last-abbrev-location (point))
  1801. (cond
  1802. ((equal idlwave-abbrev-change-case 'down)
  1803. (downcase-region last-abbrev-location (point)))
  1804. (idlwave-abbrev-change-case
  1805. (upcase-region last-abbrev-location (point)))))
  1806. (if (and idlwave-abbrev-move (> arg 0))
  1807. (if (boundp 'post-command-hook)
  1808. (setq idlwave-command-hook (list 'backward-char (1+ arg)))
  1809. (backward-char arg)))
  1810. t))
  1811. (defun idlwave-in-comment ()
  1812. "Return t if point is inside a comment, nil otherwise."
  1813. (save-excursion
  1814. (let ((here (point)))
  1815. (and (idlwave-goto-comment) (> here (point))))))
  1816. (defun idlwave-goto-comment ()
  1817. "Move to start of comment delimiter on current line.
  1818. Moves to end of line if there is no comment delimiter.
  1819. Ignores comment delimiters in strings.
  1820. Returns point if comment found and nil otherwise."
  1821. (let ((eos (point-at-eol))
  1822. (data (match-data))
  1823. found)
  1824. ;; Look for first comment delimiter not in a string
  1825. (beginning-of-line)
  1826. (setq found (search-forward comment-start eos 'lim))
  1827. (while (and found (idlwave-in-quote))
  1828. (setq found (search-forward comment-start eos 'lim)))
  1829. (store-match-data data)
  1830. (and found (not (idlwave-in-quote))
  1831. (progn
  1832. (backward-char 1)
  1833. (point)))))
  1834. (defun idlwave-region-active-p ()
  1835. "Should we operate on an active region?"
  1836. (if (fboundp 'use-region-p)
  1837. (use-region-p)
  1838. (region-active-p)))
  1839. (defun idlwave-show-matching-quote ()
  1840. "Insert quote and show matching quote if this is end of a string."
  1841. (interactive)
  1842. (let ((bq (idlwave-in-quote))
  1843. (inq last-command-event))
  1844. (if (and bq (not (idlwave-in-comment)))
  1845. (let ((delim (char-after bq)))
  1846. (insert inq)
  1847. (if (eq inq delim)
  1848. (save-excursion
  1849. (goto-char bq)
  1850. (sit-for 1))))
  1851. ;; Not the end of a string
  1852. (insert inq))))
  1853. (defun idlwave-show-begin-check ()
  1854. "Ensure that the previous word was a token before `idlwave-show-begin'.
  1855. An END token must be preceded by whitespace."
  1856. (if (not (idlwave-quoted))
  1857. (if
  1858. (save-excursion
  1859. (backward-word 1)
  1860. (backward-char 1)
  1861. (looking-at "[ \t\n\f]"))
  1862. (idlwave-show-begin))))
  1863. (defun idlwave-show-begin ()
  1864. "Find the start of current block and blinks to it for a second.
  1865. Also checks if the correct END statement has been used."
  1866. ;; All end statements are reserved words
  1867. ;; Re-indent end line
  1868. ;;(insert-char ?\ 1) ;; So indent, etc. work well
  1869. ;;(backward-char 1)
  1870. (let* ((pos (point-marker))
  1871. (last-abbrev-marker (copy-marker last-abbrev-location))
  1872. (eol-pos (point-at-eol))
  1873. begin-pos end-pos end end1 )
  1874. (if idlwave-reindent-end (idlwave-indent-line))
  1875. (setq last-abbrev-location (marker-position last-abbrev-marker))
  1876. (when (and (idlwave-check-abbrev 0 t)
  1877. idlwave-show-block)
  1878. (save-excursion
  1879. ;; Move inside current block
  1880. (goto-char last-abbrev-marker)
  1881. (idlwave-block-jump-out -1 'nomark)
  1882. (setq begin-pos (point))
  1883. (idlwave-block-jump-out 1 'nomark)
  1884. (setq end-pos (point))
  1885. (if (> end-pos eol-pos)
  1886. (setq end-pos pos))
  1887. (goto-char end-pos)
  1888. (setq end (buffer-substring
  1889. (progn
  1890. (skip-chars-backward "a-zA-Z")
  1891. (point))
  1892. end-pos))
  1893. (goto-char begin-pos)
  1894. (when (setq end1 (cdr (idlwave-block-master)))
  1895. (cond
  1896. ((null end1)) ; no-operation
  1897. ((string= (downcase end) (downcase end1))
  1898. (sit-for 1))
  1899. ((string= (downcase end) "end")
  1900. ;; A generic end
  1901. (if idlwave-expand-generic-end
  1902. (save-excursion
  1903. (goto-char pos)
  1904. (backward-char 3)
  1905. (insert (if (string= end "END") (upcase end1) end1))
  1906. (delete-char 3)))
  1907. (sit-for 1))
  1908. (t
  1909. (beep)
  1910. (message "Warning: Shouldn't this be \"%s\" instead of \"%s\"?"
  1911. end1 end)
  1912. (sit-for 1))))))))
  1913. ;;(delete-char 1))
  1914. (defun idlwave-block-master ()
  1915. (let ((case-fold-search t))
  1916. (save-excursion
  1917. (cond
  1918. ((looking-at "pro\\|case\\|switch\\|function\\>")
  1919. (assoc (downcase (match-string 0)) idlwave-block-matches))
  1920. ((looking-at "begin\\>")
  1921. (let ((limit (save-excursion
  1922. (idlwave-beginning-of-statement)
  1923. (point))))
  1924. (cond
  1925. ((re-search-backward ":[ \t]*\\=" limit t)
  1926. ;; seems to be a case thing
  1927. '("begin" . "end"))
  1928. ((re-search-backward idlwave-block-match-regexp limit t)
  1929. (assoc (downcase (match-string 1))
  1930. idlwave-block-matches))
  1931. (t
  1932. ;; Just a normal block
  1933. '("begin" . "end")))))
  1934. (t nil)))))
  1935. (defun idlwave-close-block ()
  1936. "Terminate the current block with the correct END statement."
  1937. (interactive)
  1938. ;; Start new line if we are not in a new line
  1939. (unless (save-excursion
  1940. (skip-chars-backward " \t")
  1941. (bolp))
  1942. (let ((idlwave-show-block nil))
  1943. (newline-and-indent)))
  1944. (let ((last-abbrev-location (point))) ; for upcasing
  1945. (insert "end")
  1946. (idlwave-show-begin)))
  1947. (defun idlwave-custom-ampersand-surround (&optional is-action)
  1948. "Surround &, leaving room for && (which surround as well)."
  1949. (let* ((prev-char (char-after (- (point) 2)))
  1950. (next-char (char-after (point)))
  1951. (amp-left (eq prev-char ?&))
  1952. (amp-right (eq next-char ?&))
  1953. (len (if amp-left 2 1)))
  1954. (unless amp-right ;no need to do it twice, amp-left will catch it.
  1955. (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
  1956. (defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
  1957. "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
  1958. (let* ((prev-char (char-after (- (point) 2)))
  1959. (next-char (char-after (point)))
  1960. (method-invoke (and gtr (eq prev-char ?-)))
  1961. (len (if method-invoke 2 1)))
  1962. (unless (eq next-char ?=)
  1963. ;; Key binding: pad only on left, to save for possible >=/<=
  1964. (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
  1965. (defun idlwave-surround (&optional before after length is-action)
  1966. "Surround the LENGTH characters before point with blanks.
  1967. LENGTH defaults to 1.
  1968. Optional arguments BEFORE and AFTER affect the behavior before and
  1969. after the characters (see also description of `idlwave-make-space'):
  1970. nil do nothing
  1971. 0 force no spaces
  1972. integer > 0 force exactly n spaces
  1973. integer < 0 at least |n| spaces
  1974. The function does nothing if any of the following conditions is true:
  1975. - `idlwave-surround-by-blank' is nil
  1976. - the character before point is inside a string or comment"
  1977. (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
  1978. (let ((length (or length 1))) ; establish a default for LENGTH
  1979. (backward-char length)
  1980. (save-restriction
  1981. (let ((here (point)))
  1982. (skip-chars-backward " \t")
  1983. (if (bolp)
  1984. ;; avoid clobbering indent
  1985. (progn
  1986. (move-to-column (idlwave-calculate-indent))
  1987. (if (<= (point) here)
  1988. (narrow-to-region (point) here))
  1989. (goto-char here)))
  1990. (idlwave-make-space before))
  1991. (skip-chars-forward " \t"))
  1992. (forward-char length)
  1993. (idlwave-make-space after)
  1994. ;; Check to see if the line should auto wrap
  1995. (if (and (equal (char-after (1- (point))) ?\ )
  1996. (> (current-column) fill-column))
  1997. (funcall auto-fill-function)))))
  1998. (defun idlwave-make-space (n)
  1999. "Make space at point.
  2000. The space affected is all the spaces and tabs around point.
  2001. If n is non-nil then point is left abs(n) spaces from the beginning of
  2002. the contiguous space.
  2003. The amount of space at point is determined by N.
  2004. If the value of N is:
  2005. nil - do nothing.
  2006. > 0 - exactly N spaces.
  2007. < 0 - a minimum of -N spaces, i.e., do not change if there are
  2008. already -N spaces.
  2009. 0 - no spaces (i.e. remove any existing space)."
  2010. (if (integerp n)
  2011. (let
  2012. ((start-col (progn (skip-chars-backward " \t") (current-column)))
  2013. (left (point))
  2014. (end-col (progn (skip-chars-forward " \t") (current-column))))
  2015. (delete-horizontal-space)
  2016. (cond
  2017. ((> n 0)
  2018. (idlwave-indent-to (+ start-col n))
  2019. (goto-char (+ left n)))
  2020. ((< n 0)
  2021. (idlwave-indent-to end-col (- n))
  2022. (goto-char (- left n)))
  2023. ;; n = 0, done
  2024. ))))
  2025. (defun idlwave-newline ()
  2026. "Insert a newline and indent the current and previous line."
  2027. (interactive)
  2028. ;;
  2029. ;; Handle unterminated single and double quotes
  2030. ;; If not in a comment and in a string then insertion of a newline
  2031. ;; will mean unbalanced quotes.
  2032. ;;
  2033. (if (and (not (idlwave-in-comment)) (idlwave-in-quote))
  2034. (progn (beep)
  2035. (message "Warning: unbalanced quotes?")))
  2036. (newline)
  2037. ;;
  2038. ;; The current line is being split, the cursor should be at the
  2039. ;; beginning of the new line skipping the leading indentation.
  2040. ;;
  2041. ;; The reason we insert the new line before indenting is that the
  2042. ;; indenting could be confused by keywords (e.g. END) on the line
  2043. ;; after the split point. This prevents us from just using
  2044. ;; `indent-for-tab-command' followed by `newline-and-indent'.
  2045. ;;
  2046. (beginning-of-line 0)
  2047. (idlwave-indent-line)
  2048. (forward-line)
  2049. (idlwave-indent-line))
  2050. ;;
  2051. ;; Use global variable 'comment-column' to set parallel comment
  2052. ;;
  2053. ;; Modeled on lisp.el
  2054. ;; Emacs Lisp and IDL (Wave CL) have identical comment syntax
  2055. (defun idlwave-comment-hook ()
  2056. "Compute indent for the beginning of the IDL comment delimiter."
  2057. (if (or (looking-at idlwave-no-change-comment)
  2058. (looking-at (or idlwave-begin-line-comment "^;")))
  2059. (current-column)
  2060. (if (looking-at idlwave-code-comment)
  2061. (if (save-excursion (skip-chars-backward " \t") (bolp))
  2062. ;; On line by itself, indent as code
  2063. (let ((tem (idlwave-calculate-indent)))
  2064. (if (listp tem) (car tem) tem))
  2065. ;; after code - do not change
  2066. (current-column))
  2067. (skip-chars-backward " \t")
  2068. (max (if (bolp) 0 (1+ (current-column)))
  2069. comment-column))))
  2070. (defun idlwave-split-line ()
  2071. "Continue line by breaking line at point and indent the lines.
  2072. For a code line insert continuation marker. If the line is a line comment
  2073. then the new line will contain a comment with the same indentation.
  2074. Splits strings with the IDL operator `+' if `idlwave-split-line-string' is
  2075. non-nil."
  2076. (interactive)
  2077. ;; Expand abbreviation, just like normal RET would.
  2078. (and abbrev-mode (expand-abbrev))
  2079. (let (beg)
  2080. (if (not (idlwave-in-comment))
  2081. ;; For code line add continuation.
  2082. ;; Check if splitting a string.
  2083. (progn
  2084. (if (setq beg (idlwave-in-quote))
  2085. (if idlwave-split-line-string
  2086. ;; Split the string.
  2087. (progn (insert (setq beg (char-after beg)) " + "
  2088. idlwave-continuation-char beg)
  2089. (backward-char 1)
  2090. (newline-and-indent)
  2091. (forward-char 1))
  2092. ;; Do not split the string.
  2093. (beep)
  2094. (message "Warning: continuation inside string!!")
  2095. (insert " " idlwave-continuation-char))
  2096. ;; Not splitting a string.
  2097. (if (not (member (char-before) '(?\ ?\t)))
  2098. (insert " "))
  2099. (insert idlwave-continuation-char)
  2100. (newline-and-indent)))
  2101. (indent-new-comment-line))
  2102. ;; Indent previous line
  2103. (setq beg (- (point-max) (point)))
  2104. (forward-line -1)
  2105. (idlwave-indent-line)
  2106. (goto-char (- (point-max) beg))
  2107. ;; Reindent new line
  2108. (idlwave-indent-line)))
  2109. (defun idlwave-beginning-of-subprogram (&optional nomark)
  2110. "Move point to the beginning of the current program unit.
  2111. If NOMARK is non-nil, do not push mark."
  2112. (interactive)
  2113. (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
  2114. (defun idlwave-end-of-subprogram (&optional nomark)
  2115. "Move point to the start of the next program unit.
  2116. If NOMARK is non-nil, do not push mark."
  2117. (interactive)
  2118. (idlwave-end-of-statement)
  2119. (idlwave-find-key idlwave-end-unit-reg 1 nomark))
  2120. (defun idlwave-mark-statement ()
  2121. "Mark current IDL statement."
  2122. (interactive)
  2123. (idlwave-end-of-statement)
  2124. (let ((end (point)))
  2125. (idlwave-beginning-of-statement)
  2126. (push-mark end nil t)))
  2127. (defun idlwave-mark-block ()
  2128. "Mark containing block."
  2129. (interactive)
  2130. (idlwave-end-of-statement)
  2131. (idlwave-backward-up-block -1)
  2132. (idlwave-end-of-statement)
  2133. (let ((end (point)))
  2134. (idlwave-backward-block)
  2135. (idlwave-beginning-of-statement)
  2136. (push-mark end nil t)))
  2137. (defun idlwave-mark-subprogram ()
  2138. "Put mark at beginning of program, point at end.
  2139. The marks are pushed."
  2140. (interactive)
  2141. (idlwave-end-of-statement)
  2142. (idlwave-beginning-of-subprogram)
  2143. (let ((beg (point)))
  2144. (idlwave-forward-block)
  2145. (push-mark beg nil t))
  2146. (exchange-point-and-mark))
  2147. (defun idlwave-backward-up-block (&optional arg)
  2148. "Move to beginning of enclosing block if prefix ARG >= 0.
  2149. If prefix ARG < 0 then move forward to enclosing block end."
  2150. (interactive "p")
  2151. (idlwave-block-jump-out (- arg) 'nomark))
  2152. (defun idlwave-beginning-of-block ()
  2153. "Go to the beginning of the current block."
  2154. (interactive)
  2155. (idlwave-block-jump-out -1 'nomark)
  2156. (forward-word 1))
  2157. (defun idlwave-end-of-block ()
  2158. "Go to the beginning of the current block."
  2159. (interactive)
  2160. (idlwave-block-jump-out 1 'nomark)
  2161. (backward-word 1))
  2162. (defun idlwave-forward-block (&optional arg)
  2163. "Move across next nested block."
  2164. (interactive)
  2165. (let ((arg (or arg 1)))
  2166. (if (idlwave-down-block arg)
  2167. (idlwave-block-jump-out arg 'nomark))))
  2168. (defun idlwave-backward-block ()
  2169. "Move backward across previous nested block."
  2170. (interactive)
  2171. (if (idlwave-down-block -1)
  2172. (idlwave-block-jump-out -1 'nomark)))
  2173. (defun idlwave-down-block (&optional arg)
  2174. "Go down a block.
  2175. With ARG: ARG >= 0 go forwards, ARG < 0 go backwards.
  2176. Returns non-nil if successful."
  2177. (interactive "p")
  2178. (let (status)
  2179. (if (< arg 0)
  2180. ;; Backward
  2181. (let ((eos (save-excursion
  2182. (idlwave-block-jump-out -1 'nomark)
  2183. (point))))
  2184. (if (setq status (idlwave-find-key
  2185. idlwave-end-block-reg -1 'nomark eos))
  2186. (idlwave-beginning-of-statement)
  2187. (message "No nested block before beginning of containing block.")))
  2188. ;; Forward
  2189. (let ((eos (save-excursion
  2190. (idlwave-block-jump-out 1 'nomark)
  2191. (point))))
  2192. (if (setq status (idlwave-find-key
  2193. idlwave-begin-block-reg 1 'nomark eos))
  2194. (idlwave-end-of-statement)
  2195. (message "No nested block before end of containing block."))))
  2196. status))
  2197. (defun idlwave-mark-doclib ()
  2198. "Put point at beginning of doc library header, mark at end.
  2199. The marks are pushed."
  2200. (interactive)
  2201. (let (beg
  2202. (here (point)))
  2203. (goto-char (point-max))
  2204. (if (re-search-backward idlwave-doclib-start nil t)
  2205. (progn
  2206. (setq beg (progn (beginning-of-line) (point)))
  2207. (if (re-search-forward idlwave-doclib-end nil t)
  2208. (progn
  2209. (forward-line 1)
  2210. (push-mark beg nil t)
  2211. (message "Could not find end of doc library header.")))
  2212. (message "Could not find doc library header start.")
  2213. (goto-char here)))))
  2214. (defun idlwave-current-routine-fullname ()
  2215. (let ((name (idlwave-current-routine)))
  2216. (idlwave-make-full-name (nth 2 name) (car name))))
  2217. (defun idlwave-current-routine ()
  2218. "Return (NAME TYPE CLASS) of current routine."
  2219. (idlwave-routines)
  2220. (save-excursion
  2221. (idlwave-beginning-of-subprogram 'nomark)
  2222. (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
  2223. (let* ((type (if (string= (downcase (match-string 1)) "pro")
  2224. 'pro 'function))
  2225. (class (idlwave-sintern-class (match-string 3)))
  2226. (name (idlwave-sintern-routine-or-method (match-string 4) class)))
  2227. (list name type class)))))
  2228. (defvar idlwave-shell-prompt-pattern)
  2229. (defun idlwave-beginning-of-statement ()
  2230. "Move to beginning of the current statement.
  2231. Skips back past statement continuations.
  2232. Point is placed at the beginning of the line whether or not this is an
  2233. actual statement."
  2234. (interactive)
  2235. (cond
  2236. ((derived-mode-p 'idlwave-shell-mode)
  2237. (if (re-search-backward idlwave-shell-prompt-pattern nil t)
  2238. (goto-char (match-end 0))))
  2239. (t
  2240. (if (save-excursion (forward-line -1) (idlwave-is-continuation-line))
  2241. (idlwave-previous-statement)
  2242. (beginning-of-line)))))
  2243. (defun idlwave-previous-statement ()
  2244. "Move point to beginning of the previous statement.
  2245. Returns t if the current line before moving is the beginning of
  2246. the first non-comment statement in the file, and nil otherwise."
  2247. (interactive)
  2248. (let (first-statement)
  2249. (if (not (= (forward-line -1) 0))
  2250. ;; first line in file
  2251. t
  2252. ;; skip blank lines, label lines, include lines and line comments
  2253. (while (and
  2254. ;; The current statement is the first statement until we
  2255. ;; reach another statement.
  2256. (setq first-statement
  2257. (or
  2258. (looking-at idlwave-comment-line-start-skip)
  2259. (looking-at "[ \t]*$")
  2260. (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
  2261. (looking-at "^@")))
  2262. (= (forward-line -1) 0)))
  2263. ;; skip continuation lines
  2264. (while (and
  2265. (save-excursion
  2266. (forward-line -1)
  2267. (idlwave-is-continuation-line))
  2268. (= (forward-line -1) 0)))
  2269. first-statement)))
  2270. (defun idlwave-end-of-statement ()
  2271. "Move point to the end of the current IDL statement.
  2272. If not in a statement just moves to end of line. Returns position."
  2273. (interactive)
  2274. (while (and (idlwave-is-continuation-line)
  2275. (= (forward-line 1) 0))
  2276. (while (and (idlwave-is-comment-or-empty-line)
  2277. (= (forward-line 1) 0))))
  2278. (end-of-line)
  2279. (point))
  2280. (defun idlwave-end-of-statement0 ()
  2281. "Move point to the end of the current IDL statement.
  2282. If not in a statement just moves to end of line. Returns position."
  2283. (interactive)
  2284. (while (and (idlwave-is-continuation-line)
  2285. (= (forward-line 1) 0)))
  2286. (end-of-line)
  2287. (point))
  2288. (defun idlwave-next-statement ()
  2289. "Move point to beginning of the next IDL statement.
  2290. Returns t if that statement is the last non-comment IDL statement
  2291. in the file, and nil otherwise."
  2292. (interactive)
  2293. (let (last-statement)
  2294. (idlwave-end-of-statement)
  2295. ;; skip blank lines, label lines, include lines and line comments
  2296. (while (and (= (forward-line 1) 0)
  2297. ;; The current statement is the last statement until
  2298. ;; we reach a new statement.
  2299. (setq last-statement
  2300. (or
  2301. (looking-at idlwave-comment-line-start-skip)
  2302. (looking-at "[ \t]*$")
  2303. (looking-at (concat "[ \t]*" idlwave-label "[ \t]*$"))
  2304. (looking-at "^@")))))
  2305. last-statement))
  2306. (defun idlwave-skip-multi-commands (&optional lim)
  2307. "Skip past multiple commands on a line (with `&')."
  2308. (let ((save-point (point)))
  2309. (when (re-search-forward ".*&" lim t)
  2310. (goto-char (match-end 0))
  2311. (if (idlwave-quoted)
  2312. (goto-char save-point)
  2313. (if (eq (char-after (- (point) 2)) ?&) (goto-char save-point))))
  2314. (point)))
  2315. (defun idlwave-skip-label-or-case ()
  2316. "Skip label or case statement element.
  2317. Returns position after label.
  2318. If there is no label point is not moved and nil is returned."
  2319. ;; Case expressions and labels are terminated by a colon.
  2320. ;; So we find the first colon in the line and make sure
  2321. ;; - no `?' is before it (might be a ? b : c)
  2322. ;; - it is not in a comment
  2323. ;; - not in a string constant
  2324. ;; - not in parenthesis (like a[0:3])
  2325. ;; - not followed by another ":" in explicit class, ala a->b::c
  2326. ;; As many in this mode, this function is heuristic and not an exact
  2327. ;; parser.
  2328. (let* ((start (point))
  2329. (eos (save-excursion (idlwave-end-of-statement) (point)))
  2330. (end (idlwave-find-key ":" 1 'nomark eos)))
  2331. (if (and end
  2332. (= (nth 0 (parse-partial-sexp start end)) 0)
  2333. (not (string-match "\\?" (buffer-substring start end)))
  2334. (not (string-match "^::" (buffer-substring end eos))))
  2335. (progn
  2336. (forward-char)
  2337. (point))
  2338. (goto-char start)
  2339. nil)))
  2340. (defun idlwave-start-of-substatement (&optional pre)
  2341. "Move to start of next IDL substatement after point.
  2342. Uses the type of the current IDL statement to determine if the next
  2343. statement is on a new line or is a subpart of the current statement.
  2344. Returns point at start of substatement modulo whitespace.
  2345. If optional argument is non-nil move to beginning of current
  2346. substatement."
  2347. (let ((orig (point))
  2348. (eos (idlwave-end-of-statement))
  2349. (ifnest 0)
  2350. st nst last)
  2351. (idlwave-beginning-of-statement)
  2352. (idlwave-skip-label-or-case)
  2353. (if (< (point) orig)
  2354. (idlwave-skip-multi-commands orig))
  2355. (setq last (point))
  2356. ;; Continue looking for substatements until we are past orig
  2357. (while (and (<= (point) orig) (not (eobp)))
  2358. (setq last (point))
  2359. (setq nst (nth 1 (cdr (setq st (car (idlwave-statement-type))))))
  2360. (if (equal (car st) 'if) (setq ifnest (1+ ifnest)))
  2361. (cond ((and nst
  2362. (idlwave-find-key nst 1 'nomark eos))
  2363. (goto-char (match-end 0)))
  2364. ((and (> ifnest 0) (idlwave-find-key "\\<else\\>" 1 'nomark eos))
  2365. (setq ifnest (1- ifnest))
  2366. (goto-char (match-end 0)))
  2367. (t (setq ifnest 0)
  2368. (idlwave-next-statement))))
  2369. (if pre (goto-char last))
  2370. ;; If a continuation line starts here, move to next line
  2371. (if (looking-at "[ \t]*\\$\\([ \t]*\\(;\\|$\\)\\)")
  2372. (beginning-of-line 2))
  2373. (point)))
  2374. (defun idlwave-statement-type ()
  2375. "Return the type of the current IDL statement.
  2376. Uses `idlwave-statement-match' to return a cons of (type . point) with
  2377. point the ending position where the type was determined. Type is the
  2378. association from `idlwave-statement-match', i.e. the cons cell from the
  2379. list not just the type symbol. Returns nil if not an identifiable
  2380. statement."
  2381. (save-excursion
  2382. ;; Skip whitespace within a statement which is spaces, tabs, continuations
  2383. ;; and possibly comments
  2384. (while (looking-at "[ \t]*\\$")
  2385. (forward-line 1))
  2386. (skip-chars-forward " \t")
  2387. (let ((st idlwave-statement-match)
  2388. (case-fold-search t))
  2389. (while (and (not (looking-at (nth 0 (cdr (car st)))))
  2390. (setq st (cdr st))))
  2391. (if st
  2392. (append st (match-end 0))))))
  2393. (defun idlwave-expand-equal (&optional before after is-action)
  2394. "Pad '=' with spaces.
  2395. Two cases: Assignment statement, and keyword assignment.
  2396. Which case is determined using `idlwave-start-of-substatement' and
  2397. `idlwave-statement-type'. The equal sign will be surrounded by BEFORE
  2398. and AFTER blanks. If `idlwave-pad-keyword' is t then keyword assignment
  2399. is treated just like assignment statements. When nil, spaces are
  2400. removed for keyword assignment. Any other value keeps the current space
  2401. around the `='. Limits in for loops are treated as keyword assignment.
  2402. Starting with IDL 6.0, a number of op= assignments are available.
  2403. Since ambiguities of the form:
  2404. r and= b
  2405. rand= b
  2406. can occur, alphanumeric operator assignment will never be pre-padded,
  2407. only post-padded. You must use a space before these to disambiguate
  2408. \(not just for padding, but for proper parsing by IDL too!). Other
  2409. operators, such as ##=, ^=, etc., will be pre-padded.
  2410. IS-ACTION is ignored.
  2411. See `idlwave-surround'."
  2412. (if idlwave-surround-by-blank
  2413. (let
  2414. ((non-an-ops "\\(##\\|\\*\\|\\+\\|-\\|/\\|<\\|>\\|\\^\\)\\=")
  2415. (an-ops
  2416. "\\s-\\(AND\\|EQ\\|GE\\|GT\\|LE\\|LT\\|MOD\\|NE\\|OR\\|XOR\\)\\=")
  2417. (len 1))
  2418. (save-excursion
  2419. (let ((case-fold-search t))
  2420. (backward-char)
  2421. (if (or
  2422. (re-search-backward non-an-ops nil t)
  2423. ;; Why doesn't ##? work for both?
  2424. (re-search-backward "\\(#\\)\\=" nil t))
  2425. (setq len (1+ (length (match-string 1))))
  2426. (when (re-search-backward an-ops nil t)
  2427. ;(setq begin nil) ; won't modify begin
  2428. (setq len (1+ (length (match-string 1))))))))
  2429. (if (eq t idlwave-pad-keyword)
  2430. ;; Everything gets padded equally
  2431. (idlwave-surround before after len)
  2432. ;; Treating keywords/for variables specially...
  2433. (let ((st (save-excursion ; To catch "for" variables
  2434. (idlwave-start-of-substatement t)
  2435. (idlwave-statement-type)))
  2436. (what (save-excursion ; To catch keywords
  2437. (skip-chars-backward "= \t")
  2438. (nth 2 (idlwave-where)))))
  2439. (cond ((or (memq what '(function-keyword procedure-keyword))
  2440. (memq (caar st) '(for pdef)))
  2441. (cond
  2442. ((null idlwave-pad-keyword)
  2443. (idlwave-surround 0 0)
  2444. ) ; remove space
  2445. (t))) ; leave any spaces alone
  2446. (t (idlwave-surround before after len))))))))
  2447. (defun idlwave-indent-and-action (&optional arg)
  2448. "Call `idlwave-indent-line' and do expand actions.
  2449. With prefix ARG non-nil, indent the entire sub-statement."
  2450. (interactive "p")
  2451. (save-excursion
  2452. (if (and idlwave-expand-generic-end
  2453. (re-search-backward "\\<\\(end\\)\\s-*\\="
  2454. (max 0 (- (point) 10)) t)
  2455. (looking-at "\\(end\\)\\([ \n\t]\\|\\'\\)"))
  2456. (progn (goto-char (match-end 1))
  2457. ;;Expand the END abbreviation, just as RET or Space would have.
  2458. (if abbrev-mode (expand-abbrev)
  2459. (idlwave-show-begin)))))
  2460. (when (and (not arg) current-prefix-arg)
  2461. (setq arg current-prefix-arg)
  2462. (setq current-prefix-arg nil))
  2463. (if arg
  2464. (idlwave-indent-statement)
  2465. (idlwave-indent-line t)))
  2466. (defun idlwave-indent-line (&optional expand)
  2467. "Indent current IDL line as code or as a comment.
  2468. The actions in `idlwave-indent-action-table' are performed.
  2469. If the optional argument EXPAND is non-nil then the actions in
  2470. `idlwave-indent-expand-table' are performed."
  2471. (interactive)
  2472. ;; Move point out of left margin.
  2473. (if (save-excursion
  2474. (skip-chars-backward " \t")
  2475. (bolp))
  2476. (skip-chars-forward " \t"))
  2477. (let ((mloc (point-marker)))
  2478. (save-excursion
  2479. (beginning-of-line)
  2480. (if (looking-at idlwave-comment-line-start-skip)
  2481. ;; Indentation for a line comment
  2482. (progn
  2483. (skip-chars-forward " \t")
  2484. (idlwave-indent-left-margin (idlwave-comment-hook)))
  2485. ;;
  2486. ;; Code Line
  2487. ;;
  2488. ;; Before indenting, run action routines.
  2489. ;;
  2490. (if (and expand idlwave-do-actions)
  2491. (mapc 'idlwave-do-action idlwave-indent-expand-table))
  2492. ;;
  2493. (if idlwave-do-actions
  2494. (mapc 'idlwave-do-action idlwave-indent-action-table))
  2495. ;;
  2496. ;; No longer expand abbrevs on the line. The user can do this
  2497. ;; manually using expand-region-abbrevs.
  2498. ;;
  2499. ;; Indent for code line
  2500. ;;
  2501. (beginning-of-line)
  2502. (if (or
  2503. ;; a label line
  2504. (looking-at (concat "^" idlwave-label "[ \t]*$"))
  2505. ;; a batch command
  2506. (looking-at "^[ \t]*@"))
  2507. ;; leave flush left
  2508. nil
  2509. ;; indent the line
  2510. (idlwave-indent-left-margin (idlwave-calculate-indent)))
  2511. ;; Adjust parallel comment
  2512. (end-of-line)
  2513. (if (idlwave-in-comment)
  2514. ;; Emacs 21 is too smart with fill-column on comment indent
  2515. (let ((fill-column (if (fboundp 'comment-indent-new-line)
  2516. (1- (frame-width))
  2517. fill-column)))
  2518. (indent-for-comment)))))
  2519. (goto-char mloc)
  2520. ;; Get rid of marker
  2521. (set-marker mloc nil)))
  2522. (defun idlwave-do-action (action)
  2523. "Perform an action repeatedly on a line.
  2524. ACTION is a list (REG . FUNC). REG is a regular expression. FUNC is
  2525. either a function name to be called with `funcall' or a list to be
  2526. evaluated with `eval'. The action performed by FUNC should leave
  2527. point after the match for REG - otherwise an infinite loop may be
  2528. entered. FUNC is always passed a final argument of 'is-action, so it
  2529. can discriminate between being run as an action, or a key binding."
  2530. (let ((action-key (car action))
  2531. (action-routine (cdr action)))
  2532. (beginning-of-line)
  2533. (while (idlwave-look-at action-key)
  2534. (if (listp action-routine)
  2535. (eval (append action-routine '('is-action)))
  2536. (funcall action-routine 'is-action)))))
  2537. (defun idlwave-indent-to (col &optional min)
  2538. "Indent from point with spaces until column COL.
  2539. Inserts space before markers at point."
  2540. (if (not min) (setq min 0))
  2541. (insert-before-markers
  2542. (make-string (max min (- col (current-column))) ?\ )))
  2543. (defun idlwave-indent-left-margin (col)
  2544. "Indent the current line to column COL.
  2545. Indents such that first non-whitespace character is at column COL
  2546. Inserts spaces before markers at point."
  2547. (save-excursion
  2548. (beginning-of-line)
  2549. (delete-horizontal-space)
  2550. (idlwave-indent-to col)))
  2551. (defun idlwave-indent-subprogram ()
  2552. "Indent program unit which contains point."
  2553. (interactive)
  2554. (save-excursion
  2555. (idlwave-end-of-statement)
  2556. (idlwave-beginning-of-subprogram)
  2557. (let ((beg (point)))
  2558. (idlwave-forward-block)
  2559. (message "Indenting subprogram...")
  2560. (indent-region beg (point) nil))
  2561. (message "Indenting subprogram...done.")))
  2562. (defun idlwave-indent-statement ()
  2563. "Indent current statement, including all continuation lines."
  2564. (interactive)
  2565. (save-excursion
  2566. (idlwave-beginning-of-statement)
  2567. (let ((beg (point)))
  2568. (idlwave-end-of-statement)
  2569. (indent-region beg (point) nil))))
  2570. (defun idlwave-calculate-indent ()
  2571. "Return appropriate indentation for current line as IDL code."
  2572. (save-excursion
  2573. (beginning-of-line)
  2574. (cond
  2575. ;; Check for beginning of unit - main (beginning of buffer), pro, or
  2576. ;; function
  2577. ((idlwave-look-at idlwave-begin-unit-reg)
  2578. 0)
  2579. ;; Check for continuation line
  2580. ((save-excursion
  2581. (and (= (forward-line -1) 0)
  2582. (idlwave-is-continuation-line)))
  2583. (idlwave-calculate-cont-indent))
  2584. ;; calculate indent based on previous and current statements
  2585. (t (let* (beg-prev-pos
  2586. (the-indent
  2587. ;; calculate indent based on previous statement
  2588. (save-excursion
  2589. (cond
  2590. ;; Beginning of file
  2591. ((prog1
  2592. (idlwave-previous-statement)
  2593. (setq beg-prev-pos (point)))
  2594. 0)
  2595. ;; Main block
  2596. ((idlwave-look-at idlwave-begin-unit-reg t)
  2597. (+ (idlwave-current-statement-indent)
  2598. idlwave-main-block-indent))
  2599. ;; Begin block
  2600. ((idlwave-look-at idlwave-begin-block-reg t)
  2601. (+ (idlwave-min-current-statement-indent)
  2602. idlwave-block-indent))
  2603. ;; End Block
  2604. ((idlwave-look-at idlwave-end-block-reg t)
  2605. (progn
  2606. ;; Match to the *beginning* of the block opener
  2607. (goto-char beg-prev-pos)
  2608. (idlwave-block-jump-out -1 'nomark) ; go to begin block
  2609. (idlwave-min-current-statement-indent)))
  2610. ;; idlwave-end-offset
  2611. ;; idlwave-block-indent))
  2612. ;; Default to current indent
  2613. ((idlwave-current-statement-indent))))))
  2614. ;; adjust the indentation based on the current statement
  2615. (cond
  2616. ;; End block
  2617. ((idlwave-look-at idlwave-end-block-reg)
  2618. (+ the-indent idlwave-end-offset))
  2619. (the-indent)))))))
  2620. ;;
  2621. ;; Parentheses indent
  2622. ;;
  2623. (defun idlwave-calculate-paren-indent (beg-reg end-reg close-exp)
  2624. "Calculate the continuation indent inside a paren group.
  2625. Returns a cons-cell with (open . indent), where open is the
  2626. location of the open paren."
  2627. (let ((open (nth 1 (parse-partial-sexp beg-reg end-reg))))
  2628. ;; Found an innermost open paren.
  2629. (when open
  2630. (goto-char open)
  2631. ;; Line up with next word unless this is a closing paren.
  2632. (cons open
  2633. (cond
  2634. ;; Plain Kernighan-style nested indent
  2635. (idlwave-indent-parens-nested
  2636. (+ idlwave-continuation-indent (idlwave-current-indent)))
  2637. ;; This is a closed paren - line up under open paren.
  2638. (close-exp
  2639. (current-column))
  2640. ;; Empty (or just comment) follows -- revert to basic indent
  2641. ((progn
  2642. ;; Skip paren
  2643. (forward-char 1)
  2644. (looking-at "[ \t$]*\\(;.*\\)?$"))
  2645. nil)
  2646. ;; Line up with first word after any blank space
  2647. ((progn
  2648. (skip-chars-forward " \t")
  2649. (current-column))))))))
  2650. (defun idlwave-calculate-cont-indent ()
  2651. "Calculates the IDL continuation indent column from the previous statement.
  2652. Note that here previous statement usually means the beginning of the
  2653. current statement if this statement is a continuation of the previous
  2654. line. Various special types of continuations, including assignments,
  2655. routine definitions, and parenthetical groupings, are treated separately."
  2656. (save-excursion
  2657. (let* ((case-fold-search t)
  2658. (end-reg (progn (beginning-of-line) (point)))
  2659. (beg-last-statement (save-excursion (idlwave-previous-statement)
  2660. (point)))
  2661. (beg-reg (progn (idlwave-start-of-substatement 'pre)
  2662. (if (eq (line-beginning-position) end-reg)
  2663. (goto-char beg-last-statement)
  2664. (point))))
  2665. (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
  2666. idlwave-continuation-indent))
  2667. fancy-nonparen-indent fancy-paren-indent)
  2668. (cond
  2669. ;; Align then with its matching if, etc.
  2670. ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
  2671. ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
  2672. ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
  2673. ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
  2674. "[ \t]*until")
  2675. ("\\<case\\>" . "[ \t]*of")))
  2676. match cont-re)
  2677. (goto-char end-reg)
  2678. (and
  2679. (setq cont-re
  2680. (catch 'exit
  2681. (while (setq match (car matchers))
  2682. (if (looking-at (cdr match))
  2683. (throw 'exit (car match)))
  2684. (setq matchers (cdr matchers)))))
  2685. (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
  2686. (if (looking-at "end") ;; that one's special
  2687. (- (idlwave-current-indent)
  2688. (+ idlwave-block-indent idlwave-end-offset))
  2689. (idlwave-current-indent)))
  2690. ;; Indent in from the previous line for continuing statements
  2691. ((let ((matchers '("\\<then\\>"
  2692. "\\<do\\>"
  2693. "\\<repeat\\>"
  2694. "\\<else\\>"))
  2695. match)
  2696. (catch 'exit
  2697. (goto-char end-reg)
  2698. (if (/= (forward-line -1) 0)
  2699. (throw 'exit nil))
  2700. (while (setq match (car matchers))
  2701. (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
  2702. "\\(;.*\\)?$"))
  2703. (throw 'exit t))
  2704. (setq matchers (cdr matchers)))))
  2705. (+ idlwave-continuation-indent (idlwave-current-indent)))
  2706. ;; Parenthetical indent, either traditional or Kernighan style
  2707. ((setq fancy-paren-indent
  2708. (let* ((end-reg end-reg)
  2709. (close-exp (progn
  2710. (goto-char end-reg)
  2711. (skip-chars-forward " \t")
  2712. (looking-at "\\s)")))
  2713. indent-cons)
  2714. (catch 'loop
  2715. (while (setq indent-cons (idlwave-calculate-paren-indent
  2716. beg-reg end-reg close-exp))
  2717. ;; First permitted containing paren
  2718. (if (or
  2719. idlwave-indent-to-open-paren
  2720. idlwave-indent-parens-nested
  2721. (null (cdr indent-cons))
  2722. (< (- (cdr indent-cons) basic-indent)
  2723. idlwave-max-extra-continuation-indent))
  2724. (throw 'loop (cdr indent-cons)))
  2725. (setq end-reg (car indent-cons))))))
  2726. fancy-paren-indent)
  2727. ;; A continued assignment, or procedure call/definition
  2728. ((and
  2729. (> idlwave-max-extra-continuation-indent 0)
  2730. (setq fancy-nonparen-indent
  2731. (progn
  2732. (goto-char beg-reg)
  2733. (while (idlwave-look-at "&")) ; skip continued statements
  2734. (cond
  2735. ;; A continued Procedure call or definition
  2736. ((progn
  2737. (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
  2738. (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
  2739. (goto-char (match-end 0))
  2740. ;; Comment only, or blank line with "$"? Basic indent.
  2741. (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
  2742. nil
  2743. (current-column)))
  2744. ;; Continued assignment (with =):
  2745. ((catch 'assign ;
  2746. (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
  2747. (goto-char (match-end 0))
  2748. (if (null (idlwave-what-function beg-reg))
  2749. (throw 'assign t))))
  2750. (unless (or
  2751. (idlwave-in-quote)
  2752. (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
  2753. (save-excursion
  2754. (goto-char beg-last-statement)
  2755. (eq (caar (idlwave-statement-type)) 'for)))
  2756. (current-column))))))
  2757. (< (- fancy-nonparen-indent basic-indent)
  2758. idlwave-max-extra-continuation-indent))
  2759. (if fancy-paren-indent ;calculated but disallowed paren indent
  2760. (+ fancy-nonparen-indent idlwave-continuation-indent)
  2761. fancy-nonparen-indent))
  2762. ;; Basic indent, by default
  2763. (t basic-indent)))))
  2764. (defun idlwave-find-key (key-re &optional dir nomark limit)
  2765. "Move to next match of the regular expression KEY-RE.
  2766. Matches inside comments or string constants will be ignored.
  2767. If DIR is negative, the search will be backwards.
  2768. At a successful match, the mark is pushed unless NOMARK is non-nil.
  2769. Searches are limited to LIMIT.
  2770. Searches are case-insensitive and use a special syntax table which
  2771. treats `$' and `_' as word characters.
  2772. Return value is the beginning of the match or (in case of failure) nil."
  2773. (setq dir (or dir 0))
  2774. (let ((case-fold-search t)
  2775. (search-func (if (> dir 0) 're-search-forward 're-search-backward))
  2776. found)
  2777. (idlwave-with-special-syntax
  2778. (save-excursion
  2779. (catch 'exit
  2780. (while (funcall search-func key-re limit t)
  2781. (if (not (idlwave-quoted))
  2782. (throw 'exit (setq found (match-beginning 0)))
  2783. (if (or (and (> dir 0) (eobp))
  2784. (and (< dir 0) (bobp)))
  2785. (throw 'exit nil)))))))
  2786. (if found
  2787. (progn
  2788. (if (not nomark) (push-mark))
  2789. (goto-char found)
  2790. found)
  2791. nil)))
  2792. (defun idlwave-block-jump-out (&optional dir nomark)
  2793. "When optional argument DIR is non-negative, move forward to end of
  2794. current block using the `idlwave-begin-block-reg' and `idlwave-end-block-reg'
  2795. regular expressions. When DIR is negative, move backwards to block beginning.
  2796. Recursively calls itself to skip over nested blocks. DIR defaults to
  2797. forward. Calls `push-mark' unless the optional argument NOMARK is
  2798. non-nil. Movement is limited by the start of program units because of
  2799. possibility of unbalanced blocks."
  2800. (interactive "P")
  2801. (or dir (setq dir 0))
  2802. (let* ((here (point))
  2803. (case-fold-search t)
  2804. (limit (if (>= dir 0) (point-max) (point-min)))
  2805. (block-limit (if (>= dir 0)
  2806. idlwave-begin-block-reg
  2807. idlwave-end-block-reg))
  2808. found
  2809. (block-reg (concat idlwave-begin-block-reg "\\|"
  2810. idlwave-end-block-reg))
  2811. (unit-limit (or (save-excursion
  2812. (if (< dir 0)
  2813. (idlwave-find-key
  2814. idlwave-begin-unit-reg dir t limit)
  2815. (end-of-line)
  2816. (idlwave-find-key
  2817. idlwave-end-unit-reg dir t limit)))
  2818. limit)))
  2819. (if (>= dir 0) (end-of-line)) ;Make sure we are in current block
  2820. (if (setq found (idlwave-find-key block-reg dir t unit-limit))
  2821. (while (and found (looking-at block-limit))
  2822. (if (>= dir 0) (forward-word 1))
  2823. (idlwave-block-jump-out dir t)
  2824. (setq found (idlwave-find-key block-reg dir t unit-limit))))
  2825. (if (not nomark) (push-mark here))
  2826. (if (not found) (goto-char unit-limit)
  2827. (if (>= dir 0) (forward-word 1)))))
  2828. (defun idlwave-min-current-statement-indent (&optional end-reg)
  2829. "The minimum indent in the current statement."
  2830. (idlwave-beginning-of-statement)
  2831. (if (not (idlwave-is-continuation-line))
  2832. (idlwave-current-indent)
  2833. (let ((min (idlwave-current-indent)) comm-or-empty)
  2834. (while (and (= (forward-line 1) 0)
  2835. (or (setq comm-or-empty (idlwave-is-comment-or-empty-line))
  2836. (idlwave-is-continuation-line))
  2837. (or (null end-reg) (< (point) end-reg)))
  2838. (unless comm-or-empty (setq min (min min (idlwave-current-indent)))))
  2839. (if (or comm-or-empty (and end-reg (>= (point) end-reg)))
  2840. min
  2841. (min min (idlwave-current-indent))))))
  2842. (defun idlwave-current-statement-indent (&optional last-line)
  2843. "Return indentation of the current statement.
  2844. If in a statement, moves to beginning of statement before finding indent."
  2845. (if last-line
  2846. (idlwave-end-of-statement)
  2847. (idlwave-beginning-of-statement))
  2848. (idlwave-current-indent))
  2849. (defun idlwave-current-indent ()
  2850. "Return the column of the indentation of the current line.
  2851. Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
  2852. (save-excursion
  2853. (beginning-of-line)
  2854. (skip-chars-forward " \t")
  2855. ;; if we are at the end of blank line return 0
  2856. (cond ((eolp) 0)
  2857. ((current-column)))))
  2858. (defun idlwave-is-continuation-line ()
  2859. "Test if current line is continuation line.
  2860. Blank or comment-only lines following regular continuation lines (with
  2861. `$') count as continuations too."
  2862. (let (p)
  2863. (save-excursion
  2864. (or
  2865. (idlwave-look-at "\\<\\$")
  2866. (catch 'loop
  2867. (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
  2868. (eq (forward-line -1) 0))
  2869. (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
  2870. (defun idlwave-is-comment-line ()
  2871. "Test if the current line is a comment line."
  2872. (save-excursion
  2873. (beginning-of-line 1)
  2874. (looking-at "[ \t]*;")))
  2875. (defun idlwave-is-comment-or-empty-line ()
  2876. "Test if the current line is a comment line."
  2877. (save-excursion
  2878. (beginning-of-line 1)
  2879. (looking-at "[ \t]*[;\n]")))
  2880. (defun idlwave-look-at (regexp &optional cont beg)
  2881. "Search current line from current point for REGEXP.
  2882. If optional argument CONT is non-nil, searches to the end of
  2883. the current statement.
  2884. If optional arg BEG is non-nil, search starts from the beginning of the
  2885. current statement.
  2886. Ignores matches that end in a comment or inside a string expression.
  2887. Returns point if successful, nil otherwise.
  2888. This function produces unexpected results if REGEXP contains quotes or
  2889. a comment delimiter. The search is case insensitive.
  2890. If successful leaves point after the match, otherwise, does not move point."
  2891. (let ((here (point))
  2892. (case-fold-search t)
  2893. (eos (save-excursion
  2894. (if cont (idlwave-end-of-statement) (end-of-line))
  2895. (point)))
  2896. found)
  2897. (idlwave-with-special-syntax
  2898. (if beg (idlwave-beginning-of-statement))
  2899. (while (and (setq found (re-search-forward regexp eos t))
  2900. (idlwave-quoted))))
  2901. (if (not found) (goto-char here))
  2902. found))
  2903. (defun idlwave-fill-paragraph (&optional nohang)
  2904. "Fill paragraphs in comments.
  2905. A paragraph is made up of all contiguous lines having the same comment
  2906. leader (the leading whitespace before the comment delimiter and the
  2907. comment delimiter). In addition, paragraphs are separated by blank
  2908. line comments. The indentation is given by the hanging indent of the
  2909. first line, otherwise by the minimum indentation of the lines after
  2910. the first line. The indentation of the first line does not change.
  2911. Does not effect code lines. Does not fill comments on the same line
  2912. with code. The hanging indent is given by the end of the first match
  2913. matching `idlwave-hang-indent-regexp' on the paragraph's first line.
  2914. If the optional argument NOHANG is non-nil then the hanging indent is
  2915. ignored."
  2916. (interactive "P")
  2917. ;; check if this is a line comment
  2918. (if (save-excursion
  2919. (beginning-of-line)
  2920. (skip-chars-forward " \t")
  2921. (looking-at comment-start))
  2922. (let
  2923. ((indent 999)
  2924. pre here diff fill-prefix-reg bcl first-indent
  2925. hang start end)
  2926. ;; Change tabs to spaces in the surrounding paragraph.
  2927. ;; The surrounding paragraph will be the largest containing block of
  2928. ;; contiguous line comments. Thus, we may be changing tabs in
  2929. ;; a much larger area than is needed, but this is the easiest
  2930. ;; brute force way to do it.
  2931. ;;
  2932. ;; This has the undesirable side effect of replacing the tabs
  2933. ;; permanently without the user's request or knowledge.
  2934. (save-excursion
  2935. (backward-paragraph)
  2936. (setq start (point)))
  2937. (save-excursion
  2938. (forward-paragraph)
  2939. (setq end (point)))
  2940. (untabify start end)
  2941. ;;
  2942. (setq here (point))
  2943. (beginning-of-line)
  2944. (setq bcl (point))
  2945. (re-search-forward (concat "^[ \t]*" comment-start "+")
  2946. (point-at-eol) t)
  2947. ;; Get the comment leader on the line and its length
  2948. (setq pre (current-column))
  2949. ;; the comment leader is the indentation plus exactly the
  2950. ;; number of consecutive ";".
  2951. (setq fill-prefix-reg
  2952. (concat
  2953. (setq fill-prefix
  2954. (regexp-quote (buffer-substring (point-at-bol) (point))))
  2955. "[^;]"))
  2956. ;; Mark the beginning and end of the paragraph
  2957. (goto-char bcl)
  2958. (while (and (looking-at fill-prefix-reg)
  2959. (not (looking-at paragraph-separate))
  2960. (not (bobp)))
  2961. (forward-line -1))
  2962. ;; Move to first line of paragraph
  2963. (if (/= (point) bcl)
  2964. (forward-line 1))
  2965. (setq start (point))
  2966. (goto-char bcl)
  2967. (while (and (looking-at fill-prefix-reg)
  2968. (not (looking-at paragraph-separate))
  2969. (not (eobp)))
  2970. (forward-line 1))
  2971. (beginning-of-line)
  2972. (if (or (not (looking-at fill-prefix-reg))
  2973. (looking-at paragraph-separate))
  2974. (forward-line -1))
  2975. (end-of-line)
  2976. ;; if at end of buffer add a newline (need this because
  2977. ;; fill-region needs END to be at the beginning of line after
  2978. ;; the paragraph or it will add a line).
  2979. (if (eobp)
  2980. (progn (insert ?\n) (backward-char 1)))
  2981. ;; Set END to the beginning of line after the paragraph
  2982. ;; END is calculated as distance from end of buffer
  2983. (setq end (- (point-max) (point) 1))
  2984. ;;
  2985. ;; Calculate the indentation for the paragraph.
  2986. ;;
  2987. ;; In the following while statements, after one iteration
  2988. ;; point will be at the beginning of a line in which case
  2989. ;; the while will not be executed for the
  2990. ;; the first paragraph line and thus will not affect the
  2991. ;; indentation.
  2992. ;;
  2993. ;; First check to see if indentation is based on hanging indent.
  2994. (if (and (not nohang) idlwave-hanging-indent
  2995. (setq hang
  2996. (save-excursion
  2997. (goto-char start)
  2998. (idlwave-calc-hanging-indent))))
  2999. ;; Adjust lines of paragraph by inserting spaces so that
  3000. ;; each line's indent is at least as great as the hanging
  3001. ;; indent. This is needed for fill-paragraph to work with
  3002. ;; a fill-prefix.
  3003. (progn
  3004. (setq indent hang)
  3005. (beginning-of-line)
  3006. (while (> (point) start)
  3007. (re-search-forward comment-start-skip (point-at-eol) t)
  3008. (if (> (setq diff (- indent (current-column))) 0)
  3009. (progn
  3010. (if (>= here (point))
  3011. ;; adjust the original location for the
  3012. ;; inserted text.
  3013. (setq here (+ here diff)))
  3014. (insert (make-string diff ?\ ))))
  3015. (forward-line -1))
  3016. )
  3017. ;; No hang. Instead find minimum indentation of paragraph
  3018. ;; after first line.
  3019. ;; For the following while statement, since START is at the
  3020. ;; beginning of line and END is at the end of line
  3021. ;; point is greater than START at least once (which would
  3022. ;; be the case for a single line paragraph).
  3023. (while (> (point) start)
  3024. (beginning-of-line)
  3025. (setq indent
  3026. (min indent
  3027. (progn
  3028. (re-search-forward comment-start-skip (point-at-eol) t)
  3029. (current-column))))
  3030. (forward-line -1)))
  3031. (setq fill-prefix (concat fill-prefix
  3032. (make-string (- indent pre)
  3033. ?\ )))
  3034. ;; first-line indent
  3035. (setq first-indent
  3036. (max
  3037. (progn
  3038. (re-search-forward comment-start-skip (point-at-eol) t)
  3039. (current-column))
  3040. indent))
  3041. ;; try to keep point at its original place
  3042. (goto-char here)
  3043. ;; In place of the more modern fill-region-as-paragraph, a hack
  3044. ;; to keep whitespace untouched on the first line within the
  3045. ;; indent length and to preserve any indent on the first line
  3046. ;; (first indent).
  3047. (save-excursion
  3048. (setq diff
  3049. (buffer-substring start (+ start first-indent -1)))
  3050. (subst-char-in-region start (+ start first-indent -1) ?\ ?~ nil)
  3051. (fill-region-as-paragraph
  3052. start
  3053. (- (point-max) end)
  3054. (current-justification)
  3055. nil)
  3056. (delete-region start (+ start first-indent -1))
  3057. (goto-char start)
  3058. (insert diff))
  3059. ;; When we want the point at the beginning of the comment
  3060. ;; body fill-region will put it at the beginning of the line.
  3061. (if (bolp) (skip-chars-forward (concat " \t" comment-start)))
  3062. (setq fill-prefix nil))))
  3063. (defun idlwave-calc-hanging-indent ()
  3064. "Calculate the position of the hanging indent for the comment paragraph.
  3065. The hanging indent position is given by the first match with the
  3066. `idlwave-hang-indent-regexp'. If `idlwave-use-last-hang-indent' is
  3067. non-nil then use last occurrence matching `idlwave-hang-indent-regexp'
  3068. on the line.
  3069. If not found returns nil."
  3070. (if idlwave-use-last-hang-indent
  3071. (save-excursion
  3072. (end-of-line)
  3073. (if (re-search-backward idlwave-hang-indent-regexp (point-at-bol) t)
  3074. (+ (current-column) (length idlwave-hang-indent-regexp))))
  3075. (save-excursion
  3076. (beginning-of-line)
  3077. (if (re-search-forward idlwave-hang-indent-regexp (point-at-eol) t)
  3078. (current-column)))))
  3079. (defun idlwave-auto-fill ()
  3080. "Called to break lines in auto fill mode.
  3081. Only fills non-comment lines if `idlwave-fill-comment-line-only' is
  3082. non-nil. Places a continuation character at the end of the line if
  3083. not in a comment. Splits strings with IDL concatenation operator `+'
  3084. if `idlwave-auto-fill-split-string' is non-nil."
  3085. (if (<= (current-column) fill-column)
  3086. nil ; do not to fill
  3087. (if (or (not idlwave-fill-comment-line-only)
  3088. (save-excursion
  3089. ;; Check for comment line
  3090. (beginning-of-line)
  3091. (looking-at idlwave-comment-line-start-skip)))
  3092. (let (beg)
  3093. (idlwave-indent-line)
  3094. ;; Prevent actions do-auto-fill which calls indent-line-function.
  3095. (let (idlwave-do-actions
  3096. (paragraph-separate ".")
  3097. (fill-nobreak-predicate
  3098. (if (and (idlwave-in-quote)
  3099. idlwave-auto-fill-split-string)
  3100. (lambda () ;; We'll need 5 spaces for " ' + $"
  3101. (<= (- fill-column (current-column)) 5)
  3102. ))))
  3103. (do-auto-fill))
  3104. (save-excursion
  3105. (end-of-line 0)
  3106. ;; Indent the split line
  3107. (idlwave-indent-line))
  3108. (if (save-excursion
  3109. (beginning-of-line)
  3110. (looking-at idlwave-comment-line-start-skip))
  3111. ;; A continued line comment
  3112. ;; We treat continued line comments as part of a comment
  3113. ;; paragraph. So we check for a hanging indent.
  3114. (if idlwave-hanging-indent
  3115. (let ((here (- (point-max) (point)))
  3116. (indent
  3117. (save-excursion
  3118. (forward-line -1)
  3119. (idlwave-calc-hanging-indent))))
  3120. (when indent
  3121. ;; Remove whitespace between comment delimiter and
  3122. ;; text, insert spaces for appropriate indentation.
  3123. (beginning-of-line)
  3124. (re-search-forward comment-start-skip (point-at-eol) t)
  3125. (delete-horizontal-space)
  3126. (idlwave-indent-to indent)
  3127. (goto-char (- (point-max) here)))))
  3128. ;; Split code or comment?
  3129. (if (save-excursion
  3130. (end-of-line 0)
  3131. (idlwave-in-comment))
  3132. ;; Splitting a non-full-line comment.
  3133. ;; Insert the comment delimiter from split line
  3134. (progn
  3135. (save-excursion
  3136. (beginning-of-line)
  3137. (skip-chars-forward " \t")
  3138. ;; Insert blank to keep off beginning of line
  3139. (insert " "
  3140. (save-excursion
  3141. (forward-line -1)
  3142. (buffer-substring (idlwave-goto-comment)
  3143. (progn
  3144. (skip-chars-forward "; ")
  3145. (point))))))
  3146. (idlwave-indent-line))
  3147. ;; Split code line - add continuation character
  3148. (save-excursion
  3149. (end-of-line 0)
  3150. ;; Check to see if we split a string
  3151. (if (and (setq beg (idlwave-in-quote))
  3152. idlwave-auto-fill-split-string)
  3153. ;; Split the string and concatenate.
  3154. ;; The first extra space is for the space
  3155. ;; the line was split. That space was removed.
  3156. (insert " " (char-after beg) " +"))
  3157. (insert " $"))
  3158. (if beg
  3159. (if idlwave-auto-fill-split-string
  3160. ;; Make the second part of continued string
  3161. (save-excursion
  3162. (beginning-of-line)
  3163. (skip-chars-forward " \t")
  3164. (insert (char-after beg)))
  3165. ;; Warning
  3166. (beep)
  3167. (message "Warning: continuation inside a string.")))
  3168. ;; Although do-auto-fill (via indent-new-comment-line) calls
  3169. ;; idlwave-indent-line for the new line, re-indent again
  3170. ;; because of the addition of the continuation character.
  3171. (idlwave-indent-line))
  3172. )))))
  3173. (defun idlwave-auto-fill-mode (arg)
  3174. "Toggle auto-fill mode for IDL mode.
  3175. With arg, turn auto-fill mode on if arg is positive.
  3176. In auto-fill mode, inserting a space at a column beyond `fill-column'
  3177. automatically breaks the line at a previous space."
  3178. (interactive "P")
  3179. (prog1 (set idlwave-fill-function
  3180. (if (if (null arg)
  3181. (not (symbol-value idlwave-fill-function))
  3182. (> (prefix-numeric-value arg) 0))
  3183. 'idlwave-auto-fill
  3184. nil))
  3185. ;; update mode-line
  3186. (set-buffer-modified-p (buffer-modified-p))))
  3187. ;(defun idlwave-fill-routine-call ()
  3188. ; "Fill a routine definition or statement, indenting appropriately."
  3189. ; (let ((where (idlwave-where)))))
  3190. (defun idlwave-doc-header (&optional nomark)
  3191. "Insert a documentation header at the beginning of the unit.
  3192. Inserts the value of the variable `idlwave-file-header'. Sets mark
  3193. before moving to do insertion unless the optional prefix argument
  3194. NOMARK is non-nil."
  3195. (interactive "P")
  3196. (or nomark (push-mark))
  3197. ;; make sure we catch the current line if it begins the unit
  3198. (if idlwave-header-to-beginning-of-file
  3199. (goto-char (point-min))
  3200. (end-of-line)
  3201. (idlwave-beginning-of-subprogram)
  3202. (beginning-of-line)
  3203. ;; skip function or procedure line
  3204. (if (idlwave-look-at "\\<\\(pro\\|function\\)\\>")
  3205. (progn
  3206. (idlwave-end-of-statement)
  3207. (if (> (forward-line 1) 0) (insert "\n")))))
  3208. (let ((pos (point)))
  3209. (if idlwave-file-header
  3210. (cond ((car idlwave-file-header)
  3211. (insert-file-contents (car idlwave-file-header)))
  3212. ((stringp (car (cdr idlwave-file-header)))
  3213. (insert (car (cdr idlwave-file-header))))))
  3214. (goto-char pos)))
  3215. (defun idlwave-default-insert-timestamp ()
  3216. "Default timestamp insertion function."
  3217. (insert (current-time-string))
  3218. (insert ", " (user-full-name))
  3219. (if (boundp 'user-mail-address)
  3220. (insert " <" user-mail-address ">")
  3221. (insert " <" (user-login-name) "@" (system-name) ">"))
  3222. ;; Remove extra spaces from line
  3223. (idlwave-fill-paragraph)
  3224. ;; Insert a blank line comment to separate from the date entry -
  3225. ;; will keep the entry from flowing onto date line if re-filled.
  3226. (insert "\n;\n;\t\t"))
  3227. (defun idlwave-doc-modification ()
  3228. "Insert a brief modification log at the beginning of the current program.
  3229. Looks for an occurrence of the value of user variable
  3230. `idlwave-doc-modifications-keyword' if non-nil. Inserts time and user
  3231. name and places the point for the user to add a log. Before moving, saves
  3232. location on mark ring so that the user can return to previous point."
  3233. (interactive)
  3234. (push-mark)
  3235. (let* (beg end)
  3236. (if (and (or (re-search-backward idlwave-doclib-start nil t)
  3237. (progn
  3238. (goto-char (point-min))
  3239. (re-search-forward idlwave-doclib-start nil t)))
  3240. (setq beg (match-beginning 0))
  3241. (re-search-forward idlwave-doclib-end nil t)
  3242. (setq end (match-end 0)))
  3243. (progn
  3244. (goto-char beg)
  3245. (if (re-search-forward
  3246. (concat idlwave-doc-modifications-keyword ":")
  3247. end t)
  3248. (end-of-line)
  3249. (goto-char end)
  3250. (end-of-line -1)
  3251. (insert "\n" comment-start "\n")
  3252. (insert comment-start " " idlwave-doc-modifications-keyword ":"))
  3253. (insert "\n;\n;\t")
  3254. (run-hooks 'idlwave-timestamp-hook))
  3255. (error "No valid DOCLIB header"))))
  3256. ;; CJC 3/16/93
  3257. ;; Interface to expand-region-abbrevs which did not work when the
  3258. ;; abbrev hook associated with an abbrev moves point backwards
  3259. ;; after abbrev expansion, e.g., as with the abbrev '.n'.
  3260. ;; The original would enter an infinite loop in attempting to expand
  3261. ;; .n (it would continually expand and unexpand the abbrev without expanding
  3262. ;; because the point would keep going back to the beginning of the
  3263. ;; abbrev instead of to the end of the abbrev). We now keep the
  3264. ;; abbrev hook from moving backwards.
  3265. ;;;
  3266. (defun idlwave-expand-region-abbrevs (start end)
  3267. "Expand each abbrev occurrence in the region.
  3268. Calling from a program, arguments are START END."
  3269. (interactive "r")
  3270. (save-excursion
  3271. (goto-char (min start end))
  3272. (let ((idlwave-show-block nil) ;Do not blink
  3273. (idlwave-abbrev-move nil)) ;Do not move
  3274. (expand-region-abbrevs start end 'noquery))))
  3275. (defun idlwave-quoted ()
  3276. "Return t if point is in a comment or quoted string.
  3277. Returns nil otherwise."
  3278. (or (idlwave-in-comment) (idlwave-in-quote)))
  3279. (defun idlwave-in-quote ()
  3280. "Return location of the opening quote
  3281. if point is in a IDL string constant, nil otherwise.
  3282. Ignores comment delimiters on the current line.
  3283. Properly handles nested quotation marks and octal
  3284. constants - a double quote followed by an octal digit."
  3285. ;; Treat an octal inside an apostrophe to be a normal string. Treat a
  3286. ;; double quote followed by an octal digit to be an octal constant
  3287. ;; rather than a string. Therefore, there is no terminating double
  3288. ;; quote.
  3289. (save-excursion
  3290. ;; Because single and double quotes can quote each other we must
  3291. ;; search for the string start from the beginning of line.
  3292. (let* ((start (point))
  3293. (eol (point-at-eol))
  3294. (bq (progn (beginning-of-line) (point)))
  3295. (endq (point))
  3296. (data (match-data))
  3297. delim
  3298. found)
  3299. (while (< endq start)
  3300. ;; Find string start
  3301. ;; Don't find an octal constant beginning with a double quote
  3302. (if (re-search-forward "[\"']" eol 'lim)
  3303. ;; Find the string end.
  3304. ;; In IDL, two consecutive delimiters after the start of a
  3305. ;; string act as an
  3306. ;; escape for the delimiter in the string.
  3307. ;; Two consecutive delimiters alone (i.e., not after the
  3308. ;; start of a string) is the null string.
  3309. (progn
  3310. ;; Move to position after quote
  3311. (goto-char (1+ (match-beginning 0)))
  3312. (setq bq (1- (point)))
  3313. ;; Get the string delimiter
  3314. (setq delim (char-to-string (preceding-char)))
  3315. ;; Check for null string
  3316. (if (looking-at delim)
  3317. (progn (setq endq (point)) (forward-char 1))
  3318. ;; Look for next unpaired delimiter
  3319. (setq found (search-forward delim eol 'lim))
  3320. (while (looking-at delim)
  3321. (forward-char 1)
  3322. (setq found (search-forward delim eol 'lim)))
  3323. (setq endq (if found (1- (point)) (point)))
  3324. ))
  3325. (progn (setq bq (point)) (setq endq (point)))))
  3326. (store-match-data data)
  3327. ;; return string beginning position or nil
  3328. (if (> start bq) bq))))
  3329. (defun idlwave-is-pointer-dereference (&optional limit)
  3330. "Determine if the character after point is a pointer dereference *."
  3331. (and
  3332. (eq (char-after) ?\*)
  3333. (not (idlwave-in-quote))
  3334. (save-excursion
  3335. (forward-char)
  3336. (re-search-backward (concat "\\(" idlwave-idl-keywords
  3337. "\\|[[(*+-/=,^><]\\)\\s-*\\*") limit t))))
  3338. ;; Statement templates
  3339. ;; Replace these with a general template function, something like
  3340. ;; expand.el (I think there was also something with a name similar to
  3341. ;; dmacro.el)
  3342. (defun idlwave-template (s1 s2 &optional prompt noindent)
  3343. "Build a template with optional prompt expression.
  3344. Opens a line if point is not followed by a newline modulo intervening
  3345. whitespace. S1 and S2 are strings. S1 is inserted at point followed
  3346. by S2. Point is inserted between S1 and S2. The case of S1 and S2 is
  3347. adjusted according to `idlwave-abbrev-change-case'. If optional
  3348. argument PROMPT is a string then it is displayed as a message in the
  3349. minibuffer. The PROMPT serves as a reminder to the user of an
  3350. expression to enter.
  3351. The lines containing S1 and S2 are reindented using `indent-region'
  3352. unless the optional second argument NOINDENT is non-nil."
  3353. (if (derived-mode-p 'idlwave-shell-mode)
  3354. ;; This is a gross hack to avoit template abbrev expansion
  3355. ;; in the shell. FIXME: This is a dirty hack.
  3356. (if (and (eq this-command 'self-insert-command)
  3357. (equal last-abbrev-location (point)))
  3358. (insert last-abbrev-text)
  3359. (error "No templates in idlwave-shell"))
  3360. (cond ((eq idlwave-abbrev-change-case 'down)
  3361. (setq s1 (downcase s1) s2 (downcase s2)))
  3362. (idlwave-abbrev-change-case
  3363. (setq s1 (upcase s1) s2 (upcase s2))))
  3364. (let ((beg (point-at-bol))
  3365. end)
  3366. (if (not (looking-at "\\s-*\n"))
  3367. (open-line 1))
  3368. (insert s1)
  3369. (save-excursion
  3370. (insert s2)
  3371. (setq end (point)))
  3372. (if (not noindent)
  3373. (indent-region beg end nil))
  3374. (if (stringp prompt)
  3375. (message "%s" prompt)))))
  3376. (defun idlwave-rw-case (string)
  3377. "Make STRING have the case required by `idlwave-reserved-word-upcase'."
  3378. (if idlwave-reserved-word-upcase
  3379. (upcase string)
  3380. string))
  3381. (defun idlwave-elif ()
  3382. "Build skeleton IDL if-else block."
  3383. (interactive)
  3384. (idlwave-template
  3385. (idlwave-rw-case "if")
  3386. (idlwave-rw-case " then begin\n\nendif else begin\n\nendelse")
  3387. "Condition expression"))
  3388. (defun idlwave-case ()
  3389. "Build skeleton IDL case statement."
  3390. (interactive)
  3391. (idlwave-template
  3392. (idlwave-rw-case "case")
  3393. (idlwave-rw-case " of\n\nendcase")
  3394. "Selector expression"))
  3395. (defun idlwave-switch ()
  3396. "Build skeleton IDL switch statement."
  3397. (interactive)
  3398. (idlwave-template
  3399. (idlwave-rw-case "switch")
  3400. (idlwave-rw-case " of\n\nendswitch")
  3401. "Selector expression"))
  3402. (defun idlwave-for ()
  3403. "Build skeleton IDL loop statement."
  3404. (interactive)
  3405. (idlwave-template
  3406. (idlwave-rw-case "for")
  3407. (idlwave-rw-case " do begin\n\nendfor")
  3408. "Loop expression"))
  3409. (defun idlwave-if ()
  3410. "Build skeleton IDL if statement."
  3411. (interactive)
  3412. (idlwave-template
  3413. (idlwave-rw-case "if")
  3414. (idlwave-rw-case " then begin\n\nendif")
  3415. "Scalar logical expression"))
  3416. (defun idlwave-procedure ()
  3417. (interactive)
  3418. (idlwave-template
  3419. (idlwave-rw-case "pro")
  3420. (idlwave-rw-case "\n\nreturn\nend")
  3421. "Procedure name"))
  3422. (defun idlwave-function ()
  3423. (interactive)
  3424. (idlwave-template
  3425. (idlwave-rw-case "function")
  3426. (idlwave-rw-case "\n\nreturn\nend")
  3427. "Function name"))
  3428. (defun idlwave-repeat ()
  3429. (interactive)
  3430. (idlwave-template
  3431. (idlwave-rw-case "repeat begin\n\nendrep until")
  3432. (idlwave-rw-case "")
  3433. "Exit condition"))
  3434. (defun idlwave-while ()
  3435. (interactive)
  3436. (idlwave-template
  3437. (idlwave-rw-case "while")
  3438. (idlwave-rw-case " do begin\n\nendwhile")
  3439. "Entry condition"))
  3440. (defun idlwave-split-string (string &optional pattern)
  3441. "Return a list of substrings of STRING which are separated by PATTERN.
  3442. If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
  3443. (or pattern
  3444. (setq pattern "[ \f\t\n\r\v]+"))
  3445. (let (parts (start 0))
  3446. (while (string-match pattern string start)
  3447. (setq parts (cons (substring string start (match-beginning 0)) parts)
  3448. start (match-end 0)))
  3449. (nreverse (cons (substring string start) parts))))
  3450. (defun idlwave-replace-string (string replace_string replace_with)
  3451. (let* ((start 0)
  3452. (last (length string))
  3453. (ret_string "")
  3454. end)
  3455. (while (setq end (string-match replace_string string start))
  3456. (setq ret_string
  3457. (concat ret_string (substring string start end) replace_with))
  3458. (setq start (match-end 0)))
  3459. (setq ret_string (concat ret_string (substring string start last)))))
  3460. (defun idlwave-get-buffer-visiting (file)
  3461. ;; Return the buffer currently visiting FILE
  3462. (cond
  3463. ((boundp 'find-file-compare-truenames) ; XEmacs
  3464. (let ((find-file-compare-truenames t))
  3465. (get-file-buffer file)))
  3466. ((fboundp 'find-buffer-visiting) ; Emacs
  3467. (find-buffer-visiting file))
  3468. (t (error "This should not happen (idlwave-get-buffer-visiting)"))))
  3469. (defvar idlwave-outlawed-buffers nil
  3470. "List of buffers pulled up by IDLWAVE for special reasons.
  3471. Buffers in this list may be killed by `idlwave-kill-autoloaded-buffers'.")
  3472. (defun idlwave-find-file-noselect (file &optional why)
  3473. ;; Return a buffer visiting file.
  3474. (or (idlwave-get-buffer-visiting file)
  3475. (let ((buf (find-file-noselect file)))
  3476. (if why (add-to-list 'idlwave-outlawed-buffers (cons buf why)))
  3477. buf)))
  3478. (defun idlwave-kill-autoloaded-buffers ()
  3479. "Kill buffers created automatically by IDLWAVE.
  3480. Function prompts for a letter to identify the buffers to kill.
  3481. Possible letters are:
  3482. f Buffers created by the command \\[idlwave-find-module] or mouse
  3483. clicks in the routine info window.
  3484. s Buffers created by the IDLWAVE Shell to display where execution
  3485. stopped or an error was found.
  3486. a Both of the above.
  3487. Buffers containing unsaved changes require confirmation before they are killed."
  3488. (interactive)
  3489. (if (null idlwave-outlawed-buffers)
  3490. (error "No IDLWAVE-created buffers available")
  3491. (princ (format "Kill IDLWAVE-created buffers: [f]ind source(%d), [s]hell display(%d), [a]ll ? "
  3492. (idlwave-count-outlawed-buffers 'find)
  3493. (idlwave-count-outlawed-buffers 'shell)))
  3494. (let ((c (read-char)))
  3495. (cond
  3496. ((member c '(?f ?\C-f))
  3497. (idlwave-do-kill-autoloaded-buffers 'find))
  3498. ((member c '(?s ?\C-s))
  3499. (idlwave-do-kill-autoloaded-buffers 'shell))
  3500. ((member c '(?a ?\C-a))
  3501. (idlwave-do-kill-autoloaded-buffers t))
  3502. (t (error "Abort"))))))
  3503. (defun idlwave-count-outlawed-buffers (tag)
  3504. "How many outlawed buffers have tag TAG?"
  3505. (length (delq nil
  3506. (mapcar
  3507. (lambda (x) (eq (cdr x) tag))
  3508. idlwave-outlawed-buffers))))
  3509. (defun idlwave-do-kill-autoloaded-buffers (&rest reasons)
  3510. "Kill all buffers pulled up by IDLWAVE matching REASONS."
  3511. (let* ((list (copy-sequence idlwave-outlawed-buffers))
  3512. (cnt 0)
  3513. entry)
  3514. (while (setq entry (pop list))
  3515. (if (buffer-live-p (car entry))
  3516. (and (or (memq t reasons)
  3517. (memq (cdr entry) reasons))
  3518. (kill-buffer (car entry))
  3519. (incf cnt)
  3520. (setq idlwave-outlawed-buffers
  3521. (delq entry idlwave-outlawed-buffers)))
  3522. (setq idlwave-outlawed-buffers
  3523. (delq entry idlwave-outlawed-buffers))))
  3524. (message "%d buffer%s killed" cnt (if (= cnt 1) "" "s"))))
  3525. (defun idlwave-revoke-license-to-kill ()
  3526. "Remove BUFFER from the buffers which may be killed.
  3527. Killing would be done by `idlwave-do-kill-autoloaded-buffers'.
  3528. Intended for `after-save-hook'."
  3529. (let* ((buf (current-buffer))
  3530. (entry (assq buf idlwave-outlawed-buffers)))
  3531. ;; Revoke license
  3532. (if entry
  3533. (setq idlwave-outlawed-buffers
  3534. (delq entry idlwave-outlawed-buffers)))
  3535. ;; Remove this function from the hook.
  3536. (remove-hook 'after-save-hook 'idlwave-revoke-license-to-kill 'local)))
  3537. (defvar idlwave-path-alist)
  3538. (defun idlwave-locate-lib-file (file)
  3539. ;; Find FILE on the scanned lib path and return a buffer visiting it
  3540. (let* ((dirs idlwave-path-alist)
  3541. dir efile)
  3542. (catch 'exit
  3543. (while (setq dir (car (pop dirs)))
  3544. (if (file-regular-p
  3545. (setq efile (expand-file-name file dir)))
  3546. (throw 'exit efile))))))
  3547. (defun idlwave-expand-lib-file-name (file)
  3548. ;; Find FILE on the scanned lib path and return a buffer visiting it
  3549. ;; This is for, e.g., finding source with no user catalog
  3550. (cond
  3551. ((null file) nil)
  3552. ((file-name-absolute-p file) file)
  3553. (t (idlwave-locate-lib-file file))))
  3554. (defun idlwave-make-tags ()
  3555. "Create the IDL tags file IDLTAGS in the current directory from
  3556. the list of directories specified in the minibuffer. Directories may be
  3557. for example: . /usr/local/rsi/idl/lib. All the subdirectories of the
  3558. specified top directories are searched if the directory name is prefixed
  3559. by @. Specify @ directories with care, it may take a long, long time if
  3560. you specify /."
  3561. (interactive)
  3562. (let (directory directories cmd append status numdirs dir getsubdirs
  3563. buffer save_buffer files numfiles item errbuf)
  3564. ;;
  3565. ;; Read list of directories
  3566. (setq directory (read-string "Tag Directories: " "."))
  3567. (setq directories (idlwave-split-string directory "[ \t]+"))
  3568. ;;
  3569. ;; Set etags command, vars
  3570. (setq cmd "etags --output=IDLTAGS --language=none --regex='/[
  3571. \\t]*[pP][Rr][Oo][ \\t]+\\([^ \\t,]+\\)/' --regex='/[
  3572. \\t]*[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn][ \\t]+\\([^ \\t,]+\\)/' ")
  3573. (setq append " ")
  3574. (setq status 0)
  3575. ;;
  3576. ;; For each directory
  3577. (setq numdirs 0)
  3578. (setq dir (nth numdirs directories))
  3579. (while (and dir)
  3580. ;;
  3581. ;; Find the subdirectories
  3582. (if (string-match "^[@]\\(.+\\)$" dir)
  3583. (setq getsubdirs t) (setq getsubdirs nil))
  3584. (if (and getsubdirs) (setq dir (substring dir 1 (length dir))))
  3585. (setq dir (expand-file-name dir))
  3586. (if (file-directory-p dir)
  3587. (progn
  3588. (if (and getsubdirs)
  3589. (progn
  3590. (setq buffer (get-buffer-create "*idltags*"))
  3591. (call-process "sh" nil buffer nil "-c"
  3592. (concat "find " dir " -type d -print"))
  3593. (setq save_buffer (current-buffer))
  3594. (set-buffer buffer)
  3595. (setq files (idlwave-split-string
  3596. (idlwave-replace-string
  3597. (buffer-substring 1 (point-max))
  3598. "\n" "/*.pro ")
  3599. "[ \t]+"))
  3600. (set-buffer save_buffer)
  3601. (kill-buffer buffer))
  3602. (setq files (list (concat dir "/*.pro"))))
  3603. ;;
  3604. ;; For each subdirectory
  3605. (setq numfiles 0)
  3606. (setq item (nth numfiles files))
  3607. (while (and item)
  3608. ;;
  3609. ;; Call etags
  3610. (if (not (string-match "^[ \\t]*$" item))
  3611. (progn
  3612. (message "%s" (concat "Tagging " item "..."))
  3613. (setq errbuf (get-buffer-create "*idltags-error*"))
  3614. (setq status (+ status
  3615. (if (eq 0 (call-process
  3616. "sh" nil errbuf nil "-c"
  3617. (concat cmd append item)))
  3618. 0
  3619. 1)))
  3620. ;;
  3621. ;; Append additional tags
  3622. (setq append " --append ")
  3623. (setq numfiles (1+ numfiles))
  3624. (setq item (nth numfiles files)))
  3625. (progn
  3626. (setq numfiles (1+ numfiles))
  3627. (setq item (nth numfiles files))
  3628. )))
  3629. (setq numdirs (1+ numdirs))
  3630. (setq dir (nth numdirs directories)))
  3631. (progn
  3632. (setq numdirs (1+ numdirs))
  3633. (setq dir (nth numdirs directories)))))
  3634. (setq errbuf (get-buffer-create "*idltags-error*"))
  3635. (if (= status 0)
  3636. (kill-buffer errbuf))
  3637. (message "")
  3638. ))
  3639. (defun idlwave-toggle-comment-region (beg end &optional n)
  3640. "Comment the lines in the region if the first non-blank line is
  3641. commented, and conversely, uncomment region. If optional prefix arg
  3642. N is non-nil, then for N positive, add N comment delimiters or for N
  3643. negative, remove N comment delimiters.
  3644. Uses `comment-region' which does not place comment delimiters on
  3645. blank lines."
  3646. (interactive "r\nP")
  3647. (if n
  3648. (comment-region beg end (prefix-numeric-value n))
  3649. (save-excursion
  3650. (goto-char beg)
  3651. (beginning-of-line)
  3652. ;; skip blank lines
  3653. (skip-chars-forward " \t\n")
  3654. (if (looking-at (concat "[ \t]*\\(" comment-start "+\\)"))
  3655. (if (fboundp 'uncomment-region)
  3656. (uncomment-region beg end)
  3657. (comment-region beg end
  3658. (- (length (buffer-substring
  3659. (match-beginning 1)
  3660. (match-end 1))))))
  3661. (comment-region beg end)))))
  3662. ;; ----------------------------------------------------------------------------
  3663. ;; ----------------------------------------------------------------------------
  3664. ;; ----------------------------------------------------------------------------
  3665. ;; ----------------------------------------------------------------------------
  3666. ;;
  3667. ;; Completion and Routine Info
  3668. ;;
  3669. ;; String "intern" functions
  3670. ;; For the completion and routine info function, we want to normalize
  3671. ;; the case of procedure names etc. We do this by "interning" these
  3672. ;; string is a hand-crafted way. Hashes are used to map the downcase
  3673. ;; version of the strings to the cased versions. Most *-sint-*
  3674. ;; variables consist of *two* hashes, a buffer+shell, followed by a
  3675. ;; system hash. The former is re-scanned, and the latter takes case
  3676. ;; precedence.
  3677. ;;
  3678. ;; Since these cased versions are really lisp objects, we can use `eq'
  3679. ;; to search, which is a large performance boost. All new strings
  3680. ;; need to be "sinterned". We do this as early as possible after
  3681. ;; getting these strings from completion or buffer substrings. So
  3682. ;; most of the code can simply assume to deal with "sinterned"
  3683. ;; strings. The only exception is that the functions which scan whole
  3684. ;; buffers for routine information do not intern the grabbed strings.
  3685. ;; This is only done afterwards. Therefore in these functions it is
  3686. ;; *not* safe to assume the strings can be compared with `eq' and be
  3687. ;; fed into the routine assq functions.
  3688. ;; Here we define the hashing functions.
  3689. ;; The variables which hold the hashes.
  3690. (defvar idlwave-sint-routines '(nil))
  3691. (defvar idlwave-sint-keywords '(nil))
  3692. (defvar idlwave-sint-methods '(nil))
  3693. (defvar idlwave-sint-classes '(nil))
  3694. (defvar idlwave-sint-dirs '(nil))
  3695. (defvar idlwave-sint-libnames '(nil))
  3696. (defun idlwave-reset-sintern (&optional what)
  3697. "Reset all sintern hashes."
  3698. ;; Make sure the hash functions are accessible.
  3699. (unless (and (fboundp 'gethash)
  3700. (fboundp 'puthash))
  3701. (require 'cl)
  3702. (or (fboundp 'puthash)
  3703. (defalias 'puthash 'cl-puthash)))
  3704. (let ((entries '((idlwave-sint-routines 1000 10)
  3705. (idlwave-sint-keywords 1000 10)
  3706. (idlwave-sint-methods 100 10)
  3707. (idlwave-sint-classes 10 10))))
  3708. ;; Make sure these are lists
  3709. (loop for entry in entries
  3710. for var = (car entry)
  3711. do (if (not (consp (symbol-value var))) (set var (list nil))))
  3712. ;; Reset the system & library hash
  3713. (when (or (eq what t) (eq what 'syslib)
  3714. (null (cdr idlwave-sint-routines)))
  3715. (loop for entry in entries
  3716. for var = (car entry) for size = (nth 1 entry)
  3717. do (setcdr (symbol-value var)
  3718. (make-hash-table ':size size ':test 'equal)))
  3719. (setq idlwave-sint-dirs nil
  3720. idlwave-sint-libnames nil))
  3721. ;; Reset the buffer & shell hash
  3722. (when (or (eq what t) (eq what 'bufsh)
  3723. (null (car idlwave-sint-routines)))
  3724. (loop for entry in entries
  3725. for var = (car entry) for size = (nth 1 entry)
  3726. do (setcar (symbol-value var)
  3727. (make-hash-table ':size size ':test 'equal))))))
  3728. (defun idlwave-sintern-routine-or-method (name &optional class set)
  3729. (if class
  3730. (idlwave-sintern-method name set)
  3731. (idlwave-sintern-routine name set)))
  3732. (defun idlwave-sintern (stype &rest args)
  3733. (apply (intern (concat "idlwave-sintern-" (symbol-name stype))) args))
  3734. ;;(defmacro idlwave-sintern (type var)
  3735. ;; `(cond ((not (stringp name)) name)
  3736. ;; ((gethash (downcase name) (cdr ,var)))
  3737. ;; ((gethash (downcase name) (car ,var)))
  3738. ;; (set (idlwave-sintern-set name ,type ,var set))
  3739. ;; (name)))
  3740. (defun idlwave-sintern-routine (name &optional set)
  3741. (cond ((not (stringp name)) name)
  3742. ((gethash (downcase name) (cdr idlwave-sint-routines)))
  3743. ((gethash (downcase name) (car idlwave-sint-routines)))
  3744. (set (idlwave-sintern-set name 'routine idlwave-sint-routines set))
  3745. (name)))
  3746. (defun idlwave-sintern-keyword (name &optional set)
  3747. (cond ((not (stringp name)) name)
  3748. ((gethash (downcase name) (cdr idlwave-sint-keywords)))
  3749. ((gethash (downcase name) (car idlwave-sint-keywords)))
  3750. (set (idlwave-sintern-set name 'keyword idlwave-sint-keywords set))
  3751. (name)))
  3752. (defun idlwave-sintern-method (name &optional set)
  3753. (cond ((not (stringp name)) name)
  3754. ((gethash (downcase name) (cdr idlwave-sint-methods)))
  3755. ((gethash (downcase name) (car idlwave-sint-methods)))
  3756. (set (idlwave-sintern-set name 'method idlwave-sint-methods set))
  3757. (name)))
  3758. (defun idlwave-sintern-class (name &optional set)
  3759. (cond ((not (stringp name)) name)
  3760. ((gethash (downcase name) (cdr idlwave-sint-classes)))
  3761. ((gethash (downcase name) (car idlwave-sint-classes)))
  3762. (set (idlwave-sintern-set name 'class idlwave-sint-classes set))
  3763. (name)))
  3764. (defun idlwave-sintern-dir (dir &optional set)
  3765. (car (or (member dir idlwave-sint-dirs)
  3766. (setq idlwave-sint-dirs (cons dir idlwave-sint-dirs)))))
  3767. (defun idlwave-sintern-libname (name &optional set)
  3768. (car (or (member name idlwave-sint-libnames)
  3769. (setq idlwave-sint-libnames (cons name idlwave-sint-libnames)))))
  3770. (defun idlwave-sintern-set (name type tables set)
  3771. (let* ((func (or (cdr (assq type idlwave-completion-case))
  3772. 'identity))
  3773. (iname (funcall (if (eq func 'preserve) 'identity func) name))
  3774. (table (if (eq set 'sys) (cdr tables) (car tables))))
  3775. (puthash (downcase name) iname table)
  3776. iname))
  3777. (defun idlwave-sintern-keyword-list (kwd-list &optional set)
  3778. "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
  3779. (mapc (lambda(x)
  3780. (setcar x (idlwave-sintern-keyword (car x) set)))
  3781. (cdr kwd-list))
  3782. kwd-list)
  3783. (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
  3784. "Sintern all strings in the rinfo LIST.
  3785. With optional parameter SET: also set new patterns. Probably this
  3786. will always have to be t. If DEFAULT-DIR is passed, it is used as
  3787. the base of the directory."
  3788. (let (entry name type class kwds res source call new)
  3789. (while list
  3790. (setq entry (car list)
  3791. list (cdr list)
  3792. name (car entry)
  3793. type (nth 1 entry)
  3794. class (nth 2 entry)
  3795. source (nth 3 entry)
  3796. call (nth 4 entry)
  3797. kwds (nthcdr 5 entry))
  3798. ;; The class and name
  3799. (if class
  3800. (progn
  3801. (if (symbolp class) (setq class (symbol-name class)))
  3802. (setq class (idlwave-sintern-class class set))
  3803. (setq name (idlwave-sintern-method name set)))
  3804. (setq name (idlwave-sintern-routine name set)))
  3805. ;; The source
  3806. (let ((source-type (car source))
  3807. (source-file (nth 1 source))
  3808. (source-dir (if default-dir
  3809. (file-name-as-directory default-dir)
  3810. (nth 2 source)))
  3811. (source-lib (nth 3 source)))
  3812. (if (stringp source-dir)
  3813. (setq source-dir (idlwave-sintern-dir source-dir set)))
  3814. (if (stringp source-lib)
  3815. (setq source-lib (idlwave-sintern-libname source-lib set)))
  3816. (setq source (list source-type source-file source-dir source-lib)))
  3817. ;; The keywords
  3818. (setq kwds (mapcar (lambda (x)
  3819. (idlwave-sintern-keyword-list x set))
  3820. kwds))
  3821. ;; Build a canonicalized list
  3822. (setq new (nconc (list name type class source call) kwds)
  3823. res (cons new res)))
  3824. (nreverse res)))
  3825. ;; Creating new sintern tables
  3826. (defun idlwave-new-sintern-type (tag)
  3827. "Define a variable and a function to sintern the new type TAG.
  3828. This defines the function `idlwave-sintern-TAG' and the variable
  3829. `idlwave-sint-TAGs'."
  3830. (let* ((name (symbol-name tag))
  3831. (names (concat name "s"))
  3832. (var (intern (concat "idlwave-sint-" names)))
  3833. (func (intern (concat "idlwave-sintern-" name))))
  3834. (set var nil) ; initial value of the association list
  3835. (fset func ; set the function
  3836. `(lambda (name &optional set)
  3837. (cond ((not (stringp name)) name)
  3838. ((cdr (assoc (downcase name) ,var)))
  3839. (set
  3840. (setq ,var (cons (cons (downcase name) name) ,var))
  3841. name)
  3842. (name))))))
  3843. (defun idlwave-reset-sintern-type (tag)
  3844. "Reset the sintern variable associated with TAG."
  3845. (set (intern (concat "idlwave-sint-" (symbol-name tag) "s")) nil))
  3846. ;;---------------------------------------------------------------------------
  3847. ;; The variables which hold the information
  3848. (defvar idlwave-system-routines nil
  3849. "Holds the routine-info obtained by scanning buffers.")
  3850. (defvar idlwave-buffer-routines nil
  3851. "Holds the routine-info obtained by scanning buffers.")
  3852. (defvar idlwave-compiled-routines nil
  3853. "Holds the routine-info obtained by asking the shell.")
  3854. (defvar idlwave-unresolved-routines nil
  3855. "Holds the unresolved routine-info obtained by asking the shell.")
  3856. (defvar idlwave-user-catalog-routines nil
  3857. "Holds the procedure routine-info from the user scan.")
  3858. (defvar idlwave-library-catalog-routines nil
  3859. "Holds the procedure routine-info from the .idlwave_catalog library files.")
  3860. (defvar idlwave-library-catalog-libname nil
  3861. "Name of library catalog loaded from .idlwave_catalog files.")
  3862. (defvar idlwave-path-alist nil
  3863. "Alist with !PATH directories and zero or more flags if the dir has
  3864. been scanned in a user catalog ('user) or discovered in a library
  3865. catalog \('lib).")
  3866. (defvar idlwave-true-path-alist nil
  3867. "Like `idlwave-path-alist', but with true filenames.")
  3868. (defvar idlwave-routines nil
  3869. "Holds the combined procedure/function/method routine-info.")
  3870. (defvar idlwave-class-alist nil
  3871. "Holds the class names known to IDLWAVE.")
  3872. (defvar idlwave-class-history nil
  3873. "The history of classes selected with the minibuffer.")
  3874. (defvar idlwave-force-class-query nil)
  3875. (defvar idlwave-before-completion-wconf nil
  3876. "The window configuration just before the completion buffer was displayed.")
  3877. (defvar idlwave-last-system-routine-info-cons-cell nil
  3878. "The last cons cell in the system routine info.")
  3879. ;;
  3880. ;; The code to get routine info from different sources.
  3881. (defvar idlwave-system-routines)
  3882. (defvar idlwave-catalog-process nil
  3883. "The background process currently updating the catalog.")
  3884. (defun idlwave-routines ()
  3885. "Provide a list of IDL routines.
  3886. This routine loads the builtin routines on the first call.
  3887. Later it only returns the value of the variable."
  3888. (if (and idlwave-catalog-process
  3889. (processp idlwave-catalog-process))
  3890. (progn
  3891. (cond
  3892. ((equal (process-status idlwave-catalog-process) 'exit)
  3893. (message "updating........")
  3894. (setq idlwave-catalog-process nil)
  3895. (idlwave-update-routine-info '(4)))
  3896. ((equal (process-status idlwave-catalog-process) 'run)
  3897. ;; Keep it running...
  3898. )
  3899. (t
  3900. ;; Something is wrong, get rid of the process
  3901. (message "Problem with catalog process") (beep)
  3902. (condition-case nil
  3903. (kill-process idlwave-catalog-process)
  3904. (error nil))
  3905. (setq idlwave-catalog-process nil)))))
  3906. (or idlwave-routines
  3907. (progn
  3908. (idlwave-update-routine-info)
  3909. ;; return the current value
  3910. idlwave-routines)))
  3911. (defvar idlwave-update-rinfo-hook nil
  3912. "List of functions which should run after a global rinfo update.
  3913. Does not run after automatic updates of buffer or the shell.")
  3914. (defun idlwave-rescan-catalog-directories ()
  3915. "Rescan the previously selected directories. For batch processing."
  3916. (idlwave-update-routine-info '(16)))
  3917. (defun idlwave-rescan-asynchronously ()
  3918. "Dispatch another Emacs instance to update the idlwave catalog.
  3919. After the process finishes normally, the first access to routine info
  3920. will re-read the catalog."
  3921. (interactive)
  3922. (if (processp idlwave-catalog-process)
  3923. (if (eq (process-status idlwave-catalog-process) 'run)
  3924. (if (yes-or-no-p "A catalog-updating process is running. Kill it? ")
  3925. (progn
  3926. (condition-case nil
  3927. (kill-process idlwave-catalog-process)
  3928. (error nil))
  3929. (error "Process killed, no new process started"))
  3930. (error "Quit"))
  3931. (condition-case nil
  3932. (kill-process idlwave-catalog-process)
  3933. (error nil))))
  3934. (if (or (not idlwave-user-catalog-file)
  3935. (not (stringp idlwave-user-catalog-file))
  3936. (not (file-regular-p idlwave-user-catalog-file)))
  3937. (error "No catalog has been produced yet"))
  3938. (let* ((emacs (concat invocation-directory invocation-name))
  3939. (args (list "-batch"
  3940. "-l" (expand-file-name "~/.emacs")
  3941. "-l" "idlwave"
  3942. "-f" "idlwave-rescan-catalog-directories"))
  3943. (process (apply 'start-process "idlcat"
  3944. nil emacs args)))
  3945. (setq idlwave-catalog-process process)
  3946. (set-process-sentinel
  3947. process
  3948. (lambda (pro why)
  3949. (when (string-match "finished" why)
  3950. (setq idlwave-routines nil
  3951. idlwave-system-routines nil
  3952. idlwave-catalog-process nil)
  3953. (or (idlwave-start-load-rinfo-timer)
  3954. (idlwave-update-routine-info '(4))))))
  3955. (message "Background job started to update catalog file")))
  3956. ;; Format for all routine info user catalog, library catalogs, etc.:
  3957. ;;
  3958. ;; ("ROUTINE" type class
  3959. ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
  3960. ;; (buffer pro_file dir) | (compiled pro_file dir)
  3961. ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
  3962. ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
  3963. ;;
  3964. ;; DIR will be supplied dynamically while loading library catalogs,
  3965. ;; and is sinterned to save space, as is LIBNAME. PRO_FILE can be a
  3966. ;; complete filepath, in which case DIR is unnecessary. HELPFILE can
  3967. ;; be nil, as can LINK1, etc., if no HTML help is available.
  3968. (defvar idlwave-load-rinfo-idle-timer)
  3969. (defvar idlwave-shell-path-query)
  3970. (defun idlwave-update-routine-info (&optional arg no-concatenate)
  3971. "Update the internal routine-info lists.
  3972. These lists are used by `idlwave-routine-info' (\\[idlwave-routine-info])
  3973. and by `idlwave-complete' (\\[idlwave-complete]) to provide information
  3974. about individual routines.
  3975. The information can come from 4 sources:
  3976. 1. IDL programs in the current editing session
  3977. 2. Compiled modules in an IDL shell running as Emacs subprocess
  3978. 3. A list which covers the IDL system routines.
  3979. 4. A list which covers the prescanned library files.
  3980. Scans all IDLWAVE-mode buffers of the current editing session (see
  3981. `idlwave-scan-all-buffers-for-routine-info').
  3982. When an IDL shell is running, this command also queries the IDL program
  3983. for currently compiled routines.
  3984. With prefix ARG, also reload the system and library lists.
  3985. With two prefix ARG's, also rescans the chosen user catalog tree.
  3986. With three prefix args, dispatch asynchronous process to do the update.
  3987. If NO-CONCATENATE is non-nil, don't pre-concatenate the routine info
  3988. lists, but instead wait for the shell query to complete and
  3989. asynchronously finish updating routine info. This is set
  3990. automatically when called interactively. When you need routine
  3991. information updated immediately, leave NO-CONCATENATE nil."
  3992. (interactive "P\np")
  3993. ;; Stop any idle processing
  3994. (if (or (and (fboundp 'itimerp)
  3995. (itimerp idlwave-load-rinfo-idle-timer))
  3996. (and (fboundp 'timerp)
  3997. (timerp idlwave-load-rinfo-idle-timer)))
  3998. (cancel-timer idlwave-load-rinfo-idle-timer))
  3999. (cond
  4000. ((equal arg '(64))
  4001. ;; Start a background process which updates the catalog.
  4002. (idlwave-rescan-asynchronously))
  4003. ((equal arg '(16))
  4004. ;; Update the user catalog now, and wait for them.
  4005. (idlwave-create-user-catalog-file t))
  4006. (t
  4007. (let* ((load (or arg
  4008. idlwave-buffer-case-takes-precedence
  4009. (null idlwave-routines)))
  4010. ;; The override-idle means, even if the idle timer has done some
  4011. ;; preparing work, load and renormalize everything anyway.
  4012. (override-idle (or arg idlwave-buffer-case-takes-precedence)))
  4013. (setq idlwave-buffer-routines nil
  4014. idlwave-compiled-routines nil
  4015. idlwave-unresolved-routines nil)
  4016. ;; Reset the appropriate hashes
  4017. (if (get 'idlwave-reset-sintern 'done-by-idle)
  4018. ;; reset was already done in idle time, so skip this step now once
  4019. (put 'idlwave-reset-sintern 'done-by-idle nil)
  4020. (idlwave-reset-sintern (cond (load t)
  4021. ((null idlwave-system-routines) t)
  4022. (t 'bufsh))))
  4023. (if idlwave-buffer-case-takes-precedence
  4024. ;; We can safely scan the buffer stuff first
  4025. (progn
  4026. (idlwave-update-buffer-routine-info)
  4027. (and load (idlwave-load-all-rinfo override-idle)))
  4028. ;; We first do the system info, and then the buffers
  4029. (and load (idlwave-load-all-rinfo override-idle))
  4030. (idlwave-update-buffer-routine-info))
  4031. ;; Let's see if there is a shell
  4032. (let* ((shell-is-running (and (fboundp 'idlwave-shell-is-running)
  4033. (idlwave-shell-is-running)))
  4034. (ask-shell (and shell-is-running
  4035. idlwave-query-shell-for-routine-info)))
  4036. ;; Load the library catalogs again, first re-scanning the path
  4037. (when arg
  4038. (if shell-is-running
  4039. (idlwave-shell-send-command idlwave-shell-path-query
  4040. '(progn
  4041. (idlwave-shell-get-path-info)
  4042. (idlwave-scan-library-catalogs))
  4043. 'hide)
  4044. (idlwave-scan-library-catalogs)))
  4045. (if (or (not ask-shell)
  4046. (not no-concatenate))
  4047. ;; 1. If we are not going to ask the shell, we need to do the
  4048. ;; concatenation now.
  4049. ;; 2. When this function is called non-interactively, it
  4050. ;; means that someone needs routine info *now*. The
  4051. ;; shell update causes the concatenation to be
  4052. ;; *delayed*, so not in time for the current command.
  4053. ;; Therefore, we do a concatenation now, even though
  4054. ;; the shell might do it again.
  4055. (idlwave-concatenate-rinfo-lists nil 'run-hooks))
  4056. (when ask-shell
  4057. ;; Ask the shell about the routines it knows of.
  4058. (message "Querying the shell")
  4059. (idlwave-shell-update-routine-info nil t)))))))
  4060. (defvar idlwave-load-rinfo-steps-done (make-vector 6 nil))
  4061. (defvar idlwave-load-rinfo-idle-timer nil)
  4062. (defun idlwave-start-load-rinfo-timer ()
  4063. (if (or (and (fboundp 'itimerp)
  4064. (itimerp idlwave-load-rinfo-idle-timer))
  4065. (and (fboundp 'timerp)
  4066. (timerp idlwave-load-rinfo-idle-timer)))
  4067. (cancel-timer idlwave-load-rinfo-idle-timer))
  4068. (setq idlwave-load-rinfo-steps-done (make-vector 6 nil))
  4069. (setq idlwave-load-rinfo-idle-timer nil)
  4070. (if (and idlwave-init-rinfo-when-idle-after
  4071. (numberp idlwave-init-rinfo-when-idle-after)
  4072. (not (equal 0 idlwave-init-rinfo-when-idle-after))
  4073. (not idlwave-routines))
  4074. (condition-case nil
  4075. (progn
  4076. (setq idlwave-load-rinfo-idle-timer
  4077. (run-with-idle-timer
  4078. idlwave-init-rinfo-when-idle-after
  4079. nil 'idlwave-load-rinfo-next-step)))
  4080. (error nil))))
  4081. (defvar idlwave-library-routines nil "Obsolete variable.")
  4082. ;;------ XML Help routine info system
  4083. (defun idlwave-load-system-routine-info ()
  4084. ;; Load the system routine info from the cached routine info file,
  4085. ;; which, if necessary, will be re-created from the XML file on
  4086. ;; disk. As a last fallback, load the (likely outdated) idlw-rinfo
  4087. ;; file distributed with older IDLWAVE versions (<6.0)
  4088. (unless (and (load idlwave-xml-system-rinfo-converted-file
  4089. 'noerror 'nomessage)
  4090. (idlwave-xml-system-routine-info-up-to-date))
  4091. ;; See if we can create it from XML source
  4092. (condition-case nil
  4093. (idlwave-convert-xml-system-routine-info)
  4094. (error
  4095. (unless (load idlwave-xml-system-rinfo-converted-file
  4096. 'noerror 'nomessage)
  4097. (if idlwave-system-routines
  4098. (message
  4099. "Failed to load converted routine info, using old conversion.")
  4100. (message
  4101. "Failed to convert XML routine info, falling back on idlw-rinfo.")
  4102. (if (not (load "idlw-rinfo" 'noerror 'nomessage))
  4103. (message
  4104. "Could not locate any system routine information."))))))))
  4105. (defun idlwave-xml-system-routine-info-up-to-date()
  4106. (let* ((dir (file-name-as-directory
  4107. (expand-file-name "help/online_help" (idlwave-sys-dir))))
  4108. (catalog-file (expand-file-name "idl_catalog.xml" dir)))
  4109. (file-newer-than-file-p ;converted file is newer than catalog
  4110. idlwave-xml-system-rinfo-converted-file
  4111. catalog-file)))
  4112. (defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
  4113. (defvar idlwave-system-variables-alist nil
  4114. "Alist of system variables and the associated structure tags.
  4115. Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
  4116. (defvar idlwave-executive-commands-alist nil
  4117. "Alist of system variables and their help files.")
  4118. (defvar idlwave-help-special-topic-words nil)
  4119. (defun idlwave-shorten-syntax (syntax name &optional class)
  4120. ;; From a list of syntax statements, shorten with %s and group with "or"
  4121. (let ((case-fold-search t))
  4122. (mapconcat
  4123. (lambda (x)
  4124. (while (string-match name x)
  4125. (setq x (replace-match "%s" t t x)))
  4126. (if class
  4127. (while (string-match class x)
  4128. (setq x (replace-match "%s" t t x))))
  4129. x)
  4130. (nreverse syntax)
  4131. " or ")))
  4132. (defun idlwave-xml-create-class-method-lists (xml-entry)
  4133. ;; Create a class list entry from the xml parsed list., returning a
  4134. ;; cons of form (class-entry method-entries).
  4135. (let* ((nameblock (nth 1 xml-entry))
  4136. (class (cdr (assq 'name nameblock)))
  4137. (link (cdr (assq 'link nameblock)))
  4138. (params (cddr xml-entry))
  4139. (case-fold-search t)
  4140. class-entry
  4141. method methods-entry extra-kwds
  4142. props get-props set-props init-props inherits
  4143. pelem ptype)
  4144. (while params
  4145. (setq pelem (car params))
  4146. (when (listp pelem)
  4147. (setq ptype (car pelem)
  4148. props (car (cdr pelem)))
  4149. (cond
  4150. ((eq ptype 'SUPERCLASS)
  4151. (let ((pname (cdr (assq 'name props)))
  4152. (plink (cdr (assq 'link props))))
  4153. (unless (and (string= pname "None")
  4154. (string= plink "None"))
  4155. (push pname inherits))))
  4156. ((eq ptype 'PROPERTY)
  4157. (let ((pname (cdr (assq 'name props)))
  4158. (plink (cdr (assq 'link props)))
  4159. (get (string= (cdr (assq 'get props)) "Yes"))
  4160. (set (string= (cdr (assq 'set props)) "Yes"))
  4161. (init (string= (cdr (assq 'init props)) "Yes")))
  4162. (if get (push (list pname plink) get-props))
  4163. (if set (push (list pname plink) set-props))
  4164. (if init (push (list pname plink) init-props))))
  4165. ((eq ptype 'METHOD)
  4166. (setq method (cdr (assq 'name props)))
  4167. (setq extra-kwds ;;Assume all property keywords are gathered already
  4168. (cond
  4169. ((string-match (concat class "::Init") method)
  4170. (put 'init-props 'matched t)
  4171. init-props)
  4172. ((string-match (concat class "::GetProperty") method)
  4173. (put 'get-props 'matched t)
  4174. get-props)
  4175. ((string-match (concat class "::SetProperty") method)
  4176. (put 'set-props 'matched t)
  4177. set-props)
  4178. (t nil)))
  4179. (setq methods-entry
  4180. (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
  4181. methods-entry)))
  4182. (t)))
  4183. (setq params (cdr params)))
  4184. ;;(unless (get 'init-props 'matched)
  4185. ;; (message "Failed to match Init in class %s" class))
  4186. ;;(unless (get 'get-props 'matched)
  4187. ;; (message "Failed to match GetProperty in class %s" class))
  4188. ;;(unless (get 'set-props 'matched)
  4189. ;; (message "Failed to match SetProperty in class %s" class))
  4190. (setq class-entry
  4191. (if inherits
  4192. (list class (append '(inherits) inherits) (list 'link link))
  4193. (list class (list 'link link))))
  4194. (cons class-entry methods-entry)))
  4195. (defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
  4196. ;; Create correctly structured list elements from ROUTINE or METHOD
  4197. ;; XML list structures. Return a list of list elements, with more
  4198. ;; than one sub-list possible if a routine can serve as both
  4199. ;; procedure and function (e.g. call_method).
  4200. (let* ((nameblock (nth 1 xml-entry))
  4201. (name (cdr (assq 'name nameblock)))
  4202. (link (cdr (assq 'link nameblock)))
  4203. (params (cddr xml-entry))
  4204. (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
  4205. (case-fold-search t)
  4206. syntax kwd klink pref-list kwds pelem ptype props result type)
  4207. (if class ;; strip out class name from class method name string
  4208. (if (string-match (concat class "::") name)
  4209. (setq name (substring name (match-end 0)))))
  4210. (while params
  4211. (setq pelem (car params))
  4212. (when (listp pelem)
  4213. (setq ptype (car pelem)
  4214. props (car (cdr pelem)))
  4215. (cond
  4216. ((eq ptype 'SYNTAX)
  4217. (setq syntax (cdr (assq 'name props)))
  4218. (if (string-match "-&gt;" syntax)
  4219. (setq syntax (replace-match "->" t nil syntax)))
  4220. (setq type (cdr (assq 'type props)))
  4221. (push syntax
  4222. (aref syntax-vec (cond
  4223. ((string-match "^pro" type) 0)
  4224. ((string-match "^fun" type) 1)
  4225. ((string-match "^exec" type) 2)))))
  4226. ((eq ptype 'KEYWORD)
  4227. (setq kwd (cdr (assq 'name props))
  4228. klink (cdr (assq 'link props)))
  4229. (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
  4230. (progn
  4231. (setq pref-list
  4232. (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
  4233. kwd (substring kwd (match-end 0)))
  4234. (loop for x in pref-list do
  4235. (push (list (concat x kwd) klink) kwds)))
  4236. (push (list kwd klink) kwds)))
  4237. (t))); Do nothing for the others
  4238. (setq params (cdr params)))
  4239. ;; Debug
  4240. ;; (if (and (null (aref syntax-vec 0))
  4241. ;; (null (aref syntax-vec 1))
  4242. ;; (null (aref syntax-vec 2)))
  4243. ;; (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
  4244. ;; (if class
  4245. ;; (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
  4246. ;; (insert (message "Missing SYNTAX entry for %s\n" name)))))
  4247. ;; Executive commands are treated specially
  4248. (if (aref syntax-vec 2)
  4249. (cons (substring name 1) link)
  4250. (if extra-kws (setq kwds (nconc kwds extra-kws)))
  4251. (setq kwds (idlwave-rinfo-group-keywords kwds link))
  4252. (loop for idx from 0 to 1 do
  4253. (if (aref syntax-vec idx)
  4254. (push (append (list name (if (eq idx 0) 'pro 'fun)
  4255. class '(system)
  4256. (idlwave-shorten-syntax
  4257. (aref syntax-vec idx) name class))
  4258. kwds) result)))
  4259. result)))
  4260. (defun idlwave-rinfo-group-keywords (kwds master-link)
  4261. ;; Group keywords by link file, as a list with elements
  4262. ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
  4263. (let (kwd link anchor linkfiles block master-elt)
  4264. (while kwds
  4265. (setq kwd (car kwds)
  4266. link (idlwave-split-link-target (nth 1 kwd))
  4267. anchor (cdr link)
  4268. link (car link)
  4269. kwd (car kwd))
  4270. (if (setq block (assoc link linkfiles))
  4271. (push (cons kwd anchor) (cdr block))
  4272. (push (list link (cons kwd anchor)) linkfiles))
  4273. (setq kwds (cdr kwds)))
  4274. ;; Ensure the master link is there
  4275. (if (setq master-elt (assoc master-link linkfiles))
  4276. (if (eq (car linkfiles) master-elt)
  4277. linkfiles
  4278. (cons master-elt (delq master-elt linkfiles)))
  4279. (push (list master-link) linkfiles))))
  4280. (defun idlwave-convert-xml-clean-statement-aliases (aliases)
  4281. ;; Clean up the syntax of routines which are actually aliases by
  4282. ;; removing the "OR" from the statements
  4283. (let (syntax entry)
  4284. (loop for x in aliases do
  4285. (setq entry (assoc x idlwave-system-routines))
  4286. (when entry
  4287. (while (string-match " +or +" (setq syntax (nth 4 entry)))
  4288. (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
  4289. (defun idlwave-convert-xml-clean-routine-aliases (aliases)
  4290. ;; Duplicate and trim original routine aliases from rinfo list
  4291. ;; This if for, e.g. OPENR/OPENW/OPENU
  4292. (let (alias remove-list new parts all-parts)
  4293. (loop for x in aliases do
  4294. (when (setq parts (split-string (cdr x) "/"))
  4295. (setq new (assoc (cdr x) all-parts))
  4296. (unless new
  4297. (setq new (cons (cdr x) parts))
  4298. (push new all-parts))
  4299. (setcdr new (delete (car x) (cdr new)))))
  4300. ;; Add any missing aliases (separate by slashes)
  4301. (loop for x in all-parts do
  4302. (if (cdr x)
  4303. (push (cons (nth 1 x) (car x)) aliases)))
  4304. (loop for x in aliases do
  4305. (when (setq alias (assoc (cdr x) idlwave-system-routines))
  4306. (unless (memq alias remove-list) (push alias remove-list))
  4307. (setq alias (copy-sequence alias))
  4308. (setcar alias (car x))
  4309. (push alias idlwave-system-routines)))
  4310. (loop for x in remove-list do
  4311. (delq x idlwave-system-routines))))
  4312. (defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
  4313. ;; Duplicate and trim original routine aliases from rinfo list
  4314. ;; This if for, e.g. !X, !Y, !Z.
  4315. (let (alias remove-list)
  4316. (loop for x in aliases do
  4317. (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
  4318. (unless (memq alias remove-list) (push alias remove-list))
  4319. (setq alias (copy-sequence alias))
  4320. (setcar alias (car x))
  4321. (push alias idlwave-system-variables-alist)))
  4322. (loop for x in remove-list do
  4323. (delq x idlwave-system-variables-alist))))
  4324. (defun idlwave-xml-create-sysvar-alist (xml-entry)
  4325. ;; Create a sysvar list entry from the xml parsed list.
  4326. (let* ((nameblock (nth 1 xml-entry))
  4327. (name (cdr (assq 'name nameblock)))
  4328. (sysvar (substring name (progn (string-match "^ *!" name)
  4329. (match-end 0))))
  4330. (link (cdr (assq 'link nameblock)))
  4331. (params (cddr xml-entry))
  4332. (case-fold-search t)
  4333. pelem ptype props tags)
  4334. (while params
  4335. (setq pelem (car params))
  4336. (when (listp pelem)
  4337. (setq ptype (car pelem)
  4338. props (car (cdr pelem)))
  4339. (cond
  4340. ((eq ptype 'FIELD)
  4341. (push (cons (cdr (assq 'name props))
  4342. (cdr
  4343. (idlwave-split-link-target (cdr (assq 'link props)))))
  4344. tags))))
  4345. (setq params (cdr params)))
  4346. (delq nil
  4347. (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
  4348. (defvar idlwave-xml-routine-info-file nil)
  4349. (defun idlwave-save-routine-info ()
  4350. (if idlwave-xml-routine-info-file
  4351. (with-temp-file idlwave-xml-system-rinfo-converted-file
  4352. (insert
  4353. (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  4354. ;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
  4355. ;; Automatically generated from source file:
  4356. ;; " idlwave-xml-routine-info-file "
  4357. ;; on " (current-time-string) "
  4358. ;; Do not edit."))
  4359. (insert (format "\n(setq idlwave-xml-routine-info-file \n \"%s\")"
  4360. idlwave-xml-routine-info-file))
  4361. (insert "\n(setq idlwave-system-routines\n '")
  4362. (prin1 idlwave-system-routines (current-buffer))
  4363. (insert ")")
  4364. (insert "\n(setq idlwave-system-variables-alist\n '")
  4365. (prin1 idlwave-system-variables-alist (current-buffer))
  4366. (insert ")")
  4367. (insert "\n(setq idlwave-system-class-info\n '")
  4368. (prin1 idlwave-system-class-info (current-buffer))
  4369. (insert ")")
  4370. (insert "\n(setq idlwave-executive-commands-alist\n '")
  4371. (prin1 idlwave-executive-commands-alist (current-buffer))
  4372. (insert ")")
  4373. (insert "\n(setq idlwave-help-special-topic-words\n '")
  4374. (prin1 idlwave-help-special-topic-words (current-buffer))
  4375. (insert ")"))))
  4376. (defun idlwave-convert-xml-system-routine-info ()
  4377. "Convert XML supplied IDL routine info into internal form.
  4378. Cache to disk for quick recovery."
  4379. (interactive)
  4380. (let* ((dir (file-name-as-directory
  4381. (expand-file-name "help/online_help" (idlwave-sys-dir))))
  4382. (catalog-file (expand-file-name "idl_catalog.xml" dir))
  4383. (elem-cnt 0)
  4384. props rinfo msg-cnt elem type nelem class-result alias
  4385. routines routine-aliases statement-aliases sysvar-aliases)
  4386. (if (not (file-exists-p catalog-file))
  4387. (error "No such XML routine info file: %s" catalog-file)
  4388. (if (not (file-readable-p catalog-file))
  4389. (error "Cannot read XML routine info file: %s" catalog-file)))
  4390. (message "Reading XML routine info...")
  4391. (setq rinfo (xml-parse-file catalog-file))
  4392. (message "Reading XML routine info...done")
  4393. (setq rinfo (assq 'CATALOG rinfo))
  4394. (unless rinfo (error "Failed to parse XML routine info"))
  4395. ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
  4396. (setq rinfo (cddr rinfo))
  4397. (setq nelem (length rinfo)
  4398. msg-cnt (/ nelem 20))
  4399. (setq idlwave-xml-routine-info-file nil)
  4400. (message "Converting XML routine info...")
  4401. (setq idlwave-system-routines nil
  4402. idlwave-system-variables-alist nil
  4403. idlwave-system-class-info nil
  4404. idlwave-executive-commands-alist nil
  4405. idlwave-help-special-topic-words nil)
  4406. (while rinfo
  4407. (setq elem (car rinfo)
  4408. rinfo (cdr rinfo))
  4409. (incf elem-cnt)
  4410. (when (listp elem)
  4411. (setq type (car elem)
  4412. props (car (cdr elem)))
  4413. (if (= (mod elem-cnt msg-cnt) 0)
  4414. (message "Converting XML routine info...%2d%%"
  4415. (/ (* elem-cnt 100) nelem)))
  4416. (cond
  4417. ((eq type 'ROUTINE)
  4418. (if (setq alias (assq 'alias_to props))
  4419. (push (cons (cdr (assq 'name props)) (cdr alias))
  4420. routine-aliases)
  4421. (setq routines (idlwave-xml-create-rinfo-list elem))
  4422. (if (listp (cdr routines))
  4423. (setq idlwave-system-routines
  4424. (nconc idlwave-system-routines routines))
  4425. ;; a cons cell is an executive commands
  4426. (push routines idlwave-executive-commands-alist))))
  4427. ((eq type 'CLASS)
  4428. (setq class-result (idlwave-xml-create-class-method-lists elem))
  4429. (push (car class-result) idlwave-system-class-info)
  4430. (setq idlwave-system-routines
  4431. (nconc idlwave-system-routines (cdr class-result))))
  4432. ((eq type 'STATEMENT)
  4433. (push (cons (cdr (assq 'name props))
  4434. (cdr (assq 'link props)))
  4435. idlwave-help-special-topic-words)
  4436. ;; Save the links to those which are statement aliases (not routines)
  4437. (if (setq alias (assq 'alias_to props))
  4438. (unless (member (cdr alias) statement-aliases)
  4439. (push (cdr alias) statement-aliases))))
  4440. ((eq type 'SYSVAR)
  4441. (if (setq alias (cdr (assq 'alias_to props)))
  4442. (push (cons (substring (cdr (assq 'name props)) 1)
  4443. (substring alias 1))
  4444. sysvar-aliases)
  4445. (push (idlwave-xml-create-sysvar-alist elem)
  4446. idlwave-system-variables-alist)))
  4447. (t))))
  4448. (idlwave-convert-xml-clean-routine-aliases routine-aliases)
  4449. (idlwave-convert-xml-clean-statement-aliases statement-aliases)
  4450. (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
  4451. (setq idlwave-xml-routine-info-file catalog-file)
  4452. (idlwave-save-routine-info)
  4453. (message "Converting XML routine info...done")))
  4454. ;; ("ROUTINE" type class
  4455. ;; (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
  4456. ;; (buffer pro_file dir) | (compiled pro_file dir)
  4457. ;; "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
  4458. ;; ("HELPFILE2" (("KWD2" . link) ...)) ...)
  4459. (defun idlwave-load-rinfo-next-step ()
  4460. (let ((inhibit-quit t)
  4461. (arr idlwave-load-rinfo-steps-done))
  4462. (if (catch 'exit
  4463. (when (not (aref arr 0))
  4464. (message "Loading system routine info in idle time...")
  4465. (idlwave-load-system-routine-info)
  4466. ;;(load "idlw-rinfo" 'noerror 'nomessage)
  4467. (message "Loading system routine info in idle time...done")
  4468. (aset arr 0 t)
  4469. (throw 'exit t))
  4470. (when (not (aref arr 1))
  4471. (message "Normalizing idlwave-system-routines in idle time...")
  4472. (idlwave-reset-sintern t)
  4473. (put 'idlwave-reset-sintern 'done-by-idle t)
  4474. (setq idlwave-system-routines
  4475. (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
  4476. (message "Normalizing idlwave-system-routines in idle time...done")
  4477. (aset arr 1 t)
  4478. (throw 'exit t))
  4479. (when (not (aref arr 2))
  4480. (when (and (stringp idlwave-user-catalog-file)
  4481. (file-regular-p idlwave-user-catalog-file))
  4482. (message "Loading user catalog in idle time...")
  4483. (condition-case nil
  4484. (load-file idlwave-user-catalog-file)
  4485. (error (throw 'exit nil)))
  4486. ;; Check for the old style catalog and warn
  4487. (if (and
  4488. (boundp 'idlwave-library-routines)
  4489. idlwave-library-routines)
  4490. (progn
  4491. (setq idlwave-library-routines nil)
  4492. (ding)
  4493. (message "Outdated user catalog: %s... recreate"
  4494. idlwave-user-catalog-file))
  4495. (message "Loading user catalog in idle time...done")))
  4496. (aset arr 2 t)
  4497. (throw 'exit t))
  4498. (when (not (aref arr 3))
  4499. (when idlwave-user-catalog-routines
  4500. (message "Normalizing user catalog routines in idle time...")
  4501. (setq idlwave-user-catalog-routines
  4502. (idlwave-sintern-rinfo-list
  4503. idlwave-user-catalog-routines 'sys))
  4504. (message
  4505. "Normalizing user catalog routines in idle time...done"))
  4506. (aset arr 3 t)
  4507. (throw 'exit t))
  4508. (when (not (aref arr 4))
  4509. (idlwave-scan-library-catalogs
  4510. "Loading and normalizing library catalogs in idle time...")
  4511. (aset arr 4 t)
  4512. (throw 'exit t))
  4513. (when (not (aref arr 5))
  4514. (message "Finishing initialization in idle time...")
  4515. (idlwave-routines)
  4516. (message "Finishing initialization in idle time...done")
  4517. (aset arr 5 t)
  4518. (throw 'exit nil)))
  4519. ;; restart the timer
  4520. (if (sit-for 1)
  4521. (idlwave-load-rinfo-next-step)
  4522. (setq idlwave-load-rinfo-idle-timer
  4523. (run-with-idle-timer
  4524. idlwave-init-rinfo-when-idle-after
  4525. nil 'idlwave-load-rinfo-next-step))))))
  4526. (defvar idlwave-after-load-rinfo-hook nil)
  4527. (defun idlwave-load-all-rinfo (&optional force)
  4528. ;; Load and case-treat the system, user catalog, and library routine
  4529. ;; info files.
  4530. ;; System
  4531. (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
  4532. ;;(load "idlw-rinfo" 'noerror 'nomessage))
  4533. (idlwave-load-system-routine-info))
  4534. (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
  4535. (message "Normalizing idlwave-system-routines...")
  4536. (setq idlwave-system-routines
  4537. (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
  4538. (message "Normalizing idlwave-system-routines...done"))
  4539. (when idlwave-system-routines
  4540. (setq idlwave-routines (copy-sequence idlwave-system-routines))
  4541. (setq idlwave-last-system-routine-info-cons-cell
  4542. (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
  4543. ;; User catalog
  4544. (when (and (stringp idlwave-user-catalog-file)
  4545. (file-regular-p idlwave-user-catalog-file))
  4546. (condition-case nil
  4547. (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
  4548. (load-file idlwave-user-catalog-file))
  4549. (error nil))
  4550. (when (and
  4551. (boundp 'idlwave-library-routines)
  4552. idlwave-library-routines)
  4553. (setq idlwave-library-routines nil)
  4554. (error "Outdated user catalog: %s... recreate"
  4555. idlwave-user-catalog-file))
  4556. (setq idlwave-true-path-alist nil)
  4557. (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
  4558. (message "Normalizing user catalog routines...")
  4559. (setq idlwave-user-catalog-routines
  4560. (idlwave-sintern-rinfo-list
  4561. idlwave-user-catalog-routines 'sys))
  4562. (message "Normalizing user catalog routines...done")))
  4563. ;; Library catalog
  4564. (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
  4565. (idlwave-scan-library-catalogs
  4566. "Loading and normalizing library catalogs..."))
  4567. (run-hooks 'idlwave-after-load-rinfo-hook))
  4568. (defun idlwave-update-buffer-routine-info ()
  4569. (let (res)
  4570. (cond
  4571. ((eq idlwave-scan-all-buffers-for-routine-info t)
  4572. ;; Scan all buffers, current buffer last
  4573. (message "Scanning all buffers...")
  4574. (setq res (idlwave-get-routine-info-from-buffers
  4575. (reverse (buffer-list)))))
  4576. ((null idlwave-scan-all-buffers-for-routine-info)
  4577. ;; Don't scan any buffers
  4578. (setq res nil))
  4579. (t
  4580. ;; Just scan this buffer
  4581. (if (derived-mode-p 'idlwave-mode)
  4582. (progn
  4583. (message "Scanning current buffer...")
  4584. (setq res (idlwave-get-routine-info-from-buffers
  4585. (list (current-buffer))))))))
  4586. ;; Put the result into the correct variable
  4587. (setq idlwave-buffer-routines
  4588. (idlwave-sintern-rinfo-list res 'set))))
  4589. (defun idlwave-concatenate-rinfo-lists (&optional quiet run-hook)
  4590. "Put the different sources for routine information together."
  4591. ;; The sequence here is important because earlier definitions shadow
  4592. ;; later ones. We assume that if things in the buffers are newer
  4593. ;; then in the shell of the system, they are meant to be different.
  4594. (setcdr idlwave-last-system-routine-info-cons-cell
  4595. (append idlwave-buffer-routines
  4596. idlwave-compiled-routines
  4597. idlwave-library-catalog-routines
  4598. idlwave-user-catalog-routines))
  4599. (setq idlwave-class-alist nil)
  4600. ;; Give a message with information about the number of routines we have.
  4601. (unless quiet
  4602. (message
  4603. "Routines Found: buffer(%d) compiled(%d) library(%d) user(%d) system(%d)"
  4604. (length idlwave-buffer-routines)
  4605. (length idlwave-compiled-routines)
  4606. (length idlwave-library-catalog-routines)
  4607. (length idlwave-user-catalog-routines)
  4608. (length idlwave-system-routines)))
  4609. (if run-hook
  4610. (run-hooks 'idlwave-update-rinfo-hook)))
  4611. (defun idlwave-class-alist ()
  4612. "Return the class alist - make it if necessary."
  4613. (or idlwave-class-alist
  4614. (let (class)
  4615. (loop for x in idlwave-routines do
  4616. (when (and (setq class (nth 2 x))
  4617. (not (assq class idlwave-class-alist)))
  4618. (push (list class) idlwave-class-alist)))
  4619. idlwave-class-alist)))
  4620. ;; Three functions for the hooks
  4621. (defun idlwave-save-buffer-update ()
  4622. (idlwave-update-current-buffer-info 'save-buffer))
  4623. (defun idlwave-kill-buffer-update ()
  4624. (idlwave-update-current-buffer-info 'kill-buffer))
  4625. (defun idlwave-new-buffer-update ()
  4626. (idlwave-update-current-buffer-info 'find-file))
  4627. (defun idlwave-update-current-buffer-info (why)
  4628. "Update `idlwave-routines' for current buffer.
  4629. Can run from `after-save-hook'."
  4630. (when (and (derived-mode-p 'idlwave-mode)
  4631. (or (eq t idlwave-auto-routine-info-updates)
  4632. (memq why idlwave-auto-routine-info-updates))
  4633. idlwave-scan-all-buffers-for-routine-info
  4634. idlwave-routines)
  4635. (condition-case nil
  4636. (let (routines)
  4637. (idlwave-replace-buffer-routine-info
  4638. (buffer-file-name)
  4639. (if (eq why 'kill-buffer)
  4640. nil
  4641. (setq routines
  4642. (idlwave-sintern-rinfo-list
  4643. (idlwave-get-routine-info-from-buffers
  4644. (list (current-buffer))) 'set))))
  4645. (idlwave-concatenate-rinfo-lists 'quiet)
  4646. routines)
  4647. (error nil))))
  4648. (defun idlwave-replace-buffer-routine-info (file new)
  4649. "Cut the part from FILE out of `idlwave-buffer-routines' and add NEW."
  4650. (let ((list idlwave-buffer-routines)
  4651. found)
  4652. (while list
  4653. ;; The following test uses eq to make sure it works correctly
  4654. ;; when two buffers visit the same file. Then the file names
  4655. ;; will be equal, but not eq.
  4656. (if (eq (idlwave-routine-source-file (nth 3 (car list))) file)
  4657. (progn
  4658. (setcar list nil)
  4659. (setq found t))
  4660. (if found
  4661. ;; End of that section reached. Jump.
  4662. (setq list nil)))
  4663. (setq list (cdr list)))
  4664. (setq idlwave-buffer-routines
  4665. (append new (delq nil idlwave-buffer-routines)))))
  4666. ;;----- Scanning buffers -------------------
  4667. (defun idlwave-get-routine-info-from-buffers (buffers)
  4668. "Call `idlwave-get-buffer-routine-info' on idlwave-mode buffers in BUFFERS."
  4669. (let (buf routine-lists res)
  4670. (save-excursion
  4671. (while (setq buf (pop buffers))
  4672. (set-buffer buf)
  4673. (if (and (derived-mode-p 'idlwave-mode)
  4674. buffer-file-name)
  4675. ;; yes, this buffer has the right mode.
  4676. (progn (setq res (condition-case nil
  4677. (idlwave-get-buffer-routine-info)
  4678. (error nil)))
  4679. (push res routine-lists)))))
  4680. ;; Concatenate the individual lists and return the result
  4681. (apply 'nconc routine-lists)))
  4682. (defun idlwave-get-buffer-routine-info ()
  4683. "Scan the current buffer for routine info. Return (PRO-LIST FUNC-LIST)."
  4684. (let* ((case-fold-search t)
  4685. routine-list string entry)
  4686. (save-excursion
  4687. (save-restriction
  4688. (widen)
  4689. (goto-char (point-min))
  4690. (while (re-search-forward
  4691. "^[ \t]*\\(pro\\|function\\)[ \t]" nil t)
  4692. (setq string (buffer-substring-no-properties
  4693. (match-beginning 0)
  4694. (progn
  4695. (idlwave-end-of-statement)
  4696. (point))))
  4697. (setq entry (idlwave-parse-definition string))
  4698. (push entry routine-list))))
  4699. routine-list))
  4700. (defvar idlwave-scanning-lib-dir)
  4701. (defvar idlwave-scanning-lib)
  4702. (defun idlwave-parse-definition (string)
  4703. "Parse a module definition."
  4704. (let ((case-fold-search t)
  4705. start name args type keywords class)
  4706. ;; Remove comments
  4707. (while (string-match ";.*" string)
  4708. (setq string (replace-match "" t t string)))
  4709. ;; Remove the continuation line stuff
  4710. (while (string-match "\\([^a-zA-Z0-9$_]\\)\\$[ \t]*\n" string)
  4711. (setq string (replace-match "\\1 " t nil string)))
  4712. (while (string-match "\n" string)
  4713. (setq string (replace-match " " t nil string)))
  4714. ;; Match the name and type.
  4715. (when (string-match
  4716. "\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)" string)
  4717. (setq start (match-end 0))
  4718. (setq type (downcase (match-string 1 string)))
  4719. (if (match-beginning 3)
  4720. (setq class (match-string 3 string)))
  4721. (setq name (match-string 4 string)))
  4722. ;; Match normal args and keyword args
  4723. (while (string-match
  4724. ",\\s-*\\([a-zA-Z][a-zA-Z0-9$_]*\\|\\(_ref\\)?_extra\\)\\s-*\\(=\\)?"
  4725. string start)
  4726. (setq start (match-end 0))
  4727. (if (match-beginning 3)
  4728. (push (match-string 1 string) keywords)
  4729. (push (match-string 1 string) args)))
  4730. ;; Normalize and sort.
  4731. (setq args (nreverse args))
  4732. (setq keywords (sort keywords (lambda (a b)
  4733. (string< (downcase a) (downcase b)))))
  4734. ;; Make and return the entry
  4735. ;; We don't know which argument are optional, so this information
  4736. ;; will not be contained in the calling sequence.
  4737. (list name
  4738. (if (equal type "pro") 'pro 'fun)
  4739. class
  4740. (cond ((not (boundp 'idlwave-scanning-lib))
  4741. (list 'buffer (buffer-file-name)))
  4742. ; ((string= (downcase
  4743. ; (file-name-sans-extension
  4744. ; (file-name-nondirectory (buffer-file-name))))
  4745. ; (downcase name))
  4746. ; (list 'lib))
  4747. ; (t (cons 'lib (file-name-nondirectory (buffer-file-name))))
  4748. (t (list 'user (file-name-nondirectory (buffer-file-name))
  4749. idlwave-scanning-lib-dir "UserLib")))
  4750. (concat
  4751. (if (string= type "function") "Result = " "")
  4752. (if class "Obj ->[%s::]" "")
  4753. "%s"
  4754. (if args
  4755. (concat
  4756. (if (string= type "function") "(" ", ")
  4757. (mapconcat 'identity args ", ")
  4758. (if (string= type "function") ")" ""))))
  4759. (if keywords
  4760. (cons nil (mapcar 'list keywords)) ;No help file
  4761. nil))))
  4762. ;;----- Scanning the user catalog -------------------
  4763. (defun idlwave-sys-dir ()
  4764. "Return the syslib directory, or a dummy that never matches."
  4765. (cond
  4766. ((and idlwave-system-directory
  4767. (not (string= idlwave-system-directory "")))
  4768. idlwave-system-directory)
  4769. ((getenv "IDL_DIR"))
  4770. (t "@@@@@@@@")))
  4771. (defun idlwave-create-user-catalog-file (&optional arg)
  4772. "Scan all files on selected dirs of IDL search path for routine information.
  4773. A widget checklist will allow you to choose the directories. Write
  4774. the result as a file `idlwave-user-catalog-file'. When this file
  4775. exists, it will be automatically loaded to give routine information
  4776. about library routines. With ARG, just rescan the same directories
  4777. as last time - so no widget will pop up."
  4778. (interactive "P")
  4779. ;; Make sure the file is loaded if it exists.
  4780. (if (and (stringp idlwave-user-catalog-file)
  4781. (file-regular-p idlwave-user-catalog-file))
  4782. (condition-case nil
  4783. (load-file idlwave-user-catalog-file)
  4784. (error nil)))
  4785. ;; Make sure the file name makes sense
  4786. (unless (and (stringp idlwave-user-catalog-file)
  4787. (> (length idlwave-user-catalog-file) 0)
  4788. (file-accessible-directory-p
  4789. (file-name-directory idlwave-user-catalog-file))
  4790. (not (string= "" (file-name-nondirectory
  4791. idlwave-user-catalog-file))))
  4792. (error "`idlwave-user-catalog-file' does not point to a file in an accessible directory"))
  4793. (cond
  4794. ;; Rescan the known directories
  4795. ((and arg idlwave-path-alist
  4796. (consp (car idlwave-path-alist)))
  4797. (idlwave-scan-user-lib-files idlwave-path-alist))
  4798. ;; Expand the directories from library-path and run the widget
  4799. (idlwave-library-path
  4800. (idlwave-display-user-catalog-widget
  4801. (if idlwave-true-path-alist
  4802. ;; Propagate any flags on the existing path-alist
  4803. (mapcar (lambda (x)
  4804. (let ((path-entry (assoc (file-truename x)
  4805. idlwave-true-path-alist)))
  4806. (if path-entry
  4807. (cons x (cdr path-entry))
  4808. (list x))))
  4809. (idlwave-expand-path idlwave-library-path))
  4810. (mapcar 'list (idlwave-expand-path idlwave-library-path)))))
  4811. ;; Ask the shell for the path and then run the widget
  4812. (t
  4813. (message "Asking the shell for IDL path...")
  4814. (require 'idlw-shell)
  4815. (idlwave-shell-send-command idlwave-shell-path-query
  4816. '(idlwave-user-catalog-command-hook nil)
  4817. 'hide))))
  4818. ;; Parse shell path information and select among it.
  4819. (defun idlwave-user-catalog-command-hook (&optional arg)
  4820. ;; Command hook used by `idlwave-create-user-catalog-file'.
  4821. (if arg
  4822. ;; Scan immediately
  4823. (idlwave-scan-user-lib-files idlwave-path-alist)
  4824. ;; Set the path and display the widget
  4825. (idlwave-shell-get-path-info 'no-write) ; set to something path-alist
  4826. (idlwave-scan-library-catalogs "Locating library catalogs..." 'no-load)
  4827. (idlwave-display-user-catalog-widget idlwave-path-alist)))
  4828. (defconst idlwave-user-catalog-widget-help-string
  4829. "This is the front-end to the creation of the IDLWAVE user catalog.
  4830. Please select the directories on IDL's search path from which you
  4831. would like to extract routine information, to be stored in the file:
  4832. %s
  4833. If this is not the correct file, first set variable
  4834. `idlwave-user-catalog-file', and call this command again.
  4835. N.B. Many libraries include pre-scanned catalog files
  4836. \(\".idlwave_catalog\"). These are marked with \"[LIB]\", and need
  4837. not be scanned. You can scan your own libraries off-line using the
  4838. perl script `idlwave_catalog'.
  4839. After selecting the directories, choose [Scan & Save] to scan the library
  4840. directories and save the routine info.
  4841. \n")
  4842. (defvar idlwave-widget)
  4843. (defvar widget-keymap)
  4844. (defun idlwave-display-user-catalog-widget (dirs-list)
  4845. "Create the widget to select IDL search path directories for scanning."
  4846. (interactive)
  4847. (require 'widget)
  4848. (require 'wid-edit)
  4849. (unless dirs-list
  4850. (error "Don't know IDL's search path"))
  4851. (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
  4852. (switch-to-buffer (get-buffer-create "*IDLWAVE Widget*"))
  4853. (kill-all-local-variables)
  4854. (make-local-variable 'idlwave-widget)
  4855. (widget-insert (format idlwave-user-catalog-widget-help-string
  4856. idlwave-user-catalog-file))
  4857. (widget-create 'push-button
  4858. :notify 'idlwave-widget-scan-user-lib-files
  4859. "Scan & Save")
  4860. (widget-insert " ")
  4861. (widget-create 'push-button
  4862. :notify 'idlwave-delete-user-catalog-file
  4863. "Delete File")
  4864. (widget-insert " ")
  4865. (widget-create 'push-button
  4866. :notify
  4867. (lambda (&rest ignore)
  4868. (let ((path-list (widget-get idlwave-widget :path-dirs)))
  4869. (dolist (x path-list)
  4870. (unless (memq 'lib (cdr x))
  4871. (idlwave-path-alist-add-flag x 'user)))
  4872. (idlwave-display-user-catalog-widget path-list)))
  4873. "Select All Non-Lib")
  4874. (widget-insert " ")
  4875. (widget-create 'push-button
  4876. :notify
  4877. (lambda (&rest ignore)
  4878. (let ((path-list (widget-get idlwave-widget :path-dirs)))
  4879. (dolist (x path-list)
  4880. (idlwave-path-alist-remove-flag x 'user))
  4881. (idlwave-display-user-catalog-widget path-list)))
  4882. "Deselect All")
  4883. (widget-insert " ")
  4884. (widget-create 'push-button
  4885. :notify (lambda (&rest ignore)
  4886. (kill-buffer (current-buffer)))
  4887. "Quit")
  4888. (widget-insert "\n\n")
  4889. (widget-insert "Select Directories: \n")
  4890. (setq idlwave-widget
  4891. (apply 'widget-create
  4892. 'checklist
  4893. :value (delq nil (mapcar (lambda (x)
  4894. (if (memq 'user (cdr x))
  4895. (car x)))
  4896. dirs-list))
  4897. :greedy t
  4898. :tag "List of directories"
  4899. (mapcar (lambda (x)
  4900. (list 'item
  4901. (if (memq 'lib (cdr x))
  4902. (concat "[LIB] " (car x) )
  4903. (car x)))) dirs-list)))
  4904. (widget-put idlwave-widget :path-dirs dirs-list)
  4905. (widget-insert "\n")
  4906. (use-local-map widget-keymap)
  4907. (widget-setup)
  4908. (goto-char (point-min))
  4909. (delete-other-windows))
  4910. (defun idlwave-delete-user-catalog-file (&rest ignore)
  4911. (if (yes-or-no-p
  4912. (format "Delete file %s " idlwave-user-catalog-file))
  4913. (progn
  4914. (delete-file idlwave-user-catalog-file)
  4915. (message "%s has been deleted" idlwave-user-catalog-file))))
  4916. (defun idlwave-widget-scan-user-lib-files (&rest ignore)
  4917. ;; Call `idlwave-scan-user-lib-files' with data taken from the widget.
  4918. (let* ((widget idlwave-widget)
  4919. (selected-dirs (widget-value widget))
  4920. (path-alist (widget-get widget :path-dirs))
  4921. (this-path-alist path-alist)
  4922. dir-entry)
  4923. (while (setq dir-entry (pop this-path-alist))
  4924. (if (member
  4925. (if (memq 'lib (cdr dir-entry))
  4926. (concat "[LIB] " (car dir-entry))
  4927. (car dir-entry))
  4928. selected-dirs)
  4929. (idlwave-path-alist-add-flag dir-entry 'user)
  4930. (idlwave-path-alist-remove-flag dir-entry 'user)))
  4931. (idlwave-scan-user-lib-files path-alist)))
  4932. (defvar font-lock-mode)
  4933. (defun idlwave-scan-user-lib-files (path-alist)
  4934. ;; Scan the PRO files in PATH-ALIST and store the info in the user catalog
  4935. (let* ((idlwave-scanning-lib t)
  4936. (idlwave-scanning-lib-dir "")
  4937. (idlwave-completion-case nil)
  4938. dirs-alist dir files file)
  4939. (setq idlwave-user-catalog-routines nil
  4940. idlwave-path-alist path-alist ; for library-path instead
  4941. idlwave-true-path-alist nil)
  4942. (if idlwave-auto-write-paths (idlwave-write-paths))
  4943. (with-current-buffer (get-buffer-create "*idlwave-scan.pro*")
  4944. (idlwave-mode)
  4945. (setq dirs-alist (reverse path-alist))
  4946. (while (setq dir (pop dirs-alist))
  4947. (when (memq 'user (cdr dir)) ; Has it marked for scan?
  4948. (setq dir (car dir))
  4949. (setq idlwave-scanning-lib-dir dir)
  4950. (when (file-directory-p dir)
  4951. (setq files (directory-files dir 'full "\\.[pP][rR][oO]\\'"))
  4952. (while (setq file (pop files))
  4953. (when (file-regular-p file)
  4954. (if (not (file-readable-p file))
  4955. (message "Skipping %s (no read permission)" file)
  4956. (message "Scanning %s..." file)
  4957. (erase-buffer)
  4958. (insert-file-contents file 'visit)
  4959. (setq idlwave-user-catalog-routines
  4960. (append (idlwave-get-routine-info-from-buffers
  4961. (list (current-buffer)))
  4962. idlwave-user-catalog-routines)))))))))
  4963. (message "Creating user catalog file...")
  4964. (kill-buffer "*idlwave-scan.pro*")
  4965. (kill-buffer (get-buffer-create "*IDLWAVE Widget*"))
  4966. (let ((font-lock-maximum-size 0)
  4967. (auto-mode-alist nil))
  4968. (find-file idlwave-user-catalog-file))
  4969. (if (and (boundp 'font-lock-mode)
  4970. font-lock-mode)
  4971. (font-lock-mode 0))
  4972. (erase-buffer)
  4973. (insert ";; IDLWAVE user catalog file\n")
  4974. (insert (format ";; Created %s\n\n" (current-time-string)))
  4975. ;; Define the routine info list
  4976. (insert "\n(setq idlwave-user-catalog-routines\n '(")
  4977. (let ((standard-output (current-buffer)))
  4978. (mapc (lambda (x)
  4979. (insert "\n ")
  4980. (prin1 x)
  4981. (goto-char (point-max)))
  4982. idlwave-user-catalog-routines))
  4983. (insert (format "))\n\n;;; %s ends here\n"
  4984. (file-name-nondirectory idlwave-user-catalog-file)))
  4985. (goto-char (point-min))
  4986. ;; Save the buffer
  4987. (save-buffer 0)
  4988. (kill-buffer (current-buffer)))
  4989. (message "Creating user catalog file...done")
  4990. (message "Info for %d routines saved in %s"
  4991. (length idlwave-user-catalog-routines)
  4992. idlwave-user-catalog-file)
  4993. (sit-for 2)
  4994. (idlwave-update-routine-info t))
  4995. (defun idlwave-read-paths ()
  4996. (if (and (stringp idlwave-path-file)
  4997. (file-regular-p idlwave-path-file))
  4998. (condition-case nil
  4999. (load idlwave-path-file t t t)
  5000. (error nil))))
  5001. (defun idlwave-write-paths ()
  5002. (interactive)
  5003. (when (and idlwave-path-alist idlwave-system-directory)
  5004. (let ((font-lock-maximum-size 0)
  5005. (auto-mode-alist nil))
  5006. (find-file idlwave-path-file))
  5007. (if (and (boundp 'font-lock-mode)
  5008. font-lock-mode)
  5009. (font-lock-mode 0))
  5010. (erase-buffer)
  5011. (insert ";; IDLWAVE paths\n")
  5012. (insert (format ";; Created %s\n\n" (current-time-string)))
  5013. ;; Define the variable which knows the value of "!DIR"
  5014. (insert (format "\n(setq idlwave-system-directory \"%s\")\n"
  5015. idlwave-system-directory))
  5016. ;; Define the variable which contains a list of all scanned directories
  5017. (insert "\n(setq idlwave-path-alist\n '(")
  5018. (let ((standard-output (current-buffer)))
  5019. (mapc (lambda (x)
  5020. (insert "\n ")
  5021. (prin1 x)
  5022. (goto-char (point-max)))
  5023. idlwave-path-alist))
  5024. (insert "))\n")
  5025. (save-buffer 0)
  5026. (kill-buffer (current-buffer))))
  5027. (defun idlwave-expand-path (path &optional default-dir)
  5028. ;; Expand parts of path starting with '+' recursively into directory list.
  5029. ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
  5030. (message "Expanding path...")
  5031. (let (path1 dir recursive)
  5032. (while (setq dir (pop path))
  5033. (if (setq recursive (string= (substring dir 0 1) "+"))
  5034. (setq dir (substring dir 1)))
  5035. (if (and recursive
  5036. (not (file-name-absolute-p dir)))
  5037. (setq dir (expand-file-name dir default-dir)))
  5038. (if recursive
  5039. ;; Expand recursively
  5040. (setq path1 (append (idlwave-recursive-directory-list dir) path1))
  5041. ;; Keep unchanged
  5042. (push dir path1)))
  5043. (message "Expanding path...done")
  5044. (nreverse path1)))
  5045. (defun idlwave-recursive-directory-list (dir)
  5046. ;; Return a list of all directories below DIR, including DIR itself
  5047. (let ((path (list dir)) path1 file files)
  5048. (while (setq dir (pop path))
  5049. (when (file-directory-p dir)
  5050. (setq files (nreverse (directory-files dir t "[^.]")))
  5051. (while (setq file (pop files))
  5052. (if (file-directory-p file)
  5053. (push (file-name-as-directory file) path)))
  5054. (push dir path1)))
  5055. path1))
  5056. ;;----- Scanning the library catalogs ------------------
  5057. (defun idlwave-scan-library-catalogs (&optional message-base no-load)
  5058. "Scan for library catalog files (.idlwave_catalog) and ingest.
  5059. All directories on `idlwave-path-alist' (or `idlwave-library-path'
  5060. instead, if present) are searched. Print MESSAGE-BASE along with the
  5061. libraries being loaded, if passed, and skip loading/normalizing if
  5062. NO-LOAD is non-nil. The variable `idlwave-use-library-catalogs' can
  5063. be set to nil to disable library catalog scanning."
  5064. (when idlwave-use-library-catalogs
  5065. (let ((dirs
  5066. (if idlwave-library-path
  5067. (idlwave-expand-path idlwave-library-path)
  5068. (mapcar 'car idlwave-path-alist)))
  5069. (old-libname "")
  5070. dir-entry dir catalog all-routines)
  5071. (if message-base (message message-base))
  5072. (while (setq dir (pop dirs))
  5073. (catch 'continue
  5074. (when (file-readable-p
  5075. (setq catalog (expand-file-name ".idlwave_catalog" dir)))
  5076. (unless no-load
  5077. (setq idlwave-library-catalog-routines nil)
  5078. ;; Load the catalog file
  5079. (condition-case nil
  5080. (load catalog t t t)
  5081. (error (throw 'continue t)))
  5082. (when (and
  5083. message-base
  5084. (not (string= idlwave-library-catalog-libname
  5085. old-libname)))
  5086. (message "%s" (concat message-base
  5087. idlwave-library-catalog-libname))
  5088. (setq old-libname idlwave-library-catalog-libname))
  5089. (when idlwave-library-catalog-routines
  5090. (setq all-routines
  5091. (append
  5092. (idlwave-sintern-rinfo-list
  5093. idlwave-library-catalog-routines 'sys dir)
  5094. all-routines))))
  5095. ;; Add a 'lib flag if on path-alist
  5096. (when (and idlwave-path-alist
  5097. (setq dir-entry (assoc dir idlwave-path-alist)))
  5098. (idlwave-path-alist-add-flag dir-entry 'lib)))))
  5099. (unless no-load (setq idlwave-library-catalog-routines all-routines))
  5100. (if message-base (message (concat message-base "done"))))))
  5101. ;;----- Communicating with the Shell -------------------
  5102. ;; First, here is the idl program which can be used to query IDL for
  5103. ;; defined routines.
  5104. (defconst idlwave-routine-info.pro
  5105. "
  5106. ;; START OF IDLWAVE SUPPORT ROUTINES
  5107. pro idlwave_print_safe,item,limit
  5108. catch,err
  5109. if err ne 0 then begin
  5110. print,'Could not print item.'
  5111. return
  5112. endif
  5113. if n_elements(item) gt limit then $
  5114. print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
  5115. else print,item
  5116. end
  5117. pro idlwave_print_info_entry,name,func=func,separator=sep
  5118. ;; See if it's an object method
  5119. if name eq '' then return
  5120. func = keyword_set(func)
  5121. methsep = strpos(name,'::')
  5122. meth = methsep ne -1
  5123. ;; Get routine info
  5124. pars = routine_info(name,/parameters,functions=func)
  5125. source = routine_info(name,/source,functions=func)
  5126. nargs = pars.num_args
  5127. nkw = pars.num_kw_args
  5128. if nargs gt 0 then args = pars.args
  5129. if nkw gt 0 then kwargs = pars.kw_args
  5130. ;; Trim the class, and make the name
  5131. if meth then begin
  5132. class = strmid(name,0,methsep)
  5133. name = strmid(name,methsep+2,strlen(name)-1)
  5134. if nargs gt 0 then begin
  5135. ;; remove the self argument
  5136. wh = where(args ne 'SELF',nargs)
  5137. if nargs gt 0 then args = args[wh]
  5138. endif
  5139. endif else begin
  5140. ;; No class, just a normal routine.
  5141. class = \"\"
  5142. endelse
  5143. ;; Calling sequence
  5144. cs = \"\"
  5145. if func then cs = 'Result = '
  5146. if meth then cs = cs + 'Obj -> [' + '%s' + '::]'
  5147. cs = cs + '%s'
  5148. if func then cs = cs + '(' else if nargs gt 0 then cs = cs + ', '
  5149. if nargs gt 0 then begin
  5150. for j=0,nargs-1 do begin
  5151. cs = cs + args[j]
  5152. if j lt nargs-1 then cs = cs + ', '
  5153. endfor
  5154. end
  5155. if func then cs = cs + ')'
  5156. ;; Keyword arguments
  5157. kwstring = ''
  5158. if nkw gt 0 then begin
  5159. for j=0,nkw-1 do begin
  5160. kwstring = kwstring + ' ' + kwargs[j]
  5161. endfor
  5162. endif
  5163. ret=(['IDLWAVE-PRO','IDLWAVE-FUN'])[func]
  5164. print,ret + ': ' + name + sep + class + sep + source[0].path $
  5165. + sep + cs + sep + kwstring
  5166. end
  5167. pro idlwave_routine_info,file
  5168. on_error,1
  5169. sep = '<@>'
  5170. print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
  5171. all = routine_info()
  5172. fileQ=n_elements(file) ne 0
  5173. if fileQ then file=strtrim(file,2)
  5174. for i=0L,n_elements(all)-1L do begin
  5175. if fileQ then begin
  5176. if (routine_info(all[i],/SOURCE)).path eq file then $
  5177. idlwave_print_info_entry,all[i],separator=sep
  5178. endif else idlwave_print_info_entry,all[i],separator=sep
  5179. endfor
  5180. all = routine_info(/functions)
  5181. for i=0L,n_elements(all)-1L do begin
  5182. if fileQ then begin
  5183. if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
  5184. idlwave_print_info_entry,all[i],separator=sep,/FUNC
  5185. endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
  5186. endfor
  5187. print,'>>>END OF IDLWAVE ROUTINE INFO'
  5188. end
  5189. pro idlwave_get_sysvars
  5190. on_error,1
  5191. catch,error_status
  5192. if error_status ne 0 then begin
  5193. print, 'Cannot get info about system variables'
  5194. endif else begin
  5195. help,/brief,output=s,/system_variables ; ? unsafe use of OUTPUT=
  5196. s = strtrim(strjoin(s,' ',/single),2) ; make one line
  5197. v = strsplit(s,' +',/regex,/extract) ; get variables
  5198. for i=0L,n_elements(v)-1 do begin
  5199. t = [''] ; get tag list
  5200. a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
  5201. print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
  5202. endfor
  5203. endelse
  5204. end
  5205. pro idlwave_get_class_tags, class
  5206. res = execute('tags=tag_names({'+class+'})')
  5207. if res then print,'IDLWAVE-CLASS-TAGS: '+class+' '+strjoin(tags,' ',/single)
  5208. end
  5209. ;; END OF IDLWAVE SUPPORT ROUTINES
  5210. "
  5211. "The IDL programs to get info from the shell.")
  5212. (defvar idlwave-idlwave_routine_info-compiled nil
  5213. "Remember if the routine info procedure is already compiled.")
  5214. (defvar idlwave-shell-temp-pro-file)
  5215. (defvar idlwave-shell-temp-rinfo-save-file)
  5216. (defun idlwave-shell-compile-helper-routines (&optional wait)
  5217. (unless (and idlwave-idlwave_routine_info-compiled
  5218. (file-readable-p (idlwave-shell-temp-file 'rinfo)))
  5219. (with-current-buffer (idlwave-find-file-noselect
  5220. (idlwave-shell-temp-file 'pro))
  5221. (erase-buffer)
  5222. (insert idlwave-routine-info.pro)
  5223. (save-buffer 0))
  5224. (idlwave-shell-send-command
  5225. (concat ".run \"" idlwave-shell-temp-pro-file "\"")
  5226. nil 'hide wait)
  5227. (idlwave-shell-send-command
  5228. (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
  5229. (idlwave-shell-temp-file 'rinfo))
  5230. nil 'hide)
  5231. (setq idlwave-idlwave_routine_info-compiled t))
  5232. ;; Restore if necessary. Must use execute to hide lame routine_info
  5233. ;; errors on undefined routine
  5234. (idlwave-shell-send-command
  5235. (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
  5236. idlwave-shell-temp-rinfo-save-file
  5237. idlwave-shell-temp-rinfo-save-file)
  5238. nil 'hide))
  5239. (defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
  5240. "Query the shell for routine_info of compiled modules and update the lists."
  5241. ;; Save and compile the procedure. The compiled procedure is then
  5242. ;; saved into an IDL SAVE file, to allow for fast RESTORE. We may
  5243. ;; need to test for and possibly RESTORE the procedure each time we
  5244. ;; use it, since the user may have killed or redefined it. In
  5245. ;; particular, .RESET_SESSION will kill all user procedures. If
  5246. ;; FILE is set, only update routine info for routines in that file.
  5247. (idlwave-shell-compile-helper-routines wait)
  5248. ; execute the routine_info procedure, and analyze the output
  5249. (idlwave-shell-send-command
  5250. (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
  5251. `(progn
  5252. (idlwave-shell-routine-info-filter)
  5253. (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
  5254. 'hide wait))
  5255. ;; ---------------------------------------------------------------------------
  5256. ;;
  5257. ;; Completion and displaying routine calling sequences
  5258. (defvar idlwave-completion-help-info nil)
  5259. (defvar idlwave-completion-help-links nil)
  5260. (defvar idlwave-current-obj_new-class nil)
  5261. (defvar idlwave-complete-special nil)
  5262. (defvar method-selector)
  5263. (defvar class-selector)
  5264. (defvar type-selector)
  5265. (defvar super-classes)
  5266. (defun idlwave-complete (&optional arg module class)
  5267. "Complete a function, procedure or keyword name at point.
  5268. This function is smart and figures out what can be completed
  5269. at this point.
  5270. - At the beginning of a statement it completes procedure names.
  5271. - In the middle of a statement it completes function names.
  5272. - After a `(' or `,' in the argument list of a function or procedure,
  5273. it completes a keyword of the relevant function or procedure.
  5274. - In the first arg of `OBJ_NEW', it completes a class name.
  5275. When several completions are possible, a list will be displayed in
  5276. the *Completions* buffer. If this list is too long to fit into the
  5277. window, scrolling can be achieved by repeatedly pressing
  5278. \\[idlwave-complete].
  5279. The function also knows about object methods. When it needs a class
  5280. name, the action depends upon `idlwave-query-class', which see. You
  5281. can force IDLWAVE to ask you for a class name with a
  5282. \\[universal-argument] prefix argument to this command.
  5283. See also the variables `idlwave-keyword-completion-adds-equal' and
  5284. `idlwave-function-completion-adds-paren'.
  5285. The optional ARG can be used to specify the completion type in order
  5286. to override IDLWAVE's idea of what should be completed at point.
  5287. Possible values are:
  5288. 0 <=> query for the completion type
  5289. 1 <=> 'procedure
  5290. 2 <=> 'procedure-keyword
  5291. 3 <=> 'function
  5292. 4 <=> 'function-keyword
  5293. 5 <=> 'procedure-method
  5294. 6 <=> 'procedure-method-keyword
  5295. 7 <=> 'function-method
  5296. 8 <=> 'function-method-keyword
  5297. 9 <=> 'class
  5298. As a special case, the universal argument C-u forces completion of
  5299. function names in places where the default would be a keyword.
  5300. Two prefix argument, C-u C-u, prompts for a regexp by which to limit
  5301. completion.
  5302. For Lisp programmers only:
  5303. When we force a keyword, optional argument MODULE can contain the module name.
  5304. When we force a method or a method keyword, CLASS can specify the class."
  5305. (interactive "P")
  5306. (idlwave-routines)
  5307. (let* ((where-list
  5308. (if (and arg
  5309. (or (and (integerp arg) (not (equal arg '(16))))
  5310. (symbolp arg)))
  5311. (idlwave-make-force-complete-where-list arg module class)
  5312. (idlwave-where)))
  5313. (what (nth 2 where-list))
  5314. (idlwave-force-class-query (equal arg '(4)))
  5315. (completion-regexp-list
  5316. (if (equal arg '(16))
  5317. (list (read-string (concat "Completion Regexp: "))))))
  5318. (if (and module (string-match "::" module))
  5319. (setq class (substring module 0 (match-beginning 0))
  5320. module (substring module (match-end 0))))
  5321. (cond
  5322. ((and (null arg)
  5323. (eq (car-safe last-command) 'idlwave-display-completion-list)
  5324. (get-buffer-window "*Completions*"))
  5325. (setq this-command last-command)
  5326. (idlwave-scroll-completions))
  5327. ;; Complete a filename in quotes
  5328. ((and (idlwave-in-quote)
  5329. (not (eq what 'class)))
  5330. (idlwave-complete-filename))
  5331. ;; Check for any special completion functions
  5332. ((and idlwave-complete-special
  5333. (idlwave-call-special idlwave-complete-special)))
  5334. ((null what)
  5335. (error "Nothing to complete here"))
  5336. ;; Complete a class
  5337. ((eq what 'class)
  5338. (setq idlwave-completion-help-info '(class))
  5339. (idlwave-complete-class))
  5340. ((eq what 'procedure)
  5341. ;; Complete a procedure name
  5342. (let* ((cw-list (nth 3 where-list))
  5343. (class-selector (idlwave-determine-class cw-list 'pro))
  5344. (super-classes (unless (idlwave-explicit-class-listed cw-list)
  5345. (idlwave-all-class-inherits class-selector)))
  5346. (isa (concat "procedure" (if class-selector "-method" "")))
  5347. (type-selector 'pro))
  5348. (setq idlwave-completion-help-info
  5349. (list 'routine nil type-selector class-selector nil super-classes))
  5350. (idlwave-complete-in-buffer
  5351. 'procedure (if class-selector 'method 'routine)
  5352. (idlwave-routines) 'idlwave-selector
  5353. (format "Select a %s name%s"
  5354. isa
  5355. (if class-selector
  5356. (format " (class is %s)"
  5357. (if (eq class-selector t)
  5358. "unknown" class-selector))
  5359. ""))
  5360. isa
  5361. 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
  5362. ((eq what 'function)
  5363. ;; Complete a function name
  5364. (let* ((cw-list (nth 3 where-list))
  5365. (class-selector (idlwave-determine-class cw-list 'fun))
  5366. (super-classes (unless (idlwave-explicit-class-listed cw-list)
  5367. (idlwave-all-class-inherits class-selector)))
  5368. (isa (concat "function" (if class-selector "-method" "")))
  5369. (type-selector 'fun))
  5370. (setq idlwave-completion-help-info
  5371. (list 'routine nil type-selector class-selector nil super-classes))
  5372. (idlwave-complete-in-buffer
  5373. 'function (if class-selector 'method 'routine)
  5374. (idlwave-routines) 'idlwave-selector
  5375. (format "Select a %s name%s"
  5376. isa
  5377. (if class-selector
  5378. (format " (class is %s)"
  5379. (if (eq class-selector t)
  5380. "unknown" class-selector))
  5381. ""))
  5382. isa
  5383. 'idlwave-attach-method-classes 'idlwave-add-file-link-selector)))
  5384. ((and (memq what '(procedure-keyword function-keyword)) ; Special Case
  5385. (equal arg '(4)))
  5386. (idlwave-complete 3))
  5387. ((eq what 'procedure-keyword)
  5388. ;; Complete a procedure keyword
  5389. (let* ((where (nth 3 where-list))
  5390. (name (car where))
  5391. (method-selector name)
  5392. (type-selector 'pro)
  5393. (class (idlwave-determine-class where 'pro))
  5394. (class-selector class)
  5395. (super-classes (idlwave-all-class-inherits class-selector))
  5396. (isa (format "procedure%s-keyword" (if class "-method" "")))
  5397. (entry (idlwave-best-rinfo-assq
  5398. name 'pro class (idlwave-routines)))
  5399. (system (if entry (eq (car (nth 3 entry)) 'system)))
  5400. (list (idlwave-entry-keywords entry 'do-link)))
  5401. (unless (or entry (eq class t))
  5402. (error "Nothing known about procedure %s"
  5403. (idlwave-make-full-name class name)))
  5404. (setq list (idlwave-fix-keywords name 'pro class list
  5405. super-classes system))
  5406. (unless list (error "No keywords available for procedure %s"
  5407. (idlwave-make-full-name class name)))
  5408. (setq idlwave-completion-help-info
  5409. (list 'keyword name type-selector class-selector entry super-classes))
  5410. (idlwave-complete-in-buffer
  5411. 'keyword 'keyword list nil
  5412. (format "Select keyword for procedure %s%s"
  5413. (idlwave-make-full-name class name)
  5414. (if (or (member '("_EXTRA") list)
  5415. (member '("_REF_EXTRA") list))
  5416. " (note _EXTRA)" ""))
  5417. isa
  5418. 'idlwave-attach-keyword-classes)))
  5419. ((eq what 'function-keyword)
  5420. ;; Complete a function keyword
  5421. (let* ((where (nth 3 where-list))
  5422. (name (car where))
  5423. (method-selector name)
  5424. (type-selector 'fun)
  5425. (class (idlwave-determine-class where 'fun))
  5426. (class-selector class)
  5427. (super-classes (idlwave-all-class-inherits class-selector))
  5428. (isa (format "function%s-keyword" (if class "-method" "")))
  5429. (entry (idlwave-best-rinfo-assq
  5430. name 'fun class (idlwave-routines)))
  5431. (system (if entry (eq (car (nth 3 entry)) 'system)))
  5432. (list (idlwave-entry-keywords entry 'do-link))
  5433. msg-name)
  5434. (unless (or entry (eq class t))
  5435. (error "Nothing known about function %s"
  5436. (idlwave-make-full-name class name)))
  5437. (setq list (idlwave-fix-keywords name 'fun class list
  5438. super-classes system))
  5439. ;; OBJ_NEW: Messages mention the proper Init method
  5440. (setq msg-name (if (and (null class)
  5441. (string= (upcase name) "OBJ_NEW"))
  5442. (concat idlwave-current-obj_new-class
  5443. "::Init (via OBJ_NEW)")
  5444. (idlwave-make-full-name class name)))
  5445. (unless list (error "No keywords available for function %s"
  5446. msg-name))
  5447. (setq idlwave-completion-help-info
  5448. (list 'keyword name type-selector class-selector nil super-classes))
  5449. (idlwave-complete-in-buffer
  5450. 'keyword 'keyword list nil
  5451. (format "Select keyword for function %s%s" msg-name
  5452. (if (or (member '("_EXTRA") list)
  5453. (member '("_REF_EXTRA") list))
  5454. " (note _EXTRA)" ""))
  5455. isa
  5456. 'idlwave-attach-keyword-classes)))
  5457. (t (error "This should not happen (idlwave-complete)")))))
  5458. (defvar idlwave-complete-special nil
  5459. "List of special completion functions.
  5460. These functions are called for each completion. Each function must
  5461. check if its own special completion context is present. If yes, it
  5462. should use `idlwave-complete-in-buffer' to do some completion and
  5463. return t. If such a function returns t, *no further* attempts to
  5464. complete other contexts will be done. If the function returns nil,
  5465. other completions will be tried.")
  5466. (defun idlwave-call-special (functions &rest args)
  5467. (let ((funcs functions)
  5468. fun ret)
  5469. (catch 'exit
  5470. (while (setq fun (pop funcs))
  5471. (if (setq ret (apply fun args))
  5472. (throw 'exit ret)))
  5473. nil)))
  5474. (defun idlwave-make-force-complete-where-list (what &optional module class)
  5475. ;; Return an artificial WHERE specification to force the completion
  5476. ;; routine to complete a specific item independent of context.
  5477. ;; WHAT is the prefix arg of `idlwave-complete', see there for details.
  5478. ;; MODULE and CLASS can be used to specify the routine name and class.
  5479. ;; The class name will also be found in MODULE if that is like "class::mod".
  5480. (let* ((what-list '(("procedure") ("procedure-keyword")
  5481. ("function") ("function-keyword")
  5482. ("procedure-method") ("procedure-method-keyword")
  5483. ("function-method") ("function-method-keyword")
  5484. ("class")))
  5485. (module (idlwave-sintern-routine-or-method module class))
  5486. (class (idlwave-sintern-class class))
  5487. (what (cond
  5488. ((equal what 0)
  5489. (setq what
  5490. (intern (completing-read
  5491. "Complete what? " what-list nil t))))
  5492. ((integerp what)
  5493. (setq what (intern (car (nth (1- what) what-list)))))
  5494. ((and what
  5495. (symbolp what)
  5496. (assoc (symbol-name what) what-list))
  5497. what)
  5498. (t (error "Invalid WHAT"))))
  5499. (nil-list '(nil nil nil nil))
  5500. (class-list (list nil nil (or class t) nil)))
  5501. (cond
  5502. ((eq what 'procedure)
  5503. (list nil-list nil-list 'procedure nil-list nil))
  5504. ((eq what 'procedure-keyword)
  5505. (let* ((class-selector nil)
  5506. (super-classes nil)
  5507. (type-selector 'pro)
  5508. (pro (or module
  5509. (idlwave-completing-read
  5510. "Procedure: " (idlwave-routines) 'idlwave-selector))))
  5511. (setq pro (idlwave-sintern-routine pro))
  5512. (list nil-list nil-list 'procedure-keyword
  5513. (list pro nil nil nil) nil)))
  5514. ((eq what 'function)
  5515. (list nil-list nil-list 'function nil-list nil))
  5516. ((eq what 'function-keyword)
  5517. (let* ((class-selector nil)
  5518. (super-classes nil)
  5519. (type-selector 'fun)
  5520. (func (or module
  5521. (idlwave-completing-read
  5522. "Function: " (idlwave-routines) 'idlwave-selector))))
  5523. (setq func (idlwave-sintern-routine func))
  5524. (list nil-list nil-list 'function-keyword
  5525. (list func nil nil nil) nil)))
  5526. ((eq what 'procedure-method)
  5527. (list nil-list nil-list 'procedure class-list nil))
  5528. ((eq what 'procedure-method-keyword)
  5529. (let* ((class (idlwave-determine-class class-list 'pro))
  5530. (class-selector class)
  5531. (super-classes (idlwave-all-class-inherits class-selector))
  5532. (type-selector 'pro)
  5533. (pro (or module
  5534. (idlwave-completing-read
  5535. (format "Procedure in %s class: " class-selector)
  5536. (idlwave-routines) 'idlwave-selector))))
  5537. (setq pro (idlwave-sintern-method pro))
  5538. (list nil-list nil-list 'procedure-keyword
  5539. (list pro nil class nil) nil)))
  5540. ((eq what 'function-method)
  5541. (list nil-list nil-list 'function class-list nil))
  5542. ((eq what 'function-method-keyword)
  5543. (let* ((class (idlwave-determine-class class-list 'fun))
  5544. (class-selector class)
  5545. (super-classes (idlwave-all-class-inherits class-selector))
  5546. (type-selector 'fun)
  5547. (func (or module
  5548. (idlwave-completing-read
  5549. (format "Function in %s class: " class-selector)
  5550. (idlwave-routines) 'idlwave-selector))))
  5551. (setq func (idlwave-sintern-method func))
  5552. (list nil-list nil-list 'function-keyword
  5553. (list func nil class nil) nil)))
  5554. ((eq what 'class)
  5555. (list nil-list nil-list 'class nil-list nil))
  5556. (t (error "Invalid value for WHAT")))))
  5557. (defun idlwave-completing-read (&rest args)
  5558. ;; Completing read, case insensitive
  5559. (let ((old-value (default-value 'completion-ignore-case)))
  5560. (unwind-protect
  5561. (progn
  5562. (setq-default completion-ignore-case t)
  5563. (apply 'completing-read args))
  5564. (setq-default completion-ignore-case old-value))))
  5565. (defvar idlwave-shell-default-directory)
  5566. (defun idlwave-complete-filename ()
  5567. "Use the comint stuff to complete a file name."
  5568. (require 'comint)
  5569. (let* ((comint-file-name-chars "~/A-Za-z0-9+@:_.$#%={}\\-")
  5570. (comint-completion-addsuffix nil)
  5571. (default-directory
  5572. (if (and (boundp 'idlwave-shell-default-directory)
  5573. (stringp idlwave-shell-default-directory)
  5574. (file-directory-p idlwave-shell-default-directory))
  5575. idlwave-shell-default-directory
  5576. default-directory)))
  5577. (comint-dynamic-complete-filename)))
  5578. (defun idlwave-make-full-name (class name)
  5579. ;; Make a fully qualified module name including the class name
  5580. (concat (if class (format "%s::" class) "") name))
  5581. (defun idlwave-rinfo-assoc (name type class list)
  5582. "Like `idlwave-rinfo-assq', but sintern strings first."
  5583. (idlwave-rinfo-assq
  5584. (idlwave-sintern-routine-or-method name class)
  5585. type (idlwave-sintern-class class) list))
  5586. (defun idlwave-rinfo-assq (name type class list)
  5587. ;; Works like assq, but also checks type and class
  5588. (catch 'exit
  5589. (let (match)
  5590. (while (setq match (assq name list))
  5591. (and (or (eq type t)
  5592. (eq (nth 1 match) type))
  5593. (eq (nth 2 match) class)
  5594. (throw 'exit match))
  5595. (setq list (cdr (memq match list)))))))
  5596. (defun idlwave-rinfo-assq-any-class (name type class list)
  5597. ;; Return the first matching method on the inheritance list
  5598. (let* ((classes (cons class (idlwave-all-class-inherits class)))
  5599. class rtn)
  5600. (while classes
  5601. (if (setq rtn (idlwave-rinfo-assq name type (pop classes) list))
  5602. (setq classes nil)))
  5603. rtn))
  5604. (defun idlwave-best-rinfo-assq (name type class list &optional with-file
  5605. keep-system)
  5606. "Like `idlwave-rinfo-assq', but get all twins and sort, then return first.
  5607. If WITH-FILE is passed, find the best rinfo entry with a file
  5608. included. If KEEP-SYSTEM is set, don't prune system for compiled
  5609. syslib files."
  5610. (let ((twins (idlwave-routine-twins
  5611. (idlwave-rinfo-assq-any-class name type class list)
  5612. list))
  5613. syslibp)
  5614. (when (> (length twins) 1)
  5615. (setq twins (sort twins 'idlwave-routine-entry-compare-twins))
  5616. (if (and (null keep-system)
  5617. (eq 'system (car (nth 3 (car twins))))
  5618. (setq syslibp (idlwave-any-syslib (cdr twins)))
  5619. (not (equal 1 syslibp)))
  5620. ;; Its a compiled syslib, so we need to remove the system entry
  5621. (setq twins (cdr twins)))
  5622. (if with-file
  5623. (setq twins (delq nil
  5624. (mapcar (lambda (x)
  5625. (if (nth 1 (nth 3 x)) x))
  5626. twins)))))
  5627. (car twins)))
  5628. (defun idlwave-best-rinfo-assoc (name type class list &optional with-file
  5629. keep-system)
  5630. "Like `idlwave-best-rinfo-assq', but sintern strings first."
  5631. (idlwave-best-rinfo-assq
  5632. (idlwave-sintern-routine-or-method name class)
  5633. type (idlwave-sintern-class class) list with-file keep-system))
  5634. (defun idlwave-any-syslib (entries)
  5635. "Does the entry list ENTRIES contain a syslib entry?
  5636. If yes, return the index (>=1)."
  5637. (let (file (cnt 0))
  5638. (catch 'exit
  5639. (while entries
  5640. (incf cnt)
  5641. (setq file (idlwave-routine-source-file (nth 3 (car entries))))
  5642. (if (and file (idlwave-syslib-p file))
  5643. (throw 'exit cnt)
  5644. (setq entries (cdr entries))))
  5645. nil)))
  5646. (defun idlwave-all-assq (key list)
  5647. "Return a list of all associations of Key in LIST."
  5648. (let (rtn elt)
  5649. (while (setq elt (assq key list))
  5650. (push elt rtn)
  5651. (setq list (cdr (memq elt list))))
  5652. (nreverse rtn)))
  5653. (defun idlwave-all-method-classes (method &optional type)
  5654. "Return all classes which have a method METHOD.
  5655. TYPE is 'fun or 'pro.
  5656. When TYPE is not specified, both procedures and functions will be considered."
  5657. (if (null method)
  5658. (mapcar 'car (idlwave-class-alist))
  5659. (let (rtn)
  5660. (mapc (lambda (x)
  5661. (and (nth 2 x)
  5662. (or (not type)
  5663. (eq type (nth 1 x)))
  5664. (push (nth 2 x) rtn)))
  5665. (idlwave-all-assq method (idlwave-routines)))
  5666. (idlwave-uniquify rtn))))
  5667. (defun idlwave-all-method-keyword-classes (method keyword &optional type)
  5668. "Return all classes which have a method METHOD with keyword KEYWORD.
  5669. TYPE is 'fun or 'pro.
  5670. When TYPE is not specified, both procedures and functions will be considered."
  5671. (if (or (null method)
  5672. (null keyword))
  5673. nil
  5674. (let (rtn)
  5675. (mapc (lambda (x)
  5676. (and (nth 2 x) ; non-nil class
  5677. (or (not type) ; correct or unspecified type
  5678. (eq type (nth 1 x)))
  5679. (assoc keyword (idlwave-entry-keywords x))
  5680. (push (nth 2 x) rtn)))
  5681. (idlwave-all-assq method (idlwave-routines)))
  5682. (idlwave-uniquify rtn))))
  5683. (defun idlwave-members-only (list club)
  5684. "Return list of all elements in LIST which are also in CLUB."
  5685. (let (rtn)
  5686. (while list
  5687. (if (member (car list) club)
  5688. (setq rtn (cons (car list) rtn)))
  5689. (setq list (cdr list)))
  5690. (nreverse rtn)))
  5691. (defun idlwave-nonmembers-only (list club)
  5692. "Return list of all elements in LIST which are not in CLUB."
  5693. (let (rtn)
  5694. (while list
  5695. (if (member (car list) club)
  5696. nil
  5697. (setq rtn (cons (car list) rtn)))
  5698. (setq list (cdr list)))
  5699. (nreverse rtn)))
  5700. (defun idlwave-explicit-class-listed (info)
  5701. "Return whether or not the class is listed explicitly, ala a->b::c.
  5702. INFO is as returned by `idlwave-what-function' or `-procedure'."
  5703. (let ((apos (nth 3 info)))
  5704. (if apos
  5705. (save-excursion (goto-char apos)
  5706. (looking-at "->[a-zA-Z][a-zA-Z0-9$_]*::")))))
  5707. (defvar idlwave-determine-class-special nil
  5708. "List of special functions for determining class.
  5709. Must accept two arguments: `apos' and `info'.")
  5710. (defun idlwave-determine-class (info type)
  5711. ;; Determine the class of a routine call.
  5712. ;; INFO is the `cw-list' structure as returned by idlwave-where.
  5713. ;; The second element in this structure is the class. When nil, we
  5714. ;; return nil. When t, try to get the class from text properties at
  5715. ;; the arrow. When the object is "self", we use the class of the
  5716. ;; current routine. otherwise prompt the user for a class name.
  5717. ;; Also stores the selected class as a text property at the arrow.
  5718. ;; TYPE is 'fun or 'pro.
  5719. (let* ((class (nth 2 info))
  5720. (apos (nth 3 info))
  5721. (nassoc (assoc (if (stringp (car info))
  5722. (upcase (car info))
  5723. (car info))
  5724. idlwave-query-class))
  5725. (dassoc (assq (if (car info) 'keyword-default 'method-default)
  5726. idlwave-query-class))
  5727. (query (cond (nassoc (cdr nassoc))
  5728. (dassoc (cdr dassoc))
  5729. (t t)))
  5730. (arrow (and apos (string= (buffer-substring apos (+ 2 apos)) "->")))
  5731. (is-self
  5732. (and arrow
  5733. (save-excursion (goto-char apos)
  5734. (forward-word -1)
  5735. (let ((case-fold-search t))
  5736. (looking-at "self\\>")))))
  5737. (force-query idlwave-force-class-query)
  5738. store special-class class-alist)
  5739. (cond
  5740. ((null class) nil)
  5741. ((eq t class)
  5742. ;; There is an object which would like to know its class
  5743. (if (and arrow (get-text-property apos 'idlwave-class)
  5744. idlwave-store-inquired-class
  5745. (not force-query))
  5746. (setq class (get-text-property apos 'idlwave-class)
  5747. class (idlwave-sintern-class class)))
  5748. (if (and (eq t class) is-self)
  5749. (setq class (or (nth 2 (idlwave-current-routine)) class)))
  5750. ;; Before prompting, try any special class determination routines
  5751. (when (and (eq t class)
  5752. idlwave-determine-class-special
  5753. (not force-query))
  5754. (setq special-class
  5755. (idlwave-call-special idlwave-determine-class-special apos))
  5756. (if special-class
  5757. (setq class (idlwave-sintern-class special-class)
  5758. store idlwave-store-inquired-class)))
  5759. ;; Prompt for a class, if we need to
  5760. (when (and (eq class t)
  5761. (or force-query query))
  5762. (setq class-alist
  5763. (mapcar 'list (idlwave-all-method-classes (car info) type)))
  5764. (setq class
  5765. (idlwave-sintern-class
  5766. (cond
  5767. ((and (= (length class-alist) 0) (not force-query))
  5768. (error "No classes available with method %s" (car info)))
  5769. ((and (= (length class-alist) 1) (not force-query))
  5770. (car (car class-alist)))
  5771. (t
  5772. (setq store idlwave-store-inquired-class)
  5773. (idlwave-completing-read
  5774. (format "Class%s: " (if (stringp (car info))
  5775. (format " for %s method %s"
  5776. type (car info))
  5777. ""))
  5778. class-alist nil nil nil 'idlwave-class-history))))))
  5779. ;; Store it, if requested
  5780. (when (and class (not (eq t class)))
  5781. ;; We have a real class here
  5782. (when (and store arrow)
  5783. (condition-case ()
  5784. (add-text-properties
  5785. apos (+ apos 2)
  5786. `(idlwave-class ,class face ,idlwave-class-arrow-face
  5787. rear-nonsticky t))
  5788. (error nil)))
  5789. (setf (nth 2 info) class))
  5790. ;; Return the class
  5791. class)
  5792. ;; Default as fallback
  5793. (t class))))
  5794. (defun idlwave-selector (a)
  5795. (and (eq (nth 1 a) type-selector)
  5796. (or (and (nth 2 a) (eq class-selector t))
  5797. (eq (nth 2 a) class-selector)
  5798. (memq (nth 2 a) super-classes))))
  5799. (defun idlwave-add-file-link-selector (a)
  5800. ;; Record a file link, if any, for the tested names during selection.
  5801. (let ((sel (idlwave-selector a)) file)
  5802. (if (and sel (setq file (idlwave-entry-has-help a)))
  5803. (push (cons (car a) file) idlwave-completion-help-links))
  5804. sel))
  5805. (defun idlwave-where ()
  5806. "Find out where we are.
  5807. The return value is a list with the following stuff:
  5808. \(PRO-LIST FUNC-LIST COMPLETE-WHAT CW-LIST LAST-CHAR)
  5809. PRO-LIST (PRO POINT CLASS ARROW)
  5810. FUNC-LIST (FUNC POINT CLASS ARROW)
  5811. COMPLETE-WHAT a symbol indicating what kind of completion makes sense here
  5812. CW-LIST (PRO-OR-FUNC POINT CLASS ARROW) Like PRO-LIST, for what can
  5813. be completed here.
  5814. LAST-CHAR last relevant character before point (non-white non-comment,
  5815. not part of current identifier or leading slash).
  5816. In the lists, we have these meanings:
  5817. PRO: Procedure name
  5818. FUNC: Function name
  5819. POINT: Where is this
  5820. CLASS: What class has the routine (nil=no, t=is method, but class unknown)
  5821. ARROW: Location of the arrow"
  5822. (idlwave-routines)
  5823. (let* (;(bos (save-excursion (idlwave-beginning-of-statement) (point)))
  5824. (bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
  5825. (func-entry (idlwave-what-function bos))
  5826. (func (car func-entry))
  5827. (func-class (nth 1 func-entry))
  5828. (func-arrow (nth 2 func-entry))
  5829. (func-point (or (nth 3 func-entry) 0))
  5830. (func-level (or (nth 4 func-entry) 0))
  5831. (pro-entry (idlwave-what-procedure bos))
  5832. (pro (car pro-entry))
  5833. (pro-class (nth 1 pro-entry))
  5834. (pro-arrow (nth 2 pro-entry))
  5835. (pro-point (or (nth 3 pro-entry) 0))
  5836. (last-char (idlwave-last-valid-char))
  5837. (case-fold-search t)
  5838. (match-string (buffer-substring bos (point)))
  5839. cw cw-mod cw-arrow cw-class cw-point)
  5840. (if (< func-point pro-point) (setq func nil))
  5841. (cond
  5842. ((string-match "\\`[ \t]*\\(pro\\|function\\)[ \t]+[a-zA-Z0-9_]*\\'"
  5843. match-string)
  5844. (setq cw 'class))
  5845. ((string-match
  5846. "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)?\\'"
  5847. (if (> pro-point 0)
  5848. (buffer-substring pro-point (point))
  5849. match-string))
  5850. (setq cw 'procedure cw-class pro-class cw-point pro-point
  5851. cw-arrow pro-arrow))
  5852. ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
  5853. match-string)
  5854. nil)
  5855. ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
  5856. match-string)
  5857. (setq cw 'class))
  5858. ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
  5859. match-string)
  5860. (setq cw 'class))
  5861. ((and func
  5862. (> func-point pro-point)
  5863. (= func-level 1)
  5864. (memq last-char '(?\( ?,)))
  5865. (setq cw 'function-keyword cw-mod func cw-point func-point
  5866. cw-class func-class cw-arrow func-arrow))
  5867. ((and pro (eq last-char ?,))
  5868. (setq cw 'procedure-keyword cw-mod pro cw-point pro-point
  5869. cw-class pro-class cw-arrow pro-arrow))
  5870. ; ((member last-char '(?\' ?\) ?\] ?!))
  5871. ; ;; after these chars, a function makes no sense
  5872. ; ;; FIXME: I am sure there can be more in this list
  5873. ; ;; FIXME: Do we want to do this at all?
  5874. ; nil)
  5875. ;; Everywhere else we try a function.
  5876. (t
  5877. (setq cw 'function)
  5878. (save-excursion
  5879. (if (re-search-backward "->[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\s-*\\)?\\(\\([$a-zA-Z0-9_]+\\)::\\)?[$a-zA-Z0-9_]*\\=" bos t)
  5880. (setq cw-arrow (copy-marker (match-beginning 0))
  5881. cw-class (if (match-end 4)
  5882. (idlwave-sintern-class (match-string 4))
  5883. t))))))
  5884. (list (list pro pro-point pro-class pro-arrow)
  5885. (list func func-point func-class func-arrow)
  5886. cw
  5887. (list cw-mod cw-point cw-class cw-arrow)
  5888. last-char)))
  5889. (defun idlwave-this-word (&optional class)
  5890. ;; Grab the word around point. CLASS is for the `skip-chars=...' functions
  5891. (setq class (or class "a-zA-Z0-9$_."))
  5892. (save-excursion
  5893. (buffer-substring
  5894. (progn (skip-chars-backward class) (point))
  5895. (progn (skip-chars-forward class) (point)))))
  5896. (defun idlwave-what-function (&optional bound)
  5897. ;; Find out if point is within the argument list of a function.
  5898. ;; The return value is ("function-name" class arrow-start (point) level).
  5899. ;; Level is 1 on the top level parentheses, higher further down.
  5900. ;; If the optional BOUND is an integer, bound backwards directed
  5901. ;; searches to this point.
  5902. (catch 'exit
  5903. (let (pos
  5904. func-point
  5905. (cnt 0)
  5906. func arrow-start class)
  5907. (idlwave-with-special-syntax
  5908. (save-restriction
  5909. (save-excursion
  5910. (narrow-to-region (max 1 (or bound 0)) (point-max))
  5911. ;; move back out of the current parenthesis
  5912. (while (condition-case nil
  5913. (progn (up-list -1) t)
  5914. (error nil))
  5915. (setq pos (point))
  5916. (incf cnt)
  5917. (when (and (= (following-char) ?\()
  5918. (re-search-backward
  5919. "\\(::\\|\\<\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\="
  5920. bound t))
  5921. (setq func (match-string 2)
  5922. func-point (goto-char (match-beginning 2))
  5923. pos func-point)
  5924. (if (re-search-backward
  5925. "->[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\=" bound t)
  5926. (setq arrow-start (copy-marker (match-beginning 0))
  5927. class (or (match-string 2) t)))
  5928. (throw
  5929. 'exit
  5930. (list
  5931. (idlwave-sintern-routine-or-method func class)
  5932. (idlwave-sintern-class class)
  5933. arrow-start func-point cnt)))
  5934. (goto-char pos))
  5935. (throw 'exit nil)))))))
  5936. (defun idlwave-what-procedure (&optional bound)
  5937. ;; Find out if point is within the argument list of a procedure.
  5938. ;; The return value is ("procedure-name" class arrow-pos (point)).
  5939. ;; If the optional BOUND is an integer, bound backwards directed
  5940. ;; searches to this point.
  5941. (let ((pos (point)) pro-point
  5942. pro class arrow-start string)
  5943. (save-excursion
  5944. ;;(idlwave-beginning-of-statement)
  5945. (idlwave-start-of-substatement 'pre)
  5946. (setq string (buffer-substring (point) pos))
  5947. (if (string-match
  5948. "\\`[ \t]*\\([a-zA-Z][a-zA-Z0-9$_]*\\)[ \t]*\\(,\\|\\'\\)" string)
  5949. (setq pro (match-string 1 string)
  5950. pro-point (+ (point) (match-beginning 1)))
  5951. (if (and (idlwave-skip-object)
  5952. (setq string (buffer-substring (point) pos))
  5953. (string-match
  5954. "\\`[ \t]*\\(->\\)[ \t]*\\(\\([a-zA-Z][a-zA-Z0-9$_]*\\)::\\)?\\([a-zA-Z][a-zA-Z0-9$_]*\\)?[ \t]*\\(,\\|\\(\\$\\s *\\(;.*\\)?\\)?$\\)"
  5955. string))
  5956. (setq pro (if (match-beginning 4)
  5957. (match-string 4 string))
  5958. pro-point (if (match-beginning 4)
  5959. (+ (point) (match-beginning 4))
  5960. pos)
  5961. arrow-start (copy-marker (+ (point) (match-beginning 1)))
  5962. class (or (match-string 3 string) t)))))
  5963. (list (idlwave-sintern-routine-or-method pro class)
  5964. (idlwave-sintern-class class)
  5965. arrow-start
  5966. pro-point)))
  5967. (defun idlwave-skip-object ()
  5968. ;; If there is an object at point, move over it and return t.
  5969. (let ((pos (point)))
  5970. (if (catch 'exit
  5971. (save-excursion
  5972. (skip-chars-forward " ") ; white space
  5973. (skip-chars-forward "*") ; de-reference
  5974. (cond
  5975. ((looking-at idlwave-identifier)
  5976. (goto-char (match-end 0)))
  5977. ((eq (following-char) ?\()
  5978. nil)
  5979. (t (throw 'exit nil)))
  5980. (catch 'endwhile
  5981. (while t
  5982. (cond ((eq (following-char) ?.)
  5983. (forward-char 1)
  5984. (if (not (looking-at idlwave-identifier))
  5985. (throw 'exit nil))
  5986. (goto-char (match-end 0)))
  5987. ((memq (following-char) '(?\( ?\[))
  5988. (condition-case nil
  5989. (forward-list 1)
  5990. (error (throw 'exit nil))))
  5991. (t (throw 'endwhile t)))))
  5992. (if (looking-at "[ \t]*->")
  5993. (throw 'exit (setq pos (match-beginning 0)))
  5994. (throw 'exit nil))))
  5995. (goto-char pos)
  5996. nil)))
  5997. (defun idlwave-last-valid-char ()
  5998. "Return the last character before point which is not white or a comment
  5999. and also not part of the current identifier. Since we do this in
  6000. order to identify places where keywords are, we consider the initial
  6001. `/' of a keyword as part of the identifier.
  6002. This function is not general, can only be used for completion stuff."
  6003. (catch 'exit
  6004. (save-excursion
  6005. ;; skip the current identifier
  6006. (skip-chars-backward "a-zA-Z0-9_$")
  6007. ;; also skip a leading slash which might be belong to the keyword
  6008. (if (eq (preceding-char) ?/)
  6009. (backward-char 1))
  6010. ;; FIXME: does not check if this is a valid identifier
  6011. (while t
  6012. (skip-chars-backward " \t")
  6013. (cond
  6014. ((memq (preceding-char) '(?\; ?\$)) (throw 'exit nil))
  6015. ((eq (preceding-char) ?\n)
  6016. (beginning-of-line 0)
  6017. (if (looking-at "\\([^\n]*\\)\\$[ \t]*\\(;[^\n]*\\)?\n")
  6018. ;; continuation line
  6019. (goto-char (match-end 1))
  6020. (throw 'exit nil)))
  6021. (t (throw 'exit (preceding-char))))))))
  6022. (defvar idlwave-complete-after-success-form nil
  6023. "A form to evaluate after successful completion.")
  6024. (defvar idlwave-complete-after-success-form-force nil
  6025. "A form to evaluate after completion selection in *Completions* buffer.")
  6026. (defconst idlwave-completion-mark (make-marker)
  6027. "A mark pointing to the beginning of the completion string.")
  6028. (defvar completion-highlight-first-word-only) ;XEmacs.
  6029. (defun idlwave-complete-in-buffer (type stype list selector prompt isa
  6030. &optional prepare-display-function
  6031. special-selector)
  6032. "Perform TYPE completion of word before point against LIST.
  6033. SELECTOR is the PREDICATE argument for the completion function. Show
  6034. PROMPT in echo area. TYPE is one of the intern types, e.g. 'function,
  6035. 'procedure, 'class-tag, 'keyword, 'sysvar, etc. SPECIAL-SELECTOR is
  6036. used only once, for `all-completions', and can be used to, e.g.,
  6037. accumulate information on matching completions."
  6038. (let* ((completion-ignore-case t)
  6039. beg (end (point)) slash part spart completion all-completions
  6040. dpart dcompletion)
  6041. (unless list
  6042. (error (concat prompt ": No completions available")))
  6043. ;; What is already in the buffer?
  6044. (save-excursion
  6045. (skip-chars-backward "a-zA-Z0-9_$")
  6046. (setq slash (eq (preceding-char) ?/)
  6047. beg (point)
  6048. idlwave-complete-after-success-form
  6049. (list 'idlwave-after-successful-completion
  6050. (list 'quote type) slash beg)
  6051. idlwave-complete-after-success-form-force
  6052. (list 'idlwave-after-successful-completion
  6053. (list 'quote type) slash (list 'quote 'force))))
  6054. ;; Try a completion
  6055. (setq part (buffer-substring beg end)
  6056. dpart (downcase part)
  6057. spart (idlwave-sintern stype part)
  6058. completion (try-completion part list selector)
  6059. dcompletion (if (stringp completion) (downcase completion))
  6060. idlwave-completion-help-links nil)
  6061. (cond
  6062. ((null completion)
  6063. ;; nothing available.
  6064. (error (concat prompt ": no completion for \"%s\"") part))
  6065. ((and (not (equal dpart dcompletion))
  6066. (not (eq t completion)))
  6067. ;; We can add something
  6068. (delete-region beg end)
  6069. (insert (if (and (string= part dpart)
  6070. (or (not (string= part ""))
  6071. idlwave-complete-empty-string-as-lower-case)
  6072. (not idlwave-completion-force-default-case))
  6073. dcompletion
  6074. completion))
  6075. (if (eq t (try-completion completion list selector))
  6076. ;; Now this is a unique match
  6077. (idlwave-after-successful-completion type slash beg))
  6078. t)
  6079. ((or (eq completion t)
  6080. (and (= 1 (length (setq all-completions
  6081. (idlwave-uniquify
  6082. (all-completions part list
  6083. (or special-selector
  6084. selector))))))
  6085. (equal dpart dcompletion)))
  6086. ;; This is already complete
  6087. (idlwave-after-successful-completion type slash beg)
  6088. (message "%s is already the complete %s" part isa)
  6089. nil)
  6090. (t
  6091. ;; We cannot add something - offer a list.
  6092. (message "Making completion list...")
  6093. (unless idlwave-completion-help-links ; already set somewhere?
  6094. (mapc (lambda (x) ; Pass link prop through to highlight-linked
  6095. (let ((link (get-text-property 0 'link (car x))))
  6096. (if link
  6097. (push (cons (car x) link)
  6098. idlwave-completion-help-links))))
  6099. list))
  6100. (let* ((list all-completions)
  6101. ;; "complete" means, this is already a valid completion
  6102. (complete (memq spart all-completions))
  6103. (completion-highlight-first-word-only t)) ; XEmacs
  6104. ;; (completion-fixup-function ; Emacs
  6105. ;; (lambda () (and (eq (preceding-char) ?>)
  6106. ;; (re-search-backward " <" beg t)))))
  6107. (setq list (sort list (lambda (a b)
  6108. (string< (downcase a) (downcase b)))))
  6109. (if prepare-display-function
  6110. (setq list (funcall prepare-display-function list)))
  6111. (if (and (string= part dpart)
  6112. (or (not (string= part ""))
  6113. idlwave-complete-empty-string-as-lower-case)
  6114. (not idlwave-completion-force-default-case))
  6115. (setq list (mapcar (lambda (x)
  6116. (if (listp x)
  6117. (setcar x (downcase (car x)))
  6118. (setq x (downcase x)))
  6119. x)
  6120. list)))
  6121. (idlwave-display-completion-list list prompt beg complete))
  6122. t))))
  6123. (defun idlwave-complete-class ()
  6124. "Complete a class at point."
  6125. (interactive)
  6126. ;; Call `idlwave-routines' to make sure the class list will be available
  6127. (idlwave-routines)
  6128. ;; Check for the special case of completing empty string after pro/function
  6129. (if (let ((case-fold-search t))
  6130. (save-excursion
  6131. (and
  6132. (re-search-backward "\\<\\(pro\\|function\\)[ \t]+\\="
  6133. (- (point) 15) t)
  6134. (goto-char (point-min))
  6135. (re-search-forward
  6136. "^[ \t]*\\(pro\\|function\\)[ \t]+\\([a-zA-Z0-9_]+::\\)" nil t))))
  6137. ;; Yank the full class specification
  6138. (insert (match-string 2))
  6139. ;; Do the completion, using list gathered from `idlwave-routines'
  6140. (idlwave-complete-in-buffer
  6141. 'class 'class (idlwave-class-alist) nil
  6142. "Select a class" "class"
  6143. (lambda (list) ;; Push it to help-links if system help available
  6144. (mapcar (lambda (x)
  6145. (let* ((entry (idlwave-class-info x))
  6146. (link (nth 1 (assq 'link entry))))
  6147. (if link (push (cons x link)
  6148. idlwave-completion-help-links))
  6149. x))
  6150. list)))))
  6151. (defun idlwave-attach-classes (list type show-classes)
  6152. ;; Attach the proper class list to a LIST of completion items.
  6153. ;; TYPE, when 'kwd, shows classes for method keywords, when
  6154. ;; 'class-tag, for class tags, and otherwise for methods.
  6155. ;; SHOW-CLASSES is the value of `idlwave-completion-show-classes'.
  6156. (if (or (null show-classes) ; don't want to see classes
  6157. (null class-selector) ; not a method call
  6158. (and
  6159. (stringp class-selector) ; the class is already known
  6160. (not super-classes))) ; no possibilities for inheritance
  6161. ;; In these cases, we do not have to do anything
  6162. list
  6163. (let* ((do-prop (and (>= show-classes 0)
  6164. (>= emacs-major-version 21)))
  6165. (do-buf (not (= show-classes 0)))
  6166. ;; (do-dots (featurep 'xemacs))
  6167. (do-dots t)
  6168. (inherit (if (and (not (eq type 'class-tag)) super-classes)
  6169. (cons class-selector super-classes)))
  6170. (max (abs show-classes))
  6171. (lmax (if do-dots (apply 'max (mapcar 'length list))))
  6172. classes nclasses class-info space)
  6173. (mapcar
  6174. (lambda (x)
  6175. ;; get the classes
  6176. (if (eq type 'class-tag)
  6177. ;; Just one class for tags
  6178. (setq classes
  6179. (list
  6180. (idlwave-class-or-superclass-with-tag class-selector x)))
  6181. ;; Multiple classes for method or method-keyword
  6182. (setq classes
  6183. (if (eq type 'kwd)
  6184. (idlwave-all-method-keyword-classes
  6185. method-selector x type-selector)
  6186. (idlwave-all-method-classes x type-selector)))
  6187. (if inherit
  6188. (setq classes
  6189. (delq nil
  6190. (mapcar (lambda (x) (if (memq x inherit) x nil))
  6191. classes)))))
  6192. (setq nclasses (length classes))
  6193. ;; Make the separator between item and class-info
  6194. (if do-dots
  6195. (setq space (concat " " (make-string (- lmax (length x)) ?.)))
  6196. (setq space " "))
  6197. (if do-buf
  6198. ;; We do want info in the buffer
  6199. (if (<= nclasses max)
  6200. (setq class-info (concat
  6201. space
  6202. "<" (mapconcat 'identity classes ",") ">"))
  6203. (setq class-info (format "%s<%d classes>" space nclasses)))
  6204. (setq class-info nil))
  6205. (when do-prop
  6206. ;; We do want properties
  6207. (setq x (copy-sequence x))
  6208. (put-text-property 0 (length x)
  6209. 'help-echo (mapconcat 'identity classes " ")
  6210. x))
  6211. (if class-info
  6212. (list x class-info)
  6213. x))
  6214. list))))
  6215. (defun idlwave-attach-method-classes (list)
  6216. ;; Call idlwave-attach-classes with method parameters
  6217. (idlwave-attach-classes list 'method idlwave-completion-show-classes))
  6218. (defun idlwave-attach-keyword-classes (list)
  6219. ;; Call idlwave-attach-classes with keyword parameters
  6220. (idlwave-attach-classes list 'kwd idlwave-completion-show-classes))
  6221. (defun idlwave-attach-class-tag-classes (list)
  6222. ;; Call idlwave-attach-classes with class structure tags
  6223. (idlwave-attach-classes list 'class-tag idlwave-completion-show-classes))
  6224. ;;----------------------------------------------------------------------
  6225. ;;----------------------------------------------------------------------
  6226. ;;----------------------------------------------------------------------
  6227. ;;----------------------------------------------------------------------
  6228. ;;----------------------------------------------------------------------
  6229. (when (featurep 'xemacs)
  6230. (defvar rtn)
  6231. (defun idlwave-pset (item)
  6232. (set 'rtn item)))
  6233. (defun idlwave-popup-select (ev list title &optional sort)
  6234. "Select an item in LIST with a popup menu.
  6235. TITLE is the title to put atop the popup. If SORT is non-nil,
  6236. sort the list before displaying."
  6237. (let ((maxpopup idlwave-max-popup-menu-items)
  6238. rtn menu)
  6239. (cond ((null list))
  6240. ((= 1 (length list))
  6241. (setq rtn (car list)))
  6242. ((featurep 'xemacs)
  6243. (if sort (setq list (sort list (lambda (a b)
  6244. (string< (upcase a) (upcase b))))))
  6245. (setq menu
  6246. (append (list title)
  6247. (mapcar (lambda (x) (vector x (list 'idlwave-pset
  6248. x)))
  6249. list)))
  6250. (setq menu (idlwave-split-menu-xemacs menu maxpopup))
  6251. (let ((resp (get-popup-menu-response menu)))
  6252. (funcall (event-function resp) (event-object resp))))
  6253. (t
  6254. (if sort (setq list (sort list (lambda (a b)
  6255. (string< (upcase a) (upcase b))))))
  6256. (setq menu (cons title
  6257. (list
  6258. (append (list "")
  6259. (mapcar (lambda(x) (cons x x)) list)))))
  6260. (setq menu (idlwave-split-menu-emacs menu maxpopup))
  6261. (setq rtn (x-popup-menu ev menu))))
  6262. rtn))
  6263. (defun idlwave-split-menu-xemacs (menu N)
  6264. "Split the MENU into submenus of maximum length N."
  6265. (if (<= (length menu) (1+ N))
  6266. ;; No splitting needed
  6267. menu
  6268. (let* ((title (car menu))
  6269. (entries (cdr menu))
  6270. (menu (list title))
  6271. (cnt 0)
  6272. (nextmenu nil))
  6273. (while entries
  6274. (while (and entries (< cnt N))
  6275. (setq cnt (1+ cnt)
  6276. nextmenu (cons (car entries) nextmenu)
  6277. entries (cdr entries)))
  6278. (setq nextmenu (nreverse nextmenu))
  6279. (setq nextmenu (cons (format "%s...%s"
  6280. (aref (car nextmenu) 0)
  6281. (aref (nth (1- cnt) nextmenu) 0))
  6282. nextmenu))
  6283. (setq menu (cons nextmenu menu)
  6284. nextmenu nil
  6285. cnt 0))
  6286. (nreverse menu))))
  6287. (defun idlwave-split-menu-emacs (menu N)
  6288. "Split the MENU into submenus of maximum length N."
  6289. (if (<= (length (nth 1 menu)) (1+ N))
  6290. ;; No splitting needed
  6291. menu
  6292. (let* ((title (car menu))
  6293. (entries (cdr (nth 1 menu)))
  6294. (menu nil)
  6295. (cnt 0)
  6296. (nextmenu nil))
  6297. (while entries
  6298. (while (and entries (< cnt N))
  6299. (setq cnt (1+ cnt)
  6300. nextmenu (cons (car entries) nextmenu)
  6301. entries (cdr entries)))
  6302. (setq nextmenu (nreverse nextmenu))
  6303. (prin1 nextmenu)
  6304. (setq nextmenu (cons (format "%s...%s"
  6305. (car (car nextmenu))
  6306. (car (nth (1- cnt) nextmenu)))
  6307. nextmenu))
  6308. (setq menu (cons nextmenu menu)
  6309. nextmenu nil
  6310. cnt 0))
  6311. (setq menu (nreverse menu))
  6312. (setq menu (cons title menu))
  6313. menu)))
  6314. (defvar idlwave-completion-setup-hook nil)
  6315. (defun idlwave-scroll-completions (&optional message)
  6316. "Scroll the completion window on this frame."
  6317. (let ((cwin (get-buffer-window "*Completions*" 'visible))
  6318. (win (selected-window)))
  6319. (unwind-protect
  6320. (progn
  6321. (select-window cwin)
  6322. (condition-case nil
  6323. (scroll-up)
  6324. (error (if (and (listp last-command)
  6325. (nth 2 last-command))
  6326. (progn
  6327. (select-window win)
  6328. (eval idlwave-complete-after-success-form))
  6329. (set-window-start cwin (point-min)))))
  6330. (and message (message "%s" message)))
  6331. (select-window win))))
  6332. (defun idlwave-display-completion-list (list &optional message beg complete)
  6333. "Display the completions in LIST in the completions buffer and echo MESSAGE."
  6334. (unless (and (get-buffer-window "*Completions*")
  6335. (idlwave-local-value 'idlwave-completion-p "*Completions*"))
  6336. (move-marker idlwave-completion-mark beg)
  6337. (setq idlwave-before-completion-wconf (current-window-configuration)))
  6338. (if (featurep 'xemacs)
  6339. (idlwave-display-completion-list-xemacs
  6340. list)
  6341. (idlwave-display-completion-list-emacs list))
  6342. ;; Store a special value in `this-command'. When `idlwave-complete'
  6343. ;; finds this in `last-command', it will scroll the *Completions* buffer.
  6344. (setq this-command (list 'idlwave-display-completion-list message complete))
  6345. ;; Mark the completions buffer as created by cib
  6346. (idlwave-set-local 'idlwave-completion-p t "*Completions*")
  6347. ;; Fontify the classes
  6348. (if (and idlwave-completion-fontify-classes
  6349. (consp (car list)))
  6350. (idlwave-completion-fontify-classes))
  6351. ;; Run the hook
  6352. (run-hooks 'idlwave-completion-setup-hook)
  6353. ;; Display the message
  6354. (message "%s" (or message "Making completion list...done")))
  6355. (defun idlwave-choose (function &rest args)
  6356. "Call FUNCTION as a completion chooser and pass ARGS to it."
  6357. (let ((completion-ignore-case t)) ; install correct value
  6358. (apply function args))
  6359. (if (and (derived-mode-p 'idlwave-shell-mode)
  6360. (boundp 'font-lock-mode)
  6361. (not font-lock-mode))
  6362. ;; For the shell, remove the fontification of the word before point
  6363. (let ((beg (save-excursion
  6364. (skip-chars-backward "a-zA-Z0-9_")
  6365. (point))))
  6366. (remove-text-properties beg (point) '(face nil))))
  6367. (eval idlwave-complete-after-success-form-force))
  6368. (defun idlwave-keyboard-quit ()
  6369. (interactive)
  6370. (unwind-protect
  6371. (if (eq (car-safe last-command) 'idlwave-display-completion-list)
  6372. (idlwave-restore-wconf-after-completion))
  6373. (keyboard-quit)))
  6374. (defun idlwave-restore-wconf-after-completion ()
  6375. "Restore the old (before completion) window configuration."
  6376. (and idlwave-completion-restore-window-configuration
  6377. idlwave-before-completion-wconf
  6378. (set-window-configuration idlwave-before-completion-wconf)))
  6379. (defun idlwave-one-key-select (sym prompt delay)
  6380. "Make the user select an element from the alist in the variable SYM.
  6381. The keys of the alist are expected to be strings. The function returns the
  6382. car of the selected association.
  6383. To do this, PROMPT is displayed and the user must hit a letter key to
  6384. select an entry. If the user does not reply within DELAY seconds, a help
  6385. window with the options is displayed automatically.
  6386. The key which is associated with each option is generated automatically.
  6387. First, the strings are checked for preselected keys, like in \"[P]rint\".
  6388. If these don't exist, a letter in the string is automatically selected."
  6389. (let* ((alist (symbol-value sym))
  6390. (temp-buffer-show-hook (if (fboundp 'fit-window-to-buffer)
  6391. '(fit-window-to-buffer)))
  6392. keys-alist char)
  6393. ;; First check the cache
  6394. (if (and (eq (symbol-value sym) (get sym :one-key-alist-last)))
  6395. (setq keys-alist (get sym :one-key-alist-cache))
  6396. ;; Need to make new list
  6397. (setq keys-alist (idlwave-make-one-key-alist alist))
  6398. (put sym :one-key-alist-cache keys-alist)
  6399. (put sym :one-key-alist-last alist))
  6400. ;; Display prompt and wait for quick reply
  6401. (message "%s[%s]" prompt
  6402. (mapconcat (lambda(x) (char-to-string (car x)))
  6403. keys-alist ""))
  6404. (if (sit-for delay)
  6405. ;; No quick reply: Show help
  6406. (save-window-excursion
  6407. (with-output-to-temp-buffer "*Completions*"
  6408. (dolist (x keys-alist)
  6409. (princ (nth 1 x))
  6410. (princ "\n")))
  6411. (setq char (read-char)))
  6412. (setq char (read-char)))
  6413. (message nil)
  6414. ;; Return the selected result
  6415. (nth 2 (assoc char keys-alist))))
  6416. ;; Used for, e.g., electric debug super-examine.
  6417. (defun idlwave-make-one-key-alist (alist)
  6418. "Make an alist for single key selection."
  6419. (let ((l alist) keys-alist name start char help
  6420. (cnt 0)
  6421. (case-fold-search nil))
  6422. (while l
  6423. (setq name (car (car l))
  6424. l (cdr l))
  6425. (catch 'exit
  6426. ;; First check if the configuration predetermined a key
  6427. (if (string-match "\\[\\(.\\)\\]" name)
  6428. (progn
  6429. (setq char (string-to-char (downcase (match-string 1 name)))
  6430. help (format "%c: %s" char name)
  6431. keys-alist (cons (list char help name) keys-alist))
  6432. (throw 'exit t)))
  6433. ;; Then check for capital letters
  6434. (setq start 0)
  6435. (while (string-match "[A-Z]" name start)
  6436. (setq start (match-end 0)
  6437. char (string-to-char (downcase (match-string 0 name))))
  6438. (if (not (assoc char keys-alist))
  6439. (progn
  6440. (setq help (format "%c: %s" char
  6441. (replace-match
  6442. (concat "[" (match-string 0 name) "]")
  6443. t t name))
  6444. keys-alist (cons (list char help name) keys-alist))
  6445. (throw 'exit t))))
  6446. ;; Now check for lowercase letters
  6447. (setq start 0)
  6448. (while (string-match "[a-z]" name start)
  6449. (setq start (match-end 0)
  6450. char (string-to-char (match-string 0 name)))
  6451. (if (not (assoc char keys-alist))
  6452. (progn
  6453. (setq help (format "%c: %s" char
  6454. (replace-match
  6455. (concat "[" (match-string 0 name) "]")
  6456. t t name))
  6457. keys-alist (cons (list char help name) keys-alist))
  6458. (throw 'exit t))))
  6459. ;; Bummer, nothing found! Use a stupid number
  6460. (setq char (string-to-char (int-to-string (setq cnt (1+ cnt))))
  6461. help (format "%c: %s" char name)
  6462. keys-alist (cons (list char help name) keys-alist))))
  6463. (nreverse keys-alist)))
  6464. (defun idlwave-set-local (var value &optional buffer)
  6465. "Set the buffer-local value of VAR in BUFFER to VALUE."
  6466. (with-current-buffer (or buffer (current-buffer))
  6467. (set (make-local-variable var) value)))
  6468. (defun idlwave-local-value (var &optional buffer)
  6469. "Return the value of VAR in BUFFER, but only if VAR is local to BUFFER."
  6470. (with-current-buffer (or buffer (current-buffer))
  6471. (and (local-variable-p var (current-buffer))
  6472. (symbol-value var))))
  6473. ;; In XEmacs, we can use :activate-callback directly to advice the
  6474. ;; choose functions. We use the private keymap only for the online
  6475. ;; help feature.
  6476. (defvar idlwave-completion-map nil
  6477. "Keymap for `completion-list-mode' with `idlwave-complete'.")
  6478. (defun idlwave-display-completion-list-xemacs (list &rest cl-args)
  6479. (with-output-to-temp-buffer "*Completions*"
  6480. (apply 'display-completion-list list
  6481. ':activate-callback 'idlwave-default-choose-completion
  6482. cl-args))
  6483. (with-current-buffer "*Completions*"
  6484. (use-local-map
  6485. (or idlwave-completion-map
  6486. (setq idlwave-completion-map
  6487. (idlwave-make-modified-completion-map-xemacs
  6488. (current-local-map)))))))
  6489. (defun idlwave-default-choose-completion (&rest args)
  6490. "Execute `default-choose-completion' and then restore the win-conf."
  6491. (apply 'idlwave-choose 'default-choose-completion args))
  6492. (defun idlwave-make-modified-completion-map-xemacs (old-map)
  6493. "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
  6494. (let ((new-map (copy-keymap old-map)))
  6495. (define-key new-map [button3up] 'idlwave-mouse-completion-help)
  6496. (define-key new-map [button3] (lambda ()
  6497. (interactive)
  6498. (setq this-command last-command)))
  6499. new-map))
  6500. ;; In Emacs we also replace keybindings in the completion
  6501. ;; map in order to install our wrappers.
  6502. (defun idlwave-display-completion-list-emacs (list)
  6503. "Display completion list and install the choose wrappers."
  6504. (with-output-to-temp-buffer "*Completions*"
  6505. (display-completion-list list))
  6506. (with-current-buffer "*Completions*"
  6507. (use-local-map
  6508. (or idlwave-completion-map
  6509. (setq idlwave-completion-map
  6510. (idlwave-make-modified-completion-map-emacs
  6511. (current-local-map)))))))
  6512. (defun idlwave-make-modified-completion-map-emacs (old-map)
  6513. "Replace `choose-completion' and `mouse-choose-completion' in OLD-MAP."
  6514. (let ((new-map (copy-keymap old-map)))
  6515. (substitute-key-definition
  6516. 'choose-completion 'idlwave-choose-completion new-map)
  6517. (substitute-key-definition
  6518. 'mouse-choose-completion 'idlwave-mouse-choose-completion new-map)
  6519. (define-key new-map [mouse-3] 'idlwave-mouse-completion-help)
  6520. new-map))
  6521. (defun idlwave-choose-completion (&rest args)
  6522. "Choose the completion that point is in or next to."
  6523. (interactive)
  6524. (apply 'idlwave-choose 'choose-completion args))
  6525. (defun idlwave-mouse-choose-completion (&rest args)
  6526. "Click on an alternative in the `*Completions*' buffer to choose it."
  6527. (interactive "e")
  6528. (apply 'idlwave-choose 'mouse-choose-completion args))
  6529. ;;----------------------------------------------------------------------
  6530. ;;----------------------------------------------------------------------
  6531. ;;; ------------------------------------------------------------------------
  6532. ;;; Structure parsing code, and code to manage class info
  6533. ;;
  6534. ;; - Go again over the documentation how to write a completion
  6535. ;; plugin. It is in self.el, but currently still very bad.
  6536. ;; This could be in a separate file in the distribution, or
  6537. ;; in an appendix for the manual.
  6538. (defvar idlwave-struct-skip
  6539. "[ \t]*\\(\\$.*\n\\(^[ \t]*\\(\\$[ \t]*\\)?\\(;.*\\)?\n\\)*\\)?[ \t]*"
  6540. "Regexp for skipping continued blank or comment-only lines in structures.")
  6541. (defvar idlwave-struct-tag-regexp
  6542. (concat "[{,]" ;leading comma/brace
  6543. idlwave-struct-skip ; 4 groups
  6544. "\\([a-zA-Z][a-zA-Z0-9_]*\\)" ;the tag itself, group 5
  6545. "[ \t]*:") ; the final colon
  6546. "Regexp for structure tags.")
  6547. (defun idlwave-struct-tags ()
  6548. "Return a list of all tags in the structure defined at point.
  6549. Point is expected just before the opening `{' of the struct definition."
  6550. (save-excursion
  6551. (let* ((borders (idlwave-struct-borders))
  6552. (beg (car borders))
  6553. (end (cdr borders))
  6554. tags)
  6555. (goto-char beg)
  6556. (save-restriction
  6557. (narrow-to-region beg end)
  6558. (while (re-search-forward idlwave-struct-tag-regexp end t)
  6559. ;; Check if we are still on the top level of the structure.
  6560. (if (and (condition-case nil (progn (up-list -1) t) (error nil))
  6561. (= (point) beg))
  6562. (push (match-string-no-properties 5) tags))
  6563. (goto-char (match-end 0))))
  6564. (nreverse tags))))
  6565. (defun idlwave-find-struct-tag (tag)
  6566. "Find a given TAG in the structure defined at point."
  6567. (let* ((borders (idlwave-struct-borders))
  6568. (end (cdr borders))
  6569. (case-fold-search t))
  6570. (re-search-forward (concat "\\(^[ \t]*\\|[,{][ \t]*\\)" tag "[ \t]*:")
  6571. end t)))
  6572. (defun idlwave-struct-inherits ()
  6573. "Return a list of all `inherits' names in the struct at point.
  6574. Point is expected just before the opening `{' of the struct definition."
  6575. (save-excursion
  6576. (let* ((borders (idlwave-struct-borders))
  6577. (beg (car borders))
  6578. (end (cdr borders))
  6579. (case-fold-search t)
  6580. names)
  6581. (goto-char beg)
  6582. (save-restriction
  6583. (narrow-to-region beg end)
  6584. (while (re-search-forward
  6585. (concat "[{,]" ;leading comma/brace
  6586. idlwave-struct-skip ; 4 groups
  6587. "inherits" ; The INHERITS tag
  6588. idlwave-struct-skip ; 4 more
  6589. "\\([a-zA-Z][a-zA-Z0-9_]*\\)") ; The super-group, #9
  6590. end t)
  6591. ;; Check if we are still on the top level of the structure.
  6592. (if (and (condition-case nil (progn (up-list -1) t) (error nil))
  6593. (= (point) beg))
  6594. (push (match-string-no-properties 9) names))
  6595. (goto-char (match-end 0))))
  6596. (nreverse names))))
  6597. (defun idlwave-in-structure ()
  6598. "Return t if point is inside an IDL structure definition."
  6599. (let ((beg (point)))
  6600. (save-excursion
  6601. (if (not (or (idlwave-in-comment) (idlwave-in-quote)))
  6602. (if (idlwave-find-structure-definition nil nil 'back)
  6603. (let ((borders (idlwave-struct-borders)))
  6604. (or (= (car borders) (cdr borders)) ;; struct not yet closed...
  6605. (and (> beg (car borders)) (< beg (cdr borders))))))))))
  6606. (defun idlwave-struct-borders ()
  6607. "Return the borders of the {...} after point as a cons cell."
  6608. (let (beg)
  6609. (save-excursion
  6610. (skip-chars-forward "^{")
  6611. (setq beg (point))
  6612. (condition-case nil (forward-list 1)
  6613. (error (goto-char beg)))
  6614. (cons beg (point)))))
  6615. (defun idlwave-find-structure-definition (&optional var name bound)
  6616. "Search forward for a structure definition.
  6617. If VAR is non-nil, search for a structure assigned to variable VAR.
  6618. If NAME is non-nil, search for a named structure NAME, if a string,
  6619. or a generic named structure otherwise. If BOUND is an integer, limit
  6620. the search. If BOUND is the symbol `all', we search first back and
  6621. then forward through the entire file. If BOUND is the symbol `back'
  6622. we search only backward."
  6623. (let* ((ws "[ \t]*\\(\\$.*\n[ \t]*\\)*")
  6624. (case-fold-search t)
  6625. (lim (if (integerp bound) bound nil))
  6626. (re (concat
  6627. (if var
  6628. (concat "\\<" (regexp-quote (downcase var)) "\\>" ws)
  6629. "\\(\\)")
  6630. "=" ws "\\({\\)"
  6631. (if name
  6632. (if (stringp name)
  6633. (concat ws "\\(\\<" (downcase name) "\\)[^a-zA-Z0-9_$]")
  6634. ;; Just a generic name
  6635. (concat ws "\\<\\([a-zA-Z_0-9$]+\\)" ws ","))
  6636. ""))))
  6637. (if (or (and (or (eq bound 'all) (eq bound 'back))
  6638. (re-search-backward re nil t))
  6639. (and (not (eq bound 'back)) (re-search-forward re lim t)))
  6640. (progn
  6641. (goto-char (match-beginning 3))
  6642. (match-string-no-properties 5)))))
  6643. (defvar idlwave-class-info nil)
  6644. (defvar idlwave-class-reset nil) ; to reset buffer-local classes
  6645. (add-hook 'idlwave-update-rinfo-hook
  6646. (lambda () (setq idlwave-class-reset t)))
  6647. (add-hook 'idlwave-after-load-rinfo-hook
  6648. (lambda () (setq idlwave-class-info nil)))
  6649. (defun idlwave-class-info (class)
  6650. (let (list entry)
  6651. (if idlwave-class-info
  6652. (if idlwave-class-reset
  6653. (setq
  6654. idlwave-class-reset nil
  6655. idlwave-class-info ; Remove any visited in a buffer
  6656. (delq nil (mapcar
  6657. (lambda (x)
  6658. (let ((filebuf
  6659. (idlwave-class-file-or-buffer
  6660. (or (cdr (assq 'found-in x)) (car x)))))
  6661. (if (cdr filebuf)
  6662. nil
  6663. x)))
  6664. idlwave-class-info))))
  6665. ;; Info is nil, put in the system stuff to start.
  6666. (setq idlwave-class-info idlwave-system-class-info)
  6667. (setq list idlwave-class-info)
  6668. (while (setq entry (pop list))
  6669. (idlwave-sintern-class-info entry)))
  6670. (setq class (idlwave-sintern-class class))
  6671. (or (assq class idlwave-class-info)
  6672. (progn (idlwave-scan-class-info class)
  6673. (assq class idlwave-class-info)))))
  6674. (defun idlwave-sintern-class-info (entry)
  6675. "Sintern the class names in a class-info entry."
  6676. (let ((inherits (assq 'inherits entry)))
  6677. (setcar entry (idlwave-sintern-class (car entry) 'set))
  6678. (if inherits
  6679. (setcdr inherits (mapcar (lambda (x) (idlwave-sintern-class x 'set))
  6680. (cdr inherits))))))
  6681. (defun idlwave-find-class-definition (class &optional all-hook alt-class)
  6682. "Find class structure definition(s).
  6683. If ALL-HOOK is set, find all named structure definitions in a given
  6684. class__define routine, on which ALL-HOOK will be run. If ALT-CLASS is
  6685. set, look for the name__define pro, and inside of it, for the ALT-CLASS
  6686. class/struct definition."
  6687. (let ((case-fold-search t) end-lim name)
  6688. (when (re-search-forward
  6689. (concat "^[ \t]*pro[ \t]+" (downcase class) "__define" "\\>") nil t)
  6690. (if all-hook
  6691. (progn
  6692. ;; For everything there
  6693. (setq end-lim (save-excursion (idlwave-end-of-subprogram) (point)))
  6694. (while (setq name
  6695. (idlwave-find-structure-definition nil t end-lim))
  6696. (funcall all-hook name)))
  6697. (idlwave-find-structure-definition nil (or alt-class class))))))
  6698. (defun idlwave-class-file-or-buffer (class)
  6699. "Find buffer visiting CLASS definition."
  6700. (let* ((pro (concat (downcase class) "__define"))
  6701. (file (idlwave-routine-source-file
  6702. (nth 3 (idlwave-rinfo-assoc pro 'pro nil
  6703. (idlwave-routines))))))
  6704. (cons file (if file (idlwave-get-buffer-visiting file)))))
  6705. (defun idlwave-scan-class-info (class)
  6706. "Scan all class and named structure info in the class__define pro."
  6707. (let* ((idlwave-auto-routine-info-updates nil)
  6708. (filebuf (idlwave-class-file-or-buffer class))
  6709. (file (car filebuf))
  6710. (buf (cdr filebuf))
  6711. (class (idlwave-sintern-class class)))
  6712. (if (or
  6713. (not file)
  6714. (and ;; neither a regular file nor a visited buffer
  6715. (not buf)
  6716. (not (file-regular-p file))))
  6717. nil ; Cannot find the file/buffer to get any info
  6718. (save-excursion
  6719. (if buf (set-buffer buf)
  6720. ;; Read the file in temporarily
  6721. (set-buffer (get-buffer-create " *IDLWAVE-tmp*"))
  6722. (erase-buffer)
  6723. (unless (derived-mode-p 'idlwave-mode)
  6724. (idlwave-mode))
  6725. (insert-file-contents file))
  6726. (save-excursion
  6727. (goto-char 1)
  6728. (idlwave-find-class-definition class
  6729. ;; Scan all of the structures found there
  6730. (lambda (name)
  6731. (let* ((this-class (idlwave-sintern-class name))
  6732. (entry
  6733. (list this-class
  6734. (cons 'tags (idlwave-struct-tags))
  6735. (cons 'inherits (idlwave-struct-inherits)))))
  6736. (if (not (eq this-class class))
  6737. (setq entry (nconc entry (list (cons 'found-in class)))))
  6738. (idlwave-sintern-class-info entry)
  6739. (push entry idlwave-class-info)))))))))
  6740. (defun idlwave-class-found-in (class)
  6741. "Return the FOUND-IN property of the CLASS."
  6742. (cdr (assq 'found-in (idlwave-class-info class))))
  6743. (defun idlwave-class-tags (class)
  6744. "Return the native tags in CLASS."
  6745. (cdr (assq 'tags (idlwave-class-info class))))
  6746. (defun idlwave-class-inherits (class)
  6747. "Return the direct superclasses of CLASS."
  6748. (cdr (assq 'inherits (idlwave-class-info class))))
  6749. (defun idlwave-all-class-tags (class)
  6750. "Return a list of native and inherited tags in CLASS."
  6751. (condition-case err
  6752. (apply 'append (mapcar 'idlwave-class-tags
  6753. (cons class (idlwave-all-class-inherits class))))
  6754. (error
  6755. (idlwave-class-tag-reset)
  6756. (error "%s" (error-message-string err)))))
  6757. (defun idlwave-all-class-inherits (class)
  6758. "Return a list of all superclasses of CLASS (recursively expanded).
  6759. The list is cached in `idlwave-class-info' for faster access."
  6760. (cond
  6761. ((not idlwave-support-inheritance) nil)
  6762. ((eq class nil) nil)
  6763. ((eq class t) nil)
  6764. (t
  6765. (let ((info (idlwave-class-info class))
  6766. entry)
  6767. (if (setq entry (assq 'all-inherits info))
  6768. (cdr entry)
  6769. ;; Save the depth of inheritance scan to check for circular references
  6770. (let ((inherits (mapcar (lambda (x) (cons x 0))
  6771. (idlwave-class-inherits class)))
  6772. rtn all-inherits cl)
  6773. (while inherits
  6774. (setq cl (pop inherits)
  6775. rtn (cons (car cl) rtn)
  6776. inherits (append (mapcar (lambda (x)
  6777. (cons x (1+ (cdr cl))))
  6778. (idlwave-class-inherits (car cl)))
  6779. inherits))
  6780. (if (> (cdr cl) 999)
  6781. (error
  6782. "Class scan: inheritance depth exceeded. Circular inheritance?")
  6783. ))
  6784. (setq all-inherits (nreverse rtn))
  6785. (nconc info (list (cons 'all-inherits all-inherits)))
  6786. all-inherits))))))
  6787. (defun idlwave-entry-keywords (entry &optional record-link)
  6788. "Return the flat entry keywords alist from routine-info entry.
  6789. If RECORD-LINK is non-nil, the keyword text is copied and a text
  6790. property indicating the link is added."
  6791. (let (kwds)
  6792. (mapc
  6793. (lambda (key-list)
  6794. (let ((file (car key-list)))
  6795. (mapcar (lambda (key-cons)
  6796. (let ((key (car key-cons))
  6797. (link (cdr key-cons)))
  6798. (when (and record-link file)
  6799. (setq key (copy-sequence key))
  6800. (put-text-property
  6801. 0 (length key)
  6802. 'link
  6803. (concat
  6804. file
  6805. (if link
  6806. (concat idlwave-html-link-sep
  6807. (number-to-string link))))
  6808. key))
  6809. (push (list key) kwds)))
  6810. (cdr key-list))))
  6811. (nthcdr 5 entry))
  6812. (nreverse kwds)))
  6813. (defun idlwave-entry-find-keyword (entry keyword)
  6814. "Find keyword KEYWORD in entry ENTRY, and return (with link) if set."
  6815. (catch 'exit
  6816. (mapc
  6817. (lambda (key-list)
  6818. (let ((file (car key-list))
  6819. (kwd (assoc keyword (cdr key-list))))
  6820. (when kwd
  6821. (setq kwd (cons (car kwd)
  6822. (if (and file (cdr kwd))
  6823. (concat file
  6824. idlwave-html-link-sep
  6825. (number-to-string (cdr kwd)))
  6826. (cdr kwd))))
  6827. (throw 'exit kwd))))
  6828. (nthcdr 5 entry))))
  6829. ;;==========================================================================
  6830. ;;
  6831. ;; Completing class structure tags. This is a completion plugin.
  6832. ;; The necessary taglist is constructed dynamically
  6833. (defvar idlwave-current-tags-class nil)
  6834. (defvar idlwave-current-class-tags nil)
  6835. (defvar idlwave-current-native-class-tags nil)
  6836. (defvar idlwave-sint-class-tags nil)
  6837. (declare-function idlwave-sintern-class-tag "idlwave" t t)
  6838. (idlwave-new-sintern-type 'class-tag)
  6839. (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
  6840. (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
  6841. (defun idlwave-complete-class-structure-tag ()
  6842. "Complete a structure tag on a `self' argument in an object method."
  6843. (interactive)
  6844. (let ((pos (point))
  6845. (case-fold-search t))
  6846. (if (save-excursion
  6847. ;; Check if the context is right
  6848. (skip-chars-backward "a-zA-Z0-9._$")
  6849. (and (< (point) (- pos 4))
  6850. (looking-at "self\\.")))
  6851. (let* ((class-selector (nth 2 (idlwave-current-routine)))
  6852. (super-classes (idlwave-all-class-inherits class-selector)))
  6853. ;; Check if we are in a class routine
  6854. (unless class-selector
  6855. (error "Not in a method procedure or function"))
  6856. ;; Check if we need to update the "current" class
  6857. (if (not (equal class-selector idlwave-current-tags-class))
  6858. (idlwave-prepare-class-tag-completion class-selector))
  6859. (setq idlwave-completion-help-info
  6860. (list 'idlwave-complete-class-structure-tag-help
  6861. (idlwave-sintern-routine
  6862. (concat class-selector "__define"))
  6863. nil))
  6864. ;; FIXME: idlwave-cpl-bold doesn't seem used anywhere.
  6865. (let ((idlwave-cpl-bold idlwave-current-native-class-tags))
  6866. (idlwave-complete-in-buffer
  6867. 'class-tag 'class-tag
  6868. idlwave-current-class-tags nil
  6869. (format "Select a tag of class %s" class-selector)
  6870. "class tag"
  6871. 'idlwave-attach-class-tag-classes))
  6872. t) ; return t to skip other completions
  6873. nil)))
  6874. (defun idlwave-class-tag-reset ()
  6875. (setq idlwave-current-tags-class nil))
  6876. (defun idlwave-prepare-class-tag-completion (class)
  6877. "Find and parse the necessary class definitions for class structure tags."
  6878. (setq idlwave-sint-class-tags nil)
  6879. (setq idlwave-current-tags-class class)
  6880. (setq idlwave-current-class-tags
  6881. (mapcar (lambda (x)
  6882. (list (idlwave-sintern-class-tag x 'set)))
  6883. (idlwave-all-class-tags class)))
  6884. (setq idlwave-current-native-class-tags
  6885. (mapcar 'downcase (idlwave-class-tags class))))
  6886. ;===========================================================================
  6887. ;;
  6888. ;; Completing system variables and their structure fields
  6889. ;; This is also a plugin.
  6890. (defvar idlwave-sint-sysvars nil)
  6891. (defvar idlwave-sint-sysvartags nil)
  6892. (declare-function idlwave-sintern-sysvar "idlwave" t t)
  6893. (declare-function idlwave-sintern-sysvartag "idlwave" t t)
  6894. (idlwave-new-sintern-type 'sysvar)
  6895. (idlwave-new-sintern-type 'sysvartag)
  6896. (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
  6897. (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
  6898. (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
  6899. (defun idlwave-complete-sysvar-or-tag ()
  6900. "Complete a system variable."
  6901. (interactive)
  6902. (let ((pos (point))
  6903. (case-fold-search t))
  6904. (cond ((save-excursion
  6905. ;; Check if the context is right for system variable
  6906. (skip-chars-backward "[a-zA-Z0-9_$]")
  6907. (equal (char-before) ?!))
  6908. (setq idlwave-completion-help-info '(idlwave-complete-sysvar-help))
  6909. (idlwave-complete-in-buffer 'sysvar 'sysvar
  6910. idlwave-system-variables-alist nil
  6911. "Select a system variable"
  6912. "system variable")
  6913. t) ; return t to skip other completions
  6914. ((save-excursion
  6915. ;; Check if the context is right for sysvar tag
  6916. (skip-chars-backward "a-zA-Z0-9_$.")
  6917. (and (equal (char-before) ?!)
  6918. (looking-at "\\([a-zA-Z][a-zA-Z0-9_$]*\\)\\.")
  6919. (<= (match-end 0) pos)))
  6920. ;; Complete a system variable tag
  6921. (let* ((var (idlwave-sintern-sysvar (match-string 1)))
  6922. (entry (assq var idlwave-system-variables-alist))
  6923. (tags (cdr (assq 'tags entry))))
  6924. (or entry (error "!%s is not a known system variable" var))
  6925. (or tags (error "System variable !%s is not a structure" var))
  6926. (setq idlwave-completion-help-info
  6927. (list 'idlwave-complete-sysvar-tag-help var))
  6928. (idlwave-complete-in-buffer 'sysvartag 'sysvartag
  6929. tags nil
  6930. "Select a system variable tag"
  6931. "system variable tag")
  6932. t)) ; return t to skip other completions
  6933. (t nil))))
  6934. (defvar idlw-help-link) ;dynamic variables set by help callback
  6935. (defun idlwave-complete-sysvar-help (mode word)
  6936. (let ((word (or (nth 1 idlwave-completion-help-info) word))
  6937. (entry (assoc word idlwave-system-variables-alist)))
  6938. (cond
  6939. ((eq mode 'test)
  6940. (and (stringp word) entry (nth 1 (assq 'link entry))))
  6941. ((eq mode 'set)
  6942. ;; Setting dynamic!!!
  6943. (if entry (setq idlw-help-link (nth 1 (assq 'link entry)))))
  6944. (t (error "This should not happen")))))
  6945. (defun idlwave-complete-sysvar-tag-help (mode word)
  6946. (let* ((var (nth 1 idlwave-completion-help-info))
  6947. (entry (assoc var idlwave-system-variables-alist))
  6948. (tags (cdr (assq 'tags entry)))
  6949. (main (nth 1 (assq 'link entry)))
  6950. target)
  6951. (cond
  6952. ((eq mode 'test) ; we can at least link the main
  6953. (and (stringp word) entry main))
  6954. ((eq mode 'set)
  6955. (if entry
  6956. (setq idlw-help-link
  6957. (if (setq target (cdr (assoc-string word tags t)))
  6958. (idlwave-substitute-link-target main target)
  6959. main)))) ;; setting dynamic!!!
  6960. (t (error "This should not happen")))))
  6961. (defun idlwave-split-link-target (link)
  6962. "Split a given LINK into link file and anchor."
  6963. (if (string-match idlwave-html-link-sep link)
  6964. (cons (substring link 0 (match-beginning 0))
  6965. (string-to-number (substring link (match-end 0))))))
  6966. (defun idlwave-substitute-link-target (link target)
  6967. "Substitute the TARGET anchor for the given LINK."
  6968. (let (main-base)
  6969. (setq main-base (if (string-match "#" link)
  6970. (substring link 0 (match-beginning 0))
  6971. link))
  6972. (if target
  6973. (concat main-base idlwave-html-link-sep (number-to-string target))
  6974. link)))
  6975. ;; Fake help in the source buffer for class structure tags.
  6976. ;; IDLW-HELP-LINK AND IDLW-HELP-NAME ARE GLOBAL-VARIABLES HERE.
  6977. ;; (from idlwave-do-mouse-completion-help)
  6978. (defvar idlw-help-name)
  6979. (defvar idlw-help-link)
  6980. (defvar idlwave-help-do-class-struct-tag nil)
  6981. (defun idlwave-complete-class-structure-tag-help (mode word)
  6982. (cond
  6983. ((eq mode 'test) ; nothing gets fontified for class tags
  6984. nil)
  6985. ((eq mode 'set)
  6986. (let (class-with found-in)
  6987. (when (setq class-with
  6988. (idlwave-class-or-superclass-with-tag
  6989. idlwave-current-tags-class
  6990. word))
  6991. (if (assq (idlwave-sintern-class class-with)
  6992. idlwave-system-class-info)
  6993. (error "No help available for system class tags"))
  6994. (if (setq found-in (idlwave-class-found-in class-with))
  6995. (setq idlw-help-name (cons (concat found-in "__define") class-with))
  6996. (setq idlw-help-name (concat class-with "__define")))))
  6997. (setq idlw-help-link word
  6998. idlwave-help-do-class-struct-tag t))
  6999. (t (error "This should not happen"))))
  7000. (defun idlwave-class-or-superclass-with-tag (class tag)
  7001. "Find and return the CLASS or one of its superclass with the
  7002. associated TAG, if any."
  7003. (let ((sclasses (cons class (idlwave-all-class-inherits class)))
  7004. cl)
  7005. (catch 'exit
  7006. (while sclasses
  7007. (setq cl (pop sclasses))
  7008. (let ((tags (idlwave-class-tags cl)))
  7009. (while tags
  7010. (if (eq t (compare-strings tag 0 nil (car tags) 0 nil t))
  7011. (throw 'exit cl))
  7012. (setq tags (cdr tags))))))))
  7013. (defun idlwave-sysvars-reset ()
  7014. (if (and (fboundp 'idlwave-shell-is-running)
  7015. (idlwave-shell-is-running)
  7016. idlwave-idlwave_routine_info-compiled)
  7017. (idlwave-shell-send-command "idlwave_get_sysvars"
  7018. 'idlwave-process-sysvars 'hide)))
  7019. (defun idlwave-process-sysvars ()
  7020. (idlwave-shell-filter-sysvars)
  7021. (setq idlwave-sint-sysvars nil
  7022. idlwave-sint-sysvartags nil)
  7023. (idlwave-sintern-sysvar-alist))
  7024. (defun idlwave-sintern-sysvar-alist ()
  7025. (let ((list idlwave-system-variables-alist) entry tags)
  7026. (while (setq entry (pop list))
  7027. (setcar entry (idlwave-sintern-sysvar (car entry) 'set))
  7028. (setq tags (assq 'tags entry))
  7029. (if tags
  7030. (setcdr tags
  7031. (mapcar (lambda (x)
  7032. (cons (idlwave-sintern-sysvartag (car x) 'set)
  7033. (cdr x)))
  7034. (cdr tags)))))))
  7035. (defvar idlwave-shell-command-output)
  7036. (defun idlwave-shell-filter-sysvars ()
  7037. "Get any new system variables and tags."
  7038. (let ((text idlwave-shell-command-output)
  7039. (start 0)
  7040. (old idlwave-system-variables-alist)
  7041. var tags type name class link old-entry)
  7042. (setq idlwave-system-variables-alist nil)
  7043. (while (string-match "^IDLWAVE-SYSVAR: !\\([a-zA-Z0-9_$]+\\)\\( \\(.*\\)\\)?"
  7044. text start)
  7045. (setq start (match-end 0)
  7046. var (match-string 1 text)
  7047. tags (if (match-end 3)
  7048. (idlwave-split-string (match-string 3 text))))
  7049. ;; Maintain old links, if present
  7050. (setq old-entry (assq (idlwave-sintern-sysvar var) old))
  7051. (setq link (assq 'link old-entry))
  7052. (setq idlwave-system-variables-alist
  7053. (cons (list var
  7054. (cons
  7055. 'tags
  7056. (mapcar (lambda (x)
  7057. (cons x
  7058. (cdr (assq
  7059. (idlwave-sintern-sysvartag x)
  7060. (cdr (assq 'tags old-entry))))))
  7061. tags)) link)
  7062. idlwave-system-variables-alist)))
  7063. ;; Keep the old value if query was not successful
  7064. (setq idlwave-system-variables-alist
  7065. (or idlwave-system-variables-alist old))))
  7066. (defun idlwave-completion-fontify-classes ()
  7067. "Goto the *Completions* buffer and fontify the class info."
  7068. (when (featurep 'font-lock)
  7069. (with-current-buffer "*Completions*"
  7070. (save-excursion
  7071. (goto-char (point-min))
  7072. (let ((buffer-read-only nil))
  7073. (while (re-search-forward "\\.*<[^>]+>" nil t)
  7074. (put-text-property (match-beginning 0) (match-end 0)
  7075. 'face 'font-lock-string-face)))))))
  7076. (defun idlwave-uniquify (list)
  7077. (let ((ht (make-hash-table :size (length list) :test 'equal)))
  7078. (delq nil
  7079. (mapcar (lambda (x)
  7080. (unless (gethash x ht)
  7081. (puthash x t ht)
  7082. x))
  7083. list))))
  7084. (defun idlwave-after-successful-completion (type slash &optional verify)
  7085. "Add `=' or `(' after successful completion of keyword and function.
  7086. Restore the pre-completion window configuration if possible."
  7087. (cond
  7088. ((eq type 'procedure)
  7089. nil)
  7090. ((eq type 'function)
  7091. (cond
  7092. ((equal idlwave-function-completion-adds-paren nil) nil)
  7093. ((or (equal idlwave-function-completion-adds-paren t)
  7094. (equal idlwave-function-completion-adds-paren 1))
  7095. (insert "("))
  7096. ((equal idlwave-function-completion-adds-paren 2)
  7097. (insert "()")
  7098. (backward-char 1))
  7099. (t nil)))
  7100. ((eq type 'keyword)
  7101. (if (and idlwave-keyword-completion-adds-equal
  7102. (not slash))
  7103. (progn (insert "=") t)
  7104. nil)))
  7105. ;; Restore the pre-completion window configuration if this is safe.
  7106. (if (or (eq verify 'force) ; force
  7107. (and
  7108. (get-buffer-window "*Completions*") ; visible
  7109. (idlwave-local-value 'idlwave-completion-p
  7110. "*Completions*") ; cib-buffer
  7111. (eq (marker-buffer idlwave-completion-mark)
  7112. (current-buffer)) ; buffer OK
  7113. (equal (marker-position idlwave-completion-mark)
  7114. verify))) ; pos OK
  7115. (idlwave-restore-wconf-after-completion))
  7116. (move-marker idlwave-completion-mark nil)
  7117. (setq idlwave-before-completion-wconf nil))
  7118. (defun idlwave-mouse-context-help (ev &optional arg)
  7119. "Call `idlwave-context-help' on the clicked location."
  7120. (interactive "eP")
  7121. (mouse-set-point ev)
  7122. (idlwave-context-help arg))
  7123. (defvar idlwave-last-context-help-pos nil)
  7124. (defun idlwave-context-help (&optional arg)
  7125. "Display IDL Online Help on context.
  7126. If point is on a keyword, help for that keyword will be shown. If
  7127. point is on a routine name or in the argument list of a routine, help
  7128. for that routine will be displayed. Works for system routines and
  7129. keywords, it pulls up text help. For other routines and keywords,
  7130. visits the source file, finding help in the header (if
  7131. `idlwave-help-source-try-header' is non-nil) or the routine definition
  7132. itself."
  7133. (interactive "P")
  7134. (idlwave-do-context-help arg))
  7135. (defun idlwave-mouse-completion-help (ev)
  7136. "Display online help about the completion at point."
  7137. (interactive "eP")
  7138. ;; Restore last-command for next command, to make
  7139. ;; scrolling/canceling of completions work.
  7140. (setq this-command last-command)
  7141. (idlwave-do-mouse-completion-help ev))
  7142. (defun idlwave-routine-info (&optional arg external)
  7143. "Display a routines calling sequence and list of keywords.
  7144. When point is on the name a function or procedure, or in the argument
  7145. list of a function or procedure, this command displays a help buffer with
  7146. the information. When called with prefix arg, enforce class query.
  7147. When point is on an object operator `->', display the class stored in
  7148. this arrow, if any (see `idlwave-store-inquired-class'). With a prefix
  7149. arg, the class property is cleared out."
  7150. (interactive "P")
  7151. (idlwave-routines)
  7152. (if (string-match "->" (buffer-substring
  7153. (max (point-min) (1- (point)))
  7154. (min (+ 2 (point)) (point-max))))
  7155. ;; Cursor is on an arrow
  7156. (if (get-text-property (point) 'idlwave-class)
  7157. ;; arrow has class property
  7158. (if arg
  7159. ;; Remove property
  7160. (save-excursion
  7161. (backward-char 1)
  7162. (when (looking-at ".?\\(->\\)")
  7163. (remove-text-properties (match-beginning 1) (match-end 1)
  7164. '(idlwave-class nil face nil))
  7165. (message "Class property removed from arrow")))
  7166. ;; Echo class property
  7167. (message "Arrow has text property identifying object to be class %s"
  7168. (get-text-property (point) 'idlwave-class)))
  7169. ;; No property found
  7170. (message "Arrow has no class text property"))
  7171. ;; Not on an arrow...
  7172. (let* ((idlwave-query-class nil)
  7173. (idlwave-force-class-query (equal arg '(4)))
  7174. (module (idlwave-what-module)))
  7175. (if (car module)
  7176. (apply 'idlwave-display-calling-sequence
  7177. (idlwave-fix-module-if-obj_new module))
  7178. (error "Don't know which calling sequence to show")))))
  7179. (defun idlwave-resolve (&optional arg)
  7180. "Call RESOLVE_ROUTINE on the module name at point.
  7181. Like `idlwave-routine-info', this looks for a routine call at point.
  7182. After confirmation in the minibuffer, it will use the shell to issue
  7183. a RESOLVE call for this routine, to attempt to make it defined and its
  7184. routine info available for IDLWAVE. If the routine is a method call,
  7185. both `class__method' and `class__define' will be tried.
  7186. With ARG, enforce query for the class of object methods."
  7187. (interactive "P")
  7188. (let* ((idlwave-query-class nil)
  7189. (idlwave-force-class-query (equal arg '(4)))
  7190. (module (idlwave-what-module))
  7191. (name (idlwave-make-full-name (nth 2 module) (car module)))
  7192. (type (if (eq (nth 1 module) 'pro) "pro" "function"))
  7193. (resolve (read-string "Resolve: " (format "%s %s" type name)))
  7194. (kwd "")
  7195. class)
  7196. (if (string-match "\\(pro\\|function\\)[ \t]+\\(\\(.*\\)::\\)?\\(.*\\)"
  7197. resolve)
  7198. (setq type (match-string 1 resolve)
  7199. class (if (match-beginning 2)
  7200. (match-string 3 resolve)
  7201. nil)
  7202. name (match-string 4 resolve)))
  7203. (if (string= (downcase type) "function")
  7204. (setq kwd ",/is_function"))
  7205. (cond
  7206. ((null class)
  7207. (idlwave-shell-send-command
  7208. (format "resolve_routine,'%s'%s" (downcase name) kwd)
  7209. 'idlwave-update-routine-info
  7210. nil t))
  7211. (t
  7212. (idlwave-shell-send-command
  7213. (format "resolve_routine,'%s__define'%s" (downcase class) kwd)
  7214. (list 'idlwave-shell-send-command
  7215. (format "resolve_routine,'%s__%s'%s"
  7216. (downcase class) (downcase name) kwd)
  7217. '(idlwave-update-routine-info)
  7218. nil t))))))
  7219. (defun idlwave-find-module-this-file ()
  7220. (interactive)
  7221. (idlwave-find-module '(4)))
  7222. (defun idlwave-find-module (&optional arg)
  7223. "Find the source code of an IDL module.
  7224. Works for modules for which IDLWAVE has routine info available.
  7225. The function offers as default the module name `idlwave-routine-info'
  7226. would use. With ARG limit to this buffer. With two prefix ARG's
  7227. force class query for object methods."
  7228. (interactive "P")
  7229. (let* ((idlwave-query-class nil)
  7230. (idlwave-force-class-query (equal arg '(16)))
  7231. (this-buffer (equal arg '(4)))
  7232. (module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
  7233. (default (if module
  7234. (concat (idlwave-make-full-name
  7235. (nth 2 module) (car module))
  7236. (if (eq (nth 1 module) 'pro) "<p>" "<f>"))
  7237. "none"))
  7238. (list
  7239. (idlwave-uniquify
  7240. (delq nil
  7241. (mapcar (lambda (x)
  7242. (if (eq 'system (car-safe (nth 3 x)))
  7243. ;; Take out system routines with no source.
  7244. nil
  7245. (list
  7246. (concat (idlwave-make-full-name
  7247. (nth 2 x) (car x))
  7248. (if (eq (nth 1 x) 'pro) "<p>" "<f>")))))
  7249. (if this-buffer
  7250. (idlwave-save-buffer-update)
  7251. (idlwave-routines))))))
  7252. (name (idlwave-completing-read
  7253. (if (or (not this-buffer)
  7254. (assoc default list))
  7255. (format "Module (Default %s): " default)
  7256. (format "Module in this file: "))
  7257. list))
  7258. type class)
  7259. (if (string-match "\\`\\s-*\\'" name)
  7260. ;; Nothing, use the default.
  7261. (setq name default))
  7262. (if (string-match "<[fp]>" name)
  7263. (setq type (substring name -2 -1)
  7264. name (substring name 0 -3)))
  7265. (if (string-match "\\(.*\\)::\\(.*\\)" name)
  7266. (setq class (match-string 1 name)
  7267. name (match-string 2 name)))
  7268. (setq name (idlwave-sintern-routine-or-method name class)
  7269. class (idlwave-sintern-class class)
  7270. type (cond ((equal type "f") 'fun)
  7271. ((equal type "p") 'pro)
  7272. (t t)))
  7273. (idlwave-do-find-module name type class nil this-buffer)))
  7274. (defun idlwave-do-find-module (name type class
  7275. &optional force-source this-buffer)
  7276. (let ((name1 (idlwave-make-full-name class name))
  7277. source buf1 entry
  7278. (buf (current-buffer))
  7279. (pos (point))
  7280. file name2)
  7281. (setq entry (idlwave-best-rinfo-assq name type class (idlwave-routines)
  7282. 'WITH-FILE)
  7283. source (or force-source (nth 3 entry))
  7284. name2 (if (nth 2 entry)
  7285. (idlwave-make-full-name (nth 2 entry) name)
  7286. name1))
  7287. (if source
  7288. (setq file (idlwave-routine-source-file source)))
  7289. (unless file ; Try to find it on the path.
  7290. (setq file
  7291. (idlwave-expand-lib-file-name
  7292. (if class
  7293. (format "%s__define.pro" (downcase class))
  7294. (format "%s.pro" (downcase name))))))
  7295. (cond
  7296. ((or (null name) (equal name ""))
  7297. (error "Abort"))
  7298. ((eq (car source) 'system)
  7299. (error "Source code for system routine %s is not available"
  7300. name2))
  7301. ((or (not file) (not (file-regular-p file)))
  7302. (error "Source code for routine %s is not available"
  7303. name2))
  7304. (t
  7305. (when (not this-buffer)
  7306. (setq buf1
  7307. (idlwave-find-file-noselect file 'find))
  7308. (pop-to-buffer buf1 t))
  7309. (goto-char (point-max))
  7310. (let ((case-fold-search t))
  7311. (if (re-search-backward
  7312. (concat "^[ \t]*\\<"
  7313. (cond ((eq type 'fun) "function")
  7314. ((eq type 'pro) "pro")
  7315. (t "\\(pro\\|function\\)"))
  7316. "\\>[ \t]+"
  7317. (regexp-quote (downcase name2))
  7318. "[^a-zA-Z0-9_$]")
  7319. nil t)
  7320. (goto-char (match-beginning 0))
  7321. (pop-to-buffer buf)
  7322. (goto-char pos)
  7323. (error "Could not find routine %s" name2)))))))
  7324. (defun idlwave-what-module ()
  7325. "Return a default module for stuff near point.
  7326. Used by `idlwave-routine-info' and `idlwave-find-module'."
  7327. (idlwave-routines)
  7328. (if (let ((case-fold-search t))
  7329. (save-excursion
  7330. (idlwave-beginning-of-statement)
  7331. (looking-at "[ \t]*\\(pro\\|function\\)[ \t]+\\(\\([a-zA-Z0-9_$]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)\\([, \t\n]\\|$\\)")))
  7332. ;; This is a function or procedure definition statement
  7333. ;; We return the defined routine as module.
  7334. (list
  7335. (idlwave-sintern-routine-or-method (match-string-no-properties 4)
  7336. (match-string-no-properties 2))
  7337. (if (equal (downcase (match-string 1)) "pro") 'pro 'fun)
  7338. (idlwave-sintern-class (match-string 3)))
  7339. ;; Not a definition statement - analyze precise position.
  7340. (let* ((where (idlwave-where))
  7341. (cw (nth 2 where))
  7342. (pro (car (nth 0 where)))
  7343. (func (car (nth 1 where)))
  7344. (this-word (idlwave-this-word "a-zA-Z0-9$_"))
  7345. (next-char (save-excursion (skip-chars-forward "a-zA-Z0-9$_")
  7346. (following-char)))
  7347. )
  7348. (cond
  7349. ((and (eq cw 'procedure)
  7350. (not (equal this-word "")))
  7351. (setq this-word (idlwave-sintern-routine-or-method
  7352. this-word (nth 2 (nth 3 where))))
  7353. (list this-word 'pro
  7354. (idlwave-determine-class
  7355. (cons this-word (cdr (nth 3 where)))
  7356. 'pro)))
  7357. ((and (eq cw 'function)
  7358. (not (equal this-word ""))
  7359. (or (eq next-char ?\() ; exclude arrays, vars.
  7360. (looking-at "[a-zA-Z0-9_]*[ \t]*(")))
  7361. (setq this-word (idlwave-sintern-routine-or-method
  7362. this-word (nth 2 (nth 3 where))))
  7363. (list this-word 'fun
  7364. (idlwave-determine-class
  7365. (cons this-word (cdr (nth 3 where)))
  7366. 'fun)))
  7367. ((and (memq cw '(function-keyword procedure-keyword))
  7368. (not (equal this-word ""))
  7369. (eq next-char ?\()) ; A function!
  7370. (setq this-word (idlwave-sintern-routine this-word))
  7371. (list this-word 'fun nil))
  7372. (func
  7373. (list func 'fun (idlwave-determine-class (nth 1 where) 'fun)))
  7374. (pro
  7375. (list pro 'pro (idlwave-determine-class (nth 0 where) 'pro)))
  7376. (t nil)))))
  7377. (defun idlwave-what-module-find-class ()
  7378. "Call `idlwave-what-module' and find the inherited class if necessary."
  7379. (let* ((module (idlwave-what-module))
  7380. (class (nth 2 module)))
  7381. (if (and (= (length module) 3)
  7382. (stringp class))
  7383. (list (car module)
  7384. (nth 1 module)
  7385. (apply 'idlwave-find-inherited-class module))
  7386. module)))
  7387. (defun idlwave-find-inherited-class (name type class)
  7388. "Find the class which defines TYPE NAME and is CLASS or inherited by CLASS."
  7389. (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
  7390. (if entry
  7391. (nth 2 entry)
  7392. class)))
  7393. (defun idlwave-fix-module-if-obj_new (module)
  7394. "Check if MODULE points to obj_new.
  7395. If yes, and if the cursor is in the keyword region, change to the
  7396. appropriate Init method."
  7397. (let* ((name (car module))
  7398. (pos (point))
  7399. (case-fold-search t)
  7400. string)
  7401. (if (and (stringp name)
  7402. (equal (downcase name) "obj_new")
  7403. (save-excursion
  7404. (idlwave-beginning-of-statement)
  7405. (setq string (buffer-substring (point) pos))
  7406. (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
  7407. string)))
  7408. (let ((name "Init")
  7409. (class (match-string 1 string)))
  7410. (setq module (list (idlwave-sintern-method "Init")
  7411. 'fun
  7412. (idlwave-sintern-class class)))))
  7413. module))
  7414. (defun idlwave-fix-keywords (name type class keywords
  7415. &optional super-classes system)
  7416. "Update a list of keywords.
  7417. Translate OBJ_NEW, adding all super-class keywords, or all keywords
  7418. from all classes if CLASS equals t. If SYSTEM is non-nil, don't
  7419. demand _EXTRA in the keyword list."
  7420. (let ((case-fold-search t))
  7421. ;; If this is the OBJ_NEW function, try to figure out the class and use
  7422. ;; the keywords from the corresponding INIT method.
  7423. (if (and (equal (upcase name) "OBJ_NEW")
  7424. (derived-mode-p 'idlwave-mode 'idlwave-shell-mode))
  7425. (let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
  7426. (string (buffer-substring bos (point)))
  7427. (case-fold-search t)
  7428. class)
  7429. (and (string-match "obj_new([^'\"]*['\"]\\([a-zA-Z0-9_]+\\)"
  7430. string)
  7431. (setq class (idlwave-sintern-class (match-string 1 string)))
  7432. (setq idlwave-current-obj_new-class class)
  7433. (setq keywords
  7434. (append keywords
  7435. (idlwave-entry-keywords
  7436. (idlwave-rinfo-assq
  7437. (idlwave-sintern-method "INIT")
  7438. 'fun
  7439. class
  7440. (idlwave-routines)) 'do-link))))))
  7441. ;; If the class is `t', combine all keywords of all methods NAME
  7442. (when (eq class t)
  7443. (mapc (lambda (entry)
  7444. (and
  7445. (nth 2 entry) ; non-nil class
  7446. (eq (nth 1 entry) type) ; correct type
  7447. (setq keywords
  7448. (append keywords
  7449. (idlwave-entry-keywords entry 'do-link)))))
  7450. (idlwave-all-assq name (idlwave-routines)))
  7451. (setq keywords (idlwave-uniquify keywords)))
  7452. ;; If we have inheritance, add all keywords from superclasses, if
  7453. ;; the user indicated that method in `idlwave-keyword-class-inheritance'
  7454. (when (and
  7455. super-classes
  7456. idlwave-keyword-class-inheritance
  7457. (stringp class)
  7458. (or
  7459. system
  7460. (assq (idlwave-sintern-keyword "_extra") keywords)
  7461. (assq (idlwave-sintern-keyword "_ref_extra") keywords))
  7462. ;; Check if one of the keyword-class regexps matches the name
  7463. (let ((regexps idlwave-keyword-class-inheritance) re)
  7464. (catch 'exit
  7465. (while (setq re (pop regexps))
  7466. (if (string-match re name) (throw 'exit t))))))
  7467. (loop for entry in (idlwave-routines) do
  7468. (and (nth 2 entry) ; non-nil class
  7469. (memq (nth 2 entry) super-classes) ; an inherited class
  7470. (eq (nth 1 entry) type) ; correct type
  7471. (eq (car entry) name) ; correct name
  7472. (mapc (lambda (k) (add-to-list 'keywords k))
  7473. (idlwave-entry-keywords entry 'do-link))))
  7474. (setq keywords (idlwave-uniquify keywords)))
  7475. ;; Return the final list
  7476. keywords))
  7477. (defun idlwave-expand-keyword (keyword module)
  7478. "Expand KEYWORD to one of the valid keyword parameters of MODULE.
  7479. KEYWORD may be an exact match or an abbreviation of a keyword.
  7480. If the match is exact, KEYWORD itself is returned, even if there may be other
  7481. keywords of which KEYWORD is an abbreviation. This is necessary because some
  7482. system routines have keywords which are prefixes of other keywords.
  7483. If KEYWORD is an abbreviation of several keywords, a list of all possible
  7484. completions is returned.
  7485. If the abbreviation was unique, the correct keyword is returned.
  7486. If it cannot be a keyword, the function return nil.
  7487. If we do not know about MODULE, just return KEYWORD literally."
  7488. (let* ((name (car module))
  7489. (type (nth 1 module))
  7490. (class (nth 2 module))
  7491. (kwd (idlwave-sintern-keyword keyword))
  7492. (entry (idlwave-best-rinfo-assoc name type class (idlwave-routines)))
  7493. (kwd-alist (idlwave-entry-keywords entry))
  7494. (extra (or (assq (idlwave-sintern-keyword "_EXTRA") kwd-alist)
  7495. (assq (idlwave-sintern-keyword "_REF_EXTRA") kwd-alist)))
  7496. (completion-ignore-case t)
  7497. candidates)
  7498. (cond ((assq kwd kwd-alist)
  7499. kwd)
  7500. ((setq candidates (all-completions kwd kwd-alist))
  7501. (if (= (length candidates) 1)
  7502. (car candidates)
  7503. candidates))
  7504. ((and entry extra)
  7505. ;; Inheritance may cause this keyword to be correct
  7506. keyword)
  7507. (entry
  7508. ;; We do know the function, which does not have the keyword.
  7509. nil)
  7510. (t
  7511. ;; We do not know the function, so this just might be a correct
  7512. ;; keyword - return it as it is.
  7513. keyword))))
  7514. (defvar idlwave-rinfo-mouse-map
  7515. (let ((map (make-sparse-keymap)))
  7516. (define-key map
  7517. (if (featurep 'xemacs) [button2] [mouse-2])
  7518. 'idlwave-mouse-active-rinfo)
  7519. (define-key map
  7520. (if (featurep 'xemacs) [(shift button2)] [(shift mouse-2)])
  7521. 'idlwave-mouse-active-rinfo-shift)
  7522. (define-key map
  7523. (if (featurep 'xemacs) [button3] [mouse-3])
  7524. 'idlwave-mouse-active-rinfo-right)
  7525. (define-key map " " 'idlwave-active-rinfo-space)
  7526. (define-key map "q" 'idlwave-quit-help)
  7527. map))
  7528. (defvar idlwave-rinfo-map
  7529. (let ((map (make-sparse-keymap)))
  7530. (define-key map "q" 'idlwave-quit-help)
  7531. map))
  7532. (defvar idlwave-popup-source nil)
  7533. (defvar idlwave-rinfo-marker (make-marker))
  7534. (defun idlwave-quit-help ()
  7535. (interactive)
  7536. (let ((ri-window (get-buffer-window "*Help*"))
  7537. (olh-window (get-buffer-window "*IDLWAVE Help*")))
  7538. (when (and olh-window
  7539. (fboundp 'idlwave-help-quit))
  7540. (select-window olh-window)
  7541. (idlwave-help-quit))
  7542. (when (window-live-p ri-window)
  7543. (delete-window ri-window))))
  7544. (defun idlwave-display-calling-sequence (name type class
  7545. &optional initial-class)
  7546. ;; Display the calling sequence of module NAME, type TYPE in class CLASS.
  7547. (let* ((initial-class (or initial-class class))
  7548. (entry (or (idlwave-best-rinfo-assq name type class
  7549. (idlwave-routines))
  7550. (idlwave-rinfo-assq name type class
  7551. idlwave-unresolved-routines)))
  7552. (name (or (car entry) name))
  7553. (class (or (nth 2 entry) class))
  7554. (superclasses (idlwave-all-class-inherits initial-class))
  7555. (twins (idlwave-routine-twins entry))
  7556. (dtwins (idlwave-study-twins twins))
  7557. (all dtwins)
  7558. (system (eq (car (nth 3 entry)) 'system))
  7559. (calling-seq (nth 4 entry))
  7560. (keywords (idlwave-entry-keywords entry 'do-link))
  7561. (html-file (car (nth 5 entry)))
  7562. (help-echo-kwd
  7563. "Button2: Insert KEYWORD (SHIFT=`/KEYWORD') | Button3: Online Help ")
  7564. (help-echo-use
  7565. "Button2/3: Online Help")
  7566. (help-echo-src
  7567. "Button2: Jump to source and back | Button3: Source in Help window.")
  7568. (help-echo-class
  7569. "Button2: Display info about same method in superclass")
  7570. (col 0)
  7571. (data (list name type class (current-buffer) nil initial-class))
  7572. (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
  7573. (face 'idlwave-help-link)
  7574. beg props win cnt total)
  7575. ;; Fix keywords, but don't add chained super-classes, since these
  7576. ;; are shown separately for that super-class
  7577. (setq keywords (idlwave-fix-keywords name type class keywords))
  7578. (cond
  7579. ((null entry)
  7580. (error "No %s %s known %s" type name
  7581. (if initial-class (concat "in class " initial-class) "")))
  7582. ((or (null name) (equal name ""))
  7583. (error "No function or procedure call at point"))
  7584. ((null calling-seq)
  7585. (error "Calling sequence of %s %s not available" type name))
  7586. (t
  7587. (move-marker idlwave-rinfo-marker (point))
  7588. (with-current-buffer (get-buffer-create "*Help*")
  7589. (use-local-map idlwave-rinfo-map)
  7590. (setq buffer-read-only nil)
  7591. (erase-buffer)
  7592. (set (make-local-variable 'idlwave-popup-source) nil)
  7593. (set (make-local-variable 'idlwave-current-obj_new-class)
  7594. idlwave-current-obj_new-class)
  7595. (when superclasses
  7596. (setq props (list 'mouse-face 'highlight
  7597. km-prop idlwave-rinfo-mouse-map
  7598. 'help-echo help-echo-class
  7599. 'data (cons 'class data)))
  7600. (let ((classes (cons initial-class superclasses)) c)
  7601. (insert "Classes: ")
  7602. (while (setq c (pop classes))
  7603. (insert " ")
  7604. (setq beg (point))
  7605. (insert c)
  7606. (if (equal (downcase c) (downcase class))
  7607. (add-text-properties beg (point) (list 'face 'bold))
  7608. ;; If Method exists in a different class link it
  7609. (if (idlwave-rinfo-assq name type c (idlwave-routines))
  7610. (add-text-properties beg (point) props))))
  7611. (insert "\n")))
  7612. (setq props (list 'mouse-face 'highlight
  7613. km-prop idlwave-rinfo-mouse-map
  7614. 'help-echo help-echo-use
  7615. 'data (cons 'usage data)))
  7616. (if html-file (setq props (append (list 'face face 'link html-file)
  7617. props)))
  7618. (insert "Usage: ")
  7619. (setq beg (point))
  7620. (insert (if class
  7621. (format calling-seq class name class name class name)
  7622. (format calling-seq name name name name))
  7623. "\n")
  7624. (add-text-properties beg (point) props)
  7625. (insert "Keywords:")
  7626. (if (null keywords)
  7627. (insert " No keywords accepted.")
  7628. (setq col 9)
  7629. (mapc
  7630. (lambda (x)
  7631. (if (>= (+ col 1 (length (car x)))
  7632. (window-width))
  7633. (progn
  7634. (insert "\n ")
  7635. (setq col 9)))
  7636. (insert " ")
  7637. (setq beg (point)
  7638. ;; Relevant keywords already have link property attached
  7639. props (list 'mouse-face 'highlight
  7640. km-prop idlwave-rinfo-mouse-map
  7641. 'data (cons 'keyword data)
  7642. 'help-echo help-echo-kwd
  7643. 'keyword (car x)))
  7644. (if system (setq props (append (list 'face face) props)))
  7645. (insert (car x))
  7646. (add-text-properties beg (point) props)
  7647. (setq col (+ col 1 (length (car x)))))
  7648. keywords))
  7649. (setq cnt 1 total (length all))
  7650. ;; Here entry is (key file (list of type-conses))
  7651. (while (setq entry (pop all))
  7652. (setq props (list 'mouse-face 'highlight
  7653. km-prop idlwave-rinfo-mouse-map
  7654. 'help-echo help-echo-src
  7655. 'source (list (car (car (nth 2 entry))) ;type
  7656. (nth 1 entry)
  7657. nil
  7658. (cdr (car (nth 2 entry))))
  7659. 'data (cons 'source data)))
  7660. (idlwave-insert-source-location
  7661. (format "\n%-8s %s"
  7662. (if (equal cnt 1)
  7663. (if (> total 1) "Sources:" "Source:")
  7664. "")
  7665. (if (> total 1) "- " ""))
  7666. entry props)
  7667. (incf cnt)
  7668. (when (and all (> cnt idlwave-rinfo-max-source-lines))
  7669. ;; No more source lines, please
  7670. (insert (format
  7671. "\n Source information truncated to %d entries."
  7672. idlwave-rinfo-max-source-lines))
  7673. (setq all nil)))
  7674. (goto-char (point-min))
  7675. (setq buffer-read-only t))
  7676. (display-buffer "*Help*")
  7677. (if (and (setq win (get-buffer-window "*Help*"))
  7678. idlwave-resize-routine-help-window)
  7679. (progn
  7680. (let ((ww (selected-window)))
  7681. (unwind-protect
  7682. (progn
  7683. (select-window win)
  7684. (enlarge-window (- (/ (frame-height) 2)
  7685. (window-height)))
  7686. (shrink-window-if-larger-than-buffer))
  7687. (select-window ww)))))))))
  7688. (defun idlwave-insert-source-location (prefix entry &optional file-props)
  7689. "Insert a source location into the routine info buffer.
  7690. Start line with PREFIX. If a file name is inserted, add FILE-PROPS
  7691. to it."
  7692. (let* ((key (car entry))
  7693. (file (nth 1 entry))
  7694. (types (nth 2 entry))
  7695. (shell-flag (assq 'compiled types))
  7696. (buffer-flag (assq 'buffer types))
  7697. (user-flag (assq 'user types))
  7698. (lib-flag (assq 'lib types))
  7699. (ndupl (or (and buffer-flag (idlwave-count-memq 'buffer types))
  7700. (and user-flag (idlwave-count-memq 'user types))
  7701. (and lib-flag (idlwave-count-memq 'lib types))
  7702. 1))
  7703. (doflags t)
  7704. beg special)
  7705. (insert prefix)
  7706. (cond
  7707. ((eq key 'system)
  7708. (setq doflags nil)
  7709. (insert "System "))
  7710. ((eq key 'builtin)
  7711. (setq doflags nil)
  7712. (insert "Builtin "))
  7713. ((and (not file) shell-flag)
  7714. (insert "Unresolved"))
  7715. ((null file)
  7716. (insert "ERROR"))
  7717. ((idlwave-syslib-p file)
  7718. (if (string-match "obsolete" (file-name-directory file))
  7719. (insert "Obsolete ")
  7720. (insert "SystemLib ")))
  7721. ;; New special syntax: taken directly from routine-info for
  7722. ;; library catalog routines
  7723. ((setq special (or (cdr lib-flag) (cdr user-flag)))
  7724. (insert (format "%-10s" special)))
  7725. ;; Old special syntax: a matching regexp
  7726. ((setq special (idlwave-special-lib-test file))
  7727. (insert (format "%-10s" special)))
  7728. ;; Catch-all with file
  7729. ((idlwave-lib-p file) (insert "Library "))
  7730. ;; Sanity catch all
  7731. (t (insert "Other ")))
  7732. (when doflags
  7733. (insert (concat
  7734. " ["
  7735. (if lib-flag "L" "-")
  7736. (if user-flag "C" "-")
  7737. (if shell-flag "S" "-")
  7738. (if buffer-flag "B" "-")
  7739. "] ")))
  7740. (when (> ndupl 1)
  7741. (setq beg (point))
  7742. (insert (format "(%dx) " ndupl))
  7743. (add-text-properties beg (point) (list 'face 'bold)))
  7744. (when (and file (not (equal file "")))
  7745. (setq beg (point))
  7746. (insert (apply 'abbreviate-file-name
  7747. (if (featurep 'xemacs) (list file t) (list file))))
  7748. (if file-props
  7749. (add-text-properties beg (point) file-props)))))
  7750. (defun idlwave-special-lib-test (file)
  7751. "Check the path of FILE against the regexps which define special libs.
  7752. Return the name of the special lib if there is a match."
  7753. (let ((alist idlwave-special-lib-alist)
  7754. entry rtn)
  7755. (cond
  7756. ((stringp file)
  7757. (while (setq entry (pop alist))
  7758. (if (string-match (car entry) file)
  7759. (setq rtn (cdr entry)
  7760. alist nil)))
  7761. rtn)
  7762. (t nil))))
  7763. (defun idlwave-mouse-active-rinfo-right (ev)
  7764. (interactive "e")
  7765. (idlwave-mouse-active-rinfo ev 'right))
  7766. (defun idlwave-mouse-active-rinfo-shift (ev)
  7767. (interactive "e")
  7768. (idlwave-mouse-active-rinfo ev nil 'shift))
  7769. (defun idlwave-active-rinfo-space ()
  7770. (interactive)
  7771. (idlwave-mouse-active-rinfo nil 'right))
  7772. (defun idlwave-mouse-active-rinfo (ev &optional right shift)
  7773. "Do the mouse actions in the routine info buffer.
  7774. Optional args RIGHT and SHIFT indicate, if mouse-3 was used, and if SHIFT
  7775. was pressed."
  7776. (interactive "e")
  7777. (if ev (mouse-set-point ev))
  7778. (let (data id name type class buf bufwin source link keyword
  7779. word initial-class)
  7780. (setq data (get-text-property (point) 'data)
  7781. source (get-text-property (point) 'source)
  7782. keyword (get-text-property (point) 'keyword)
  7783. link (get-text-property (point) 'link)
  7784. id (car data)
  7785. name (nth 1 data) type (nth 2 data) class (nth 3 data)
  7786. buf (nth 4 data)
  7787. initial-class (nth 6 data)
  7788. word (idlwave-this-word)
  7789. bufwin (get-buffer-window buf t))
  7790. (cond ((eq id 'class) ; Switch class being displayed
  7791. (if (window-live-p bufwin) (select-window bufwin))
  7792. (idlwave-display-calling-sequence
  7793. (idlwave-sintern-method name)
  7794. type (idlwave-sintern-class word)
  7795. initial-class))
  7796. ((eq id 'usage) ; Online help on this routine
  7797. (idlwave-online-help link name type class))
  7798. ((eq id 'source) ; Source in help or buffer
  7799. (if right ; In help
  7800. (let ((idlwave-extra-help-function 'idlwave-help-with-source)
  7801. (idlwave-help-source-try-header nil)
  7802. ;; Fake idlwave-routines so help will find the right entry
  7803. (idlwave-routines
  7804. (list (list name type class source ""))))
  7805. (idlwave-help-get-special-help name type class nil))
  7806. ;; Otherwise just pop to the source
  7807. (setq idlwave-popup-source (not idlwave-popup-source))
  7808. (if idlwave-popup-source
  7809. (condition-case err
  7810. (idlwave-do-find-module name type class source)
  7811. (error
  7812. (setq idlwave-popup-source nil)
  7813. (if (window-live-p bufwin) (select-window bufwin))
  7814. (error (nth 1 err))))
  7815. (if bufwin
  7816. (select-window bufwin)
  7817. (pop-to-buffer buf))
  7818. (goto-char (marker-position idlwave-rinfo-marker)))))
  7819. ((eq id 'keyword)
  7820. (if right
  7821. (idlwave-online-help link name type class keyword)
  7822. (idlwave-rinfo-insert-keyword keyword buf shift))))))
  7823. (defun idlwave-rinfo-insert-keyword (keyword buffer &optional shift)
  7824. "Insert KEYWORD in BUFFER. Make sure buffer is displayed in a window."
  7825. (let ((bwin (get-buffer-window buffer)))
  7826. (if idlwave-complete-empty-string-as-lower-case
  7827. (setq keyword (downcase keyword)))
  7828. (if bwin
  7829. (select-window bwin)
  7830. (pop-to-buffer buffer)
  7831. (setq bwin (get-buffer-window buffer)))
  7832. (if (eq (preceding-char) ?/)
  7833. (insert keyword)
  7834. (unless (save-excursion
  7835. (re-search-backward
  7836. "[(,][ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\)?[ \t]*\\="
  7837. (min (- (point) 100) (point-min)) t))
  7838. (insert ", "))
  7839. (if shift (insert "/"))
  7840. (insert keyword)
  7841. (if (and (not shift)
  7842. idlwave-keyword-completion-adds-equal)
  7843. (insert "=")))))
  7844. (defun idlwave-list-buffer-load-path-shadows (&optional arg)
  7845. "List the load path shadows of all routines defined in current buffer."
  7846. (interactive "P")
  7847. (idlwave-routines)
  7848. (if (derived-mode-p 'idlwave-mode)
  7849. (idlwave-list-load-path-shadows
  7850. nil (idlwave-update-current-buffer-info 'save-buffer)
  7851. "in current buffer")
  7852. (error "Current buffer is not in idlwave-mode")))
  7853. (defun idlwave-list-shell-load-path-shadows (&optional arg)
  7854. "List the load path shadows of all routines compiled under the shell.
  7855. This is very useful for checking an IDL application. Just compile the
  7856. application, do RESOLVE_ALL, and `C-c C-i' to compile all referenced
  7857. routines and update IDLWAVE internal info. Then check for shadowing
  7858. with this command."
  7859. (interactive "P")
  7860. (cond
  7861. ((or (not (fboundp 'idlwave-shell-is-running))
  7862. (not (idlwave-shell-is-running)))
  7863. (error "Shell is not running"))
  7864. ((null idlwave-compiled-routines)
  7865. (error "No compiled routines. Maybe you need to update with `C-c C-i'"))
  7866. (t
  7867. (idlwave-list-load-path-shadows nil idlwave-compiled-routines
  7868. "in the shell"))))
  7869. (defun idlwave-list-all-load-path-shadows (&optional arg)
  7870. "List the load path shadows of all routines known to IDLWAVE."
  7871. (interactive "P")
  7872. (idlwave-list-load-path-shadows nil nil "globally"))
  7873. (defvar idlwave-sort-prefer-buffer-info t
  7874. "Internal variable used to influence `idlwave-routine-twin-compare'.")
  7875. (defun idlwave-list-load-path-shadows (arg &optional special-routines loc)
  7876. "List the routines which are defined multiple times.
  7877. Search the information IDLWAVE has about IDL routines for multiple
  7878. definitions.
  7879. When SPECIAL-ROUTINES in non-nil, only look for shadows of these routines.
  7880. When IDL hits a routine call which is not defined, it will search on
  7881. the load path in order to find a definition. The output of this command
  7882. can be used to detect possible name clashes during this process."
  7883. (idlwave-routines) ; Make sure everything is loaded.
  7884. (unless (or idlwave-user-catalog-routines idlwave-library-catalog-routines)
  7885. (or (y-or-n-p
  7886. "You don't have any user or library catalogs. Continue anyway? ")
  7887. (error "Abort")))
  7888. (let* ((routines (append idlwave-system-routines
  7889. idlwave-compiled-routines
  7890. idlwave-library-catalog-routines
  7891. idlwave-user-catalog-routines
  7892. idlwave-buffer-routines
  7893. nil))
  7894. (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
  7895. (keymap (make-sparse-keymap))
  7896. (props (list 'mouse-face 'highlight
  7897. km-prop keymap
  7898. 'help-echo "Mouse2: Find source"))
  7899. (nroutines (length (or special-routines routines)))
  7900. (step (/ nroutines 100))
  7901. (n 0)
  7902. (cnt 0)
  7903. (idlwave-sort-prefer-buffer-info nil)
  7904. routine twins dtwins twin done props1 lroutines)
  7905. (if special-routines
  7906. ;; Just looking for shadows of a few special routines
  7907. (setq lroutines routines
  7908. routines special-routines))
  7909. (message "Sorting routines...")
  7910. (setq routines (sort routines
  7911. (lambda (a b)
  7912. (string< (downcase (idlwave-make-full-name
  7913. (nth 2 a) (car a)))
  7914. (downcase (idlwave-make-full-name
  7915. (nth 2 b) (car b)))))))
  7916. (message "Sorting routines...done")
  7917. (define-key keymap (if (featurep 'xemacs) [(button2)] [(mouse-2)])
  7918. (lambda (ev)
  7919. (interactive "e")
  7920. (mouse-set-point ev)
  7921. (apply 'idlwave-do-find-module
  7922. (get-text-property (point) 'find-args))))
  7923. (define-key keymap [(return)]
  7924. (lambda ()
  7925. (interactive)
  7926. (apply 'idlwave-do-find-module
  7927. (get-text-property (point) 'find-args))))
  7928. (message "Compiling list...( 0%%)")
  7929. (with-current-buffer (get-buffer-create "*Shadows*")
  7930. (setq buffer-read-only nil)
  7931. (erase-buffer)
  7932. (while (setq routine (pop routines))
  7933. (if (= (mod (setq n (1+ n)) step) 0)
  7934. (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
  7935. ;; Get a list of all twins
  7936. (setq twins (idlwave-routine-twins routine (or lroutines routines)))
  7937. (if (memq routine done)
  7938. (setq dtwins nil)
  7939. (setq dtwins (idlwave-study-twins twins)))
  7940. ;; Mark all twins as dealt with
  7941. (setq done (append twins done))
  7942. (when (or (> (length dtwins) 1)
  7943. (> (idlwave-count-memq 'lib (nth 2 (car dtwins))) 1)
  7944. (> (idlwave-count-memq 'user (nth 2 (car dtwins))) 1)
  7945. (> (idlwave-count-memq 'buffer (nth 2 (car dtwins))) 1))
  7946. (incf cnt)
  7947. (insert (format "\n%s%s"
  7948. (idlwave-make-full-name (nth 2 routine)
  7949. (car routine))
  7950. (if (eq (nth 1 routine) 'fun) "()" "")))
  7951. (while (setq twin (pop dtwins))
  7952. (setq props1 (append (list 'find-args
  7953. (list (nth 0 routine)
  7954. (nth 1 routine)
  7955. (nth 2 routine)))
  7956. props))
  7957. (idlwave-insert-source-location "\n - " twin props1))))
  7958. (goto-char (point-min))
  7959. (setq buffer-read-only t))
  7960. (setq loc (or loc ""))
  7961. (if (> cnt 0)
  7962. (progn
  7963. (display-buffer (get-buffer "*Shadows*"))
  7964. (message "%d case%s of shadowing found %s"
  7965. cnt (if (= cnt 1) "" "s") loc))
  7966. (message "No shadowing conflicts found %s" loc))))
  7967. (defun idlwave-print-source (routine)
  7968. (let* ((source (nth 3 routine))
  7969. (stype (car source))
  7970. (sfile (idlwave-routine-source-file source)))
  7971. (if (idlwave-syslib-p sfile) (setq stype 'syslib))
  7972. (if (and (eq stype 'compiled)
  7973. (or (not (stringp sfile))
  7974. (not (string-match "\\S-" sfile))))
  7975. (setq stype 'unresolved))
  7976. (princ (format " %-10s %s\n"
  7977. stype
  7978. (if sfile sfile "No source code available")))))
  7979. (defun idlwave-routine-twins (entry &optional list)
  7980. "Return all twin entries of ENTRY in LIST.
  7981. LIST defaults to `idlwave-routines'.
  7982. Twin entries are those which have the same name, type, and class.
  7983. ENTRY will also be returned, as the first item of this list."
  7984. (let* ((name (car entry))
  7985. (type (nth 1 entry))
  7986. (class (nth 2 entry))
  7987. (candidates (idlwave-all-assq name (or list (idlwave-routines))))
  7988. twins candidate)
  7989. (while (setq candidate (pop candidates))
  7990. (if (and (not (eq candidate entry))
  7991. (eq type (nth 1 candidate))
  7992. (eq class (nth 2 candidate)))
  7993. (push candidate twins)))
  7994. (if (setq candidate (idlwave-rinfo-assq name type class
  7995. idlwave-unresolved-routines))
  7996. (push candidate twins))
  7997. (cons entry (nreverse twins))))
  7998. (defun idlwave-study-twins (entries)
  7999. "Return dangerous twins of first entry in ENTRIES.
  8000. Dangerous twins are routines with same name, but in different files on
  8001. the load path. If a file is in the system library and has an entry in
  8002. the `idlwave-system-routines' list, we omit the latter as
  8003. non-dangerous because many IDL routines are implemented as library
  8004. routines, and may have been scanned."
  8005. (let* ((entry (car entries))
  8006. (idlwave-twin-name (car entry)) ;
  8007. (type (nth 1 entry)) ; Must be bound for
  8008. (idlwave-twin-class (nth 2 entry)) ; idlwave-routine-twin-compare
  8009. (cnt 0)
  8010. source type type-cons file alist syslibp key)
  8011. (while (setq entry (pop entries))
  8012. (incf cnt)
  8013. (setq source (nth 3 entry)
  8014. type (car source)
  8015. type-cons (cons type (nth 3 source))
  8016. file (idlwave-routine-source-file source))
  8017. ;; Make KEY to index entry properly
  8018. (setq key (cond ((eq type 'system) type)
  8019. (file (file-truename file))
  8020. (t 'unresolved)))
  8021. ;; Check for an entry in the system library
  8022. (if (and file
  8023. (not syslibp)
  8024. (idlwave-syslib-p file))
  8025. (setq syslibp t))
  8026. ;; If there's more than one matching entry for the same file, just
  8027. ;; append the type-cons to the type list.
  8028. (if (setq entry (assoc key alist))
  8029. (push type-cons (nth 2 entry))
  8030. (push (list key file (list type-cons)) alist)))
  8031. (setq alist (nreverse alist))
  8032. (when syslibp
  8033. ;; File is in system *library* - remove any 'system entry
  8034. (setq alist (delq (assq 'system alist) alist)))
  8035. ;; If 'system remains and we've scanned the syslib, it's a builtin
  8036. ;; (rather than a !DIR/lib/.pro file bundled as source).
  8037. (when (and (idlwave-syslib-scanned-p)
  8038. (setq entry (assoc 'system alist)))
  8039. (setcar entry 'builtin))
  8040. (sort alist 'idlwave-routine-twin-compare)))
  8041. ;; FIXME: Dynamically scoped vars need to use the `idlwave-' prefix.
  8042. ;; (defvar type)
  8043. (defmacro idlwave-xor (a b)
  8044. `(and (or ,a ,b)
  8045. (not (and ,a ,b))))
  8046. (defun idlwave-routine-entry-compare (a b)
  8047. "Compare two routine info entries for sorting.
  8048. This is the general case. It first compares class, names, and type.
  8049. If it turns out that A and B are twins (same name, class, and type),
  8050. calls another routine which compares twins on the basis of their file
  8051. names and path locations."
  8052. (let ((name (car a)) (type (nth 1 a)) (class (nth 2 a)))
  8053. (cond
  8054. ((not (equal (idlwave-downcase-safe class)
  8055. (idlwave-downcase-safe (nth 2 b))))
  8056. ;; Class decides
  8057. (cond ((null (nth 2 b)) nil)
  8058. ((null class) t)
  8059. (t (string< (downcase class) (downcase (nth 2 b))))))
  8060. ((not (equal (downcase name) (downcase (car b))))
  8061. ;; Name decides
  8062. (string< (downcase name) (downcase (car b))))
  8063. ((not (eq type (nth 1 b)))
  8064. ;; Type decides
  8065. (< (if (eq type 'fun) 1 0) (if (eq (nth 1 b) 'fun) 1 0)))
  8066. (t
  8067. ;; A and B are twins - so the decision is more complicated.
  8068. ;; Call twin-compare with the proper arguments.
  8069. (idlwave-routine-entry-compare-twins a b)))))
  8070. (defun idlwave-routine-entry-compare-twins (a b)
  8071. "Compare two routine entries, under the assumption that they are twins.
  8072. This basically calls `idlwave-routine-twin-compare' with the correct args."
  8073. (let* ((idlwave-twin-name (car a))
  8074. (type (nth 1 a))
  8075. (idlwave-twin-class (nth 2 a)) ; used in idlwave-routine-twin-compare
  8076. (asrc (nth 3 a))
  8077. (atype (car asrc))
  8078. (bsrc (nth 3 b))
  8079. (btype (car bsrc))
  8080. (afile (idlwave-routine-source-file asrc))
  8081. (bfile (idlwave-routine-source-file bsrc)))
  8082. (idlwave-routine-twin-compare
  8083. (if (stringp afile)
  8084. (list (file-truename afile) afile (list atype))
  8085. (list atype afile (list atype)))
  8086. (if (stringp bfile)
  8087. (list (file-truename bfile) bfile (list btype))
  8088. (list btype bfile (list btype))))))
  8089. ;; Bound in idlwave-study-twins,idlwave-routine-entry-compare-twins.
  8090. (defvar idlwave-twin-class)
  8091. (defvar idlwave-twin-name)
  8092. (defun idlwave-routine-twin-compare (a b)
  8093. "Compare two routine twin entries for sorting.
  8094. In here, A and B are not normal routine info entries, but special
  8095. lists (KEY FILENAME (TYPES...)).
  8096. This expects NAME TYPE IDLWAVE-TWIN-CLASS to be bound to the right values."
  8097. (let* (;; Dis-assemble entries
  8098. (akey (car a)) (bkey (car b))
  8099. (afile (nth 1 a)) (bfile (nth 1 b))
  8100. (atypes (nth 2 a)) (btypes (nth 2 b))
  8101. ;; System routines?
  8102. (asysp (memq akey '(builtin system)))
  8103. (bsysp (memq bkey '(builtin system)))
  8104. ;; Compiled routines?
  8105. (acompp (memq 'compiled atypes))
  8106. (bcompp (memq 'compiled btypes))
  8107. ;; Unresolved?
  8108. (aunresp (or (eq akey 'unresolved)
  8109. (and acompp (not afile))))
  8110. (bunresp (or (eq bkey 'unresolved)
  8111. (and bcompp (not bfile))))
  8112. ;; Buffer info available?
  8113. (abufp (memq 'buffer atypes))
  8114. (bbufp (memq 'buffer btypes))
  8115. ;; On search path?
  8116. (tpath-alist (idlwave-true-path-alist))
  8117. (apathp (and (stringp akey)
  8118. (assoc (file-name-directory akey) tpath-alist)))
  8119. (bpathp (and (stringp bkey)
  8120. (assoc (file-name-directory bkey) tpath-alist)))
  8121. ;; How early on search path? High number means early since we
  8122. ;; measure the tail of the path list
  8123. (anpath (length (memq apathp tpath-alist)))
  8124. (bnpath (length (memq bpathp tpath-alist)))
  8125. ;; Look at file names
  8126. (aname (if (stringp afile) (downcase (file-name-nondirectory afile)) ""))
  8127. (bname (if (stringp bfile) (downcase (file-name-nondirectory bfile)) ""))
  8128. (fname-re (if idlwave-twin-class
  8129. (format "\\`%s__\\(%s\\|define\\)\\.pro\\'"
  8130. (regexp-quote (downcase idlwave-twin-class))
  8131. (regexp-quote (downcase idlwave-twin-name)))
  8132. (format "\\`%s\\.pro" (regexp-quote (downcase idlwave-twin-name)))))
  8133. ;; Is file name derived from the routine name?
  8134. ;; Method file or class definition file?
  8135. (anamep (string-match fname-re aname))
  8136. (adefp (and idlwave-twin-class anamep
  8137. (string= "define" (match-string 1 aname))))
  8138. (bnamep (string-match fname-re bname))
  8139. (bdefp (and idlwave-twin-class bnamep
  8140. (string= "define" (match-string 1 bname)))))
  8141. ;; Now: follow JD's ideas about sorting. Looks really simple now,
  8142. ;; doesn't it? The difficult stuff is hidden above...
  8143. (cond
  8144. ((idlwave-xor asysp bsysp) asysp) ; System entries first
  8145. ((idlwave-xor aunresp bunresp) bunresp) ; Unresolved last
  8146. ((and idlwave-sort-prefer-buffer-info
  8147. (idlwave-xor abufp bbufp)) abufp) ; Buffers before non-buffers
  8148. ((idlwave-xor acompp bcompp) acompp) ; Compiled entries
  8149. ((idlwave-xor apathp bpathp) apathp) ; Library before non-library
  8150. ((idlwave-xor anamep bnamep) anamep) ; Correct file names first
  8151. ((and idlwave-twin-class anamep bnamep ; both file names match ->
  8152. (idlwave-xor adefp bdefp)) bdefp) ; __define after __method
  8153. ((> anpath bnpath) t) ; Who is first on path?
  8154. (t nil)))) ; Default
  8155. (defun idlwave-routine-source-file (source)
  8156. (if (nth 2 source)
  8157. (expand-file-name (nth 1 source) (nth 2 source))
  8158. (nth 1 source)))
  8159. (defun idlwave-downcase-safe (string)
  8160. "Downcase if string, else return unchanged."
  8161. (if (stringp string)
  8162. (downcase string)
  8163. string))
  8164. (defun idlwave-count-eq (elt list)
  8165. "How often is ELT in LIST?"
  8166. (length (delq nil (mapcar (lambda (x) (eq x elt)) list))))
  8167. (defun idlwave-count-memq (elt alist)
  8168. "How often is ELT a key in ALIST?"
  8169. (length (delq nil (mapcar (lambda (x) (eq (car x) elt)) alist))))
  8170. (defun idlwave-syslib-p (file)
  8171. "Non-nil if FILE is in the system library."
  8172. (let* ((true-syslib (file-name-as-directory
  8173. (file-truename
  8174. (expand-file-name "lib" (idlwave-sys-dir)))))
  8175. (true-file (file-truename file)))
  8176. (string-match (concat "^" (regexp-quote true-syslib)) true-file)))
  8177. (defun idlwave-lib-p (file)
  8178. "Non-nil if FILE is in the library."
  8179. (let ((true-dir (file-name-directory (file-truename file))))
  8180. (assoc true-dir (idlwave-true-path-alist))))
  8181. (defun idlwave-path-alist-add-flag (list-entry flag)
  8182. "Add a flag to the path list entry, if not set."
  8183. (let ((flags (cdr list-entry)))
  8184. (add-to-list 'flags flag)
  8185. (setcdr list-entry flags)))
  8186. (defun idlwave-path-alist-remove-flag (list-entry flag)
  8187. "Remove a flag to the path list entry, if set."
  8188. (let ((flags (delq flag (cdr list-entry))))
  8189. (setcdr list-entry flags)))
  8190. (defun idlwave-true-path-alist ()
  8191. "Return `idlwave-path-alist' alist with true-names.
  8192. Info is cached, but relies on the functions setting `idlwave-path-alist'
  8193. to reset the variable `idlwave-true-path-alist' to nil."
  8194. (or idlwave-true-path-alist
  8195. (setq idlwave-true-path-alist
  8196. (mapcar (lambda(x) (cons
  8197. (file-name-as-directory
  8198. (file-truename
  8199. (directory-file-name
  8200. (car x))))
  8201. (cdr x)))
  8202. idlwave-path-alist))))
  8203. (defun idlwave-syslib-scanned-p ()
  8204. "Non-nil if the system lib file !DIR/lib has been scanned."
  8205. (let* ((true-syslib (file-name-as-directory
  8206. (file-truename
  8207. (expand-file-name "lib" (idlwave-sys-dir))))))
  8208. (cdr (assoc true-syslib (idlwave-true-path-alist)))))
  8209. ;; ----------------------------------------------------------------------------
  8210. ;;
  8211. ;; Online Help display
  8212. ;; ----------------------------------------------------------------------------
  8213. ;;
  8214. ;; Additions for use with imenu.el and func-menu.el
  8215. ;; (pop-up a list of IDL units in the current file).
  8216. ;;
  8217. (defun idlwave-prev-index-position ()
  8218. "Search for the previous procedure or function.
  8219. Return nil if not found. For use with imenu.el."
  8220. (save-match-data
  8221. (cond
  8222. ((idlwave-find-key "\\<\\(pro\\|function\\)\\>" -1 'nomark))
  8223. ;; ((idlwave-find-key idlwave-begin-unit-reg 1 'nomark)
  8224. (t nil))))
  8225. (defun idlwave-unit-name ()
  8226. "Return the unit name.
  8227. Assumes that point is at the beginning of the unit as found by
  8228. `idlwave-prev-index-position'."
  8229. (forward-sexp 2)
  8230. (forward-sexp -1)
  8231. (let ((begin (point)))
  8232. (re-search-forward
  8233. "[a-zA-Z_][a-zA-Z0-9$_]+\\(::[a-zA-Z_][a-zA-Z0-9$_]+\\)?")
  8234. (if (fboundp 'buffer-substring-no-properties)
  8235. (buffer-substring-no-properties begin (point))
  8236. (buffer-substring begin (point)))))
  8237. (defalias 'idlwave-function-menu
  8238. (condition-case nil
  8239. (progn
  8240. (require 'func-menu)
  8241. 'function-menu)
  8242. (error (condition-case nil
  8243. (progn
  8244. (require 'imenu)
  8245. 'imenu)
  8246. (error nil)))))
  8247. ;; Here we hack func-menu.el in order to support this new mode.
  8248. ;; The latest versions of func-menu.el already have this stuff in, so
  8249. ;; we hack only if it is not already there.
  8250. (when (fboundp 'eval-after-load)
  8251. (eval-after-load "func-menu"
  8252. '(progn
  8253. (or (assq 'idlwave-mode fume-function-name-regexp-alist)
  8254. (not (boundp 'fume-function-name-regexp-idl)) ; avoid problems
  8255. (setq fume-function-name-regexp-alist
  8256. (cons '(idlwave-mode . fume-function-name-regexp-idl)
  8257. fume-function-name-regexp-alist)))
  8258. (or (assq 'idlwave-mode fume-find-function-name-method-alist)
  8259. (not (fboundp 'fume-find-next-idl-function-name)) ; avoid problems
  8260. (setq fume-find-function-name-method-alist
  8261. (cons '(idlwave-mode . fume-find-next-idl-function-name)
  8262. fume-find-function-name-method-alist))))))
  8263. (defun idlwave-edit-in-idlde ()
  8264. "Edit the current file in IDL Development environment."
  8265. (interactive)
  8266. (start-process "idldeclient" nil
  8267. idlwave-shell-explicit-file-name "-c" "-e"
  8268. (buffer-file-name)))
  8269. (defvar idlwave-help-use-assistant)
  8270. (defun idlwave-launch-idlhelp ()
  8271. "Start the IDLhelp application."
  8272. (interactive)
  8273. (if idlwave-help-use-assistant
  8274. (idlwave-help-assistant-raise)
  8275. (start-process "idlhelp" nil idlwave-help-application)))
  8276. ;; Menus - using easymenu.el
  8277. (defvar idlwave-mode-menu-def
  8278. `("IDLWAVE"
  8279. ["PRO/FUNC menu" idlwave-function-menu t]
  8280. ("Motion"
  8281. ["Subprogram Start" idlwave-beginning-of-subprogram t]
  8282. ["Subprogram End" idlwave-end-of-subprogram t]
  8283. ["Block Start" idlwave-beginning-of-block t]
  8284. ["Block End" idlwave-end-of-block t]
  8285. ["Up Block" idlwave-backward-up-block t]
  8286. ["Down Block" idlwave-down-block t]
  8287. ["Skip Block Backward" idlwave-backward-block t]
  8288. ["Skip Block Forward" idlwave-forward-block t])
  8289. ("Mark"
  8290. ["Subprogram" idlwave-mark-subprogram t]
  8291. ["Block" idlwave-mark-block t]
  8292. ["Header" idlwave-mark-doclib t])
  8293. ("Format"
  8294. ["Indent Entire Statement" idlwave-indent-statement
  8295. :active t :keys "C-u \\[indent-for-tab-command]" ]
  8296. ["Indent Subprogram" idlwave-indent-subprogram t]
  8297. ["(Un)Comment Region" idlwave-toggle-comment-region t]
  8298. ["Continue/Split line" idlwave-split-line t]
  8299. "--"
  8300. ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
  8301. :selected (symbol-value idlwave-fill-function)])
  8302. ("Templates"
  8303. ["Procedure" idlwave-procedure t]
  8304. ["Function" idlwave-function t]
  8305. ["Doc Header" idlwave-doc-header t]
  8306. ["Log" idlwave-doc-modification t]
  8307. "--"
  8308. ["Case" idlwave-case t]
  8309. ["For" idlwave-for t]
  8310. ["Repeat" idlwave-repeat t]
  8311. ["While" idlwave-while t]
  8312. "--"
  8313. ["Close Block" idlwave-close-block t])
  8314. ("Completion"
  8315. ["Complete" idlwave-complete t]
  8316. ("Complete Specific"
  8317. ["1 Procedure Name" (idlwave-complete 'procedure) t]
  8318. ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
  8319. "--"
  8320. ["3 Function Name" (idlwave-complete 'function) t]
  8321. ["4 Function Keyword" (idlwave-complete 'function-keyword) t]
  8322. "--"
  8323. ["5 Procedure Method Name" (idlwave-complete 'procedure-method) t]
  8324. ["6 Procedure Method Keyword" (idlwave-complete 'procedure-method-keyword) t]
  8325. "--"
  8326. ["7 Function Method Name" (idlwave-complete 'function-method) t]
  8327. ["8 Function Method Keyword" (idlwave-complete 'function-method-keyword) t]
  8328. "--"
  8329. ["9 Class Name" idlwave-complete-class t]))
  8330. ("Routine Info"
  8331. ["Show Routine Info" idlwave-routine-info t]
  8332. ["Online Context Help" idlwave-context-help t]
  8333. "--"
  8334. ["Find Routine Source" idlwave-find-module t]
  8335. ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
  8336. "--"
  8337. ["Update Routine Info" idlwave-update-routine-info t]
  8338. ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
  8339. "--"
  8340. "IDL User Catalog"
  8341. ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
  8342. ["Scan Directories" (idlwave-update-routine-info '(16))
  8343. (and idlwave-path-alist (not idlwave-catalog-process))]
  8344. ["Scan Directories &" (idlwave-update-routine-info '(64))
  8345. (and idlwave-path-alist (not idlwave-catalog-process))]
  8346. "--"
  8347. "Routine Shadows"
  8348. ["Check Current Buffer" idlwave-list-buffer-load-path-shadows t]
  8349. ["Check Compiled Routines" idlwave-list-shell-load-path-shadows t]
  8350. ["Check Everything" idlwave-list-all-load-path-shadows t])
  8351. ("Misc"
  8352. ["Kill auto-created buffers" idlwave-kill-autoloaded-buffers t]
  8353. "--"
  8354. ["Insert TAB character" idlwave-hard-tab t])
  8355. "--"
  8356. ("External"
  8357. ["Start IDL shell" idlwave-shell t]
  8358. ["Edit file in IDLDE" idlwave-edit-in-idlde t]
  8359. ["Launch IDL Help" idlwave-launch-idlhelp t])
  8360. "--"
  8361. ("Customize"
  8362. ["Browse IDLWAVE Group" idlwave-customize t]
  8363. "--"
  8364. ["Build Full Customize Menu" idlwave-create-customize-menu
  8365. (fboundp 'customize-menu-create)])
  8366. ("Documentation"
  8367. ["Describe Mode" describe-mode t]
  8368. ["Abbreviation List" idlwave-list-abbrevs t]
  8369. "--"
  8370. ["Commentary in idlwave.el" idlwave-show-commentary t]
  8371. ["Commentary in idlw-shell.el" idlwave-shell-show-commentary t]
  8372. "--"
  8373. ["Info" idlwave-info t]
  8374. "--"
  8375. ["Help with Topic" idlwave-help-assistant-help-with-topic
  8376. idlwave-help-use-assistant]
  8377. ["Launch IDL Help" idlwave-launch-idlhelp t])))
  8378. (defvar idlwave-mode-debug-menu-def
  8379. '("Debug"
  8380. ["Start IDL shell" idlwave-shell t]
  8381. ["Save and .RUN buffer" idlwave-shell-save-and-run
  8382. (and (boundp 'idlwave-shell-automatic-start)
  8383. idlwave-shell-automatic-start)]))
  8384. (if (or (featurep 'easymenu) (load "easymenu" t))
  8385. (progn
  8386. (easy-menu-define idlwave-mode-menu idlwave-mode-map
  8387. "IDL and WAVE CL editing menu"
  8388. idlwave-mode-menu-def)
  8389. (easy-menu-define idlwave-mode-debug-menu idlwave-mode-map
  8390. "IDL and WAVE CL editing menu"
  8391. idlwave-mode-debug-menu-def)))
  8392. (defun idlwave-customize ()
  8393. "Call the customize function with `idlwave' as argument."
  8394. (interactive)
  8395. ;; Try to load the code for the shell, so that we can customize it
  8396. ;; as well.
  8397. (or (featurep 'idlw-shell)
  8398. (load "idlw-shell" t))
  8399. (customize-browse 'idlwave))
  8400. (defun idlwave-create-customize-menu ()
  8401. "Create a full customization menu for IDLWAVE, insert it into the menu."
  8402. (interactive)
  8403. (if (fboundp 'customize-menu-create)
  8404. (progn
  8405. ;; Try to load the code for the shell, so that we can customize it
  8406. ;; as well.
  8407. (or (featurep 'idlw-shell)
  8408. (load "idlw-shell" t))
  8409. (easy-menu-change
  8410. '("IDLWAVE") "Customize"
  8411. `(["Browse IDLWAVE group" idlwave-customize t]
  8412. "--"
  8413. ,(customize-menu-create 'idlwave)
  8414. ["Set" Custom-set t]
  8415. ["Save" Custom-save t]
  8416. ["Reset to Current" Custom-reset-current t]
  8417. ["Reset to Saved" Custom-reset-saved t]
  8418. ["Reset to Standard Settings" Custom-reset-standard t]))
  8419. (message "\"IDLWAVE\"-menu now contains full customization menu"))
  8420. (error "Cannot expand menu (outdated version of cus-edit.el)")))
  8421. (defun idlwave-show-commentary ()
  8422. "Use the finder to view the file documentation from `idlwave.el'."
  8423. (interactive)
  8424. (finder-commentary "idlwave.el"))
  8425. (defun idlwave-shell-show-commentary ()
  8426. "Use the finder to view the file documentation from `idlw-shell.el'."
  8427. (interactive)
  8428. (finder-commentary "idlw-shell.el"))
  8429. (defun idlwave-info ()
  8430. "Read documentation for IDLWAVE in the info system."
  8431. (interactive)
  8432. (info "idlwave"))
  8433. (defun idlwave-list-abbrevs (arg)
  8434. "Show the code abbreviations define in IDLWAVE mode.
  8435. This lists all abbrevs where the replacement text differs from the input text.
  8436. These are the ones the users want to learn to speed up their writing.
  8437. The function does *not* list abbrevs which replace a word with itself
  8438. to call a hook. These hooks are used to change the case of words or
  8439. to blink the matching `begin', and the user does not need to know them.
  8440. With arg, list all abbrevs with the corresponding hook.
  8441. This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
  8442. (interactive "P")
  8443. (let ((table (symbol-value 'idlwave-mode-abbrev-table))
  8444. abbrevs
  8445. str rpl func fmt (len-str 0) (len-rpl 0))
  8446. (mapatoms
  8447. (lambda (sym)
  8448. (if (symbol-value sym)
  8449. (progn
  8450. (setq str (symbol-name sym)
  8451. rpl (symbol-value sym)
  8452. func (symbol-function sym))
  8453. (if arg
  8454. (setq func (prin1-to-string func))
  8455. (if (and (listp func) (stringp (nth 2 func)))
  8456. (setq rpl (concat "EVAL: " (nth 2 func))
  8457. func "")
  8458. (setq func "")))
  8459. (if (or arg (not (string= rpl str)))
  8460. (progn
  8461. (setq len-str (max len-str (length str)))
  8462. (setq len-rpl (max len-rpl (length rpl)))
  8463. (setq abbrevs (cons (list str rpl func) abbrevs)))))))
  8464. table)
  8465. ;; sort the list
  8466. (setq abbrevs (sort abbrevs (lambda (a b) (string< (car a) (car b)))))
  8467. ;; Make the format
  8468. (setq fmt (format "%%-%ds %%-%ds %%s\n" len-str len-rpl))
  8469. (with-output-to-temp-buffer "*Help*"
  8470. (if arg
  8471. (progn
  8472. (princ "Abbreviations and Actions in IDLWAVE-Mode\n")
  8473. (princ "=========================================\n\n")
  8474. (princ (format fmt "KEY" "REPLACE" "HOOK"))
  8475. (princ (format fmt "---" "-------" "----")))
  8476. (princ "Code Abbreviations and Templates in IDLWAVE-Mode\n")
  8477. (princ "================================================\n\n")
  8478. (princ (format fmt "KEY" "ACTION" ""))
  8479. (princ (format fmt "---" "------" "")))
  8480. (dolist (list abbrevs)
  8481. (setq str (car list)
  8482. rpl (nth 1 list)
  8483. func (nth 2 list))
  8484. (princ (format fmt str rpl func)))))
  8485. ;; Make sure each abbreviation uses only one display line
  8486. (with-current-buffer "*Help*"
  8487. (setq truncate-lines t)))
  8488. ;; Add .pro files to speedbar for support, if it's loaded
  8489. (eval-after-load "speedbar" '(speedbar-add-supported-extension ".pro"))
  8490. ;; Set an idle timer to load the routine info.
  8491. ;; Will only work on systems which support this.
  8492. (or idlwave-routines (idlwave-start-load-rinfo-timer))
  8493. ;; Run the hook
  8494. (run-hooks 'idlwave-load-hook)
  8495. (provide 'idlwave)
  8496. ;;; idlwave.el ends here