idlw-shell.el 173 KB

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