idlw-shell.el 174 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680
  1. ;; idlw-shell.el --- run IDL as an inferior process of Emacs.
  2. ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
  3. ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
  4. ;; Carsten Dominik <dominik@astro.uva.nl>
  5. ;; Chris Chase <chase@att.com>
  6. ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
  7. ;; Version: 6.1.22
  8. ;; Keywords: processes
  9. ;; Package: idlwave
  10. ;; This file is part of GNU Emacs.
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;; Commentary:
  22. ;;
  23. ;; This mode is for IDL version 5 or later. It should work on
  24. ;; Emacs>20.3 or XEmacs>20.4.
  25. ;;
  26. ;; Runs IDL as an inferior process of Emacs, much like the Emacs
  27. ;; `shell' or `telnet' commands. Provides command history and
  28. ;; searching. Provides debugging commands available in buffers
  29. ;; visiting IDL procedure files, e.g., breakpoint setting, stepping,
  30. ;; execution until a certain line, printing expressions under point,
  31. ;; visual line pointer for current execution line, etc.
  32. ;;
  33. ;; Documentation should be available online with `M-x idlwave-info'.
  34. ;;
  35. ;; New versions of IDLWAVE, documentation, and more information
  36. ;; available from:
  37. ;; http://idlwave.org
  38. ;;
  39. ;; INSTALLATION:
  40. ;; =============
  41. ;;
  42. ;; Follow the instructions in the INSTALL file of the distribution.
  43. ;; In short, put this file on your load path and add the following
  44. ;; lines to your .emacs file:
  45. ;;
  46. ;; (autoload 'idlwave-shell "idlw-shell" "IDLWAVE Shell" t)
  47. ;;
  48. ;;
  49. ;; SOURCE
  50. ;; ======
  51. ;;
  52. ;; The newest version of this file can be found on the maintainers
  53. ;; web site.
  54. ;;
  55. ;; http://idlwave.org
  56. ;;
  57. ;; DOCUMENTATION
  58. ;; =============
  59. ;;
  60. ;; IDLWAVE is documented online in info format.
  61. ;; A printable version of the documentation is available from the
  62. ;; maintainers webpage (see under SOURCE)
  63. ;;
  64. ;;
  65. ;; KNOWN PROBLEMS
  66. ;; ==============
  67. ;;
  68. ;; Under XEmacs the Debug menu in the shell does not display the
  69. ;; keybindings in the prefix map. There bindings are available anyway - so
  70. ;; it is a bug in XEmacs.
  71. ;; The Debug menu in source buffers *does* display the bindings correctly.
  72. ;;
  73. ;;
  74. ;; CUSTOMIZATION VARIABLES
  75. ;; =======================
  76. ;;
  77. ;; IDLWAVE has customize support - so if you want to learn about
  78. ;; the variables which control the behavior of the mode, use
  79. ;; `M-x idlwave-customize'.
  80. ;;
  81. ;;--------------------------------------------------------------------------
  82. ;;
  83. ;;; Code:
  84. (require 'comint)
  85. (require 'idlwave)
  86. (eval-when-compile (require 'cl))
  87. (defvar idlwave-shell-have-new-custom nil)
  88. ;;; Customizations: idlwave-shell group
  89. ;; General/Misc. customizations
  90. (defgroup idlwave-shell-general-setup nil
  91. "General setup of the Shell interaction for IDLWAVE/Shell."
  92. :prefix "idlwave-shell"
  93. :group 'idlwave)
  94. (defcustom idlwave-shell-prompt-pattern "^\r? ?IDL> "
  95. "*Regexp to match IDL prompt at beginning of a line.
  96. For example, \"^\r?IDL> \" or \"^\r?WAVE> \".
  97. The \"^\r?\" is needed, to indicate the beginning of the line, with
  98. optional return character (which IDL seems to output randomly).
  99. This variable is used to initialize `comint-prompt-regexp' in the
  100. process buffer.
  101. This is a fine thing to set in your `.emacs' file."
  102. :group 'idlwave-shell-general-setup
  103. :type 'regexp)
  104. (defcustom idlwave-shell-process-name "idl"
  105. "*Name to be associated with the IDL process. The buffer for the
  106. process output is made by surrounding this name with `*'s."
  107. :group 'idlwave-shell-general-setup
  108. :type 'string)
  109. ;; (defcustom idlwave-shell-automatic-start...) See idlwave.el
  110. (defcustom idlwave-shell-use-dedicated-window nil
  111. "*Non-nil means, never replace the shell frame with another buffer."
  112. :group 'idlwave-shell-general-setup
  113. :type 'boolean)
  114. (defcustom idlwave-shell-use-dedicated-frame nil
  115. "*Non-nil means, IDLWAVE should use a special frame to display shell buffer."
  116. :group 'idlwave-shell-general-setup
  117. :type 'boolean)
  118. (defcustom idlwave-shell-frame-parameters
  119. '((height . 30) (unsplittable . nil))
  120. "The frame parameters for a dedicated idlwave-shell frame.
  121. See also `idlwave-shell-use-dedicated-frame'.
  122. The default makes the frame splittable, so that completion works correctly."
  123. :group 'idlwave-shell-general-setup
  124. :type '(repeat
  125. (cons symbol sexp)))
  126. (defcustom idlwave-shell-raise-frame t
  127. "*Non-nil means, `idlwave-shell' raises the frame showing the shell window."
  128. :group 'idlwave-shell-general-setup
  129. :type 'boolean)
  130. (defcustom idlwave-shell-arrows-do-history t
  131. "*Non-nil means UP and DOWN arrows move through command history.
  132. This variable can have 3 values:
  133. nil Arrows just move the cursor
  134. t Arrows force the cursor back to the current command line and
  135. walk the history
  136. 'cmdline When the cursor is in the current command line, arrows walk the
  137. history. Everywhere else in the buffer, arrows move the cursor."
  138. :group 'idlwave-shell-general-setup
  139. :type '(choice
  140. (const :tag "never" nil)
  141. (const :tag "everywhere" t)
  142. (const :tag "in command line only" cmdline)))
  143. ;; FIXME: add comint-input-ring-size?
  144. (defcustom idlwave-shell-use-toolbar t
  145. "*Non-nil means, use the debugging toolbar in all IDL related buffers.
  146. Starting the shell will then add the toolbar to all idlwave-mode buffers.
  147. Exiting the shell will removed everywhere.
  148. Available on XEmacs and on Emacs 21.x or later.
  149. At any time you can toggle the display of the toolbar with
  150. `C-c C-d C-t' (`idlwave-shell-toggle-toolbar')."
  151. :group 'idlwave-shell-general-setup
  152. :type 'boolean)
  153. (defcustom idlwave-shell-temp-pro-prefix "/tmp/idltemp"
  154. "*The prefix for temporary IDL files used when compiling regions.
  155. It should be an absolute pathname.
  156. The full temporary file name is obtained by using `make-temp-file'
  157. so that the name will be unique among multiple Emacs processes."
  158. :group 'idlwave-shell-general-setup
  159. :type 'string)
  160. (defvar idlwave-shell-fix-inserted-breaks nil
  161. "*OBSOLETE VARIABLE, is no longer used.
  162. The documentation of this variable used to be:
  163. If non-nil then run `idlwave-shell-remove-breaks' to clean up IDL messages.")
  164. (defcustom idlwave-shell-prefix-key "\C-c\C-d"
  165. "*The prefix key for the debugging map `idlwave-shell-mode-prefix-map'.
  166. This variable must already be set when idlwave-shell.el is loaded.
  167. Setting it in the mode-hook is too late."
  168. :group 'idlwave-shell-general-setup
  169. :type 'string)
  170. (defcustom idlwave-shell-activate-prefix-keybindings t
  171. "Non-nil means, the debug commands will be bound to the prefix key.
  172. The prefix key itself is given in the option `idlwave-shell-prefix-key'.
  173. So by default setting a breakpoint will be on C-c C-d C-b."
  174. :group 'idlwave-shell-general-setup
  175. :type 'boolean)
  176. (defcustom idlwave-shell-automatic-electric-debug 'breakpoint
  177. "Enter the electric-debug minor mode automatically.
  178. This occurs at a breakpoint or any other halt. The mode is exited
  179. upon return to the main level. Can be set to 'breakpoint to enter
  180. electric debug mode only when breakpoints are tripped."
  181. :group 'idlwave-shell-general-setup
  182. :type '(choice
  183. (const :tag "never" nil)
  184. (const :tag "always" t)
  185. (const :tag "for breakpoints only" breakpoint)))
  186. (defcustom idlwave-shell-electric-zap-to-file t
  187. "When entering electric debug mode, select the window displaying the
  188. file at which point is stopped. This takes point away from the shell
  189. window, but is useful for stepping, etc."
  190. :group 'idlwave-shell-general-setup
  191. :type 'boolean)
  192. ;; (defcustom idlwave-shell-debug-modifiers... See idlwave.el
  193. (defvar idlwave-shell-activate-alt-keybindings nil
  194. "Obsolete variable. See `idlwave-shell-debug-modifiers'.")
  195. (defcustom idlwave-shell-use-truename nil
  196. "*Non-nil means, use `file-truename' when looking for buffers.
  197. If this variable is non-nil, Emacs will use the function `file-truename' to
  198. resolve symbolic links in the file paths printed by e.g., STOP commands.
  199. This means, unvisited files will be loaded under their truename.
  200. However, when a file is already visited under a different name, IDLWAVE will
  201. reuse that buffer.
  202. This option was once introduced in order to avoid multiple buffers visiting
  203. the same file. However, IDLWAVE no longer makes this mistake, so it is safe
  204. to set this option to nil."
  205. :group 'idlwave-shell-general-setup
  206. :type 'boolean)
  207. (defcustom idlwave-shell-file-name-chars "~/A-Za-z0-9+:_.$#%={}\\- "
  208. "The characters allowed in file names, as a string.
  209. Used for file name completion. Must not contain `'', `,' and `\"'
  210. because these are used as separators by IDL."
  211. :group 'idlwave-shell-general-setup
  212. :type 'string)
  213. (defcustom idlwave-shell-mode-hook '()
  214. "*Hook for customizing `idlwave-shell-mode'."
  215. :group 'idlwave-shell-general-setup
  216. :type 'hook)
  217. (defcustom idlwave-shell-graphics-window-size '(500 400)
  218. "Size of IDL graphics windows popped up by special IDLWAVE command.
  219. The command is `C-c C-d C-f' and accepts as a prefix the window nr.
  220. A command like `WINDOW,N,xsize=XX,ysize=YY' is sent to IDL."
  221. :group 'idlwave-shell-general-setup
  222. :type '(list
  223. (integer :tag "x size")
  224. (integer :tag "y size")))
  225. ;; Commands Sent to Shell... etc.
  226. (defgroup idlwave-shell-command-setup nil
  227. "Setup for command parameters of the Shell interaction for IDLWAVE."
  228. :prefix "idlwave-shell"
  229. :group 'idlwave)
  230. (defcustom idlwave-shell-initial-commands "!more=0 & defsysv,'!ERROR_STATE',EXISTS=__e & if __e then begin & !ERROR_STATE.MSG_PREFIX=\"% \" & delvar,__e & endif"
  231. "Initial commands, separated by newlines, to send to IDL.
  232. This string is sent to the IDL process by `idlwave-shell-mode' which is
  233. invoked by `idlwave-shell'."
  234. :group 'idlwave-shell-command-setup
  235. :type 'string)
  236. (defcustom idlwave-shell-save-command-history t
  237. "Non-nil means preserve command history between sessions.
  238. The file `idlwave-shell-command-history-file' is used to save and restore
  239. the history."
  240. :group 'idlwave-shell-command-setup
  241. :type 'boolean)
  242. (defcustom idlwave-shell-command-history-file "idlwhist"
  243. "The file in which the command history of the idlwave shell is saved.
  244. In order to change the size of the history, see the variable
  245. `comint-input-ring-size'.
  246. The history is only saved if the variable `idlwave-shell-save-command-history'
  247. is non-nil."
  248. :group 'idlwave-shell-command-setup
  249. :type 'file)
  250. (defcustom idlwave-shell-show-commands
  251. '(run misc breakpoint)
  252. "*A list of command types to show output from in the shell.
  253. Possibilities are 'run, 'debug, 'breakpoint, and 'misc. Unselected
  254. types are not displayed in the shell. The type 'everything causes all
  255. the copious shell traffic to be displayed."
  256. :group 'idlwave-shell-command-setup
  257. :type '(choice
  258. (const everything)
  259. (set :tag "Checklist" :greedy t
  260. (const :tag "All .run and .compile commands" run)
  261. (const :tag "All breakpoint commands" breakpoint)
  262. (const :tag "All debug and stepping commands" debug)
  263. (const :tag "Close, window, retall, etc. commands" misc))))
  264. (defcustom idlwave-shell-max-print-length 200
  265. "Maximum number of array elements to print when examining."
  266. :group 'idlwave-shell-command-setup
  267. :type 'integer)
  268. (defcustom idlwave-shell-examine-alist
  269. `(("Print" . ,(concat "idlwave_print_safe,___,"
  270. (number-to-string
  271. idlwave-shell-max-print-length)))
  272. ("Help" . "help,___")
  273. ("Structure Help" . "help,___,/STRUCTURE")
  274. ("Dimensions" . "print,size(___,/DIMENSIONS)")
  275. ("Type" . "print,size(___,/TNAME)")
  276. ("N_Elements" . "print,n_elements(___)")
  277. ("All Size Info" . "help,(__IWsz__=size(___,/STRUCTURE)),/STRUCTURE & print,__IWsz__.DIMENSIONS")
  278. ("Ptr Valid" . "print,ptr_valid(___)")
  279. ("Arg Present" . "print,arg_present(___)")
  280. ("Widget Valid" . "print,widget_info(___,/VALID)")
  281. ("Widget Geometry" . "help,widget_info(___,/GEOMETRY)"))
  282. "Alist of special examine commands for popup selection.
  283. The keys are used in the selection popup created by
  284. `idlwave-shell-examine-select', and the corresponding value is sent as
  285. a command to the shell, with special sequence `___' replaced by the
  286. expression being examined."
  287. :group 'idlwave-shell-command-setup
  288. :type '(repeat
  289. (cons
  290. (string :tag "Label ")
  291. (string :tag "Command"))))
  292. (defvar idlwave-shell-print-expression-function nil
  293. "*OBSOLETE VARIABLE, is no longer used.")
  294. (defcustom idlwave-shell-separate-examine-output t
  295. "*Non-nil means, put output of examine commands in their own buffer."
  296. :group 'idlwave-shell-command-setup
  297. :type 'boolean)
  298. (defcustom idlwave-shell-comint-settings
  299. '((comint-scroll-to-bottom-on-input . t)
  300. (comint-scroll-to-bottom-on-output . t)
  301. (comint-scroll-show-maximum-output . nil)
  302. (comint-prompt-read-only . t))
  303. "Alist of special settings for the comint variables in the IDLWAVE Shell.
  304. Each entry is a cons cell with the name of a variable and a value.
  305. The function `idlwave-shell-mode' will make local variables out of each entry.
  306. Changes to this variable will only be active when the shell buffer is
  307. newly created."
  308. :group 'idlwave-shell-command-setup
  309. :type '(repeat
  310. (cons variable sexp)))
  311. (defcustom idlwave-shell-query-for-class t
  312. "*Non-nil means query the shell for object class on object completions."
  313. :group 'idlwave-shell-command-setup
  314. :type 'boolean)
  315. (defcustom idlwave-shell-use-input-mode-magic nil
  316. "*Non-nil means, IDLWAVE should check for input mode spells in output.
  317. The spells are strings printed by your IDL program and matched
  318. by the regular expressions in `idlwave-shell-input-mode-spells'.
  319. When these expressions match, IDLWAVE switches to character input mode and
  320. back, respectively. See `idlwave-shell-input-mode-spells' for details."
  321. :group 'idlwave-shell-command-setup
  322. :type 'boolean)
  323. (defcustom idlwave-shell-input-mode-spells
  324. '("^<onechar>$" "^<chars>$" "^</chars>$")
  325. "The three regular expressions which match the magic spells for input modes.
  326. When the first regexp matches in the output stream of IDL, IDLWAVE
  327. prompts for a single character and sends it immediately to IDL, similar
  328. to the command \\[idlwave-shell-send-char].
  329. When the second regexp matches, IDLWAVE switches to a blocking
  330. single-character input mode. This is the same mode which can be entered
  331. manually with \\[idlwave-shell-char-mode-loop].
  332. This input mode exits when the third regexp matches in the output,
  333. or when the IDL prompt is encountered.
  334. The variable `idlwave-shell-use-input-mode-magic' must be non-nil to enable
  335. scanning for these expressions. If the IDL program produces lots of
  336. output, shell operation may be slowed down.
  337. This mechanism is useful for correct interaction with the IDL function
  338. GET_KBRD, because in normal operation IDLWAVE only sends \\n terminated
  339. strings. Here is some example code which makes use of the default spells.
  340. print,'<chars>' ; Make IDLWAVE switch to character mode
  341. REPEAT BEGIN
  342. A = GET_KBRD(1)
  343. PRINT, BYTE(A)
  344. ENDREP UNTIL A EQ 'q'
  345. print,'</chars>' ; Make IDLWAVE switch back to line mode
  346. print,'Quit the program, y or n?'
  347. print,'<onechar>' ; Ask IDLWAVE to send one character
  348. answer = GET_KBRD(1)
  349. Since the IDLWAVE shell defines the system variable `!IDLWAVE_VERSION',
  350. you could actually check if you are running under Emacs before printing
  351. the magic strings. Here is a procedure which uses this.
  352. Usage:
  353. ======
  354. idlwave_char_input ; Make IDLWAVE send one character
  355. idlwave_char_input,/on ; Start the loop to send characters
  356. idlwave_char_input,/off ; End the loop to send characters
  357. pro idlwave_char_input,on=on,off=off
  358. ;; Test if we are running under Emacs
  359. defsysv,'!idlwave_version',exists=running_emacs
  360. if running_emacs then begin
  361. if keyword_set(on) then print,'<chars>' $
  362. else if keyword_set(off) then print,'</chars>' $
  363. else print,'<onechar>'
  364. endif
  365. end"
  366. :group 'idlwave-shell-command-setup
  367. :type '(list
  368. (regexp :tag "One-char regexp")
  369. (regexp :tag "Char-mode regexp")
  370. (regexp :tag "Line-mode regexp")))
  371. (defcustom idlwave-shell-breakpoint-popup-menu t
  372. "*If non-nil, provide a menu on mouse-3 on breakpoint lines, and
  373. popup help text on the line."
  374. :group 'idlwave-shell-command-setup
  375. :type 'boolean)
  376. (defcustom idlwave-shell-reset-no-prompt nil
  377. "If non-nil, skip the yes/no prompt when resetting the IDL session."
  378. :group 'idlwave-shell-command-setup
  379. :type 'boolean)
  380. ;; Breakpoint Overlays etc
  381. (defgroup idlwave-shell-highlighting-and-faces nil
  382. "Highlighting and faces used by the IDLWAVE Shell mode."
  383. :prefix "idlwave-shell"
  384. :group 'idlwave)
  385. (defcustom idlwave-shell-mark-stop-line t
  386. "*Non-nil means, mark the source code line where IDL is currently stopped.
  387. Value decides about the method which is used to mark the line. Valid values
  388. are:
  389. nil Do not mark the line
  390. 'arrow Use the overlay arrow
  391. 'face Use `idlwave-shell-stop-line-face' to highlight the line.
  392. t Use what IDLWAVE thinks is best. Will be a face where possible,
  393. otherwise the overlay arrow.
  394. The overlay-arrow has the disadvantage to hide the first chars of a line.
  395. Since many people do not have the main block of IDL programs indented,
  396. a face highlighting may be better.
  397. In Emacs 21, the overlay arrow is displayed in a special area and never
  398. hides any code, so setting this to 'arrow on Emacs 21 sounds like a good idea."
  399. :group 'idlwave-shell-highlighting-and-faces
  400. :type '(choice
  401. (const :tag "No marking" nil)
  402. (const :tag "Use overlay arrow" arrow)
  403. (const :tag "Highlight with face" face)
  404. (const :tag "Face or arrow." t)))
  405. (defcustom idlwave-shell-overlay-arrow ">"
  406. "*The overlay arrow to display at source lines where execution halts.
  407. We use a single character by default, since the main block of IDL procedures
  408. often has no indentation. Where possible, IDLWAVE will use overlays to
  409. display the stop-lines. The arrow is only used on character-based terminals.
  410. See also `idlwave-shell-use-overlay-arrow'."
  411. :group 'idlwave-shell-highlighting-and-faces
  412. :type 'string)
  413. (defcustom idlwave-shell-stop-line-face 'highlight
  414. "*The face for `idlwave-shell-stop-line-overlay'.
  415. Allows you to choose the font, color and other properties for
  416. line where IDL is stopped. See also `idlwave-shell-mark-stop-line'."
  417. :group 'idlwave-shell-highlighting-and-faces
  418. :type 'symbol)
  419. (defcustom idlwave-shell-electric-stop-color "Violet"
  420. "*The color for the default face or overlay arrow when stopped."
  421. :group 'idlwave-shell-highlighting-and-faces
  422. :type 'string)
  423. (defcustom idlwave-shell-electric-stop-line-face
  424. (prog1
  425. (copy-face 'modeline 'idlwave-shell-electric-stop-line)
  426. (set-face-background 'idlwave-shell-electric-stop-line
  427. idlwave-shell-electric-stop-color)
  428. (condition-case nil
  429. (set-face-foreground 'idlwave-shell-electric-stop-line nil)
  430. (error nil)))
  431. "*The face for `idlwave-shell-stop-line-overlay' when in electric debug mode.
  432. Allows you to choose the font, color and other properties for the line
  433. where IDL is stopped, when in Electric Debug Mode."
  434. :group 'idlwave-shell-highlighting-and-faces
  435. :type 'symbol)
  436. (defcustom idlwave-shell-mark-breakpoints t
  437. "*Non-nil means, mark breakpoints in the source files.
  438. Valid values are:
  439. nil Do not mark breakpoints.
  440. 'face Highlight line with `idlwave-shell-breakpoint-face'.
  441. 'glyph Red dot at the beginning of line. If the display does not
  442. support glyphs, will use 'face instead.
  443. t Glyph when possible, otherwise face (same effect as 'glyph)."
  444. :group 'idlwave-shell-highlighting-and-faces
  445. :type '(choice
  446. (const :tag "No marking" nil)
  447. (const :tag "Highlight with face" face)
  448. (const :tag "Display glyph (red dot)" glyph)
  449. (const :tag "Glyph or face." t)))
  450. (defvar idlwave-shell-use-breakpoint-glyph t
  451. "Obsolete variable. See `idlwave-shell-mark-breakpoints'.")
  452. (defcustom idlwave-shell-breakpoint-face 'idlwave-shell-bp
  453. "*The face for breakpoint lines in the source code.
  454. Allows you to choose the font, color and other properties for
  455. lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'."
  456. :group 'idlwave-shell-highlighting-and-faces
  457. :type 'symbol)
  458. (if (not idlwave-shell-have-new-custom)
  459. ;; Just copy the underline face to be on the safe side.
  460. (copy-face 'underline 'idlwave-shell-bp)
  461. ;; We have the new customize - use it to define a customizable face
  462. (defface idlwave-shell-bp
  463. '((((class color)) (:foreground "Black" :background "Pink"))
  464. (t (:underline t)))
  465. "Face for highlighting lines with breakpoints."
  466. :group 'idlwave-shell-highlighting-and-faces))
  467. (defcustom idlwave-shell-disabled-breakpoint-face
  468. 'idlwave-shell-disabled-bp
  469. "*The face for disabled breakpoint lines in the source code.
  470. Allows you to choose the font, color and other properties for
  471. lines which have a breakpoint. See also `idlwave-shell-mark-breakpoints'."
  472. :group 'idlwave-shell-highlighting-and-faces
  473. :type 'symbol)
  474. (if (not idlwave-shell-have-new-custom)
  475. ;; Just copy the underline face to be on the safe side.
  476. (copy-face 'underline 'idlwave-shell-disabled-bp)
  477. ;; We have the new customize - use it to define a customizable face
  478. (defface idlwave-shell-disabled-bp
  479. '((((class color)) (:foreground "Black" :background "gray"))
  480. (t (:underline t)))
  481. "Face for highlighting lines with breakpoints."
  482. :group 'idlwave-shell-highlighting-and-faces))
  483. (defcustom idlwave-shell-expression-face 'secondary-selection
  484. "*The face for `idlwave-shell-expression-overlay'.
  485. Allows you to choose the font, color and other properties for
  486. the expression printed by IDL."
  487. :group 'idlwave-shell-highlighting-and-faces
  488. :type 'symbol)
  489. (defcustom idlwave-shell-output-face 'secondary-selection
  490. "*The face for `idlwave-shell-output-overlay'.
  491. Allows you to choose the font, color and other properties for
  492. the expression output by IDL."
  493. :group 'idlwave-shell-highlighting-and-faces
  494. :type 'symbol)
  495. ;;; End user customization variables
  496. ;;; External variables
  497. (defvar comint-last-input-start)
  498. (defvar comint-last-input-end)
  499. ;; Other variables
  500. (defvar idlwave-shell-temp-pro-file nil
  501. "Absolute pathname for temporary IDL file for compiling regions")
  502. (defvar idlwave-shell-temp-rinfo-save-file nil
  503. "Absolute pathname for temporary IDL file save file for routine_info.
  504. This is used to speed up the reloading of the routine info procedure
  505. before use by the shell.")
  506. (defun idlwave-shell-temp-file (type)
  507. "Return a temp file, creating it if necessary.
  508. TYPE is either 'pro' or 'rinfo', and `idlwave-shell-temp-pro-file' or
  509. `idlwave-shell-temp-rinfo-save-file' is set (respectively)."
  510. (cond
  511. ((eq type 'rinfo)
  512. (or idlwave-shell-temp-rinfo-save-file
  513. (setq idlwave-shell-temp-rinfo-save-file
  514. (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix))))
  515. ((eq type 'pro)
  516. (or idlwave-shell-temp-pro-file
  517. (setq idlwave-shell-temp-pro-file
  518. (idlwave-shell-make-temp-file idlwave-shell-temp-pro-prefix))))
  519. (t (error "Wrong argument (idlwave-shell-temp-file): %s"
  520. (symbol-name type)))))
  521. (defun idlwave-shell-make-temp-file (prefix)
  522. "Create a temporary file."
  523. ; Hard coded make-temp-file for Emacs<21
  524. (if (fboundp 'make-temp-file)
  525. (make-temp-file prefix)
  526. (let (file
  527. (temp-file-dir (if (boundp 'temporary-file-directory)
  528. temporary-file-directory
  529. "/tmp")))
  530. (while (condition-case ()
  531. (progn
  532. (setq file
  533. (make-temp-name
  534. (expand-file-name prefix temp-file-dir)))
  535. (if (featurep 'xemacs)
  536. (write-region "" nil file nil 'silent nil)
  537. (write-region "" nil file nil 'silent nil 'excl))
  538. nil)
  539. (file-already-exists t))
  540. ;; the file was somehow created by someone else between
  541. ;; `make-temp-name' and `write-region', let's try again.
  542. nil)
  543. file)))
  544. (defvar idlwave-shell-dirstack-query "cd,current=___cur & print,___cur"
  545. "Command used by `idlwave-shell-resync-dirs' to query IDL for
  546. the directory stack.")
  547. (defvar idlwave-shell-path-query "print,'PATH:<'+transpose(expand_path(!PATH,/ARRAY))+'>' & print,'SYSDIR:<'+!dir+'>'"
  548. "The command which gets !PATH and !DIR info from the shell.")
  549. (defvar idlwave-shell-mode-line-info nil
  550. "Additional info displayed in the mode line.")
  551. (defvar idlwave-shell-default-directory nil
  552. "The default directory in the idlwave-shell buffer, of outside use.")
  553. (defvar idlwave-shell-last-save-and-action-file nil
  554. "The last file which was compiled with `idlwave-shell-save-and-...'.")
  555. ;; Highlighting uses overlays. When necessary, require the emulation.
  556. (if (not (fboundp 'make-overlay))
  557. (condition-case nil
  558. (require 'overlay)
  559. (error nil)))
  560. (defvar idlwave-shell-stop-line-overlay nil
  561. "The overlay for where IDL is currently stopped.")
  562. (defvar idlwave-shell-is-stopped nil)
  563. (defvar idlwave-shell-expression-overlay nil
  564. "The overlay for the examined expression.")
  565. (defvar idlwave-shell-output-overlay nil
  566. "The overlay for the last IDL output.")
  567. ;; If these were already overlays, delete them. This probably means that we
  568. ;; are reloading this file.
  569. (if (overlayp idlwave-shell-stop-line-overlay)
  570. (delete-overlay idlwave-shell-stop-line-overlay))
  571. (if (overlayp idlwave-shell-expression-overlay)
  572. (delete-overlay idlwave-shell-expression-overlay))
  573. (if (overlayp idlwave-shell-output-overlay)
  574. (delete-overlay idlwave-shell-output-overlay))
  575. ;; Set to nil initially
  576. (setq idlwave-shell-stop-line-overlay nil
  577. idlwave-shell-expression-overlay nil
  578. idlwave-shell-output-overlay nil)
  579. ;; Define the shell stop overlay. When left nil, the arrow will be used.
  580. (cond
  581. ((or (null idlwave-shell-mark-stop-line)
  582. (eq idlwave-shell-mark-stop-line 'arrow))
  583. ;; Leave the overlay nil
  584. nil)
  585. ((eq idlwave-shell-mark-stop-line 'face)
  586. ;; Try to use a face. If not possible, arrow will be used anyway
  587. ;; So who can display faces?
  588. (when (or (featurep 'xemacs) ; XEmacs can do also ttys
  589. (fboundp 'tty-defined-colors) ; Emacs 21 as well
  590. window-system) ; Window systems always
  591. (progn
  592. (setq idlwave-shell-stop-line-overlay (make-overlay 1 1))
  593. (overlay-put idlwave-shell-stop-line-overlay
  594. 'face idlwave-shell-stop-line-face))))
  595. (t
  596. ;; IDLWAVE may decide. Will use a face on window systems, arrow elsewhere
  597. (if window-system
  598. (progn
  599. (setq idlwave-shell-stop-line-overlay (make-overlay 1 1))
  600. (overlay-put idlwave-shell-stop-line-overlay
  601. 'face idlwave-shell-stop-line-face)))))
  602. ;; Now the expression and output overlays
  603. (setq idlwave-shell-expression-overlay (make-overlay 1 1))
  604. (overlay-put idlwave-shell-expression-overlay
  605. 'face idlwave-shell-expression-face)
  606. (overlay-put idlwave-shell-expression-overlay
  607. 'priority 1)
  608. (setq idlwave-shell-output-overlay (make-overlay 1 1))
  609. (overlay-put idlwave-shell-output-overlay
  610. 'face idlwave-shell-output-face)
  611. (copy-face idlwave-shell-stop-line-face
  612. 'idlwave-shell-pending-stop)
  613. (copy-face idlwave-shell-electric-stop-line-face
  614. 'idlwave-shell-pending-electric-stop)
  615. (set-face-background 'idlwave-shell-pending-stop "gray70")
  616. (set-face-background 'idlwave-shell-pending-electric-stop "gray70")
  617. (defvar idlwave-shell-bp-query "help,/breakpoints"
  618. "Command to obtain list of breakpoints.")
  619. (defvar idlwave-shell-command-output nil
  620. "String for accumulating current command output.")
  621. (defvar idlwave-shell-post-command-hook nil
  622. "Lisp list expression or function to run when an IDL command is finished.
  623. The current command is finished when the IDL prompt is displayed.
  624. This is evaluated if it is a list or called with funcall.")
  625. (defvar idlwave-shell-sentinel-hook nil
  626. "Hook run when the IDL process exits.")
  627. (defvar idlwave-shell-hide-output nil
  628. "If non-nil the process output is not inserted into the output buffer.")
  629. (defvar idlwave-shell-show-if-error nil
  630. "If non-nil the process output is inserted into the output buffer if
  631. it contains an error message, even if hide-output is non-nil.")
  632. (defvar idlwave-shell-accumulation nil
  633. "Accumulate last line of output.")
  634. (defvar idlwave-shell-command-line-to-execute nil)
  635. (defvar idlwave-shell-cleanup-hook nil
  636. "List of functions to do cleanup when the shell exits.")
  637. (defvar idlwave-shell-pending-commands nil
  638. "List of commands to be sent to IDL.
  639. Each element of the list is list of \(CMD PCMD HIDE\), where CMD is a
  640. string to be sent to IDL and PCMD is a post-command to be placed on
  641. `idlwave-shell-post-command-hook'. If HIDE is non-nil, hide the output
  642. from command CMD. PCMD and HIDE are optional.")
  643. (defun idlwave-shell-buffer ()
  644. "Name of buffer associated with IDL process.
  645. The name of the buffer is made by surrounding `idlwave-shell-process-name'
  646. with `*'s."
  647. (concat "*" idlwave-shell-process-name "*"))
  648. (defvar idlwave-shell-ready nil
  649. "If non-nil can send next command to IDL process.")
  650. ;;; The following are the types of messages we attempt to catch to
  651. ;;; resync our idea of where IDL execution currently is.
  652. ;;;
  653. (defvar idlwave-shell-halt-frame nil
  654. "The frame associated with halt/breakpoint messages.")
  655. (defvar idlwave-shell-step-frame nil
  656. "The frame associated with step messages.")
  657. (defvar idlwave-shell-trace-frame nil
  658. "The frame associated with trace messages.")
  659. (defconst idlwave-shell-halt-messages
  660. '("^% Interrupted at:"
  661. "^% Stepped to:"
  662. "^% Skipped to:"
  663. "^% Stop encountered:"
  664. )
  665. "*A list of regular expressions matching IDL messages.
  666. These are the messages containing file and line information where
  667. IDL is currently stopped.")
  668. (defconst idlwave-shell-halt-messages-re
  669. (mapconcat 'identity idlwave-shell-halt-messages "\\|")
  670. "The regular expression computed from `idlwave-shell-halt-messages'.")
  671. (defconst idlwave-shell-trace-message-re
  672. "^% At " ;; First line of a trace message
  673. "*A regular expression matching IDL trace messages. These are the
  674. messages containing file and line information of a current
  675. traceback.")
  676. (defconst idlwave-shell-step-messages
  677. '("^% Stepped to:"
  678. )
  679. "*A list of regular expressions matching stepped execution messages.
  680. These are IDL messages containing file and line information where
  681. IDL has currently stepped.")
  682. (defvar idlwave-shell-break-message "^% Breakpoint at:"
  683. "*Regular expression matching an IDL breakpoint message line.")
  684. (defconst idlwave-shell-electric-debug-help
  685. " ==> IDLWAVE Electric Debug Mode Help <==
  686. Break Point Setting and Clearing:
  687. b Set breakpoint ([C-u b] for conditional, [C-n b] nth hit, etc.).
  688. d Clear nearby breakpoint.
  689. a Clear all breakpoints.
  690. i Set breakpoint in routine named here.
  691. j Set breakpoint at beginning of containing routine.
  692. \\ Toggle breakpoint disable
  693. ] Go to next breakpoint in file.
  694. [ Go to previous breakpoint in file.
  695. Stepping, Continuing, and the Stack:
  696. s or SPACE Step, into function calls.
  697. n Step, over function calls.
  698. k Skip one statement.
  699. m Continue to end of function.
  700. o Continue past end of function.
  701. u Continue to end of block.
  702. h Continue to line at cursor position.
  703. r Continue execution to next breakpoint, if any.
  704. + or = Show higher level in calling stack.
  705. - or _ Show lower level in calling stack.
  706. Examining Expressions (with prefix for examining the region):
  707. p Print expression near point or in region ([C-u p]).
  708. ? Help on expression near point or in region ([C-u ?]).
  709. x Examine expression near point or in region ([C-u x]) with
  710. letter completion of the examine type.
  711. e Prompt for an expression to print.
  712. Miscellaneous:
  713. q Quit - end debugging session and return to the Shell's main level.
  714. v Turn Electric Debugging Mode off (C-c C-d C-v to return).
  715. t Print a calling-level traceback in the shell.
  716. z Reset IDL.
  717. C-? Show this help menu.")
  718. (defvar idlwave-shell-bp-alist)
  719. ;(defvar idlwave-shell-post-command-output)
  720. (defvar idlwave-shell-sources-alist)
  721. (defvar idlwave-shell-menu-def)
  722. (defvar idlwave-shell-mode-menu)
  723. (defvar idlwave-shell-initial-commands)
  724. (defvar idlwave-shell-syntax-error)
  725. (defvar idlwave-shell-other-error)
  726. (defvar idlwave-shell-error-buffer)
  727. (defvar idlwave-shell-error-last)
  728. (defvar idlwave-shell-bp-buffer)
  729. (defvar idlwave-shell-sources-query)
  730. (defvar idlwave-shell-mode-map)
  731. (defvar idlwave-shell-calling-stack-index)
  732. (defvar idlwave-shell-only-prompt-pattern nil)
  733. (defvar tool-bar-map)
  734. (define-derived-mode idlwave-shell-mode comint-mode "IDL-Shell"
  735. "Major mode for interacting with an inferior IDL process.
  736. 1. Shell Interaction
  737. -----------------
  738. RET after the end of the process' output sends the text from the
  739. end of process to the end of the current line. RET before end of
  740. process output copies the current line (except for the prompt) to
  741. the end of the buffer.
  742. Command history, searching of previous commands, command line
  743. editing are available via the comint-mode key bindings, by default
  744. mostly on the key `C-c'. Command history is also available with
  745. the arrow keys UP and DOWN.
  746. 2. Completion
  747. ----------
  748. TAB and M-TAB do completion of IDL routines, classes and keywords -
  749. similar to M-TAB in `idlwave-mode'. In executive commands and
  750. strings, it completes file names. Abbreviations are also expanded
  751. like in `idlwave-mode'.
  752. 3. Routine Info
  753. ------------
  754. `\\[idlwave-routine-info]' displays information about an IDL routine near point,
  755. just like in `idlwave-mode'. The module used is the one at point or
  756. the one whose argument list is being edited.
  757. To update IDLWAVE's knowledge about compiled or edited modules, use
  758. \\[idlwave-update-routine-info].
  759. \\[idlwave-find-module] find the source of a module.
  760. \\[idlwave-resolve] tells IDL to compile an unresolved module.
  761. \\[idlwave-context-help] shows the online help on the item at
  762. point, if online help has been installed.
  763. 4. Debugging
  764. ---------
  765. A complete set of commands for compiling and debugging IDL programs
  766. is available from the menu. Also keybindings starting with a
  767. `C-c C-d' prefix are available for most commands in the *idl* buffer
  768. and also in source buffers. The best place to learn about the
  769. keybindings is again the menu.
  770. On Emacs versions where this is possible, a debugging toolbar is
  771. installed.
  772. When IDL is halted in the middle of a procedure, the corresponding
  773. line of that procedure file is displayed with an overlay in another
  774. window. Breakpoints are also highlighted in the source.
  775. \\[idlwave-shell-resync-dirs] queries IDL in order to change Emacs current directory
  776. to correspond to the IDL process current directory.
  777. 5. Expression Examination
  778. ----------------------
  779. Expressions near point can be examined with print,
  780. \\[idlwave-shell-print] or \\[idlwave-shell-mouse-print] with the
  781. mouse, help, \\[idlwave-shell-help-expression] or
  782. \\[idlwave-shell-mouse-help] with the mouse, or with a
  783. configurable set of custom examine commands using
  784. \\[idlwave-shell-examine-select]. The mouse examine commands can
  785. also work by click and drag, to select an expression for
  786. examination.
  787. 6. Hooks
  788. -----
  789. Turning on `idlwave-shell-mode' runs `comint-mode-hook' and
  790. `idlwave-shell-mode-hook' (in that order).
  791. 7. Documentation and Customization
  792. -------------------------------
  793. Info documentation for this package is available. Use \\[idlwave-info]
  794. to display (complain to your sysadmin if that does not work).
  795. For PostScript and HTML versions of the documentation, check IDLWAVE's
  796. homepage at URL `http://idlwave.org'.
  797. IDLWAVE has customize support - see the group `idlwave'.
  798. 8. Keybindings
  799. -----------
  800. \\{idlwave-shell-mode-map}"
  801. :abbrev-table idlwave-mode-abbrev-table
  802. (idlwave-setup) ; Make sure config files and paths, etc. are available.
  803. (unless (file-name-absolute-p idlwave-shell-command-history-file)
  804. (setq idlwave-shell-command-history-file
  805. (expand-file-name idlwave-shell-command-history-file
  806. idlwave-config-directory)))
  807. (setq comint-prompt-regexp idlwave-shell-prompt-pattern)
  808. (setq comint-process-echoes t)
  809. ;; Can not use history expansion because "!" is used for system variables.
  810. (setq comint-input-autoexpand nil)
  811. ;; (setq comint-input-ring-size 64)
  812. (set (make-local-variable 'completion-ignore-case) t)
  813. (set (make-local-variable 'comint-completion-addsuffix) '("/" . ""))
  814. (setq comint-input-ignoredups t)
  815. (setq idlwave-shell-mode-line-info nil)
  816. (setq mode-line-format
  817. '(""
  818. mode-line-modified
  819. mode-line-buffer-identification
  820. " "
  821. global-mode-string
  822. " %[("
  823. mode-name
  824. mode-line-process
  825. minor-mode-alist
  826. "%n"
  827. ")%]-"
  828. idlwave-shell-mode-line-info
  829. "---"
  830. (line-number-mode "L%l--")
  831. (column-number-mode "C%c--")
  832. (-3 . "%p")
  833. "-%-"))
  834. ;; (make-local-variable 'idlwave-shell-bp-alist)
  835. (setq idlwave-shell-halt-frame nil
  836. idlwave-shell-trace-frame nil
  837. idlwave-shell-command-output nil
  838. idlwave-shell-step-frame nil)
  839. (idlwave-shell-display-line nil)
  840. (setq idlwave-shell-calling-stack-index 0)
  841. (setq idlwave-shell-only-prompt-pattern
  842. (concat "\\`[ \t\n]*"
  843. (substring idlwave-shell-prompt-pattern 1)
  844. "[ \t\n]*\\'"))
  845. (when idlwave-shell-query-for-class
  846. (add-to-list (make-local-variable 'idlwave-determine-class-special)
  847. 'idlwave-shell-get-object-class)
  848. (setq idlwave-store-inquired-class t))
  849. ;; Make sure comint-last-input-end does not go to beginning of
  850. ;; buffer (in case there were other processes already in this buffer).
  851. (set-marker comint-last-input-end (point))
  852. (setq idlwave-idlwave_routine_info-compiled nil)
  853. (setq idlwave-shell-ready nil)
  854. (setq idlwave-shell-bp-alist nil)
  855. (idlwave-shell-update-bp-overlays) ; Throw away old overlays
  856. (setq idlwave-shell-post-command-hook nil ;clean up any old stuff
  857. idlwave-shell-sources-alist nil)
  858. (setq idlwave-shell-default-directory default-directory)
  859. (setq idlwave-shell-hide-output nil)
  860. ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
  861. ;; (make-local-hook 'kill-buffer-hook)
  862. (add-hook 'kill-buffer-hook 'idlwave-shell-kill-shell-buffer-confirm
  863. nil 'local)
  864. (add-hook 'kill-buffer-hook 'idlwave-shell-delete-temp-files nil 'local)
  865. (add-hook 'kill-emacs-hook 'idlwave-shell-delete-temp-files)
  866. (easy-menu-add idlwave-shell-mode-menu idlwave-shell-mode-map)
  867. ;; Set the optional comint variables
  868. (when idlwave-shell-comint-settings
  869. (let ((list idlwave-shell-comint-settings) entry)
  870. (while (setq entry (pop list))
  871. (set (make-local-variable (car entry)) (cdr entry)))))
  872. (unless (memq 'comint-carriage-motion
  873. (default-value 'comint-output-filter-functions))
  874. ;; Strip those pesky ctrl-m's.
  875. (add-hook 'comint-output-filter-functions
  876. (lambda (string)
  877. (when (string-match "\r" string)
  878. (let ((pmark (process-mark (get-buffer-process
  879. (current-buffer)))))
  880. (save-excursion
  881. ;; bare CR -> delete preceding line
  882. (goto-char comint-last-output-start)
  883. (while (search-forward "\r" pmark t)
  884. (delete-region (point) (line-beginning-position)))))))
  885. 'append 'local)
  886. (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m nil 'local))
  887. ;; Python-mode, bundled with many Emacs installs, quite cavalierly
  888. ;; adds this function to the global default hook. It interferes
  889. ;; with overlay-arrows.
  890. (remove-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
  891. ;; IDLWAVE syntax, and turn on abbreviations
  892. (set (make-local-variable 'comment-start) ";")
  893. (setq abbrev-mode t)
  894. ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
  895. ;; make-local-hook 'post-command-hook)
  896. (add-hook 'post-command-hook 'idlwave-command-hook nil t)
  897. ;; Read the command history?
  898. (when (and idlwave-shell-save-command-history
  899. (stringp idlwave-shell-command-history-file))
  900. (set (make-local-variable 'comint-input-ring-file-name)
  901. idlwave-shell-command-history-file)
  902. (if (file-regular-p idlwave-shell-command-history-file)
  903. (comint-read-input-ring)))
  904. ;; Turn off the non-debug toolbar buttons (open,save,etc.)
  905. (set (make-local-variable 'tool-bar-map) nil)
  906. (idlwave-shell-send-command idlwave-shell-initial-commands nil 'hide)
  907. ;; Turn off IDL's ^d interpreting, and define a system
  908. ;; variable which knows the version of IDLWAVE
  909. (idlwave-shell-send-command
  910. (format "defsysv,'!idlwave_version','%s',1" idlwave-mode-version)
  911. nil 'hide)
  912. ;; Read the paths, and save if they changed
  913. (idlwave-shell-send-command idlwave-shell-path-query
  914. 'idlwave-shell-get-path-info
  915. 'hide))
  916. (defvar idlwave-system-directory)
  917. (defun idlwave-shell-get-path-info (&optional no-write)
  918. "Get the path lists, writing to file unless NO-WRITE is set."
  919. (let* ((rpl (idlwave-shell-path-filter))
  920. (sysdir (car rpl))
  921. (dirs (cdr rpl))
  922. (old-path-alist idlwave-path-alist)
  923. (old-sys-dir idlwave-system-directory)
  924. path-changed sysdir-changed)
  925. (when sysdir
  926. (setq idlwave-system-directory sysdir)
  927. (if (setq sysdir-changed
  928. (not (string= idlwave-system-directory old-sys-dir)))
  929. (put 'idlwave-system-directory 'from-shell t)))
  930. ;; Preserve any existing flags
  931. (setq idlwave-path-alist
  932. (mapcar (lambda (x)
  933. (let ((old-entry (assoc x old-path-alist)))
  934. (if old-entry
  935. (cons x (cdr old-entry))
  936. (list x))))
  937. dirs))
  938. (if (setq path-changed (not (equal idlwave-path-alist old-path-alist)))
  939. (put 'idlwave-path-alist 'from-shell t))
  940. (if idlwave-path-alist
  941. (if (and (not no-write)
  942. idlwave-auto-write-paths
  943. (or sysdir-changed path-changed)
  944. (not idlwave-library-path))
  945. (idlwave-write-paths))
  946. ;; Fall back
  947. (setq idlwave-path-alist old-path-alist))))
  948. (if (not (fboundp 'idl-shell))
  949. (fset 'idl-shell 'idlwave-shell))
  950. (defvar idlwave-shell-idl-wframe nil
  951. "Frame for displaying the IDL shell window.")
  952. (defvar idlwave-shell-display-wframe nil
  953. "Frame for displaying the IDL source files.")
  954. (defvar idlwave-shell-calling-stack-index 0)
  955. (defvar idlwave-shell-calling-stack-routine nil)
  956. (defun idlwave-shell-source-frame ()
  957. "Return the frame to be used for source display."
  958. (if idlwave-shell-use-dedicated-frame
  959. ;; We want separate frames for source and shell
  960. (if (frame-live-p idlwave-shell-display-wframe)
  961. ;; The frame exists, so we use it.
  962. idlwave-shell-display-wframe
  963. ;; The frame does not exist. We use the current frame.
  964. ;; However, if the current is the shell frame, we make a new frame,
  965. ;; or recycle the first existing visible frame
  966. (setq idlwave-shell-display-wframe
  967. (if (eq (selected-frame) idlwave-shell-idl-wframe)
  968. (or
  969. (let ((flist (visible-frame-list))
  970. (frame (selected-frame)))
  971. (catch 'exit
  972. (while flist
  973. (if (not (eq (car flist)
  974. idlwave-shell-idl-wframe))
  975. (throw 'exit (car flist))
  976. (setq flist (cdr flist))))))
  977. (make-frame))
  978. (selected-frame))))))
  979. (defun idlwave-shell-shell-frame ()
  980. "Return the frame to be used for the shell buffer."
  981. (if idlwave-shell-use-dedicated-frame
  982. ;; We want a dedicated frame
  983. (if (frame-live-p idlwave-shell-idl-wframe)
  984. ;; It does exist, so we use it.
  985. idlwave-shell-idl-wframe
  986. ;; It does not exist. Check if we have a source frame.
  987. (if (not (frame-live-p idlwave-shell-display-wframe))
  988. ;; We do not have a source frame, so we use this one.
  989. (setq idlwave-shell-display-wframe (selected-frame)))
  990. ;; Return a new frame
  991. (setq idlwave-shell-idl-wframe
  992. (make-frame idlwave-shell-frame-parameters)))))
  993. ;;;###autoload
  994. (defun idlwave-shell (&optional arg quick)
  995. "Run an inferior IDL, with I/O through buffer `(idlwave-shell-buffer)'.
  996. If buffer exists but shell process is not running, start new IDL.
  997. If buffer exists and shell process is running, just switch to the buffer.
  998. When called with a prefix ARG, or when `idlwave-shell-use-dedicated-frame'
  999. is non-nil, the shell buffer and the source buffers will be in
  1000. separate frames.
  1001. The command to run comes from variable `idlwave-shell-explicit-file-name',
  1002. with options taken from `idlwave-shell-command-line-options'.
  1003. The buffer is put in `idlwave-shell-mode', providing commands for sending
  1004. input and controlling the IDL job. See help on `idlwave-shell-mode'.
  1005. See also the variable `idlwave-shell-prompt-pattern'.
  1006. \(Type \\[describe-mode] in the shell buffer for a list of commands.)"
  1007. (interactive "P")
  1008. (if (eq arg 'quick)
  1009. (progn
  1010. (let ((idlwave-shell-use-dedicated-frame nil))
  1011. (idlwave-shell nil)
  1012. (delete-other-windows))
  1013. (and idlwave-shell-use-dedicated-frame
  1014. (setq idlwave-shell-idl-wframe (selected-frame)))
  1015. (add-hook 'idlwave-shell-sentinel-hook
  1016. 'save-buffers-kill-emacs t))
  1017. ;; A non-nil arg means, we want a dedicated frame. This will last
  1018. ;; for the current editing session.
  1019. (if arg (setq idlwave-shell-use-dedicated-frame t))
  1020. (if (equal arg '(16)) (setq idlwave-shell-use-dedicated-frame nil))
  1021. ;; Check if the process still exists. If not, create it.
  1022. (unless (comint-check-proc (idlwave-shell-buffer))
  1023. (let* ((prg (or idlwave-shell-explicit-file-name "idl"))
  1024. (buf (apply 'make-comint
  1025. idlwave-shell-process-name prg nil
  1026. (if (stringp idlwave-shell-command-line-options)
  1027. (idlwave-split-string
  1028. idlwave-shell-command-line-options)
  1029. idlwave-shell-command-line-options)))
  1030. (process (get-buffer-process buf)))
  1031. (setq idlwave-idlwave_routine_info-compiled nil)
  1032. (set-process-filter process 'idlwave-shell-filter)
  1033. (set-process-sentinel process 'idlwave-shell-sentinel)
  1034. (set-buffer buf)
  1035. (idlwave-shell-mode)))
  1036. (let ((window (idlwave-display-buffer (idlwave-shell-buffer) nil
  1037. (idlwave-shell-shell-frame)))
  1038. (current-window (selected-window)))
  1039. (select-window window)
  1040. (goto-char (point-max))
  1041. (if idlwave-shell-use-dedicated-window
  1042. (set-window-dedicated-p window t))
  1043. (select-window current-window)
  1044. (if idlwave-shell-ready
  1045. (raise-frame (window-frame window)))
  1046. (if (eq (selected-frame) (window-frame window))
  1047. (select-window window))))
  1048. ;; Save the paths at the end, if they are from the Shell and new.
  1049. (add-hook 'idlwave-shell-sentinel-hook
  1050. (lambda ()
  1051. (if (and
  1052. idlwave-auto-write-paths
  1053. idlwave-path-alist
  1054. (not idlwave-library-path)
  1055. (get 'idlwave-path-alist 'from-shell))
  1056. (idlwave-write-paths)))))
  1057. (defun idlwave-shell-recenter-shell-window (&optional arg)
  1058. "Run `idlwave-shell', but make sure the current window stays selected."
  1059. (interactive "P")
  1060. (let ((window (selected-window)))
  1061. (idlwave-shell arg)
  1062. (select-window window)))
  1063. (defun idlwave-shell-hide-p (type &optional list)
  1064. "Whether to hide this type of command.
  1065. Return either nil or 'hide."
  1066. (let ((list (or list idlwave-shell-show-commands)))
  1067. (if (listp list)
  1068. (if (not (memq type list)) 'hide))))
  1069. (defun idlwave-shell-add-or-remove-show (type)
  1070. "Add or remove a show command from the list."
  1071. (if (listp idlwave-shell-show-commands)
  1072. (setq idlwave-shell-show-commands
  1073. (if (memq type idlwave-shell-show-commands)
  1074. (delq type idlwave-shell-show-commands)
  1075. (add-to-list'idlwave-shell-show-commands type)))
  1076. (setq idlwave-shell-show-commands (list type))))
  1077. (defun idlwave-shell-send-command (&optional cmd pcmd hide preempt
  1078. show-if-error)
  1079. "Send a command to IDL process.
  1080. \(CMD PCMD HIDE\) are placed at the end of `idlwave-shell-pending-commands'.
  1081. If IDL is ready the first command in `idlwave-shell-pending-commands',
  1082. CMD, is sent to the IDL process.
  1083. If optional second argument PCMD is non-nil it will be placed on
  1084. `idlwave-shell-post-command-hook' when CMD is executed.
  1085. If the optional third argument HIDE is non-nil, then hide output from
  1086. CMD, unless it is the symbol 'mostly, in which case only output
  1087. beginning with \"%\" is hidden, and all other output (i.e., the
  1088. results of a PRINT command), is shown. This helps with, e.g.,
  1089. stepping through code with output.
  1090. If optional fourth argument PREEMPT is non-nil CMD is put at front of
  1091. `idlwave-shell-pending-commands'. If PREEMPT is 'wait, wait for all
  1092. output to complete and the next prompt to arrive before returning
  1093. \(useful if you need an answer now\). IDL is considered ready if the
  1094. prompt is present and if `idlwave-shell-ready' is non-nil.
  1095. If SHOW-IF-ERROR is non-nil, show the output if it contains an error
  1096. message, independent of what HIDE is set to."
  1097. ; (setq hide nil) ; FIXME: turn this on for debugging only
  1098. ; (if (null cmd)
  1099. ; (progn
  1100. ; (message "SENDING Pending commands: %s"
  1101. ; (prin1-to-string idlwave-shell-pending-commands)))
  1102. ; (message "SENDING %s|||%s" cmd pcmd))
  1103. (if (and (symbolp idlwave-shell-show-commands)
  1104. (eq idlwave-shell-show-commands 'everything))
  1105. (setq hide nil))
  1106. (let ((save-buffer (current-buffer))
  1107. buf proc)
  1108. ;; Get or make the buffer and its process
  1109. (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
  1110. (not (setq proc (get-buffer-process buf))))
  1111. (if (not idlwave-shell-automatic-start)
  1112. (error "%s"
  1113. (substitute-command-keys
  1114. "You need to first start an IDL shell with \\[idlwave-shell]"))
  1115. (idlwave-shell-recenter-shell-window)
  1116. (setq buf (get-buffer (idlwave-shell-buffer)))
  1117. (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
  1118. (not (setq proc (get-buffer-process buf))))
  1119. ;; Still nothing
  1120. (error "Problem with autostarting IDL shell"))))
  1121. (when (or cmd idlwave-shell-pending-commands)
  1122. (set-buffer buf)
  1123. ;; To make this easy, always push CMD onto pending commands
  1124. (if cmd
  1125. (setq idlwave-shell-pending-commands
  1126. (if preempt
  1127. ;; Put at front.
  1128. (append (list (list cmd pcmd hide show-if-error))
  1129. idlwave-shell-pending-commands)
  1130. ;; Put at end.
  1131. (append idlwave-shell-pending-commands
  1132. (list (list cmd pcmd hide show-if-error))))))
  1133. ;; Check if IDL ready
  1134. (let ((save-point (point-marker)))
  1135. (goto-char (process-mark proc))
  1136. (if (and idlwave-shell-ready
  1137. ;; Check for IDL prompt
  1138. (prog2
  1139. (forward-line 0)
  1140. ;; (beginning-of-line) ; Changed for Emacs 21
  1141. (looking-at idlwave-shell-prompt-pattern)
  1142. (goto-char (process-mark proc))))
  1143. ;; IDL ready for command, execute it
  1144. (let* ((lcmd (car idlwave-shell-pending-commands))
  1145. (cmd (car lcmd))
  1146. (pcmd (nth 1 lcmd))
  1147. (hide (nth 2 lcmd))
  1148. (show-if-error (nth 3 lcmd)))
  1149. ;; If this is an executive command, reset the stack pointer
  1150. (if (eq (string-to-char cmd) ?.)
  1151. (setq idlwave-shell-calling-stack-index 0))
  1152. ;; Set post-command
  1153. (setq idlwave-shell-post-command-hook pcmd)
  1154. ;; Output hiding
  1155. (setq idlwave-shell-hide-output hide)
  1156. ;;Showing errors
  1157. (setq idlwave-shell-show-if-error show-if-error)
  1158. ;; Pop command
  1159. (setq idlwave-shell-pending-commands
  1160. (cdr idlwave-shell-pending-commands))
  1161. ;; Send command for execution
  1162. (set-marker comint-last-input-start (point))
  1163. (set-marker comint-last-input-end (point))
  1164. (comint-simple-send proc cmd)
  1165. (setq idlwave-shell-ready nil)
  1166. (if (equal preempt 'wait) ; Get all the output at once
  1167. (while (not idlwave-shell-ready)
  1168. (when (not (accept-process-output proc 6)) ; long wait
  1169. (setq idlwave-shell-pending-commands nil)
  1170. (error "Process timed out"))))))
  1171. (goto-char save-point))
  1172. (set-buffer save-buffer))))
  1173. (defun idlwave-shell-send-char (c &optional error)
  1174. "Send one character to the shell, without a newline."
  1175. (interactive "cChar to send to IDL: \np")
  1176. (let ((errf (if error 'error 'message))
  1177. buf proc)
  1178. (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
  1179. (not (setq proc (get-buffer-process buf))))
  1180. (funcall errf "Shell is not running"))
  1181. (if (equal c ?\C-g)
  1182. (funcall errf "Abort")
  1183. (comint-send-string proc (char-to-string c)))))
  1184. (defvar idlwave-shell-char-mode-active)
  1185. (defun idlwave-shell-input-mode-magic (string)
  1186. "Check STRING for magic words and toggle character input mode.
  1187. See also the variable `idlwave-shell-input-mode-spells'."
  1188. (cond
  1189. ((string-match (car idlwave-shell-input-mode-spells) string)
  1190. (call-interactively 'idlwave-shell-send-char))
  1191. ((and (boundp 'idlwave-shell-char-mode-active)
  1192. (string-match (nth 2 idlwave-shell-input-mode-spells) string))
  1193. (setq idlwave-shell-char-mode-active 'exit))
  1194. ((string-match (nth 1 idlwave-shell-input-mode-spells) string)
  1195. ;; Set a timer which will soon start the character loop
  1196. (if (fboundp 'start-itimer)
  1197. (start-itimer "IDLWAVE Char Mode" 'idlwave-shell-char-mode-loop 0.5
  1198. nil nil t 'no-error)
  1199. (run-at-time 0.5 nil 'idlwave-shell-char-mode-loop 'no-error)))))
  1200. (defvar keyboard-quit)
  1201. (defun idlwave-shell-char-mode-loop (&optional no-error)
  1202. "Enter a loop which accepts single characters and sends them to IDL.
  1203. Characters are sent one by one, without newlines. The loop is blocking
  1204. and intercepts all input events to Emacs. You can use this command
  1205. to interact with the IDL command GET_KBRD.
  1206. The loop can be aborted by typing `C-g'. The loop also exits automatically
  1207. when the IDL prompt gets displayed again after the current IDL command."
  1208. (interactive)
  1209. ;; First check if there is a shell waiting for input
  1210. (let ((idlwave-shell-char-mode-active t)
  1211. (errf (if no-error 'message 'error))
  1212. buf proc c)
  1213. (if (or (not (setq buf (get-buffer (idlwave-shell-buffer))))
  1214. (not (setq proc (get-buffer-process buf))))
  1215. (funcall errf "Shell is not running"))
  1216. (if idlwave-shell-ready
  1217. (funcall errf "No IDL program seems to be waiting for input"))
  1218. ;; OK, start the loop
  1219. (message "Character mode on: Sending single chars (`C-g' to exit)")
  1220. (message
  1221. (catch 'exit
  1222. (while t
  1223. ;; Wait for input
  1224. ;; FIXME: Is it too dangerous to inhibit quit here?
  1225. (let ((inhibit-quit t))
  1226. ;; We wait and check frequently if we should abort
  1227. (while (sit-for 0.3)
  1228. (and idlwave-shell-ready
  1229. (throw 'exit "Character mode off (prompt displayed)"))
  1230. (and (eq idlwave-shell-char-mode-active 'exit)
  1231. (throw 'exit "Character mode off (closing spell incantation)")))
  1232. ;; Interpret input as a character - ignore non-char input
  1233. (condition-case nil
  1234. (setq c (read-char))
  1235. (error (ding) (throw 'exit "Character mode off")))
  1236. (cond
  1237. ((null c) ; Non-char event: ignore
  1238. (ding))
  1239. ((equal c ?\C-g) ; Abort the loop
  1240. (setq keyboard-quit nil)
  1241. (ding)
  1242. (throw 'exit "Character mode off (keyboard quit)"))
  1243. (t ; Send the character and continue the loop
  1244. (comint-send-string proc (char-to-string c))))
  1245. (and (eq idlwave-shell-char-mode-active 'exit)
  1246. (throw 'exit "Single char loop exited"))))))))
  1247. (defun idlwave-shell-move-or-history (up &optional arg)
  1248. "When in last line of process buffer, do `comint-previous-input'.
  1249. Otherwise just move the line. Move down unless UP is non-nil."
  1250. (let* ((proc-pos (marker-position
  1251. (process-mark (get-buffer-process (current-buffer)))))
  1252. (arg (or arg 1))
  1253. (arg (if up arg (- arg))))
  1254. (if (eq t idlwave-shell-arrows-do-history) (goto-char proc-pos))
  1255. (if (and idlwave-shell-arrows-do-history
  1256. (>= (1+ (point-at-eol)) proc-pos))
  1257. (comint-previous-input arg)
  1258. (forward-line (- arg)))))
  1259. (defun idlwave-shell-up-or-history (&optional arg)
  1260. "When in last line of process buffer, move to previous input.
  1261. Otherwise just go up one line."
  1262. (interactive "p")
  1263. (idlwave-shell-move-or-history t arg))
  1264. (defun idlwave-shell-down-or-history (&optional arg)
  1265. "When in last line of process buffer, move to next input.
  1266. Otherwise just go down one line."
  1267. (interactive "p")
  1268. (idlwave-shell-move-or-history nil arg))
  1269. ;; Newer versions of comint.el changed the name of comint-filter to
  1270. ;; comint-output-filter.
  1271. (defun idlwave-shell-comint-filter (process string) nil)
  1272. (if (fboundp 'comint-output-filter)
  1273. (fset 'idlwave-shell-comint-filter (symbol-function 'comint-output-filter))
  1274. (fset 'idlwave-shell-comint-filter (symbol-function 'comint-filter)))
  1275. (defun idlwave-shell-is-running ()
  1276. "Return t if the shell process is running."
  1277. (eq (process-status idlwave-shell-process-name) 'run))
  1278. (defun idlwave-shell-filter-hidden-output (output)
  1279. "Filter hidden output, leaving the good stuff.
  1280. Remove everything to the first newline, and all lines with % in front
  1281. of them, with optional follow-on lines starting with two spaces. This
  1282. works well enough, since any print output typically arrives before
  1283. error messages, etc."
  1284. (setq output (substring output (string-match "\n" output)))
  1285. (while (string-match "\\(\n\\|\\`\\)%.*\\(\n .*\\)*" output)
  1286. (setq output (replace-match "" nil t output)))
  1287. (unless
  1288. (string-match idlwave-shell-only-prompt-pattern output)
  1289. output))
  1290. (defvar idlwave-shell-hidden-output-buffer " *idlwave-shell-hidden-output*"
  1291. "Buffer containing hidden output from IDL commands.")
  1292. (defvar idlwave-shell-current-state nil)
  1293. (defun idlwave-shell-filter (proc string)
  1294. "Watch for IDL prompt and filter incoming text.
  1295. When the IDL prompt is received executes `idlwave-shell-post-command-hook'
  1296. and then calls `idlwave-shell-send-command' for any pending commands."
  1297. ;; We no longer do the cleanup here - this is done by the process sentinel
  1298. (if (eq (process-status idlwave-shell-process-name) 'run)
  1299. ;; OK, process is still running, so we can use it.
  1300. (let ((data (match-data)) p full-output)
  1301. (unwind-protect
  1302. (progn
  1303. ;; Ring the bell if necessary
  1304. (while (setq p (string-match "\C-G" string))
  1305. (ding)
  1306. (aset string p ?\C-j ))
  1307. (if idlwave-shell-hide-output
  1308. (save-excursion
  1309. (while (setq p (string-match "\C-M" string))
  1310. (aset string p ?\ ))
  1311. (set-buffer
  1312. (get-buffer-create idlwave-shell-hidden-output-buffer))
  1313. (goto-char (point-max))
  1314. (insert string))
  1315. (idlwave-shell-comint-filter proc string))
  1316. ;; Watch for magic - need to accumulate the current line
  1317. ;; since it may not be sent all at once.
  1318. (if (string-match "\n" string)
  1319. (progn
  1320. (if idlwave-shell-use-input-mode-magic
  1321. (idlwave-shell-input-mode-magic
  1322. (concat idlwave-shell-accumulation string)))
  1323. (setq idlwave-shell-accumulation
  1324. (substring string
  1325. (progn (string-match "\\(.*[\n\r]+\\)*"
  1326. string)
  1327. (match-end 0)))))
  1328. (setq idlwave-shell-accumulation
  1329. (concat idlwave-shell-accumulation string)))
  1330. ;; ;; Test/Debug code
  1331. ;;(with-current-buffer
  1332. ;; (get-buffer-create "*idlwave-shell-output*")
  1333. ;; (goto-char (point-max))
  1334. ;; (insert "\nReceived STRING\n===>\n" string "\n<====\n"))
  1335. ;; Check for prompt in current accumulating output
  1336. (when (setq idlwave-shell-ready
  1337. (string-match idlwave-shell-prompt-pattern
  1338. idlwave-shell-accumulation))
  1339. ;; Gather the command output
  1340. (if idlwave-shell-hide-output
  1341. (with-current-buffer idlwave-shell-hidden-output-buffer
  1342. (setq full-output (buffer-string))
  1343. (goto-char (point-max))
  1344. (re-search-backward idlwave-shell-prompt-pattern nil t)
  1345. (goto-char (match-end 0))
  1346. (setq idlwave-shell-command-output
  1347. (buffer-substring-no-properties
  1348. (point-min) (point)))
  1349. (delete-region (point-min) (point)))
  1350. (setq idlwave-shell-command-output
  1351. (with-current-buffer (process-buffer proc)
  1352. (buffer-substring-no-properties
  1353. (save-excursion
  1354. (goto-char (process-mark proc))
  1355. (forward-line 0) ; Emacs 21 (beginning-of-line nil)
  1356. (point))
  1357. comint-last-input-end))))
  1358. ;; Scan for state and do post commands - bracket
  1359. ;; them with idlwave-shell-ready=nil since they may
  1360. ;; call idlwave-shell-send-command themselves.
  1361. (let ((idlwave-shell-ready nil))
  1362. (idlwave-shell-scan-for-state)
  1363. ;; Show the output in the shell if it contains an error
  1364. (if idlwave-shell-hide-output
  1365. (if (and idlwave-shell-show-if-error
  1366. (eq idlwave-shell-current-state 'error))
  1367. (idlwave-shell-comint-filter proc full-output)
  1368. ;; If it's only *mostly* hidden, filter % lines,
  1369. ;; and show anything that remains
  1370. (if (eq idlwave-shell-hide-output 'mostly)
  1371. (let ((filtered
  1372. (idlwave-shell-filter-hidden-output
  1373. full-output)))
  1374. (if filtered
  1375. (idlwave-shell-comint-filter
  1376. proc filtered))))))
  1377. ;; Call the post-command hook
  1378. (if (listp idlwave-shell-post-command-hook)
  1379. (progn
  1380. ;;(message "Calling list")
  1381. ;;(prin1 idlwave-shell-post-command-hook)
  1382. (eval idlwave-shell-post-command-hook))
  1383. ;;(message "Calling command function")
  1384. (funcall idlwave-shell-post-command-hook))
  1385. ;; Reset to default state for next command.
  1386. ;; Also we do not want to find this prompt again.
  1387. (setq idlwave-shell-accumulation nil
  1388. idlwave-shell-command-output nil
  1389. idlwave-shell-post-command-hook nil
  1390. idlwave-shell-hide-output nil
  1391. idlwave-shell-show-if-error nil))
  1392. ;; Done with post command. Do pending command if
  1393. ;; any.
  1394. (idlwave-shell-send-command)))
  1395. (store-match-data data)))))
  1396. (defun idlwave-shell-sentinel (process event)
  1397. "The sentinel function for the IDLWAVE shell process."
  1398. (let* ((buf (idlwave-shell-buffer))
  1399. (win (get-buffer-window buf)))
  1400. (when (get-buffer buf)
  1401. (with-current-buffer (idlwave-shell-buffer)
  1402. (goto-char (point-max))
  1403. (insert (format "\n\n Process %s %s" process event))
  1404. (if (and idlwave-shell-save-command-history
  1405. (stringp idlwave-shell-command-history-file))
  1406. (condition-case nil
  1407. (comint-write-input-ring)
  1408. (error nil)))))
  1409. (when (and (> (length (frame-list)) 1)
  1410. (frame-live-p idlwave-shell-idl-wframe))
  1411. (delete-frame idlwave-shell-idl-wframe)
  1412. (setq idlwave-shell-idl-wframe nil
  1413. idlwave-shell-display-wframe nil))
  1414. (when (and (window-live-p win)
  1415. (not (one-window-p 'nomini)))
  1416. (delete-window win))
  1417. (idlwave-shell-cleanup)
  1418. ;; Run the hook, if possible in the shell buffer.
  1419. (if (get-buffer buf)
  1420. (with-current-buffer buf
  1421. (run-hooks 'idlwave-shell-sentinel-hook))
  1422. (run-hooks 'idlwave-shell-sentinel-hook))))
  1423. (defvar idlwave-shell-error-buffer " *idlwave-shell-errors*"
  1424. "Buffer containing syntax errors from IDL compilations.")
  1425. ;; FIXME: the following two variables do not currently allow line breaks
  1426. ;; in module and file names. I am not sure if it will be necessary to
  1427. ;; change this. Currently it seems to work the way it is.
  1428. (defvar idlwave-shell-syntax-error
  1429. "^% Syntax error.\\s-*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
  1430. "A regular expression to match an IDL syntax error.
  1431. The first pair matches the file name, the second pair matches the line
  1432. number.")
  1433. (defvar idlwave-shell-other-error
  1434. "^% .*\n\\s-*At:\\s-*\\(.*\\),\\s-*Line\\s-*\\(.*\\)"
  1435. "A regular expression to match any IDL error.")
  1436. (defvar idlwave-shell-halting-error
  1437. "^% .*\n\\([^%].*\n\\)*% Execution halted at:\\(\\s-*\\S-+\\s-*[0-9]+\\s-*.*\\)\n"
  1438. "A regular expression to match errors which halt execution.")
  1439. (defvar idlwave-shell-cant-continue-error
  1440. "^% Can't continue from this point.\n"
  1441. "A regular expression to match errors stepping errors.")
  1442. (defvar idlwave-shell-file-line-message
  1443. (concat
  1444. "\\(" ; program name group (1)
  1445. "\\$MAIN\\$\\|" ; main level routine
  1446. "\\<[a-zA-Z][a-zA-Z0-9_$:]*" ; start with a letter followed by [..]
  1447. "\\([ \t]*\n[ \t]*[a-zA-Z0-9_$:]+\\)*"; continuation lines program name (2)
  1448. "\\)" ; end program name group (1)
  1449. "[ \t\n]+" ; white space
  1450. "\\(" ; line number group (3)
  1451. "[0-9]+" ; the line number (the fix point)
  1452. "\\([ \t]*\n[ \t]*[0-9]+\\)*" ; continuation lines number (4)
  1453. "\\)" ; end line number group (3)
  1454. "[ \t\n]+" ; white space
  1455. "\\(" ; file name group (5)
  1456. "[^ \t\n]+" ; file names can contain any non-white
  1457. "\\([ \t]*\n[ \t]*[^ \t\n]+\\)*" ; continuation lines file name (6)
  1458. "\\)" ; end line number group (5)
  1459. )
  1460. "*A regular expression to parse out the file name and line number.
  1461. The 1st group should match the subroutine name.
  1462. The 3rd group is the line number.
  1463. The 5th group is the file name.
  1464. All parts may contain linebreaks surrounded by spaces. This is important
  1465. in IDL5 which inserts random linebreaks in long module and file names.")
  1466. (defvar idlwave-shell-electric-debug-mode) ; defined by easy-mmode
  1467. (defun idlwave-shell-scan-for-state ()
  1468. "Scan for state info.
  1469. Looks for messages in output from last IDL command indicating where
  1470. IDL has stopped. The types of messages we are interested in are
  1471. execution halted, stepped, breakpoint, interrupted at and trace
  1472. messages. For breakpoint messages process any attached count or
  1473. command parameters. Update the stop line if a message is found.
  1474. The variable `idlwave-shell-current-state' is set to 'error, 'halt,
  1475. or 'breakpoint, which describes the status, or nil for none of
  1476. the above."
  1477. (let (trace)
  1478. (cond
  1479. ;; Make sure we have output
  1480. ((not idlwave-shell-command-output))
  1481. ;; First Priority: Syntax and other errors
  1482. ((or
  1483. (string-match idlwave-shell-syntax-error
  1484. idlwave-shell-command-output)
  1485. (string-match idlwave-shell-other-error
  1486. idlwave-shell-command-output))
  1487. (with-current-buffer
  1488. (get-buffer-create idlwave-shell-error-buffer)
  1489. (erase-buffer)
  1490. (insert idlwave-shell-command-output)
  1491. (goto-char (point-min))
  1492. (setq idlwave-shell-error-last (point)))
  1493. (setq idlwave-shell-current-state 'error)
  1494. (idlwave-shell-goto-next-error))
  1495. ;; Second Priority: Halting errors
  1496. ((string-match idlwave-shell-halting-error
  1497. idlwave-shell-command-output)
  1498. ;; Grab the file and line state info.
  1499. (setq idlwave-shell-calling-stack-index 0)
  1500. (setq idlwave-shell-halt-frame
  1501. (idlwave-shell-parse-line
  1502. (substring idlwave-shell-command-output
  1503. (match-beginning 2)))
  1504. idlwave-shell-current-state 'error)
  1505. (idlwave-shell-display-line (idlwave-shell-pc-frame)))
  1506. ;; Third Priority: Various types of innocuous HALT and
  1507. ;; TRACEBACK messages.
  1508. ((or (setq trace (string-match idlwave-shell-trace-message-re
  1509. idlwave-shell-command-output))
  1510. (string-match idlwave-shell-halt-messages-re
  1511. idlwave-shell-command-output))
  1512. ;; Grab the file and line state info.
  1513. (setq idlwave-shell-calling-stack-index 0)
  1514. (setq idlwave-shell-halt-frame
  1515. (idlwave-shell-parse-line
  1516. (substring idlwave-shell-command-output (match-end 0))))
  1517. (setq idlwave-shell-current-state 'halt)
  1518. ;; Don't debug trace messages
  1519. (idlwave-shell-display-line
  1520. (idlwave-shell-pc-frame) nil
  1521. (if trace 'disable
  1522. (if idlwave-shell-electric-debug-mode 'force))))
  1523. ;; Fourth Priority: Breakpoints
  1524. ((string-match idlwave-shell-break-message
  1525. idlwave-shell-command-output)
  1526. (setq idlwave-shell-calling-stack-index 0)
  1527. (setq idlwave-shell-halt-frame
  1528. (idlwave-shell-parse-line
  1529. (substring idlwave-shell-command-output (match-end 0))))
  1530. ;; We used to count hits on breakpoints
  1531. ;; this is no longer supported since IDL breakpoints
  1532. ;; have learned counting.
  1533. ;; Do breakpoint command processing
  1534. (let ((bp (assoc
  1535. (list
  1536. (nth 0 idlwave-shell-halt-frame)
  1537. (nth 1 idlwave-shell-halt-frame))
  1538. idlwave-shell-bp-alist)))
  1539. ;(message "Scanning with %s" bp)
  1540. (if bp
  1541. (let ((cmd (idlwave-shell-bp-get bp 'cmd)))
  1542. (if cmd ;; Execute any breakpoint command
  1543. (if (listp cmd) (eval cmd) (funcall cmd))))
  1544. ;; A breakpoint that we did not know about - perhaps it was
  1545. ;; set by the user... Let's update our list.
  1546. (idlwave-shell-bp-query)))
  1547. (setq idlwave-shell-current-state 'breakpoint)
  1548. (idlwave-shell-display-line (idlwave-shell-pc-frame)))
  1549. ;; Last Priority: Can't Step errors
  1550. ((string-match idlwave-shell-cant-continue-error
  1551. idlwave-shell-command-output)
  1552. (setq idlwave-shell-current-state 'breakpoint))
  1553. ;; Otherwise, no particular state
  1554. (t (setq idlwave-shell-current-state nil)))))
  1555. (defun idlwave-shell-parse-line (string &optional skip-main)
  1556. "Parse IDL message for the subroutine, file name and line number."
  1557. ;We need to work hard here to remove the stupid line breaks inserted by
  1558. ;IDL5. These line breaks can be right in the middle of procedure
  1559. ;or file names.
  1560. ;It is very difficult to come up with a robust solution. This one seems
  1561. ;to be pretty good though.
  1562. ;
  1563. ;Here is in what ways it improves over the previous solution:
  1564. ;
  1565. ;1. The procedure name can be split and will be restored.
  1566. ;2. The number can be split. I have never seen this, but who knows.
  1567. ;3. We do not require the `.pro' extension for files.
  1568. ;
  1569. ;This function can still break when the file name ends on an end line
  1570. ;and the message line contains an additional line with garbage. Then
  1571. ;the first part of that garbage will be added to the file name.
  1572. ;However, the function checks the existence of the files with and
  1573. ;without this last part - thus the function only breaks if file name
  1574. ;plus garbage match an existing regular file. This is hopefully very
  1575. ;unlikely.
  1576. ;
  1577. ;If optional arg SKIP-MAIN is non-nil, don't parse $MAIN$ routine stop
  1578. ;statements.
  1579. (let (number procedure file)
  1580. (when (and (not (if skip-main (string-match ":\\s-*\\$MAIN" string)))
  1581. (string-match idlwave-shell-file-line-message string))
  1582. (setq procedure (match-string 1 string)
  1583. number (match-string 3 string)
  1584. file (match-string 5 string))
  1585. ;; Repair the strings
  1586. (setq procedure (idlwave-shell-repair-string procedure))
  1587. (setq number (idlwave-shell-repair-string number))
  1588. (setq file (idlwave-shell-repair-file-name file))
  1589. ;; If we have a file, return the frame list
  1590. (if file
  1591. (list (idlwave-shell-file-name file)
  1592. (string-to-number number)
  1593. procedure)
  1594. ;; No success finding a file
  1595. nil))))
  1596. (defun idlwave-shell-repair-string (string)
  1597. "Repair a string by taking out all linebreaks. This is destructive!"
  1598. (while (string-match "[ \t]*\n[ \t]*" string)
  1599. (setq string (replace-match "" t t string)))
  1600. string)
  1601. (defun idlwave-shell-repair-file-name (file)
  1602. "Repair a file name string by taking out all linebreaks.
  1603. The last line of STRING may be garbage - we check which one makes a valid
  1604. file name."
  1605. (let ((file1 "") (file2 "") (start 0))
  1606. ;; We scan no further than to the next "^%" line
  1607. (if (string-match "^%" file)
  1608. (setq file (substring file 0 (match-beginning 0))))
  1609. ;; Take out the line breaks
  1610. (while (string-match "[ \t]*\n[ \t]*" file start)
  1611. (setq file1 (concat file1 (substring file start (match-beginning 0)))
  1612. start (match-end 0)))
  1613. (setq file2 (concat file1 (substring file start)))
  1614. (cond
  1615. ((file-regular-p file2) file2)
  1616. ((file-regular-p file1) file1)
  1617. ;; If we cannot verify the existence of the file, we return the shorter
  1618. ;; name. The idea behind this is that this may be a relative file name
  1619. ;; and our idea about the current working directory may be wrong.
  1620. ;; If it is a relative file name, it hopefully is short.
  1621. ((not (string= "" file1)) file1)
  1622. ((not (string= "" file2)) file2)
  1623. (t nil))))
  1624. (defun idlwave-shell-cleanup ()
  1625. "Do necessary cleanup for a terminated IDL process."
  1626. (setq idlwave-shell-step-frame nil
  1627. idlwave-shell-halt-frame nil
  1628. idlwave-shell-pending-commands nil
  1629. idlwave-shell-command-line-to-execute nil
  1630. idlwave-shell-bp-alist nil
  1631. idlwave-shell-calling-stack-index 0
  1632. idlwave-idlwave_routine_info-compiled nil)
  1633. (idlwave-shell-delete-temp-files)
  1634. (idlwave-shell-display-line nil)
  1635. (idlwave-shell-update-bp-overlays) ; kill old overlays
  1636. (idlwave-shell-kill-buffer idlwave-shell-hidden-output-buffer)
  1637. (idlwave-shell-kill-buffer idlwave-shell-bp-buffer)
  1638. (idlwave-shell-kill-buffer idlwave-shell-error-buffer)
  1639. ;; (idlwave-shell-kill-buffer (idlwave-shell-buffer))
  1640. (and (get-buffer (idlwave-shell-buffer))
  1641. (bury-buffer (get-buffer (idlwave-shell-buffer))))
  1642. (run-hooks 'idlwave-shell-cleanup-hook))
  1643. (defun idlwave-shell-kill-buffer (buf)
  1644. "Kill buffer BUF if it exists."
  1645. (if (setq buf (get-buffer buf))
  1646. (kill-buffer buf)))
  1647. (defun idlwave-shell-kill-shell-buffer-confirm ()
  1648. (when (idlwave-shell-is-running)
  1649. (ding)
  1650. (unless (y-or-n-p "IDL shell is running. Are you sure you want to kill the buffer? ")
  1651. (error "Abort"))
  1652. (message "Killing buffer *idl* and the associated process")))
  1653. (defun idlwave-shell-window (n)
  1654. "Issue a `window,N' command to IDL, with special window size.
  1655. The size is given by `idlwave-shell-graphics-window-size'."
  1656. (interactive "P")
  1657. (let ((n (if n (prefix-numeric-value n) 0)))
  1658. (idlwave-shell-send-command
  1659. (apply 'format "window,%d,xs=%d,ys=%d"
  1660. n idlwave-shell-graphics-window-size)
  1661. nil (idlwave-shell-hide-p 'misc) nil t)))
  1662. (defun idlwave-shell-resync-dirs ()
  1663. "Resync the buffer's idea of the current directory.
  1664. This command queries IDL with the command bound to
  1665. `idlwave-shell-dirstack-query', reads the output for the new
  1666. directory."
  1667. (interactive)
  1668. (idlwave-shell-send-command idlwave-shell-dirstack-query
  1669. 'idlwave-shell-filter-directory
  1670. 'hide 'wait))
  1671. (defun idlwave-shell-retall (&optional arg)
  1672. "Return from the entire calling stack.
  1673. Also get rid of widget events in the queue."
  1674. (interactive "P")
  1675. (save-selected-window
  1676. ;;if (widget_info(/MANAGED))[0] gt 0 then for i=0,n_elements(widget_info(/MANAGED))-1 do widget_control,(widget_info(/MANAGED))[i],/clear_events &
  1677. (idlwave-shell-send-command "retall" nil
  1678. (if (idlwave-shell-hide-p 'misc) 'mostly)
  1679. nil t)
  1680. (idlwave-shell-display-line nil)))
  1681. (defun idlwave-shell-closeall (&optional arg)
  1682. "Close all open files."
  1683. (interactive "P")
  1684. (idlwave-shell-send-command "close,/all" nil
  1685. (idlwave-shell-hide-p 'misc) nil t))
  1686. (defun idlwave-shell-quit (&optional arg)
  1687. "Exit the IDL process after confirmation.
  1688. With prefix ARG, exit without confirmation."
  1689. (interactive "P")
  1690. (if (not (idlwave-shell-is-running))
  1691. (error "Shell is not running")
  1692. (if (or arg (y-or-n-p "Exit the IDLWAVE Shell? "))
  1693. (condition-case nil
  1694. (idlwave-shell-send-command "exit")
  1695. (error nil)))))
  1696. (defun idlwave-shell-reset (&optional hidden)
  1697. "Reset IDL. Return to main level and destroy the leftover variables.
  1698. This issues the following commands:
  1699. RETALL
  1700. WIDGET_CONTROL,/RESET
  1701. CLOSE, /ALL
  1702. HEAP_GC, /VERBOSE"
  1703. ;; OBJ_DESTROY, OBJ_VALID() FIXME: should this be added?
  1704. (interactive "P")
  1705. (when (or idlwave-shell-reset-no-prompt
  1706. (yes-or-no-p "Really Reset IDL and discard current session? "))
  1707. (message "Resetting IDL")
  1708. (setq idlwave-shell-calling-stack-index 0)
  1709. ;; Give widget exit handlers a chance
  1710. (idlwave-shell-send-command "retall" nil hidden)
  1711. (idlwave-shell-send-command "widget_control,/reset" nil hidden)
  1712. (idlwave-shell-send-command "close,/all" nil hidden)
  1713. ;; (idlwave-shell-send-command "obj_destroy, obj_valid()" nil hidden)
  1714. (idlwave-shell-send-command "heap_gc,/verbose" nil hidden)
  1715. (idlwave-shell-display-line nil)))
  1716. (defun idlwave-shell-path-filter ()
  1717. ;; Convert the output of the path query into a list of directories
  1718. (let ((path-string idlwave-shell-command-output)
  1719. (case-fold-search t)
  1720. (start 0)
  1721. dirs sysdir)
  1722. (while (string-match "^PATH:[ \t]*<\\(.*\\)>[ \t]*\n" path-string start)
  1723. (push (match-string 1 path-string) dirs)
  1724. (setq start (match-end 0)))
  1725. (setq dirs (mapcar 'file-name-as-directory dirs))
  1726. (if (string-match "^SYSDIR:[ \t]*<\\(.*\\)>[ \t]*\n" path-string)
  1727. (setq sysdir (file-name-as-directory
  1728. (match-string 1 path-string))))
  1729. (cons sysdir (nreverse dirs))))
  1730. (defun idlwave-shell-routine-info-filter ()
  1731. "Function which parses the special output from idlwave_routine_info.pro."
  1732. (let ((text idlwave-shell-command-output)
  1733. (start 0)
  1734. sep sep-re file type spec specs name cs key keys class entry)
  1735. ;; (message "GOT: %s" text) ;??????????????????????
  1736. ;; Initialize variables
  1737. (setq idlwave-compiled-routines nil
  1738. idlwave-unresolved-routines nil)
  1739. ;; Cut out the correct part of the output.
  1740. (if (string-match
  1741. "^>>>BEGIN OF IDLWAVE ROUTINE INFO (\"\\(.+\\)\" IS THE SEPARATOR.*"
  1742. text)
  1743. (setq sep (match-string 1 text)
  1744. sep-re (concat (regexp-quote sep) " *")
  1745. text (substring text (match-end 0)))
  1746. ;; Set dummy values and kill the text
  1747. (setq sep "@" sep-re "@ *" text "")
  1748. (if idlwave-idlwave_routine_info-compiled
  1749. (message
  1750. "Routine Info warning: No match for BEGIN line in \n>>>\n%s\n<<<\n"
  1751. idlwave-shell-command-output)))
  1752. (if (string-match "^>>>END OF IDLWAVE ROUTINE INFO.*" text)
  1753. (setq text (substring text 0 (match-beginning 0)))
  1754. (if idlwave-idlwave_routine_info-compiled
  1755. (message
  1756. "Routine Info warning: No match for END line in \n>>>\n%s\n<<<\n"
  1757. idlwave-shell-command-output)))
  1758. ;; Match the output lines
  1759. (while (string-match "^IDLWAVE-\\(PRO\\|FUN\\): \\(.*\\)" text start)
  1760. (setq start (match-end 0))
  1761. (setq type (match-string 1 text)
  1762. spec (match-string 2 text)
  1763. specs (idlwave-split-string spec sep-re)
  1764. name (nth 0 specs)
  1765. class (if (equal (nth 1 specs) "") nil (nth 1 specs))
  1766. file (nth 2 specs)
  1767. cs (nth 3 specs)
  1768. key (nth 4 specs)
  1769. keys (if (and (stringp key)
  1770. (not (string-match "\\` *\\'" key)))
  1771. (mapcar 'list
  1772. (delete "" (idlwave-split-string key " +")))))
  1773. (setq name (idlwave-sintern-routine-or-method name class t)
  1774. class (idlwave-sintern-class class t)
  1775. file (if (equal file "") nil file)
  1776. keys (mapcar (lambda (x)
  1777. (list (idlwave-sintern-keyword (car x) t))) keys))
  1778. ;; In the following ignore routines already defined in buffers,
  1779. ;; assuming that if the buffer stuff differs, it is a "new"
  1780. ;; version, not yet compiled, and should take precedence.
  1781. ;; We could do the same for the library to avoid duplicates -
  1782. ;; but I think frequently a user might have several versions of
  1783. ;; the same function in different programs, and in this case the
  1784. ;; compiled one will be the best guess of all versions.
  1785. ;; Therefore, we leave duplicates of library routines in.
  1786. (cond ((string= name "$MAIN$")) ; ignore this one
  1787. ((and (string= type "PRO")
  1788. ;; FIXME: is it OK to make the buffer routines dominate?
  1789. (or t (null file)
  1790. (not (idlwave-rinfo-assq name 'pro class
  1791. idlwave-buffer-routines)))
  1792. ;; FIXME: is it OK to make the library routines dominate?
  1793. ;;(not (idlwave-rinfo-assq name 'pro class
  1794. ;; idlwave-library-routines))
  1795. )
  1796. (setq entry (list name 'pro class
  1797. (cons 'compiled
  1798. (if file
  1799. (list
  1800. (file-name-nondirectory file)
  1801. (idlwave-sintern-dir
  1802. (file-name-directory file)))))
  1803. cs (cons nil keys)))
  1804. (if file
  1805. (push entry idlwave-compiled-routines)
  1806. (push entry idlwave-unresolved-routines)))
  1807. ((and (string= type "FUN")
  1808. ;; FIXME: is it OK to make the buffer routines dominate?
  1809. (or t (not file)
  1810. (not (idlwave-rinfo-assq name 'fun class
  1811. idlwave-buffer-routines)))
  1812. ;; FIXME: is it OK to make the library routines dominate?
  1813. ;; (not (idlwave-rinfo-assq name 'fun class
  1814. ;; idlwave-library-routines))
  1815. )
  1816. (setq entry (list name 'fun class
  1817. (cons 'compiled
  1818. (if file
  1819. (list
  1820. (file-name-nondirectory file)
  1821. (idlwave-sintern-dir
  1822. (file-name-directory file)))))
  1823. cs (cons nil keys)))
  1824. (if file
  1825. (push entry idlwave-compiled-routines)
  1826. (push entry idlwave-unresolved-routines))))))
  1827. ;; Reverse the definitions so that they are alphabetically sorted.
  1828. (setq idlwave-compiled-routines (nreverse idlwave-compiled-routines)
  1829. idlwave-unresolved-routines (nreverse idlwave-unresolved-routines)))
  1830. (defun idlwave-shell-filter-directory ()
  1831. "Get the current directory from `idlwave-shell-command-output'.
  1832. Change the default directory for the process buffer to concur."
  1833. (with-current-buffer (idlwave-shell-buffer)
  1834. (if (string-match ",___cur[\n\r ]+\\([^\n\r]+\\)[\n\r]"
  1835. idlwave-shell-command-output)
  1836. (let ((dir (substring idlwave-shell-command-output
  1837. (match-beginning 1) (match-end 1))))
  1838. ;; (message "Setting Emacs working dir to %s" dir)
  1839. (setq idlwave-shell-default-directory dir)
  1840. (setq default-directory (file-name-as-directory dir))))))
  1841. (defvar idlwave-shell-get-object-class nil)
  1842. (defun idlwave-shell-get-object-class (apos)
  1843. "Query the shell for the class of the object before point."
  1844. (let ((bos (save-excursion (idlwave-start-of-substatement 'pre) (point)))
  1845. (bol (save-excursion (forward-line 0) (point)))
  1846. expression)
  1847. (save-excursion
  1848. (goto-char apos)
  1849. (setq expression (buffer-substring
  1850. (catch 'exit
  1851. (while t
  1852. (if (not (re-search-backward
  1853. "[^][.A-Za-z0-9_() ]" bos t))
  1854. (throw 'exit bos)) ;ran into bos
  1855. (if (not (idlwave-is-pointer-dereference bol))
  1856. (throw 'exit (1+ (point))))))
  1857. apos)))
  1858. (when (not (string= expression ""))
  1859. (setq idlwave-shell-get-object-class nil)
  1860. (idlwave-shell-send-command
  1861. (concat "if obj_valid(" expression ") then print,obj_class("
  1862. expression ")")
  1863. 'idlwave-shell-parse-object-class
  1864. 'hide 'wait)
  1865. ;; If we don't know anything about the class, update shell routines
  1866. (if (and idlwave-shell-get-object-class
  1867. (not (assoc-string idlwave-shell-get-object-class
  1868. (idlwave-class-alist) t)))
  1869. (idlwave-shell-maybe-update-routine-info))
  1870. idlwave-shell-get-object-class)))
  1871. (defun idlwave-shell-parse-object-class ()
  1872. "Parse the output of the obj_class command."
  1873. (let ((match "obj_class([^\n\r]+[\n\r ]"))
  1874. (if (string-match (concat match "\\([A-Za-z_0-9]+\\) *[\n\r]\\("
  1875. idlwave-shell-prompt-pattern "\\)")
  1876. idlwave-shell-command-output)
  1877. (setq idlwave-shell-get-object-class
  1878. (match-string 1 idlwave-shell-command-output)))))
  1879. (defvar idlwave-sint-sysvars nil)
  1880. (idlwave-new-sintern-type 'execcomm)
  1881. (defun idlwave-shell-complete (&optional arg)
  1882. "Do completion in the idlwave-shell buffer.
  1883. Calls `idlwave-shell-complete-filename' after some executive commands or
  1884. in strings. Otherwise, calls `idlwave-complete' to complete modules and
  1885. keywords."
  1886. (interactive "P")
  1887. (let (exec-cmd)
  1888. (cond
  1889. ((and
  1890. (setq exec-cmd (idlwave-shell-executive-command))
  1891. (cdr exec-cmd)
  1892. (member (upcase (cdr exec-cmd))
  1893. '(".R" ".RU" ".RUN" ".RN" ".RNE" ".RNEW"
  1894. ".COM" ".COMP" ".COMPI" ".COMPIL" ".COMPILE")))
  1895. ;; We are in a command line with an executive command
  1896. (idlwave-shell-complete-filename))
  1897. ((car-safe exec-cmd)
  1898. (setq idlwave-completion-help-info
  1899. '(idlwave-shell-complete-execcomm-help))
  1900. (idlwave-complete-in-buffer 'execcomm 'execcomm
  1901. idlwave-executive-commands-alist nil
  1902. "Select an executive command"
  1903. "system variable"))
  1904. ((idlwave-shell-batch-command)
  1905. (idlwave-shell-complete-filename))
  1906. ((idlwave-shell-shell-command)
  1907. (idlwave-shell-complete-filename))
  1908. ((and (idlwave-shell-filename-string)
  1909. (save-excursion
  1910. (beginning-of-line)
  1911. (let ((case-fold-search t))
  1912. (not (looking-at ".*obj_new")))))
  1913. (idlwave-shell-complete-filename))
  1914. (t
  1915. ;; Default completion of modules and keywords
  1916. (idlwave-complete arg)))))
  1917. ;; Get rid of opaque dynamic variable passing of idlw-help-link?
  1918. (defvar idlw-help-link) ; dynamic variable from idlwave-do-mouse-completion-help
  1919. (defun idlwave-shell-complete-execcomm-help (mode word)
  1920. (let ((word (or (nth 1 idlwave-completion-help-info) word))
  1921. (entry (assoc-string word idlwave-executive-commands-alist t)))
  1922. (cond
  1923. ((eq mode 'test)
  1924. (and (stringp word) entry (cdr entry)))
  1925. ((eq mode 'set)
  1926. (if entry (setq idlw-help-link (cdr entry)))) ; setting dynamic variable!
  1927. (t (error "This should not happen")))))
  1928. (defun idlwave-shell-complete-filename (&optional arg)
  1929. "Complete a file name at point if after a file name.
  1930. We assume that we are after a file name when completing one of the
  1931. args of an executive .run, .rnew or .compile."
  1932. ;; CWD might have changed, resync, to set default directory
  1933. (idlwave-shell-resync-dirs)
  1934. (let ((comint-file-name-chars idlwave-shell-file-name-chars))
  1935. (comint-filename-completion)))
  1936. (defun idlwave-shell-executive-command ()
  1937. "Return the name of the current executive command, if any."
  1938. (save-excursion
  1939. (idlwave-beginning-of-statement)
  1940. (cons (looking-at "[ \t]*\\.")
  1941. (if (looking-at "[ \t]*[.]\\([^ \t\n\r]+\\)[ \t]")
  1942. (match-string 1)))))
  1943. (defun idlwave-shell-filename-string ()
  1944. "Return t if in a string and after what could be a file name."
  1945. (let ((limit (point-at-bol)))
  1946. (save-excursion
  1947. ;; Skip backwards over file name chars
  1948. (skip-chars-backward idlwave-shell-file-name-chars limit)
  1949. ;; Check of the next char is a string delimiter
  1950. (memq (preceding-char) '(?\' ?\")))))
  1951. (defun idlwave-shell-batch-command ()
  1952. "Return t if we're in a batch command statement like @foo"
  1953. (let ((limit (point-at-bol)))
  1954. (save-excursion
  1955. ;; Skip backwards over filename
  1956. (skip-chars-backward idlwave-shell-file-name-chars limit)
  1957. (skip-chars-backward " \t" limit)
  1958. (and (eq (preceding-char) ?@) (not (idlwave-in-quote))))))
  1959. (defun idlwave-shell-shell-command ()
  1960. "Return t if we're in a shell command statement like $ls"
  1961. (save-excursion
  1962. (idlwave-beginning-of-statement)
  1963. (looking-at "\\$")))
  1964. ;; Debugging Commands ------------------------------------------------------
  1965. (defun idlwave-shell-redisplay (&optional hide)
  1966. "Try to resync the display with where execution has stopped.
  1967. Issues a \"help,/trace\" command followed by a call to
  1968. `idlwave-shell-display-line'. Also updates the breakpoint
  1969. overlays."
  1970. (interactive)
  1971. (setq idlwave-shell-calling-stack-index 0)
  1972. (idlwave-shell-send-command
  1973. "help,/trace"
  1974. '(idlwave-shell-display-line
  1975. (idlwave-shell-pc-frame))
  1976. hide)
  1977. (idlwave-shell-bp-query))
  1978. (defun idlwave-shell-display-level-in-calling-stack (&optional hide)
  1979. (idlwave-shell-send-command
  1980. "help,/trace"
  1981. `(progn
  1982. ;; scanning for the state will reset the stack level - restore it
  1983. (setq idlwave-shell-calling-stack-index
  1984. ,idlwave-shell-calling-stack-index)
  1985. ;; parse the stack and visit the selected frame
  1986. (idlwave-shell-parse-stack-and-display))
  1987. hide))
  1988. (defun idlwave-shell-parse-stack-and-display ()
  1989. (let* ((lines (delete "" (idlwave-split-string
  1990. idlwave-shell-command-output "^%")))
  1991. (stack (delq nil (mapcar 'idlwave-shell-parse-line lines)))
  1992. (nmax (1- (length stack)))
  1993. (nmin 0) message)
  1994. (cond
  1995. ((< nmax nmin)
  1996. (setq idlwave-shell-calling-stack-index 0)
  1997. (ding)
  1998. (message "Problem with calling stack"))
  1999. ((> idlwave-shell-calling-stack-index nmax)
  2000. (ding)
  2001. (setq idlwave-shell-calling-stack-index nmax
  2002. message (format "%d is the highest calling stack level - can't go further up"
  2003. (- nmax))))
  2004. ((< idlwave-shell-calling-stack-index nmin)
  2005. (ding)
  2006. (setq idlwave-shell-calling-stack-index nmin
  2007. message (format "%d is the current calling stack level - can't go further down"
  2008. (- nmin)))))
  2009. (setq idlwave-shell-calling-stack-routine
  2010. (nth 2 (nth idlwave-shell-calling-stack-index stack)))
  2011. ;; force edebug for this frame if we're in that mode already
  2012. (idlwave-shell-display-line
  2013. (nth idlwave-shell-calling-stack-index stack) nil
  2014. (if idlwave-shell-electric-debug-mode 'force))
  2015. (message "%s" (or message
  2016. (format "In routine %s (stack level %d)"
  2017. idlwave-shell-calling-stack-routine
  2018. (- idlwave-shell-calling-stack-index))))))
  2019. (defun idlwave-shell-stack-up ()
  2020. "Display the source code one step up the calling stack."
  2021. (interactive)
  2022. (incf idlwave-shell-calling-stack-index)
  2023. (idlwave-shell-display-level-in-calling-stack 'hide))
  2024. (defun idlwave-shell-stack-down ()
  2025. "Display the source code one step down the calling stack."
  2026. (interactive)
  2027. (decf idlwave-shell-calling-stack-index)
  2028. (idlwave-shell-display-level-in-calling-stack 'hide))
  2029. (defun idlwave-shell-goto-frame (&optional frame)
  2030. "Set buffer to FRAME with point at the frame line.
  2031. If the optional argument FRAME is nil then `idlwave-shell-pc-frame'
  2032. is used. Does nothing if the resulting frame is nil."
  2033. (if frame ()
  2034. (setq frame (idlwave-shell-pc-frame)))
  2035. (cond
  2036. (frame
  2037. (set-buffer (idlwave-find-file-noselect (car frame) 'shell))
  2038. (widen)
  2039. (goto-char (point-min))
  2040. (forward-line (1- (nth 1 frame))))))
  2041. (defun idlwave-shell-pc-frame ()
  2042. "Return the frame for IDL execution."
  2043. (and idlwave-shell-halt-frame
  2044. (list (nth 0 idlwave-shell-halt-frame)
  2045. (nth 1 idlwave-shell-halt-frame)
  2046. (nth 2 idlwave-shell-halt-frame))))
  2047. (defun idlwave-shell-valid-frame (frame)
  2048. "Check that frame is for an existing file."
  2049. (file-readable-p (car frame)))
  2050. (defun idlwave-shell-stop-line-pending ()
  2051. ;; Temporarily change the color of the stop line overlay
  2052. (if idlwave-shell-stop-line-overlay
  2053. (overlay-put idlwave-shell-stop-line-overlay 'face
  2054. (if idlwave-shell-electric-debug-mode
  2055. 'idlwave-shell-pending-electric-stop
  2056. 'idlwave-shell-pending-stop))))
  2057. (defvar idlwave-shell-suppress-electric-debug nil)
  2058. (defun idlwave-shell-display-line (frame &optional col debug)
  2059. "Display frame file in other window with overlay arrow.
  2060. FRAME is a list of file name, line number, and subroutine name. If
  2061. FRAME is nil then remove overlay. If COL is set, move point to that
  2062. column in the line. If DEBUG is non-nil, enable the electric debug
  2063. mode. If it is 'disable, do not enable no matter what the setting of
  2064. `idlwave-shell-automatic-electric-debug'. If it is 'force, enable no
  2065. matter what the settings of that variable."
  2066. (if (not frame)
  2067. ;; remove stop-line overlay from old position
  2068. (progn
  2069. (setq overlay-arrow-string nil)
  2070. (setq idlwave-shell-mode-line-info nil)
  2071. (setq idlwave-shell-is-stopped nil)
  2072. (if idlwave-shell-stop-line-overlay
  2073. (delete-overlay idlwave-shell-stop-line-overlay))
  2074. ;; turn off electric debug everywhere, if it's on
  2075. (idlwave-shell-electric-debug-all-off))
  2076. (if (not (idlwave-shell-valid-frame frame))
  2077. ;; fixme: errors are dangerous in shell filters. but i think i
  2078. ;; have never encountered this one.
  2079. (error "invalid frame - unable to access file: %s" (car frame))
  2080. ;;
  2081. ;; buffer : the buffer to display a line in.
  2082. ;; select-shell: current buffer is the shell.
  2083. ;;
  2084. (setq idlwave-shell-mode-line-info
  2085. (if (nth 2 frame)
  2086. (format "[%d:%s]"
  2087. (- idlwave-shell-calling-stack-index)
  2088. (nth 2 frame))))
  2089. (let* ((buffer (idlwave-find-file-noselect (car frame) 'shell))
  2090. (select-shell (equal (buffer-name) (idlwave-shell-buffer)))
  2091. window pos electric)
  2092. ;; first make sure the shell window is visible
  2093. (idlwave-display-buffer (idlwave-shell-buffer)
  2094. nil (idlwave-shell-shell-frame))
  2095. ;; now display the buffer and remember which window it is.
  2096. (setq window (idlwave-display-buffer buffer
  2097. nil (idlwave-shell-source-frame)))
  2098. ;; enter the buffer and mark the line
  2099. (with-current-buffer buffer
  2100. (save-restriction
  2101. (widen)
  2102. (goto-char (point-min))
  2103. (forward-line (1- (nth 1 frame)))
  2104. (setq pos (point))
  2105. (setq idlwave-shell-is-stopped t)
  2106. (if idlwave-shell-stop-line-overlay
  2107. (progn
  2108. ;; restore face and move overlay
  2109. (overlay-put idlwave-shell-stop-line-overlay 'face
  2110. (if idlwave-shell-electric-debug-mode
  2111. idlwave-shell-electric-stop-line-face
  2112. idlwave-shell-stop-line-face))
  2113. (move-overlay idlwave-shell-stop-line-overlay
  2114. (point) (point-at-eol)
  2115. (current-buffer)))
  2116. ;; use the arrow instead, but only if marking is wanted.
  2117. (if idlwave-shell-mark-stop-line
  2118. (setq overlay-arrow-string idlwave-shell-overlay-arrow))
  2119. (or overlay-arrow-position ; create the marker if necessary
  2120. (setq overlay-arrow-position (make-marker)))
  2121. (set-marker overlay-arrow-position (point) buffer)))
  2122. ;; if the point is outside the restriction, widen the buffer.
  2123. (if (or (< pos (point-min)) (> pos (point-max)))
  2124. (progn
  2125. (widen)
  2126. (goto-char pos)))
  2127. ;; if we have the column of the error, move the cursor there.
  2128. (if col (move-to-column col))
  2129. (setq pos (point))
  2130. ;; enter electric debug mode, if not prohibited and not in
  2131. ;; it already
  2132. (when (and (not idlwave-shell-electric-debug-mode)
  2133. (or (eq debug 'force)
  2134. (and
  2135. (not (eq debug 'disable)) ;; explicitly disabled
  2136. (or
  2137. (eq idlwave-shell-automatic-electric-debug t)
  2138. (and
  2139. (eq idlwave-shell-automatic-electric-debug
  2140. 'breakpoint)
  2141. (not (eq idlwave-shell-current-state 'error))))
  2142. (not idlwave-shell-suppress-electric-debug))))
  2143. (idlwave-shell-electric-debug-mode t))
  2144. (setq electric idlwave-shell-electric-debug-mode))
  2145. ;; Make sure pos is really displayed in the window.
  2146. (set-window-point window pos)
  2147. ;; If we came from the shell, go back there. Otherwise select
  2148. ;; the window where the error/halt is displayed.
  2149. (if (or (and idlwave-shell-electric-zap-to-file electric)
  2150. (and (equal (buffer-name) (idlwave-shell-buffer))
  2151. (not select-shell)))
  2152. (select-window window))))))
  2153. (defun idlwave-shell-step (arg)
  2154. "Step one source line.
  2155. If given prefix argument ARG, step ARG source lines."
  2156. (interactive "p")
  2157. (or (not arg) (< arg 1)
  2158. (setq arg 1))
  2159. (idlwave-shell-stop-line-pending)
  2160. (idlwave-shell-send-command
  2161. (concat ".s " (if (integerp arg) (int-to-string arg) arg))
  2162. nil (if (idlwave-shell-hide-p 'debug) 'mostly) nil t))
  2163. (defun idlwave-shell-stepover (arg)
  2164. "Stepover one source line.
  2165. If given prefix argument ARG, step ARG source lines.
  2166. Uses IDL's stepover executive command which does not enter called functions."
  2167. (interactive "p")
  2168. (or (not arg) (< arg 1)
  2169. (setq arg 1))
  2170. (idlwave-shell-stop-line-pending)
  2171. (idlwave-shell-send-command
  2172. (concat ".so " (if (integerp arg) (int-to-string arg) arg))
  2173. nil (if (idlwave-shell-hide-p 'debug) 'mostly) nil t))
  2174. (defun idlwave-shell-break-here (&optional count cmd condition disabled
  2175. no-show)
  2176. "Set breakpoint at current line.
  2177. If COUNT is nil then an ordinary breakpoint is set. We treat a COUNT
  2178. of 1 as a temporary breakpoint using the ONCE keyword. Counts greater
  2179. than 1 use the IDL AFTER=count keyword to break only after reaching
  2180. the statement COUNT times.
  2181. Optional argument CMD is a list or function to evaluate upon reaching
  2182. the breakpoint. CONDITION is a break condition, and DISABLED, if
  2183. non-nil disables the breakpoint."
  2184. (interactive "P")
  2185. (when (listp count)
  2186. (if (equal (car count) 4)
  2187. (setq condition (read-string "Break Condition: ")))
  2188. (setq count nil))
  2189. (idlwave-shell-set-bp
  2190. ;; Create breakpoint
  2191. (idlwave-shell-bp (idlwave-shell-current-frame)
  2192. (list count cmd condition disabled)
  2193. (idlwave-shell-current-module))
  2194. no-show))
  2195. (defun idlwave-shell-set-bp-check (bp)
  2196. "Check for failure to set breakpoint.
  2197. This is run on `idlwave-shell-post-command-hook'.
  2198. Offers to recompile the procedure if we failed. This usually fixes
  2199. the problem with not being able to set the breakpoint."
  2200. ;; Scan for message
  2201. (if idlwave-shell-command-output
  2202. (cond
  2203. ((string-match "% BREAKPOINT: *Unable to find code"
  2204. idlwave-shell-command-output)
  2205. ;; Offer to recompile
  2206. (if (progn
  2207. (beep)
  2208. (y-or-n-p
  2209. (concat "Okay to recompile file "
  2210. (idlwave-shell-bp-get bp 'file) "?")))
  2211. ;; Recompile
  2212. (progn
  2213. ;; Clean up before retrying
  2214. (idlwave-shell-command-failure)
  2215. (idlwave-shell-send-command
  2216. (concat ".run \"" (idlwave-shell-bp-get bp 'file) "\"") nil
  2217. (if (idlwave-shell-hide-p 'run) 'mostly) nil t)
  2218. ;; Try setting breakpoint again
  2219. (idlwave-shell-set-bp bp))
  2220. (beep)
  2221. (message "Unable to set breakpoint.")
  2222. (idlwave-shell-command-failure))
  2223. nil)
  2224. ((string-match "% Syntax error" idlwave-shell-command-output)
  2225. (message "Syntax error in condition.")
  2226. (idlwave-shell-command-failure)
  2227. nil)
  2228. (t 'okay))))
  2229. (defun idlwave-shell-command-failure ()
  2230. "Do any necessary clean up when an IDL command fails.
  2231. Call this from a function attached to `idlwave-shell-post-command-hook'
  2232. that detects the failure of a command.
  2233. For example, this is called from `idlwave-shell-set-bp-check' when a
  2234. breakpoint can not be set."
  2235. ;; Clear pending commands
  2236. (setq idlwave-shell-pending-commands nil))
  2237. (defun idlwave-shell-cont (&optional no-show)
  2238. "Continue executing."
  2239. (interactive)
  2240. (idlwave-shell-stop-line-pending)
  2241. (idlwave-shell-send-command ".c" (unless no-show
  2242. '(idlwave-shell-redisplay 'hide))
  2243. (if (idlwave-shell-hide-p 'debug) 'mostly)
  2244. nil t))
  2245. (defun idlwave-shell-go ()
  2246. "Run .GO. This starts the main program of the last compiled file."
  2247. (interactive)
  2248. (idlwave-shell-stop-line-pending)
  2249. (idlwave-shell-send-command ".go" '(idlwave-shell-redisplay 'hide)
  2250. (if (idlwave-shell-hide-p 'debug) 'mostly)
  2251. nil t))
  2252. (defun idlwave-shell-return ()
  2253. "Run .RETURN (continue to next return, but stay in subprogram)."
  2254. (interactive)
  2255. (idlwave-shell-stop-line-pending)
  2256. (idlwave-shell-send-command ".return" '(idlwave-shell-redisplay 'hide)
  2257. (if (idlwave-shell-hide-p 'debug) 'mostly)
  2258. nil t))
  2259. (defun idlwave-shell-skip ()
  2260. "Run .SKIP (skip one line, then step)."
  2261. (interactive)
  2262. (idlwave-shell-stop-line-pending)
  2263. (idlwave-shell-send-command ".skip" '(idlwave-shell-redisplay 'hide)
  2264. (if (idlwave-shell-hide-p 'debug) 'mostly)
  2265. nil t))
  2266. (defun idlwave-shell-clear-bp (bp &optional no-query)
  2267. "Clear breakpoint BP.
  2268. Clears in IDL and in `idlwave-shell-bp-alist'."
  2269. (let ((index (idlwave-shell-bp-get bp)))
  2270. (if index
  2271. (progn
  2272. (idlwave-shell-send-command
  2273. (concat "breakpoint,/clear," (int-to-string index))
  2274. nil (idlwave-shell-hide-p 'breakpoint) nil t)
  2275. (unless no-query (idlwave-shell-bp-query))))))
  2276. (defun idlwave-shell-current-frame ()
  2277. "Return a list containing the current file name and line point is in.
  2278. If in the IDL shell buffer, returns `idlwave-shell-pc-frame'."
  2279. (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
  2280. ;; In IDL shell
  2281. (idlwave-shell-pc-frame)
  2282. ;; In source
  2283. (list (idlwave-shell-file-name (buffer-file-name))
  2284. (save-restriction
  2285. (widen)
  2286. (1+ (count-lines 1 (point-at-bol)))))))
  2287. (defun idlwave-shell-current-module ()
  2288. "Return the name of the module for the current file.
  2289. Returns nil if unable to obtain a module name."
  2290. (if (eq (current-buffer) (get-buffer (idlwave-shell-buffer)))
  2291. ;; In IDL shell
  2292. (nth 2 idlwave-shell-halt-frame)
  2293. ;; In pro file
  2294. (save-restriction
  2295. (widen)
  2296. (save-excursion
  2297. (if (idlwave-prev-index-position)
  2298. (let* ((module (idlwave-what-module))
  2299. (name (idlwave-make-full-name (nth 2 module) (car module)))
  2300. (type (nth 1 module)))
  2301. (list (upcase name) type)))))))
  2302. (defun idlwave-shell-clear-current-bp ()
  2303. "Remove breakpoint at current line.
  2304. This command can be called from the shell buffer if IDL is currently
  2305. stopped at a breakpoint."
  2306. (interactive)
  2307. (let ((bp (idlwave-shell-find-current-bp)))
  2308. (if bp (idlwave-shell-clear-bp bp))))
  2309. (defun idlwave-shell-toggle-enable-current-bp (&optional bp force
  2310. no-update)
  2311. "Disable or enable current breakpoint or a breakpoint passed in BP.
  2312. If FORCE is 'disable or 'enable, for that condition instead of
  2313. toggling. If NO-UPDATE is non-nil, don't update the breakpoint
  2314. list after toggling."
  2315. (interactive)
  2316. (let* ((bp (or bp (idlwave-shell-find-current-bp)))
  2317. (disabled (idlwave-shell-bp-get bp 'disabled)))
  2318. (cond ((eq force 'disable) (setq disabled nil))
  2319. ((eq force 'enable) (setq disabled t)))
  2320. (when bp
  2321. (setf (nth 3 (cdr (cdr bp))) (not disabled))
  2322. (idlwave-shell-send-command
  2323. (concat "breakpoint,"
  2324. (if disabled "/enable," "/disable,")
  2325. (int-to-string (idlwave-shell-bp-get bp)))
  2326. nil (idlwave-shell-hide-p 'breakpoint) nil t)
  2327. (unless no-update (idlwave-shell-bp-query)))))
  2328. (defun idlwave-shell-enable-all-bp (&optional enable no-update bpl)
  2329. "Disable all breakpoints we know about which need disabling.
  2330. If ENABLE is non-nil, enable them instead."
  2331. (let ((bpl (or bpl idlwave-shell-bp-alist)) disabled modified)
  2332. (while bpl
  2333. (setq disabled (idlwave-shell-bp-get (car bpl) 'disabled))
  2334. (when (idlwave-xor (not disabled) (eq enable 'enable))
  2335. (idlwave-shell-toggle-enable-current-bp
  2336. (car bpl) (if (eq enable 'enable) 'enable 'disable) no-update)
  2337. (push (car bpl) modified))
  2338. (setq bpl (cdr bpl)))
  2339. (unless no-update (idlwave-shell-bp-query))
  2340. modified))
  2341. (defun idlwave-shell-to-here ()
  2342. "Set a breakpoint with count 1 then continue."
  2343. (interactive)
  2344. ;; temporarily disable all other breakpoints
  2345. (let ((disabled (idlwave-shell-enable-all-bp 'disable 'no-update)))
  2346. (idlwave-shell-break-here 1 nil nil nil 'no-show)
  2347. (idlwave-shell-cont 'no-show)
  2348. (idlwave-shell-enable-all-bp 'enable 'no-update disabled))
  2349. (idlwave-shell-redisplay)) ; sync up everything at the end
  2350. (defun idlwave-shell-break-this-module (&optional arg)
  2351. (interactive "P")
  2352. (save-excursion
  2353. (idlwave-beginning-of-subprogram)
  2354. (idlwave-shell-break-here arg)))
  2355. (defun idlwave-shell-break-in ()
  2356. "Look for a module name near point and set a break point for it.
  2357. The command looks for an identifier near point and sets a breakpoint
  2358. for the first line of the corresponding module. If MODULE is `t', set
  2359. in the current routine."
  2360. (interactive)
  2361. (let* ((module (idlwave-fix-module-if-obj_new (idlwave-what-module)))
  2362. (type (nth 1 module))
  2363. (name (car module))
  2364. (class (nth 2 module)))
  2365. (if module
  2366. (progn
  2367. (setq module (idlwave-make-full-name class name))
  2368. (idlwave-shell-module-source-query module type)
  2369. (idlwave-shell-set-bp-in-module name type class))
  2370. (error "No identifier at point"))))
  2371. (defun idlwave-shell-set-bp-in-module (name type class)
  2372. "Set breakpoint in module.
  2373. Assumes that `idlwave-shell-sources-alist' contains an entry for that module."
  2374. (let* ((module (idlwave-make-full-name class name))
  2375. (source-file
  2376. (car-safe (cdr-safe
  2377. (or
  2378. (assoc (upcase module)
  2379. idlwave-shell-sources-alist)
  2380. (nth 3 (idlwave-best-rinfo-assoc name type class
  2381. (idlwave-routines)))))))
  2382. buf)
  2383. (if (or (not source-file)
  2384. (not (file-regular-p source-file))
  2385. (not (setq buf
  2386. (or (idlwave-get-buffer-visiting source-file)
  2387. (find-file-noselect source-file)))))
  2388. (progn
  2389. (message "The source file for module %s is probably not compiled"
  2390. module)
  2391. (beep))
  2392. (with-current-buffer buf
  2393. (save-excursion
  2394. (goto-char (point-min))
  2395. (let ((case-fold-search t))
  2396. (if (re-search-forward
  2397. (concat "^[ \t]*\\(pro\\|function\\)[ \t]+"
  2398. (downcase module)
  2399. "[ \t\n,]") nil t)
  2400. (progn
  2401. (goto-char (match-beginning 1))
  2402. (message "Setting breakpoint for module %s" module)
  2403. (idlwave-shell-break-here))
  2404. (message "Cannot find module %s in file %s" module source-file)
  2405. (beep))))))))
  2406. (defun idlwave-shell-up ()
  2407. "Run to end of current block.
  2408. Sets a breakpoint with count 1 at end of block, then continues."
  2409. (interactive)
  2410. (if (idlwave-shell-pc-frame)
  2411. (save-excursion
  2412. (idlwave-shell-goto-frame)
  2413. ;; find end of subprogram
  2414. (let ((eos (save-excursion
  2415. (idlwave-beginning-of-subprogram)
  2416. (idlwave-forward-block)
  2417. (point))))
  2418. (idlwave-backward-up-block -1)
  2419. ;; move beyond end block line - IDL will not break there.
  2420. ;; That is, you can put a breakpoint there but when IDL does
  2421. ;; break it will report that it is at the next line.
  2422. (idlwave-next-statement)
  2423. (idlwave-end-of-statement)
  2424. ;; Make sure we are not beyond subprogram
  2425. (if (< (point) eos)
  2426. ;; okay
  2427. ()
  2428. ;; Move back inside subprogram
  2429. (goto-char eos)
  2430. (idlwave-previous-statement))
  2431. (idlwave-shell-to-here)))))
  2432. (defun idlwave-shell-out ()
  2433. "Attempt to run until this procedure exits.
  2434. Runs to the last statement and then steps 1 statement. Use the .out command."
  2435. (interactive)
  2436. (idlwave-shell-send-command ".o" nil
  2437. (if (idlwave-shell-hide-p 'debug) 'mostly)
  2438. nil t))
  2439. (defun idlwave-shell-goto-previous-bp ()
  2440. "Move to the previous breakpoint in the buffer."
  2441. (interactive)
  2442. (idlwave-shell-move-to-bp -1))
  2443. (defun idlwave-shell-goto-next-bp ()
  2444. "Move to the next breakpoint in the buffer."
  2445. (interactive)
  2446. (idlwave-shell-move-to-bp 1))
  2447. (defun idlwave-shell-move-to-bp (dir)
  2448. "Move to the next or previous breakpoint, depending on direction DIR."
  2449. (let* ((frame (idlwave-shell-current-frame))
  2450. (file (car frame))
  2451. (orig-bp-line (nth 1 frame))
  2452. (bp-alist idlwave-shell-bp-alist)
  2453. (orig-func (if (> dir 0) '> '<))
  2454. (closer-func (if (> dir 0) '< '>))
  2455. bp got-bp bp-line cur-line)
  2456. (while (setq bp (pop bp-alist))
  2457. (when (string= file (car (car bp)))
  2458. (setq got-bp 1)
  2459. (setq cur-line (nth 1 (car bp)))
  2460. (if (and
  2461. (funcall orig-func cur-line orig-bp-line)
  2462. (or (not bp-line) (funcall closer-func cur-line bp-line)))
  2463. (setq bp-line cur-line))))
  2464. (unless bp-line (error "No further breakpoints"))
  2465. (goto-char (point-min))
  2466. (forward-line (1- bp-line))))
  2467. ;; Examine Commands ------------------------------------------------------
  2468. (defun idlwave-shell-help-expression (arg)
  2469. "Print help on current expression. See `idlwave-shell-print'."
  2470. (interactive "P")
  2471. (idlwave-shell-print arg 'help))
  2472. (defmacro idlwave-shell-mouse-examine (help &optional ev)
  2473. "Create a function for generic examination of expressions."
  2474. `(lambda (event)
  2475. "Expansion function for expression examination."
  2476. (interactive "e")
  2477. (let* ((drag-track (fboundp 'mouse-drag-track))
  2478. (transient-mark-mode t)
  2479. (zmacs-regions t)
  2480. (tracker (if (featurep 'xemacs)
  2481. (if (fboundp
  2482. 'default-mouse-track-event-is-with-button)
  2483. 'idlwave-xemacs-hack-mouse-track
  2484. 'mouse-track)
  2485. ;; Emacs 22 no longer completes the drag with
  2486. ;; mouse-drag-region, without an additional
  2487. ;; event. mouse-drag-track does so.
  2488. (if drag-track 'mouse-drag-track 'mouse-drag-region))))
  2489. (funcall tracker event)
  2490. (idlwave-shell-print (if (idlwave-region-active-p) '(4) nil)
  2491. ,help ,ev))))
  2492. ;; Begin terrible hack section -- XEmacs tests for button2 explicitly
  2493. ;; on drag events, calling drag-n-drop code if detected. Ughhh...
  2494. (defun idlwave-default-mouse-track-event-is-with-button (event n)
  2495. t)
  2496. (defun idlwave-xemacs-hack-mouse-track (event)
  2497. (if (featurep 'xemacs)
  2498. (let ((oldfunc (symbol-function
  2499. 'default-mouse-track-event-is-with-button)))
  2500. (unwind-protect
  2501. (progn
  2502. (fset 'default-mouse-track-event-is-with-button
  2503. 'idlwave-default-mouse-track-event-is-with-button)
  2504. (mouse-track event))
  2505. (fset 'default-mouse-track-event-is-with-button oldfunc)))))
  2506. ;;; End terrible hack section
  2507. (defun idlwave-shell-mouse-print (event)
  2508. "Print value of variable at the mouse position, with `print'."
  2509. (interactive "e")
  2510. (funcall (idlwave-shell-mouse-examine nil) event))
  2511. (defun idlwave-shell-mouse-help (event)
  2512. "Print value of variable at the mouse position, with `help'."
  2513. (interactive "e")
  2514. (funcall (idlwave-shell-mouse-examine 'help) event))
  2515. (defun idlwave-shell-examine-select (event)
  2516. "Pop-up a list to select from for examining the expression."
  2517. (interactive "e")
  2518. (funcall (idlwave-shell-mouse-examine nil event) event))
  2519. (defmacro idlwave-shell-examine (help)
  2520. "Create a function for key-driven expression examination."
  2521. `(lambda ()
  2522. (interactive)
  2523. (idlwave-shell-print nil ,help)))
  2524. (defvar idlwave-shell-examine-label nil
  2525. "Label to include with examine text if in a separate buffer.")
  2526. (defvar idlwave-shell-examine-completion-list nil)
  2527. (defun idlwave-shell-print (arg &optional help ev complete-help-type)
  2528. "Print current expression.
  2529. With HELP non-nil, show help on expression. If HELP is a string,
  2530. the expression will be put in place of ___, e.g.:
  2531. print,size(___,/DIMENSIONS)
  2532. HELP can also be a cons cell ( NAME . STRING ) in which case NAME will
  2533. be used to label the help print-out.
  2534. Otherwise, print is called on the expression.
  2535. An expression is an identifier plus 1 pair of matched parentheses
  2536. directly following the identifier - an array or function call.
  2537. Alternatively, an expression is the contents of any matched
  2538. parentheses when the open parenthesis is not directly preceded by an
  2539. identifier. If point is at the beginning or within an expression
  2540. return the inner-most containing expression, otherwise, return the
  2541. preceding expression.
  2542. With prefix arg, or if transient mode set and the region is defined,
  2543. use the current region as the expression.
  2544. With double prefix arg ARG prompt for an expression.
  2545. If EV is a valid event passed, pop-up a list from
  2546. `idlwave-shell-examine-alist' from which to select the help
  2547. command text. If instead COMPLETE-HELP-TYPE is non-nil, choose
  2548. from `idlwave-shell-examine-alist' via mini-buffer shortcut key."
  2549. (interactive "P")
  2550. ;; For speed: assume the helper routine hasn't been lost, e.g. with
  2551. ;; .FULL_RESET_SESSION. We'll recover if necessary
  2552. (unless idlwave-idlwave_routine_info-compiled
  2553. (idlwave-shell-compile-helper-routines))
  2554. (save-excursion
  2555. (let* ((process (get-buffer-process (current-buffer)))
  2556. (process-mark (if process (process-mark process)))
  2557. (stack-label
  2558. (if (and (integerp idlwave-shell-calling-stack-index)
  2559. (> idlwave-shell-calling-stack-index 0))
  2560. (format " [-%d:%s]"
  2561. idlwave-shell-calling-stack-index
  2562. idlwave-shell-calling-stack-routine)))
  2563. expr beg end cmd)
  2564. (cond
  2565. ((equal arg '(16))
  2566. (setq expr (read-string "Expression: ")))
  2567. ((and (or arg (idlwave-region-active-p))
  2568. (< (- (region-end) (region-beginning)) 2000))
  2569. (setq beg (region-beginning)
  2570. end (region-end)))
  2571. (t
  2572. (idlwave-with-special-syntax
  2573. ;; Move to beginning of current or previous expression
  2574. (if (looking-at "\\<\\|(")
  2575. ;; At beginning of expression, don't move backwards unless
  2576. ;; this is at the end of an identifier.
  2577. (if (looking-at "\\>")
  2578. (backward-sexp))
  2579. (backward-sexp))
  2580. (if (looking-at "\\>")
  2581. ;; Move to beginning of identifier - must be an array or
  2582. ;; function expression.
  2583. (backward-sexp))
  2584. ;; Move to end of expression
  2585. (setq beg (point))
  2586. (forward-sexp)
  2587. (while (looking-at "\\>[[(]\\|\\.")
  2588. ;; an array
  2589. (forward-sexp))
  2590. (setq end (point)))))
  2591. ;; Get expression, but first move the begin mark if a
  2592. ;; process-mark is inside the region, to keep the overlay from
  2593. ;; wandering in the Shell.
  2594. (when (and beg end)
  2595. (if (and process-mark (> process-mark beg) (< process-mark end))
  2596. (setq beg (marker-position process-mark)))
  2597. (setq expr (buffer-substring beg end)))
  2598. ;; Show the overlay(s) and attach any necessary hooks and filters
  2599. (when (and beg end idlwave-shell-expression-overlay)
  2600. (move-overlay idlwave-shell-expression-overlay beg end
  2601. (current-buffer))
  2602. (add-hook 'pre-command-hook
  2603. 'idlwave-shell-delete-expression-overlay))
  2604. (add-hook 'pre-command-hook
  2605. 'idlwave-shell-delete-output-overlay)
  2606. ;; Remove empty or comment-only lines
  2607. (while (string-match "\n[ \t]*\\(;.*\\)?\r*\n" expr)
  2608. (setq expr (replace-match "\n" t t expr)))
  2609. ;; Concatenate continuation lines
  2610. (while (string-match "[ \t]*\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*\\|$\\)" expr)
  2611. (setq expr (replace-match "" t t expr)))
  2612. ;; Remove final newline
  2613. (if (string-match "\n[ \t\r]*\\'" expr)
  2614. (setq expr (replace-match "" t t expr)))
  2615. (catch 'exit
  2616. ;; Pop-up or complete on the examine selection list, if appropriate
  2617. (if (or
  2618. complete-help-type
  2619. (and ev idlwave-shell-examine-alist)
  2620. (consp help))
  2621. (let ((help-cons
  2622. (if (consp help) help
  2623. (assoc
  2624. ;; A cons from either a pop-up or mini-buffer completion
  2625. (if complete-help-type
  2626. (idlwave-one-key-select 'idlwave-shell-examine-alist
  2627. "Examine with: " 1.5)
  2628. ;; (idlwave-completing-read
  2629. ;; "Examine with: "
  2630. ;; idlwave-shell-examine-alist nil nil nil
  2631. ;; 'idlwave-shell-examine-completion-list
  2632. ;; "Print")
  2633. (idlwave-popup-select
  2634. ev
  2635. (mapcar 'car idlwave-shell-examine-alist)
  2636. "Examine with"))
  2637. idlwave-shell-examine-alist))))
  2638. (setq help (cdr help-cons))
  2639. (if (null help) (throw 'exit nil))
  2640. (if idlwave-shell-separate-examine-output
  2641. (setq idlwave-shell-examine-label
  2642. (concat
  2643. (format "==>%s<==\n%s:" expr (car help-cons))
  2644. stack-label "\n"))))
  2645. ;; The regular help label (no popups, cons cells, etc.)
  2646. (setq idlwave-shell-examine-label
  2647. (concat
  2648. (format "==>%s<==\n%s:" expr
  2649. (cond ((null help) "print")
  2650. ((stringp help) help)
  2651. (t (symbol-name help))))
  2652. stack-label "\n")))
  2653. ;; Send the command
  2654. (if stack-label
  2655. (setq expr (idlwave-retrieve-expression-from-level
  2656. expr
  2657. idlwave-shell-calling-stack-index)))
  2658. (setq cmd (idlwave-shell-help-statement help expr))
  2659. ;;(idlwave-shell-recenter-shell-window)
  2660. (idlwave-shell-send-command
  2661. cmd
  2662. 'idlwave-shell-check-compiled-and-display
  2663. (if idlwave-shell-separate-examine-output 'hide))))))
  2664. (defvar idlwave-shell-examine-window-alist nil
  2665. "Variable to hold the win/height pairs for all *Examine* windows.")
  2666. (defvar idlwave-shell-examine-map (make-sparse-keymap))
  2667. (define-key idlwave-shell-examine-map "q" 'idlwave-shell-examine-display-quit)
  2668. (define-key idlwave-shell-examine-map "c" 'idlwave-shell-examine-display-clear)
  2669. (defun idlwave-shell-check-compiled-and-display ()
  2670. "Check examine output for warning about undefined procedure/function."
  2671. (if (string-match "% Attempt to call undefined" idlwave-shell-command-output)
  2672. (idlwave-shell-compile-helper-routines))
  2673. (if idlwave-shell-separate-examine-output
  2674. (idlwave-shell-examine-display)
  2675. (idlwave-shell-examine-highlight)))
  2676. (defun idlwave-shell-examine-display ()
  2677. "View the examine command output in a separate buffer."
  2678. (let (win cur-beg cur-end)
  2679. (with-current-buffer (get-buffer-create "*Examine*")
  2680. (use-local-map idlwave-shell-examine-map)
  2681. (setq buffer-read-only nil)
  2682. (goto-char (point-max))
  2683. (save-restriction
  2684. (narrow-to-region (point) (point))
  2685. (if (string-match "^% Syntax error." idlwave-shell-command-output)
  2686. (insert "% Syntax error.\n")
  2687. (insert idlwave-shell-command-output)
  2688. ;; Just take the last bit between the prompts (if more than one).
  2689. (let* ((end (or
  2690. (re-search-backward idlwave-shell-prompt-pattern nil t)
  2691. (point-max)))
  2692. (beg (progn
  2693. (goto-char
  2694. (or (progn (if (re-search-backward
  2695. idlwave-shell-prompt-pattern nil t)
  2696. (match-end 0)))
  2697. (point-min)))
  2698. (re-search-forward "\n")))
  2699. (str (buffer-substring beg end)))
  2700. (delete-region (point-min) (point-max))
  2701. (insert str)
  2702. (if idlwave-shell-examine-label
  2703. (progn (goto-char (point-min))
  2704. (insert idlwave-shell-examine-label)
  2705. (setq idlwave-shell-examine-label nil)))))
  2706. (setq cur-beg (point-min)
  2707. cur-end (point-max))
  2708. (setq buffer-read-only t)
  2709. (move-overlay idlwave-shell-output-overlay cur-beg cur-end
  2710. (current-buffer))
  2711. ;; Look for the examine buffer in all windows. If one is
  2712. ;; found in a frame all by itself, use that, otherwise, switch
  2713. ;; to or create an examine window in this frame, and resize if
  2714. ;; it's a newly created window
  2715. (let* ((winlist (get-buffer-window-list "*Examine*" nil 'visible)))
  2716. (setq win (idlwave-display-buffer
  2717. "*Examine*"
  2718. nil
  2719. (let ((list winlist) thiswin)
  2720. (catch 'exit
  2721. (save-selected-window
  2722. (while (setq thiswin (pop list))
  2723. (select-window thiswin)
  2724. (if (one-window-p)
  2725. (throw 'exit (window-frame thiswin)))))))))
  2726. (set-window-start win (point-min)) ; Ensure the point is visible.
  2727. (save-selected-window
  2728. (select-window win)
  2729. (let ((elt (assoc win idlwave-shell-examine-window-alist)))
  2730. (when (and (not (one-window-p))
  2731. (or (not (memq win winlist)) ;a newly created window
  2732. (eq (window-height) (cdr elt))))
  2733. ;; Autosize it.
  2734. (enlarge-window (- (/ (frame-height) 2)
  2735. (window-height)))
  2736. (shrink-window-if-larger-than-buffer)
  2737. ;; Clean the window list of dead windows
  2738. (setq idlwave-shell-examine-window-alist
  2739. (delq nil
  2740. (mapcar (lambda (x) (if (window-live-p (car x)) x))
  2741. idlwave-shell-examine-window-alist)))
  2742. ;; And add the new value.
  2743. (if (setq elt (assoc win idlwave-shell-examine-window-alist))
  2744. (setcdr elt (window-height))
  2745. (add-to-list 'idlwave-shell-examine-window-alist
  2746. (cons win (window-height)))))))))
  2747. ;; Recenter for maximum output, after widened
  2748. (save-selected-window
  2749. (select-window win)
  2750. (goto-char (point-max))
  2751. (skip-chars-backward "\n")
  2752. (recenter -1)))))
  2753. (defun idlwave-shell-examine-display-quit ()
  2754. (interactive)
  2755. (let ((win (selected-window)))
  2756. (if (one-window-p)
  2757. (delete-frame (window-frame win))
  2758. (delete-window win))))
  2759. (defun idlwave-shell-examine-display-clear ()
  2760. (interactive)
  2761. (let ((buf (get-buffer "*Examine*")))
  2762. (when (bufferp buf)
  2763. (with-current-buffer buf
  2764. (let ((inhibit-read-only t))
  2765. (erase-buffer))))))
  2766. (defun idlwave-retrieve-expression-from-level (expr level)
  2767. "Return IDL command to print the expression EXPR from stack level LEVEL.
  2768. It does not seem possible to evaluate an expression on a different
  2769. level than the current. Therefore, this function retrieves variables
  2770. by reference from other levels, and then includes that variable in
  2771. place of the chosen one.
  2772. Since this function depends upon the undocumented IDL routine
  2773. routine_names, there is no guarantee that this will work with future
  2774. versions of IDL."
  2775. (let ((fetch (- 0 level))
  2776. (start 0)
  2777. var fetch-start fetch-end pre post)
  2778. ;; FIXME: In the following we try to find the variables in expression
  2779. ;; This is quite empirical - I don't know in what situations this will
  2780. ;; break. We will look for identifiers and exclude cases where we
  2781. ;; know it is not a variable. To distinguish array references from
  2782. ;; function calls, we require that arrays use [] instead of ()
  2783. (while (string-match
  2784. "\\(\\`\\|[^a-zA-Z0-9$_][ \t]*\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([ \t]*[^a-zA-Z0-9$_]\\|\\'\\)" expr start)
  2785. (setq var (match-string 2 expr)
  2786. start (match-end 2)
  2787. pre (substring expr 0 (match-beginning 2))
  2788. post (substring expr (match-end 2)))
  2789. (cond
  2790. ((or
  2791. ;; Exclude identifiers which are not variables
  2792. (string-match ",[ \t$\n]*/\\'" pre) ;; a `/' KEYWORD
  2793. (and (string-match "[,(][ \t\n]*\\'" pre)
  2794. (string-match "\\`[ \t]*=" post)) ;; a `=' KEYWORD
  2795. (string-match "\\`(" post) ;; a function
  2796. (string-match "->[ \t]*\\'" pre) ;; a method
  2797. (string-match "\\.\\'" pre))) ;; structure member
  2798. ;; Skip over strings
  2799. ((and (string-match "\\([\"\']\\)[^\1]*$" pre)
  2800. (string-match (concat "^[^" (match-string 1 pre) "]*"
  2801. (match-string 1 pre)) post))
  2802. (setq start (+ start (match-end 0))))
  2803. ;; seems to be a variable - delimit its name
  2804. (t
  2805. (put-text-property start (- start (length var)) 'fetch t expr))))
  2806. (setq start 0)
  2807. (while (setq fetch-start
  2808. (next-single-property-change start 'fetch expr))
  2809. (if (get-text-property start 'fetch expr) ; it's on in range
  2810. (setq fetch-end fetch-start ;it's off in range
  2811. fetch-start start)
  2812. (setq fetch-end (next-single-property-change fetch-start 'fetch expr)))
  2813. (unless fetch-end (setq fetch-end (length expr)))
  2814. (remove-text-properties fetch-start fetch-end '(fetch) expr)
  2815. (setq expr (concat (substring expr 0 fetch-start)
  2816. (format "(routine_names('%s',fetch=%d))"
  2817. (substring expr fetch-start fetch-end)
  2818. fetch)
  2819. (substring expr fetch-end)))
  2820. (setq start fetch-end))
  2821. (if (get-text-property 0 'fetch expr) ; Full expression, left over
  2822. (setq expr (format "(routine_names('%s',fetch=%d))" expr fetch)))
  2823. expr))
  2824. (defun idlwave-shell-help-statement (help expr)
  2825. "Construct a help statement for printing expression EXPR.
  2826. HELP can be non-nil for `help,', nil for 'print,' or any string into which
  2827. to insert expression in place of the marker ___, e.g.: print,
  2828. size(___,/DIMENSIONS)"
  2829. (cond
  2830. ((null help)
  2831. (concat "idlwave_print_safe, " expr ","
  2832. (number-to-string idlwave-shell-max-print-length)))
  2833. ((stringp help)
  2834. (if (string-match "\\(^\\|[^_]\\)\\(___\\)\\([^_]\\|$\\)" help)
  2835. (concat (substring help 0 (match-beginning 2))
  2836. expr
  2837. (substring help (match-end 2)))))
  2838. (t
  2839. (concat "help, " expr))))
  2840. (defun idlwave-shell-examine-highlight ()
  2841. "Highlight the most recent IDL output."
  2842. (let* ((buffer (get-buffer (idlwave-shell-buffer)))
  2843. (process (get-buffer-process buffer))
  2844. (process-mark (if process (process-mark process)))
  2845. output-begin output-end)
  2846. (with-current-buffer buffer
  2847. (goto-char process-mark)
  2848. (beginning-of-line)
  2849. (setq output-end (point))
  2850. (re-search-backward idlwave-shell-prompt-pattern nil t)
  2851. (beginning-of-line 2)
  2852. (setq output-begin (point)))
  2853. ;; First make sure the shell window is visible
  2854. (idlwave-display-buffer (idlwave-shell-buffer)
  2855. nil (idlwave-shell-shell-frame))
  2856. (if (and idlwave-shell-output-overlay process-mark)
  2857. (move-overlay idlwave-shell-output-overlay
  2858. output-begin output-end buffer))))
  2859. (defun idlwave-shell-delete-output-overlay ()
  2860. (unless (or (eq this-command 'idlwave-shell-mouse-nop)
  2861. (eq this-command 'handle-switch-frame))
  2862. (condition-case nil
  2863. (if idlwave-shell-output-overlay
  2864. (delete-overlay idlwave-shell-output-overlay))
  2865. (error nil))
  2866. (remove-hook 'pre-command-hook 'idlwave-shell-delete-output-overlay)))
  2867. (defun idlwave-shell-delete-expression-overlay ()
  2868. (unless (or (eq this-command 'idlwave-shell-mouse-nop)
  2869. (eq this-command 'handle-switch-frame))
  2870. (condition-case nil
  2871. (if idlwave-shell-expression-overlay
  2872. (delete-overlay idlwave-shell-expression-overlay))
  2873. (error nil))
  2874. (remove-hook 'pre-command-hook 'idlwave-shell-delete-expression-overlay)))
  2875. (defvar idlwave-shell-bp-alist nil
  2876. "Alist of breakpoints.
  2877. A breakpoint is a cons cell \(\(file line\) . \(\(index module\) data\)\)
  2878. The car is the `frame' for the breakpoint:
  2879. file - full path file name.
  2880. line - line number of breakpoint - integer.
  2881. The first element of the cdr is a list of internal IDL data:
  2882. index - the index number of the breakpoint internal to IDL.
  2883. module - the module for breakpoint internal to IDL.
  2884. Remaining elements of the cdr:
  2885. data - Data associated with the breakpoint by idlwave-shell currently
  2886. contains four items:
  2887. count - number of times to execute breakpoint. When count reaches 0
  2888. the breakpoint is cleared and removed from the alist.
  2889. command - command to execute when breakpoint is reached, either a
  2890. lisp function to be called with `funcall' with no arguments or a
  2891. list to be evaluated with `eval'.
  2892. condition - any condition to apply to the breakpoint.
  2893. disabled - whether the bp is disabled.")
  2894. (defun idlwave-shell-run-region (beg end &optional n)
  2895. "Compile and run the region using the IDL process.
  2896. Copies the region to a temporary file `idlwave-shell-temp-pro-file'
  2897. and issues the IDL .run command for the file. Because the region
  2898. is compiled and run as a main program there is no problem with
  2899. begin-end blocks extending over multiple lines - which would be
  2900. a problem if `idlwave-shell-evaluate-region' was used.
  2901. An END statement is appended to the region if necessary.
  2902. If there is a prefix argument, display IDL process."
  2903. (interactive "r\nP")
  2904. (let ((oldbuf (current-buffer)))
  2905. (with-current-buffer (idlwave-find-file-noselect
  2906. (idlwave-shell-temp-file 'pro) 'tmp)
  2907. (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
  2908. (set (make-local-variable 'comment-start) ";")
  2909. (erase-buffer)
  2910. (insert-buffer-substring oldbuf beg end)
  2911. (if (not (save-excursion
  2912. (idlwave-previous-statement)
  2913. (idlwave-look-at "\\<end\\>")))
  2914. (insert "\nend\n"))
  2915. (save-buffer 0)))
  2916. (idlwave-shell-send-command (concat ".run \""
  2917. idlwave-shell-temp-pro-file "\"")
  2918. nil
  2919. (if (idlwave-shell-hide-p 'run) 'mostly)
  2920. nil t)
  2921. (if n
  2922. (idlwave-display-buffer (idlwave-shell-buffer)
  2923. nil (idlwave-shell-shell-frame))))
  2924. (defun idlwave-shell-evaluate-region (beg end &optional n)
  2925. "Send region to the IDL process.
  2926. If there is a prefix argument, display IDL process.
  2927. Does not work for a region with multiline blocks - use
  2928. `idlwave-shell-run-region' for this."
  2929. (interactive "r\nP")
  2930. (idlwave-shell-send-command (buffer-substring beg end))
  2931. (if n
  2932. (idlwave-display-buffer (idlwave-shell-buffer)
  2933. nil (idlwave-shell-shell-frame))))
  2934. (defun idlwave-shell-delete-temp-files ()
  2935. "Delete the temporary files and kill associated buffers."
  2936. (if (stringp idlwave-shell-temp-pro-file)
  2937. (condition-case nil
  2938. (let ((buf (idlwave-get-buffer-visiting
  2939. idlwave-shell-temp-pro-file)))
  2940. (if (buffer-live-p buf)
  2941. (kill-buffer buf))
  2942. (delete-file idlwave-shell-temp-pro-file))
  2943. (error nil)))
  2944. (if (stringp idlwave-shell-temp-rinfo-save-file)
  2945. (condition-case nil
  2946. (delete-file idlwave-shell-temp-rinfo-save-file)
  2947. (error nil))))
  2948. (defun idlwave-display-buffer (buf not-this-window-p &optional frame)
  2949. (if (featurep 'xemacs)
  2950. ;; The XEmacs version enforces the frame
  2951. (display-buffer buf not-this-window-p frame)
  2952. ;; For Emacs, we need to force the frame ourselves.
  2953. (let ((this-frame (selected-frame)))
  2954. (save-excursion ;; make sure we end up in the same buffer
  2955. (if (frame-live-p frame)
  2956. (select-frame frame))
  2957. (if (eq this-frame (selected-frame))
  2958. ;; same frame: use display buffer, to make sure the current
  2959. ;; window stays.
  2960. (display-buffer buf)
  2961. ;; different frame
  2962. (if (one-window-p)
  2963. ;; only window: switch
  2964. (progn
  2965. (switch-to-buffer buf)
  2966. (selected-window)) ; must return the window.
  2967. ;; several windows - use display-buffer
  2968. (display-buffer buf not-this-window-p)))))))
  2969. ; (if (not (frame-live-p frame)) (setq frame nil))
  2970. ; (display-buffer buf not-this-window-p frame))
  2971. (defvar idlwave-shell-bp-buffer " *idlwave-shell-bp*"
  2972. "Scratch buffer for parsing IDL breakpoint lists and other stuff.")
  2973. (defun idlwave-shell-bp-query (&optional no-show)
  2974. "Reconcile idlwave-shell's breakpoint list with IDL's.
  2975. Queries IDL using the string in `idlwave-shell-bp-query'."
  2976. (interactive)
  2977. (idlwave-shell-send-command idlwave-shell-bp-query
  2978. `(progn
  2979. (idlwave-shell-filter-bp (quote ,no-show)))
  2980. 'hide))
  2981. (defun idlwave-shell-bp-get (bp &optional item)
  2982. "Get a value for a breakpoint.
  2983. BP has the form of elements in `idlwave-shell-bp-alist'.
  2984. Optional second arg ITEM is the particular value to retrieve.
  2985. ITEM can be 'file, 'line, 'index, 'module, 'count, 'cmd,
  2986. 'condition, 'disabled, 'type, or 'data. 'data returns a list
  2987. of 'count, 'cmd and 'condition. Defaults to 'index."
  2988. (cond
  2989. ;; Frame
  2990. ((eq item 'line) (nth 1 (car bp)))
  2991. ((eq item 'file) (nth 0 (car bp)))
  2992. ;; idlwave-shell breakpoint data
  2993. ((eq item 'data) (cdr (cdr bp)))
  2994. ((eq item 'count) (nth 0 (cdr (cdr bp))))
  2995. ((eq item 'cmd) (nth 1 (cdr (cdr bp))))
  2996. ((eq item 'condition) (nth 2 (cdr (cdr bp))))
  2997. ((eq item 'disabled) (nth 3 (cdr (cdr bp))))
  2998. ;; IDL breakpoint info
  2999. ((eq item 'module)
  3000. (let ((module (nth 1 (car (cdr bp)))))
  3001. (if (listp module) (car module) module)))
  3002. ((eq item 'type)
  3003. (let ((module (nth 1 (car (cdr bp)))))
  3004. (if (listp module) (nth 1 module))))
  3005. ;; index - default
  3006. (t (nth 0 (car (cdr bp))))))
  3007. (defun idlwave-shell-filter-bp (&optional no-show)
  3008. "Get the breakpoints from `idlwave-shell-command-output'.
  3009. Create `idlwave-shell-bp-alist' updating breakpoint count and command
  3010. data from previous breakpoint list. If NO-SHOW is set, don't update
  3011. the breakpoint overlays."
  3012. (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer)
  3013. (erase-buffer)
  3014. (insert idlwave-shell-command-output)
  3015. (goto-char (point-min))
  3016. (let ((old-bp-alist idlwave-shell-bp-alist)
  3017. ;; Searching the breakpoints
  3018. ;; In IDL 5.5, the breakpoint reporting format changed.
  3019. (bp-re54 "^[ \t]*\\([0-9]+\\)[ \t]+\\(\\S-+\\)?[ \t]+\\([0-9]+\\)[ \t]+\\(\\S-+\\)")
  3020. (bp-re55
  3021. (concat
  3022. "^\\s-*\\([0-9]+\\)" ; 1 index
  3023. "\\s-+\\([0-9]+\\)" ; 2 line number
  3024. "\\s-+\\(Uncompiled\\|" ; 3-6 either uncompiled or routine name
  3025. "\\(\\(Func=\\|Pro=\\)\\(\\$?[a-zA-Z][a-zA-Z0-9$_:]*\\$?\\)\\)\\)"
  3026. "\\(\\s-*,\\s-*After=[0-9]+/\\([0-9]+\\)?\\)?" ; 7-8 After part
  3027. "\\(\\s-*,\\s-*\\(BreakOnce\\)\\)?" ; 9-10 BreakOnce
  3028. "\\(\\s-*,\\s-*\\(Condition='\\(.*\\)'\\)\n?\\)?" ; 11-13 Condition
  3029. "\\(\\s-*,\\s-*\\(Disabled\\)\n?\\)?" ; 14-15 Disabled
  3030. "\\s-+\\(\\S-+\\)")) ; 16 File name
  3031. file line index module
  3032. count condition disabled
  3033. bp-re indmap)
  3034. (setq idlwave-shell-bp-alist (list nil))
  3035. ;; Search for either header type, and set the correct regexp
  3036. (when (or
  3037. (if (re-search-forward "^\\s-*Index.*\n\\s-*-" nil t)
  3038. (setq bp-re bp-re54 ; versions <= 5.4
  3039. indmap '(1 2 3 4))) ;index module line file
  3040. (if (re-search-forward
  3041. "^\\s-*Index\\s-*Line\\s-*Attributes\\s-*File" nil t)
  3042. (setq bp-re bp-re55 ; versions >= 5.5
  3043. indmap '(1 6 2 16)))) ; index module line file
  3044. ;; There seems to be a breakpoint listing here, parse breakpoint lines.
  3045. (while (re-search-forward bp-re nil t)
  3046. (setq index (string-to-number (match-string (nth 0 indmap)))
  3047. module (match-string (nth 1 indmap))
  3048. line (string-to-number (match-string (nth 2 indmap)))
  3049. file (idlwave-shell-file-name (match-string (nth 3 indmap))))
  3050. (if (eq bp-re bp-re55)
  3051. (setq count (if (match-string 10) 1
  3052. (if (match-string 8)
  3053. (string-to-number (match-string 8))))
  3054. condition (match-string 13)
  3055. disabled (not (null (match-string 15)))))
  3056. ;; Add the breakpoint info to the list
  3057. (nconc idlwave-shell-bp-alist
  3058. (list (cons (list file line)
  3059. (list
  3060. (list index module)
  3061. ;; bp data: count, command, condition, disabled
  3062. count nil condition disabled))))))
  3063. (setq idlwave-shell-bp-alist (cdr idlwave-shell-bp-alist))
  3064. ;; Update breakpoint data
  3065. (if (eq bp-re bp-re54)
  3066. (mapc 'idlwave-shell-update-bp old-bp-alist)
  3067. (mapc 'idlwave-shell-update-bp-command-only old-bp-alist))))
  3068. ;; Update the breakpoint overlays
  3069. (unless no-show (idlwave-shell-update-bp-overlays))
  3070. ;; Return the new list
  3071. idlwave-shell-bp-alist)
  3072. (defun idlwave-shell-update-bp-command-only (bp)
  3073. (idlwave-shell-update-bp bp t))
  3074. (defun idlwave-shell-update-bp (bp &optional command-only)
  3075. "Update BP data in breakpoint list.
  3076. If BP frame is in `idlwave-shell-bp-alist' updates the breakpoint data."
  3077. (let ((match (assoc (car bp) idlwave-shell-bp-alist)))
  3078. (if match
  3079. (if command-only
  3080. (setf (nth 1 (cdr (cdr match))) (nth 1 (cdr (cdr match))))
  3081. (setcdr (cdr match) (cdr (cdr bp)))))))
  3082. (defun idlwave-shell-set-bp-data (bp data)
  3083. "Set the data of BP to DATA."
  3084. (setcdr (cdr bp) data))
  3085. (defun idlwave-shell-bp (frame &optional data module)
  3086. "Create a breakpoint structure containing FRAME and DATA.
  3087. Second and third args, DATA and MODULE, are optional. Returns
  3088. a breakpoint of the format used in `idlwave-shell-bp-alist'.
  3089. Can be used in commands attempting match a breakpoint in
  3090. `idlwave-shell-bp-alist'."
  3091. (cons frame ;; (file line)
  3092. (cons (list nil module) ;; (index_id (module type) | module)
  3093. data))) ;; (count command condition disabled)
  3094. (defvar idlwave-shell-old-bp nil
  3095. "List of breakpoints previous to setting a new breakpoint.")
  3096. (defun idlwave-shell-sources-bp (bp)
  3097. "Check `idlwave-shell-sources-alist' for source of breakpoint using BP.
  3098. If an equivalency is found, return the IDL internal source name.
  3099. Otherwise return the filename in BP."
  3100. (let*
  3101. ((bp-file (idlwave-shell-bp-get bp 'file))
  3102. (bp-module (idlwave-shell-bp-get bp 'module))
  3103. (internal-file-list
  3104. (if bp-module
  3105. (cdr (assoc bp-module idlwave-shell-sources-alist)))))
  3106. (if (and internal-file-list
  3107. (equal bp-file (nth 0 internal-file-list)))
  3108. (nth 1 internal-file-list)
  3109. bp-file)))
  3110. (defun idlwave-shell-set-bp (bp &optional no-show)
  3111. "Try to set a breakpoint BP.
  3112. The breakpoint will be placed at the beginning of the statement on the
  3113. line specified by BP or at the next IDL statement if that line is not
  3114. a statement. Determines IDL's internal representation for the
  3115. breakpoint, which may have occurred at a different line than
  3116. specified. If NO-SHOW is non-nil, don't do any updating."
  3117. ;; Get and save the old breakpoints
  3118. (idlwave-shell-send-command
  3119. idlwave-shell-bp-query
  3120. `(progn
  3121. (idlwave-shell-filter-bp (quote ,no-show))
  3122. (setq idlwave-shell-old-bp idlwave-shell-bp-alist))
  3123. 'hide)
  3124. ;; Get sources for this routine in the sources list
  3125. (idlwave-shell-module-source-query (idlwave-shell-bp-get bp 'module)
  3126. (idlwave-shell-bp-get bp 'type))
  3127. (let*
  3128. ((count (idlwave-shell-bp-get bp 'count))
  3129. (condition (idlwave-shell-bp-get bp 'condition))
  3130. (disabled (idlwave-shell-bp-get bp 'disabled))
  3131. (key (concat (if (and count (numberp count))
  3132. (cond
  3133. ((= count 1) ",/once")
  3134. ((> count 1) (format ",after=%d" count))))
  3135. (if condition (concat ",CONDITION=\"" condition "\""))
  3136. ;; IDL can't simultaneously set a condition/count
  3137. ;; and disable a breakpoint, but it does keep both
  3138. ;; of these when resetting the same BP. We assume
  3139. ;; DISABLE and CONDITION/COUNT are not set
  3140. ;; together for a newly created breakpoint.
  3141. (if (and disabled (not condition) (not count))
  3142. ",/DISABLE")))
  3143. (line (idlwave-shell-bp-get bp 'line)))
  3144. (idlwave-shell-send-command
  3145. (concat "breakpoint,'"
  3146. (idlwave-shell-sources-bp bp) "',"
  3147. (if (integerp line) (setq line (int-to-string line)))
  3148. key)
  3149. ;; Check for failure and adjust breakpoint to match IDL's list
  3150. `(progn
  3151. (if (idlwave-shell-set-bp-check (quote ,bp))
  3152. (idlwave-shell-set-bp-adjust (quote ,bp) (quote ,no-show))))
  3153. ;; hide output?
  3154. (idlwave-shell-hide-p 'breakpoint)
  3155. 'preempt t)))
  3156. (defun idlwave-shell-set-bp-adjust (bp &optional no-show)
  3157. "Find the breakpoint in IDL's internal list of breakpoints."
  3158. (idlwave-shell-send-command
  3159. idlwave-shell-bp-query
  3160. `(progn
  3161. (idlwave-shell-filter-bp 'no-show)
  3162. (idlwave-shell-new-bp (quote ,bp))
  3163. (unless (quote ,no-show)
  3164. (idlwave-shell-update-bp-overlays)))
  3165. 'hide
  3166. 'preempt))
  3167. (defun idlwave-shell-find-bp (frame)
  3168. "Return breakpoint from `idlwave-shell-bp-alist' for frame.
  3169. Returns nil if frame not found."
  3170. (assoc frame idlwave-shell-bp-alist))
  3171. (defun idlwave-shell-find-current-bp ()
  3172. "Find breakpoint here, or at halt location."
  3173. (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame))))
  3174. (when (not bp)
  3175. ;; Try moving to beginning of halted-at statement
  3176. (save-excursion
  3177. (idlwave-shell-goto-frame)
  3178. (idlwave-beginning-of-statement)
  3179. (setq bp (idlwave-shell-find-bp (idlwave-shell-current-frame))))
  3180. (unless bp
  3181. (beep)
  3182. (message "Cannot identify breakpoint for this line")))
  3183. bp))
  3184. (defun idlwave-shell-new-bp (bp)
  3185. "Find the new breakpoint in IDL's list and update with DATA.
  3186. The actual line number for a breakpoint in IDL may be different than
  3187. the line number used with the IDL breakpoint command.
  3188. Looks for a new breakpoint index number in the list. This is
  3189. considered the new breakpoint if the file name of frame matches."
  3190. (let ((obp-index (mapcar 'idlwave-shell-bp-get idlwave-shell-old-bp))
  3191. (bpl idlwave-shell-bp-alist))
  3192. (while (and (member (idlwave-shell-bp-get (car bpl)) obp-index)
  3193. (setq bpl (cdr bpl))))
  3194. (if (and
  3195. (not bpl)
  3196. ;; No additional breakpoint.
  3197. ;; Need to check if we are just replacing a breakpoint.
  3198. (setq bpl (assoc (car bp) idlwave-shell-bp-alist)))
  3199. (setq bpl (list bpl)))
  3200. (if (and bpl
  3201. (equal (idlwave-shell-bp-get (setq bpl (car bpl)) 'file)
  3202. (idlwave-shell-bp-get bp 'file)))
  3203. ;; Got the breakpoint - add count, command to it.
  3204. ;; This updates `idlwave-shell-bp-alist' because a deep copy was
  3205. ;; not done for bpl.
  3206. (idlwave-shell-set-bp-data bpl (idlwave-shell-bp-get bp 'data))
  3207. (beep)
  3208. (message "Failed to identify breakpoint in IDL"))))
  3209. (defvar idlwave-shell-bp-overlays nil
  3210. "Alist of overlays marking breakpoints.")
  3211. (defvar idlwave-shell-bp-glyph)
  3212. (defvar idlwave-shell-debug-line-map (make-sparse-keymap))
  3213. (define-key idlwave-shell-debug-line-map
  3214. (if (featurep 'xemacs) [button3] [mouse-3])
  3215. 'idlwave-shell-mouse-active-bp)
  3216. (defun idlwave-shell-update-bp-overlays ()
  3217. "Update the overlays which mark breakpoints in the source code.
  3218. Existing overlays are recycled, in order to minimize consumption."
  3219. (when idlwave-shell-mark-breakpoints
  3220. (let ((ov-alist (copy-alist idlwave-shell-bp-overlays))
  3221. (bp-list idlwave-shell-bp-alist)
  3222. (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph))
  3223. idlwave-shell-bp-glyph))
  3224. ov ov-list bp buf old-buffers win)
  3225. ;; Delete the old overlays from their buffers
  3226. (if ov-alist
  3227. (while (setq ov-list (pop ov-alist))
  3228. (while (setq ov (pop (cdr ov-list)))
  3229. (add-to-list 'old-buffers (overlay-buffer ov))
  3230. (delete-overlay ov))))
  3231. (setq ov-alist idlwave-shell-bp-overlays
  3232. idlwave-shell-bp-overlays
  3233. (if idlwave-shell-bp-glyph
  3234. (mapcar 'list (mapcar 'car idlwave-shell-bp-glyph))
  3235. (list (list 'bp))))
  3236. (while (setq bp (pop bp-list))
  3237. (save-excursion
  3238. (idlwave-shell-goto-frame (car bp))
  3239. (let* ((end (point-at-eol))
  3240. (beg (progn (beginning-of-line 1) (point)))
  3241. (condition (idlwave-shell-bp-get bp 'condition))
  3242. (count (idlwave-shell-bp-get bp 'count))
  3243. (disabled (idlwave-shell-bp-get bp 'disabled))
  3244. (type (if idlwave-shell-bp-glyph
  3245. (cond
  3246. (condition 'bp-cond )
  3247. (count
  3248. (cond
  3249. ((<= count 0) 'bp)
  3250. ((<= count 4)
  3251. (intern
  3252. (concat "bp-" (number-to-string count))))
  3253. (t 'bp-n)))
  3254. (t 'bp))
  3255. 'bp))
  3256. (help-list
  3257. (delq nil
  3258. (list
  3259. (if count
  3260. (concat "after:" (int-to-string count)))
  3261. (if condition
  3262. (concat "condition:" condition))
  3263. (if disabled "disabled"))))
  3264. (help-text (concat
  3265. "BP "
  3266. (int-to-string (idlwave-shell-bp-get bp))
  3267. (if help-list
  3268. (concat
  3269. " - "
  3270. (mapconcat 'identity help-list ", ")))
  3271. (if (and (not count) (not condition))
  3272. " (use mouse-3 for breakpoint actions)")))
  3273. (full-type (if disabled
  3274. (intern (concat (symbol-name type)
  3275. "-disabled"))
  3276. type))
  3277. (ov-existing (assq full-type ov-alist))
  3278. (ov (or (and (cdr ov-existing)
  3279. (pop (cdr ov-existing)))
  3280. (idlwave-shell-make-new-bp-overlay type disabled)))
  3281. match)
  3282. (if idlwave-shell-breakpoint-popup-menu
  3283. (overlay-put ov 'help-echo help-text))
  3284. (move-overlay ov beg end)
  3285. (if (setq match (assq full-type idlwave-shell-bp-overlays))
  3286. (push ov (cdr match))
  3287. (nconc idlwave-shell-bp-overlays
  3288. (list (list full-type ov)))))
  3289. ;; Take care of margins if using a glyph
  3290. (when use-glyph
  3291. (if old-buffers
  3292. (setq old-buffers (delq (current-buffer) old-buffers)))
  3293. (if (fboundp 'set-specifier) ;; XEmacs
  3294. (set-specifier left-margin-width (cons (current-buffer) 2))
  3295. (if (< left-margin-width 2)
  3296. (setq left-margin-width 2)))
  3297. (let ((window (get-buffer-window (current-buffer) 0)))
  3298. (if window
  3299. (set-window-margins
  3300. window left-margin-width right-margin-width))))))
  3301. (if use-glyph
  3302. (while (setq buf (pop old-buffers))
  3303. (with-current-buffer buf
  3304. (if (fboundp 'set-specifier) ;; XEmacs
  3305. (set-specifier left-margin-width (cons (current-buffer) 0))
  3306. (setq left-margin-width 0))
  3307. (let ((window (get-buffer-window buf 0)))
  3308. (if window
  3309. (set-window-margins
  3310. window left-margin-width right-margin-width)))))))))
  3311. (defun idlwave-shell-make-new-bp-overlay (&optional type disabled)
  3312. "Make a new overlay for highlighting breakpoints.
  3313. This stuff is strongly dependent upon the version of Emacs. If TYPE
  3314. is passed, make an overlay of that type ('bp or 'bp-cond, currently
  3315. only for glyphs)."
  3316. (let ((ov (make-overlay 1 1))
  3317. (use-glyph (and (memq idlwave-shell-mark-breakpoints '(t glyph))
  3318. idlwave-shell-bp-glyph))
  3319. (type (or type 'bp))
  3320. (face (if disabled
  3321. idlwave-shell-disabled-breakpoint-face
  3322. idlwave-shell-breakpoint-face)))
  3323. (if (featurep 'xemacs)
  3324. ;; This is XEmacs
  3325. (progn
  3326. (when idlwave-shell-breakpoint-popup-menu
  3327. (set-extent-property ov 'mouse-face 'highlight)
  3328. (set-extent-property ov 'keymap idlwave-shell-debug-line-map))
  3329. (cond
  3330. ;; tty's cannot display glyphs
  3331. ((eq (console-type) 'tty)
  3332. (set-extent-property ov 'face face))
  3333. ;; use the glyph
  3334. (use-glyph
  3335. (let ((glyph (cdr (assq type idlwave-shell-bp-glyph))))
  3336. (if disabled (setq glyph (car glyph)) (setq glyph (nth 1 glyph)))
  3337. (set-extent-property ov 'begin-glyph glyph)
  3338. (set-extent-property ov 'begin-glyph-layout 'outside-margin)))
  3339. ;; use the face
  3340. (idlwave-shell-mark-breakpoints
  3341. (set-extent-property ov 'face face))
  3342. ;; no marking
  3343. (t nil))
  3344. (set-extent-priority ov -1)) ; make stop line face prevail
  3345. ;; This is Emacs
  3346. (when idlwave-shell-breakpoint-popup-menu
  3347. (overlay-put ov 'mouse-face 'highlight)
  3348. (overlay-put ov 'keymap idlwave-shell-debug-line-map))
  3349. (cond
  3350. (window-system
  3351. (if use-glyph
  3352. (let ((image-props (cdr (assq type idlwave-shell-bp-glyph)))
  3353. string)
  3354. (if disabled (setq image-props
  3355. (append image-props
  3356. (list :conversion 'disabled))))
  3357. (setq string
  3358. (propertize "@"
  3359. 'display
  3360. (list (list 'margin 'left-margin)
  3361. image-props)))
  3362. (overlay-put ov 'before-string string))
  3363. ;; just the face
  3364. (overlay-put ov 'face face)))
  3365. ;; use a face
  3366. (idlwave-shell-mark-breakpoints
  3367. (overlay-put ov 'face face))
  3368. ;; No marking
  3369. (t nil)))
  3370. ov))
  3371. (defun idlwave-shell-mouse-active-bp (ev)
  3372. "Does right-click mouse action on breakpoint lines."
  3373. (interactive "e")
  3374. (if ev (mouse-set-point ev))
  3375. (let ((bp (idlwave-shell-find-bp (idlwave-shell-current-frame)))
  3376. index condition count select cmd disabled)
  3377. (unless bp
  3378. (error "Breakpoint not found"))
  3379. (setq index (int-to-string (idlwave-shell-bp-get bp))
  3380. condition (idlwave-shell-bp-get bp 'condition)
  3381. cmd (idlwave-shell-bp-get bp 'cmd)
  3382. count (idlwave-shell-bp-get bp 'count)
  3383. disabled (idlwave-shell-bp-get bp 'disabled))
  3384. (setq select (idlwave-popup-select
  3385. ev
  3386. (delq nil
  3387. (list (if disabled "Enable" "Disable")
  3388. "Clear"
  3389. "Clear All"
  3390. (if condition "Remove Condition" "Add Condition")
  3391. (if condition "Change Condition")
  3392. (if count "Remove Repeat Count"
  3393. "Add Repeat Count")
  3394. (if count "Change Repeat Count")))
  3395. (concat "BreakPoint " index)))
  3396. (if select
  3397. (cond
  3398. ((string-equal select "Clear All")
  3399. (idlwave-shell-clear-all-bp))
  3400. ((string-equal select "Clear")
  3401. (idlwave-shell-clear-current-bp))
  3402. ((string-match "Condition" select)
  3403. (idlwave-shell-break-here count cmd
  3404. (if (or (not condition)
  3405. (string-match "Change" select))
  3406. (read-string "Break Condition: "))
  3407. disabled))
  3408. ((string-match "Count" select)
  3409. (idlwave-shell-break-here (if (or (not count)
  3410. (string-match "Change" select))
  3411. (string-to-number
  3412. (read-string "Break After Count: ")))
  3413. cmd condition disabled))
  3414. ((string-match "able$" select)
  3415. (idlwave-shell-toggle-enable-current-bp))
  3416. (t
  3417. (message "Unimplemented: %s" select))))))
  3418. (defun idlwave-shell-edit-default-command-line (arg)
  3419. "Edit the current execute command."
  3420. (interactive "P")
  3421. (setq idlwave-shell-command-line-to-execute
  3422. (read-string "IDL> " idlwave-shell-command-line-to-execute)))
  3423. (defun idlwave-shell-execute-default-command-line (arg)
  3424. "Execute a command line. On first use, ask for the command.
  3425. Also with prefix arg, ask for the command. You can also use the command
  3426. `idlwave-shell-edit-default-command-line' to edit the line."
  3427. (interactive "P")
  3428. (cond
  3429. ((equal arg '(16))
  3430. (setq idlwave-shell-command-line-to-execute nil))
  3431. ((equal arg '(4))
  3432. (setq idlwave-shell-command-line-to-execute
  3433. (read-string "IDL> " idlwave-shell-command-line-to-execute))))
  3434. (idlwave-shell-reset 'hidden)
  3435. (idlwave-shell-send-command
  3436. (or idlwave-shell-command-line-to-execute
  3437. (with-current-buffer (idlwave-shell-buffer)
  3438. (ring-ref comint-input-ring 0)))
  3439. '(idlwave-shell-redisplay 'hide)))
  3440. (defun idlwave-shell-save-and-run ()
  3441. "Save file and run it in IDL.
  3442. Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
  3443. When called from the shell buffer, re-run the file which was last handled by
  3444. one of the save-and-.. commands."
  3445. (interactive)
  3446. (idlwave-shell-save-and-action 'run))
  3447. (defun idlwave-shell-save-and-compile ()
  3448. "Save file and run it in IDL.
  3449. Runs `save-buffer' and sends '.COMPILE' command for the associated file to IDL.
  3450. When called from the shell buffer, re-compile the file which was last handled by
  3451. one of the save-and-.. commands."
  3452. (interactive)
  3453. (idlwave-shell-save-and-action 'compile))
  3454. (defun idlwave-shell-save-and-batch ()
  3455. "Save file and batch it in IDL.
  3456. Runs `save-buffer' and sends a '@file' command for the associated file to IDL.
  3457. When called from the shell buffer, re-batch the file which was last handled by
  3458. one of the save-and-.. commands."
  3459. (interactive)
  3460. (idlwave-shell-save-and-action 'batch))
  3461. (defun idlwave-shell-save-and-action (action)
  3462. "Save file and compile it in IDL.
  3463. Runs `save-buffer' and sends a '.RUN' command for the associated file to IDL.
  3464. When called from the shell buffer, re-compile the file which was last
  3465. handled by this command."
  3466. ;; Remove the stop overlay.
  3467. (if idlwave-shell-stop-line-overlay
  3468. (delete-overlay idlwave-shell-stop-line-overlay))
  3469. (if idlwave-shell-is-stopped
  3470. (idlwave-shell-electric-debug-all-off))
  3471. (setq idlwave-shell-is-stopped nil)
  3472. (setq overlay-arrow-string nil)
  3473. (let (buf)
  3474. (cond
  3475. ((derived-mode-p 'idlwave-mode)
  3476. (save-buffer)
  3477. (setq idlwave-shell-last-save-and-action-file (buffer-file-name)))
  3478. (idlwave-shell-last-save-and-action-file
  3479. (if (setq buf (idlwave-get-buffer-visiting
  3480. idlwave-shell-last-save-and-action-file))
  3481. (with-current-buffer buf
  3482. (save-buffer))))
  3483. (t (setq idlwave-shell-last-save-and-action-file
  3484. (read-file-name "File: ")))))
  3485. (if (file-regular-p idlwave-shell-last-save-and-action-file)
  3486. (progn
  3487. (idlwave-shell-send-command
  3488. (concat (cond ((eq action 'run) ".run ")
  3489. ((eq action 'compile) ".compile ")
  3490. ((eq action 'batch) "@")
  3491. (t (error "Unknown action %s" action)))
  3492. "\""
  3493. idlwave-shell-last-save-and-action-file
  3494. "\"")
  3495. `(idlwave-shell-maybe-update-routine-info nil
  3496. ,idlwave-shell-last-save-and-action-file)
  3497. (if (idlwave-shell-hide-p 'run) 'mostly) nil t)
  3498. (idlwave-shell-bp-query))
  3499. (let ((msg (format "No such file %s"
  3500. idlwave-shell-last-save-and-action-file)))
  3501. (setq idlwave-shell-last-save-and-action-file nil)
  3502. (error msg))))
  3503. (defun idlwave-shell-maybe-update-routine-info (&optional wait file)
  3504. "Update the routine info if the shell is not stopped at an error."
  3505. (if (and (not idlwave-shell-is-stopped)
  3506. (or (eq t idlwave-auto-routine-info-updates)
  3507. (memq 'compile-buffer idlwave-auto-routine-info-updates))
  3508. idlwave-query-shell-for-routine-info
  3509. idlwave-routines)
  3510. (idlwave-shell-update-routine-info t nil wait file)))
  3511. (defvar idlwave-shell-sources-query "help,/source,/full"
  3512. "IDL command to obtain source files for compiled procedures.")
  3513. (defvar idlwave-shell-sources-alist nil
  3514. "Alist of IDL procedure names and compiled source files.
  3515. Elements of the alist have the form:
  3516. (module name . (source-file-truename idlwave-internal-filename))")
  3517. (defun idlwave-shell-module-source-query (module &optional type)
  3518. "Determine the source file for a given module.
  3519. Query as a function if TYPE set to something beside 'pro."
  3520. (if module
  3521. (idlwave-shell-send-command
  3522. (format "print,(routine_info('%s',/SOURCE%s)).PATH" module
  3523. (if (eq type 'pro) "" ",/FUNCTIONS"))
  3524. `(idlwave-shell-module-source-filter ,module)
  3525. 'hide 'wait)))
  3526. (defun idlwave-shell-module-source-filter (module)
  3527. "Get module source, and update `idlwave-shell-sources-alist'."
  3528. (let ((old (assoc (upcase module) idlwave-shell-sources-alist))
  3529. filename)
  3530. (when (string-match "\.PATH *[\n\r]\\([^%][^\r\n]+\\)[\n\r]"
  3531. idlwave-shell-command-output)
  3532. (setq filename (substring idlwave-shell-command-output
  3533. (match-beginning 1) (match-end 1)))
  3534. (if old
  3535. (setcdr old (list (idlwave-shell-file-name filename) filename))
  3536. (setq idlwave-shell-sources-alist
  3537. (append idlwave-shell-sources-alist
  3538. (list (cons (upcase module)
  3539. (list (idlwave-shell-file-name filename)
  3540. filename)))))))))
  3541. (defun idlwave-shell-sources-query ()
  3542. "Determine source files for all IDL compiled procedures.
  3543. Queries IDL using the string in `idlwave-shell-sources-query'."
  3544. (interactive)
  3545. (idlwave-shell-send-command idlwave-shell-sources-query
  3546. 'idlwave-shell-sources-filter
  3547. 'hide))
  3548. (defun idlwave-shell-sources-filter ()
  3549. "Get source files from `idlwave-shell-sources-query' output.
  3550. Create `idlwave-shell-sources-alist' consisting of list elements
  3551. of the form:
  3552. (module name . (source-file-truename idlwave-internal-filename))"
  3553. (with-current-buffer (get-buffer-create idlwave-shell-bp-buffer)
  3554. (erase-buffer)
  3555. (insert idlwave-shell-command-output)
  3556. (goto-char (point-min))
  3557. (let (cpro cfun)
  3558. (if (re-search-forward "Compiled Procedures:" nil t)
  3559. (progn
  3560. (forward-line) ; Skip $MAIN$
  3561. (setq cpro (point))))
  3562. (if (re-search-forward "Compiled Functions:" nil t)
  3563. (progn
  3564. (setq cfun (point))
  3565. (setq idlwave-shell-sources-alist
  3566. (append
  3567. ;; compiled procedures
  3568. (progn
  3569. (narrow-to-region cpro (point-at-bol))
  3570. (goto-char (point-min))
  3571. (idlwave-shell-sources-grep))
  3572. ;; compiled functions
  3573. (progn
  3574. (widen)
  3575. (goto-char cfun)
  3576. (idlwave-shell-sources-grep)))))))))
  3577. (defun idlwave-shell-sources-grep ()
  3578. (save-excursion
  3579. (let ((al (list nil)))
  3580. (while (and
  3581. (not (progn (forward-line) (eobp)))
  3582. (re-search-forward
  3583. "\\s-*\\(\\S-+\\)\\s-+\\(\\S-+\\)" nil t))
  3584. (nconc al
  3585. (list
  3586. (cons
  3587. (buffer-substring ; name
  3588. (match-beginning 1) (match-end 1))
  3589. (let ((internal-filename
  3590. (buffer-substring ; source
  3591. (match-beginning 2) (match-end 2))))
  3592. (list
  3593. (idlwave-shell-file-name internal-filename)
  3594. internal-filename))
  3595. ))))
  3596. (cdr al))))
  3597. (defun idlwave-shell-clear-all-bp ()
  3598. "Remove all breakpoints in IDL."
  3599. (interactive)
  3600. (idlwave-shell-send-command
  3601. idlwave-shell-bp-query
  3602. '(progn
  3603. (idlwave-shell-filter-bp)
  3604. (mapcar (lambda (x) (idlwave-shell-clear-bp x 'no-query))
  3605. idlwave-shell-bp-alist)
  3606. (idlwave-shell-bp-query))
  3607. 'hide))
  3608. (defun idlwave-shell-list-all-bp ()
  3609. "List all breakpoints in IDL."
  3610. (interactive)
  3611. (idlwave-shell-send-command
  3612. idlwave-shell-bp-query))
  3613. (defvar idlwave-shell-error-last 0
  3614. "Position of last syntax error in `idlwave-shell-error-buffer'.")
  3615. (defun idlwave-shell-goto-next-error ()
  3616. "Move point to next IDL syntax error."
  3617. (interactive)
  3618. (let (frame col)
  3619. (with-current-buffer idlwave-shell-error-buffer
  3620. (goto-char idlwave-shell-error-last)
  3621. (if (or
  3622. (re-search-forward idlwave-shell-syntax-error nil t)
  3623. (re-search-forward idlwave-shell-other-error nil t))
  3624. (progn
  3625. (setq frame
  3626. (list
  3627. (save-match-data
  3628. (idlwave-shell-file-name
  3629. (buffer-substring (match-beginning 1 )
  3630. (match-end 1))))
  3631. (string-to-number
  3632. (buffer-substring (match-beginning 2)
  3633. (match-end 2)))))
  3634. ;; Try to find the column of the error
  3635. (save-excursion
  3636. (setq col
  3637. (if (re-search-backward "\\^" nil t)
  3638. (current-column)
  3639. 0)))))
  3640. (setq idlwave-shell-error-last (point)))
  3641. (if frame
  3642. (progn
  3643. (idlwave-shell-display-line frame col 'disable))
  3644. (beep)
  3645. (message "No more errors."))))
  3646. (defun idlwave-shell-file-name (name)
  3647. "If `idlwave-shell-use-truename' is non-nil, convert file name to true name.
  3648. Otherwise, just expand the file name."
  3649. (let ((def-dir (if (derived-mode-p 'idlwave-shell-mode)
  3650. default-directory
  3651. idlwave-shell-default-directory)))
  3652. (if idlwave-shell-use-truename
  3653. (file-truename name def-dir)
  3654. (expand-file-name name def-dir))))
  3655. ;; Keybindings ------------------------------------------------------------
  3656. (defvar idlwave-shell-mode-map (copy-keymap comint-mode-map)
  3657. "Keymap for `idlwave-mode'.")
  3658. (defvar idlwave-shell-electric-debug-mode-map (make-sparse-keymap))
  3659. (defvar idlwave-shell-mode-prefix-map (make-sparse-keymap))
  3660. (fset 'idlwave-shell-mode-prefix-map idlwave-shell-mode-prefix-map)
  3661. (defvar idlwave-mode-prefix-map (make-sparse-keymap))
  3662. (fset 'idlwave-mode-prefix-map idlwave-mode-prefix-map)
  3663. (defun idlwave-shell-define-key-both (key hook)
  3664. "Define a key in both the shell and buffer mode maps."
  3665. (define-key idlwave-mode-map key hook)
  3666. (define-key idlwave-shell-mode-map key hook))
  3667. ;(define-key idlwave-shell-mode-map "\M-?" 'comint-dynamic-list-completions)
  3668. ;(define-key idlwave-shell-mode-map "\t" 'comint-dynamic-complete)
  3669. (define-key idlwave-shell-mode-map "\C-w" 'comint-kill-region)
  3670. (define-key idlwave-shell-mode-map "\t" 'idlwave-shell-complete)
  3671. (define-key idlwave-shell-mode-map "\M-\t" 'idlwave-shell-complete)
  3672. (define-key idlwave-shell-mode-map "\C-c\C-s" 'idlwave-shell)
  3673. (define-key idlwave-shell-mode-map "\C-c?" 'idlwave-routine-info)
  3674. (define-key idlwave-shell-mode-map "\C-g" 'idlwave-keyboard-quit)
  3675. (define-key idlwave-shell-mode-map "\M-?" 'idlwave-context-help)
  3676. (define-key idlwave-shell-mode-map [(control meta ?\?)]
  3677. 'idlwave-help-assistant-help-with-topic)
  3678. (define-key idlwave-shell-mode-map "\C-c\C-i" 'idlwave-update-routine-info)
  3679. (define-key idlwave-shell-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
  3680. (define-key idlwave-shell-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
  3681. (define-key idlwave-shell-mode-map "\C-c=" 'idlwave-resolve)
  3682. (define-key idlwave-shell-mode-map "\C-c\C-v" 'idlwave-find-module)
  3683. (define-key idlwave-shell-mode-map "\C-c\C-k" 'idlwave-kill-autoloaded-buffers)
  3684. (define-key idlwave-shell-mode-map idlwave-shell-prefix-key
  3685. 'idlwave-shell-debug-map)
  3686. (define-key idlwave-shell-mode-map [(up)] 'idlwave-shell-up-or-history)
  3687. (define-key idlwave-shell-mode-map [(down)] 'idlwave-shell-down-or-history)
  3688. (define-key idlwave-mode-map "\C-c\C-y" 'idlwave-shell-char-mode-loop)
  3689. (define-key idlwave-mode-map "\C-c\C-x" 'idlwave-shell-send-char)
  3690. ;; The mouse bindings for PRINT and HELP
  3691. (idlwave-shell-define-key-both
  3692. (if (featurep 'xemacs)
  3693. [(shift button2)]
  3694. [(shift down-mouse-2)])
  3695. 'idlwave-shell-mouse-print)
  3696. (idlwave-shell-define-key-both
  3697. (if (featurep 'xemacs)
  3698. [(control meta button2)]
  3699. [(control meta down-mouse-2)])
  3700. 'idlwave-shell-mouse-help)
  3701. (idlwave-shell-define-key-both
  3702. (if (featurep 'xemacs)
  3703. [(control shift button2)]
  3704. [(control shift down-mouse-2)])
  3705. 'idlwave-shell-examine-select)
  3706. ;; Add this one from the idlwave-mode-map
  3707. (define-key idlwave-shell-mode-map
  3708. (if (featurep 'xemacs)
  3709. [(shift button3)]
  3710. [(shift mouse-3)])
  3711. 'idlwave-mouse-context-help)
  3712. ;; For Emacs, we need to turn off the button release events.
  3713. (defun idlwave-shell-mouse-nop (event)
  3714. (interactive "e"))
  3715. (unless (featurep 'xemacs)
  3716. (idlwave-shell-define-key-both
  3717. [(shift mouse-2)] 'idlwave-shell-mouse-nop)
  3718. (idlwave-shell-define-key-both
  3719. [(shift control mouse-2)] 'idlwave-shell-mouse-nop)
  3720. (idlwave-shell-define-key-both
  3721. [(control meta mouse-2)] 'idlwave-shell-mouse-nop))
  3722. ;; The following set of bindings is used to bind the debugging keys.
  3723. ;; If `idlwave-shell-activate-prefix-keybindings' is non-nil, the
  3724. ;; first key in the list gets bound the C-c C-d prefix map. If
  3725. ;; `idlwave-shell-debug-modifiers' is non-nil, the second key in the
  3726. ;; list gets bound with the specified modifiers in both
  3727. ;; `idlwave-mode-map' and `idlwave-shell-mode-map'. The next list
  3728. ;; item, if non-nil, means to bind this as a single key in the
  3729. ;; electric-debug-mode-map.
  3730. ;;
  3731. ;; [C-c C-d]-binding debug-modifier-key command bind-electric-debug buf-only
  3732. ;; Used keys: abcdef hijklmnopqrstuvwxyz
  3733. ;; Unused keys: g
  3734. (let* ((specs
  3735. '(([(control ?b)] ?b idlwave-shell-break-here t t)
  3736. ([(control ?i)] ?i idlwave-shell-break-in t t)
  3737. ([(control ?j)] ?j idlwave-shell-break-this-module t t)
  3738. ([(control ?d)] ?d idlwave-shell-clear-current-bp t)
  3739. ([(control ?a)] ?a idlwave-shell-clear-all-bp t)
  3740. ([(control ?\\)] ?\\ idlwave-shell-toggle-enable-current-bp t)
  3741. ([(control ?s)] ?s idlwave-shell-step t)
  3742. ([(control ?n)] ?n idlwave-shell-stepover t)
  3743. ([(control ?k)] ?k idlwave-shell-skip t)
  3744. ([(control ?u)] ?u idlwave-shell-up t)
  3745. ([(control ?o)] ?o idlwave-shell-out t)
  3746. ([(control ?m)] ?m idlwave-shell-return t)
  3747. ([(control ?h)] ?h idlwave-shell-to-here t t)
  3748. ([(control ?r)] ?r idlwave-shell-cont t)
  3749. ([(control ?y)] ?y idlwave-shell-execute-default-command-line)
  3750. ([(control ?z)] ?z idlwave-shell-reset t)
  3751. ([(control ?q)] ?q idlwave-shell-quit)
  3752. ([(control ?p)] ?p idlwave-shell-print t)
  3753. ([( ??)] ?? idlwave-shell-help-expression t)
  3754. ([(control ?v)] ?v idlwave-shell-toggle-electric-debug-mode t t)
  3755. ([(control ?x)] ?x idlwave-shell-goto-next-error)
  3756. ([(control ?c)] ?c idlwave-shell-save-and-run t)
  3757. ([( ?@)] ?@ idlwave-shell-save-and-batch)
  3758. ([(control ?e)] ?e idlwave-shell-run-region)
  3759. ([(control ?w)] ?w idlwave-shell-resync-dirs)
  3760. ([(control ?l)] ?l idlwave-shell-redisplay t)
  3761. ([(control ?t)] ?t idlwave-shell-toggle-toolbar)
  3762. ([(control up)] up idlwave-shell-stack-up)
  3763. ([(control down)] down idlwave-shell-stack-down)
  3764. ([( ?[)] ?[ idlwave-shell-goto-previous-bp t t)
  3765. ([( ?])] ?] idlwave-shell-goto-next-bp t t)
  3766. ([(control ?f)] ?f idlwave-shell-window)))
  3767. (mod (cond ((and idlwave-shell-debug-modifiers
  3768. (listp idlwave-shell-debug-modifiers)
  3769. (not (equal '() idlwave-shell-debug-modifiers)))
  3770. idlwave-shell-debug-modifiers)
  3771. (idlwave-shell-activate-alt-keybindings
  3772. '(alt))))
  3773. (shift (memq 'shift mod))
  3774. (mod-noshift (delete 'shift (copy-sequence mod)))
  3775. s k1 c2 k2 cmd electric only-buffer cannotshift)
  3776. (while (setq s (pop specs))
  3777. (setq k1 (nth 0 s)
  3778. c2 (nth 1 s)
  3779. cmd (nth 2 s)
  3780. electric (nth 3 s)
  3781. only-buffer (nth 4 s)
  3782. cannotshift (and shift (characterp c2) (eq c2 (upcase c2))))
  3783. ;; The regular prefix keymap.
  3784. (when (and idlwave-shell-activate-prefix-keybindings k1)
  3785. (unless only-buffer
  3786. (define-key idlwave-shell-mode-prefix-map k1 cmd))
  3787. (define-key idlwave-mode-prefix-map k1 cmd))
  3788. ;; The debug modifier map
  3789. (when (and mod window-system)
  3790. (if (char-or-string-p c2)
  3791. (setq k2 (vector (append mod-noshift
  3792. (list (if shift (upcase c2) c2)))))
  3793. (setq k2 (vector (append mod (list c2)))))
  3794. (unless cannotshift
  3795. (define-key idlwave-mode-map k2 cmd)
  3796. (unless only-buffer (define-key idlwave-shell-mode-map k2 cmd))))
  3797. ;; The electric debug single-keystroke map
  3798. (if (and electric (char-or-string-p c2))
  3799. (define-key idlwave-shell-electric-debug-mode-map (char-to-string c2)
  3800. cmd))))
  3801. ;; A few extras in the electric debug map
  3802. (define-key idlwave-shell-electric-debug-mode-map " " 'idlwave-shell-step)
  3803. (define-key idlwave-shell-electric-debug-mode-map "+" 'idlwave-shell-stack-up)
  3804. (define-key idlwave-shell-electric-debug-mode-map "=" 'idlwave-shell-stack-up)
  3805. (define-key idlwave-shell-electric-debug-mode-map "-"
  3806. 'idlwave-shell-stack-down)
  3807. (define-key idlwave-shell-electric-debug-mode-map "_"
  3808. 'idlwave-shell-stack-down)
  3809. (define-key idlwave-shell-electric-debug-mode-map "e"
  3810. (lambda () (interactive) (idlwave-shell-print '(16))))
  3811. (define-key idlwave-shell-electric-debug-mode-map "q" 'idlwave-shell-retall)
  3812. (define-key idlwave-shell-electric-debug-mode-map "t"
  3813. (lambda () (interactive) (idlwave-shell-send-command "help,/TRACE")))
  3814. (define-key idlwave-shell-electric-debug-mode-map [(control ??)]
  3815. 'idlwave-shell-electric-debug-help)
  3816. (define-key idlwave-shell-electric-debug-mode-map "x"
  3817. (lambda (arg) (interactive "P")
  3818. (idlwave-shell-print arg nil nil t)))
  3819. ; Enter the prefix map in two places.
  3820. (fset 'idlwave-debug-map idlwave-mode-prefix-map)
  3821. (fset 'idlwave-shell-debug-map idlwave-shell-mode-prefix-map)
  3822. ;; The Electric Debug Minor Mode --------------------------------------------
  3823. (defun idlwave-shell-toggle-electric-debug-mode ()
  3824. "Toggle electric-debug-mode, suppressing re-entry into mode if turned off."
  3825. (interactive)
  3826. ;; If turning it off, make sure it stays off throughout the debug
  3827. ;; session until we return or hit $MAIN$. Cancel this suppression
  3828. ;; if it's explicitly turned on.
  3829. (if idlwave-shell-electric-debug-mode
  3830. (progn ;; Turn it off, and make sure it stays off.
  3831. (setq idlwave-shell-suppress-electric-debug t)
  3832. (idlwave-shell-electric-debug-mode 0))
  3833. (setq idlwave-shell-suppress-electric-debug nil)
  3834. (idlwave-shell-electric-debug-mode t)))
  3835. (defvar idlwave-shell-electric-debug-read-only)
  3836. (defvar idlwave-shell-electric-debug-buffers nil)
  3837. (define-minor-mode idlwave-shell-electric-debug-mode
  3838. "Toggle Idlwave Shell Electric Debug mode.
  3839. With a prefix argument ARG, enable the mode if ARG is positive,
  3840. and disable it otherwise. If called from Lisp, enable the mode
  3841. if ARG is omitted or nil.
  3842. When Idlwave Shell Electric Debug mode is enabled, the Idlwave
  3843. Shell debugging commands are available as single key sequences."
  3844. nil " *Debugging*" idlwave-shell-electric-debug-mode-map)
  3845. (add-hook
  3846. 'idlwave-shell-electric-debug-mode-on-hook
  3847. (lambda ()
  3848. (set (make-local-variable 'idlwave-shell-electric-debug-read-only)
  3849. buffer-read-only)
  3850. (setq buffer-read-only t)
  3851. (add-to-list 'idlwave-shell-electric-debug-buffers (current-buffer))
  3852. (if idlwave-shell-stop-line-overlay
  3853. (overlay-put idlwave-shell-stop-line-overlay 'face
  3854. idlwave-shell-electric-stop-line-face))
  3855. (if (facep 'fringe)
  3856. (set-face-foreground 'fringe idlwave-shell-electric-stop-color
  3857. (selected-frame)))))
  3858. (add-hook
  3859. 'idlwave-shell-electric-debug-mode-off-hook
  3860. (lambda ()
  3861. ;; Return to previous read-only state
  3862. (setq buffer-read-only (if (boundp 'idlwave-shell-electric-debug-read-only)
  3863. idlwave-shell-electric-debug-read-only))
  3864. (setq idlwave-shell-electric-debug-buffers
  3865. (delq (current-buffer) idlwave-shell-electric-debug-buffers))
  3866. (if idlwave-shell-stop-line-overlay
  3867. (overlay-put idlwave-shell-stop-line-overlay 'face
  3868. idlwave-shell-stop-line-face)
  3869. (if (facep 'fringe)
  3870. (set-face-foreground 'fringe (face-foreground 'default))))))
  3871. ;; easy-mmode defines electric-debug-mode for us, so we need to advise it.
  3872. (defadvice idlwave-shell-electric-debug-mode (after print-enter activate)
  3873. "Print out an entrance message."
  3874. (when idlwave-shell-electric-debug-mode
  3875. (message
  3876. "Electric Debugging mode entered. Press [C-?] for help, [q] to quit"))
  3877. (force-mode-line-update))
  3878. ;; Turn it off in all relevant buffers
  3879. (defvar idlwave-shell-electric-debug-buffers nil)
  3880. (defun idlwave-shell-electric-debug-all-off ()
  3881. (setq idlwave-shell-suppress-electric-debug nil)
  3882. (let ((buffers idlwave-shell-electric-debug-buffers)
  3883. buf)
  3884. (save-excursion
  3885. (while (setq buf (pop buffers))
  3886. (when (buffer-live-p buf)
  3887. (set-buffer buf)
  3888. (when (and (derived-mode-p 'idlwave-mode)
  3889. buffer-file-name
  3890. idlwave-shell-electric-debug-mode)
  3891. (idlwave-shell-electric-debug-mode 0))))))
  3892. (setq idlwave-shell-electric-debug-buffers nil))
  3893. ;; Show the help text
  3894. (defun idlwave-shell-electric-debug-help ()
  3895. (interactive)
  3896. (with-output-to-temp-buffer "*IDLWAVE Electric Debug Help*"
  3897. (princ idlwave-shell-electric-debug-help))
  3898. (let* ((current-window (selected-window))
  3899. (window (get-buffer-window "*IDLWAVE Electric Debug Help*"))
  3900. (window-lines (window-height window)))
  3901. (select-window window)
  3902. (enlarge-window (1+ (- (count-lines 1 (point-max)) window-lines)))
  3903. (select-window current-window)))
  3904. ;; The Menus --------------------------------------------------------------
  3905. (defvar idlwave-shell-menu-def
  3906. `("Debug"
  3907. ["Electric Debug Mode"
  3908. idlwave-shell-electric-debug-mode
  3909. :style toggle :selected idlwave-shell-electric-debug-mode
  3910. :included (derived-mode-p 'idlwave-mode) :keys "C-c C-d C-v"]
  3911. "--"
  3912. ("Compile & Run"
  3913. ["Save and .RUN" idlwave-shell-save-and-run
  3914. (or (derived-mode-p 'idlwave-mode)
  3915. idlwave-shell-last-save-and-action-file)]
  3916. ["Save and .COMPILE" idlwave-shell-save-and-compile
  3917. (or (derived-mode-p 'idlwave-mode)
  3918. idlwave-shell-last-save-and-action-file)]
  3919. ["Save and @Batch" idlwave-shell-save-and-batch
  3920. (or (derived-mode-p 'idlwave-mode)
  3921. idlwave-shell-last-save-and-action-file)]
  3922. "--"
  3923. ["Goto Next Error" idlwave-shell-goto-next-error t]
  3924. "--"
  3925. ["Compile and Run Region" idlwave-shell-run-region
  3926. (derived-mode-p 'idlwave-mode)]
  3927. ["Evaluate Region" idlwave-shell-evaluate-region
  3928. (derived-mode-p 'idlwave-mode)]
  3929. "--"
  3930. ["Execute Default Cmd" idlwave-shell-execute-default-command-line t]
  3931. ["Edit Default Cmd" idlwave-shell-edit-default-command-line t])
  3932. ("Breakpoints"
  3933. ["Set Breakpoint" idlwave-shell-break-here
  3934. :keys "C-c C-d C-b" :active (derived-mode-p 'idlwave-mode)]
  3935. ("Set Special Breakpoint"
  3936. ["Set After Count Breakpoint"
  3937. (progn
  3938. (let ((count (string-to-number (read-string "Break after count: "))))
  3939. (if (integerp count) (idlwave-shell-break-here count))))
  3940. :active (derived-mode-p 'idlwave-mode)]
  3941. ["Set Condition Breakpoint"
  3942. (idlwave-shell-break-here '(4))
  3943. :active (derived-mode-p 'idlwave-mode)])
  3944. ["Break in Module" idlwave-shell-break-in
  3945. :keys "C-c C-d C-i" :active (derived-mode-p 'idlwave-mode)]
  3946. ["Break in this Module" idlwave-shell-break-this-module
  3947. :keys "C-c C-d C-j" :active (derived-mode-p 'idlwave-mode)]
  3948. ["Clear Breakpoint" idlwave-shell-clear-current-bp t]
  3949. ["Clear All Breakpoints" idlwave-shell-clear-all-bp t]
  3950. ["Disable/Enable Breakpoint" idlwave-shell-toggle-enable-current-bp t]
  3951. ["Goto Previous Breakpoint" idlwave-shell-goto-previous-bp
  3952. :keys "C-c C-d [" :active (derived-mode-p 'idlwave-mode)]
  3953. ["Goto Next Breakpoint" idlwave-shell-goto-next-bp
  3954. :keys "C-c C-d ]" :active (derived-mode-p 'idlwave-mode)]
  3955. ["List All Breakpoints" idlwave-shell-list-all-bp t]
  3956. ["Resync Breakpoints" idlwave-shell-bp-query t])
  3957. ("Continue/Step"
  3958. ["Step (into)" idlwave-shell-step t]
  3959. ["Step (over)" idlwave-shell-stepover t]
  3960. ["Skip One Statement" idlwave-shell-skip t]
  3961. ["Continue" idlwave-shell-cont t]
  3962. ["... to End of Block" idlwave-shell-up t]
  3963. ["... to End of Subprog" idlwave-shell-return t]
  3964. ["... to End of Subprog+1" idlwave-shell-out t]
  3965. ["... to Here (Cursor Line)" idlwave-shell-to-here
  3966. :keys "C-c C-d C-h" :active (derived-mode-p 'idlwave-mode)])
  3967. ("Examine Expressions"
  3968. ["Print expression" idlwave-shell-print t]
  3969. ["Help on expression" idlwave-shell-help-expression t]
  3970. ("Examine nearby expression with"
  3971. ,@(mapcar (lambda(x)
  3972. `[ ,(car x) (idlwave-shell-print nil ',x) t ])
  3973. idlwave-shell-examine-alist))
  3974. ("Examine region with"
  3975. ,@(mapcar (lambda(x)
  3976. `[ ,(car x) (idlwave-shell-print '(4) ',x) t ])
  3977. idlwave-shell-examine-alist)))
  3978. ("Call Stack"
  3979. ["Stack Up" idlwave-shell-stack-up t]
  3980. ["Stack Down" idlwave-shell-stack-down t]
  3981. "--"
  3982. ["Redisplay and Sync" idlwave-shell-redisplay t])
  3983. ("Show Commands"
  3984. ["Everything" (if (eq idlwave-shell-show-commands 'everything)
  3985. (progn
  3986. (setq idlwave-shell-show-commands
  3987. (get 'idlwave-shell-show-commands 'last-val))
  3988. (put 'idlwave-shell-show-commands 'last-val nil))
  3989. (put 'idlwave-shell-show-commands 'last-val
  3990. idlwave-shell-show-commands)
  3991. (setq idlwave-shell-show-commands 'everything))
  3992. :style toggle :selected (and (not (listp idlwave-shell-show-commands))
  3993. (eq idlwave-shell-show-commands
  3994. 'everything))]
  3995. "--"
  3996. ["Compiling Commands" (idlwave-shell-add-or-remove-show 'run)
  3997. :style toggle
  3998. :selected (not (idlwave-shell-hide-p
  3999. 'run
  4000. (get 'idlwave-shell-show-commands 'last-val)))
  4001. :active (not (eq idlwave-shell-show-commands 'everything))]
  4002. ["Breakpoint Commands" (idlwave-shell-add-or-remove-show 'breakpoint)
  4003. :style toggle
  4004. :selected (not (idlwave-shell-hide-p
  4005. 'breakpoint
  4006. (get 'idlwave-shell-show-commands 'last-val)))
  4007. :active (not (eq idlwave-shell-show-commands 'everything))]
  4008. ["Debug Commands" (idlwave-shell-add-or-remove-show 'debug)
  4009. :style toggle
  4010. :selected (not (idlwave-shell-hide-p
  4011. 'debug
  4012. (get 'idlwave-shell-show-commands 'last-val)))
  4013. :active (not (eq idlwave-shell-show-commands 'everything))]
  4014. ["Miscellaneous Commands" (idlwave-shell-add-or-remove-show 'misc)
  4015. :style toggle
  4016. :selected (not (idlwave-shell-hide-p
  4017. 'misc
  4018. (get 'idlwave-shell-show-commands 'last-val)))
  4019. :active (not (eq idlwave-shell-show-commands 'everything))])
  4020. ("Input Mode"
  4021. ["Send one char" idlwave-shell-send-char t]
  4022. ["Temporary Character Mode" idlwave-shell-char-mode-loop t]
  4023. "--"
  4024. ["Use Input Mode Magic"
  4025. (setq idlwave-shell-use-input-mode-magic
  4026. (not idlwave-shell-use-input-mode-magic))
  4027. :style toggle :selected idlwave-shell-use-input-mode-magic])
  4028. "--"
  4029. ["Update Working Dir" idlwave-shell-resync-dirs t]
  4030. ["Save Path Info"
  4031. (idlwave-shell-send-command idlwave-shell-path-query
  4032. 'idlwave-shell-get-path-info
  4033. 'hide)
  4034. t]
  4035. ["Reset IDL" idlwave-shell-reset t]
  4036. "--"
  4037. ["Toggle Toolbar" idlwave-shell-toggle-toolbar t]
  4038. ["Exit IDL" idlwave-shell-quit t]))
  4039. (if (or (featurep 'easymenu) (load "easymenu" t))
  4040. (progn
  4041. (easy-menu-define
  4042. idlwave-mode-debug-menu idlwave-mode-map "IDL debugging menus"
  4043. idlwave-shell-menu-def)
  4044. (easy-menu-define
  4045. idlwave-shell-mode-menu idlwave-shell-mode-map "IDL shell menus"
  4046. idlwave-shell-menu-def)
  4047. (save-current-buffer
  4048. (dolist (buf (buffer-list))
  4049. (set-buffer buf)
  4050. (if (derived-mode-p 'idlwave-mode)
  4051. (progn
  4052. (easy-menu-remove idlwave-mode-debug-menu)
  4053. (easy-menu-add idlwave-mode-debug-menu)))))))
  4054. ;; The Breakpoint Glyph -------------------------------------------------------
  4055. (defvar idlwave-shell-bp-glyph nil
  4056. "The glyphs to mark breakpoint lines in the source code.")
  4057. (let ((image-alist
  4058. '((bp . "/* XPM */
  4059. static char * file[] = {
  4060. \"14 12 3 1\",
  4061. \" c None s backgroundColor\",
  4062. \". c #4B4B4B4B4B4B\",
  4063. \"R c #FFFF00000000\",
  4064. \" \",
  4065. \" .... \",
  4066. \" .RRRR. \",
  4067. \" .RRRRRR. \",
  4068. \" .RRRRRRRR. \",
  4069. \" .RRRRRRRR. \",
  4070. \" .RRRRRRRR. \",
  4071. \" .RRRRRRRR. \",
  4072. \" .RRRRRR. \",
  4073. \" .RRRR. \",
  4074. \" .... \",
  4075. \" \"};")
  4076. (bp-cond . "/* XPM */
  4077. static char * file[] = {
  4078. \"14 12 4 1\",
  4079. \" c None s backgroundColor\",
  4080. \". c #4B4B4B4B4B4B\",
  4081. \"R c #FFFF00000000\",
  4082. \"B c #000000000000\",
  4083. \" \",
  4084. \" .... \",
  4085. \" .RRRR. \",
  4086. \" .RRRRRR. \",
  4087. \" .RRRRRRRR. \",
  4088. \" .RRBBBBRR. \",
  4089. \" .RRRRRRRR. \",
  4090. \" .RRBBBBRR. \",
  4091. \" .RRRRRR. \",
  4092. \" .RRRR. \",
  4093. \" .... \",
  4094. \" \"};")
  4095. (bp-1 . "/* XPM */
  4096. static char * file[] = {
  4097. \"14 12 4 1\",
  4098. \" c None s backgroundColor\",
  4099. \". c #4B4B4B4B4B4B\",
  4100. \"X c #FFFF00000000\",
  4101. \"o c #000000000000\",
  4102. \" \",
  4103. \" .... \",
  4104. \" .XXXX. \",
  4105. \" .XXooXX. \",
  4106. \" .XXoooXXX. \",
  4107. \" .XXXooXXX. \",
  4108. \" .XXXooXXX. \",
  4109. \" .XXooooXX. \",
  4110. \" .XooooX. \",
  4111. \" .XXXX. \",
  4112. \" .... \",
  4113. \" \"};")
  4114. (bp-2 . "/* XPM */
  4115. static char * file[] = {
  4116. \"14 12 4 1\",
  4117. \" c None s backgroundColor\",
  4118. \". c #4B4B4B4B4B4B\",
  4119. \"X c #FFFF00000000\",
  4120. \"o c #000000000000\",
  4121. \" \",
  4122. \" .... \",
  4123. \" .XXXX. \",
  4124. \" .XoooXX. \",
  4125. \" .XXoXooXX. \",
  4126. \" .XXXXooXX. \",
  4127. \" .XXXooXXX. \",
  4128. \" .XXooXXXX. \",
  4129. \" .XooooX. \",
  4130. \" .XXXX. \",
  4131. \" .... \",
  4132. \" \"};")
  4133. (bp-3 . "/* XPM */
  4134. static char * file[] = {
  4135. \"14 12 4 1\",
  4136. \" c None s backgroundColor\",
  4137. \". c #4B4B4B4B4B4B\",
  4138. \"X c #FFFF00000000\",
  4139. \"o c #000000000000\",
  4140. \" \",
  4141. \" .... \",
  4142. \" .XXXX. \",
  4143. \" .XoooXX. \",
  4144. \" .XXXXooXX. \",
  4145. \" .XXXooXXX. \",
  4146. \" .XXXXooXX. \",
  4147. \" .XXoXooXX. \",
  4148. \" .XoooXX. \",
  4149. \" .XXXX. \",
  4150. \" .... \",
  4151. \" \"};")
  4152. (bp-4 . "/* XPM */
  4153. static char * file[] = {
  4154. \"14 12 4 1\",
  4155. \" c None s backgroundColor\",
  4156. \". c #4B4B4B4B4B4B\",
  4157. \"X c #FFFF00000000\",
  4158. \"o c #000000000000\",
  4159. \" \",
  4160. \" .... \",
  4161. \" .XXXX. \",
  4162. \" .XoXXoX. \",
  4163. \" .XXoXXoXX. \",
  4164. \" .XXooooXX. \",
  4165. \" .XXXXooXX. \",
  4166. \" .XXXXooXX. \",
  4167. \" .XXXooX. \",
  4168. \" .XXXX. \",
  4169. \" .... \",
  4170. \" \"};")
  4171. (bp-n . "/* XPM */
  4172. static char * file[] = {
  4173. \"14 12 4 1\",
  4174. \" c None s backgroundColor\",
  4175. \". c #4B4B4B4B4B4B\",
  4176. \"X c #FFFF00000000\",
  4177. \"o c #000000000000\",
  4178. \" \",
  4179. \" .... \",
  4180. \" .XXXX. \",
  4181. \" .XXXXXX. \",
  4182. \" .XXoXoXXX. \",
  4183. \" .XXooXoXX. \",
  4184. \" .XXoXXoXX. \",
  4185. \" .XXoXXoXX. \",
  4186. \" .XoXXoX. \",
  4187. \" .XXXX. \",
  4188. \" .... \",
  4189. \" \"};"))) im-cons im)
  4190. (while (setq im-cons (pop image-alist))
  4191. (setq im (cond ((and (featurep 'xemacs)
  4192. (featurep 'xpm))
  4193. (list
  4194. (let ((data (cdr im-cons)))
  4195. (string-match "#FFFF00000000" data)
  4196. (setq data (replace-match "#8F8F8F8F8F8F" t t data))
  4197. (make-glyph data))
  4198. (make-glyph (cdr im-cons))))
  4199. ((and (not (featurep 'xemacs))
  4200. (fboundp 'image-type-available-p)
  4201. (image-type-available-p 'xpm))
  4202. (list 'image :type 'xpm :data (cdr im-cons)
  4203. :ascent 'center))
  4204. (t nil)))
  4205. (if im (push (cons (car im-cons) im) idlwave-shell-bp-glyph))))
  4206. (provide 'idlw-shell)
  4207. (provide 'idlwave-shell)
  4208. ;; Load the toolbar when wanted by the user.
  4209. (autoload 'idlwave-toolbar-toggle "idlw-toolbar"
  4210. "Toggle the IDLWAVE toolbar.")
  4211. (autoload 'idlwave-toolbar-add-everywhere "idlw-toolbar"
  4212. "Add IDLWAVE toolbar.")
  4213. (defun idlwave-shell-toggle-toolbar ()
  4214. "Toggle the display of the debugging toolbar."
  4215. (interactive)
  4216. (idlwave-toolbar-toggle))
  4217. (if idlwave-shell-use-toolbar
  4218. (add-hook 'idlwave-shell-mode-hook 'idlwave-toolbar-add-everywhere))
  4219. ;;; idlw-shell.el ends here