edebug.el 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467
  1. ;;; edebug.el --- a source-level debugger for Emacs Lisp
  2. ;; Copyright (C) 1988-1995, 1997, 1999-2012 Free Software Foundation, Inc.
  3. ;; Author: Daniel LaLiberte <liberte@holonexus.org>
  4. ;; Maintainer: FSF
  5. ;; Keywords: lisp, tools, maint
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This minor mode allows programmers to step through Emacs Lisp
  19. ;; source code while executing functions. You can also set
  20. ;; breakpoints, trace (stopping at each expression), evaluate
  21. ;; expressions as if outside Edebug, reevaluate and display a list of
  22. ;; expressions, trap errors normally caught by debug, and display a
  23. ;; debug style backtrace.
  24. ;;; Minimal Instructions
  25. ;; =====================
  26. ;; First evaluate a defun with C-M-x, then run the function. Step
  27. ;; through the code with SPC, mark breakpoints with b, go until a
  28. ;; breakpoint is reached with g, and quit execution with q. Use the
  29. ;; "?" command in edebug to describe other commands.
  30. ;; See the Emacs Lisp Reference Manual for more details.
  31. ;; If you wish to change the default edebug global command prefix, change:
  32. ;; (setq edebug-global-prefix "\C-xX")
  33. ;; Edebug was written by
  34. ;; Daniel LaLiberte
  35. ;; GTE Labs
  36. ;; 40 Sylvan Rd
  37. ;; Waltham, MA 02254
  38. ;; liberte@holonexus.org
  39. ;;; Code:
  40. ;;; Bug reporting
  41. (defalias 'edebug-submit-bug-report 'report-emacs-bug)
  42. ;;; Options
  43. (defgroup edebug nil
  44. "A source-level debugger for Emacs Lisp."
  45. :group 'lisp)
  46. (defcustom edebug-setup-hook nil
  47. "Functions to call before edebug is used.
  48. Each time it is set to a new value, Edebug will call those functions
  49. once and then reset `edebug-setup-hook' to nil. You could use this
  50. to load up Edebug specifications associated with a package you are
  51. using, but only when you also use Edebug."
  52. :type 'hook
  53. :group 'edebug)
  54. ;; edebug-all-defs and edebug-all-forms need to be autoloaded
  55. ;; because the byte compiler binds them; as a result, if edebug
  56. ;; is first loaded for a require in a compilation, they will be left unbound.
  57. ;;;###autoload
  58. (defcustom edebug-all-defs nil
  59. "If non-nil, evaluating defining forms instruments for Edebug.
  60. This applies to `eval-defun', `eval-region', `eval-buffer', and
  61. `eval-current-buffer'. `eval-region' is also called by
  62. `eval-last-sexp', and `eval-print-last-sexp'.
  63. You can use the command `edebug-all-defs' to toggle the value of this
  64. variable. You may wish to make it local to each buffer with
  65. \(make-local-variable 'edebug-all-defs) in your
  66. `emacs-lisp-mode-hook'."
  67. :type 'boolean
  68. :group 'edebug)
  69. ;; edebug-all-defs and edebug-all-forms need to be autoloaded
  70. ;; because the byte compiler binds them; as a result, if edebug
  71. ;; is first loaded for a require in a compilation, they will be left unbound.
  72. ;;;###autoload
  73. (defcustom edebug-all-forms nil
  74. "Non-nil means evaluation of all forms will instrument for Edebug.
  75. This doesn't apply to loading or evaluations in the minibuffer.
  76. Use the command `edebug-all-forms' to toggle the value of this option."
  77. :type 'boolean
  78. :group 'edebug)
  79. (defcustom edebug-eval-macro-args nil
  80. "Non-nil means all macro call arguments may be evaluated.
  81. If this variable is nil, the default, Edebug will *not* wrap
  82. macro call arguments as if they will be evaluated.
  83. For each macro, an `edebug-form-spec' overrides this option.
  84. So to specify exceptions for macros that have some arguments evaluated
  85. and some not, use `def-edebug-spec' to specify an `edebug-form-spec'."
  86. :type 'boolean
  87. :group 'edebug)
  88. (defcustom edebug-save-windows t
  89. "If non-nil, Edebug saves and restores the window configuration.
  90. That takes some time, so if your program does not care what happens to
  91. the window configurations, it is better to set this variable to nil.
  92. If the value is a list, only the listed windows are saved and
  93. restored.
  94. `edebug-toggle-save-windows' may be used to change this variable."
  95. :type '(choice boolean (repeat string))
  96. :group 'edebug)
  97. (defcustom edebug-save-displayed-buffer-points nil
  98. "If non-nil, save and restore point in all displayed buffers.
  99. Saving and restoring point in other buffers is necessary if you are
  100. debugging code that changes the point of a buffer that is displayed
  101. in a non-selected window. If Edebug or the user then selects the
  102. window, the buffer's point will be changed to the window's point.
  103. Saving and restoring point in all buffers is expensive, since it
  104. requires selecting each window twice, so enable this only if you
  105. need it."
  106. :type 'boolean
  107. :group 'edebug)
  108. (defcustom edebug-initial-mode 'step
  109. "Initial execution mode for Edebug, if non-nil.
  110. If this variable is non-nil, it specifies the initial execution mode
  111. for Edebug when it is first activated. Possible values are step, next,
  112. go, Go-nonstop, trace, Trace-fast, continue, and Continue-fast."
  113. :type '(choice (const step) (const next) (const go)
  114. (const Go-nonstop) (const trace)
  115. (const Trace-fast) (const continue)
  116. (const Continue-fast))
  117. :group 'edebug)
  118. (defcustom edebug-trace nil
  119. "Non-nil means display a trace of function entry and exit.
  120. Tracing output is displayed in a buffer named `*edebug-trace*', one
  121. function entry or exit per line, indented by the recursion level.
  122. You can customize by replacing functions `edebug-print-trace-before'
  123. and `edebug-print-trace-after'."
  124. :type 'boolean
  125. :group 'edebug)
  126. (defcustom edebug-test-coverage nil
  127. "If non-nil, Edebug tests coverage of all expressions debugged.
  128. This is done by comparing the result of each expression with the
  129. previous result. Coverage is considered OK if two different
  130. results are found.
  131. Use `edebug-display-freq-count' to display the frequency count and
  132. coverage information for a definition."
  133. :type 'boolean
  134. :group 'edebug)
  135. (defcustom edebug-continue-kbd-macro nil
  136. "If non-nil, continue defining or executing any keyboard macro.
  137. Use this with caution since it is not debugged."
  138. :type 'boolean
  139. :group 'edebug)
  140. (defcustom edebug-print-length 50
  141. "If non-nil, default value of `print-length' for printing results in Edebug."
  142. :type 'integer
  143. :group 'edebug)
  144. (defcustom edebug-print-level 50
  145. "If non-nil, default value of `print-level' for printing results in Edebug."
  146. :type 'integer
  147. :group 'edebug)
  148. (defcustom edebug-print-circle t
  149. "If non-nil, default value of `print-circle' for printing results in Edebug."
  150. :type 'boolean
  151. :group 'edebug)
  152. (defcustom edebug-unwrap-results nil
  153. "Non-nil if Edebug should unwrap results of expressions.
  154. That is, Edebug will try to remove its own instrumentation from the result.
  155. This is useful when debugging macros where the results of expressions
  156. are instrumented expressions. But don't do this when results might be
  157. circular or an infinite loop will result."
  158. :type 'boolean
  159. :group 'edebug)
  160. (defcustom edebug-on-error t
  161. "Value bound to `debug-on-error' while Edebug is active.
  162. If `debug-on-error' is non-nil, that value is still used.
  163. If the value is a list of signal names, Edebug will stop when any of
  164. these errors are signaled from Lisp code whether or not the signal is
  165. handled by a `condition-case'. This option is useful for debugging
  166. signals that *are* handled since they would otherwise be missed.
  167. After execution is resumed, the error is signaled again."
  168. :type '(choice (const :tag "off")
  169. (repeat :menu-tag "When"
  170. :value (nil)
  171. (symbol :format "%v"))
  172. (const :tag "always" t))
  173. :group 'edebug)
  174. (defcustom edebug-on-quit t
  175. "Value bound to `debug-on-quit' while Edebug is active."
  176. :type 'boolean
  177. :group 'edebug)
  178. (defcustom edebug-global-break-condition nil
  179. "If non-nil, an expression to test for at every stop point.
  180. If the result is non-nil, then break. Errors are ignored."
  181. :type 'sexp
  182. :group 'edebug)
  183. (defcustom edebug-sit-for-seconds 1
  184. "Number of seconds to pause when execution mode is `trace' or `continue'."
  185. :type 'number
  186. :group 'edebug)
  187. ;;; Form spec utilities.
  188. (defmacro def-edebug-form-spec (symbol spec-form)
  189. "For compatibility with old version."
  190. (def-edebug-spec symbol (eval spec-form)))
  191. (make-obsolete 'def-edebug-form-spec 'def-edebug-spec "22.1")
  192. (defun get-edebug-spec (symbol)
  193. ;; Get the spec of symbol resolving all indirection.
  194. (let ((edebug-form-spec (get symbol 'edebug-form-spec))
  195. indirect)
  196. (while (and (symbolp edebug-form-spec)
  197. (setq indirect (get edebug-form-spec 'edebug-form-spec)))
  198. ;; (edebug-trace "indirection: %s" edebug-form-spec)
  199. (setq edebug-form-spec indirect))
  200. edebug-form-spec
  201. ))
  202. ;;;###autoload
  203. (defun edebug-basic-spec (spec)
  204. "Return t if SPEC uses only extant spec symbols.
  205. An extant spec symbol is a symbol that is not a function and has a
  206. `edebug-form-spec' property."
  207. (cond ((listp spec)
  208. (catch 'basic
  209. (while spec
  210. (unless (edebug-basic-spec (car spec)) (throw 'basic nil))
  211. (setq spec (cdr spec)))
  212. t))
  213. ((symbolp spec)
  214. (unless (functionp spec) (get spec 'edebug-form-spec)))))
  215. ;;; Utilities
  216. ;; Define edebug-gensym - from old cl.el
  217. (defvar edebug-gensym-index 0
  218. "Integer used by `edebug-gensym' to produce new names.")
  219. (defun edebug-gensym (&optional prefix)
  220. "Generate a fresh uninterned symbol.
  221. There is an optional argument, PREFIX. PREFIX is the string
  222. that begins the new name. Most people take just the default,
  223. except when debugging needs suggest otherwise."
  224. (if (null prefix)
  225. (setq prefix "G"))
  226. (let ((newsymbol nil)
  227. (newname ""))
  228. (while (not newsymbol)
  229. (setq newname (concat prefix (int-to-string edebug-gensym-index)))
  230. (setq edebug-gensym-index (+ edebug-gensym-index 1))
  231. (if (not (intern-soft newname))
  232. (setq newsymbol (make-symbol newname))))
  233. newsymbol))
  234. (defun edebug-lambda-list-keywordp (object)
  235. "Return t if OBJECT is a lambda list keyword.
  236. A lambda list keyword is a symbol that starts with `&'."
  237. (and (symbolp object)
  238. (= ?& (aref (symbol-name object) 0))))
  239. (defun edebug-last-sexp ()
  240. ;; Return the last sexp before point in current buffer.
  241. ;; Assumes Emacs Lisp syntax is active.
  242. (car
  243. (read-from-string
  244. (buffer-substring
  245. (save-excursion
  246. (forward-sexp -1)
  247. (point))
  248. (point)))))
  249. (defun edebug-window-list ()
  250. "Return a list of windows, in order of `next-window'."
  251. ;; This doesn't work for epoch.
  252. (let (window-list)
  253. (walk-windows (lambda (w) (push w window-list)))
  254. (nreverse window-list)))
  255. ;; Not used.
  256. '(defun edebug-two-window-p ()
  257. "Return t if there are two windows."
  258. (and (not (one-window-p))
  259. (eq (selected-window)
  260. (next-window (next-window (selected-window))))))
  261. (defsubst edebug-lookup-function (object)
  262. (while (and (symbolp object) (fboundp object))
  263. (setq object (symbol-function object)))
  264. object)
  265. (defun edebug-macrop (object)
  266. "Return the macro named by OBJECT, or nil if it is not a macro."
  267. (setq object (edebug-lookup-function object))
  268. (if (and (listp object)
  269. (eq 'macro (car object))
  270. (functionp (cdr object)))
  271. object))
  272. (defun edebug-sort-alist (alist function)
  273. ;; Return the ALIST sorted with comparison function FUNCTION.
  274. ;; This uses 'sort so the sorting is destructive.
  275. (sort alist (function
  276. (lambda (e1 e2)
  277. (funcall function (car e1) (car e2))))))
  278. ;;(def-edebug-spec edebug-save-restriction t)
  279. ;; Not used. If it is used, def-edebug-spec must be defined before use.
  280. '(defmacro edebug-save-restriction (&rest body)
  281. "Evaluate BODY while saving the current buffers restriction.
  282. BODY may change buffer outside of current restriction, unlike
  283. save-restriction. BODY may change the current buffer,
  284. and the restriction will be restored to the original buffer,
  285. and the current buffer remains current.
  286. Return the result of the last expression in BODY."
  287. `(let ((edebug:s-r-beg (point-min-marker))
  288. (edebug:s-r-end (point-max-marker)))
  289. (unwind-protect
  290. (progn ,@body)
  291. (with-current-buffer (marker-buffer edebug:s-r-beg)
  292. (narrow-to-region edebug:s-r-beg edebug:s-r-end)))))
  293. ;;; Display
  294. (defconst edebug-trace-buffer "*edebug-trace*"
  295. "Name of the buffer to put trace info in.")
  296. (defun edebug-pop-to-buffer (buffer &optional window)
  297. ;; Like pop-to-buffer, but select window where BUFFER was last shown.
  298. ;; Select WINDOW if it is provided and still exists. Otherwise,
  299. ;; if buffer is currently shown in several windows, choose one.
  300. ;; Otherwise, find a new window, possibly splitting one.
  301. (setq window
  302. (cond
  303. ((and (edebug-window-live-p window)
  304. (eq (window-buffer window) buffer))
  305. window)
  306. ((eq (window-buffer (selected-window)) buffer)
  307. ;; Selected window already displays BUFFER.
  308. (selected-window))
  309. ((edebug-get-buffer-window buffer))
  310. ((one-window-p 'nomini)
  311. ;; When there's one window only, split it.
  312. (split-window))
  313. ((let ((trace-window (get-buffer-window edebug-trace-buffer)))
  314. (catch 'found
  315. (dolist (elt (window-list nil 'nomini))
  316. (unless (or (eq elt (selected-window)) (eq elt trace-window)
  317. (window-dedicated-p elt))
  318. ;; Found a non-dedicated window not showing
  319. ;; `edebug-trace-buffer', use it.
  320. (throw 'found elt))))))
  321. ;; All windows are dedicated or show `edebug-trace-buffer', split
  322. ;; selected one.
  323. (t (split-window))))
  324. (select-window window)
  325. (set-window-buffer window buffer)
  326. (set-window-hscroll window 0);; should this be??
  327. ;; Selecting the window does not set the buffer until command loop.
  328. ;;(set-buffer buffer)
  329. )
  330. (defun edebug-get-displayed-buffer-points ()
  331. ;; Return a list of buffer point pairs, for all displayed buffers.
  332. (let (list)
  333. (walk-windows (lambda (w)
  334. (unless (eq w (selected-window))
  335. (push (cons (window-buffer w)
  336. (window-point w))
  337. list))))
  338. list))
  339. (defun edebug-set-buffer-points (buffer-points)
  340. ;; Restore the buffer-points created by edebug-get-displayed-buffer-points.
  341. (save-current-buffer
  342. (mapcar (lambda (buf-point)
  343. (when (buffer-live-p (car buf-point))
  344. (set-buffer (car buf-point))
  345. (goto-char (cdr buf-point))))
  346. buffer-points)))
  347. (defun edebug-current-windows (which-windows)
  348. ;; Get either a full window configuration or some window information.
  349. (if (listp which-windows)
  350. (mapcar (function (lambda (window)
  351. (if (edebug-window-live-p window)
  352. (list window
  353. (window-buffer window)
  354. (window-point window)
  355. (window-start window)
  356. (window-hscroll window)))))
  357. which-windows)
  358. (current-window-configuration)))
  359. (defun edebug-set-windows (window-info)
  360. ;; Set either a full window configuration or some window information.
  361. (if (listp window-info)
  362. (mapcar (function
  363. (lambda (one-window-info)
  364. (if one-window-info
  365. (apply (function
  366. (lambda (window buffer point start hscroll)
  367. (if (edebug-window-live-p window)
  368. (progn
  369. (set-window-buffer window buffer)
  370. (set-window-point window point)
  371. (set-window-start window start)
  372. (set-window-hscroll window hscroll)))))
  373. one-window-info))))
  374. window-info)
  375. (set-window-configuration window-info)))
  376. (defalias 'edebug-get-buffer-window 'get-buffer-window)
  377. (defalias 'edebug-sit-for 'sit-for)
  378. (defalias 'edebug-input-pending-p 'input-pending-p)
  379. ;;; Redefine read and eval functions
  380. ;; read is redefined to maybe instrument forms.
  381. ;; eval-defun is redefined to check edebug-all-forms and edebug-all-defs.
  382. ;; Save the original read function
  383. (or (fboundp 'edebug-original-read)
  384. (defalias 'edebug-original-read (symbol-function 'read)))
  385. (defun edebug-read (&optional stream)
  386. "Read one Lisp expression as text from STREAM, return as Lisp object.
  387. If STREAM is nil, use the value of `standard-input' (which see).
  388. STREAM or the value of `standard-input' may be:
  389. a buffer (read from point and advance it)
  390. a marker (read from where it points and advance it)
  391. a function (call it with no arguments for each character,
  392. call it with a char as argument to push a char back)
  393. a string (takes text from string, starting at the beginning)
  394. t (read text line using minibuffer and use it).
  395. This version, from Edebug, maybe instruments the expression. But the
  396. STREAM must be the current buffer to do so. Whether it instruments is
  397. also dependent on the values of `edebug-all-defs' and
  398. `edebug-all-forms'."
  399. (or stream (setq stream standard-input))
  400. (if (eq stream (current-buffer))
  401. (edebug-read-and-maybe-wrap-form)
  402. (edebug-original-read stream)))
  403. (or (fboundp 'edebug-original-eval-defun)
  404. (defalias 'edebug-original-eval-defun (symbol-function 'eval-defun)))
  405. ;; We should somehow arrange to be able to do this
  406. ;; without actually replacing the eval-defun command.
  407. (defun edebug-eval-defun (edebug-it)
  408. "Evaluate the top-level form containing point, or after point.
  409. If the current defun is actually a call to `defvar', then reset the
  410. variable using its initial value expression even if the variable
  411. already has some other value. (Normally `defvar' does not change the
  412. variable's value if it already has a value.) Treat `defcustom'
  413. similarly. Reinitialize the face according to `defface' specification.
  414. With a prefix argument, instrument the code for Edebug.
  415. Setting `edebug-all-defs' to a non-nil value reverses the meaning of
  416. the prefix argument. Code is then instrumented when this function is
  417. invoked without a prefix argument
  418. If acting on a `defun' for FUNCTION, and the function was instrumented,
  419. `Edebug: FUNCTION' is printed in the minibuffer. If not instrumented,
  420. just FUNCTION is printed.
  421. If not acting on a `defun', the result of evaluation is displayed in
  422. the minibuffer."
  423. (interactive "P")
  424. (let* ((edebugging (not (eq (not edebug-it) (not edebug-all-defs))))
  425. (edebug-result)
  426. (form
  427. (let ((edebug-all-forms edebugging)
  428. (edebug-all-defs (eq edebug-all-defs (not edebug-it))))
  429. (edebug-read-top-level-form))))
  430. ;; This should be consistent with `eval-defun-1', but not the
  431. ;; same, since that gets a macroexpanded form.
  432. (cond ((and (eq (car form) 'defvar)
  433. (cdr-safe (cdr-safe form)))
  434. ;; Force variable to be bound.
  435. (makunbound (nth 1 form)))
  436. ((and (eq (car form) 'defcustom)
  437. (default-boundp (nth 1 form)))
  438. ;; Force variable to be bound.
  439. ;; FIXME: Shouldn't this use the :setter or :initializer?
  440. (set-default (nth 1 form) (eval (nth 2 form) lexical-binding)))
  441. ((eq (car form) 'defface)
  442. ;; Reset the face.
  443. (setq face-new-frame-defaults
  444. (assq-delete-all (nth 1 form) face-new-frame-defaults))
  445. (put (nth 1 form) 'face-defface-spec nil)
  446. ;; See comments in `eval-defun-1' for purpose of code below
  447. (setq form (prog1 `(prog1 ,form
  448. (put ',(nth 1 form) 'saved-face
  449. ',(get (nth 1 form) 'saved-face))
  450. (put ',(nth 1 form) 'customized-face
  451. ,(nth 2 form)))
  452. (put (nth 1 form) 'saved-face nil)))))
  453. (setq edebug-result (eval (eval-sexp-add-defvars form) lexical-binding))
  454. (if (not edebugging)
  455. (princ edebug-result)
  456. edebug-result)))
  457. ;;;###autoload
  458. (defalias 'edebug-defun 'edebug-eval-top-level-form)
  459. ;;;###autoload
  460. (defun edebug-eval-top-level-form ()
  461. "Evaluate the top level form point is in, stepping through with Edebug.
  462. This is like `eval-defun' except that it steps the code for Edebug
  463. before evaluating it. It displays the value in the echo area
  464. using `eval-expression' (which see).
  465. If you do this on a function definition such as a defun or defmacro,
  466. it defines the function and instruments its definition for Edebug,
  467. so it will do Edebug stepping when called later. It displays
  468. `Edebug: FUNCTION' in the echo area to indicate that FUNCTION is now
  469. instrumented for Edebug.
  470. If the current defun is actually a call to `defvar' or `defcustom',
  471. evaluating it this way resets the variable using its initial value
  472. expression even if the variable already has some other value.
  473. \(Normally `defvar' and `defcustom' do not alter the value if there
  474. already is one.)"
  475. (interactive)
  476. (eval-expression
  477. ;; Bind edebug-all-forms only while reading, not while evalling
  478. ;; but this causes problems while edebugging edebug.
  479. (let ((edebug-all-forms t)
  480. (edebug-all-defs t))
  481. (eval-sexp-add-defvars
  482. (edebug-read-top-level-form)))))
  483. (defun edebug-read-top-level-form ()
  484. (let ((starting-point (point)))
  485. (end-of-defun)
  486. (beginning-of-defun)
  487. (prog1
  488. (edebug-read-and-maybe-wrap-form)
  489. ;; Recover point, but only if no error occurred.
  490. (goto-char starting-point))))
  491. ;; Compatibility with old versions.
  492. (defalias 'edebug-all-defuns 'edebug-all-defs)
  493. ;;;###autoload
  494. (defun edebug-all-defs ()
  495. "Toggle edebugging of all definitions."
  496. (interactive)
  497. (setq edebug-all-defs (not edebug-all-defs))
  498. (message "Edebugging all definitions is %s."
  499. (if edebug-all-defs "on" "off")))
  500. ;;;###autoload
  501. (defun edebug-all-forms ()
  502. "Toggle edebugging of all forms."
  503. (interactive)
  504. (setq edebug-all-forms (not edebug-all-forms))
  505. (message "Edebugging all forms is %s."
  506. (if edebug-all-forms "on" "off")))
  507. (defun edebug-install-read-eval-functions ()
  508. (interactive)
  509. ;; Don't install if already installed.
  510. (unless load-read-function
  511. (setq load-read-function 'edebug-read)
  512. (defalias 'eval-defun 'edebug-eval-defun)))
  513. (defun edebug-uninstall-read-eval-functions ()
  514. (interactive)
  515. (setq load-read-function nil)
  516. (defalias 'eval-defun (symbol-function 'edebug-original-eval-defun)))
  517. ;;; Edebug internal data
  518. ;; The internal data that is needed for edebugging is kept in the
  519. ;; buffer-local variable `edebug-form-data'.
  520. (make-variable-buffer-local 'edebug-form-data)
  521. (defvar edebug-form-data nil)
  522. ;; A list of entries associating symbols with buffer regions.
  523. ;; This is an automatic buffer local variable. Each entry looks like:
  524. ;; @code{(@var{symbol} @var{begin-marker} @var{end-marker}). The markers
  525. ;; are at the beginning and end of an entry level form and @var{symbol} is
  526. ;; a symbol that holds all edebug related information for the form on its
  527. ;; property list.
  528. ;; In the future, the symbol will be irrelevant and edebug data will
  529. ;; be stored in the definitions themselves rather than in the property
  530. ;; list of a symbol.
  531. (defun edebug-make-form-data-entry (symbol begin end)
  532. (list symbol begin end))
  533. (defsubst edebug-form-data-name (entry)
  534. (car entry))
  535. (defsubst edebug-form-data-begin (entry)
  536. (nth 1 entry))
  537. (defsubst edebug-form-data-end (entry)
  538. (nth 2 entry))
  539. (defsubst edebug-set-form-data-entry (entry name begin end)
  540. (setcar entry name);; in case name is changed
  541. (set-marker (nth 1 entry) begin)
  542. (set-marker (nth 2 entry) end))
  543. (defun edebug-get-form-data-entry (pnt &optional end-point)
  544. ;; Find the edebug form data entry which is closest to PNT.
  545. ;; If END-POINT is supplied, match must be exact.
  546. ;; Return `nil' if none found.
  547. (let ((rest edebug-form-data)
  548. closest-entry
  549. (closest-dist 999999)) ;; need maxint here
  550. (while (and rest (< 0 closest-dist))
  551. (let* ((entry (car rest))
  552. (begin (edebug-form-data-begin entry))
  553. (dist (- pnt begin)))
  554. (setq rest (cdr rest))
  555. (if (and (<= 0 dist)
  556. (< dist closest-dist)
  557. (or (not end-point)
  558. (= end-point (edebug-form-data-end entry)))
  559. (<= pnt (edebug-form-data-end entry)))
  560. (setq closest-dist dist
  561. closest-entry entry))))
  562. closest-entry))
  563. ;; Also need to find all contained entries,
  564. ;; and find an entry given a symbol, which should be just assq.
  565. (defun edebug-form-data-symbol ()
  566. ;; Return the edebug data symbol of the form where point is in.
  567. ;; If point is not inside a edebuggable form, cause error.
  568. (or (edebug-form-data-name (edebug-get-form-data-entry (point)))
  569. (error "Not inside instrumented form")))
  570. (defun edebug-make-top-form-data-entry (new-entry)
  571. ;; Make NEW-ENTRY the first element in the `edebug-form-data' list.
  572. (edebug-clear-form-data-entry new-entry)
  573. (setq edebug-form-data (cons new-entry edebug-form-data)))
  574. (defun edebug-clear-form-data-entry (entry)
  575. ;; If non-nil, clear ENTRY out of the form data.
  576. ;; Maybe clear the markers and delete the symbol's edebug property?
  577. (if entry
  578. (progn
  579. ;; Instead of this, we could just find all contained forms.
  580. ;; (put (car entry) 'edebug nil) ;
  581. ;; (mapcar 'edebug-clear-form-data-entry ; dangerous
  582. ;; (get (car entry) 'edebug-dependents))
  583. ;; (set-marker (nth 1 entry) nil)
  584. ;; (set-marker (nth 2 entry) nil)
  585. (setq edebug-form-data (delq entry edebug-form-data)))))
  586. ;;; Parser utilities
  587. (defun edebug-syntax-error (&rest args)
  588. ;; Signal an invalid-read-syntax with ARGS.
  589. (signal 'invalid-read-syntax args))
  590. (defconst edebug-read-syntax-table
  591. ;; Lookup table for significant characters indicating the class of the
  592. ;; token that follows. This is not a \"real\" syntax table.
  593. (let ((table (make-char-table 'syntax-table 'symbol))
  594. (i 0))
  595. (while (< i ?!)
  596. (aset table i 'space)
  597. (setq i (1+ i)))
  598. (aset table ?\( 'lparen)
  599. (aset table ?\) 'rparen)
  600. (aset table ?\' 'quote)
  601. (aset table ?\` 'backquote)
  602. (aset table ?\, 'comma)
  603. (aset table ?\" 'string)
  604. (aset table ?\? 'char)
  605. (aset table ?\[ 'lbracket)
  606. (aset table ?\] 'rbracket)
  607. (aset table ?\. 'dot)
  608. (aset table ?\# 'hash)
  609. ;; We treat numbers as symbols, because of confusion with -, -1, and 1-.
  610. ;; We don't care about any other chars since they won't be seen.
  611. table))
  612. (defun edebug-next-token-class ()
  613. ;; Move to the next token and return its class. We only care about
  614. ;; lparen, rparen, dot, quote, backquote, comma, string, char, vector,
  615. ;; or symbol.
  616. (edebug-skip-whitespace)
  617. (if (and (eq (following-char) ?.)
  618. (save-excursion
  619. (forward-char 1)
  620. (or (and (eq (aref edebug-read-syntax-table (following-char))
  621. 'symbol)
  622. (not (= (following-char) ?\;)))
  623. (memq (following-char) '(?\, ?\.)))))
  624. 'symbol
  625. (aref edebug-read-syntax-table (following-char))))
  626. (defun edebug-skip-whitespace ()
  627. ;; Leave point before the next token, skipping white space and comments.
  628. (skip-chars-forward " \t\r\n\f")
  629. (while (= (following-char) ?\;)
  630. (skip-chars-forward "^\n") ; skip the comment
  631. (skip-chars-forward " \t\r\n\f")))
  632. ;; Mostly obsolete reader; still used in one case.
  633. (defun edebug-read-sexp ()
  634. ;; Read one sexp from the current buffer starting at point.
  635. ;; Leave point immediately after it. A sexp can be a list or atom.
  636. ;; An atom is a symbol (or number), character, string, or vector.
  637. ;; This works for reading anything legitimate, but it
  638. ;; is gummed up by parser inconsistencies (bugs?)
  639. (let ((class (edebug-next-token-class)))
  640. (cond
  641. ;; read goes one too far if a (possibly quoted) string or symbol
  642. ;; is immediately followed by non-whitespace.
  643. ((eq class 'symbol) (edebug-original-read (current-buffer)))
  644. ((eq class 'string) (edebug-original-read (current-buffer)))
  645. ((eq class 'quote) (forward-char 1)
  646. (list 'quote (edebug-read-sexp)))
  647. ((eq class 'backquote)
  648. (list '\` (edebug-read-sexp)))
  649. ((eq class 'comma)
  650. (list '\, (edebug-read-sexp)))
  651. (t ; anything else, just read it.
  652. (edebug-original-read (current-buffer))))))
  653. ;;; Offsets for reader
  654. ;; Define a structure to represent offset positions of expressions.
  655. ;; Each offset structure looks like: (before . after) for constituents,
  656. ;; or for structures that have elements: (before <subexpressions> . after)
  657. ;; where the <subexpressions> are the offset structures for subexpressions
  658. ;; including the head of a list.
  659. (defvar edebug-offsets nil)
  660. ;; Stack of offset structures in reverse order of the nesting.
  661. ;; This is used to get back to previous levels.
  662. (defvar edebug-offsets-stack nil)
  663. (defvar edebug-current-offset nil) ; Top of the stack, for convenience.
  664. ;; We must store whether we just read a list with a dotted form that
  665. ;; is itself a list. This structure will be condensed, so the offsets
  666. ;; must also be condensed.
  667. (defvar edebug-read-dotted-list nil)
  668. (defsubst edebug-initialize-offsets ()
  669. ;; Reinitialize offset recording.
  670. (setq edebug-current-offset nil))
  671. (defun edebug-store-before-offset (point)
  672. ;; Add a new offset pair with POINT as the before offset.
  673. (let ((new-offset (list point)))
  674. (if edebug-current-offset
  675. (setcdr edebug-current-offset
  676. (cons new-offset (cdr edebug-current-offset)))
  677. ;; Otherwise, we are at the top level, so initialize.
  678. (setq edebug-offsets new-offset
  679. edebug-offsets-stack nil
  680. edebug-read-dotted-list nil))
  681. ;; Cons the new offset to the front of the stack.
  682. (setq edebug-offsets-stack (cons new-offset edebug-offsets-stack)
  683. edebug-current-offset new-offset)
  684. ))
  685. (defun edebug-store-after-offset (point)
  686. ;; Finalize the current offset struct by reversing it and
  687. ;; store POINT as the after offset.
  688. (if (not edebug-read-dotted-list)
  689. ;; Just reverse the offsets of all subexpressions.
  690. (setcdr edebug-current-offset (nreverse (cdr edebug-current-offset)))
  691. ;; We just read a list after a dot, which will be abbreviated out.
  692. (setq edebug-read-dotted-list nil)
  693. ;; Drop the corresponding offset pair.
  694. ;; That is, nconc the reverse of the rest of the offsets
  695. ;; with the cdr of last offset.
  696. (setcdr edebug-current-offset
  697. (nconc (nreverse (cdr (cdr edebug-current-offset)))
  698. (cdr (car (cdr edebug-current-offset))))))
  699. ;; Now append the point using nconc.
  700. (setq edebug-current-offset (nconc edebug-current-offset point))
  701. ;; Pop the stack.
  702. (setq edebug-offsets-stack (cdr edebug-offsets-stack)
  703. edebug-current-offset (car edebug-offsets-stack)))
  704. (defun edebug-ignore-offset ()
  705. ;; Ignore the last created offset pair.
  706. (setcdr edebug-current-offset (cdr (cdr edebug-current-offset))))
  707. (defmacro edebug-storing-offsets (point &rest body)
  708. (declare (debug (form body)) (indent 1))
  709. `(unwind-protect
  710. (progn
  711. (edebug-store-before-offset ,point)
  712. ,@body)
  713. (edebug-store-after-offset (point))))
  714. ;;; Reader for Emacs Lisp.
  715. ;; Uses edebug-next-token-class (and edebug-skip-whitespace) above.
  716. (defconst edebug-read-alist
  717. '((symbol . edebug-read-symbol)
  718. (lparen . edebug-read-list)
  719. (string . edebug-read-string)
  720. (quote . edebug-read-quote)
  721. (backquote . edebug-read-backquote)
  722. (comma . edebug-read-comma)
  723. (lbracket . edebug-read-vector)
  724. (hash . edebug-read-function)
  725. ))
  726. (defun edebug-read-storing-offsets (stream)
  727. (let (edebug-read-dotted-list) ; see edebug-store-after-offset
  728. (edebug-storing-offsets (point)
  729. (funcall
  730. (or (cdr (assq (edebug-next-token-class) edebug-read-alist))
  731. ;; anything else, just read it.
  732. 'edebug-original-read)
  733. stream))))
  734. (defun edebug-read-symbol (stream)
  735. (edebug-original-read stream))
  736. (defun edebug-read-string (stream)
  737. (edebug-original-read stream))
  738. (defun edebug-read-quote (stream)
  739. ;; Turn 'thing into (quote thing)
  740. (forward-char 1)
  741. (list
  742. (edebug-storing-offsets (1- (point)) 'quote)
  743. (edebug-read-storing-offsets stream)))
  744. (defun edebug-read-backquote (stream)
  745. ;; Turn `thing into (\` thing)
  746. (forward-char 1)
  747. (list
  748. (edebug-storing-offsets (1- (point)) '\`)
  749. (edebug-read-storing-offsets stream)))
  750. (defun edebug-read-comma (stream)
  751. ;; Turn ,thing into (\, thing). Handle ,@ and ,. also.
  752. (let ((opoint (point)))
  753. (forward-char 1)
  754. (let ((symbol '\,))
  755. (cond ((eq (following-char) ?\.)
  756. (setq symbol '\,\.)
  757. (forward-char 1))
  758. ((eq (following-char) ?\@)
  759. (setq symbol '\,@)
  760. (forward-char 1)))
  761. ;; Generate the same structure of offsets we would have
  762. ;; if the resulting list appeared verbatim in the input text.
  763. (list
  764. (edebug-storing-offsets opoint symbol)
  765. (edebug-read-storing-offsets stream)))))
  766. (defun edebug-read-function (stream)
  767. ;; Turn #'thing into (function thing)
  768. (forward-char 1)
  769. (cond ((eq ?\' (following-char))
  770. (forward-char 1)
  771. (list
  772. (edebug-storing-offsets (- (point) 2)
  773. (if (featurep 'cl) 'function* 'function))
  774. (edebug-read-storing-offsets stream)))
  775. ((memq (following-char) '(?: ?B ?O ?X ?b ?o ?x ?1 ?2 ?3 ?4 ?5 ?6
  776. ?7 ?8 ?9 ?0))
  777. (backward-char 1)
  778. (edebug-original-read stream))
  779. (t (edebug-syntax-error "Bad char after #"))))
  780. (defun edebug-read-list (stream)
  781. (forward-char 1) ; skip \(
  782. (prog1
  783. (let ((elements))
  784. (while (not (memq (edebug-next-token-class) '(rparen dot)))
  785. (push (edebug-read-storing-offsets stream) elements))
  786. (setq elements (nreverse elements))
  787. (if (eq 'dot (edebug-next-token-class))
  788. (let (dotted-form)
  789. (forward-char 1) ; skip \.
  790. (setq dotted-form (edebug-read-storing-offsets stream))
  791. elements (nconc elements dotted-form)
  792. (if (not (eq (edebug-next-token-class) 'rparen))
  793. (edebug-syntax-error "Expected `)'"))
  794. (setq edebug-read-dotted-list (listp dotted-form))
  795. ))
  796. elements)
  797. (forward-char 1) ; skip \)
  798. ))
  799. (defun edebug-read-vector (stream)
  800. (forward-char 1) ; skip \[
  801. (prog1
  802. (let ((elements))
  803. (while (not (eq 'rbracket (edebug-next-token-class)))
  804. (push (edebug-read-storing-offsets stream) elements))
  805. (apply 'vector (nreverse elements)))
  806. (forward-char 1) ; skip \]
  807. ))
  808. ;;; Cursors for traversal of list and vector elements with offsets.
  809. (defvar edebug-dotted-spec nil)
  810. (defun edebug-new-cursor (expressions offsets)
  811. ;; Return a new cursor for EXPRESSIONS with OFFSETS.
  812. (if (vectorp expressions)
  813. (setq expressions (append expressions nil)))
  814. (cons expressions offsets))
  815. (defsubst edebug-set-cursor (cursor expressions offsets)
  816. ;; Set the CURSOR's EXPRESSIONS and OFFSETS to the given.
  817. ;; Return the cursor.
  818. (setcar cursor expressions)
  819. (setcdr cursor offsets)
  820. cursor)
  821. (defun edebug-copy-cursor (cursor)
  822. ;; Copy the cursor using the same object and offsets.
  823. (cons (car cursor) (cdr cursor)))
  824. (defsubst edebug-cursor-expressions (cursor)
  825. (car cursor))
  826. (defsubst edebug-cursor-offsets (cursor)
  827. (cdr cursor))
  828. (defsubst edebug-empty-cursor (cursor)
  829. ;; Return non-nil if CURSOR is empty - meaning no more elements.
  830. (null (car cursor)))
  831. (defsubst edebug-top-element (cursor)
  832. ;; Return the top element at the cursor.
  833. ;; Assumes not empty.
  834. (car (car cursor)))
  835. (defun edebug-top-element-required (cursor &rest error)
  836. ;; Check if a dotted form is required.
  837. (if edebug-dotted-spec (edebug-no-match cursor "Dot expected."))
  838. ;; Check if there is at least one more argument.
  839. (if (edebug-empty-cursor cursor) (apply 'edebug-no-match cursor error))
  840. ;; Return that top element.
  841. (edebug-top-element cursor))
  842. (defsubst edebug-top-offset (cursor)
  843. ;; Return the top offset pair corresponding to the top element.
  844. (car (cdr cursor)))
  845. (defun edebug-move-cursor (cursor)
  846. ;; Advance and return the cursor to the next element and offset.
  847. ;; throw no-match if empty before moving.
  848. ;; This is a violation of the cursor encapsulation, but
  849. ;; there is plenty of that going on while matching.
  850. ;; The following test should always fail.
  851. (if (edebug-empty-cursor cursor)
  852. (edebug-no-match cursor "Not enough arguments."))
  853. (setcar cursor (cdr (car cursor)))
  854. (setcdr cursor (cdr (cdr cursor)))
  855. cursor)
  856. (defun edebug-before-offset (cursor)
  857. ;; Return the before offset of the cursor.
  858. ;; If there is nothing left in the offsets,
  859. ;; return one less than the offset itself,
  860. ;; which is the after offset for a list.
  861. (let ((offset (edebug-cursor-offsets cursor)))
  862. (if (consp offset)
  863. (car (car offset))
  864. (1- offset))))
  865. (defun edebug-after-offset (cursor)
  866. ;; Return the after offset of the cursor object.
  867. (let ((offset (edebug-top-offset cursor)))
  868. (while (consp offset)
  869. (setq offset (cdr offset)))
  870. offset))
  871. ;;; The Parser
  872. ;; The top level function for parsing forms is
  873. ;; edebug-read-and-maybe-wrap-form; it calls all the rest. It checks the
  874. ;; syntax a bit and leaves point at any error it finds, but otherwise
  875. ;; should appear to work like eval-defun.
  876. ;; The basic plan is to surround each expression with a call to
  877. ;; the edebug debugger together with indexes into a table of positions of
  878. ;; all expressions. Thus an expression "exp" becomes:
  879. ;; (edebug-after (edebug-before 1) 2 exp)
  880. ;; When this is evaluated, first point is moved to the beginning of
  881. ;; exp at offset 1 of the current function. The expression is
  882. ;; evaluated, which may cause more edebug calls, and then point is
  883. ;; moved to offset 2 after the end of exp.
  884. ;; The highest level expressions of the function are wrapped in a call to
  885. ;; edebug-enter, which supplies the function name and the actual
  886. ;; arguments to the function. See functions edebug-enter, edebug-before,
  887. ;; and edebug-after for more details.
  888. ;; Dynamically bound vars, left unbound, but globally declared.
  889. ;; This is to quiet the byte compiler.
  890. ;; Window data of the highest definition being wrapped.
  891. ;; This data is shared by all embedded definitions.
  892. (defvar edebug-top-window-data)
  893. (defvar edebug-&optional)
  894. (defvar edebug-&rest)
  895. (defvar edebug-gate nil) ;; whether no-match forces an error.
  896. (defvar edebug-def-name nil) ; name of definition, used by interactive-form
  897. (defvar edebug-old-def-name nil) ; previous name of containing definition.
  898. (defvar edebug-error-point nil)
  899. (defvar edebug-best-error nil)
  900. (defun edebug-read-and-maybe-wrap-form ()
  901. ;; Read a form and wrap it with edebug calls, if the conditions are right.
  902. ;; Here we just catch any no-match not caught below and signal an error.
  903. ;; Run the setup hook.
  904. ;; If it gets an error, make it nil.
  905. (let ((temp-hook edebug-setup-hook))
  906. (setq edebug-setup-hook nil)
  907. (run-hooks 'temp-hook))
  908. (let (result
  909. edebug-top-window-data
  910. edebug-def-name;; make sure it is locally nil
  911. ;; I don't like these here!!
  912. edebug-&optional
  913. edebug-&rest
  914. edebug-gate
  915. edebug-best-error
  916. edebug-error-point
  917. no-match
  918. ;; Do this once here instead of several times.
  919. (max-lisp-eval-depth (+ 800 max-lisp-eval-depth))
  920. (max-specpdl-size (+ 2000 max-specpdl-size)))
  921. (setq no-match
  922. (catch 'no-match
  923. (setq result (edebug-read-and-maybe-wrap-form1))
  924. nil))
  925. (if no-match
  926. (apply 'edebug-syntax-error no-match))
  927. result))
  928. (defun edebug-read-and-maybe-wrap-form1 ()
  929. (let (spec
  930. def-kind
  931. defining-form-p
  932. def-name
  933. ;; These offset things don't belong here, but to support recursive
  934. ;; calls to edebug-read, they need to be here.
  935. edebug-offsets
  936. edebug-offsets-stack
  937. edebug-current-offset ; reset to nil
  938. )
  939. (save-excursion
  940. (if (and (eq 'lparen (edebug-next-token-class))
  941. (eq 'symbol (progn (forward-char 1) (edebug-next-token-class))))
  942. ;; Find out if this is a defining form from first symbol
  943. (setq def-kind (edebug-original-read (current-buffer))
  944. spec (and (symbolp def-kind) (get-edebug-spec def-kind))
  945. defining-form-p (and (listp spec)
  946. (eq '&define (car spec)))
  947. ;; This is incorrect in general!! But OK most of the time.
  948. def-name (if (and defining-form-p
  949. (eq 'name (car (cdr spec)))
  950. (eq 'symbol (edebug-next-token-class)))
  951. (edebug-original-read (current-buffer))))))
  952. ;;;(message "all defs: %s all forms: %s" edebug-all-defs edebug-all-forms)
  953. (cond
  954. (defining-form-p
  955. (if (or edebug-all-defs edebug-all-forms)
  956. ;; If it is a defining form and we are edebugging defs,
  957. ;; then let edebug-list-form start it.
  958. (let ((cursor (edebug-new-cursor
  959. (list (edebug-read-storing-offsets (current-buffer)))
  960. (list edebug-offsets))))
  961. (car
  962. (edebug-make-form-wrapper
  963. cursor
  964. (edebug-before-offset cursor)
  965. (1- (edebug-after-offset cursor))
  966. (list (cons (symbol-name def-kind) (cdr spec))))))
  967. ;; Not edebugging this form, so reset the symbol's edebug
  968. ;; property to be just a marker at the definition's source code.
  969. ;; This only works for defs with simple names.
  970. (put def-name 'edebug (point-marker))
  971. ;; Also nil out dependent defs.
  972. '(mapcar (function
  973. (lambda (def)
  974. (put def-name 'edebug nil)))
  975. (get def-name 'edebug-dependents))
  976. (edebug-read-sexp)))
  977. ;; If all forms are being edebugged, explicitly wrap it.
  978. (edebug-all-forms
  979. (let ((cursor (edebug-new-cursor
  980. (list (edebug-read-storing-offsets (current-buffer)))
  981. (list edebug-offsets))))
  982. (edebug-make-form-wrapper
  983. cursor
  984. (edebug-before-offset cursor)
  985. (edebug-after-offset cursor)
  986. nil)))
  987. ;; Not a defining form, and not edebugging.
  988. (t (edebug-read-sexp)))
  989. ))
  990. (defvar edebug-def-args) ; args of defining form.
  991. (defvar edebug-def-interactive) ; is it an emacs interactive function?
  992. (defvar edebug-inside-func) ;; whether code is inside function context.
  993. ;; Currently def-form sets this to nil; def-body sets it to t.
  994. (defun edebug-interactive-p-name ()
  995. ;; Return a unique symbol for the variable used to store the
  996. ;; status of interactive-p for this function.
  997. (intern (format "edebug-%s-interactive-p" edebug-def-name)))
  998. (defun edebug-wrap-def-body (forms)
  999. "Wrap the FORMS of a definition body."
  1000. (if edebug-def-interactive
  1001. `(let ((,(edebug-interactive-p-name)
  1002. (interactive-p)))
  1003. ,(edebug-make-enter-wrapper forms))
  1004. (edebug-make-enter-wrapper forms)))
  1005. (defun edebug-make-enter-wrapper (forms)
  1006. ;; Generate the enter wrapper for some forms of a definition.
  1007. ;; This is not to be used for the body of other forms, e.g. `while',
  1008. ;; since it wraps the list of forms with a call to `edebug-enter'.
  1009. ;; Uses the dynamically bound vars edebug-def-name and edebug-def-args.
  1010. ;; Do this after parsing since that may find a name.
  1011. (setq edebug-def-name
  1012. (or edebug-def-name edebug-old-def-name (edebug-gensym "edebug-anon")))
  1013. `(edebug-enter
  1014. (quote ,edebug-def-name)
  1015. ,(if edebug-inside-func
  1016. `(list
  1017. ;; Doesn't work with more than one def-body!!
  1018. ;; But the list will just be reversed.
  1019. ,@(nreverse edebug-def-args))
  1020. 'nil)
  1021. (function (lambda () ,@forms))
  1022. ))
  1023. (defvar edebug-form-begin-marker) ; the mark for def being instrumented
  1024. (defvar edebug-offset-index) ; the next available offset index.
  1025. (defvar edebug-offset-list) ; the list of offset positions.
  1026. (defun edebug-inc-offset (offset)
  1027. ;; modifies edebug-offset-index and edebug-offset-list
  1028. ;; accesses edebug-func-marc and buffer point
  1029. (prog1
  1030. edebug-offset-index
  1031. (setq edebug-offset-list (cons (- offset edebug-form-begin-marker)
  1032. edebug-offset-list)
  1033. edebug-offset-index (1+ edebug-offset-index))))
  1034. (defun edebug-make-before-and-after-form (before-index form after-index)
  1035. ;; Return the edebug form for the current function at offset BEFORE-INDEX
  1036. ;; given FORM. Looks like:
  1037. ;; (edebug-after (edebug-before BEFORE-INDEX) AFTER-INDEX FORM)
  1038. ;; Also increment the offset index for subsequent use.
  1039. (list 'edebug-after
  1040. (list 'edebug-before before-index)
  1041. after-index form))
  1042. (defun edebug-make-after-form (form after-index)
  1043. ;; Like edebug-make-before-and-after-form, but only after.
  1044. (list 'edebug-after 0 after-index form))
  1045. (defun edebug-unwrap (sexp)
  1046. "Return the unwrapped SEXP or return it as is if it is not wrapped.
  1047. The SEXP might be the result of wrapping a body, which is a list of
  1048. expressions; a `progn' form will be returned enclosing these forms."
  1049. (if (consp sexp)
  1050. (cond
  1051. ((eq 'edebug-after (car sexp))
  1052. (nth 3 sexp))
  1053. ((eq 'edebug-enter (car sexp))
  1054. (let ((forms (nthcdr 2 (nth 1 (nth 3 sexp)))))
  1055. (if (> (length forms) 1)
  1056. (cons 'progn forms) ;; could return (values forms) instead.
  1057. (car forms))))
  1058. (t sexp);; otherwise it is not wrapped, so just return it.
  1059. )
  1060. sexp))
  1061. (defun edebug-unwrap* (sexp)
  1062. "Return the SEXP recursively unwrapped."
  1063. (let ((new-sexp (edebug-unwrap sexp)))
  1064. (while (not (eq sexp new-sexp))
  1065. (setq sexp new-sexp
  1066. new-sexp (edebug-unwrap sexp)))
  1067. (if (consp new-sexp)
  1068. (mapcar 'edebug-unwrap* new-sexp)
  1069. new-sexp)))
  1070. (defun edebug-defining-form (cursor form-begin form-end speclist)
  1071. ;; Process the defining form, starting outside the form.
  1072. ;; The speclist is a generated list spec that looks like:
  1073. ;; (("def-symbol" defining-form-spec-sans-&define))
  1074. ;; Skip the first offset.
  1075. (edebug-set-cursor cursor (edebug-cursor-expressions cursor)
  1076. (cdr (edebug-cursor-offsets cursor)))
  1077. (edebug-make-form-wrapper
  1078. cursor
  1079. form-begin (1- form-end)
  1080. speclist))
  1081. (defun edebug-make-form-wrapper (cursor form-begin form-end
  1082. &optional speclist)
  1083. ;; Wrap a form, usually a defining form, but any evaluated one.
  1084. ;; If speclist is non-nil, this is being called by edebug-defining-form.
  1085. ;; Otherwise it is being called from edebug-read-and-maybe-wrap-form1.
  1086. ;; This is a hack, but I haven't figured out a simpler way yet.
  1087. (let* ((form-data-entry (edebug-get-form-data-entry form-begin form-end))
  1088. ;; Set this marker before parsing.
  1089. (edebug-form-begin-marker
  1090. (if form-data-entry
  1091. (edebug-form-data-begin form-data-entry)
  1092. ;; Buffer must be current-buffer for this to work:
  1093. (set-marker (make-marker) form-begin))))
  1094. (let (edebug-offset-list
  1095. (edebug-offset-index 0)
  1096. result
  1097. ;; For definitions.
  1098. ;; (edebug-containing-def-name edebug-def-name)
  1099. ;; Get name from form-data, if any.
  1100. (edebug-old-def-name (edebug-form-data-name form-data-entry))
  1101. edebug-def-name
  1102. edebug-def-args
  1103. edebug-def-interactive
  1104. edebug-inside-func;; whether wrapped code executes inside a function.
  1105. )
  1106. (setq result
  1107. (if speclist
  1108. (edebug-match cursor speclist)
  1109. ;; else wrap as an enter-form.
  1110. (edebug-make-enter-wrapper (list (edebug-form cursor)))))
  1111. ;; Set the name here if it was not set by edebug-make-enter-wrapper.
  1112. (setq edebug-def-name
  1113. (or edebug-def-name edebug-old-def-name (edebug-gensym "edebug-anon")))
  1114. ;; Add this def as a dependent of containing def. Buggy.
  1115. '(if (and edebug-containing-def-name
  1116. (not (get edebug-containing-def-name 'edebug-dependents)))
  1117. (put edebug-containing-def-name 'edebug-dependents
  1118. (cons edebug-def-name
  1119. (get edebug-containing-def-name
  1120. 'edebug-dependents))))
  1121. ;; Create a form-data-entry or modify existing entry's markers.
  1122. ;; In the latter case, pointers to the entry remain eq.
  1123. (if (not form-data-entry)
  1124. (setq form-data-entry
  1125. (edebug-make-form-data-entry
  1126. edebug-def-name
  1127. edebug-form-begin-marker
  1128. ;; Buffer must be current-buffer.
  1129. (set-marker (make-marker) form-end)
  1130. ))
  1131. (edebug-set-form-data-entry
  1132. form-data-entry edebug-def-name ;; in case name is changed
  1133. form-begin form-end))
  1134. ;; (message "defining: %s" edebug-def-name) (sit-for 2)
  1135. (edebug-make-top-form-data-entry form-data-entry)
  1136. (message "Edebug: %s" edebug-def-name)
  1137. ;;(debug edebug-def-name)
  1138. ;; Destructively reverse edebug-offset-list and make vector from it.
  1139. (setq edebug-offset-list (vconcat (nreverse edebug-offset-list)))
  1140. ;; Side effects on the property list of edebug-def-name.
  1141. (edebug-clear-frequency-count edebug-def-name)
  1142. (edebug-clear-coverage edebug-def-name)
  1143. ;; Set up the initial window data.
  1144. (if (not edebug-top-window-data) ;; if not already set, do it now.
  1145. (let ((window ;; Find the best window for this buffer.
  1146. (or (get-buffer-window (current-buffer))
  1147. (selected-window))))
  1148. (setq edebug-top-window-data
  1149. (cons window (window-start window)))))
  1150. ;; Store the edebug data in symbol's property list.
  1151. (put edebug-def-name 'edebug
  1152. ;; A struct or vector would be better here!!
  1153. (list edebug-form-begin-marker
  1154. nil ; clear breakpoints
  1155. edebug-offset-list
  1156. edebug-top-window-data
  1157. ))
  1158. result
  1159. )))
  1160. (defun edebug-clear-frequency-count (name)
  1161. ;; Create initial frequency count vector.
  1162. ;; For each stop point, the counter is incremented each time it is visited.
  1163. (put name 'edebug-freq-count
  1164. (make-vector (length edebug-offset-list) 0)))
  1165. (defun edebug-clear-coverage (name)
  1166. ;; Create initial coverage vector.
  1167. ;; Only need one per expression, but it is simpler to use stop points.
  1168. (put name 'edebug-coverage
  1169. (make-vector (length edebug-offset-list) 'unknown)))
  1170. (defun edebug-form (cursor)
  1171. ;; Return the instrumented form for the following form.
  1172. ;; Add the point offsets to the edebug-offset-list for the form.
  1173. (let* ((form (edebug-top-element-required cursor "Expected form"))
  1174. (offset (edebug-top-offset cursor)))
  1175. (prog1
  1176. (cond
  1177. ((consp form)
  1178. ;; The first offset for a list form is for the list form itself.
  1179. (if (eq 'quote (car form))
  1180. form
  1181. (let* ((head (car form))
  1182. (spec (and (symbolp head) (get-edebug-spec head)))
  1183. (new-cursor (edebug-new-cursor form offset)))
  1184. ;; Find out if this is a defining form from first symbol.
  1185. ;; An indirect spec would not work here, yet.
  1186. (if (and (consp spec) (eq '&define (car spec)))
  1187. (edebug-defining-form
  1188. new-cursor
  1189. (car offset);; before the form
  1190. (edebug-after-offset cursor)
  1191. (cons (symbol-name head) (cdr spec)))
  1192. ;; Wrap a regular form.
  1193. (edebug-make-before-and-after-form
  1194. (edebug-inc-offset (car offset))
  1195. (edebug-list-form new-cursor)
  1196. ;; After processing the list form, the new-cursor is left
  1197. ;; with the offset after the form.
  1198. (edebug-inc-offset (edebug-cursor-offsets new-cursor))))
  1199. )))
  1200. ((symbolp form)
  1201. (cond
  1202. ;; Check for constant symbols that don't get wrapped.
  1203. ((or (memq form '(t nil))
  1204. (keywordp form))
  1205. form)
  1206. (t ;; just a variable
  1207. (edebug-make-after-form form (edebug-inc-offset (cdr offset))))))
  1208. ;; Anything else is self-evaluating.
  1209. (t form))
  1210. (edebug-move-cursor cursor))))
  1211. (defsubst edebug-forms (cursor) (edebug-match cursor '(&rest form)))
  1212. (defsubst edebug-sexps (cursor) (edebug-match cursor '(&rest sexp)))
  1213. (defsubst edebug-list-form-args (head cursor)
  1214. ;; Process the arguments of a list form given that head of form is a symbol.
  1215. ;; Helper for edebug-list-form
  1216. (let ((spec (get-edebug-spec head)))
  1217. (cond
  1218. (spec
  1219. (cond
  1220. ((consp spec)
  1221. ;; It is a speclist.
  1222. (let (edebug-best-error
  1223. edebug-error-point);; This may not be needed.
  1224. (edebug-match-sublist cursor spec)))
  1225. ((eq t spec) (edebug-forms cursor))
  1226. ((eq 0 spec) (edebug-sexps cursor))
  1227. ((symbolp spec) (funcall spec cursor));; Not used by edebug,
  1228. ; but leave it in for compatibility.
  1229. ))
  1230. ;; No edebug-form-spec provided.
  1231. ((edebug-macrop head)
  1232. (if edebug-eval-macro-args
  1233. (edebug-forms cursor)
  1234. (edebug-sexps cursor)))
  1235. (t ;; Otherwise it is a function call.
  1236. (edebug-forms cursor)))))
  1237. (defun edebug-list-form (cursor)
  1238. ;; Return an instrumented form built from the list form.
  1239. ;; The after offset will be left in the cursor after processing the form.
  1240. (let ((head (edebug-top-element-required cursor "Expected elements"))
  1241. ;; Prevent backtracking whenever instrumenting.
  1242. (edebug-gate t)
  1243. ;; A list form is never optional because it matches anything.
  1244. (edebug-&optional nil)
  1245. (edebug-&rest nil))
  1246. ;; Skip the first offset.
  1247. (edebug-set-cursor cursor (edebug-cursor-expressions cursor)
  1248. (cdr (edebug-cursor-offsets cursor)))
  1249. (cond
  1250. ((symbolp head)
  1251. (cond
  1252. ((null head) nil) ; () is valid.
  1253. ((eq head 'interactive-p)
  1254. ;; Special case: replace (interactive-p) with variable
  1255. (setq edebug-def-interactive 'check-it)
  1256. (edebug-move-cursor cursor)
  1257. (edebug-interactive-p-name))
  1258. (t
  1259. (cons head (edebug-list-form-args
  1260. head (edebug-move-cursor cursor))))))
  1261. ((consp head)
  1262. (if (eq (car head) '\,)
  1263. ;; The head of a form should normally be a symbol or a lambda
  1264. ;; expression but it can also be an unquote form to be filled
  1265. ;; before evaluation. We evaluate the arguments anyway, on the
  1266. ;; assumption that the unquote form will place a proper function
  1267. ;; name (rather than a macro name).
  1268. (edebug-match cursor '(("," def-form) body))
  1269. ;; Process anonymous function and args.
  1270. ;; This assumes no anonymous macros.
  1271. (edebug-match-specs cursor '(lambda-expr body) 'edebug-match-specs)))
  1272. (t (edebug-syntax-error
  1273. "Head of list form must be a symbol or lambda expression")))
  1274. ))
  1275. ;;; Matching of specs.
  1276. (defvar edebug-after-dotted-spec nil)
  1277. (defvar edebug-matching-depth 0) ;; initial value
  1278. (defconst edebug-max-depth 150) ;; maximum number of matching recursions.
  1279. ;;; Failure to match
  1280. ;; This throws to no-match, if there are higher alternatives.
  1281. ;; Otherwise it signals an error. The place of the error is found
  1282. ;; with the two before- and after-offset functions.
  1283. (defun edebug-no-match (cursor &rest edebug-args)
  1284. ;; Throw a no-match, or signal an error immediately if gate is active.
  1285. ;; Remember this point in case we need to report this error.
  1286. (setq edebug-error-point (or edebug-error-point
  1287. (edebug-before-offset cursor))
  1288. edebug-best-error (or edebug-best-error edebug-args))
  1289. (if (and edebug-gate (not edebug-&optional))
  1290. (progn
  1291. (if edebug-error-point
  1292. (goto-char edebug-error-point))
  1293. (apply 'edebug-syntax-error edebug-args))
  1294. (funcall 'throw 'no-match edebug-args)))
  1295. (defun edebug-match (cursor specs)
  1296. ;; Top level spec matching function.
  1297. ;; Used also at each lower level of specs.
  1298. (let (edebug-&optional
  1299. edebug-&rest
  1300. edebug-best-error
  1301. edebug-error-point
  1302. (edebug-gate edebug-gate) ;; locally bound to limit effect
  1303. )
  1304. (edebug-match-specs cursor specs 'edebug-match-specs)))
  1305. (defun edebug-match-one-spec (cursor spec)
  1306. ;; Match one spec, which is not a keyword &-spec.
  1307. (cond
  1308. ((symbolp spec) (edebug-match-symbol cursor spec))
  1309. ((vectorp spec) (edebug-match cursor (append spec nil)))
  1310. ((stringp spec) (edebug-match-string cursor spec))
  1311. ((listp spec) (edebug-match-list cursor spec))
  1312. ))
  1313. (defun edebug-match-specs (cursor specs remainder-handler)
  1314. ;; Append results of matching the list of specs.
  1315. ;; The first spec is handled and the remainder-handler handles the rest.
  1316. (let ((edebug-matching-depth
  1317. (if (> edebug-matching-depth edebug-max-depth)
  1318. (error "Too deep - perhaps infinite loop in spec?")
  1319. (1+ edebug-matching-depth))))
  1320. (cond
  1321. ((null specs) nil)
  1322. ;; Is the spec dotted?
  1323. ((atom specs)
  1324. (let ((edebug-dotted-spec t));; Containing spec list was dotted.
  1325. (edebug-match-specs cursor (list specs) remainder-handler)))
  1326. ;; Is the form dotted?
  1327. ((not (listp (edebug-cursor-expressions cursor)));; allow nil
  1328. (if (not edebug-dotted-spec)
  1329. (edebug-no-match cursor "Dotted spec required."))
  1330. ;; Cancel dotted spec and dotted form.
  1331. (let ((edebug-dotted-spec)
  1332. (this-form (edebug-cursor-expressions cursor))
  1333. (this-offset (edebug-cursor-offsets cursor)))
  1334. ;; Wrap the form in a list, (by changing the cursor??)...
  1335. (edebug-set-cursor cursor (list this-form) this-offset)
  1336. ;; and process normally, then unwrap the result.
  1337. (car (edebug-match-specs cursor specs remainder-handler))))
  1338. (t;; Process normally.
  1339. (let* ((spec (car specs))
  1340. (rest)
  1341. (first-char (and (symbolp spec) (aref (symbol-name spec) 0))))
  1342. ;;(message "spec = %s first char = %s" spec first-char) (sit-for 1)
  1343. (nconc
  1344. (cond
  1345. ((eq ?& first-char);; "&" symbols take all following specs.
  1346. (funcall (get-edebug-spec spec) cursor (cdr specs)))
  1347. ((eq ?: first-char);; ":" symbols take one following spec.
  1348. (setq rest (cdr (cdr specs)))
  1349. (funcall (get-edebug-spec spec) cursor (car (cdr specs))))
  1350. (t;; Any other normal spec.
  1351. (setq rest (cdr specs))
  1352. (edebug-match-one-spec cursor spec)))
  1353. (funcall remainder-handler cursor rest remainder-handler)))))))
  1354. ;; Define specs for all the symbol specs with functions used to process them.
  1355. ;; Perhaps we shouldn't be doing this with edebug-form-specs since the
  1356. ;; user may want to define macros or functions with the same names.
  1357. ;; We could use an internal obarray for these primitive specs.
  1358. (dolist (pair '((&optional . edebug-match-&optional)
  1359. (&rest . edebug-match-&rest)
  1360. (&or . edebug-match-&or)
  1361. (form . edebug-match-form)
  1362. (sexp . edebug-match-sexp)
  1363. (body . edebug-match-body)
  1364. (&define . edebug-match-&define)
  1365. (name . edebug-match-name)
  1366. (:name . edebug-match-colon-name)
  1367. (arg . edebug-match-arg)
  1368. (def-body . edebug-match-def-body)
  1369. (def-form . edebug-match-def-form)
  1370. ;; Less frequently used:
  1371. ;; (function . edebug-match-function)
  1372. (lambda-expr . edebug-match-lambda-expr)
  1373. (&not . edebug-match-&not)
  1374. (&key . edebug-match-&key)
  1375. (place . edebug-match-place)
  1376. (gate . edebug-match-gate)
  1377. ;; (nil . edebug-match-nil) not this one - special case it.
  1378. ))
  1379. (put (car pair) 'edebug-form-spec (cdr pair)))
  1380. (defun edebug-match-symbol (cursor symbol)
  1381. ;; Match a symbol spec.
  1382. (let* ((spec (get-edebug-spec symbol)))
  1383. (cond
  1384. (spec
  1385. (if (consp spec)
  1386. ;; It is an indirect spec.
  1387. (edebug-match cursor spec)
  1388. ;; Otherwise it should be the symbol name of a function.
  1389. ;; There could be a bug here - maybe need to do edebug-match bindings.
  1390. (funcall spec cursor)))
  1391. ((null symbol) ;; special case this.
  1392. (edebug-match-nil cursor))
  1393. ((fboundp symbol) ; is it a predicate?
  1394. (let ((sexp (edebug-top-element-required cursor "Expected" symbol)))
  1395. ;; Special case for edebug-`.
  1396. (if (and (listp sexp) (eq (car sexp) '\,))
  1397. (edebug-match cursor '(("," def-form)))
  1398. (if (not (funcall symbol sexp))
  1399. (edebug-no-match cursor symbol "failed"))
  1400. (edebug-move-cursor cursor)
  1401. (list sexp))))
  1402. (t (error "%s is not a form-spec or function" symbol))
  1403. )))
  1404. (defun edebug-match-sexp (cursor)
  1405. (list (prog1 (edebug-top-element-required cursor "Expected sexp")
  1406. (edebug-move-cursor cursor))))
  1407. (defun edebug-match-form (cursor)
  1408. (list (edebug-form cursor)))
  1409. (defalias 'edebug-match-place 'edebug-match-form)
  1410. ;; Currently identical to edebug-match-form.
  1411. ;; This is for common lisp setf-style place arguments.
  1412. (defsubst edebug-match-body (cursor) (edebug-forms cursor))
  1413. (defun edebug-match-&optional (cursor specs)
  1414. ;; Keep matching until one spec fails.
  1415. (edebug-&optional-wrapper cursor specs 'edebug-&optional-wrapper))
  1416. (defun edebug-&optional-wrapper (cursor specs remainder-handler)
  1417. (let (result
  1418. (edebug-&optional specs)
  1419. (edebug-gate nil)
  1420. (this-form (edebug-cursor-expressions cursor))
  1421. (this-offset (edebug-cursor-offsets cursor)))
  1422. (if (null (catch 'no-match
  1423. (setq result
  1424. (edebug-match-specs cursor specs remainder-handler))
  1425. ;; Returning nil means no no-match was thrown.
  1426. nil))
  1427. result
  1428. ;; no-match, but don't fail; just reset cursor and return nil.
  1429. (edebug-set-cursor cursor this-form this-offset)
  1430. nil)))
  1431. (defun edebug-&rest-wrapper (cursor specs remainder-handler)
  1432. (if (null specs) (setq specs edebug-&rest))
  1433. ;; Reuse the &optional handler with this as the remainder handler.
  1434. (edebug-&optional-wrapper cursor specs remainder-handler))
  1435. (defun edebug-match-&rest (cursor specs)
  1436. ;; Repeatedly use specs until failure.
  1437. (let ((edebug-&rest specs) ;; remember these
  1438. edebug-best-error
  1439. edebug-error-point)
  1440. (edebug-&rest-wrapper cursor specs 'edebug-&rest-wrapper)))
  1441. (defun edebug-match-&or (cursor specs)
  1442. ;; Keep matching until one spec succeeds, and return its results.
  1443. ;; If none match, fail.
  1444. ;; This needs to be optimized since most specs spend time here.
  1445. (let ((original-specs specs)
  1446. (this-form (edebug-cursor-expressions cursor))
  1447. (this-offset (edebug-cursor-offsets cursor)))
  1448. (catch 'matched
  1449. (while specs
  1450. (catch 'no-match
  1451. (throw 'matched
  1452. (let (edebug-gate ;; only while matching each spec
  1453. edebug-best-error
  1454. edebug-error-point)
  1455. ;; Doesn't support e.g. &or symbolp &rest form
  1456. (edebug-match-one-spec cursor (car specs)))))
  1457. ;; Match failed, so reset and try again.
  1458. (setq specs (cdr specs))
  1459. ;; Reset the cursor for the next match.
  1460. (edebug-set-cursor cursor this-form this-offset))
  1461. ;; All failed.
  1462. (apply 'edebug-no-match cursor "Expected one of" original-specs))
  1463. ))
  1464. (defun edebug-match-&not (cursor specs)
  1465. ;; If any specs match, then fail
  1466. (if (null (catch 'no-match
  1467. (let ((edebug-gate nil))
  1468. (save-excursion
  1469. (edebug-match-&or cursor specs)))
  1470. nil))
  1471. ;; This means something matched, so it is a no match.
  1472. (edebug-no-match cursor "Unexpected"))
  1473. ;; This means nothing matched, so it is OK.
  1474. nil) ;; So, return nothing
  1475. (def-edebug-spec &key edebug-match-&key)
  1476. (defun edebug-match-&key (cursor specs)
  1477. ;; Following specs must look like (<name> <spec>) ...
  1478. ;; where <name> is the name of a keyword, and spec is its spec.
  1479. ;; This really doesn't save much over the expanded form and takes time.
  1480. (edebug-match-&rest
  1481. cursor
  1482. (cons '&or
  1483. (mapcar (function (lambda (pair)
  1484. (vector (format ":%s" (car pair))
  1485. (car (cdr pair)))))
  1486. specs))))
  1487. (defun edebug-match-gate (cursor)
  1488. ;; Simply set the gate to prevent backtracking at this level.
  1489. (setq edebug-gate t)
  1490. nil)
  1491. (defun edebug-match-list (cursor specs)
  1492. ;; The spec is a list, but what kind of list, and what context?
  1493. (if edebug-dotted-spec
  1494. ;; After dotted spec but form did not contain dot,
  1495. ;; so match list spec elements as if spliced in.
  1496. (prog1
  1497. (let ((edebug-dotted-spec))
  1498. (edebug-match-specs cursor specs 'edebug-match-specs))
  1499. ;; If it matched, really clear the dotted-spec flag.
  1500. (setq edebug-dotted-spec nil))
  1501. (let ((spec (car specs))
  1502. (form (edebug-top-element-required cursor "Expected" specs)))
  1503. (cond
  1504. ((eq 'quote spec)
  1505. (let ((spec (car (cdr specs))))
  1506. (cond
  1507. ((symbolp spec)
  1508. ;; Special case: spec quotes a symbol to match.
  1509. ;; Change in future. Use "..." instead.
  1510. (if (not (eq spec form))
  1511. (edebug-no-match cursor "Expected" spec))
  1512. (edebug-move-cursor cursor)
  1513. (setq edebug-gate t)
  1514. form)
  1515. (t
  1516. (error "Bad spec: %s" specs)))))
  1517. ((listp form)
  1518. (prog1
  1519. (list (edebug-match-sublist
  1520. ;; First offset is for the list form itself.
  1521. ;; Treat nil as empty list.
  1522. (edebug-new-cursor form (cdr (edebug-top-offset cursor)))
  1523. specs))
  1524. (edebug-move-cursor cursor)))
  1525. ((and (eq 'vector spec) (vectorp form))
  1526. ;; Special case: match a vector with the specs.
  1527. (let ((result (edebug-match-sublist
  1528. (edebug-new-cursor
  1529. form (cdr (edebug-top-offset cursor)))
  1530. (cdr specs))))
  1531. (edebug-move-cursor cursor)
  1532. (list (apply 'vector result))))
  1533. (t (edebug-no-match cursor "Expected" specs)))
  1534. )))
  1535. (defun edebug-match-sublist (cursor specs)
  1536. ;; Match a sublist of specs.
  1537. (let (edebug-&optional
  1538. ;;edebug-best-error
  1539. ;;edebug-error-point
  1540. )
  1541. (prog1
  1542. ;; match with edebug-match-specs so edebug-best-error is not bound.
  1543. (edebug-match-specs cursor specs 'edebug-match-specs)
  1544. (if (not (edebug-empty-cursor cursor))
  1545. (if edebug-best-error
  1546. (apply 'edebug-no-match cursor edebug-best-error)
  1547. ;; A failed &rest or &optional spec may leave some args.
  1548. (edebug-no-match cursor "Failed matching" specs)
  1549. )))))
  1550. (defun edebug-match-string (cursor spec)
  1551. (let ((sexp (edebug-top-element-required cursor "Expected" spec)))
  1552. (if (not (eq (intern spec) sexp))
  1553. (edebug-no-match cursor "Expected" spec)
  1554. ;; Since it matched, failure means immediate error, unless &optional.
  1555. (setq edebug-gate t)
  1556. (edebug-move-cursor cursor)
  1557. (list sexp)
  1558. )))
  1559. (defun edebug-match-nil (cursor)
  1560. ;; There must be nothing left to match a nil.
  1561. (if (not (edebug-empty-cursor cursor))
  1562. (edebug-no-match cursor "Unmatched argument(s)")
  1563. nil))
  1564. (defun edebug-match-function (cursor)
  1565. (error "Use function-form instead of function in edebug spec"))
  1566. (defun edebug-match-&define (cursor specs)
  1567. ;; Match a defining form.
  1568. ;; Normally, &define is interpreted specially other places.
  1569. ;; This should only be called inside of a spec list to match the remainder
  1570. ;; of the current list. e.g. ("lambda" &define args def-body)
  1571. (edebug-make-form-wrapper
  1572. cursor
  1573. (edebug-before-offset cursor)
  1574. ;; Find the last offset in the list.
  1575. (let ((offsets (edebug-cursor-offsets cursor)))
  1576. (while (consp offsets) (setq offsets (cdr offsets)))
  1577. offsets)
  1578. specs))
  1579. (defun edebug-match-lambda-expr (cursor)
  1580. ;; The expression must be a function.
  1581. ;; This will match any list form that begins with a symbol
  1582. ;; that has an edebug-form-spec beginning with &define. In
  1583. ;; practice, only lambda expressions should be used.
  1584. ;; I could add a &lambda specification to avoid confusion.
  1585. (let* ((sexp (edebug-top-element-required
  1586. cursor "Expected lambda expression"))
  1587. (offset (edebug-top-offset cursor))
  1588. (head (and (consp sexp) (car sexp)))
  1589. (spec (and (symbolp head) (get-edebug-spec head)))
  1590. (edebug-inside-func nil))
  1591. ;; Find out if this is a defining form from first symbol.
  1592. (if (and (consp spec) (eq '&define (car spec)))
  1593. (prog1
  1594. (list
  1595. (edebug-defining-form
  1596. (edebug-new-cursor sexp offset)
  1597. (car offset);; before the sexp
  1598. (edebug-after-offset cursor)
  1599. (cons (symbol-name head) (cdr spec))))
  1600. (edebug-move-cursor cursor))
  1601. (edebug-no-match cursor "Expected lambda expression")
  1602. )))
  1603. (defun edebug-match-name (cursor)
  1604. ;; Set the edebug-def-name bound in edebug-defining-form.
  1605. (let ((name (edebug-top-element-required cursor "Expected name")))
  1606. ;; Maybe strings and numbers could be used.
  1607. (if (not (symbolp name))
  1608. (edebug-no-match cursor "Symbol expected for name of definition"))
  1609. (setq edebug-def-name
  1610. (if edebug-def-name
  1611. ;; Construct a new name by appending to previous name.
  1612. (intern (format "%s@%s" edebug-def-name name))
  1613. name))
  1614. (edebug-move-cursor cursor)
  1615. (list name)))
  1616. (defun edebug-match-colon-name (cursor spec)
  1617. ;; Set the edebug-def-name to the spec.
  1618. (setq edebug-def-name
  1619. (if edebug-def-name
  1620. ;; Construct a new name by appending to previous name.
  1621. (intern (format "%s@%s" edebug-def-name spec))
  1622. spec))
  1623. nil)
  1624. (defun edebug-match-arg (cursor)
  1625. ;; set the def-args bound in edebug-defining-form
  1626. (let ((edebug-arg (edebug-top-element-required cursor "Expected arg")))
  1627. (if (or (not (symbolp edebug-arg))
  1628. (edebug-lambda-list-keywordp edebug-arg))
  1629. (edebug-no-match cursor "Bad argument:" edebug-arg))
  1630. (edebug-move-cursor cursor)
  1631. (setq edebug-def-args (cons edebug-arg edebug-def-args))
  1632. (list edebug-arg)))
  1633. (defun edebug-match-def-form (cursor)
  1634. ;; Like form but the form is wrapped in edebug-enter form.
  1635. ;; The form is assumed to be executing outside of the function context.
  1636. ;; This is a hack for now, since a def-form might execute inside as well.
  1637. ;; Not to be used otherwise.
  1638. (let ((edebug-inside-func nil))
  1639. (list (edebug-make-enter-wrapper (list (edebug-form cursor))))))
  1640. (defun edebug-match-def-body (cursor)
  1641. ;; Like body but body is wrapped in edebug-enter form.
  1642. ;; The body is assumed to be executing inside of the function context.
  1643. ;; Not to be used otherwise.
  1644. (let ((edebug-inside-func t))
  1645. (list (edebug-wrap-def-body (edebug-forms cursor)))))
  1646. ;;;; Edebug Form Specs
  1647. ;;; ==========================================================
  1648. ;;; See cl-specs.el for common lisp specs.
  1649. ;;;;* Spec for def-edebug-spec
  1650. ;;; Out of date.
  1651. (defun edebug-spec-p (object)
  1652. "Return non-nil if OBJECT is a symbol with an edebug-form-spec property."
  1653. (and (symbolp object)
  1654. (get object 'edebug-form-spec)))
  1655. (def-edebug-spec def-edebug-spec
  1656. ;; Top level is different from lower levels.
  1657. (&define :name edebug-spec name
  1658. &or "nil" edebug-spec-p "t" "0" (&rest edebug-spec)))
  1659. (def-edebug-spec edebug-spec-list
  1660. ;; A list must have something in it, or it is nil, a symbolp
  1661. ((edebug-spec . [&or nil edebug-spec])))
  1662. (def-edebug-spec edebug-spec
  1663. (&or
  1664. (vector &rest edebug-spec) ; matches a vector
  1665. ("vector" &rest edebug-spec) ; matches a vector spec
  1666. ("quote" symbolp)
  1667. edebug-spec-list
  1668. stringp
  1669. [edebug-lambda-list-keywordp &rest edebug-spec]
  1670. [keywordp gate edebug-spec]
  1671. edebug-spec-p ;; Including all the special ones e.g. form.
  1672. symbolp;; a predicate
  1673. ))
  1674. ;;;* Emacs special forms and some functions.
  1675. ;; quote expects only one argument, although it allows any number.
  1676. (def-edebug-spec quote sexp)
  1677. ;; The standard defining forms.
  1678. (def-edebug-spec defconst defvar)
  1679. (def-edebug-spec defvar (symbolp &optional form stringp))
  1680. (def-edebug-spec defun
  1681. (&define name lambda-list
  1682. [&optional stringp]
  1683. [&optional ("interactive" interactive)]
  1684. def-body))
  1685. ;; FIXME? Isn't this missing the doc-string? Cf defun.
  1686. (def-edebug-spec defmacro
  1687. (&define name lambda-list [&optional ("declare" &rest sexp)] def-body))
  1688. (def-edebug-spec arglist lambda-list) ;; deprecated - use lambda-list.
  1689. (def-edebug-spec lambda-list
  1690. (([&rest arg]
  1691. [&optional ["&optional" arg &rest arg]]
  1692. &optional ["&rest" arg]
  1693. )))
  1694. (def-edebug-spec interactive
  1695. (&optional &or stringp def-form))
  1696. ;; A function-form is for an argument that may be a function or a form.
  1697. ;; This specially recognizes anonymous functions quoted with quote.
  1698. (def-edebug-spec function-form
  1699. ;; form at the end could also handle "function",
  1700. ;; but recognize it specially to avoid wrapping function forms.
  1701. (&or ([&or "quote" "function"] &or symbolp lambda-expr) form))
  1702. ;; function expects a symbol or a lambda or macro expression
  1703. ;; A macro is allowed by Emacs.
  1704. (def-edebug-spec function (&or symbolp lambda-expr))
  1705. ;; lambda is a macro in emacs 19.
  1706. (def-edebug-spec lambda (&define lambda-list
  1707. [&optional stringp]
  1708. [&optional ("interactive" interactive)]
  1709. def-body))
  1710. ;; A macro expression is a lambda expression with "macro" prepended.
  1711. (def-edebug-spec macro (&define "lambda" lambda-list def-body))
  1712. ;; (def-edebug-spec anonymous-form ((&or ["lambda" lambda] ["macro" macro])))
  1713. ;; Standard functions that take function-forms arguments.
  1714. (def-edebug-spec mapcar (function-form form))
  1715. (def-edebug-spec mapconcat (function-form form form))
  1716. (def-edebug-spec mapatoms (function-form &optional form))
  1717. (def-edebug-spec apply (function-form &rest form))
  1718. (def-edebug-spec funcall (function-form &rest form))
  1719. ;; FIXME? The manual uses this form (maybe that's just for illustration?):
  1720. ;; (def-edebug-spec let
  1721. ;; ((&rest &or symbolp (gate symbolp &optional form))
  1722. ;; body))
  1723. (def-edebug-spec let
  1724. ((&rest &or (symbolp &optional form) symbolp)
  1725. body))
  1726. (def-edebug-spec let* let)
  1727. (def-edebug-spec setq (&rest symbolp form))
  1728. (def-edebug-spec setq-default setq)
  1729. (def-edebug-spec cond (&rest (&rest form)))
  1730. (def-edebug-spec condition-case
  1731. (symbolp
  1732. form
  1733. &rest ([&or symbolp (&rest symbolp)] body)))
  1734. (def-edebug-spec \` (backquote-form))
  1735. ;; Supports quotes inside backquotes,
  1736. ;; but only at the top level inside unquotes.
  1737. (def-edebug-spec backquote-form
  1738. (&or
  1739. ([&or "," ",@"] &or ("quote" backquote-form) form)
  1740. ;; The simple version:
  1741. ;; (backquote-form &rest backquote-form)
  1742. ;; doesn't handle (a . ,b). The straightforward fix:
  1743. ;; (backquote-form . [&or nil backquote-form])
  1744. ;; uses up too much stack space.
  1745. ;; Note that `(foo . ,@bar) is not valid, so we don't need to handle it.
  1746. (backquote-form [&rest [&not ","] backquote-form]
  1747. . [&or nil backquote-form])
  1748. ;; If you use dotted forms in backquotes, replace the previous line
  1749. ;; with the following. This takes quite a bit more stack space, however.
  1750. ;; (backquote-form . [&or nil backquote-form])
  1751. (vector &rest backquote-form)
  1752. sexp))
  1753. ;; Special version of backquote that instruments backquoted forms
  1754. ;; destined to be evaluated, usually as the result of a
  1755. ;; macroexpansion. Backquoted code can only have unquotes (, and ,@)
  1756. ;; in places where list forms are allowed, and predicates. If the
  1757. ;; backquote is used in a macro, unquoted code that come from
  1758. ;; arguments must be instrumented, if at all, with def-form not def-body.
  1759. ;; We could assume that all forms (not nested in other forms)
  1760. ;; in arguments of macros should be def-forms, whether or not the macros
  1761. ;; are defined with edebug-` but this would be expensive.
  1762. ;; ,@ might have some problems.
  1763. (defalias 'edebug-\` '\`) ;; same macro as regular backquote.
  1764. (def-edebug-spec edebug-\` (def-form))
  1765. ;; Assume immediate quote in unquotes mean backquote at next higher level.
  1766. (def-edebug-spec \, (&or ("quote" edebug-\`) def-form))
  1767. (def-edebug-spec \,@ (&define ;; so (,@ form) is never wrapped.
  1768. &or ("quote" edebug-\`) def-form))
  1769. ;; New byte compiler.
  1770. (def-edebug-spec defsubst defun)
  1771. (def-edebug-spec dont-compile t)
  1772. (def-edebug-spec eval-when-compile t)
  1773. (def-edebug-spec eval-and-compile t)
  1774. (def-edebug-spec save-selected-window t)
  1775. (def-edebug-spec save-current-buffer t)
  1776. (def-edebug-spec delay-mode-hooks t)
  1777. (def-edebug-spec with-temp-file t)
  1778. (def-edebug-spec with-temp-message t)
  1779. (def-edebug-spec with-syntax-table t)
  1780. (def-edebug-spec push (form sexp))
  1781. (def-edebug-spec pop (sexp))
  1782. (def-edebug-spec 1value (form))
  1783. (def-edebug-spec noreturn (form))
  1784. ;; Anything else?
  1785. ;; Some miscellaneous specs for macros in public packages.
  1786. ;; Send me yours.
  1787. ;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu)
  1788. (def-edebug-spec ad-dolist ((symbolp form &optional form) body))
  1789. (def-edebug-spec defadvice
  1790. (&define name ;; thing being advised.
  1791. (name ;; class is [&or "before" "around" "after"
  1792. ;; "activation" "deactivation"]
  1793. name ;; name of advice
  1794. &rest sexp ;; optional position and flags
  1795. )
  1796. [&optional stringp]
  1797. [&optional ("interactive" interactive)]
  1798. def-body))
  1799. (def-edebug-spec easy-menu-define (symbolp body))
  1800. (def-edebug-spec with-custom-print body)
  1801. ;;; The debugger itself
  1802. (defvar edebug-active nil) ;; Non-nil when edebug is active
  1803. ;;; add minor-mode-alist entry
  1804. (or (assq 'edebug-active minor-mode-alist)
  1805. (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*")
  1806. minor-mode-alist)))
  1807. (defvar edebug-stack nil)
  1808. ;; Stack of active functions evaluated via edebug.
  1809. ;; Should be nil at the top level.
  1810. (defvar edebug-stack-depth -1)
  1811. ;; Index of last edebug-stack item.
  1812. (defvar edebug-offset-indices nil)
  1813. ;; Stack of offset indices of visited edebug sexps.
  1814. ;; Should be nil at the top level.
  1815. ;; Each function adds one cons. Top is modified with setcar.
  1816. (defvar edebug-entered nil
  1817. ;; Non-nil if edebug has already been entered at this recursive edit level.
  1818. ;; This should stay nil at the top level.
  1819. )
  1820. ;; Should these be options?
  1821. (defconst edebug-debugger 'edebug
  1822. ;; Name of function to use for debugging when error or quit occurs.
  1823. ;; Set this to 'debug if you want to debug edebug.
  1824. )
  1825. ;; Dynamically bound variables, declared globally but left unbound.
  1826. (defvar edebug-function) ; the function being executed. change name!!
  1827. (defvar edebug-args) ; the arguments of the function
  1828. (defvar edebug-data) ; the edebug data for the function
  1829. (defvar edebug-value) ; the result of the expression
  1830. (defvar edebug-after-index)
  1831. (defvar edebug-def-mark) ; the mark for the definition
  1832. (defvar edebug-freq-count) ; the count of expression visits.
  1833. (defvar edebug-coverage) ; the coverage results of each expression of function.
  1834. (defvar edebug-buffer) ; which buffer the function is in.
  1835. (defvar edebug-result) ; the result of the function call returned by body
  1836. (defvar edebug-outside-executing-macro)
  1837. (defvar edebug-outside-defining-kbd-macro)
  1838. (defvar edebug-execution-mode 'step) ; Current edebug mode set by user.
  1839. (defvar edebug-next-execution-mode nil) ; Use once instead of initial mode.
  1840. (defvar edebug-outside-debug-on-error) ; the value of debug-on-error outside
  1841. (defvar edebug-outside-debug-on-quit) ; the value of debug-on-quit outside
  1842. (defvar edebug-outside-overriding-local-map)
  1843. (defvar edebug-outside-overriding-terminal-local-map)
  1844. (defvar edebug-outside-pre-command-hook)
  1845. (defvar edebug-outside-post-command-hook)
  1846. (defvar cl-lexical-debug) ;; Defined in cl.el
  1847. ;;; Handling signals
  1848. (defun edebug-signal (edebug-signal-name edebug-signal-data)
  1849. "Signal an error. Args are SIGNAL-NAME, and associated DATA.
  1850. A signal name is a symbol with an `error-conditions' property
  1851. that is a list of condition names.
  1852. A handler for any of those names will get to handle this signal.
  1853. The symbol `error' should always be one of them.
  1854. DATA should be a list. Its elements are printed as part of the error message.
  1855. If the signal is handled, DATA is made available to the handler.
  1856. See `condition-case'.
  1857. This is the Edebug replacement for the standard `signal'. It should
  1858. only be active while Edebug is. It checks `debug-on-error' to see
  1859. whether it should call the debugger. When execution is resumed, the
  1860. error is signaled again.
  1861. \n(fn SIGNAL-NAME DATA)"
  1862. (if (and (listp debug-on-error) (memq edebug-signal-name debug-on-error))
  1863. (edebug 'error (cons edebug-signal-name edebug-signal-data)))
  1864. ;; If we reach here without another non-local exit, then send signal again.
  1865. ;; i.e. the signal is not continuable, yet.
  1866. ;; Avoid infinite recursion.
  1867. (let ((signal-hook-function nil))
  1868. (signal edebug-signal-name edebug-signal-data)))
  1869. ;;; Entering Edebug
  1870. (defun edebug-enter (edebug-function edebug-args edebug-body)
  1871. ;; Entering FUNC. The arguments are ARGS, and the body is BODY.
  1872. ;; Setup edebug variables and evaluate BODY. This function is called
  1873. ;; when a function evaluated with edebug-eval-top-level-form is entered.
  1874. ;; Return the result of BODY.
  1875. ;; Is this the first time we are entering edebug since
  1876. ;; lower-level recursive-edit command?
  1877. ;; More precisely, this tests whether Edebug is currently active.
  1878. (if (not edebug-entered)
  1879. (let ((edebug-entered t)
  1880. ;; Binding max-lisp-eval-depth here is OK,
  1881. ;; but not inside an unwind-protect.
  1882. ;; Doing it here also keeps it from growing too large.
  1883. (max-lisp-eval-depth (+ 100 max-lisp-eval-depth)) ; too much??
  1884. (max-specpdl-size (+ 200 max-specpdl-size))
  1885. (debugger edebug-debugger) ; only while edebug is active.
  1886. (edebug-outside-debug-on-error debug-on-error)
  1887. (edebug-outside-debug-on-quit debug-on-quit)
  1888. ;; Binding these may not be the right thing to do.
  1889. ;; We want to allow the global values to be changed.
  1890. (debug-on-error (or debug-on-error edebug-on-error))
  1891. (debug-on-quit edebug-on-quit)
  1892. ;; Lexical bindings must be uncompiled for this to work.
  1893. (cl-lexical-debug t)
  1894. (edebug-outside-overriding-local-map overriding-local-map)
  1895. (edebug-outside-overriding-terminal-local-map
  1896. overriding-terminal-local-map)
  1897. ;; Save the outside value of executing macro. (here??)
  1898. (edebug-outside-executing-macro executing-kbd-macro)
  1899. (edebug-outside-pre-command-hook
  1900. (edebug-var-status 'pre-command-hook))
  1901. (edebug-outside-post-command-hook
  1902. (edebug-var-status 'post-command-hook)))
  1903. (unwind-protect
  1904. (let (;; Don't keep reading from an executing kbd macro
  1905. ;; within edebug unless edebug-continue-kbd-macro is
  1906. ;; non-nil. Again, local binding may not be best.
  1907. (executing-kbd-macro
  1908. (if edebug-continue-kbd-macro executing-kbd-macro))
  1909. ;; Don't get confused by the user's keymap changes.
  1910. (overriding-local-map nil)
  1911. (overriding-terminal-local-map nil)
  1912. (signal-hook-function 'edebug-signal)
  1913. ;; Disable command hooks. This is essential when
  1914. ;; a hook function is instrumented - to avoid infinite loop.
  1915. ;; This may be more than we need, however.
  1916. (pre-command-hook nil)
  1917. (post-command-hook nil))
  1918. (setq edebug-execution-mode (or edebug-next-execution-mode
  1919. edebug-initial-mode
  1920. edebug-execution-mode)
  1921. edebug-next-execution-mode nil)
  1922. (edebug-enter edebug-function edebug-args edebug-body))
  1923. ;; Reset global variables in case outside value was changed.
  1924. (setq executing-kbd-macro edebug-outside-executing-macro)
  1925. (edebug-restore-status
  1926. 'post-command-hook edebug-outside-post-command-hook)
  1927. (edebug-restore-status
  1928. 'pre-command-hook edebug-outside-pre-command-hook)))
  1929. (let* ((edebug-data (get edebug-function 'edebug))
  1930. (edebug-def-mark (car edebug-data)) ; mark at def start
  1931. (edebug-freq-count (get edebug-function 'edebug-freq-count))
  1932. (edebug-coverage (get edebug-function 'edebug-coverage))
  1933. (edebug-buffer (marker-buffer edebug-def-mark))
  1934. (edebug-stack (cons edebug-function edebug-stack))
  1935. (edebug-offset-indices (cons 0 edebug-offset-indices))
  1936. )
  1937. (if (get edebug-function 'edebug-on-entry)
  1938. (progn
  1939. (setq edebug-execution-mode 'step)
  1940. (if (eq (get edebug-function 'edebug-on-entry) 'temp)
  1941. (put edebug-function 'edebug-on-entry nil))))
  1942. (if edebug-trace
  1943. (edebug-enter-trace edebug-body)
  1944. (funcall edebug-body))
  1945. )))
  1946. (defun edebug-var-status (var)
  1947. "Return a cons cell describing the status of VAR's current binding.
  1948. The purpose of this function is so you can properly undo
  1949. subsequent changes to the same binding, by passing the status
  1950. cons cell to `edebug-restore-status'. The status cons cell
  1951. has the form (LOCUS . VALUE), where LOCUS can be a buffer
  1952. \(for a buffer-local binding), a frame (for a frame-local binding),
  1953. or nil (if the default binding is current)."
  1954. (cons (variable-binding-locus var)
  1955. (symbol-value var)))
  1956. (defun edebug-restore-status (var status)
  1957. "Reset VAR based on STATUS.
  1958. STATUS should be a list returned by `edebug-var-status'."
  1959. (let ((locus (car status))
  1960. (value (cdr status)))
  1961. (cond ((bufferp locus)
  1962. (if (buffer-live-p locus)
  1963. (with-current-buffer locus
  1964. (set var value))))
  1965. ((framep locus)
  1966. (modify-frame-parameters locus (list (cons var value))))
  1967. (t
  1968. (set var value)))))
  1969. (defun edebug-enter-trace (edebug-body)
  1970. (let ((edebug-stack-depth (1+ edebug-stack-depth))
  1971. edebug-result)
  1972. (edebug-print-trace-before
  1973. (format "%s args: %s" edebug-function edebug-args))
  1974. (prog1 (setq edebug-result (funcall edebug-body))
  1975. (edebug-print-trace-after
  1976. (format "%s result: %s" edebug-function edebug-result)))))
  1977. (def-edebug-spec edebug-tracing (form body))
  1978. (defmacro edebug-tracing (msg &rest body)
  1979. "Print MSG in *edebug-trace* before and after evaluating BODY.
  1980. The result of BODY is also printed."
  1981. `(let ((edebug-stack-depth (1+ edebug-stack-depth))
  1982. edebug-result)
  1983. (edebug-print-trace-before ,msg)
  1984. (prog1 (setq edebug-result (progn ,@body))
  1985. (edebug-print-trace-after
  1986. (format "%s result: %s" ,msg edebug-result)))))
  1987. (defun edebug-print-trace-before (msg)
  1988. "Function called to print trace info before expression evaluation.
  1989. MSG is printed after `::::{ '."
  1990. (edebug-trace-display
  1991. edebug-trace-buffer "%s{ %s" (make-string edebug-stack-depth ?\:) msg))
  1992. (defun edebug-print-trace-after (msg)
  1993. "Function called to print trace info after expression evaluation.
  1994. MSG is printed after `::::} '."
  1995. (edebug-trace-display
  1996. edebug-trace-buffer "%s} %s" (make-string edebug-stack-depth ?\:) msg))
  1997. (defun edebug-slow-before (edebug-before-index)
  1998. (unless edebug-active
  1999. ;; Debug current function given BEFORE position.
  2000. ;; Called from functions compiled with edebug-eval-top-level-form.
  2001. ;; Return the before index.
  2002. (setcar edebug-offset-indices edebug-before-index)
  2003. ;; Increment frequency count
  2004. (aset edebug-freq-count edebug-before-index
  2005. (1+ (aref edebug-freq-count edebug-before-index)))
  2006. (if (or (not (memq edebug-execution-mode '(Go-nonstop next)))
  2007. (edebug-input-pending-p))
  2008. (edebug-debugger edebug-before-index 'before nil)))
  2009. edebug-before-index)
  2010. (defun edebug-fast-before (edebug-before-index)
  2011. ;; Do nothing.
  2012. )
  2013. (defun edebug-slow-after (edebug-before-index edebug-after-index edebug-value)
  2014. (if edebug-active
  2015. edebug-value
  2016. ;; Debug current function given AFTER position and VALUE.
  2017. ;; Called from functions compiled with edebug-eval-top-level-form.
  2018. ;; Return VALUE.
  2019. (setcar edebug-offset-indices edebug-after-index)
  2020. ;; Increment frequency count
  2021. (aset edebug-freq-count edebug-after-index
  2022. (1+ (aref edebug-freq-count edebug-after-index)))
  2023. (if edebug-test-coverage (edebug-update-coverage))
  2024. (if (and (eq edebug-execution-mode 'Go-nonstop)
  2025. (not (edebug-input-pending-p)))
  2026. ;; Just return result.
  2027. edebug-value
  2028. (edebug-debugger edebug-after-index 'after edebug-value)
  2029. )))
  2030. (defun edebug-fast-after (edebug-before-index edebug-after-index edebug-value)
  2031. ;; Do nothing but return the value.
  2032. edebug-value)
  2033. (defun edebug-run-slow ()
  2034. (defalias 'edebug-before 'edebug-slow-before)
  2035. (defalias 'edebug-after 'edebug-slow-after))
  2036. ;; This is not used, yet.
  2037. (defun edebug-run-fast ()
  2038. (defalias 'edebug-before 'edebug-fast-before)
  2039. (defalias 'edebug-after 'edebug-fast-after))
  2040. (edebug-run-slow)
  2041. (defun edebug-update-coverage ()
  2042. (let ((old-result (aref edebug-coverage edebug-after-index)))
  2043. (cond
  2044. ((eq 'ok-coverage old-result))
  2045. ((eq 'unknown old-result)
  2046. (aset edebug-coverage edebug-after-index edebug-value))
  2047. ;; Test if a different result.
  2048. ((not (eq edebug-value old-result))
  2049. (aset edebug-coverage edebug-after-index 'ok-coverage)))))
  2050. ;; Dynamically declared unbound variables.
  2051. (defvar edebug-arg-mode) ; the mode, either before, after, or error
  2052. (defvar edebug-breakpoints)
  2053. (defvar edebug-break-data) ; break data for current function.
  2054. (defvar edebug-break) ; whether a break occurred.
  2055. (defvar edebug-global-break) ; whether a global break occurred.
  2056. (defvar edebug-break-condition) ; whether the breakpoint is conditional.
  2057. (defvar edebug-break-result nil)
  2058. (defvar edebug-global-break-result nil)
  2059. (defun edebug-debugger (edebug-offset-index edebug-arg-mode edebug-value)
  2060. (if inhibit-redisplay
  2061. ;; Don't really try to enter edebug within an eval from redisplay.
  2062. edebug-value
  2063. ;; Check breakpoints and pending input.
  2064. ;; If edebug display should be updated, call edebug-display.
  2065. ;; Return edebug-value.
  2066. (let* ( ;; This needs to be here since breakpoints may be changed.
  2067. (edebug-breakpoints (car (cdr edebug-data))) ; list of breakpoints
  2068. (edebug-break-data (assq edebug-offset-index edebug-breakpoints))
  2069. (edebug-break-condition (car (cdr edebug-break-data)))
  2070. (edebug-global-break
  2071. (if edebug-global-break-condition
  2072. (condition-case nil
  2073. (setq edebug-global-break-result
  2074. ;; FIXME: lexbind.
  2075. (eval edebug-global-break-condition))
  2076. (error nil))))
  2077. (edebug-break))
  2078. ;;; (edebug-trace "exp: %s" edebug-value)
  2079. ;; Test whether we should break.
  2080. (setq edebug-break
  2081. (or edebug-global-break
  2082. (and edebug-break-data
  2083. (or (not edebug-break-condition)
  2084. (setq edebug-break-result
  2085. ;; FIXME: lexbind.
  2086. (eval edebug-break-condition))))))
  2087. (if (and edebug-break
  2088. (nth 2 edebug-break-data)) ; is it temporary?
  2089. ;; Delete the breakpoint.
  2090. (setcdr edebug-data
  2091. (cons (delq edebug-break-data edebug-breakpoints)
  2092. (cdr (cdr edebug-data)))))
  2093. ;; Display if mode is not go, continue, or Continue-fast
  2094. ;; or break, or input is pending,
  2095. (if (or (not (memq edebug-execution-mode '(go continue Continue-fast)))
  2096. edebug-break
  2097. (edebug-input-pending-p))
  2098. (edebug-display)) ; <--------------- display
  2099. edebug-value
  2100. )))
  2101. ;; window-start now stored with each function.
  2102. ;;(defvar edebug-window-start nil)
  2103. ;; Remember where each buffers' window starts between edebug calls.
  2104. ;; This is to avoid spurious recentering.
  2105. ;; Does this still need to be buffer-local??
  2106. ;;(setq-default edebug-window-start nil)
  2107. ;;(make-variable-buffer-local 'edebug-window-start)
  2108. ;; Dynamically declared unbound vars
  2109. (defvar edebug-point) ; the point in edebug buffer
  2110. (defvar edebug-outside-buffer) ; the current-buffer outside of edebug
  2111. (defvar edebug-outside-point) ; the point outside of edebug
  2112. (defvar edebug-outside-mark) ; the mark outside of edebug
  2113. (defvar edebug-window-data) ; window and window-start for current function
  2114. (defvar edebug-outside-windows) ; outside window configuration
  2115. (defvar edebug-eval-buffer) ; for the evaluation list.
  2116. (defvar edebug-outside-o-a-p) ; outside overlay-arrow-position
  2117. (defvar edebug-outside-o-a-s) ; outside overlay-arrow-string
  2118. (defvar edebug-outside-c-i-e-a) ; outside cursor-in-echo-area
  2119. (defvar edebug-outside-d-c-i-n-s-w) ; outside default-cursor-in-non-selected-windows
  2120. (defvar edebug-eval-list nil) ;; List of expressions to evaluate.
  2121. (defvar edebug-previous-result nil) ;; Last result returned.
  2122. ;; Emacs 19 adds an arg to mark and mark-marker.
  2123. (defalias 'edebug-mark-marker 'mark-marker)
  2124. (defun edebug-display ()
  2125. (unless (marker-position edebug-def-mark)
  2126. ;; The buffer holding the source has been killed.
  2127. ;; Let's at least show a backtrace so the user can figure out
  2128. ;; which function we're talking about.
  2129. (debug))
  2130. ;; Setup windows for edebug, determine mode, maybe enter recursive-edit.
  2131. ;; Uses local variables of edebug-enter, edebug-before, edebug-after
  2132. ;; and edebug-debugger.
  2133. (let ((edebug-active t) ; for minor mode alist
  2134. (edebug-with-timeout-suspend (with-timeout-suspend))
  2135. edebug-stop ; should we enter recursive-edit
  2136. (edebug-point (+ edebug-def-mark
  2137. (aref (nth 2 edebug-data) edebug-offset-index)))
  2138. edebug-buffer-outside-point ; current point in edebug-buffer
  2139. ;; window displaying edebug-buffer
  2140. (edebug-window-data (nth 3 edebug-data))
  2141. (edebug-outside-window (selected-window))
  2142. (edebug-outside-buffer (current-buffer))
  2143. (edebug-outside-point (point))
  2144. (edebug-outside-mark (edebug-mark))
  2145. (edebug-outside-unread-command-events unread-command-events)
  2146. edebug-outside-windows ; window or screen configuration
  2147. edebug-buffer-points
  2148. edebug-eval-buffer ; declared here so we can kill it below
  2149. (edebug-eval-result-list (and edebug-eval-list
  2150. (edebug-eval-result-list)))
  2151. edebug-trace-window
  2152. edebug-trace-window-start
  2153. (edebug-outside-o-a-p overlay-arrow-position)
  2154. (edebug-outside-o-a-s overlay-arrow-string)
  2155. (edebug-outside-c-i-e-a cursor-in-echo-area)
  2156. (edebug-outside-d-c-i-n-s-w
  2157. (default-value 'cursor-in-non-selected-windows)))
  2158. (unwind-protect
  2159. (let ((overlay-arrow-position overlay-arrow-position)
  2160. (overlay-arrow-string overlay-arrow-string)
  2161. (cursor-in-echo-area nil)
  2162. (unread-command-events unread-command-events)
  2163. ;; any others??
  2164. )
  2165. (setq-default cursor-in-non-selected-windows t)
  2166. (if (not (buffer-name edebug-buffer))
  2167. (let ((debug-on-error nil))
  2168. (error "Buffer defining %s not found" edebug-function)))
  2169. (if (eq 'after edebug-arg-mode)
  2170. ;; Compute result string now before windows are modified.
  2171. (edebug-compute-previous-result edebug-value))
  2172. (if edebug-save-windows
  2173. ;; Save windows now before we modify them.
  2174. (setq edebug-outside-windows
  2175. (edebug-current-windows edebug-save-windows)))
  2176. (if edebug-save-displayed-buffer-points
  2177. (setq edebug-buffer-points (edebug-get-displayed-buffer-points)))
  2178. ;; First move the edebug buffer point to edebug-point
  2179. ;; so that window start doesn't get changed when we display it.
  2180. ;; I don't know if this is going to help.
  2181. ;;(set-buffer edebug-buffer)
  2182. ;;(goto-char edebug-point)
  2183. ;; If edebug-buffer is not currently displayed,
  2184. ;; first find a window for it.
  2185. (edebug-pop-to-buffer edebug-buffer (car edebug-window-data))
  2186. (setcar edebug-window-data (selected-window))
  2187. ;; Now display eval list, if any.
  2188. ;; This is done after the pop to edebug-buffer
  2189. ;; so that buffer-window correspondence is correct after quitting.
  2190. (edebug-eval-display edebug-eval-result-list)
  2191. ;; The evaluation list better not have deleted edebug-window-data.
  2192. (select-window (car edebug-window-data))
  2193. (set-buffer edebug-buffer)
  2194. (setq edebug-buffer-outside-point (point))
  2195. (goto-char edebug-point)
  2196. (if (eq 'before edebug-arg-mode)
  2197. ;; Check whether positions are up-to-date.
  2198. ;; This assumes point is never before symbol.
  2199. (if (not (memq (following-char) '(?\( ?\# ?\` )))
  2200. (let ((debug-on-error nil))
  2201. (error "Source has changed - reevaluate definition of %s"
  2202. edebug-function)
  2203. )))
  2204. (setcdr edebug-window-data
  2205. (edebug-adjust-window (cdr edebug-window-data)))
  2206. ;; Test if there is input, not including keyboard macros.
  2207. (if (edebug-input-pending-p)
  2208. (progn
  2209. (setq edebug-execution-mode 'step
  2210. edebug-stop t)
  2211. (edebug-stop)
  2212. ;; (discard-input) ; is this unfriendly??
  2213. ))
  2214. ;; Now display arrow based on mode.
  2215. (edebug-overlay-arrow)
  2216. (cond
  2217. ((eq 'error edebug-arg-mode)
  2218. ;; Display error message
  2219. (setq edebug-execution-mode 'step)
  2220. (edebug-overlay-arrow)
  2221. (beep)
  2222. (if (eq 'quit (car edebug-value))
  2223. (message "Quit")
  2224. (edebug-report-error edebug-value)))
  2225. (edebug-break
  2226. (cond
  2227. (edebug-global-break
  2228. (message "Global Break: %s => %s"
  2229. edebug-global-break-condition
  2230. edebug-global-break-result))
  2231. (edebug-break-condition
  2232. (message "Break: %s => %s"
  2233. edebug-break-condition
  2234. edebug-break-result))
  2235. ((not (eq edebug-execution-mode 'Continue-fast))
  2236. (message "Break"))
  2237. (t)))
  2238. (t (message "")))
  2239. (setq unread-command-events nil)
  2240. (if (eq 'after edebug-arg-mode)
  2241. (progn
  2242. ;; Display result of previous evaluation.
  2243. (if (and edebug-break
  2244. (not (eq edebug-execution-mode 'Continue-fast)))
  2245. (edebug-sit-for edebug-sit-for-seconds)) ; Show message.
  2246. (edebug-previous-result)))
  2247. (cond
  2248. (edebug-break
  2249. (cond
  2250. ((eq edebug-execution-mode 'continue)
  2251. (edebug-sit-for edebug-sit-for-seconds))
  2252. ((eq edebug-execution-mode 'Continue-fast) (edebug-sit-for 0))
  2253. (t (setq edebug-stop t))))
  2254. ;; not edebug-break
  2255. ((eq edebug-execution-mode 'trace)
  2256. (edebug-sit-for edebug-sit-for-seconds)) ; Force update and pause.
  2257. ((eq edebug-execution-mode 'Trace-fast)
  2258. (edebug-sit-for 0))) ; Force update and continue.
  2259. (unwind-protect
  2260. (if (or edebug-stop
  2261. (memq edebug-execution-mode '(step next))
  2262. (eq edebug-arg-mode 'error))
  2263. (progn
  2264. ;; (setq edebug-execution-mode 'step)
  2265. ;; (edebug-overlay-arrow) ; This doesn't always show up.
  2266. (edebug-recursive-edit))) ; <---------- Recursive edit
  2267. ;; Reset the edebug-window-data to whatever it is now.
  2268. (let ((window (if (eq (window-buffer) edebug-buffer)
  2269. (selected-window)
  2270. (edebug-get-buffer-window edebug-buffer))))
  2271. ;; Remember window-start for edebug-buffer, if still displayed.
  2272. (if window
  2273. (progn
  2274. (setcar edebug-window-data window)
  2275. (setcdr edebug-window-data (window-start window)))))
  2276. ;; Save trace window point before restoring outside windows.
  2277. ;; Could generalize this for other buffers.
  2278. (setq edebug-trace-window (get-buffer-window edebug-trace-buffer))
  2279. (if edebug-trace-window
  2280. (setq edebug-trace-window-start
  2281. (and edebug-trace-window
  2282. (window-start edebug-trace-window))))
  2283. ;; Restore windows before continuing.
  2284. (if edebug-save-windows
  2285. (progn
  2286. (edebug-set-windows edebug-outside-windows)
  2287. ;; Restore displayed buffer points.
  2288. ;; Needed even if restoring windows because
  2289. ;; window-points are not restored. (should they be??)
  2290. (if edebug-save-displayed-buffer-points
  2291. (edebug-set-buffer-points edebug-buffer-points))
  2292. ;; Unrestore trace window's window-point.
  2293. (if edebug-trace-window
  2294. (set-window-start edebug-trace-window
  2295. edebug-trace-window-start))
  2296. ;; Unrestore edebug-buffer's window-start, if displayed.
  2297. (let ((window (car edebug-window-data)))
  2298. (if (and (edebug-window-live-p window)
  2299. (eq (window-buffer) edebug-buffer))
  2300. (progn
  2301. (set-window-start window (cdr edebug-window-data)
  2302. 'no-force)
  2303. ;; Unrestore edebug-buffer's window-point.
  2304. ;; Needed in addition to setting the buffer point
  2305. ;; - otherwise quitting doesn't leave point as is.
  2306. ;; But this causes point to not be restored at times.
  2307. ;; Also, it may not be a visible window.
  2308. ;; (set-window-point window edebug-point)
  2309. )))
  2310. ;; Unrestore edebug-buffer's point. Rerestored below.
  2311. ;; (goto-char edebug-point) ;; in edebug-buffer
  2312. )
  2313. ;; Since we may be in a save-excursion, in case of quit,
  2314. ;; reselect the outside window only.
  2315. ;; Only needed if we are not recovering windows??
  2316. (if (edebug-window-live-p edebug-outside-window)
  2317. (select-window edebug-outside-window))
  2318. ) ; if edebug-save-windows
  2319. ;; Restore current buffer always, in case application needs it.
  2320. (if (buffer-name edebug-outside-buffer)
  2321. (set-buffer edebug-outside-buffer))
  2322. ;; Restore point, and mark.
  2323. ;; Needed even if restoring windows because
  2324. ;; that doesn't restore point and mark in the current buffer.
  2325. ;; But don't restore point if edebug-buffer is current buffer.
  2326. (if (not (eq edebug-buffer edebug-outside-buffer))
  2327. (goto-char edebug-outside-point))
  2328. (if (marker-buffer (edebug-mark-marker))
  2329. ;; Does zmacs-regions need to be nil while doing set-marker?
  2330. (set-marker (edebug-mark-marker) edebug-outside-mark))
  2331. ) ; unwind-protect
  2332. ;; None of the following is done if quit or signal occurs.
  2333. ;; Restore edebug-buffer's outside point.
  2334. ;; (edebug-trace "restore edebug-buffer point: %s"
  2335. ;; edebug-buffer-outside-point)
  2336. (with-current-buffer edebug-buffer
  2337. (goto-char edebug-buffer-outside-point))
  2338. ;; ... nothing more.
  2339. )
  2340. (with-timeout-unsuspend edebug-with-timeout-suspend)
  2341. ;; Reset global variables to outside values in case they were changed.
  2342. (setq
  2343. unread-command-events edebug-outside-unread-command-events
  2344. overlay-arrow-position edebug-outside-o-a-p
  2345. overlay-arrow-string edebug-outside-o-a-s
  2346. cursor-in-echo-area edebug-outside-c-i-e-a)
  2347. (setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
  2348. )))
  2349. (defvar edebug-number-of-recursions 0)
  2350. ;; Number of recursive edits started by edebug.
  2351. ;; Should be 0 at the top level.
  2352. (defvar edebug-recursion-depth 0)
  2353. ;; Value of recursion-depth when edebug was called.
  2354. ;; Dynamically declared unbound vars
  2355. (defvar edebug-outside-match-data) ; match data outside of edebug
  2356. (defvar edebug-backtrace-buffer) ; each recursive edit gets its own
  2357. (defvar edebug-inside-windows)
  2358. (defvar edebug-interactive-p)
  2359. (defvar edebug-outside-map)
  2360. (defvar edebug-outside-standard-output)
  2361. (defvar edebug-outside-standard-input)
  2362. (defvar edebug-outside-current-prefix-arg)
  2363. (defvar edebug-outside-last-command)
  2364. (defvar edebug-outside-this-command)
  2365. ;; Note: here we have defvars for variables that are
  2366. ;; built-in in certain versions.
  2367. ;; Each defvar makes a difference
  2368. ;; in versions where the variable is *not* built-in.
  2369. ;; Emacs 18 FIXME
  2370. (defvar edebug-outside-unread-command-char)
  2371. ;; Emacs 19.
  2372. (defvar edebug-outside-last-command-event)
  2373. (defvar edebug-outside-unread-command-events)
  2374. (defvar edebug-outside-last-input-event)
  2375. (defvar edebug-outside-last-event-frame)
  2376. (defvar edebug-outside-last-nonmenu-event)
  2377. (defvar edebug-outside-track-mouse)
  2378. ;; Disable byte compiler warnings about unread-command-char and -event
  2379. ;; (maybe works with byte-compile-version 2.22 at least)
  2380. (defvar edebug-unread-command-char-warning)
  2381. (defvar edebug-unread-command-event-warning)
  2382. (eval-when-compile ; FIXME
  2383. (setq edebug-unread-command-char-warning
  2384. (get 'unread-command-char 'byte-obsolete-variable))
  2385. (put 'unread-command-char 'byte-obsolete-variable nil))
  2386. (defun edebug-recursive-edit ()
  2387. ;; Start up a recursive edit inside of edebug.
  2388. ;; The current buffer is the edebug-buffer, which is put into edebug-mode.
  2389. ;; Assume that none of the variables below are buffer-local.
  2390. (let ((edebug-buffer-read-only buffer-read-only)
  2391. ;; match-data must be done in the outside buffer
  2392. (edebug-outside-match-data
  2393. (with-current-buffer edebug-outside-buffer ; in case match buffer different
  2394. (match-data)))
  2395. ;;(edebug-number-of-recursions (1+ edebug-number-of-recursions))
  2396. (edebug-recursion-depth (recursion-depth))
  2397. edebug-entered ; bind locally to nil
  2398. (edebug-interactive-p nil) ; again non-interactive
  2399. edebug-backtrace-buffer ; each recursive edit gets its own
  2400. ;; The window configuration may be saved and restored
  2401. ;; during a recursive-edit
  2402. edebug-inside-windows
  2403. (edebug-outside-map (current-local-map))
  2404. (edebug-outside-standard-output standard-output)
  2405. (edebug-outside-standard-input standard-input)
  2406. (edebug-outside-defining-kbd-macro defining-kbd-macro)
  2407. (edebug-outside-last-command last-command)
  2408. (edebug-outside-this-command this-command)
  2409. (edebug-outside-unread-command-char unread-command-char) ; FIXME
  2410. (edebug-outside-current-prefix-arg current-prefix-arg)
  2411. (edebug-outside-last-input-event last-input-event)
  2412. (edebug-outside-last-command-event last-command-event)
  2413. (edebug-outside-last-event-frame last-event-frame)
  2414. (edebug-outside-last-nonmenu-event last-nonmenu-event)
  2415. (edebug-outside-track-mouse track-mouse)
  2416. )
  2417. (unwind-protect
  2418. (let (
  2419. ;; Declare global values local but using the same global value.
  2420. ;; We could set these to the values for previous edebug call.
  2421. (last-command last-command)
  2422. (this-command this-command)
  2423. ;; Assume no edebug command sets unread-command-char.
  2424. (unread-command-char -1)
  2425. (current-prefix-arg nil)
  2426. ;; More for Emacs 19
  2427. (last-input-event nil)
  2428. (last-command-event nil)
  2429. (last-event-frame nil)
  2430. (last-nonmenu-event nil)
  2431. (track-mouse nil)
  2432. ;; Bind again to outside values.
  2433. (debug-on-error edebug-outside-debug-on-error)
  2434. (debug-on-quit edebug-outside-debug-on-quit)
  2435. ;; Don't keep defining a kbd macro.
  2436. (defining-kbd-macro
  2437. (if edebug-continue-kbd-macro defining-kbd-macro))
  2438. ;; others??
  2439. )
  2440. (if (and (eq edebug-execution-mode 'go)
  2441. (not (memq edebug-arg-mode '(after error))))
  2442. (message "Break"))
  2443. (setq buffer-read-only t)
  2444. (setq signal-hook-function nil)
  2445. (edebug-mode)
  2446. (unwind-protect
  2447. (recursive-edit) ; <<<<<<<<<< Recursive edit
  2448. ;; Do the following, even if quit occurs.
  2449. (setq signal-hook-function 'edebug-signal)
  2450. (if edebug-backtrace-buffer
  2451. (kill-buffer edebug-backtrace-buffer))
  2452. ;; Could be an option to keep eval display up.
  2453. (if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
  2454. ;; Remember selected-window after recursive-edit.
  2455. ;; (setq edebug-inside-window (selected-window))
  2456. (set-match-data edebug-outside-match-data)
  2457. ;; Recursive edit may have changed buffers,
  2458. ;; so set it back before exiting let.
  2459. (if (buffer-name edebug-buffer) ; if it still exists
  2460. (progn
  2461. (set-buffer edebug-buffer)
  2462. (if (memq edebug-execution-mode '(go Go-nonstop))
  2463. (edebug-overlay-arrow))
  2464. (setq buffer-read-only edebug-buffer-read-only)
  2465. (use-local-map edebug-outside-map)
  2466. (remove-hook 'kill-buffer-hook 'edebug-kill-buffer t)
  2467. )
  2468. ;; gotta have a buffer to let its buffer local variables be set
  2469. (get-buffer-create " bogus edebug buffer"))
  2470. ));; inner let
  2471. ;; Reset global vars to outside values, in case they have been changed.
  2472. (setq
  2473. last-command-event edebug-outside-last-command-event
  2474. last-command edebug-outside-last-command
  2475. this-command edebug-outside-this-command
  2476. unread-command-char edebug-outside-unread-command-char
  2477. current-prefix-arg edebug-outside-current-prefix-arg
  2478. last-input-event edebug-outside-last-input-event
  2479. last-event-frame edebug-outside-last-event-frame
  2480. last-nonmenu-event edebug-outside-last-nonmenu-event
  2481. track-mouse edebug-outside-track-mouse
  2482. standard-output edebug-outside-standard-output
  2483. standard-input edebug-outside-standard-input
  2484. defining-kbd-macro edebug-outside-defining-kbd-macro
  2485. ))
  2486. ))
  2487. ;;; Display related functions
  2488. (defun edebug-adjust-window (old-start)
  2489. ;; If pos is not visible, adjust current window to fit following context.
  2490. ;;; (message "window: %s old-start: %s window-start: %s pos: %s"
  2491. ;;; (selected-window) old-start (window-start) (point)) (sit-for 5)
  2492. (if (not (pos-visible-in-window-p))
  2493. (progn
  2494. ;; First try old-start
  2495. (if old-start
  2496. (set-window-start (selected-window) old-start))
  2497. (if (not (pos-visible-in-window-p))
  2498. (progn
  2499. ;; (message "resetting window start") (sit-for 2)
  2500. (set-window-start
  2501. (selected-window)
  2502. (save-excursion
  2503. (forward-line
  2504. (if (< (point) (window-start)) -1 ; one line before if in back
  2505. (- (/ (window-height) 2)) ; center the line moving forward
  2506. ))
  2507. (beginning-of-line)
  2508. (point)))))))
  2509. (window-start))
  2510. (defconst edebug-arrow-alist
  2511. '((Continue-fast . "=")
  2512. (Trace-fast . "-")
  2513. (continue . ">")
  2514. (trace . "->")
  2515. (step . "=>")
  2516. (next . "=>")
  2517. (go . "<>")
  2518. (Go-nonstop . "..") ; not used
  2519. )
  2520. "Association list of arrows for each edebug mode.")
  2521. (defun edebug-overlay-arrow ()
  2522. ;; Set up the overlay arrow at beginning-of-line in current buffer.
  2523. ;; The arrow string is derived from edebug-arrow-alist and
  2524. ;; edebug-execution-mode.
  2525. (let ((pos (line-beginning-position)))
  2526. (setq overlay-arrow-string
  2527. (cdr (assq edebug-execution-mode edebug-arrow-alist)))
  2528. (setq overlay-arrow-position (make-marker))
  2529. (set-marker overlay-arrow-position pos (current-buffer))))
  2530. (defun edebug-toggle-save-all-windows ()
  2531. "Toggle the saving and restoring of all windows.
  2532. Also, each time you toggle it on, the inside and outside window
  2533. configurations become the same as the current configuration."
  2534. (interactive)
  2535. (setq edebug-save-windows (not edebug-save-windows))
  2536. (if edebug-save-windows
  2537. (setq edebug-inside-windows
  2538. (setq edebug-outside-windows
  2539. (edebug-current-windows
  2540. edebug-save-windows))))
  2541. (message "Window saving is %s for all windows."
  2542. (if edebug-save-windows "on" "off")))
  2543. (defmacro edebug-changing-windows (&rest body)
  2544. `(let ((window (selected-window)))
  2545. (setq edebug-inside-windows (edebug-current-windows t))
  2546. (edebug-set-windows edebug-outside-windows)
  2547. ,@body;; Code to change edebug-save-windows
  2548. (setq edebug-outside-windows (edebug-current-windows
  2549. edebug-save-windows))
  2550. ;; Problem: what about outside windows that are deleted inside?
  2551. (edebug-set-windows edebug-inside-windows)))
  2552. (defun edebug-toggle-save-selected-window ()
  2553. "Toggle the saving and restoring of the selected window.
  2554. Also, each time you toggle it on, the inside and outside window
  2555. configurations become the same as the current configuration."
  2556. (interactive)
  2557. (cond
  2558. ((eq t edebug-save-windows)
  2559. ;; Save all outside windows except the selected one.
  2560. ;; Remove (selected-window) from outside-windows.
  2561. (edebug-changing-windows
  2562. (setq edebug-save-windows (delq window (edebug-window-list)))))
  2563. ((memq (selected-window) edebug-save-windows)
  2564. (setq edebug-outside-windows
  2565. (delq (assq (selected-window) edebug-outside-windows)
  2566. edebug-outside-windows))
  2567. (setq edebug-save-windows
  2568. (delq (selected-window) edebug-save-windows)))
  2569. (t ; Save a new window.
  2570. (edebug-changing-windows
  2571. (setq edebug-save-windows (cons window edebug-save-windows)))))
  2572. (message "Window saving is %s for %s."
  2573. (if (memq (selected-window) edebug-save-windows)
  2574. "on" "off")
  2575. (selected-window)))
  2576. (defun edebug-toggle-save-windows (arg)
  2577. "Toggle the saving and restoring of windows.
  2578. With prefix, toggle for just the selected window.
  2579. Otherwise, toggle for all windows."
  2580. (interactive "P")
  2581. (if arg
  2582. (edebug-toggle-save-selected-window)
  2583. (edebug-toggle-save-all-windows)))
  2584. (defun edebug-where ()
  2585. "Show the debug windows and where we stopped in the program."
  2586. (interactive)
  2587. (if (not edebug-active)
  2588. (error "Edebug is not active"))
  2589. ;; Restore the window configuration to what it last was inside.
  2590. ;; But it is not always set. - experiment
  2591. ;;(if edebug-inside-windows
  2592. ;; (edebug-set-windows edebug-inside-windows))
  2593. (edebug-pop-to-buffer edebug-buffer)
  2594. (goto-char edebug-point))
  2595. (defun edebug-view-outside ()
  2596. "Change to the outside window configuration.
  2597. Use `edebug-where' to return."
  2598. (interactive)
  2599. (if (not edebug-active)
  2600. (error "Edebug is not active"))
  2601. (setq edebug-inside-windows
  2602. (edebug-current-windows edebug-save-windows))
  2603. (edebug-set-windows edebug-outside-windows)
  2604. (goto-char edebug-outside-point)
  2605. (message "Window configuration outside of Edebug. Return with %s"
  2606. (substitute-command-keys "\\<global-map>\\[edebug-where]")))
  2607. (defun edebug-bounce-point (arg)
  2608. "Bounce the point in the outside current buffer.
  2609. If prefix argument ARG is supplied, sit for that many seconds
  2610. before returning. The default is one second."
  2611. (interactive "p")
  2612. (if (not edebug-active)
  2613. (error "Edebug is not active"))
  2614. (save-excursion
  2615. ;; If the buffer's currently displayed, avoid set-window-configuration.
  2616. (save-window-excursion
  2617. (edebug-pop-to-buffer edebug-outside-buffer)
  2618. (goto-char edebug-outside-point)
  2619. (message "Current buffer: %s Point: %s Mark: %s"
  2620. (current-buffer) (point)
  2621. (if (marker-buffer (edebug-mark-marker))
  2622. (marker-position (edebug-mark-marker)) "<not set>"))
  2623. (edebug-sit-for arg)
  2624. (edebug-pop-to-buffer edebug-buffer (car edebug-window-data)))))
  2625. ;; Joe Wells, here is a start at your idea of adding a buffer to the internal
  2626. ;; display list. Still need to use this list in edebug-display.
  2627. '(defvar edebug-display-buffer-list nil
  2628. "List of buffers that edebug will display when it is active.")
  2629. '(defun edebug-display-buffer (buffer)
  2630. "Toggle display of a buffer inside of edebug."
  2631. (interactive "bBuffer: ")
  2632. (let ((already-displaying (memq buffer edebug-display-buffer-list)))
  2633. (setq edebug-display-buffer-list
  2634. (if already-displaying
  2635. (delq buffer edebug-display-buffer-list)
  2636. (cons buffer edebug-display-buffer-list)))
  2637. (message "Displaying %s %s" buffer
  2638. (if already-displaying "off" "on"))))
  2639. ;;; Breakpoint related functions
  2640. (defun edebug-find-stop-point ()
  2641. ;; Return (function . index) of the nearest edebug stop point.
  2642. (let* ((edebug-def-name (edebug-form-data-symbol))
  2643. (edebug-data
  2644. (let ((data (get edebug-def-name 'edebug)))
  2645. (if (or (null data) (markerp data))
  2646. (error "%s is not instrumented for Edebug" edebug-def-name))
  2647. data)) ; we could do it automatically, if data is a marker.
  2648. ;; pull out parts of edebug-data.
  2649. (edebug-def-mark (car edebug-data))
  2650. ;; (edebug-breakpoints (car (cdr edebug-data)))
  2651. (offset-vector (nth 2 edebug-data))
  2652. (offset (- (save-excursion
  2653. (if (looking-at "[ \t]")
  2654. ;; skip backwards until non-whitespace, or bol
  2655. (skip-chars-backward " \t"))
  2656. (point))
  2657. edebug-def-mark))
  2658. len i)
  2659. ;; the offsets are in order so we can do a linear search
  2660. (setq len (length offset-vector))
  2661. (setq i 0)
  2662. (while (and (< i len) (> offset (aref offset-vector i)))
  2663. (setq i (1+ i)))
  2664. (if (and (< i len)
  2665. (<= offset (aref offset-vector i)))
  2666. ;; return the relevant info
  2667. (cons edebug-def-name i)
  2668. (message "Point is not on an expression in %s."
  2669. edebug-def-name)
  2670. )))
  2671. (defun edebug-next-breakpoint ()
  2672. "Move point to the next breakpoint, or first if none past point."
  2673. (interactive)
  2674. (let ((edebug-stop-point (edebug-find-stop-point)))
  2675. (if edebug-stop-point
  2676. (let* ((edebug-def-name (car edebug-stop-point))
  2677. (index (cdr edebug-stop-point))
  2678. (edebug-data (get edebug-def-name 'edebug))
  2679. ;; pull out parts of edebug-data
  2680. (edebug-def-mark (car edebug-data))
  2681. (edebug-breakpoints (car (cdr edebug-data)))
  2682. (offset-vector (nth 2 edebug-data))
  2683. breakpoint)
  2684. (if (not edebug-breakpoints)
  2685. (message "No breakpoints in this function.")
  2686. (let ((breaks edebug-breakpoints))
  2687. (while (and breaks
  2688. (<= (car (car breaks)) index))
  2689. (setq breaks (cdr breaks)))
  2690. (setq breakpoint
  2691. (if breaks
  2692. (car breaks)
  2693. ;; goto the first breakpoint
  2694. (car edebug-breakpoints)))
  2695. (goto-char (+ edebug-def-mark
  2696. (aref offset-vector (car breakpoint))))
  2697. (message "%s"
  2698. (concat (if (nth 2 breakpoint)
  2699. "Temporary " "")
  2700. (if (car (cdr breakpoint))
  2701. (format "Condition: %s"
  2702. (edebug-safe-prin1-to-string
  2703. (car (cdr breakpoint))))
  2704. "")))
  2705. ))))))
  2706. (defun edebug-modify-breakpoint (flag &optional condition temporary)
  2707. "Modify the breakpoint for the form at point or after it.
  2708. Set it if FLAG is non-nil, clear it otherwise. Then move to that point.
  2709. If CONDITION or TEMPORARY are non-nil, add those attributes to
  2710. the breakpoint."
  2711. (let ((edebug-stop-point (edebug-find-stop-point)))
  2712. (if edebug-stop-point
  2713. (let* ((edebug-def-name (car edebug-stop-point))
  2714. (index (cdr edebug-stop-point))
  2715. (edebug-data (get edebug-def-name 'edebug))
  2716. ;; pull out parts of edebug-data
  2717. (edebug-def-mark (car edebug-data))
  2718. (edebug-breakpoints (car (cdr edebug-data)))
  2719. (offset-vector (nth 2 edebug-data))
  2720. present)
  2721. ;; delete it either way
  2722. (setq present (assq index edebug-breakpoints))
  2723. (setq edebug-breakpoints (delq present edebug-breakpoints))
  2724. (if flag
  2725. (progn
  2726. ;; add it to the list and resort
  2727. (setq edebug-breakpoints
  2728. (edebug-sort-alist
  2729. (cons
  2730. (list index condition temporary)
  2731. edebug-breakpoints) '<))
  2732. (if condition
  2733. (message "Breakpoint set in %s with condition: %s"
  2734. edebug-def-name condition)
  2735. (message "Breakpoint set in %s" edebug-def-name)))
  2736. (if present
  2737. (message "Breakpoint unset in %s" edebug-def-name)
  2738. (message "No breakpoint here")))
  2739. (setcar (cdr edebug-data) edebug-breakpoints)
  2740. (goto-char (+ edebug-def-mark (aref offset-vector index)))
  2741. ))))
  2742. (defun edebug-set-breakpoint (arg)
  2743. "Set the breakpoint of nearest sexp.
  2744. With prefix argument, make it a temporary breakpoint."
  2745. (interactive "P")
  2746. (edebug-modify-breakpoint t nil arg))
  2747. (defun edebug-unset-breakpoint ()
  2748. "Clear the breakpoint of nearest sexp."
  2749. (interactive)
  2750. (edebug-modify-breakpoint nil))
  2751. (defun edebug-set-global-break-condition (expression)
  2752. "Set `edebug-global-break-condition' to EXPRESSION."
  2753. (interactive
  2754. (list
  2755. (let ((initial (and edebug-global-break-condition
  2756. (format "%s" edebug-global-break-condition))))
  2757. (read-from-minibuffer
  2758. "Global Condition: " initial read-expression-map t
  2759. (if (equal (car read-expression-history) initial)
  2760. '(read-expression-history . 1)
  2761. 'read-expression-history)))))
  2762. (setq edebug-global-break-condition expression))
  2763. ;;; Mode switching functions
  2764. (defun edebug-set-mode (mode shortmsg msg)
  2765. ;; Set the edebug mode to MODE.
  2766. ;; Display SHORTMSG, or MSG if not within edebug.
  2767. (if (eq (1+ edebug-recursion-depth) (recursion-depth))
  2768. (progn
  2769. (setq edebug-execution-mode mode)
  2770. (message "%s" shortmsg)
  2771. ;; Continue execution
  2772. (exit-recursive-edit))
  2773. ;; This is not terribly useful!!
  2774. (setq edebug-next-execution-mode mode)
  2775. (message "%s" msg)))
  2776. (defalias 'edebug-step-through-mode 'edebug-step-mode)
  2777. (defun edebug-step-mode ()
  2778. "Proceed to next stop point."
  2779. (interactive)
  2780. (edebug-set-mode 'step "" "Edebug will stop at next stop point."))
  2781. (defun edebug-next-mode ()
  2782. "Proceed to next `after' stop point."
  2783. (interactive)
  2784. (edebug-set-mode 'next "" "Edebug will stop after next eval."))
  2785. (defun edebug-go-mode (arg)
  2786. "Go, evaluating until break.
  2787. With prefix ARG, set temporary break at current point and go."
  2788. (interactive "P")
  2789. (if arg
  2790. (edebug-set-breakpoint t))
  2791. (edebug-set-mode 'go "Go..." "Edebug will go until break."))
  2792. (defun edebug-Go-nonstop-mode ()
  2793. "Go, evaluating without debugging.
  2794. You can use `edebug-stop', or any editing command, to stop."
  2795. (interactive)
  2796. (edebug-set-mode 'Go-nonstop "Go-Nonstop..."
  2797. "Edebug will not stop at breaks."))
  2798. (defun edebug-trace-mode ()
  2799. "Begin trace mode.
  2800. Pauses for `edebug-sit-for-seconds' at each stop point."
  2801. (interactive)
  2802. (edebug-set-mode 'trace "Tracing..." "Edebug will trace with pause."))
  2803. (defun edebug-Trace-fast-mode ()
  2804. "Trace with no wait at each step.
  2805. Updates the display at each stop point, but does not pause."
  2806. (interactive)
  2807. (edebug-set-mode 'Trace-fast
  2808. "Trace fast..." "Edebug will trace without pause."))
  2809. (defun edebug-continue-mode ()
  2810. "Begin continue mode.
  2811. Pauses for `edebug-sit-for-seconds' at each break point."
  2812. (interactive)
  2813. (edebug-set-mode 'continue "Continue..."
  2814. "Edebug will pause at breakpoints."))
  2815. (defun edebug-Continue-fast-mode ()
  2816. "Trace with no wait at each step.
  2817. Updates the display at each break point, but does not pause."
  2818. (interactive)
  2819. (edebug-set-mode 'Continue-fast "Continue fast..."
  2820. "Edebug will stop and go at breakpoints."))
  2821. ;; ------------------------------------------------------------
  2822. ;; The following use the mode changing commands and breakpoints.
  2823. (defun edebug-goto-here ()
  2824. "Proceed to first stop-point at or after current position of point."
  2825. (interactive)
  2826. (edebug-go-mode t))
  2827. (defun edebug-stop ()
  2828. "Stop execution and do not continue.
  2829. Useful for exiting from trace or continue loop."
  2830. (interactive)
  2831. (message "Stop"))
  2832. '(defun edebug-forward ()
  2833. "Proceed to the exit of the next expression to be evaluated."
  2834. (interactive)
  2835. (edebug-set-mode
  2836. 'forward "Forward"
  2837. "Edebug will stop after exiting the next expression."))
  2838. (defun edebug-forward-sexp (arg)
  2839. "Proceed from the current point to the end of the ARGth sexp ahead.
  2840. If there are not ARG sexps ahead, then do `edebug-step-out'."
  2841. (interactive "p")
  2842. (condition-case nil
  2843. (let ((parse-sexp-ignore-comments t))
  2844. ;; Call forward-sexp repeatedly until done or failure.
  2845. (forward-sexp arg)
  2846. (edebug-go-mode t))
  2847. (error
  2848. (edebug-step-out)
  2849. )))
  2850. (defun edebug-step-out ()
  2851. "Proceed from the current point to the end of the containing sexp.
  2852. If there is no containing sexp that is not the top level defun,
  2853. go to the end of the last sexp, or if that is the same point, then step."
  2854. (interactive)
  2855. (condition-case nil
  2856. (let ((parse-sexp-ignore-comments t))
  2857. (up-list 1)
  2858. (save-excursion
  2859. ;; Is there still a containing expression?
  2860. (up-list 1))
  2861. (edebug-go-mode t))
  2862. (error
  2863. ;; At top level - 1, so first check if there are more sexps at this level.
  2864. (let ((start-point (point)))
  2865. ;; (up-list 1)
  2866. (down-list -1)
  2867. (if (= (point) start-point)
  2868. (edebug-step-mode) ; No more at this level, so step.
  2869. (edebug-go-mode t)
  2870. )))))
  2871. (defun edebug-instrument-function (func)
  2872. ;; Func should be a function symbol.
  2873. ;; Return the function symbol, or nil if not instrumented.
  2874. (let ((func-marker (get func 'edebug)))
  2875. (cond
  2876. ((and (markerp func-marker) (marker-buffer func-marker))
  2877. ;; It is uninstrumented, so instrument it.
  2878. (with-current-buffer (marker-buffer func-marker)
  2879. (goto-char func-marker)
  2880. (edebug-eval-top-level-form)
  2881. func))
  2882. ((consp func-marker)
  2883. (message "%s is already instrumented." func)
  2884. func)
  2885. (t
  2886. (let ((loc (find-function-noselect func t)))
  2887. (unless (cdr loc)
  2888. (error "Could not find the definition in its file"))
  2889. (with-current-buffer (car loc)
  2890. (goto-char (cdr loc))
  2891. (edebug-eval-top-level-form)
  2892. func))))))
  2893. (defun edebug-instrument-callee ()
  2894. "Instrument the definition of the function or macro about to be called.
  2895. Do this when stopped before the form or it will be too late.
  2896. One side effect of using this command is that the next time the
  2897. function or macro is called, Edebug will be called there as well."
  2898. (interactive)
  2899. (if (not (looking-at "\("))
  2900. (error "You must be before a list form")
  2901. (let ((func
  2902. (save-excursion
  2903. (down-list 1)
  2904. (if (looking-at "\(")
  2905. (edebug-form-data-name
  2906. (edebug-get-form-data-entry (point)))
  2907. (edebug-original-read (current-buffer))))))
  2908. (edebug-instrument-function func))))
  2909. (defun edebug-step-in ()
  2910. "Step into the definition of the function or macro about to be called.
  2911. This first does `edebug-instrument-callee' to ensure that it is
  2912. instrumented. Then it does `edebug-on-entry' and switches to `go' mode."
  2913. (interactive)
  2914. (let ((func (edebug-instrument-callee)))
  2915. (if func
  2916. (progn
  2917. (edebug-on-entry func 'temp)
  2918. (edebug-go-mode nil)))))
  2919. (defun edebug-on-entry (function &optional flag)
  2920. "Cause Edebug to stop when FUNCTION is called.
  2921. With prefix argument, make this temporary so it is automatically
  2922. canceled the first time the function is entered."
  2923. (interactive "aEdebug on entry to: \nP")
  2924. ;; Could store this in the edebug data instead.
  2925. (put function 'edebug-on-entry (if flag 'temp t)))
  2926. (defun cancel-edebug-on-entry (function)
  2927. (interactive "aEdebug on entry to: ")
  2928. (put function 'edebug-on-entry nil))
  2929. (if (not (fboundp 'edebug-original-debug-on-entry))
  2930. (fset 'edebug-original-debug-on-entry (symbol-function 'debug-on-entry)))
  2931. '(fset 'debug-on-entry 'edebug-debug-on-entry) ;; Should we do this?
  2932. ;; Also need edebug-cancel-debug-on-entry
  2933. '(defun edebug-debug-on-entry (function)
  2934. "Request FUNCTION to invoke debugger each time it is called.
  2935. If the user continues, FUNCTION's execution proceeds.
  2936. Works by modifying the definition of FUNCTION,
  2937. which must be written in Lisp, not predefined.
  2938. Use `cancel-debug-on-entry' to cancel the effect of this command.
  2939. Redefining FUNCTION also does that.
  2940. This version is from Edebug. If the function is instrumented for
  2941. Edebug, it calls `edebug-on-entry'."
  2942. (interactive "aDebug on entry (to function): ")
  2943. (let ((func-data (get function 'edebug)))
  2944. (if (or (null func-data) (markerp func-data))
  2945. (edebug-original-debug-on-entry function)
  2946. (edebug-on-entry function))))
  2947. (defun edebug-top-level-nonstop ()
  2948. "Set mode to Go-nonstop, and exit to top-level.
  2949. This is useful for exiting even if `unwind-protect' code may be executed."
  2950. (interactive)
  2951. (setq edebug-execution-mode 'Go-nonstop)
  2952. (top-level))
  2953. ;;(defun edebug-exit-out ()
  2954. ;; "Go until the current function exits."
  2955. ;; (interactive)
  2956. ;; (edebug-set-mode 'exiting "Exit..."))
  2957. ;;; The following initial mode setting definitions are not used yet.
  2958. '(defconst edebug-initial-mode-alist
  2959. '((edebug-Continue-fast . Continue-fast)
  2960. (edebug-Trace-fast . Trace-fast)
  2961. (edebug-continue . continue)
  2962. (edebug-trace . trace)
  2963. (edebug-go . go)
  2964. (edebug-step-through . step)
  2965. (edebug-Go-nonstop . Go-nonstop)
  2966. )
  2967. "Association list between commands and the modes they set.")
  2968. '(defun edebug-set-initial-mode ()
  2969. "Ask for the initial mode of the enclosing function.
  2970. The mode is requested via the key that would be used to set the mode in
  2971. edebug-mode."
  2972. (interactive)
  2973. (let* ((this-function (edebug-which-function))
  2974. (keymap (if (eq edebug-mode-map (current-local-map))
  2975. edebug-mode-map))
  2976. (old-mode (or (get this-function 'edebug-initial-mode)
  2977. edebug-initial-mode))
  2978. (key (read-key-sequence
  2979. (format
  2980. "Change initial edebug mode for %s from %s (%s) to (enter key): "
  2981. this-function
  2982. old-mode
  2983. (where-is-internal
  2984. (car (rassq old-mode edebug-initial-mode-alist))
  2985. keymap 'firstonly
  2986. ))))
  2987. (mode (cdr (assq (key-binding key) edebug-initial-mode-alist)))
  2988. )
  2989. (if (and mode
  2990. (or (get this-function 'edebug-initial-mode)
  2991. (not (eq mode edebug-initial-mode))))
  2992. (progn
  2993. (put this-function 'edebug-initial-mode mode)
  2994. (message "Initial mode for %s is now: %s"
  2995. this-function mode))
  2996. (error "Key must map to one of the mode changing commands")
  2997. )))
  2998. ;;; Evaluation of expressions
  2999. (def-edebug-spec edebug-outside-excursion t)
  3000. (defmacro edebug-outside-excursion (&rest body)
  3001. "Evaluate an expression list in the outside context.
  3002. Return the result of the last expression."
  3003. `(save-excursion ; of current-buffer
  3004. (if edebug-save-windows
  3005. (progn
  3006. ;; After excursion, we will
  3007. ;; restore to current window configuration.
  3008. (setq edebug-inside-windows
  3009. (edebug-current-windows edebug-save-windows))
  3010. ;; Restore outside windows.
  3011. (edebug-set-windows edebug-outside-windows)))
  3012. (set-buffer edebug-buffer) ; why?
  3013. ;; (use-local-map edebug-outside-map)
  3014. (set-match-data edebug-outside-match-data)
  3015. ;; Restore outside context.
  3016. (let (;; (edebug-inside-map (current-local-map)) ;; restore map??
  3017. (last-command-event edebug-outside-last-command-event)
  3018. (last-command edebug-outside-last-command)
  3019. (this-command edebug-outside-this-command)
  3020. (unread-command-char edebug-outside-unread-command-char)
  3021. (unread-command-events edebug-outside-unread-command-events)
  3022. (current-prefix-arg edebug-outside-current-prefix-arg)
  3023. (last-input-event edebug-outside-last-input-event)
  3024. (last-event-frame edebug-outside-last-event-frame)
  3025. (last-nonmenu-event edebug-outside-last-nonmenu-event)
  3026. (track-mouse edebug-outside-track-mouse)
  3027. (standard-output edebug-outside-standard-output)
  3028. (standard-input edebug-outside-standard-input)
  3029. (executing-kbd-macro edebug-outside-executing-macro)
  3030. (defining-kbd-macro edebug-outside-defining-kbd-macro)
  3031. ;; Get the values out of the saved statuses.
  3032. (pre-command-hook (cdr edebug-outside-pre-command-hook))
  3033. (post-command-hook (cdr edebug-outside-post-command-hook))
  3034. ;; See edebug-display
  3035. (overlay-arrow-position edebug-outside-o-a-p)
  3036. (overlay-arrow-string edebug-outside-o-a-s)
  3037. (cursor-in-echo-area edebug-outside-c-i-e-a)
  3038. )
  3039. (setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
  3040. (unwind-protect
  3041. (with-current-buffer edebug-outside-buffer ; of edebug-buffer
  3042. (goto-char edebug-outside-point)
  3043. (if (marker-buffer (edebug-mark-marker))
  3044. (set-marker (edebug-mark-marker) edebug-outside-mark))
  3045. ,@body)
  3046. ;; Back to edebug-buffer. Restore rest of inside context.
  3047. ;; (use-local-map edebug-inside-map)
  3048. (if edebug-save-windows
  3049. ;; Restore inside windows.
  3050. (edebug-set-windows edebug-inside-windows))
  3051. ;; Save values that may have been changed.
  3052. (setq
  3053. edebug-outside-last-command-event last-command-event
  3054. edebug-outside-last-command last-command
  3055. edebug-outside-this-command this-command
  3056. edebug-outside-unread-command-char unread-command-char
  3057. edebug-outside-unread-command-events unread-command-events
  3058. edebug-outside-current-prefix-arg current-prefix-arg
  3059. edebug-outside-last-input-event last-input-event
  3060. edebug-outside-last-event-frame last-event-frame
  3061. edebug-outside-last-nonmenu-event last-nonmenu-event
  3062. edebug-outside-track-mouse track-mouse
  3063. edebug-outside-standard-output standard-output
  3064. edebug-outside-standard-input standard-input
  3065. edebug-outside-executing-macro executing-kbd-macro
  3066. edebug-outside-defining-kbd-macro defining-kbd-macro
  3067. edebug-outside-o-a-p overlay-arrow-position
  3068. edebug-outside-o-a-s overlay-arrow-string
  3069. edebug-outside-c-i-e-a cursor-in-echo-area
  3070. edebug-outside-d-c-i-n-s-w (default-value
  3071. 'cursor-in-non-selected-windows)
  3072. )
  3073. ;; Restore the outside saved values; don't alter
  3074. ;; the outside binding loci.
  3075. (setcdr edebug-outside-pre-command-hook pre-command-hook)
  3076. (setcdr edebug-outside-post-command-hook post-command-hook)
  3077. (setq-default cursor-in-non-selected-windows t)
  3078. )) ; let
  3079. ))
  3080. (defvar cl-debug-env) ; defined in cl; non-nil when lexical env used.
  3081. (defun edebug-eval (edebug-expr)
  3082. ;; Are there cl lexical variables active?
  3083. (eval (if (bound-and-true-p cl-debug-env)
  3084. (cl-macroexpand-all edebug-expr cl-debug-env)
  3085. edebug-expr)
  3086. lexical-binding))
  3087. (defun edebug-safe-eval (edebug-expr)
  3088. ;; Evaluate EXPR safely.
  3089. ;; If there is an error, a string is returned describing the error.
  3090. (condition-case edebug-err
  3091. (edebug-eval edebug-expr)
  3092. (error (edebug-format "%s: %s" ;; could
  3093. (get (car edebug-err) 'error-message)
  3094. (car (cdr edebug-err))))))
  3095. ;;; Printing
  3096. (defun edebug-report-error (edebug-value)
  3097. ;; Print an error message like command level does.
  3098. ;; This also prints the error name if it has no error-message.
  3099. (message "%s: %s"
  3100. (or (get (car edebug-value) 'error-message)
  3101. (format "peculiar error (%s)" (car edebug-value)))
  3102. (mapconcat (function (lambda (edebug-arg)
  3103. ;; continuing after an error may
  3104. ;; complain about edebug-arg. why??
  3105. (prin1-to-string edebug-arg)))
  3106. (cdr edebug-value) ", ")))
  3107. (defvar print-readably) ; defined by lemacs
  3108. ;; Alternatively, we could change the definition of
  3109. ;; edebug-safe-prin1-to-string to only use these if defined.
  3110. (defun edebug-safe-prin1-to-string (value)
  3111. (let ((print-escape-newlines t)
  3112. (print-length (or edebug-print-length print-length))
  3113. (print-level (or edebug-print-level print-level))
  3114. (print-circle (or edebug-print-circle print-circle))
  3115. (print-readably nil)) ; lemacs uses this.
  3116. (condition-case nil
  3117. (edebug-prin1-to-string value)
  3118. (error "#Apparently circular structure#"))))
  3119. (defun edebug-compute-previous-result (edebug-previous-value)
  3120. (if edebug-unwrap-results
  3121. (setq edebug-previous-value
  3122. (edebug-unwrap* edebug-previous-value)))
  3123. (setq edebug-previous-result
  3124. (concat "Result: "
  3125. (edebug-safe-prin1-to-string edebug-previous-value)
  3126. (eval-expression-print-format edebug-previous-value))))
  3127. (defun edebug-previous-result ()
  3128. "Print the previous result."
  3129. (interactive)
  3130. (message "%s" edebug-previous-result))
  3131. ;;; Read, Eval and Print
  3132. (defalias 'edebug-prin1 'prin1)
  3133. (defalias 'edebug-print 'print)
  3134. (defalias 'edebug-prin1-to-string 'prin1-to-string)
  3135. (defalias 'edebug-format 'format)
  3136. (defalias 'edebug-message 'message)
  3137. (defun edebug-eval-expression (edebug-expr)
  3138. "Evaluate an expression in the outside environment.
  3139. If interactive, prompt for the expression.
  3140. Print result in minibuffer."
  3141. (interactive (list (read-from-minibuffer
  3142. "Eval: " nil read-expression-map t
  3143. 'read-expression-history)))
  3144. (princ
  3145. (edebug-outside-excursion
  3146. (setq values (cons (edebug-eval edebug-expr) values))
  3147. (concat (edebug-safe-prin1-to-string (car values))
  3148. (eval-expression-print-format (car values))))))
  3149. (defun edebug-eval-last-sexp ()
  3150. "Evaluate sexp before point in the outside environment.
  3151. Print value in minibuffer."
  3152. (interactive)
  3153. (edebug-eval-expression (edebug-last-sexp)))
  3154. (defun edebug-eval-print-last-sexp ()
  3155. "Evaluate sexp before point in outside environment; insert value.
  3156. This prints the value into current buffer."
  3157. (interactive)
  3158. (let* ((edebug-form (edebug-last-sexp))
  3159. (edebug-result-string
  3160. (edebug-outside-excursion
  3161. (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form))))
  3162. (standard-output (current-buffer)))
  3163. (princ "\n")
  3164. ;; princ the string to get rid of quotes.
  3165. (princ edebug-result-string)
  3166. (princ "\n")
  3167. ))
  3168. ;;; Edebug Minor Mode
  3169. ;; FIXME eh?
  3170. (defvar gud-inhibit-global-bindings
  3171. "*Non-nil means don't do global rebindings of C-x C-a subcommands.")
  3172. ;; Global GUD bindings for all emacs-lisp-mode buffers.
  3173. (unless gud-inhibit-global-bindings
  3174. (define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode)
  3175. (define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode)
  3176. (define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode)
  3177. (define-key emacs-lisp-mode-map "\C-x\C-a\C-l" 'edebug-where))
  3178. (defvar edebug-mode-map
  3179. (let ((map (copy-keymap emacs-lisp-mode-map)))
  3180. ;; control
  3181. (define-key map " " 'edebug-step-mode)
  3182. (define-key map "n" 'edebug-next-mode)
  3183. (define-key map "g" 'edebug-go-mode)
  3184. (define-key map "G" 'edebug-Go-nonstop-mode)
  3185. (define-key map "t" 'edebug-trace-mode)
  3186. (define-key map "T" 'edebug-Trace-fast-mode)
  3187. (define-key map "c" 'edebug-continue-mode)
  3188. (define-key map "C" 'edebug-Continue-fast-mode)
  3189. ;;(define-key map "f" 'edebug-forward) not implemented
  3190. (define-key map "f" 'edebug-forward-sexp)
  3191. (define-key map "h" 'edebug-goto-here)
  3192. (define-key map "I" 'edebug-instrument-callee)
  3193. (define-key map "i" 'edebug-step-in)
  3194. (define-key map "o" 'edebug-step-out)
  3195. ;; quitting and stopping
  3196. (define-key map "q" 'top-level)
  3197. (define-key map "Q" 'edebug-top-level-nonstop)
  3198. (define-key map "a" 'abort-recursive-edit)
  3199. (define-key map "S" 'edebug-stop)
  3200. ;; breakpoints
  3201. (define-key map "b" 'edebug-set-breakpoint)
  3202. (define-key map "u" 'edebug-unset-breakpoint)
  3203. (define-key map "B" 'edebug-next-breakpoint)
  3204. (define-key map "x" 'edebug-set-conditional-breakpoint)
  3205. (define-key map "X" 'edebug-set-global-break-condition)
  3206. ;; evaluation
  3207. (define-key map "r" 'edebug-previous-result)
  3208. (define-key map "e" 'edebug-eval-expression)
  3209. (define-key map "\C-x\C-e" 'edebug-eval-last-sexp)
  3210. (define-key map "E" 'edebug-visit-eval-list)
  3211. ;; views
  3212. (define-key map "w" 'edebug-where)
  3213. (define-key map "v" 'edebug-view-outside) ;; maybe obsolete??
  3214. (define-key map "p" 'edebug-bounce-point)
  3215. (define-key map "P" 'edebug-view-outside) ;; same as v
  3216. (define-key map "W" 'edebug-toggle-save-windows)
  3217. ;; misc
  3218. (define-key map "?" 'edebug-help)
  3219. (define-key map "d" 'edebug-backtrace)
  3220. (define-key map "-" 'negative-argument)
  3221. ;; statistics
  3222. (define-key map "=" 'edebug-temp-display-freq-count)
  3223. ;; GUD bindings
  3224. (define-key map "\C-c\C-s" 'edebug-step-mode)
  3225. (define-key map "\C-c\C-n" 'edebug-next-mode)
  3226. (define-key map "\C-c\C-c" 'edebug-go-mode)
  3227. (define-key map "\C-x " 'edebug-set-breakpoint)
  3228. (define-key map "\C-c\C-d" 'edebug-unset-breakpoint)
  3229. (define-key map "\C-c\C-t"
  3230. (lambda () (interactive) (edebug-set-breakpoint t)))
  3231. (define-key map "\C-c\C-l" 'edebug-where)
  3232. map))
  3233. ;; Autoloading these global bindings doesn't make sense because
  3234. ;; they cannot be used anyway unless Edebug is already loaded and active.
  3235. (defvar global-edebug-prefix "\^XX"
  3236. "Prefix key for global edebug commands, available from any buffer.")
  3237. (defvar global-edebug-map
  3238. (let ((map (make-sparse-keymap)))
  3239. (define-key map " " 'edebug-step-mode)
  3240. (define-key map "g" 'edebug-go-mode)
  3241. (define-key map "G" 'edebug-Go-nonstop-mode)
  3242. (define-key map "t" 'edebug-trace-mode)
  3243. (define-key map "T" 'edebug-Trace-fast-mode)
  3244. (define-key map "c" 'edebug-continue-mode)
  3245. (define-key map "C" 'edebug-Continue-fast-mode)
  3246. ;; breakpoints
  3247. (define-key map "b" 'edebug-set-breakpoint)
  3248. (define-key map "u" 'edebug-unset-breakpoint)
  3249. (define-key map "x" 'edebug-set-conditional-breakpoint)
  3250. (define-key map "X" 'edebug-set-global-break-condition)
  3251. ;; views
  3252. (define-key map "w" 'edebug-where)
  3253. (define-key map "W" 'edebug-toggle-save-windows)
  3254. ;; quitting
  3255. (define-key map "q" 'top-level)
  3256. (define-key map "Q" 'edebug-top-level-nonstop)
  3257. (define-key map "a" 'abort-recursive-edit)
  3258. ;; statistics
  3259. (define-key map "=" 'edebug-display-freq-count)
  3260. map)
  3261. "Global map of edebug commands, available from any buffer.")
  3262. (global-unset-key global-edebug-prefix)
  3263. (global-set-key global-edebug-prefix global-edebug-map)
  3264. (defun edebug-help ()
  3265. "Describe `edebug-mode'."
  3266. (interactive)
  3267. (describe-function 'edebug-mode))
  3268. (defun edebug-mode ()
  3269. "Mode for Emacs Lisp buffers while in Edebug.
  3270. In addition to all Emacs Lisp commands (except those that modify the
  3271. buffer) there are local and global key bindings to several Edebug
  3272. specific commands. E.g. `edebug-step-mode' is bound to \\[edebug-step-mode]
  3273. in the Edebug buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
  3274. Also see bindings for the eval list buffer *edebug* in `edebug-eval-mode'.
  3275. The edebug buffer commands:
  3276. \\{edebug-mode-map}
  3277. Global commands prefixed by `global-edebug-prefix':
  3278. \\{global-edebug-map}
  3279. Options:
  3280. `edebug-setup-hook'
  3281. `edebug-all-defs'
  3282. `edebug-all-forms'
  3283. `edebug-save-windows'
  3284. `edebug-save-displayed-buffer-points'
  3285. `edebug-initial-mode'
  3286. `edebug-trace'
  3287. `edebug-test-coverage'
  3288. `edebug-continue-kbd-macro'
  3289. `edebug-print-length'
  3290. `edebug-print-level'
  3291. `edebug-print-circle'
  3292. `edebug-on-error'
  3293. `edebug-on-quit'
  3294. `edebug-on-signal'
  3295. `edebug-unwrap-results'
  3296. `edebug-global-break-condition'"
  3297. ;; If the user kills the buffer in which edebug is currently active,
  3298. ;; exit to top level, because the edebug command loop can't usefully
  3299. ;; continue running in such a case.
  3300. (add-hook 'kill-buffer-hook 'edebug-kill-buffer nil t)
  3301. (use-local-map edebug-mode-map))
  3302. (defun edebug-kill-buffer ()
  3303. "Used on `kill-buffer-hook' when Edebug is operating in a buffer of Lisp code."
  3304. (let (kill-buffer-hook)
  3305. (kill-buffer (current-buffer)))
  3306. (top-level))
  3307. ;;; edebug eval list mode
  3308. ;; A list of expressions and their evaluations is displayed in *edebug*.
  3309. (defun edebug-eval-result-list ()
  3310. "Return a list of evaluations of `edebug-eval-list'."
  3311. ;; Assumes in outside environment.
  3312. ;; Don't do any edebug things now.
  3313. (let ((edebug-execution-mode 'Go-nonstop)
  3314. (edebug-trace nil))
  3315. (mapcar 'edebug-safe-eval edebug-eval-list)))
  3316. (defun edebug-eval-display-list (edebug-eval-result-list)
  3317. ;; Assumes edebug-eval-buffer exists.
  3318. (let ((edebug-eval-list-temp edebug-eval-list)
  3319. (standard-output edebug-eval-buffer)
  3320. (edebug-comment-line
  3321. (format ";%s\n" (make-string (- (window-width) 2) ?-))))
  3322. (set-buffer edebug-eval-buffer)
  3323. (erase-buffer)
  3324. (while edebug-eval-list-temp
  3325. (prin1 (car edebug-eval-list-temp)) (terpri)
  3326. (prin1 (car edebug-eval-result-list)) (terpri)
  3327. (princ edebug-comment-line)
  3328. (setq edebug-eval-list-temp (cdr edebug-eval-list-temp))
  3329. (setq edebug-eval-result-list (cdr edebug-eval-result-list)))
  3330. (edebug-pop-to-buffer edebug-eval-buffer)
  3331. ))
  3332. (defun edebug-create-eval-buffer ()
  3333. (if (not (and edebug-eval-buffer (buffer-name edebug-eval-buffer)))
  3334. (progn
  3335. (set-buffer (setq edebug-eval-buffer (get-buffer-create "*edebug*")))
  3336. (edebug-eval-mode))))
  3337. ;; Should generalize this to be callable outside of edebug
  3338. ;; with calls in user functions, e.g. (edebug-eval-display)
  3339. (defun edebug-eval-display (edebug-eval-result-list)
  3340. "Display expressions and evaluations in EDEBUG-EVAL-RESULT-LIST.
  3341. It modifies the context by popping up the eval display."
  3342. (if edebug-eval-result-list
  3343. (progn
  3344. (edebug-create-eval-buffer)
  3345. (edebug-eval-display-list edebug-eval-result-list)
  3346. )))
  3347. (defun edebug-eval-redisplay ()
  3348. "Redisplay eval list in outside environment.
  3349. May only be called from within `edebug-recursive-edit'."
  3350. (edebug-create-eval-buffer)
  3351. (edebug-outside-excursion
  3352. (edebug-eval-display-list (edebug-eval-result-list))
  3353. ))
  3354. (defun edebug-visit-eval-list ()
  3355. "Switch to the evaluation list buffer \"*edebug*\"."
  3356. (interactive)
  3357. (edebug-eval-redisplay)
  3358. (edebug-pop-to-buffer edebug-eval-buffer))
  3359. (defun edebug-update-eval-list ()
  3360. "Replace the evaluation list with the sexps now in the eval buffer."
  3361. (interactive)
  3362. (let ((starting-point (point))
  3363. new-list)
  3364. (goto-char (point-min))
  3365. ;; get the first expression
  3366. (edebug-skip-whitespace)
  3367. (if (not (eobp))
  3368. (progn
  3369. (forward-sexp 1)
  3370. (setq new-list (cons (edebug-last-sexp) new-list))))
  3371. (while (re-search-forward "^;" nil t)
  3372. (forward-line 1)
  3373. (skip-chars-forward " \t\n\r")
  3374. (if (and (/= ?\; (following-char))
  3375. (not (eobp)))
  3376. (progn
  3377. (forward-sexp 1)
  3378. (setq new-list (cons (edebug-last-sexp) new-list)))))
  3379. (setq edebug-eval-list (nreverse new-list))
  3380. (edebug-eval-redisplay)
  3381. (goto-char starting-point)))
  3382. (defun edebug-delete-eval-item ()
  3383. "Delete the item under point and redisplay."
  3384. ;; could add arg to do repeatedly
  3385. (interactive)
  3386. (if (re-search-backward "^;" nil 'nofail)
  3387. (forward-line 1))
  3388. (delete-region
  3389. (point) (progn (re-search-forward "^;" nil 'nofail)
  3390. (beginning-of-line)
  3391. (point)))
  3392. (edebug-update-eval-list))
  3393. (defvar edebug-eval-mode-map
  3394. (let ((map (make-sparse-keymap)))
  3395. (set-keymap-parent map lisp-interaction-mode-map)
  3396. (define-key map "\C-c\C-w" 'edebug-where)
  3397. (define-key map "\C-c\C-d" 'edebug-delete-eval-item)
  3398. (define-key map "\C-c\C-u" 'edebug-update-eval-list)
  3399. (define-key map "\C-x\C-e" 'edebug-eval-last-sexp)
  3400. (define-key map "\C-j" 'edebug-eval-print-last-sexp)
  3401. map)
  3402. "Keymap for Edebug Eval mode. Superset of Lisp Interaction mode.")
  3403. (put 'edebug-eval-mode 'mode-class 'special)
  3404. (define-derived-mode edebug-eval-mode lisp-interaction-mode "Edebug Eval"
  3405. "Mode for evaluation list buffer while in Edebug.
  3406. In addition to all Interactive Emacs Lisp commands there are local and
  3407. global key bindings to several Edebug specific commands. E.g.
  3408. `edebug-step-mode' is bound to \\[edebug-step-mode] in the Edebug
  3409. buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
  3410. Eval list buffer commands:
  3411. \\{edebug-eval-mode-map}
  3412. Global commands prefixed by `global-edebug-prefix':
  3413. \\{global-edebug-map}")
  3414. ;;; Interface with standard debugger.
  3415. ;; (setq debugger 'edebug) ; to use the edebug debugger
  3416. ;; (setq debugger 'debug) ; use the standard debugger
  3417. ;; Note that debug and its utilities must be byte-compiled to work,
  3418. ;; since they depend on the backtrace looking a certain way. But
  3419. ;; edebug is not dependent on this, yet.
  3420. (defun edebug (&optional edebug-arg-mode &rest debugger-args)
  3421. "Replacement for `debug'.
  3422. If we are running an edebugged function, show where we last were.
  3423. Otherwise call `debug' normally."
  3424. ;; (message "entered: %s depth: %s edebug-recursion-depth: %s"
  3425. ;; edebug-entered (recursion-depth) edebug-recursion-depth) (sit-for 1)
  3426. (if (and edebug-entered ; anything active?
  3427. (eq (recursion-depth) edebug-recursion-depth))
  3428. (let (;; Where were we before the error occurred?
  3429. (edebug-offset-index (car edebug-offset-indices))
  3430. ;; Bind variables required by edebug-display
  3431. (edebug-value (car debugger-args))
  3432. edebug-breakpoints
  3433. edebug-break-data
  3434. edebug-break-condition
  3435. edebug-global-break
  3436. (edebug-break (null edebug-arg-mode)) ;; if called explicitly
  3437. )
  3438. (edebug-display)
  3439. (if (eq edebug-arg-mode 'error)
  3440. nil
  3441. edebug-value))
  3442. ;; Otherwise call debug normally.
  3443. ;; Still need to remove extraneous edebug calls from stack.
  3444. (apply 'debug edebug-arg-mode debugger-args)
  3445. ))
  3446. (defun edebug-backtrace ()
  3447. "Display a non-working backtrace. Better than nothing..."
  3448. (interactive)
  3449. (if (or (not edebug-backtrace-buffer)
  3450. (null (buffer-name edebug-backtrace-buffer)))
  3451. (setq edebug-backtrace-buffer
  3452. (generate-new-buffer "*Backtrace*"))
  3453. ;; else, could just display edebug-backtrace-buffer
  3454. )
  3455. (with-output-to-temp-buffer (buffer-name edebug-backtrace-buffer)
  3456. (setq edebug-backtrace-buffer standard-output)
  3457. (let ((print-escape-newlines t)
  3458. (print-length 50) ; FIXME cf edebug-safe-prin1-to-string
  3459. last-ok-point)
  3460. (backtrace)
  3461. ;; Clean up the backtrace.
  3462. ;; Not quite right for current edebug scheme.
  3463. (set-buffer edebug-backtrace-buffer)
  3464. (setq truncate-lines t)
  3465. (goto-char (point-min))
  3466. (setq last-ok-point (point))
  3467. (if t (progn
  3468. ;; Delete interspersed edebug internals.
  3469. (while (re-search-forward "^ \(?edebug" nil t)
  3470. (beginning-of-line)
  3471. (cond
  3472. ((looking-at "^ \(edebug-after")
  3473. ;; Previous lines may contain code, so just delete this line
  3474. (setq last-ok-point (point))
  3475. (forward-line 1)
  3476. (delete-region last-ok-point (point)))
  3477. ((looking-at "^ edebug")
  3478. (forward-line 1)
  3479. (delete-region last-ok-point (point))
  3480. )))
  3481. )))))
  3482. ;;; Trace display
  3483. (defun edebug-trace-display (buf-name fmt &rest args)
  3484. "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
  3485. The buffer is created if it does not exist.
  3486. You must include newlines in FMT to break lines, but one newline is appended."
  3487. ;; e.g.
  3488. ;; (edebug-trace-display "*trace-point*"
  3489. ;; "saving: point = %s window-start = %s"
  3490. ;; (point) (window-start))
  3491. (let* ((oldbuf (current-buffer))
  3492. (selected-window (selected-window))
  3493. (buffer (get-buffer-create buf-name))
  3494. buf-window)
  3495. ;; (message "before pop-to-buffer") (sit-for 1)
  3496. (edebug-pop-to-buffer buffer)
  3497. (setq truncate-lines t)
  3498. (setq buf-window (selected-window))
  3499. (goto-char (point-max))
  3500. (insert (apply 'edebug-format fmt args) "\n")
  3501. ;; Make it visible.
  3502. (vertical-motion (- 1 (window-height)))
  3503. (set-window-start buf-window (point))
  3504. (goto-char (point-max))
  3505. ;; (set-window-point buf-window (point))
  3506. ;; (edebug-sit-for 0)
  3507. (bury-buffer buffer)
  3508. (select-window selected-window)
  3509. (set-buffer oldbuf))
  3510. buf-name)
  3511. (defun edebug-trace (fmt &rest args)
  3512. "Convenience call to `edebug-trace-display' using `edebug-trace-buffer'."
  3513. (apply 'edebug-trace-display edebug-trace-buffer fmt args))
  3514. ;;; Frequency count and coverage
  3515. ;; FIXME should this use overlays instead?
  3516. ;; Definitely, IMO. The current business with undo in
  3517. ;; edebug-temp-display-freq-count is horrid.
  3518. (defun edebug-display-freq-count ()
  3519. "Display the frequency count data for each line of the current definition.
  3520. The frequency counts are inserted as comment lines after each line,
  3521. and you can undo all insertions with one `undo' command.
  3522. The counts are inserted starting under the `(' before an expression
  3523. or the `)' after an expression, or on the last char of a symbol.
  3524. The counts are only displayed when they differ from previous counts on
  3525. the same line.
  3526. If coverage is being tested, whenever all known results of an expression
  3527. are `eq', the char `=' will be appended after the count
  3528. for that expression. Note that this is always the case for an
  3529. expression only evaluated once.
  3530. To clear the frequency count and coverage data for a definition,
  3531. reinstrument it."
  3532. (interactive)
  3533. (let* ((function (edebug-form-data-symbol))
  3534. (counts (get function 'edebug-freq-count))
  3535. (coverages (get function 'edebug-coverage))
  3536. (data (get function 'edebug))
  3537. (def-mark (car data)) ; mark at def start
  3538. (edebug-points (nth 2 data))
  3539. (i (1- (length edebug-points)))
  3540. (last-index)
  3541. (first-index)
  3542. (start-of-line)
  3543. (start-of-count-line)
  3544. (last-count)
  3545. )
  3546. (save-excursion
  3547. ;; Traverse in reverse order so offsets are correct.
  3548. (while (<= 0 i)
  3549. ;; Start at last expression in line.
  3550. (goto-char (+ def-mark (aref edebug-points i)))
  3551. (beginning-of-line)
  3552. (setq start-of-line (- (point) def-mark)
  3553. last-index i)
  3554. ;; Find all indexes on same line.
  3555. (while (and (<= 0 (setq i (1- i)))
  3556. (<= start-of-line (aref edebug-points i))))
  3557. ;; Insert all the indices for this line.
  3558. (forward-line 1)
  3559. (setq start-of-count-line (point)
  3560. first-index i ; really last index for line above this one.
  3561. last-count -1) ; cause first count to always appear.
  3562. (insert ";#")
  3563. ;; i == first-index still
  3564. (while (<= (setq i (1+ i)) last-index)
  3565. (let ((count (aref counts i))
  3566. (coverage (aref coverages i))
  3567. (col (save-excursion
  3568. (goto-char (+ (aref edebug-points i) def-mark))
  3569. (- (current-column)
  3570. (if (= ?\( (following-char)) 0 1)))))
  3571. (insert (make-string
  3572. (max 0 (- col (- (point) start-of-count-line))) ?\s)
  3573. (if (and (< 0 count)
  3574. (not (memq coverage
  3575. '(unknown ok-coverage))))
  3576. "=" "")
  3577. (if (= count last-count) "" (int-to-string count))
  3578. " ")
  3579. (setq last-count count)))
  3580. (insert "\n")
  3581. (setq i first-index)))))
  3582. ;; FIXME this does not work very well. Eg if you press an arrow key,
  3583. ;; or make a mouse-click, it fails with "Non-character input-event".
  3584. (defun edebug-temp-display-freq-count ()
  3585. "Temporarily display the frequency count data for the current definition.
  3586. It is removed when you hit any char."
  3587. ;; This seems not to work with Emacs 18.59. It undoes too far.
  3588. (interactive)
  3589. (let ((buffer-read-only nil))
  3590. (undo-boundary)
  3591. (edebug-display-freq-count)
  3592. (setq unread-command-char (read-char))
  3593. ;; Yuck! This doesn't seem to work at all for me.
  3594. (undo)))
  3595. ;;; Menus
  3596. (defun edebug-toggle (variable)
  3597. (set variable (not (symbol-value variable)))
  3598. (message "%s: %s" variable (symbol-value variable)))
  3599. ;; We have to require easymenu (even for Emacs 18) just so
  3600. ;; the easy-menu-define macro call is compiled correctly.
  3601. (require 'easymenu)
  3602. (defconst edebug-mode-menus
  3603. '("Edebug"
  3604. ["Stop" edebug-stop t]
  3605. ["Step" edebug-step-mode t]
  3606. ["Next" edebug-next-mode t]
  3607. ["Trace" edebug-trace-mode t]
  3608. ["Trace Fast" edebug-Trace-fast-mode t]
  3609. ["Continue" edebug-continue-mode t]
  3610. ["Continue Fast" edebug-Continue-fast-mode t]
  3611. ["Go" edebug-go-mode t]
  3612. ["Go Nonstop" edebug-Go-nonstop-mode t]
  3613. "----"
  3614. ["Help" edebug-help t]
  3615. ["Abort" abort-recursive-edit t]
  3616. ["Quit to Top Level" top-level t]
  3617. ["Quit Nonstop" edebug-top-level-nonstop t]
  3618. "----"
  3619. ("Jumps"
  3620. ["Forward Sexp" edebug-forward-sexp t]
  3621. ["Step In" edebug-step-in t]
  3622. ["Step Out" edebug-step-out t]
  3623. ["Goto Here" edebug-goto-here t])
  3624. ("Breaks"
  3625. ["Set Breakpoint" edebug-set-breakpoint t]
  3626. ["Unset Breakpoint" edebug-unset-breakpoint t]
  3627. ["Set Conditional Breakpoint" edebug-set-conditional-breakpoint t]
  3628. ["Set Global Break Condition" edebug-set-global-break-condition t]
  3629. ["Show Next Breakpoint" edebug-next-breakpoint t])
  3630. ("Views"
  3631. ["Where am I?" edebug-where t]
  3632. ["Bounce to Current Point" edebug-bounce-point t]
  3633. ["View Outside Windows" edebug-view-outside t]
  3634. ["Previous Result" edebug-previous-result t]
  3635. ["Show Backtrace" edebug-backtrace t]
  3636. ["Display Freq Count" edebug-display-freq-count t])
  3637. ("Eval"
  3638. ["Expression" edebug-eval-expression t]
  3639. ["Last Sexp" edebug-eval-last-sexp t]
  3640. ["Visit Eval List" edebug-visit-eval-list t])
  3641. ("Options"
  3642. ["Edebug All Defs" edebug-all-defs
  3643. :style toggle :selected edebug-all-defs]
  3644. ["Edebug All Forms" edebug-all-forms
  3645. :style toggle :selected edebug-all-forms]
  3646. "----"
  3647. ["Tracing" (edebug-toggle 'edebug-trace)
  3648. :style toggle :selected edebug-trace]
  3649. ["Test Coverage" (edebug-toggle 'edebug-test-coverage)
  3650. :style toggle :selected edebug-test-coverage]
  3651. ["Save Windows" edebug-toggle-save-windows
  3652. :style toggle :selected edebug-save-windows]
  3653. ["Save Point"
  3654. (edebug-toggle 'edebug-save-displayed-buffer-points)
  3655. :style toggle :selected edebug-save-displayed-buffer-points]
  3656. ))
  3657. "Menus for Edebug.")
  3658. ;;; Emacs version specific code
  3659. (defalias 'edebug-window-live-p 'window-live-p)
  3660. (defun edebug-mark ()
  3661. (mark t))
  3662. (defun edebug-set-conditional-breakpoint (arg condition)
  3663. "Set a conditional breakpoint at nearest sexp.
  3664. The condition is evaluated in the outside context.
  3665. With prefix argument, make it a temporary breakpoint."
  3666. ;; (interactive "P\nxCondition: ")
  3667. (interactive
  3668. (list
  3669. current-prefix-arg
  3670. ;; Read condition as follows; getting previous condition is cumbersome:
  3671. (let ((edebug-stop-point (edebug-find-stop-point)))
  3672. (if edebug-stop-point
  3673. (let* ((edebug-def-name (car edebug-stop-point))
  3674. (index (cdr edebug-stop-point))
  3675. (edebug-data (get edebug-def-name 'edebug))
  3676. (edebug-breakpoints (car (cdr edebug-data)))
  3677. (edebug-break-data (assq index edebug-breakpoints))
  3678. (edebug-break-condition (car (cdr edebug-break-data)))
  3679. (initial (and edebug-break-condition
  3680. (format "%s" edebug-break-condition))))
  3681. (read-from-minibuffer
  3682. "Condition: " initial read-expression-map t
  3683. (if (equal (car read-expression-history) initial)
  3684. '(read-expression-history . 1)
  3685. 'read-expression-history)))))))
  3686. (edebug-modify-breakpoint t condition arg))
  3687. (easy-menu-define edebug-menu edebug-mode-map "Edebug menus" edebug-mode-menus)
  3688. ;;; Byte-compiler
  3689. ;; Extension for bytecomp to resolve undefined function references.
  3690. ;; Requires new byte compiler.
  3691. ;; Reenable byte compiler warnings about unread-command-char and -event.
  3692. ;; Disabled before edebug-recursive-edit.
  3693. (eval-when-compile
  3694. (if edebug-unread-command-char-warning
  3695. (put 'unread-command-char 'byte-obsolete-variable
  3696. edebug-unread-command-char-warning)))
  3697. (eval-when-compile
  3698. ;; The body of eval-when-compile seems to get evaluated with eval-defun.
  3699. ;; We only want to evaluate when actually byte compiling.
  3700. ;; But it is OK to evaluate as long as byte-compiler has been loaded.
  3701. (if (featurep 'byte-compile) (progn
  3702. (defun byte-compile-resolve-functions (funcs)
  3703. "Say it is OK for the named functions to be unresolved."
  3704. (mapc
  3705. (function
  3706. (lambda (func)
  3707. (setq byte-compile-unresolved-functions
  3708. (delq (assq func byte-compile-unresolved-functions)
  3709. byte-compile-unresolved-functions))))
  3710. funcs)
  3711. nil)
  3712. '(defun byte-compile-resolve-free-references (vars)
  3713. "Say it is OK for the named variables to be referenced."
  3714. (mapcar
  3715. (function
  3716. (lambda (var)
  3717. (setq byte-compile-free-references
  3718. (delq var byte-compile-free-references))))
  3719. vars)
  3720. nil)
  3721. '(defun byte-compile-resolve-free-assignments (vars)
  3722. "Say it is OK for the named variables to be assigned."
  3723. (mapcar
  3724. (function
  3725. (lambda (var)
  3726. (setq byte-compile-free-assignments
  3727. (delq var byte-compile-free-assignments))))
  3728. vars)
  3729. nil)
  3730. (byte-compile-resolve-functions
  3731. '(reporter-submit-bug-report
  3732. edebug-gensym ;; also in cl.el
  3733. ;; Interfaces to standard functions.
  3734. edebug-original-eval-defun
  3735. edebug-original-read
  3736. edebug-get-buffer-window
  3737. edebug-mark
  3738. edebug-mark-marker
  3739. edebug-input-pending-p
  3740. edebug-sit-for
  3741. edebug-prin1-to-string
  3742. edebug-format
  3743. ;; lemacs
  3744. zmacs-deactivate-region
  3745. popup-menu
  3746. ;; CL
  3747. cl-macroexpand-all
  3748. ;; And believe it or not, the byte compiler doesn't know about:
  3749. byte-compile-resolve-functions
  3750. ))
  3751. '(byte-compile-resolve-free-references
  3752. '(read-expression-history
  3753. read-expression-map))
  3754. '(byte-compile-resolve-free-assignments
  3755. '(read-expression-history))
  3756. )))
  3757. ;;; Autoloading of Edebug accessories
  3758. (if (featurep 'cl)
  3759. (add-hook 'edebug-setup-hook
  3760. (function (lambda () (require 'cl-specs))))
  3761. ;; The following causes cl-specs to be loaded if you load cl.el.
  3762. (add-hook 'cl-load-hook
  3763. (function (lambda () (require 'cl-specs)))))
  3764. ;; edebug-cl-read and cl-read are available from liberte@cs.uiuc.edu
  3765. (if (featurep 'cl-read)
  3766. (add-hook 'edebug-setup-hook
  3767. (function (lambda () (require 'edebug-cl-read))))
  3768. ;; The following causes edebug-cl-read to be loaded when you load cl-read.el.
  3769. (add-hook 'cl-read-load-hooks
  3770. (function (lambda () (require 'edebug-cl-read)))))
  3771. ;;; Finalize Loading
  3772. ;; Finally, hook edebug into the rest of Emacs.
  3773. ;; There are probably some other things that could go here.
  3774. ;; Install edebug read and eval functions.
  3775. (edebug-install-read-eval-functions)
  3776. (provide 'edebug)
  3777. ;;; edebug.el ends here