quack.el 195 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821
  1. ;;; quack.el --- enhanced support for editing and running Scheme code
  2. (defconst quack-copyright "Copyright (C) 2002-2012, 2016 Neil Van Dyke")
  3. (defconst quack-copyright-2 "Portions Copyright (C) Free Software Foundation")
  4. ;; Emacs-style font-lock specs adapted from GNU Emacs 21.2 scheme.el.
  5. ;; Scheme Mode menu adapted from GNU Emacs 21.2 cmuscheme.el.
  6. (defconst quack-version "0.48")
  7. (defconst quack-author-name "Neil Van Dyke")
  8. (defconst quack-author-email "neil@neilvandyke.org")
  9. (defconst quack-web-page "http://www.neilvandyke.org/quack/")
  10. (defconst quack-legal-notice
  11. "This is free software; you can redistribute it and/or modify it under the
  12. terms of the GNU General Public License as published by the Free Software
  13. Foundation; either version 2, or (at your option) any later version. This is
  14. distributed in the hope that it will be useful, but without any warranty;
  15. without even the implied warranty of merchantability or fitness for a
  16. particular purpose. See the GNU General Public License for more details. See
  17. http://www.gnu.org/licenses/ for details. For other licenses and consulting,
  18. please contact Neil Van Dyke.")
  19. (defconst quack-cvsid "$Id: quack.el,v 1.494 2012-11-16 01:01:22 user Exp $")
  20. ;;; Commentary:
  21. ;; INTRODUCTION:
  22. ;;
  23. ;; Quack enhances Emacs support for Scheme programming.
  24. ;;
  25. ;; Install Quack rather than following non-Quack-based tutorials on how to
  26. ;; set up Emacs for Scheme.
  27. ;;
  28. ;; The name "Quack" was a play on "DrScheme".
  29. ;;
  30. ;; Quack is dedicated to Yosh, naturally.
  31. ;; COMPATIBILITY:
  32. ;;
  33. ;; GNU Emacs 23 and 22 -- Yes. Quack is now developed under GNU Emacs 23
  34. ;; on a GNU/Linux system, which is the preferred platform for Quacksmokers.
  35. ;; Quack should work under GNU Emacs 23 on any Un*x-like OS. Reportedly,
  36. ;; Quack also works with GNU Emacs 22 on Apple Mac OS X and Microsoft
  37. ;; Windows (NT, 2000, XP), but the author has no means of testing on those
  38. ;; platforms.
  39. ;;
  40. ;; GNU Emacs 21 -- Probably, but no longer tested.
  41. ;;
  42. ;; GNU Emacs 20 -- Probably mostly. When last tested. Some of the menus do
  43. ;; not work properly, due to a bug in easymenu.el (which the FSF will not
  44. ;; fix, since they no longer support Emacs 20). Nested block comments are
  45. ;; not fontified correctly. Pretty-lambda does not work. Quack runs less
  46. ;; efficiently in 20 than 21, due to the lack of standard hash tables.
  47. ;;
  48. ;; XEmacs 21 -- Probably mostly, but no longer tested. Block comment
  49. ;; fontification is not yet supported under XEmacs 21, due to what appears
  50. ;; to be a bug in 21.4 font-lock. Pretty-lambda does not work. XEmacs
  51. ;; Quacksmokers who always want the latest and greatest Quack should
  52. ;; consider GNU Emacs 21 -- Quack treats XEmacs like a high-maintenance
  53. ;; redheaded stepchild.
  54. ;; INSTALLATION:
  55. ;;
  56. ;; To install, put this file (`quack.el') somewhere in your Emacs load
  57. ;; path, and add the following line to your `.emacs' file:
  58. ;;
  59. ;; (require 'quack)
  60. ;;
  61. ;; If you don't know what your Emacs load path is, try invoking the command
  62. ;; "C-h v load-path RET" or consulting the Emacs manual.
  63. ;;
  64. ;; Note to advanced Emacsers: Byte-compiled `quack.elc' files generally are
  65. ;; *not* portable between Emacs implementations, nor between different
  66. ;; versions of the same implementation.
  67. ;;
  68. ;; You will also need the GNU `wget' program, which Quack uses for
  69. ;; downloading SRFI indexes. This popular program is included in most
  70. ;; GNU/Linux distributions and is available for most other platforms.
  71. ;;
  72. ;; Note to PLT Scheme users: If you do not already have the PLT manuals
  73. ;; installed, they can be downloaded from
  74. ;; `http://download.plt-scheme.org/doc/' and installed in your PLT `doc'
  75. ;; collection. If Quack is not finding installed PLT manuals, then be sure
  76. ;; that the `quack-pltcollect-dirs' variable contains the appropriate
  77. ;; collection directory (if it does not, then either set the `PLTHOME'
  78. ;; and/or `PLTCOLLECTS' environment variables appropriately, or set
  79. ;; `quack-pltcollect-dirs').
  80. ;; KEY BINDINGS:
  81. ;;
  82. ;; The key bindings that Quack adds to `scheme-mode' include:
  83. ;;
  84. ;; C-c C-q m View a manual in your Web browser.
  85. ;; C-c C-q k View the manual documentation for a keyword
  86. ;; (currently only works for PLT manuals).
  87. ;; C-c C-q s View an SRFI.
  88. ;; C-c C-q r Run an inferior Scheme process.
  89. ;; C-c C-q f Find a file using context of point for default.
  90. ;; C-c C-q l Toggle `lambda' syntax of `define'-like form.
  91. ;; C-c C-q t Tidy the formatting of the buffer.
  92. ;;
  93. ;; One additional command that does not currently have a standard binding
  94. ;; is `quack-dired-pltcollect', which prompts for a PLT collection name and
  95. ;; creates a Dired buffer on the collection's directory. (A future version
  96. ;; of Quack may integrate this functionality into a more generalized
  97. ;; documentation navigation interface.)
  98. ;; RELEASE ANNOUNCEMENTS EMAIL:
  99. ;;
  100. ;; To receive email notification when a new Quack version is released, ask
  101. ;; neil@neilvandyke.org to add you to the moderated `scheme-announce' list.
  102. ;; HISTORY:
  103. ;;
  104. ;; Version 0.48 (2016-04-03):
  105. ;; * Made fontify `#true` and `#false`.
  106. ;;
  107. ;; Version 0.47 (2012-11-15):
  108. ;; * Added indent for `call-with-' file variants and semaphore.
  109. ;; * Added font and indent for `with-handlers*', `define-runtime-path',
  110. ;; `match-let'.
  111. ;;
  112. ;; Version 0.46 (2012-06-20):
  113. ;; * Added indent for `letrec-values'.
  114. ;; * Corrected date on history for version 0.45.
  115. ;;
  116. ;; Version 0.45 (2012-06-18):
  117. ;; * Added a bunch of indent rules for Scribble definition forms
  118. ;; and Racket sequence/iterator stuff, plus Overeasy `test-section'.
  119. ;;
  120. ;; Version 0.44 (2012-04-11):
  121. ;; * Added indent and fontify for `struct', `module+', `module*'.
  122. ;; * Changed intent for `module' from `defun' to 2.
  123. ;; * Added fontify for `define-syntax-class',
  124. ;; `define-splicing-syntax-class', `begin-for-syntax'.
  125. ;; * Changed `define-struct' fontify.
  126. ;;
  127. ;; Version 0.43 (2011-08-23):
  128. ;; * Add indent and fontify for "syntax-parse".
  129. ;; * Added another compile error regexp for Racket backtraces.
  130. ;;
  131. ;; Version 0.42 (2011-07-30):
  132. ;; * Added compile error regexp for "raco".
  133. ;;
  134. ;; Version 0.41 (2011-06-04)
  135. ;; * Added `sxml-match' to `scheme-indent-function'.
  136. ;;
  137. ;; Version 0.40 (2010-12-22)
  138. ;; * Added indent rules for Racket `let:', `let*:', and `match'. And
  139. ;; a provisional rule for `define:'.
  140. ;;
  141. ;; Version 0.39 (2010-10-18)
  142. ;; * Renamed "typed/scheme" to "typed/racket".
  143. ;;
  144. ;; Version 0.38 (2010-10-14)
  145. ;; * Replaced old PLT Scheme programs in `quack-programs' with Racket.
  146. ;; * Added Racket ".rkt" and ".rktd" filename extensions.
  147. ;; * Added some Racket keywords for fontifying.
  148. ;;
  149. ;; Version 0.37 (2009-06-29)
  150. ;; * Disabled highlighting of "Compilation started at" lines.
  151. ;;
  152. ;; Version 0.36 (2009-05-27)
  153. ;; * Made `#:' ``colon keywords'' fontify in PLT-ish mode.
  154. ;; * Added PLT `r6rs' and `typed-scheme' languages to `quack-programs'.
  155. ;;
  156. ;; Version 0.35 (2009-02-24)
  157. ;; * Added `interpreter-mode-alist' support, so Scheme scripts with "#!"
  158. ;; start in `scheme-mode'.
  159. ;; * Added PLT `parameterize-break'.
  160. ;; * Improved `compile' mode for PLT 4.x tracebacks when there is only
  161. ;; file, line, and column, but no additional information.
  162. ;;
  163. ;; Version 0.34 (2009-02-19)
  164. ;; * Added fontify and indent support for PLT `define/kw', `lambda/kw',
  165. ;; `parameterize*'.
  166. ;; * Fontify Unix "#!" cookie in PLT-ish font-lock.
  167. ;; * Changed reference to `quack-announce' email list to
  168. ;; `scheme-announce'.
  169. ;; * Added PLT `default-load-handler' to
  170. ;; `quack-compilation-error-regexp-alist-additions'
  171. ;; * Changed some face ":height" attributes.
  172. ;;
  173. ;; Version 0.33 (2008-07-31)
  174. ;; * Added handlers for some PLT 4.0.1 "setup-plt" messages.
  175. ;;
  176. ;; Version 0.32 (2008-06-19)
  177. ;; * Added to `quack-programs'.
  178. ;; * Updated compatibility comments.
  179. ;; * Added indent rule for `for/fold'.
  180. ;;
  181. ;; Version 0.31 (2008-05-03)
  182. ;; * Added `defvar' for `quack-pltish-font-lock-keywords', so that the
  183. ;; GNU Emacs 22.1 compiler doesn't complain about assignment to a free
  184. ;; variable.
  185. ;; * Changed banner regexp for MzScheme for v3.99.x.
  186. ;; * Set `dynamic-wind' `scheme-indent-function to 0, when the default
  187. ;; is 3. It was just taking up too much space. DrScheme's
  188. ;; indentation seems to be equivalent -1, so there is precedent for
  189. ;; something different. We generally respect Emacs indentation
  190. ;; convention.
  191. ;; * Added fontifying and indent for PLT `define-for-syntax',
  192. ;; `define-values-for-syntax', `quasisyntax', `quasisyntax/loc',
  193. ;; `syntax', `syntax/loc', `define-parameters'.
  194. ;; * Advise `scheme-interactively-start-process' for GNU Emacs 22.
  195. ;; * Removed TODO comment that mentioned using `(current-eventspace
  196. ;; (make-eventspace))' under `mred', as Robby Findler has indicated
  197. ;; that is not good advice.
  198. ;;
  199. ;; Version 0.30 (2007-06-27)
  200. ;; * Emacs 22 compatibility change: `string-to-number' instead of
  201. ;; `string-to-int'. Thanks to Charles Comstock.
  202. ;;
  203. ;; Version 0.29 (2006-11-12)
  204. ;; * Fixed `quack-bar-syntax-string', which caused vertical bar
  205. ;; characters to be treated as whitespace. Thanks to Eric Hanchrow
  206. ;; for reporting.
  207. ;;
  208. ;; Version 0.28 (2005-05-14)
  209. ;; * Added `quack-smart-open-paren-p'.
  210. ;; * Changed `scheme-indent-function' for `parameterize' from `defun'
  211. ;; to `1'.
  212. ;; * In `quack-pltish-keywords-to-fontify': added `quasiquote',
  213. ;; `unquote', and `unquote-splicing'.
  214. ;; * Added ".mzschemerc" to `auto-mode-alist'.
  215. ;; * Added a little extra threesemi fontification for Funcelit and
  216. ;; similar Texinfo markup formats.
  217. ;;
  218. ;; Version 0.27 (2004-12-19)
  219. ;; * For Gambit-C, added REPL banner fontifying, `quack-manuals' entry,
  220. ;; and "gsi ~~/syntax-case.scm -" `quack-programs' entry.
  221. ;; * Changed "[PLT]" prefix on PLT manuals to "PLT", to make it easier
  222. ;; to type.
  223. ;; * Minor changes to reflect "MIT Scheme" becoming "MIT/GNU Scheme".
  224. ;;
  225. ;; Version 0.26 (2004-07-14)
  226. ;; * Added fontifying of a bunch of "define-"* syntax from Chicken.
  227. ;;
  228. ;; Version 0.25 (2004-07-09)
  229. ;; * Added `define-record-type' to `quack-pltish-keywords-to-fontify'.
  230. ;; * Added "csi -hygienic" to `quack-programs'.
  231. ;; * In `quack-manuals', replaced PLT-specific `r5rs' and `t-y-scheme'
  232. ;; with generic ones.
  233. ;; * Updated URL in `quack-manuals' for 3rd ed. of `tspl'.
  234. ;; * `quack-view-manual' completions no longer include symbols.
  235. ;; * `quack-view-manual' completion default is now "R5RS".
  236. ;;
  237. ;; Version 0.24 (2004-05-09)
  238. ;; * Made `quack-pltish-keywords-to-fontify' and
  239. ;; `quack-emacs-keywords-to-fontify' custom changes update
  240. ;; immediately. Bug reported by Taylor Campbell.
  241. ;; * Removed some non-syntax names from
  242. ;; `quack-pltish-keywords-to-fontify'.
  243. ;; * Documentation changes.
  244. ;;
  245. ;; Version 0.23 (2003-11-11)
  246. ;; * `quack-local-keywords-for-remote-manuals-p' can now have the value
  247. ;; of the symbol `always', to work around a defect in some versions
  248. ;; of Microsoft Windows. Thanks to Bill Clementson.
  249. ;; * `quack-w3m-browse-url-other-window' no longer splits a `*w3m*'
  250. ;; buffer.
  251. ;; * Added indent and `quack-pltish-keywords-to-fontify' rules for
  252. ;; `c-lambda' and `c-declare'.
  253. ;;
  254. ;; Version 0.22 (2003-07-03)
  255. ;; * `quack-newline-behavior' controls the RET key behavior in Scheme
  256. ;; buffers.
  257. ;; * In `quack-manuals', added Chez Scheme, and updated Chicken.
  258. ;; * Added error message navigation to `compile' for PLT `setup-plt'.
  259. ;; * Partial fix for Quack global menu disappearing from the main menu
  260. ;; bar in XEmacs. Thought it used to work, but it doesn't in XEmacs
  261. ;; 21.4.12.
  262. ;;
  263. ;; Version 0.21 (2003-05-28)
  264. ;; * `quack-find-file' is faster in many cases due to fix to
  265. ;; `quack-backward-sexp'.
  266. ;; * Added auto-mode-alist for `.ccl', `.stk', and `.stklos' files.
  267. ;; * Indent rule additions/changes for `chicken-setup' and `unit/sig'.
  268. ;;
  269. ;; Version 0.20 (2003-05-04)
  270. ;; * Added indent and fontify for SRFI-8 "receive".
  271. ;; * Added indent and fontify for additional PLT syntax.
  272. ;; * Added `quack-fontify-threesemi-p'.
  273. ;; * `quack-tidy-buffer' sets `fill-prefix' to nil when running.
  274. ;; * Added messages to `run-scheme', if only to get rid of annoying
  275. ;; "Mark set" message.
  276. ;; * Added "mzscheme -M errortrace" to `quack-programs'.
  277. ;; * `quack-dired-pltcollect' prompt defaults to `mzlib'.
  278. ;; * "Update SRFI Index" menu item has moved to top of menu, mainly to
  279. ;; avoid usability issue in a particular Emacs menu implementation.
  280. ;; * Several code quality improvements sent by Stefan Monnier will be
  281. ;; in the next release.
  282. ;;
  283. ;; Version 0.19 (2003-03-04)
  284. ;; * Commands such as `scheme-load-file' now start a Scheme process if
  285. ;; none is found.
  286. ;; * Bugfix for using `match-string-no-properties' when we meant
  287. ;; `quack-match-string-no-properties'. (Thanks to Noel Welsh.)
  288. ;;
  289. ;; Version 0.18 (2003-05-02)
  290. ;; * Removed uses of `(regexp-opt LIST t)', since XEmacs21 does not
  291. ;; create match data. (Thanks to Garrett Mitchener for debugging.)
  292. ;; * Added to `quack-programs' and `quack-manuals'.
  293. ;; * Added pretty-case-lambda.
  294. ;; * Changed PLT documentation URL function.
  295. ;;
  296. ;; Version 0.17 (2003-01-03)
  297. ;; * Pretty-lambda is supported well under GNU Emacs 21, when using PLT
  298. ;; Style fontification. Enable via the Options menu. (Based on
  299. ;; approach by Stefan Monnier; suggested by Ray Racine.)
  300. ;; * Various faces now have separate defaults for `light' and `dark'
  301. ;; backgrounds, so may now look better on dark backgrounds.
  302. ;; (Suggested by Eli Barzilay.)
  303. ;; * `quack-find-file' now respects `insert-default-directory' when
  304. ;; there is no default file. (Thanks to Eli Barzilay.)
  305. ;; * Most of the special w3m support has been moved to a separate
  306. ;; package, `w3mnav' (`http://www.neilvandyke.org/w3mnav/').
  307. ;; `quack-w3m-browse-url-other-window' has been added.
  308. ;;
  309. ;; Version 0.16 (2002-12-16)
  310. ;; * `quack-insert-closing' now calls `blink-paren-function'. (Thanks
  311. ;; to Guillaume Marceau and Steve Elkins for reporting this.)
  312. ;; * Now uses PLT 202 manuals. Added "PLT Framework" manual.
  313. ;; * Added `quack-pltish-module-defn-face'.
  314. ;; * Added some PLTish font-lock keywords.
  315. ;;
  316. ;; Version 0.15 (2002-11-21)
  317. ;; * "Keywords" are now fontified in PLT Style fontification mode.
  318. ;; * Definition names are now blue by default in PLT Style.
  319. ;; * Symbol literals with vertical bars are now fontified in PLT Style.
  320. ;; * New `quack-manuals-webjump-sites' function for people who prefer
  321. ;; to use the `webjump' package for invoking manuals.
  322. ;; * New `quack-quiet-warnings-p' option.
  323. ;; * New `quack-pltish-class-defn-face' face.
  324. ;;
  325. ;; Version 0.14 (2002-10-18)
  326. ;; * Fix for `quack-view-manual' interactive prompting (thanks to Marko
  327. ;; Slyz for reporting this).
  328. ;; * `quack-emacsw3m-go-next' and `quack-emacsw3m-go-prev' now work
  329. ;; with GTK reference documentation (not that this has anything to do
  330. ;; with Scheme).
  331. ;; * Added SLIB to `quack-manuals'.
  332. ;; * Added comment about installing PLT manuals (thanks to Marko).
  333. ;; * We now call the canonical version of Emacs "GNU Emacs," instead of
  334. ;; "FSF Emacs".
  335. ;;
  336. ;; Version 0.13 (2002-09-21)
  337. ;; * Bugfix: No longer drop SRFI index entries on the floor.
  338. ;;
  339. ;; Version 0.12 (2002-09-20)
  340. ;; * New "View SRFI" menu. Select "Update SRFI Index" if the submenus
  341. ;; "Draft", "Final", and "Withdrawn" are disabled.
  342. ;; * Most options are now settable via "Options" menu.
  343. ;; * PLT collections are no longer scanned when building "View Manuals"
  344. ;; menu.
  345. ;; * "View Keyword Docs..." back on Scheme Mode menu in addition to
  346. ;; Quack menu.
  347. ;; * Various `defcustom' variables have been made to dynamically update
  348. ;; relevant program state when changed.
  349. ;; * Under GNU Emacs 20, dynamic menus still do not work -- they now
  350. ;; display, but do not perform the selected action. Will do more
  351. ;; debugging after this release.
  352. ;; * '[' and ']' keys work in emacs-w3m of MIT Scheme manuals.
  353. ;;
  354. ;; Version 0.11 (2002-09-17)
  355. ;; * Menus now work under XEmacs. Also now partly broken for Emacs 20.
  356. ;; * New global "Quack" menu. Disable with `quack-global-menu-p'.
  357. ;; * New "View Manual" submenu under GNU Emacs 21 and XEmacs (GNU Emacs
  358. ;; 20 is stuck with the old "View Manual..." menu item).
  359. ;; * Fix for `quack-pltcollects-alist' to include PLT `doc' collection,
  360. ;; which was preventing local manuals from being used.
  361. ;; * `quack-manuals' now includes `t-y-scheme'.
  362. ;; * `quack-view-in-different-browser' command that spawns alternative
  363. ;; Web browser from the special emacs-w3m support, bound to `B'. For
  364. ;; when you normally view manuals in an Emacs window, but
  365. ;; occasionally want to view a particular page in normal Web browser.
  366. ;; * More `scheme-indent-function' properties set.
  367. ;; * `quack-about' command.
  368. ;; * Fix to `quack-keyword-at-point'.
  369. ;;
  370. ;; Version 0.10 (2002-09-11)
  371. ;; * `quack-view-srfi' now prompts with completion, including titles
  372. ;; for all SRFIs. The SRFI titles are fetched from the official SRFI
  373. ;; Web site using the GNU Wget program, and cached locally.
  374. ;; * `quack-view-srfi' also now defaults to the SRFI number at or near
  375. ;; the point.
  376. ;; * `quack-dir' variable specifies a directory where Quack should
  377. ;; store its persistent data files (e.g., cached SRFI indexes), and
  378. ;; defaults to "~/.quack/".
  379. ;; * New `quack-tidy-buffer' command. [C-c C-q t] is now bound to
  380. ;; this; [C-c C-q l] ("l" as in "lambda) is now the official binding
  381. ;; for `quack-toggle-lambda'.
  382. ;; * `quack-find-file' now recognizes PLT `dynamic-require' form.
  383. ;; * Fix to make `quack-looking-at-backward' preserve match data.
  384. ;; * Fix for benign bug in `quack-parent-sexp-search'.
  385. ;;
  386. ;; Version 0.9 (2002-09-04)
  387. ;; * Quack now works under XEmacs 21, except no menus are currently
  388. ;; defined (that will come in a later version) and block comments
  389. ;; aren't fontified.
  390. ;; * `quack-toggle-lambda' command toggles a `define' form between
  391. ;; explicit and implicit `lambda' syntax.
  392. ;; * `quack-dired-pltcollect' feature prompts for a PLT collection name
  393. ;; and creates a Dired on the collection.
  394. ;; * `)' and `]' keys are bound to insert a closing character that
  395. ;; agrees with the opening character of the sexp.
  396. ;; * Nested `#|' comment blocks are now fontified mostly correctly
  397. ;; under GNU Emacs 21.
  398. ;; * Fix to `quack-parent-sexp-search'.
  399. ;; * Fix for PLT manual keywords lookup under Emacs 20.
  400. ;; * `quack-manuals' URLs for assorted implementation manuals now point
  401. ;; to canonical Web copies.
  402. ;; * No longer warns about PLT manual keywords file found without HTML.
  403. ;; * `find-file' key bindings are automatically remapped to
  404. ;; `quack-find-file' in Scheme buffers.
  405. ;; * Both PLT-style and Emacs-style fontification now work with the
  406. ;; `noweb-mode' package. Tested under GNU Emacs 21 with
  407. ;; Debian `nowebm' package version 2.10c-1.
  408. ;; * Added to `quack-emacsish-keywords-to-fontify'.
  409. ;; * Disabled fontification of named `let'.
  410. ;; * Renamed "collect" in PLT identifiers to "pltcollect".
  411. ;; * `auto-mode-alist' set more aggressively.
  412. ;;
  413. ;; Version 0.8 (2002-08-25)
  414. ;; * PLT package file viewing mode. This is mainly used to easily
  415. ;; inspect a ".plt" package before installing it via DrScheme or
  416. ;; "setup-plt".
  417. ;; * No longer warns about `font-lock-keywords' when `noweb-mode'
  418. ;; package is installed.
  419. ;;
  420. ;; Version 0.7 (2002-08-22)
  421. ;; * Now works on GNU Emacs 20 (though people are still encouraged to
  422. ;; upgrade to GNU Emacs 21 if they are able).
  423. ;; * `quack-manuals' now includes MIT Scheme and Chicken manuals
  424. ;; (currently where Debian GNU/Linux puts them).
  425. ;; * `quack-view-srfi' command.
  426. ;; * Named-`let' name is fontified like a PLTish definition name.
  427. ;; * `define-record' and `define-opt' fontified.
  428. ;; * Scheme Mode is forced in `auto-mode-alist' for ".sch" files.
  429. ;; * Fix to `quack-backward-sexp'.
  430. ;; * `quack-warning' messages get your attention.
  431. ;; * `quack-pltrequire-at-point-data-1' search depth limited.
  432. ;;
  433. ;; Version 0.6 (2002-08-20)
  434. ;; * `quack-find-file' now supports multi-line PLT `require' forms.
  435. ;; * When `emacs-w3m' is used, the keys "[", "]", and "t" are bound to
  436. ;; navigate through PLT manuals like in Info mode.
  437. ;; * Names highlighted in PLT-style fontification of `defmacro',
  438. ;; `defmacro-public', `defsyntax'.
  439. ;; * Advised `run-scheme' no longer prompts when there is already a
  440. ;; running Scheme.
  441. ;; * "csi" (Chicken interpreter) added to `quack-programs' default.
  442. ;; * Forces `auto-mode-alist' for ".scm" files to `scheme-mode'
  443. ;; (two can play at that game, `bee-mode'!).
  444. ;; * To-do comments moved from the top of the file to throughout code.
  445. ;;
  446. ;; Version 0.5 (2002-08-15)
  447. ;; * New `quack-find-file' permits quick navigation to files indicated
  448. ;; by a PLT Scheme `require' form under the point. Currently only
  449. ;; works when the "(require" string is on the same line as point.
  450. ;; * Improved PLT-style fontification. Most noticeable difference is
  451. ;; that names in many definition forms are boldfaced. See
  452. ;; `quack-pltish-fontify-definition-names-p' option.
  453. ;; * `quack-collects-alist' added.
  454. ;; * "~/plt/" has been removed from `quack-collect-dirs' default.
  455. ;; * Unnecessary syntax table settings have been removed.
  456. ;; * Reduced memory usage in some cases, via explicit GC calls.
  457. ;;
  458. ;; Version 0.4 (2002-08-07)
  459. ;; * Functionality adapted from author's `giguile.el' package:
  460. ;; - Enhanced `run-scheme' behavior. `quack-run-mzscheme',
  461. ;; `quack-run-mred', and `quack-remove-run-scheme-menu-item-p'
  462. ;; are obsolete.
  463. ;; - Enhanced `switch-to-scheme' behavior.
  464. ;; - Options menu.
  465. ;; - Indent rules for a few Guile-isms.
  466. ;; * Inferior Scheme Mode now uses the preferred fontification method.
  467. ;; * Now uses the PLT-bundled version of R5RS manual, which permits
  468. ;; keyword searching.
  469. ;; * `quack-banner-face' for the MzScheme/MrEd banner in REPL buffer.
  470. ;; * This code includes a start on toolbars and XEmacs21 portability,
  471. ;; but neither feature is yet functional.
  472. ;;
  473. ;; Version 0.3 (2002-08-01)
  474. ;; * PLT-style fontification added, except for quoted lists. Emacs-
  475. ;; style fontification still available; see `quack-fontify-style'.
  476. ;; * `emacs-w3m' package support for lightweight viewing of PLT manuals
  477. ;; in Emacs window. If you install the `emacs-w3m' package, then you
  478. ;; can change the new `quack-browse-url-browser-function' option to
  479. ;; use it.
  480. ;; * Quack menu items added to Scheme Mode menu. "Run Scheme" item
  481. ;; is removed by default; see `quack-remove-run-scheme-menu-item-p'.
  482. ;; * MrEd REPL supported with `quack-run-mred'.
  483. ;; * Better default for `quack-collect-dirs'.
  484. ;; * More `scheme-indent-function' settings.
  485. ;; * Bugfix for `quack-prompt-for-kwmatch-choice'.
  486. ;; * Bugfix for font-lock keywords getting set too early.
  487. ;; * Now byte-compiles without warnings/errors.
  488. ;;
  489. ;; Version 0.2 (2002-07-28)
  490. ;; * Manual keywords lookup.
  491. ;; * Other minor changes.
  492. ;;
  493. ;; Version 0.1 (2002-07-18)
  494. ;; * Initial release.
  495. ;; ADMONISHMENT TO IMPRESSIONABLE YOUNG SCHEME STUDENTS:
  496. ;;
  497. ;; Quack should by no means be construed as a model of good programming,
  498. ;; much less of good software engineering. Emacs is by nature a complex
  499. ;; system of interacting kludges. To get Emacs to do useful new things is
  500. ;; to artfully weave one's extensions into a rich tapestry of sticky duct
  501. ;; tape. Also, Quack usually only got hacked on when I was stuck in a busy
  502. ;; lobby for an hour with a laptop and unable to do real work.
  503. ;;; Code:
  504. ;; Dependencies:
  505. (require 'advice)
  506. (require 'cmuscheme)
  507. (require 'compile)
  508. (require 'custom)
  509. (require 'easymenu)
  510. (require 'font-lock)
  511. (require 'scheme)
  512. (require 'thingatpt)
  513. (unless (fboundp 'customize-save-variable)
  514. (autoload 'customize-save-variable "cus-edit"))
  515. ;; Custom Variables:
  516. (defgroup quack nil
  517. "Enhanced support for editing and running Scheme code."
  518. :group 'scheme
  519. :prefix "quack-"
  520. :link '(url-link "http://www.neilvandyke.org/quack/"))
  521. (defcustom quack-dir "~/.quack"
  522. "*Directory where Quack stores various persistent data in file format."
  523. :type 'string
  524. :group 'quack)
  525. (defcustom quack-scheme-mode-keymap-prefix "\C-c\C-q"
  526. "*Keymap prefix string for `quack-scheme-mode-keymap'.
  527. One of the nice things about having C-q in the prefix is that it is unlikely to
  528. be already be in use, due to the historical reality of software flow control
  529. \(and the fact that it is hard to type). If your C-q doesn't seem to be going
  530. through, then you have several options: disable flow control (if it is safe to
  531. do so), change the value of this variable, or see the Emacs documentation for
  532. `enable-flow-control-on'."
  533. :type 'string
  534. :group 'quack)
  535. (defcustom quack-remap-find-file-bindings-p t
  536. "Whether to remap `find-file' key bindings to `quack-find-file'.
  537. The local map in Scheme Mode and Inferior Scheme Mode buffers is used."
  538. :type 'boolean
  539. :group 'quack)
  540. (defcustom quack-global-menu-p t
  541. "*Whether to have a \"Quack\" menu always on the menu bar."
  542. :type 'boolean :group 'quack)
  543. (defcustom quack-tabs-are-evil-p t
  544. "*Whether Quack should avoid use of Tab characters in indentation."
  545. :type 'boolean
  546. :group 'quack)
  547. (defcustom quack-browse-url-browser-function nil
  548. "*Optional override for `browse-url-browser-function'.
  549. If non-nil, overrides that variable for URLs viewed by `quack-browse-url'."
  550. :type '(choice (const :tag "Do Not Override" nil)
  551. (function :tag "Function")
  552. (alist :tag "Regexp/Function Association List"
  553. :key-type regexp :value-type function))
  554. :group 'quack)
  555. (defcustom quack-manuals ; TODO: Options menu.
  556. ;; TODO: If we make this so users are likely to want to override parts of it,
  557. ;; then introduce `quack-manuals-defaults' variable with this in it,
  558. ;; and let users edit `quack-manuals-overrides' which are keyed on the
  559. ;; ID symbol.
  560. ;; TODO: Have a way for finding docs on the local filesystem, and/or
  561. ;; permitting a user to easily specify location.
  562. ;; TODO: Provide a way of specifying alternative access means so that, for
  563. ;; example, we can look for R5RS first in locally-installed PLT
  564. ;; collection, then in one of various non-PLT directories it might be
  565. ;; mirrored, then remote PLT copy using local PLT keywords file, then
  566. ;; the canonical HTML copy on the Web... Maybe even permit Info
  567. ;; format. Let's just reinvent the Web, while we're at it.
  568. '(
  569. (r5rs "R5RS"
  570. "http://www.schemers.org/Documents/Standards/R5RS/HTML/"
  571. nil)
  572. (bigloo
  573. "Bigloo"
  574. "http://www-sop.inria.fr/mimosa/fp/Bigloo/doc/bigloo.html"
  575. ;;"file:///usr/share/doc/bigloo/manuals/bigloo.html"
  576. nil)
  577. (chez
  578. "Chez Scheme User's Guide"
  579. "http://www.scheme.com/csug/index.html"
  580. nil)
  581. (chicken
  582. "Chicken User's Manual"
  583. "http://www.call-with-current-continuation.org/manual/manual.html"
  584. ;;"file:///usr/share/doc/chicken/manual.html"
  585. nil)
  586. (gambit
  587. "Gambit-C home page"
  588. "http://www.iro.umontreal.ca/~gambit/")
  589. (gauche
  590. "Gauche Reference Manual"
  591. "http://www.shiro.dreamhost.com/scheme/gauche/man/gauche-refe.html"
  592. nil)
  593. (mitgnu-ref
  594. "MIT/GNU Scheme Reference"
  595. "http://www.gnu.org/software/mit-scheme/documentation/scheme.html"
  596. ;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/scheme.html"
  597. ;;"file:///usr/share/doc/mit-scheme/html/scheme.html"
  598. nil)
  599. (mitgnu-user
  600. "MIT/GNU Scheme User's Manual"
  601. "http://www.gnu.org/software/mit-scheme/documentation/user.html"
  602. ;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/user.html"
  603. ;;"file:///usr/share/doc/mit-scheme/html/user.html"
  604. nil)
  605. (mitgnu-sos
  606. "MIT/GNU Scheme SOS Reference Manual"
  607. "http://www.gnu.org/software/mit-scheme/documentation/sos.html"
  608. ;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/sos.html"
  609. ;;"file:///usr/share/doc/mit-scheme/html/sos.html"
  610. nil)
  611. (plt-mzscheme "PLT MzScheme: Language Manual" plt t)
  612. (plt-mzlib "PLT MzLib: Libraries Manual" plt t)
  613. (plt-mred "PLT MrEd: Graphical Toolbox Manual" plt t)
  614. (plt-framework "PLT Framework: GUI Application Framework" plt t)
  615. (plt-drscheme "PLT DrScheme: Programming Environment Manual" plt nil)
  616. (plt-insidemz "PLT Inside PLT MzScheme" plt nil)
  617. (plt-tools "PLT Tools: DrScheme Extension Manual" plt nil)
  618. (plt-mzc "PLT mzc: MzScheme Compiler Manual" plt t)
  619. (plt-r5rs "PLT R5RS" plt t)
  620. (scsh
  621. "Scsh Reference Manual"
  622. "http://www.scsh.net/docu/html/man-Z-H-1.html"
  623. ;;"file:///usr/share/doc/scsh-doc/scsh-manual/man-Z-H-1.html"
  624. nil)
  625. (sisc
  626. "SISC for Seasoned Schemers"
  627. "http://sisc.sourceforge.net/manual/html/"
  628. nil)
  629. (htdp "How to Design Programs"
  630. "http://www.htdp.org/"
  631. nil)
  632. (htus "How to Use Scheme"
  633. "http://www.htus.org/"
  634. nil)
  635. (t-y-scheme "Teach Yourself Scheme in Fixnum Days"
  636. "http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html"
  637. nil)
  638. (tspl "Scheme Programming Language (Dybvig)"
  639. "http://www.scheme.com/tspl/"
  640. nil)
  641. (sicp "Structure and Interpretation of Computer Programs"
  642. "http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html"
  643. nil)
  644. (slib "SLIB"
  645. "http://swissnet.ai.mit.edu/~jaffer/SLIB.html"
  646. nil)
  647. (faq "Scheme Frequently Asked Questions"
  648. "http://www.schemers.org/Documents/FAQ/"
  649. nil))
  650. "*List of specifications of manuals that can be viewed.
  651. Each manual specification is a list of four elements:
  652. (SYMBOL TITLE LOCATION USE-KEYWORDS-P)
  653. where SYMBOL is a short symbol that identifies the manual, TITLE is a string,
  654. LOCATION is either a string with the URL of the manual or the symbol `plt',
  655. and USE-KEYWORDS-P is `t' or `nil'.
  656. If LOCATION is `plt', then Quack treats it as a PLT bundled manual, looking for
  657. the HTML and keyword files in `quack-pltcollect-dirs', and optionally providing
  658. keyword lookup if USE-KEYWORDS-P is `t'. Remote canonical copies of the
  659. manuals will be used if local copies cannot be found.
  660. If LOCATION is a URL, then USE-KEYWORDS-P must be `nil'."
  661. :type '(repeat (list (symbol :tag "Identifying Symbol")
  662. (string :tag "Title String")
  663. (choice :tag "Location"
  664. (string :tag "URL")
  665. (const :tag "PLT Bundled Manual" plt))
  666. (boolean :tag "Use Keywords?")))
  667. :group 'quack)
  668. (defcustom quack-local-keywords-for-remote-manuals-p t
  669. "*If non-nil, Quack will use canonical remote Web URLs when there is a local
  670. keyword file for a PLT manual but no local HTML files. (This feature was
  671. prompted by the Debian 200.2-3 package for MzScheme, which includes keyword
  672. files but not HTML files.) If the symbol `always', then Quack will always use
  673. remote Web manuals for keywords lookup, even if local HTML files exist, as a
  674. workaround for how some versions of Emacs interact with some versions of
  675. Microsoft Windows \(inexplicably discarding the fragment identifier from `file'
  676. scheme URI\)."
  677. :type '(choice (const :tag "Permit" t)
  678. (const :tag "Forbid" nil)
  679. (const :tag "Always" always))
  680. :group 'quack
  681. :set 'quack-custom-set
  682. :initialize 'custom-initialize-default)
  683. (defcustom quack-srfi-master-base-url "http://srfi.schemers.org/"
  684. ;; Note: Intentionally not letting user change this through the options menu.
  685. "*The base URL for the master SRFI Web pages.
  686. The SRFI index files should be immediately beneath this."
  687. :type 'string
  688. :group 'quack)
  689. (defcustom quack-pltcollect-dirs
  690. (let ((good '()))
  691. (mapcar (function (lambda (dir)
  692. (and dir
  693. (not (assoc dir good))
  694. (file-directory-p dir)
  695. (setq good (nconc good (list dir))))))
  696. `(,@(let ((v (getenv "PLTCOLLECTS")))
  697. (and v (split-string v ":")))
  698. ,(let ((v (getenv "PLTHOME")))
  699. (and v (expand-file-name "collects" v)))
  700. ,@(mapcar 'expand-file-name
  701. '("/usr/lib/plt/collects"
  702. "/usr/local/lib/plt/collects"))))
  703. good)
  704. "*PLT collection directories.
  705. Listed in order of priority."
  706. :type '(repeat directory)
  707. :group 'quack
  708. :set 'quack-custom-set
  709. :initialize 'custom-initialize-default)
  710. (defcustom quack-fontify-style 'plt
  711. "*Which font-lock fontification style to use.
  712. If symbol `plt', an approximation of PLT DrScheme 200 Check Syntax
  713. fontification will be used. If symbol `emacs', then fontification in the style
  714. of GNU Emacs' Scheme Mode with extensions will be used. If nil, then Quack
  715. will not override the default Scheme Mode fontification."
  716. :type '(choice (const :tag "PLT Style" plt)
  717. (const :tag "Extended GNU Emacs Style" emacs)
  718. (const :tag "Emacs Default" nil))
  719. :group 'quack
  720. :set 'quack-custom-set
  721. :initialize 'custom-initialize-default)
  722. (defcustom quack-pltish-fontify-definition-names-p t
  723. "*If non-nil, fontify names in definition forms for PLT-style fontification.
  724. This only has effect when `quack-fontify-style' is `plt'."
  725. :type 'boolean
  726. :group 'quack
  727. :set 'quack-custom-set
  728. :initialize 'custom-initialize-default)
  729. (defcustom quack-pltish-fontify-keywords-p t
  730. ;; TODO: Rename this from "keywords" to "syntax-keywords", here, and in for
  731. ;; face names.
  732. "*If non-nil, fontify keywords in PLT-style fontification.
  733. This only has effect when `quack-fontify-style' is `plt'."
  734. :type 'boolean
  735. :group 'quack
  736. :set 'quack-custom-set
  737. :initialize 'custom-initialize-default)
  738. (defcustom quack-pltish-keywords-to-fontify
  739. ;; TODO: These are currently R5RS and some SRFI special syntax plus a bunch
  740. ;; of PLT, especially PLT 200 class.ss, and some "define-"* variants from
  741. ;; various dialects, plus some Racket 5.0.2... The dumbness of this kind of
  742. ;; highlighting without regard to context is not really satisfactory.
  743. '(
  744. "and" "begin" "begin-for-syntax"
  745. "begin0" "c-declare" "c-lambda" "case" "case-lambda" "class"
  746. "class*" "class*/names" "class100" "class100*" "compound-unit/sig" "cond"
  747. "cond-expand" "define" "define-class" "define-compound-unit"
  748. "define-const-structure"
  749. "define-constant" "define-embedded" "define-entry-point" "define-external"
  750. "define-for-syntax" "define-foreign-record" "define-foreign-type"
  751. "define-foreign-variable" "define-generic" "define-generic-procedure"
  752. "define-inline" "define-location" "define-macro" "define-method"
  753. "define-module" "define-opt" "define-public" "define-reader-ctor"
  754. "define-record" "define-record-printer" "define-record-type"
  755. "define-runtime-path"
  756. "define-signature"
  757. "define-splicing-syntax-class"
  758. "define-struct"
  759. "define-structure"
  760. "define-syntax"
  761. "define-syntax-class"
  762. "define-syntax-set" "define-values" "define-values-for-syntax"
  763. "define-values/invoke-unit/infer"
  764. "define-values/invoke-unit/sig" "define/contract" "define/override"
  765. "define/private" "define/public" "define/kw"
  766. "delay" "do" "doc" "else" "exit-handler" "field"
  767. "if" "import" "inherit" "inherit-field" "init" "init-field" "init-rest"
  768. "instantiate" "interface" "lambda" "lambda/kw" "let" "let*" "let*-values"
  769. "let+"
  770. "let-syntax" "let-values" "let/ec" "letrec" "letrec-values" "letrec-syntax"
  771. "match-lambda" "match-lambda*" "match-let" "match-let*" "match-letrec"
  772. "match-define" "mixin" "module" "module*" "module+" "opt-lambda" "or" "override" "override*"
  773. "namespace-variable-bind/invoke-unit/sig" "parameterize" "parameterize*"
  774. "parameterize-break" "private"
  775. "private*" "protect" "provide" "provide-signature-elements"
  776. "provide/contract" "public" "public*" "quasiquote"
  777. "quasisyntax" "quasisyntax/loc" "quote" "receive"
  778. "rename" "require" "require-for-syntax" "send" "send*" "set!" "set!-values"
  779. "signature->symbols" "super-instantiate" "syntax" "syntax/loc"
  780. "syntax-case" "syntax-case*" "syntax-error" "syntax-parse" "syntax-rules"
  781. "unit/sig"
  782. "unless" "unquote" "unquote-splicing" "when" "with-handlers" "with-handlers*" "with-method"
  783. "with-syntax"
  784. "define-type-alias"
  785. "define-struct:"
  786. "define:"
  787. "let:"
  788. "letrec:"
  789. "let*:"
  790. "lambda:"
  791. "match-let"
  792. "plambda:"
  793. "case-lambda:"
  794. "pcase-lambda:"
  795. "require/typed"
  796. "require/opaque-type"
  797. "require-typed-struct"
  798. "struct"
  799. "inst"
  800. "ann"
  801. )
  802. "*Scheme keywords to fontify when `quack-fontify-style' is `plt'."
  803. :type '(repeat string)
  804. :group 'quack
  805. :set 'quack-custom-set
  806. :initialize 'custom-initialize-default)
  807. (defcustom quack-emacsish-keywords-to-fontify
  808. '("and" "begin" "begin0" "call-with-current-continuation"
  809. "call-with-input-file" "call-with-output-file" "call/cc" "case"
  810. "case-lambda" "class" "cond" "delay" "do" "else" "exit-handler" "field"
  811. "for-each" "if" "import" "inherit" "init-field" "interface" "lambda" "let"
  812. "let*" "let*-values" "let-values" "let-syntax" "let/ec" "letrec"
  813. "letrec-syntax" "map" "mixin" "opt-lambda" "or" "override" "protect"
  814. "provide" "public" "rename" "require" "require-for-syntax" "syntax"
  815. "syntax-case" "syntax-error" "syntax-rules" "unit/sig" "unless" "when"
  816. "with-syntax")
  817. "*Scheme keywords to fontify when `quack-fontify-style' is `emacs'."
  818. :type '(repeat string)
  819. :group 'quack
  820. :set 'quack-custom-set
  821. :initialize 'custom-initialize-default)
  822. (defcustom quack-fontify-threesemi-p t
  823. "*Whether three-semicolon comments should be fontified differently."
  824. :type 'boolean
  825. :group 'quack
  826. :set 'quack-custom-set
  827. :initialize 'custom-initialize-default)
  828. (defcustom quack-pretty-lambda-p nil
  829. "*Whether Quack should display \"lambda\" as the lambda character.
  830. `quack-fontify-style' must be `plt'. Only supported under GNU Emacs version
  831. 21\; not under XEmacs or older GNU Emacs.
  832. Note: Pretty lambda requires that suitable iso8859-7 fonts be available. Under
  833. Debian/GNU Linux, for example, these can be downloaded and installed with the
  834. shell command \"apt-get install 'xfonts-greek-*'\". If iso8859-7 fonts are
  835. unavailable for your system, please notify the Quack author."
  836. :type 'boolean
  837. :group 'quack
  838. :set 'quack-custom-set
  839. :initialize 'custom-initialize-default)
  840. (defcustom quack-programs
  841. '("bigloo" "csi" "csi -hygienic" "gosh" "gracket" "gsi"
  842. "gsi ~~/syntax-case.scm -" "guile" "kawa" "mit-scheme" "racket"
  843. "racket -il typed/racket" "rs" "scheme" "scheme48" "scsh" "sisc" "stklos"
  844. "sxi")
  845. "List of Scheme interpreter programs that can be used with `run-scheme'.
  846. These names will be accessible via completion when `run-scheme' prompts for
  847. which program to run."
  848. :group 'quack
  849. :type '(repeat string)
  850. :set 'quack-custom-set
  851. :initialize 'custom-initialize-default)
  852. (defcustom quack-default-program "mzscheme"
  853. "Default Scheme interpreter program to use with `run-scheme'."
  854. :group 'quack
  855. :type 'string)
  856. (defcustom quack-run-scheme-always-prompts-p t
  857. "`run-scheme' should always prompt for which program to run.
  858. If nil, `run-scheme' will always use `quack-default-program' when invoked
  859. interactively without a prefix argument; this is closest to the behavior of the
  860. `cmuscheme' package."
  861. :group 'quack
  862. :type 'boolean)
  863. (defcustom quack-run-scheme-prompt-defaults-to-last-p t
  864. "If non-nil, `run-scheme' prompt should default to the last program run."
  865. :group 'quack
  866. :type 'boolean)
  867. (defcustom quack-remember-new-programs-p t
  868. "Programs are added to `quack-programs' automatically."
  869. :group 'gigule
  870. :type 'boolean)
  871. (defcustom quack-switch-to-scheme-method 'other-window
  872. "Method to use for choosing a window and frame for the process buffer.
  873. One of three symbols:
  874. `other-window' will split display in a different window in the current frame,
  875. splitting the current window if necessary.
  876. `own-frame' will display the process buffer in its own frame.
  877. `cmuscheme' will use the normal behavior of the `cmuscheme' package."
  878. :group 'quack
  879. :type '(choice (const :tag "Other Window" other-window)
  880. (const :tag "Own Frame" own-frame)
  881. (const :tag "Cmuscheme Behavior" cmuscheme)))
  882. (defcustom quack-warp-pointer-to-frame-p t
  883. "Warp mouse pointer to frame with Scheme process buffer.
  884. When `quack-switch-to-scheme-method' is `own-frame', `switch-to-scheme' will
  885. warp the mouse pointer to the frame displaying the Scheme process buffer."
  886. :group 'quack
  887. :type 'boolean)
  888. (defcustom quack-newline-behavior 'newline-indent
  889. "*Behavior of the RET key in Scheme-Mode buffers. The value is one of three
  890. symbols: `newline' inserts a normal newline, `newline-indent' \(the default\)
  891. inserts a newline and leaves the point properly indented on the new line, and
  892. `indent-newline-indent' indents the current line before inserting a newline and
  893. indenting the new one."
  894. :type '(choice (const 'newline)
  895. (const 'newline-indent)
  896. (const 'indent-newline-indent))
  897. :group 'quack)
  898. (defcustom quack-smart-open-paren-p nil
  899. "The `[' can be used to insert `(' characters.
  900. Actually, this just makes the `(' and '[' keys both insert `(', unless given a
  901. prefix argument. This makes typing parens easier on typical keyboards for
  902. which `(' requires a shift modifier but `[' does not. A later version of Quack
  903. might add actual \"smart\" support for automatic PLT-esque insertion of `['
  904. instead of `(' in some syntactic contexts."
  905. :group 'quack
  906. :type 'boolean)
  907. (defcustom quack-options-persist-p t
  908. "Option menu settings and programs persist using the `custom' facility.
  909. Note that the value of this option itself cannot be set persistently via the
  910. option menu -- you must use the `customize' interface or set it manually in an
  911. Emacs startup file. This is by design, to avoid the risk of users accidentally
  912. disabling their ability to set persistent options via the option menu."
  913. :group 'quack
  914. :type 'boolean)
  915. (defcustom quack-quiet-warnings-p t ; TODO: Options menu.
  916. "Warning messages are quiet and subtle."
  917. :group 'quack
  918. :type 'boolean)
  919. (defconst quack-pltish-comment-face 'quack-pltish-comment-face)
  920. (defface quack-pltish-comment-face
  921. '((((class color) (background light)) (:foreground "cyan4"))
  922. (((class color) (background dark)) (:foreground "cyan1"))
  923. (t (:slant italic)))
  924. "Face used for comments when `quack-fontify-style' is `plt'."
  925. :group 'quack)
  926. (defconst quack-pltish-selfeval-face 'quack-pltish-selfeval-face)
  927. (defface quack-pltish-selfeval-face
  928. '((((class color) (background light)) (:foreground "green4"))
  929. (((class color) (background dark)) (:foreground "green2"))
  930. (t ()))
  931. "Face used for self-evaluating forms when `quack-fontify-style' is `plt'."
  932. :group 'quack)
  933. (defconst quack-pltish-paren-face 'quack-pltish-paren-face)
  934. (defface quack-pltish-paren-face
  935. '((((class color) (background light)) (:foreground "red3"))
  936. (((class color) (background dark)) (:foreground "red1"))
  937. (((class grayscale)) (:foreground "gray"))
  938. (t ()))
  939. "Face used for parentheses when `quack-fontify-style' is `plt'."
  940. :group 'quack)
  941. (defconst quack-pltish-colon-keyword-face 'quack-pltish-colon-keyword-face)
  942. (defface quack-pltish-colon-keyword-face
  943. '((t (:bold t :foreground "gray50")))
  944. "Face used for `#:' keywords when `quack-fontify-style' is `plt'.
  945. Note that this isn't based on anything in PLT."
  946. :group 'quack)
  947. (defconst quack-pltish-paren-face 'quack-pltish-paren-face)
  948. (defface quack-pltish-paren-face
  949. '((((class color) (background light)) (:foreground "red3"))
  950. (((class color) (background dark)) (:foreground "red1"))
  951. (((class grayscale)) (:foreground "gray"))
  952. (t ()))
  953. "Face used for parentheses when `quack-fontify-style' is `plt'."
  954. :group 'quack)
  955. (defconst quack-banner-face 'quack-banner-face)
  956. (defface quack-banner-face
  957. '((t (:family "Helvetica")))
  958. "Face used in the inferior process buffer for the MzScheme banner.
  959. Currently only takes effect when `quack-fontify-style' is `plt'."
  960. :group 'quack)
  961. (defconst quack-pltish-defn-face 'quack-pltish-defn-face)
  962. (defface quack-pltish-defn-face
  963. '((((class color) (background light)) (:bold t :foreground "blue3"))
  964. (((class color) (background dark)) (:bold t :foreground "blue1"))
  965. (t (:bold t :underline t)))
  966. "Face used for names in toplevel definitions.
  967. For PLT-style when `quack-pltish-fontify-definition-names-p' is non-nil."
  968. :group 'quack)
  969. (defconst quack-pltish-class-defn-face 'quack-pltish-class-defn-face)
  970. (defface quack-pltish-class-defn-face
  971. '((((class color) (background light))
  972. (:foreground "purple3" :inherit quack-pltish-defn-face))
  973. (((class color) (background dark))
  974. (:foreground "purple1" :inherit quack-pltish-defn-face))
  975. (t (:inherit quack-pltish-defn-face)))
  976. "Face used for class names in toplevel definitions.
  977. For PLT-style when `quack-pltish-fontify-definition-names-p' is non-nil."
  978. :group 'quack)
  979. (defconst quack-pltish-module-defn-face 'quack-pltish-module-defn-face)
  980. (defface quack-pltish-module-defn-face
  981. '((((class color) (background light))
  982. (:foreground "purple3" :inherit quack-pltish-defn-face))
  983. (((class color) (background dark))
  984. (:foreground "purple1" :inherit quack-pltish-defn-face))
  985. (t (:inherit quack-pltish-defn-face)))
  986. "Face used for module names in toplevel definitions.
  987. For PLT-style when `quack-pltish-fontify-definition-names-p' is non-nil."
  988. :group 'quack)
  989. (defconst quack-pltish-keyword-face 'quack-pltish-keyword-face)
  990. (defface quack-pltish-keyword-face
  991. '((t (:bold t)))
  992. "Face used for keywords in PLT Style fontification.
  993. For PLT-style when `quack-pltish-fontify-keywords-p' is non-nil."
  994. :group 'quack)
  995. (defconst quack-threesemi-semi-face 'quack-threesemi-semi-face)
  996. (defface quack-threesemi-semi-face
  997. '((((class color) (background light))
  998. (:foreground "#a0ffff":background "#c0ffff"))
  999. (((class color) (background dark))
  1000. (:foreground "cyan2" :background "cyan4"))
  1001. (t (:slant italic)))
  1002. "Face used for `;;;' semicolons when `quack-fontify-threesemi-p' is non-nil."
  1003. :group 'quack)
  1004. (defconst quack-threesemi-text-face 'quack-threesemi-text-face)
  1005. (defface quack-threesemi-text-face
  1006. '((((class color) (background light))
  1007. (:foreground "cyan4" :background "#c0ffff"))
  1008. (((class color) (background dark))
  1009. (:foreground "white" :background "cyan4"))
  1010. (t (:slant italic)))
  1011. "Face used for `;;;' text when `quack-fontify-threesemi-p' is non-nil."
  1012. :group 'quack)
  1013. (defconst quack-threesemi-h1-face 'quack-threesemi-h1-face)
  1014. (defface quack-threesemi-h1-face
  1015. '((t (:bold t :family "Helvetica" :height 1.4 :size "20pt")))
  1016. "Face used for H1 headings in `;;;' text."
  1017. :group 'quack)
  1018. (defconst quack-threesemi-h2-face 'quack-threesemi-h2-face)
  1019. (defface quack-threesemi-h2-face
  1020. '((t (:bold t :family "Helvetica" :height 1.2 :size "16pt")))
  1021. "Face used for H2 headings in `;;;' text."
  1022. :group 'quack)
  1023. (defconst quack-threesemi-h3-face 'quack-threesemi-h3-face)
  1024. (defface quack-threesemi-h3-face
  1025. '((t (:bold t :family "Helvetica")))
  1026. "Face used for H3 headings in `;;;' text."
  1027. :group 'quack)
  1028. (defconst quack-pltfile-prologue-face 'quack-pltfile-prologue-face)
  1029. (defface quack-pltfile-prologue-face
  1030. '((((class color)) (:foreground "black" :background "gray66"))
  1031. (((class grayscale)) (:foreground "black" :background "gray66"))
  1032. (t ()))
  1033. "Face used for the prologue in a decoded PLT package buffer."
  1034. :group 'quack)
  1035. (defconst quack-pltfile-dir-face 'quack-pltfile-dir-face)
  1036. (defface quack-pltfile-dir-face
  1037. '((((class color)) (:bold t :foreground "white" :background "gray33"
  1038. :family "Helvetica" :height 1.2 :size "20pt"))
  1039. (((class grayscale)) (:bold t :foreground "white" :background "gray33"
  1040. :family "Helvetica" :height 1.2 :size "20pt"))
  1041. (t (:bold t :inverse-video t)))
  1042. "Face used for directory headers in a decoded PLT package buffer."
  1043. :group 'quack)
  1044. (defconst quack-pltfile-file-face 'quack-pltfile-file-face)
  1045. (defface quack-pltfile-file-face
  1046. '((((class color)) (:bold t :foreground "black" :background "gray66"
  1047. :family "Helvetica" :height 1.2 :size "20pt"))
  1048. (((class grayscale)) (:bold t :foreground "black" :background "gray66"
  1049. :family "Helvetica" :height 1.2 :size "20pt"))
  1050. (t (:bold t :inverse-video t)))
  1051. "Face used for file headers in a decoded PLT package buffer."
  1052. :group 'quack)
  1053. (defconst quack-about-title-face 'quack-about-title-face)
  1054. (defface quack-about-title-face
  1055. '((((class color) (background light))
  1056. (:bold t :family "Helvetica" :foreground "#008000"
  1057. :height 2.0 :size "24pt"))
  1058. (((class color) (background dark))
  1059. (:bold t :family "Helvetica" :foreground "#00f000"
  1060. :height 2.0 :size "24pt"))
  1061. (t (:bold t :family "Helvetica"
  1062. :height 2.0 :size "24pt")))
  1063. "Face used for Quack name in About Quack."
  1064. :group 'quack)
  1065. (defconst quack-about-face 'quack-about-face)
  1066. (defface quack-about-face
  1067. '((t (:family "Helvetica")))
  1068. "Face used for the body text in About Quack."
  1069. :group 'quack)
  1070. (defconst quack-smallprint-face 'quack-smallprint-face)
  1071. (defface quack-smallprint-face
  1072. '((t (:family "Courier" :height 0.8 :size "8pt")))
  1073. "Face used for the \"small print\" in About Quack."
  1074. :group 'quack)
  1075. ;; Compatibility/Portability Misc. Kludges:
  1076. ;; Note: Some compatibility gotchas found while porting Quack that aren't
  1077. ;; addressed by macros and functions:
  1078. ;;
  1079. ;; * `defface' in Emacs 21 supports ":weight bold", but this is silently
  1080. ;; ignored under older Emacsen, so ":bold t" must be used instead.
  1081. ;;
  1082. ;; * Third argument of `detect-coding-region' is different in Emacs 21 and
  1083. ;; XEmacs 21, so only use the first two args.
  1084. ;;
  1085. ;; * Under XEmacs 21, characters are `equal' but not `eq' to their integer
  1086. ;; ASCII values
  1087. ;;
  1088. ;; * GNU Emacs 21 faces have `:height' property that is either absolute
  1089. ;; decipoints or relative scaling factor. XEmacs 21 faces instead have
  1090. ;; `:size' property, which appears to be absolute point or mm size.
  1091. ;;
  1092. ;; * XEmacs 21 text properties appear to be front-sticky, and there did not
  1093. ;; seem to be any documentation references to stickiness.
  1094. ;;
  1095. ;; * XEmacs 21 `local-variable-p' has second argument mandatory.
  1096. ;;
  1097. ;; * XEmacs 21 does not display submenu labels at all unless the submenu has
  1098. ;; content. For inactive submenus, an empty string suffices for content.
  1099. ;;
  1100. ;; * XEmacs 21 doesn't support composite characters (which we use for very
  1101. ;; nice pretty lambda under GNU Emacs).
  1102. (eval-and-compile
  1103. (defvar quack-xemacs-p (eval '(and (boundp 'running-xemacs) running-xemacs)))
  1104. (defvar quack-gnuemacs-p (not quack-xemacs-p)))
  1105. (defmacro quack-when-xemacs (&rest args)
  1106. (if quack-xemacs-p (cons 'progn args) 'nil))
  1107. (defmacro quack-when-gnuemacs (&rest args)
  1108. (if quack-gnuemacs-p (cons 'progn args) 'nil))
  1109. (defmacro quack-define-key-after (keymap key definition &optional after)
  1110. (if quack-gnuemacs-p
  1111. `(define-key-after ,keymap ,key ,definition ,after)
  1112. `(define-key ,keymap ,key (prog1 ,definition ,after))))
  1113. (defmacro quack-delete-horizontal-space (&rest args)
  1114. (if (and quack-gnuemacs-p (>= emacs-major-version 21))
  1115. `(delete-horizontal-space ,@args)
  1116. `(delete-horizontal-space)))
  1117. (defmacro quack-match-string-no-properties (&rest args)
  1118. `(,(if quack-xemacs-p 'match-string 'match-string-no-properties) ,@args))
  1119. (defmacro quack-menufilter-return (name form)
  1120. (if (= emacs-major-version 20)
  1121. ;; Note: This isn't working in Emacs 20. Menu displays now but actions
  1122. ;; are not executed. No answer to test case posted to comp.emacs
  1123. ;; and then to gnu.emacs.help. In response to my subsequent bug
  1124. ;; report against Emacs, RMS says that, if this is indeed a bug,
  1125. ;; then nothing will be done, since 20 is no longer supported. I'm
  1126. ;; going to let this quietly not work unless someone emails me that
  1127. ;; they're actually using Emacs 20.
  1128. `(easy-menu-filter-return (easy-menu-create-menu ,name ,form))
  1129. form))
  1130. (defmacro quack-propertize (obj &rest props)
  1131. (if (and quack-gnuemacs-p (>= emacs-major-version 21))
  1132. `(propertize ,obj ,@props)
  1133. (let ((obj-var 'quack-propertize-G-obj))
  1134. `(let ((,obj-var ,obj))
  1135. (add-text-properties 0 (length ,obj-var) (list ,@props) ,obj-var)
  1136. ,obj-var))))
  1137. (eval-when-compile
  1138. (when quack-xemacs-p
  1139. (defvar inhibit-eol-conversion)
  1140. (defvar minibuffer-allow-text-properties)))
  1141. ;; Compatibility/Portability Hash Table:
  1142. (eval-and-compile
  1143. (defmacro quack-make-hash-table (&rest args)
  1144. `(,(if (>= emacs-major-version 21)
  1145. 'make-hash-table
  1146. 'quack-fake-make-hash-table)
  1147. ,@args)))
  1148. (defmacro quack-puthash (key value table)
  1149. (list (if (>= emacs-major-version 21) 'puthash 'quack-fake-puthash)
  1150. key value table))
  1151. (defmacro quack-gethash (key table &optional dflt)
  1152. (list (if (>= emacs-major-version 21) 'gethash 'quack-fake-gethash)
  1153. key table dflt))
  1154. (defun quack-fake-make-hash-table (&rest args)
  1155. ;; TODO: Parse the keyword args and make this do 'assoc or 'assq, as
  1156. ;; appropriate. Currently, this package only needs 'assoc.
  1157. (vector 'assoc '()))
  1158. (defun quack-fake-puthash (key value table)
  1159. (let ((pair (funcall (aref table 0) key (aref table 1))))
  1160. (if pair
  1161. (setcdr pair value)
  1162. (aset table 1 (cons (cons key value) (aref table 1))))))
  1163. (defun quack-fake-gethash (key table &optional dflt)
  1164. (let ((pair (funcall (aref table 0) key (aref table 1))))
  1165. (if pair (cdr pair) dflt)))
  1166. ;; Compatibility/Portability Overlays/Extents:
  1167. ;; TODO: Maybe get rid of overlays (and the XEmacs extent kludge), and just use
  1168. ;; text properties instead.
  1169. (defmacro quack-make-face-ovlext (beg end face)
  1170. (if quack-xemacs-p
  1171. `(set-extent-property (make-extent ,beg ,end) 'face ,face)
  1172. `(overlay-put (make-overlay ,beg ,end) 'face ,face)))
  1173. (defmacro quack-make-hiding-ovlext (beg end)
  1174. (if quack-xemacs-p
  1175. `(set-extent-property (make-extent ,beg ,end) 'invisible t)
  1176. `(overlay-put (make-overlay ,beg ,end) 'category 'quack-hiding-ovlcat)))
  1177. ;; Messages, Errors, Warnings:
  1178. (defmacro quack-activity (what &rest body)
  1179. (let ((var-what (make-symbol "quack-activity-G-what")))
  1180. `(let ((,var-what ,what))
  1181. (message (concat ,var-what "..."))
  1182. (prog1 (progn ,@body)
  1183. (message (concat ,var-what "...done"))))))
  1184. (defun quack-internal-error (&optional format &rest args)
  1185. (if format
  1186. (apply 'error (concat "Quack Internal Error: " format) args)
  1187. (error "Quack Internal Error.")))
  1188. (defun quack-warning (format &rest args)
  1189. (apply 'message (concat "Quack Warning: " format) args)
  1190. (unless quack-quiet-warnings-p
  1191. (beep)
  1192. (sleep-for 1)))
  1193. ;; Regular Expressions:
  1194. (defun quack-re-alt (&rest regexps)
  1195. (concat "\\(" (mapconcat 'identity regexps "\\|") "\\)"))
  1196. (defun quack-re-optional (&rest regexps)
  1197. (concat "\\("
  1198. (apply 'concat regexps)
  1199. "\\)?"))
  1200. ;; Misc.:
  1201. ;; (defun quack-abbreviate-file-name (file-name)
  1202. ;; (let ((directory-abbrev-alist '()))
  1203. ;; (abbreviate-file-name file-name)))
  1204. (defun quack-delete-file-if-can (file)
  1205. (condition-case nil (delete-file file) (error nil)))
  1206. (defun quack-expand-file-name (name-or-names &optional directory)
  1207. ;; Note: This only works for systems with Unix-like filenames.
  1208. (expand-file-name (if (listp name-or-names)
  1209. (mapconcat 'identity name-or-names "/")
  1210. name-or-names)
  1211. directory))
  1212. (defun quack-kill-current-buffer ()
  1213. (interactive)
  1214. (kill-buffer (current-buffer)))
  1215. (defun quack-line-at-point ()
  1216. (save-excursion
  1217. (buffer-substring-no-properties
  1218. (progn (beginning-of-line) (point))
  1219. (progn (end-of-line) (point)))))
  1220. (defun quack-looking-at-backward (re &optional limit)
  1221. (save-excursion
  1222. (save-restriction
  1223. (let ((start-pt (point)))
  1224. (narrow-to-region (point-min) (point))
  1225. (and (re-search-backward re limit t)
  1226. (= (match-end 0) start-pt)
  1227. (match-beginning 0))))))
  1228. (defun quack-looking-at-close-paren-backward ()
  1229. (save-match-data
  1230. (quack-looking-at-backward "[])][ \t\r\n\f]*")))
  1231. (defun quack-looking-at-open-paren-backward ()
  1232. (save-match-data
  1233. (quack-looking-at-backward "[[(][ \t\r\n\f]*")))
  1234. (defun quack-make-directory (dir)
  1235. (setq dir (file-name-as-directory dir))
  1236. (unless (file-directory-p dir)
  1237. (make-directory dir t)))
  1238. (defun quack-make-directory-for-file (file)
  1239. (let ((dir (file-name-directory file)))
  1240. (when dir (quack-make-directory dir))))
  1241. (defun quack-propertize-bold (str)
  1242. (quack-propertize str 'face 'bold))
  1243. (defun quack-propertize-face (str face)
  1244. (quack-propertize str 'face face))
  1245. (defun quack-propertize-italic (str)
  1246. (quack-propertize str 'face 'italic))
  1247. (defun quack-sort-string-list-copy (lst)
  1248. (sort (copy-sequence lst) 'string<))
  1249. (defun quack-uncomment-region (beg end)
  1250. ;; TODO: Make a quack-toggle-commentout-region.
  1251. (interactive "r")
  1252. (comment-region beg end '(4)))
  1253. (defun quack-without-side-whitespace (str)
  1254. ;; Copied from `padr-str-trim-ws' by author.
  1255. ;;
  1256. ;; TODO: Don't make an intermediate string. Use regexp match start position.
  1257. (save-match-data
  1258. (if (string-match "^[ \t\n\r]+" str)
  1259. (setq str (substring str (match-end 0))))
  1260. (if (string-match "[ \t\n\r]+$" str)
  1261. (setq str (substring str 0 (match-beginning 0))))
  1262. str))
  1263. ;; Kludgey Sexp Buffer Operations:
  1264. (defconst quack-backward-sexp-re
  1265. (concat "\\`"
  1266. (quack-re-alt "[^\";\\\\]"
  1267. "\\\\\\."
  1268. (concat "\""
  1269. (quack-re-alt "[^\"\\\\]"
  1270. "\\\\\\.")
  1271. "*\""))
  1272. "*\\([\"\\\\]\\)?"))
  1273. (defun quack-backward-sexp ()
  1274. ;; Returns non-nil iff point was in a string literal or comment.
  1275. (interactive)
  1276. (when (bobp)
  1277. (error "beginning of buffer"))
  1278. (save-match-data
  1279. (let* ((orig (point))
  1280. (bol (progn (beginning-of-line) (point))))
  1281. (if (string-match quack-backward-sexp-re
  1282. (buffer-substring-no-properties bol orig))
  1283. (if (match-beginning 3)
  1284. ;; We're in what appears to be a comment or unterminated string
  1285. ;; literal (though might not be, due to multi-line string
  1286. ;; literals and block comments), so move point to the beginning.
  1287. (progn (goto-char (+ bol (match-beginning 3)))
  1288. t)
  1289. ;; We don't appear to be in a comment or string literal, so just
  1290. ;; let `backward-sexp' do its thing.
  1291. (goto-char orig)
  1292. (backward-sexp)
  1293. nil)))))
  1294. (defun quack-parent-sexp-search (name-regexp &optional max-depth max-breadth)
  1295. (save-match-data
  1296. (save-excursion
  1297. (let ((max-depth (or max-depth 100))
  1298. (max-breadth (or max-breadth 100))
  1299. (orig-point (point))
  1300. (found 'looking)
  1301. (depth 0)
  1302. (child-start nil))
  1303. (while (and (eq found 'looking) (< depth max-depth))
  1304. (condition-case nil
  1305. (let ((breadth 0))
  1306. ;; Loop until we hit max breadth or error.
  1307. (while (< breadth max-breadth)
  1308. (when (and (quack-backward-sexp) (not child-start))
  1309. (setq child-start (point)))
  1310. (setq breadth (1+ breadth)))
  1311. ;; We hit our max breadth without erroring, so set the found
  1312. ;; flag to indicate failure and then fall out of our loop.
  1313. (setq found nil))
  1314. (error ; scan-error
  1315. ;; We probably hit the beginning of the enclosing sexp, and point
  1316. ;; should be on the first sexp, which will most often be the form
  1317. ;; name, so first check that there really is an open paren to our
  1318. ;; left, and then check if it matches our regexp.
  1319. (let ((paren-start (quack-looking-at-open-paren-backward)))
  1320. (if paren-start
  1321. ;; There is a paren, so check the name of the form.
  1322. (if (and (looking-at name-regexp)
  1323. (quack-not-symbol-char-at-point-p (match-end 0)))
  1324. ;; Found it, so set the result to a list (lexeme, lexeme
  1325. ;; end point, last nested child sexp start point, parent
  1326. ;; paren start point) and then fall out of our loop.
  1327. ;; Note that we return the original point if no child
  1328. ;; point was found, on the assumption that point was at
  1329. ;; the beginning of the child sexp (unless it was within
  1330. ;; the found form name, in which case child sexp start
  1331. ;; is nil).
  1332. (setq found (list (quack-match-string-no-properties 0)
  1333. (match-end 0)
  1334. (or child-start
  1335. (if (> orig-point (match-end 0))
  1336. orig-point))
  1337. paren-start))
  1338. ;; This form name didn't match, so try to move up in the
  1339. ;; paren syntax (which will usually mean moving left one
  1340. ;; character).
  1341. (condition-case nil
  1342. (progn (up-list -1)
  1343. (setq child-start (point))
  1344. (setq depth (1+ depth)))
  1345. (error ; scan-error
  1346. ;; We can't go up here, so set found flag to indicate
  1347. ;; failure and then fall out of the loop.
  1348. (setq found nil))))
  1349. ;; There wasn't a paren, which means we hit a scan error for
  1350. ;; some reason other than being at the beginning of the sexp,
  1351. ;; so consider the search a failure
  1352. (setq found nil))))))
  1353. (if (eq found 'looking)
  1354. nil
  1355. found)))))
  1356. ;; TODO: We really need a global definition of what are Scheme symbol
  1357. ;; constituent characters (or a whole-symbol regexp)!
  1358. (defun quack-not-symbol-char-at-point-p (pt)
  1359. ;; This is used to check for a symbol boundary point.
  1360. (save-match-data
  1361. (or (= pt (point-max))
  1362. (if (string-match "[^-a-zA-Z0-9!+<=>$%&*./:@^_~]"
  1363. (buffer-substring-no-properties pt (1+ pt)))
  1364. t))))
  1365. ;; String Constant Hashtable:
  1366. (eval-and-compile
  1367. (if (< emacs-major-version 21)
  1368. (defun quack-strconst (str) str)
  1369. (defvar quack-strconst-hashtable
  1370. (if (>= emacs-major-version 21)
  1371. (quack-make-hash-table :test 'equal :size 1000)))
  1372. (defun quack-strconst (str)
  1373. (unless (stringp str)
  1374. (error "Non-string object passed to quack-strconst: %s" str))
  1375. (or (quack-gethash str quack-strconst-hashtable nil)
  1376. (quack-puthash str str quack-strconst-hashtable)
  1377. str))))
  1378. ;; Web URLs:
  1379. (defun quack-quote-url-substring (str &optional quote-slash-p always-new-p)
  1380. (save-match-data
  1381. (let ((regexp (if quote-slash-p "[^-_.A-Za-z0-9]" "[^-_.A-Za-z0-9/]"))
  1382. (subs '())
  1383. (len (length str))
  1384. (start 0))
  1385. (while (and (> len start)
  1386. (string-match regexp str start))
  1387. (let ((beg (match-beginning 0))
  1388. (end (match-end 0)))
  1389. (when (> beg start)
  1390. (setq subs (cons (substring str start beg) subs)))
  1391. (setq subs (cons (format "%%%X" (aref str beg)) subs))
  1392. (setq start end)))
  1393. (if subs
  1394. (apply 'concat (reverse (if (> len start)
  1395. (cons (substring str start len) subs)
  1396. subs)))
  1397. (if always-new-p (copy-sequence str) str)))))
  1398. (defun quack-file-url (dir file)
  1399. ;; TODO: This is Unix-centric and a little fragile. Rewrite eventually.
  1400. (concat "file:"
  1401. (quack-quote-url-substring dir)
  1402. "/"
  1403. (or (quack-quote-url-substring file) "")))
  1404. (defun quack-build-url (base path)
  1405. (let ((base-slash-p (= (aref base (1- (length base))) ?\/)))
  1406. (if path
  1407. (mapconcat 'identity
  1408. (cons (if base-slash-p
  1409. (substring base 0 -1)
  1410. base)
  1411. path)
  1412. "/")
  1413. (if base-slash-p
  1414. base
  1415. (concat base "/")))))
  1416. ;; Web Browsing:
  1417. (defun quack-browse-url (url)
  1418. (require 'browse-url)
  1419. (message "Quack viewing URL: %s" url)
  1420. (let ((browse-url-browser-function (or quack-browse-url-browser-function
  1421. browse-url-browser-function)))
  1422. (browse-url url)))
  1423. (defun quack-browse-quack-web-page ()
  1424. (interactive)
  1425. (quack-browse-url quack-web-page))
  1426. (defun quack-w3m-browse-url-other-window (url &optional new-window)
  1427. (interactive (eval '(browse-url-interactive-arg "URL: ")))
  1428. (unless (string= (buffer-name) "*w3m*")
  1429. (switch-to-buffer-other-window (current-buffer)))
  1430. ;; TODO: If `*w3m*' buffer is visible in current frame or other frame,
  1431. ;; switch to that, for Emacsen that don't do that by default.
  1432. (eval '(w3m-browse-url url nil)))
  1433. ;; Web Getting:
  1434. (defconst quack-web-get-log-buffer-name "*quack-web-get*")
  1435. (defun quack-web-get-to-file (url out-file)
  1436. ;; TODO: Support other getting tools, such as "lynx -source", "links
  1437. ;; -source", "w3m -dump_source", and the Emacs w3 package. Most of
  1438. ;; these send the Web content to stdout, so, unlike for wget, it will
  1439. ;; be easier to insert directly to a buffer and send stderr to a temp
  1440. ;; file. We should have *-to-file-* and *-insert-via-* functions for
  1441. ;; each external downloader program anyway.
  1442. (quack-make-directory-for-file out-file)
  1443. (quack-web-get-to-file-via-wget url out-file))
  1444. ;;(defun quack-web-get-to-temp-file (url)
  1445. ;; (let ((temp-file (quack-make-temp-file "web-get")))
  1446. ;; (quack-web-get-to-file url temp-file)
  1447. ;; temp-file))
  1448. (defun quack-web-get-to-file-via-wget (url out-file)
  1449. ;; TODO: Make this initially download to a temp file; replace any
  1450. ;; pre-existing out-file after successful download. Do this for any
  1451. ;; external downloader programs that write to the specified output file
  1452. ;; before the download is complete.
  1453. (let ((window (selected-window))
  1454. (saved-buf (current-buffer))
  1455. (log-buf (get-buffer-create quack-web-get-log-buffer-name)))
  1456. (unwind-protect
  1457. (progn
  1458. ;; Prepare the log buffer.
  1459. (set-buffer log-buf)
  1460. (widen)
  1461. (buffer-disable-undo)
  1462. (goto-char (point-min))
  1463. (delete-region (point-min) (point-max))
  1464. (set-window-buffer window log-buf)
  1465. ;; Do the wget.
  1466. (quack-activity
  1467. (format "Getting %S via wget" url)
  1468. (let ((status (call-process "wget" nil t t
  1469. "-O" out-file "-t" "1" "--" url)))
  1470. (unless (= status 0)
  1471. (quack-delete-file-if-can out-file)
  1472. (error "Could not get %S via wget." url))
  1473. (kill-buffer log-buf)
  1474. out-file)))
  1475. ;; unwind-protect cleanup
  1476. (set-window-buffer window saved-buf)
  1477. (set-buffer saved-buf))))
  1478. ;; HTML Kludges:
  1479. (defun quack-strip-limited-html-tags (str)
  1480. (save-match-data
  1481. (let ((case-fold-search t)
  1482. (str-len (length str))
  1483. (frags '())
  1484. (start 0))
  1485. (while (string-match "</?[a-z]+[ \r\n]*>" str start)
  1486. (when (> (match-beginning 0) start)
  1487. (setq frags (cons (substring str start (match-beginning 0)) frags)))
  1488. (setq start (match-end 0)))
  1489. (if frags
  1490. (progn (when (< start str-len)
  1491. (setq frags (cons (substring str start) frags)))
  1492. (apply 'concat (reverse frags)))
  1493. str))))
  1494. ;; Temp Files:
  1495. (defun quack-temp-dir ()
  1496. (file-name-as-directory (expand-file-name "tmp" quack-dir)))
  1497. ;; TODO: Make sure this gets executed in load phase even if byte-compiled.
  1498. (random t)
  1499. (defun quack-make-temp-file (purpose-str)
  1500. ;; Note: There is an obvious race condition here. But we're trying to do
  1501. ;; this in portable Elisp, and if user's `quack-dir' is writable by
  1502. ;; someone other than user, then user has bigger problems.
  1503. (save-excursion
  1504. (let* ((buf (generate-new-buffer "*quack-make-temp-file*"))
  1505. (dir (quack-temp-dir))
  1506. file)
  1507. (set-buffer buf)
  1508. (quack-make-directory dir)
  1509. (while (progn (setq file (expand-file-name (format "%d-%s-%d"
  1510. (emacs-pid)
  1511. purpose-str
  1512. (random 10000))
  1513. dir))
  1514. (file-exists-p file)))
  1515. (set-visited-file-name file)
  1516. (save-buffer 0)
  1517. (kill-buffer buf)
  1518. file)))
  1519. ;; About:
  1520. (defun quack-about ()
  1521. (interactive)
  1522. (let* ((buf-name "*About Quack*")
  1523. (buf (get-buffer buf-name)))
  1524. (when buf (kill-buffer buf))
  1525. (setq buf (get-buffer-create buf-name))
  1526. (switch-to-buffer buf)
  1527. (setq buffer-read-only nil)
  1528. (widen)
  1529. (fundamental-mode)
  1530. (when font-lock-mode
  1531. ;;(quack-warning "Font-lock mode mysteriously on in fundamental-mode.")
  1532. (font-lock-mode -1))
  1533. (buffer-disable-undo)
  1534. ;;(delete-region (point-min) (point-max))
  1535. (erase-buffer)
  1536. (insert
  1537. "\n"
  1538. (quack-propertize-face (copy-sequence "Quack") 'quack-about-title-face)
  1539. " Version "
  1540. (quack-propertize-bold (copy-sequence quack-version))
  1541. "\n"
  1542. (quack-propertize-italic
  1543. (copy-sequence "Enhanced Emacs support for Scheme programming"))
  1544. "\n\n"
  1545. "You can email bug reports and feature requests to the author,\n"
  1546. quack-author-name
  1547. " <"
  1548. quack-author-email
  1549. ">. Mention that\n"
  1550. "you are using "
  1551. (quack-propertize-bold
  1552. (copy-sequence
  1553. (cond (quack-gnuemacs-p "GNU Emacs")
  1554. (quack-xemacs-p "XEmacs")
  1555. (t "*an unrecognized Emacs kind*"))))
  1556. " "
  1557. (quack-propertize-bold
  1558. (format "%d.%d" emacs-major-version emacs-minor-version))
  1559. " on "
  1560. (quack-propertize-bold (copy-sequence system-configuration))
  1561. ".\n\n"
  1562. "To be notified via email when new Quack versions are released,\n"
  1563. "ask Neil to add you to the moderated "
  1564. (quack-propertize-bold "scheme-announce")
  1565. " list.\n\n"
  1566. "Visit the Web page: "
  1567. quack-web-page
  1568. "\n")
  1569. (insert "\n\n"
  1570. (quack-propertize-face (copy-sequence quack-copyright)
  1571. 'quack-smallprint-face)
  1572. "\n"
  1573. (quack-propertize-face (copy-sequence quack-copyright-2)
  1574. 'quack-smallprint-face)
  1575. "\n\n"
  1576. (quack-propertize-face (concat quack-legal-notice "\n")
  1577. 'quack-smallprint-face))
  1578. (goto-char (point-min))
  1579. (set-buffer-modified-p nil)
  1580. (setq buffer-read-only t)
  1581. (local-set-key "q" 'quack-kill-current-buffer)
  1582. (local-set-key "w" 'quack-browse-quack-web-page)
  1583. (message
  1584. "Press `q' to quit *About Quack*, `w' to visit the Quack Web page.")))
  1585. ;; PLT Collections:
  1586. (defvar quack-pltcollects-alist-cache nil)
  1587. (defun quack-invalidate-pltcollects-caches ()
  1588. (setq quack-pltcollects-alist-cache nil)
  1589. (quack-invalidate-manuals-caches))
  1590. (defun quack-pltcollects-alist ()
  1591. (or quack-pltcollects-alist-cache
  1592. (quack-activity
  1593. "Scanning PLT collection directories"
  1594. (let ((result '()))
  1595. (mapcar (function
  1596. (lambda (dir)
  1597. (mapcar (function
  1598. (lambda (subdir)
  1599. (unless (member subdir '("." ".." "CVS" "RCS"))
  1600. (let ((subdir-path (expand-file-name subdir
  1601. dir)))
  1602. (when (file-directory-p subdir-path)
  1603. (setq result
  1604. (cons (cons subdir subdir-path)
  1605. result)))))))
  1606. (condition-case nil
  1607. (directory-files dir)
  1608. (file-error nil)))))
  1609. quack-pltcollect-dirs)
  1610. (setq quack-pltcollects-alist-cache (reverse result))))))
  1611. (defun quack-dir-for-pltcollect (name)
  1612. (cdr (assoc name (quack-pltcollects-alist))))
  1613. (defun quack-dired-pltcollect ()
  1614. (interactive)
  1615. (let* ((alist (quack-pltcollects-alist))
  1616. (default (if (assoc "mzlib" alist) "mzlib" nil))
  1617. (dir (cdr (assoc
  1618. (completing-read
  1619. (if default
  1620. (format "Dired for PLT collection (default %S): "
  1621. default)
  1622. "Dired for PLT collection: ")
  1623. alist nil t nil nil default)
  1624. alist))))
  1625. (and dir (dired dir))))
  1626. ;; Find File:
  1627. (defun quack-shorter-file-relative-name (filename &optional directory)
  1628. (let ((absolute (expand-file-name filename directory))
  1629. (relative (file-relative-name filename directory)))
  1630. (if (< (length relative) (length absolute))
  1631. relative
  1632. absolute)))
  1633. ;; TODO: Also write `quack-find-file-other-window' and
  1634. ;; `quack-find-file-other-frame' and steal appropriate key bindings.
  1635. (defun quack-find-file ()
  1636. ;; TODO: Hangup/delay problems in mega-huge files.
  1637. ;;
  1638. ;; TODO: Handle `(load <filename>)'
  1639. (interactive)
  1640. (let* ((default (quack-find-file-default))
  1641. (entry (let ((insert-default-directory (if default
  1642. nil
  1643. insert-default-directory)))
  1644. (read-file-name
  1645. (if default
  1646. (format "Quack find file (default %S): "
  1647. (quack-shorter-file-relative-name
  1648. default
  1649. default-directory))
  1650. "Quack find file: ")
  1651. default-directory
  1652. default))))
  1653. (find-file (if (string= entry "")
  1654. (or default "")
  1655. entry))))
  1656. (defun quack-find-file-default ()
  1657. (or (quack-pltrequire-at-point-filename)
  1658. ;; TODO: Add support for syntax from Guile, SLIB, Chicken, etc.
  1659. ))
  1660. ;; TODO: Guile `:use-module' support. Forget about 1.4, and do 1.6.
  1661. ;;
  1662. ;; (defun quack-guilecolonusemodule-at-point-data ()
  1663. ;; (save-match-data
  1664. ;; (when (thing-at-point-looking-at
  1665. ;; ":use-module[ \t]+\\(([^][()\"#'`,]+)\\)")
  1666. ;; (condition-case nil
  1667. ;; (car (read-from-string (buffer-substring-no-properties
  1668. ;; (match-beginning 1) (match-end 1))))
  1669. ;; (error nil)))))
  1670. ;;
  1671. ;; ;; (define-module (ice-9 expect) :use-module (ice-9 regex))
  1672. ;; TODO: Guile 1.6 `use-modules' and `use-syntax' support.
  1673. ;;
  1674. ;; (use-modules (ice-9 regex))
  1675. ;;
  1676. ;; (use-modules ((ice-9 popen)
  1677. ;; :select ((open-pipe . pipe-open) close-pipe)
  1678. ;; :renamer (symbol-prefix-proc 'unixy:)))
  1679. ;;
  1680. ;; (use-modules { SPEC }+ )
  1681. ;;
  1682. ;; SPEC ::= MODULE-NAME | (MODULE-NAME [:select SELECTION] [:renamer RENAMER])
  1683. ;;
  1684. ;; (use-syntax MODULE-NAME)
  1685. ;; TODO: Support SLIB-style `require' forms:
  1686. ;;
  1687. ;; (require 'foo)
  1688. ;; TODO: Bigloo `import' and maybe `extern' support.
  1689. ;;
  1690. ;; ;; /usr/share/doc/bigloo-examples/examples/Foreign/
  1691. ;; (module example
  1692. ;; (import (bis foreign2 "foreign2.scm"))
  1693. ;; ...)
  1694. ;;
  1695. ;; ;; /usr/share/doc/bigloo-examples/examples/Fork/
  1696. ;; (module sys-example
  1697. ;; (extern (include "sys/types.h")
  1698. ;; (include "wait.h")
  1699. ;; (include "unistd.h")
  1700. ;; ...))
  1701. ;; TODO: PLT module language syntax: (module info (lib "infotab.ss" "setup")
  1702. (defconst quack-pltrequire-at-point-data-re
  1703. (quack-re-alt "dynamic-require"
  1704. (concat "require"
  1705. (quack-re-alt "-for-syntax"
  1706. ""))))
  1707. (defconst quack-pltrequire-at-point-data-1-re
  1708. (concat quack-pltrequire-at-point-data-re
  1709. "\\>"))
  1710. (defconst quack-pltrequire-at-point-data-2-re
  1711. (concat "[^\r\n]*[[(]"
  1712. quack-pltrequire-at-point-data-re
  1713. "[ \t]+\\([^\r\n]+\\)"))
  1714. (defun quack-pltrequire-at-point-data-1 ()
  1715. (save-match-data
  1716. (let ((qpss (quack-parent-sexp-search quack-pltrequire-at-point-data-1-re
  1717. 4)))
  1718. (when qpss
  1719. (let ((child-start (nth 2 qpss)))
  1720. (when child-start
  1721. (save-excursion
  1722. (goto-char child-start)
  1723. (condition-case nil
  1724. ;; Note: It is normally OK to use the Elisp reader here.
  1725. (read (current-buffer))
  1726. (error nil)))))))))
  1727. (defun quack-pltrequire-at-point-data-2 ()
  1728. (save-match-data
  1729. (when (thing-at-point-looking-at quack-pltrequire-at-point-data-2-re)
  1730. (let* ((read-start (match-beginning 2))
  1731. (parts-pt (- (point) read-start))
  1732. (parts (buffer-substring-no-properties read-start
  1733. (match-end 2)))
  1734. (parts-len (length parts))
  1735. (start 0)
  1736. (result '()))
  1737. (condition-case nil
  1738. (while (< start parts-len)
  1739. ;; Note: It is normally OK to use the Elisp reader here.
  1740. (let ((r (read-from-string parts start)))
  1741. (when (or (not result) (> parts-pt start))
  1742. (setq result (car r)))
  1743. (setq start (cdr r))))
  1744. (error nil))
  1745. result))))
  1746. (defun quack-pltrequire-at-point-filename (&optional silent)
  1747. (let* ((d (or (quack-pltrequire-at-point-data-1)
  1748. (quack-pltrequire-at-point-data-2)))
  1749. (m (cond
  1750. ((not d) nil)
  1751. ((stringp d) d)
  1752. ((listp d)
  1753. (let ((f (car d)))
  1754. (when (symbolp f)
  1755. (cond ((memq f '(file lib)) d)
  1756. ((memq f '(all-except rename)) (nth 1 d))
  1757. ((memq f '(prefix prefix-all-except)) (nth 2 d)))))))))
  1758. (cond
  1759. ((stringp m) m)
  1760. ((listp m)
  1761. (let ((f (car m)))
  1762. (when (symbolp f)
  1763. (cond ((eq f 'file) (nth 1 f))
  1764. ((eq f 'lib)
  1765. (let* ((file (nth 1 m))
  1766. (collect (or (nth 2 m) "mzlib"))
  1767. (collect-dir (quack-dir-for-pltcollect collect))
  1768. (subs (nthcdr 3 m)))
  1769. (when file
  1770. (if collect-dir
  1771. (quack-expand-file-name (nconc subs (list file))
  1772. collect-dir)
  1773. (unless silent
  1774. (quack-warning "Cannot find collection %S" collect))
  1775. nil)))))))))))
  1776. ;; Indenting Newline:
  1777. (defun quack-newline (&optional arg)
  1778. (interactive "*P")
  1779. (if (eq quack-newline-behavior 'newline)
  1780. (newline arg)
  1781. (if (eq quack-newline-behavior 'indent-newline-indent)
  1782. (lisp-indent-line)
  1783. (unless (eq quack-newline-behavior 'newline-indent)
  1784. (error "invalid quack-newline-behavior value: %s"
  1785. quack-newline-behavior)))
  1786. (let ((n (prefix-numeric-value arg)))
  1787. (when (> n 0)
  1788. (while (> n 0)
  1789. (setq n (1- n))
  1790. (quack-delete-horizontal-space t)
  1791. (newline))
  1792. (lisp-indent-line)))))
  1793. ;; Agreeing-Paren Insert:
  1794. ;; TODO: Make paren-matching within comments limit seaching to within comments,
  1795. ;; not skip back and try to match code. One workaround is to prefix
  1796. ;; parents/brackets in comments with backslash.
  1797. (defun quack-insert-closing (prefix default-close other-open other-close)
  1798. (insert default-close)
  1799. (unless prefix
  1800. (let ((open-pt (condition-case nil
  1801. (scan-sexps (point) -1)
  1802. (error (beep) nil))))
  1803. (when open-pt
  1804. (let ((open-char (aref (buffer-substring-no-properties
  1805. open-pt (1+ open-pt))
  1806. 0)))
  1807. (when (= open-char other-open)
  1808. (delete-backward-char 1)
  1809. (insert other-close))))))
  1810. (when blink-paren-function (funcall blink-paren-function)))
  1811. (defun quack-insert-closing-paren (&optional prefix)
  1812. (interactive "P")
  1813. (quack-insert-closing prefix ?\) ?\[ ?\]))
  1814. (defun quack-insert-closing-bracket (&optional prefix)
  1815. (interactive "P")
  1816. (quack-insert-closing prefix ?\] ?\( ?\)))
  1817. ;; Opening-Paren Insert:
  1818. (defun quack-insert-opening (prefix char)
  1819. (insert (if (or prefix (not quack-smart-open-paren-p)) char ?\())
  1820. (when blink-paren-function (funcall blink-paren-function)))
  1821. (defun quack-insert-opening-paren (&optional prefix)
  1822. (interactive "P")
  1823. (quack-insert-opening prefix ?\())
  1824. (defun quack-insert-opening-bracket (&optional prefix)
  1825. (interactive "P")
  1826. (quack-insert-opening prefix ?\[))
  1827. ;; Definition Lambda Syntax Toggling:
  1828. (defconst quack-toggle-lambda-re-1
  1829. (concat "define\\*?"
  1830. (quack-re-alt "-for-syntax"
  1831. "-public"
  1832. "/override"
  1833. "/private"
  1834. "/public"
  1835. "")))
  1836. (defconst quack-toggle-lambda-re-2
  1837. (let ((ws-opt "[ \t\r\n\f]*")
  1838. (symbol "[^][() \t\r\n\f]+")
  1839. (open-paren "[[(]")
  1840. (close-paren "[])]"))
  1841. (concat ws-opt
  1842. (quack-re-alt ; #=1
  1843. (concat "\\(" ; #<2 `NAME (lambda ('
  1844. "\\(" ; #<3 name
  1845. symbol
  1846. "\\)" ; #>3
  1847. ws-opt
  1848. open-paren
  1849. ws-opt
  1850. "lambda"
  1851. ws-opt
  1852. open-paren
  1853. ws-opt
  1854. "\\)")
  1855. (concat "\\(" ; #<4 `(NAME'
  1856. open-paren
  1857. ws-opt
  1858. "\\(" ; #<5 name
  1859. symbol
  1860. "\\)" ; #>5
  1861. ws-opt
  1862. "\\)"))
  1863. "\\(" ; #<6 optional close paren
  1864. close-paren
  1865. "\\)?" ; #>6
  1866. )))
  1867. (defun quack-toggle-lambda ()
  1868. (interactive)
  1869. (save-match-data
  1870. (let ((found (quack-parent-sexp-search quack-toggle-lambda-re-1))
  1871. last-paren-marker
  1872. leave-point-marker)
  1873. (unless found
  1874. (error "Sorry, this does not appear to be a definition form."))
  1875. (unwind-protect
  1876. (let ((lexeme-end (nth 1 found))
  1877. (define-beg (nth 3 found)))
  1878. ;; Make the markers.
  1879. (setq last-paren-marker (make-marker))
  1880. (setq leave-point-marker (point-marker))
  1881. ;; Move to right after the define form keyword, and match the
  1882. ;; pattern of the two possible syntaxes. Error if no match.
  1883. (goto-char lexeme-end)
  1884. (unless (looking-at quack-toggle-lambda-re-2)
  1885. (error "Sorry, we can't grok this definition syntax."))
  1886. ;; Pattern matched, so find the closing paren of the define form.
  1887. (let ((pt (condition-case nil
  1888. (scan-sexps define-beg 1)
  1889. (error ; scan-error
  1890. nil))))
  1891. (if pt
  1892. (set-marker last-paren-marker (1- pt))
  1893. (quack-warning
  1894. "This definition form sexp is unclosed. Consider undo.")))
  1895. ;; Now act based on which syntax we saw.
  1896. (cond
  1897. ((match-beginning 2)
  1898. ;; We saw the syntax `NAME (lambda ('.
  1899. (let ((name (quack-match-string-no-properties 3)))
  1900. (when (marker-position last-paren-marker)
  1901. (goto-char last-paren-marker)
  1902. (let ((victim-beg (quack-looking-at-close-paren-backward)))
  1903. (unless victim-beg
  1904. (error "This definition form should end with `))'."))
  1905. (delete-region victim-beg (point))))
  1906. (goto-char lexeme-end)
  1907. (delete-region lexeme-end (match-end 2))
  1908. (insert " (" name (if (match-beginning 6) "" " "))))
  1909. ((match-beginning 4)
  1910. ;; We saw the syntax `(NAME'.
  1911. (let ((name (quack-match-string-no-properties 5)))
  1912. (when (marker-position last-paren-marker)
  1913. (goto-char last-paren-marker)
  1914. (insert ")"))
  1915. (goto-char lexeme-end)
  1916. (delete-region lexeme-end (match-end 4))
  1917. (insert " " name "\n")
  1918. (set-marker leave-point-marker (point))
  1919. (insert "(lambda (")
  1920. (set-marker-insertion-type leave-point-marker t)))
  1921. (t (quack-internal-error)))
  1922. ;; Reindent, which also takes care of font-lock updating of deleted
  1923. ;; and inserted text.
  1924. (indent-region define-beg
  1925. (or (marker-position last-paren-marker)
  1926. (max (marker-position leave-point-marker)
  1927. (point)))
  1928. nil))
  1929. ;; unwind-protect cleanup
  1930. (goto-char (marker-position leave-point-marker))
  1931. (set-marker leave-point-marker nil)))))
  1932. ;; Buffer Tidying:
  1933. ;; TODO: Maybe have an option to automatically tidy the buffer on save. Make
  1934. ;; default off. This can be slow for larger buffers on older computers,
  1935. ;; especially if font-lock is activated. It can also annoy people who
  1936. ;; have a CM system full of improperly formatted files, or who like
  1937. ;; things like formfeed characters in their files.
  1938. (defun quack-delete-all-in-buffer (regexp &optional subexp)
  1939. (unless subexp (setq subexp 0))
  1940. ;; Note: This moves the point and changes the match data.
  1941. (goto-char (point-min))
  1942. (while (re-search-forward regexp nil t)
  1943. (goto-char (match-end subexp))
  1944. (delete-region (match-beginning subexp) (point))))
  1945. (defun quack-tidy-buffer ()
  1946. ;; TODO: Make sure this works with odd eol conventions and the various
  1947. ;; codeset representations in various versions of Emacs.
  1948. ;; TODO: Maybe detect DrScheme ASCII-art "big letters" and protect them from
  1949. ;; reindenting.
  1950. "Tidy the formatting of the current Scheme buffer.
  1951. This reindents, converts tabs to spaces, removes trailing whitespace on lines,
  1952. removes formfeed characters, removes extraneous blank lines, and makes sure
  1953. the buffer ends with a newline.
  1954. This can conceivably corrupt multi-line string literals, but not in any way
  1955. they wouldn't be corrupted by Usenet, various mailers, typesetting for print,
  1956. etc.
  1957. This may also result in large diffs when the tidied file is commited back to a
  1958. version control or configuration management system. Consider making a VC or CM
  1959. delta that consists only of changes made by `quack-tidy-buffer'."
  1960. (interactive)
  1961. (if (= (point-min) (point-max))
  1962. (message "Buffer is empty; no tidying necessary.")
  1963. (let ((marker (point-marker))
  1964. (fill-prefix nil))
  1965. (unwind-protect
  1966. (save-excursion
  1967. (save-match-data
  1968. (quack-activity
  1969. "Tidying buffer"
  1970. ;; Make sure last character is a newline.
  1971. (unless (string= "\n" (buffer-substring-no-properties
  1972. (1- (point-max))
  1973. (point-max)))
  1974. (goto-char (point-max))
  1975. (insert "\n"))
  1976. ;; Remove form-feed characters.
  1977. (quack-delete-all-in-buffer "\f")
  1978. ;; Reindent buffer (without inserting any new tabs).
  1979. ;; Note: This is the time-consuming pass.
  1980. (let ((saved-indent-tabs-mode indent-tabs-mode))
  1981. (unwind-protect
  1982. (progn (setq indent-tabs-mode nil)
  1983. (indent-region (point-min) (point-max) nil))
  1984. ;; unwind-protect cleanup
  1985. (setq indent-tabs-mode saved-indent-tabs-mode)))
  1986. ;; Expand any remaining tabs.
  1987. (untabify (point-min) (point-max))
  1988. ;; Remove trailing whitespace on each line.
  1989. (quack-delete-all-in-buffer "\\([ \t\r]+\\)\n" 1)
  1990. ;; Remove blank lines from top.
  1991. (goto-char (point-min))
  1992. (when (looking-at "[ \t\r\n]+")
  1993. (delete-region (match-beginning 0) (match-end 0)))
  1994. ;; Remove excess adjacent blank lines.
  1995. (quack-delete-all-in-buffer "\n\n\\(\n+\\)" 1)
  1996. ;; Remove blank lines from bottom.
  1997. (goto-char (point-max))
  1998. (when (quack-looking-at-backward
  1999. "\n\\(\n\\)"
  2000. (max (point-min) (- (point-max) 3)))
  2001. (delete-region (match-beginning 1) (match-end 1))))))
  2002. ;; unwind-protect cleanup
  2003. (goto-char (marker-position marker))
  2004. (set-marker marker nil)))))
  2005. ;; SRFIs:
  2006. ;; TODO: Archive local copies of SRFIs? Have to update them when modified, but
  2007. ;; without unnecessarily downloading from the master site. This is
  2008. ;; doable with wget mirroring, but not with things like "lynx -source".
  2009. (defconst quack-srfi-subindex-kinds '(draft final withdrawn)
  2010. "List of symbols representing the three possible states of an SRFI (`draft',
  2011. `final', and `withdrawn'), in order of increasing precedence (e.g., final
  2012. follows draft,since a final version supercedes a draft version).")
  2013. (defvar quack-srfi-completes-cache 'invalid)
  2014. (defvar quack-srfi-menu-cache 'invalid)
  2015. (defun quack-srfi-completes ()
  2016. (when (eq quack-srfi-completes-cache 'invalid)
  2017. (quack-process-srfi-subindex-files))
  2018. quack-srfi-completes-cache)
  2019. (defun quack-srfi-menu (&optional noninteractive)
  2020. (when (eq quack-srfi-menu-cache 'invalid)
  2021. (quack-process-srfi-subindex-files noninteractive))
  2022. quack-srfi-menu-cache)
  2023. (defun quack-srfi-master-url (path)
  2024. (quack-build-url quack-srfi-master-base-url path))
  2025. (defun quack-srfi-subindex-master-url (kind)
  2026. (quack-srfi-master-url (list (quack-srfi-subindex-basename kind))))
  2027. (defun quack-srfi-dir ()
  2028. (file-name-as-directory (expand-file-name "srfi" quack-dir)))
  2029. (defun quack-srfi-subindex-file (kind)
  2030. (expand-file-name (quack-srfi-subindex-basename kind) (quack-srfi-dir)))
  2031. (defun quack-srfi-subindex-basename (kind)
  2032. (format "%S-srfis.html" kind))
  2033. (defun quack-invalidate-srfi-index-caches ()
  2034. (setq quack-srfi-completes-cache 'invalid)
  2035. (setq quack-srfi-menu-cache 'invalid))
  2036. (defun quack-update-srfi-index ()
  2037. (interactive)
  2038. (quack-activity
  2039. "Updating SRFI index"
  2040. (quack-download-srfi-subindex-files)))
  2041. (defun quack-download-srfi-subindex-files ()
  2042. (quack-invalidate-srfi-index-caches)
  2043. (mapcar (function
  2044. (lambda (kind)
  2045. (quack-activity
  2046. (format "Downloading %s SRFI subindex" kind)
  2047. (quack-web-get-to-file (quack-srfi-subindex-master-url kind)
  2048. (quack-srfi-subindex-file kind)))))
  2049. quack-srfi-subindex-kinds))
  2050. (defun quack-download-srfi-subindex-files-if-missing ()
  2051. (let ((missing '()))
  2052. (mapcar (function
  2053. (lambda (kind)
  2054. (unless (file-exists-p (quack-srfi-subindex-file kind))
  2055. (setq missing (nconc missing (list kind))))))
  2056. quack-srfi-subindex-kinds)
  2057. (when (and missing
  2058. (y-or-n-p "Some cached SRFI subindexes are missing. Update? "))
  2059. (quack-update-srfi-index))))
  2060. (defun quack-process-srfi-subindex-files (&optional noninteractive)
  2061. (let ((index '())
  2062. (completes '())
  2063. (menu (mapcar (function (lambda (kind) (cons kind nil)))
  2064. quack-srfi-subindex-kinds)))
  2065. ;; Invalidate dependent caches.
  2066. (quack-invalidate-srfi-index-caches)
  2067. ;; Give user a chance to download any missing cache files all at once,
  2068. ;; instead of prompting individually later.
  2069. (unless noninteractive
  2070. (quack-download-srfi-subindex-files-if-missing))
  2071. ;; Parse the index files, letting entries for successive states supercede.
  2072. (mapcar (function
  2073. (lambda (kind)
  2074. (mapcar (function
  2075. (lambda (new)
  2076. (let (old)
  2077. (if (setq old (assq (car new) index))
  2078. (setcdr old (cdr new))
  2079. (setq index (cons new index))))))
  2080. (quack-parse-srfi-subindex-file kind noninteractive))))
  2081. quack-srfi-subindex-kinds)
  2082. ;; Sort the parse form in reverse order, since the cache-building functions
  2083. ;; will reverse this.
  2084. (setq index (sort index (function (lambda (a b) (>= (car a) (car b))))))
  2085. ;; Build the completions and menu caches.
  2086. (let ((fmt (concat "%"
  2087. (if index
  2088. (number-to-string
  2089. (length (number-to-string (car (car index)))))
  2090. "")
  2091. "d %s")))
  2092. (mapcar (function
  2093. (lambda (n)
  2094. (let ((num (nth 0 n))
  2095. (kind (nth 1 n))
  2096. (title (nth 2 n)))
  2097. (unless kind (quack-internal-error))
  2098. (setq completes
  2099. (cons (cons (if (eq kind 'final)
  2100. (format "%d %s" num title)
  2101. (format "%d [%s] %s" num kind title))
  2102. num)
  2103. completes))
  2104. (let ((pair (or (assq kind menu)
  2105. (quack-internal-error))))
  2106. (setcdr pair (cons `[,(format fmt num title)
  2107. (quack-view-srfi ,num)]
  2108. (cdr pair)))))))
  2109. index))
  2110. ;; Finish the menu.
  2111. (mapcar (function (lambda (n)
  2112. (setcar n (cdr (assoc (car n)
  2113. '((draft . "Draft")
  2114. (final . "Final")
  2115. (withdrawn . "Withdrawn")))))
  2116. ;; Add dummy content so that XEmacs 21 will display
  2117. ;; the submenu label.
  2118. (unless (cdr n)
  2119. (setcdr n (cons "(None)" nil)))))
  2120. menu)
  2121. (setq menu `(["Update SRFI Index" quack-update-srfi-index]
  2122. "---"
  2123. ,@menu
  2124. ["Other SRFI..." quack-view-srfi]))
  2125. ;; Store the results.
  2126. (setq quack-srfi-menu-cache menu)
  2127. (setq quack-srfi-completes-cache completes)))
  2128. (defun quack-parse-srfi-subindex-file (kind &optional noninteractive)
  2129. (save-excursion
  2130. (let ((file (quack-srfi-subindex-file kind)))
  2131. (unless (file-exists-p file)
  2132. (error "No SRFI index file %S" file))
  2133. (let* ((buf (get-file-buffer file))
  2134. (already-visiting-p buf))
  2135. (unless buf
  2136. (setq buf (find-file-noselect file t t)))
  2137. (unwind-protect
  2138. (progn (set-buffer buf)
  2139. (quack-parse-srfi-subindex-buffer kind))
  2140. ;; unwind-protect-cleanup
  2141. (unless already-visiting-p
  2142. (kill-buffer buf)))))))
  2143. (defconst quack-parse-srfi-index-buffer-re-1
  2144. (concat
  2145. "<LI><A HREF=\"?srfi-[0-9]+/?\"?>SRFI[ \t]+"
  2146. "\\([0-9]+\\)" ; #=1 srfi number
  2147. "</A>:?[ \t]*"
  2148. "\\(" ; #<2 srfi title
  2149. ; #=3
  2150. (quack-re-alt "[^\r\n<>]" "</?[a-z]+>")
  2151. "+"
  2152. "\\)"))
  2153. (defun quack-parse-srfi-subindex-buffer (kind)
  2154. (save-excursion
  2155. (let ((case-fold-search t)
  2156. (alist '()))
  2157. (goto-char (point-min))
  2158. (while (re-search-forward quack-parse-srfi-index-buffer-re-1 nil t)
  2159. (let ((number (string-to-number (quack-match-string-no-properties 1)))
  2160. (title (quack-without-side-whitespace
  2161. (quack-strip-limited-html-tags
  2162. (quack-match-string-no-properties 2)))))
  2163. (setq alist (cons
  2164. ;;(cons number
  2165. ;; (if (and kind (not (eq kind 'final)))
  2166. ;; (format "[%s] %s" kind title)
  2167. ;; title))
  2168. (list number kind title)
  2169. alist))))
  2170. (setq alist (reverse alist)))))
  2171. (defun quack-srfi-num-url (num)
  2172. (quack-srfi-master-url (list (format "srfi-%d" num)
  2173. (format "srfi-%d.html" num))))
  2174. (defconst quack-srfi-num-at-point-re-1
  2175. "srfi[-: \t]*\\([0-9]+\\)")
  2176. (defconst quack-srfi-num-at-point-re-2
  2177. ;; Note: We can't have "[^\r\n]*" as a prefix, since it's too slow.
  2178. (concat quack-srfi-num-at-point-re-1 "[^\r\n]*"))
  2179. (defun quack-srfi-num-at-point ()
  2180. ;; TODO: Make this get the nearest SRFI number in all cases.
  2181. (save-match-data
  2182. (let ((case-fold-search t))
  2183. (cond ((thing-at-point-looking-at quack-srfi-num-at-point-re-1)
  2184. (string-to-number (quack-match-string-no-properties 1)))
  2185. ((thing-at-point-looking-at "[0-9]+")
  2186. (string-to-number (quack-match-string-no-properties 0)))
  2187. ((thing-at-point-looking-at quack-srfi-num-at-point-re-2)
  2188. (string-to-number (quack-match-string-no-properties 1)))
  2189. ((let ((str (quack-line-at-point)))
  2190. (when (string-match quack-srfi-num-at-point-re-1 str)
  2191. (string-to-number
  2192. (quack-match-string-no-properties 1 str)))))))))
  2193. (defun quack-view-srfi (num)
  2194. (interactive (list (quack-srfi-num-prompt "View SRFI number")))
  2195. (when num
  2196. (unless (and (integerp num) (>= num 0))
  2197. (error "Not a valid SRFI number: %S" num))
  2198. (quack-browse-url (quack-srfi-num-url num))))
  2199. (defun quack-srfi-num-prompt (prompt)
  2200. (let* ((completes (quack-srfi-completes))
  2201. (default (quack-srfi-num-at-point))
  2202. (input (quack-without-side-whitespace
  2203. (completing-read
  2204. (if default
  2205. (format "%s (default %d): " prompt default)
  2206. (concat prompt ": "))
  2207. completes)))
  2208. v)
  2209. (cond ((or (not input) (string= "" input)) default)
  2210. ((setq v (assoc input completes)) (cdr v))
  2211. ((and (setq v (condition-case nil
  2212. (string-to-number input)
  2213. (error nil)))
  2214. (integerp v)
  2215. (>= v 0))
  2216. v)
  2217. (t (error "Invalid SRFI number: %s" input)))))
  2218. ;; Doc Keyword Value Object:
  2219. (defmacro quack-kw-get-syntax (o) `(aref ,o 0))
  2220. (defmacro quack-kw-get-file (o) `(aref ,o 1))
  2221. (defmacro quack-kw-get-fragment (o) `(aref ,o 2))
  2222. (defmacro quack-kw-set-syntax (o v) `(aset ,o 0 ,v))
  2223. (defmacro quack-kw-set-file (o v) `(aset ,o 1 ,v))
  2224. (defmacro quack-kw-set-fragment (o v) `(aset ,o 2 ,v))
  2225. ;; Documentation Object:
  2226. ;; TODO: Rework these document representations once we know the different kinds
  2227. ;; of documents with which we'll be dealing.
  2228. (defmacro quack-doc-get-type (o) `(aref ,o 0))
  2229. (defmacro quack-doc-get-sym (o) `(aref ,o 1))
  2230. (defmacro quack-doc-get-title (o) `(aref ,o 2))
  2231. (defmacro quack-doc-get-loc (o) `(aref ,o 3))
  2232. (defmacro quack-doc-get-kw-p (o) `(aref ,o 4))
  2233. (defmacro quack-doc-get-start-url (o) `(aref ,o 5))
  2234. (defmacro quack-doc-get-kw-base-url (o) `(aref ,o 6))
  2235. (defmacro quack-doc-get-kw-file (o) `(aref ,o 7))
  2236. (defmacro quack-doc-get-kw-hashtable (o) `(aref ,o 8))
  2237. (defmacro quack-doc-set-type (o v) `(aset ,o 0 ,v))
  2238. (defmacro quack-doc-set-sym (o v) `(aset ,o 1 ,v))
  2239. (defmacro quack-doc-set-title (o v) `(aset ,o 2 ,v))
  2240. (defmacro quack-doc-set-loc (o v) `(aset ,o 3 ,v))
  2241. (defmacro quack-doc-set-kw-p (o v) `(aset ,o 4 ,v))
  2242. (defmacro quack-doc-set-start-url (o v) `(aset ,o 5 ,v))
  2243. (defmacro quack-doc-set-kw-base-url (o v) `(aset ,o 6 ,v))
  2244. (defmacro quack-doc-set-kw-file (o v) `(aset ,o 7 ,v))
  2245. (defmacro quack-doc-set-kw-hashtable (o v) `(aset ,o 8 ,v))
  2246. (defun quack-manual-to-doc (manual)
  2247. ;; Accepts a user's manual preference object of the list form:
  2248. ;;
  2249. ;; (SYM TITLE LOC KW-P)
  2250. ;;
  2251. ;; and creates a manual doc object of the vector form:
  2252. ;;
  2253. ;; [manual SYM TITLE LOC KW-P START-URL KW-BASE-URL KW-FILE KW-P
  2254. ;; KEYWORDS]
  2255. ;;
  2256. ;; KEYWORDS is not populated here -- keywords importing for a manual happens
  2257. ;; the first time keyword searching is done for the manual."
  2258. (let ((sym (nth 0 manual))
  2259. (title (nth 1 manual))
  2260. (loc (nth 2 manual))
  2261. (kw-p (nth 3 manual))
  2262. (start-url nil)
  2263. (kw-file nil)
  2264. (kw-base nil))
  2265. (cond
  2266. ;; If the location is a string, then handle manual as simple URL.
  2267. ((stringp loc)
  2268. (setq start-url loc)
  2269. (when kw-p
  2270. (quack-warning "Quack can only use keywords for PLT manuals.")
  2271. (setq kw-p nil)))
  2272. ;; If the location is a symbol, handle manual as special.
  2273. ((symbolp loc)
  2274. (cond
  2275. ;; If the location is symbol `plt', handle manual as PLT bundled.
  2276. ((eq loc 'plt)
  2277. (let* ((plt-name (let ((s (symbol-name sym)))
  2278. (if (string-match "\\`plt-\\(.+\\)\\'" s)
  2279. (match-string 1 s)
  2280. s)))
  2281. (web-base (concat
  2282. "http://download.plt-scheme.org/doc/"
  2283. plt-name
  2284. "/"))
  2285. (index-name "index.htm")
  2286. (col-dirs quack-pltcollect-dirs))
  2287. ;; Search from the collection directories for keywords and index
  2288. ;; files. Note that we currently look for keywords files even if
  2289. ;; `kw-p' is false since we want to allow the user to dynamically
  2290. ;; enable and disable keywords searching for a particular manual
  2291. ;; without us having to change `quack-docs'.
  2292. (while (and col-dirs (not (and kw-file kw-base start-url)))
  2293. (let ((dir (expand-file-name plt-name
  2294. (expand-file-name "doc"
  2295. (car col-dirs)))))
  2296. (setq col-dirs (cdr col-dirs))
  2297. (when (file-directory-p dir)
  2298. (let* ((k-f (expand-file-name "keywords" dir))
  2299. (i-f (expand-file-name index-name dir))
  2300. (i-r (file-readable-p i-f)))
  2301. (if (file-readable-p k-f)
  2302. ;; Keywords file.
  2303. (if i-r
  2304. ;; Keywords file and index file. So, unless we
  2305. ;; already found a keywords base URL, set everything
  2306. ;; based on this directory. Note that we override
  2307. ;; any existing start URL because we prefer to use
  2308. ;; the same manual version for both keywords and
  2309. ;; non-keywords access.
  2310. (unless kw-base
  2311. (setq kw-file k-f)
  2312. (setq kw-base (quack-file-url dir nil))
  2313. (setq start-url (quack-file-url dir index-name)))
  2314. ;; Keywords file, but no index file. So, unless we
  2315. ;; already have a keywords file, set it to this one.
  2316. (unless kw-file
  2317. (setq kw-file k-f)))
  2318. ;; No keywords file. So, if there is an index file, and we
  2319. ;; don't already have one, then use this one.
  2320. (when (and i-r (not start-url))
  2321. (setq start-url (quack-file-url dir index-name))))))))
  2322. ;; If we didn't find a start URL, use the Web one.
  2323. (unless start-url
  2324. (setq start-url (concat web-base index-name)))
  2325. ;; Do we have a keywords file?
  2326. (if kw-file
  2327. ;; We have a keywords file, so set the keywords base to the Web
  2328. ;; if needed and desired. Note that we never use the keywords
  2329. ;; file from one directory with the HTML files from a different
  2330. ;; directory, on the assumption that a local copy of HTML missing
  2331. ;; a keywords file is suspect, and that the Web version is
  2332. ;; therefore preferable.
  2333. (when (or (eq quack-local-keywords-for-remote-manuals-p 'always)
  2334. (and (not kw-base)
  2335. quack-local-keywords-for-remote-manuals-p))
  2336. (setq kw-base web-base))
  2337. ;; We don't have a keywords file, so warn if the user wanted
  2338. ;; keywords for this manual.
  2339. (when kw-p
  2340. (quack-warning "Could not find keywords file for manual %S."
  2341. plt-name)))))
  2342. ;; The location is an unrecognized symbol, so just barf.
  2343. (t (quack-internal-error))))
  2344. ;; The location is something other than a string or symbol, so just barf.
  2345. (t (quack-internal-error)))
  2346. ;; We've populated all the variables for the location type, so return the
  2347. ;; representation.
  2348. (vector 'manual sym title loc kw-p start-url kw-base kw-file nil)))
  2349. (defun quack-doc-keyword-lookup (doc keyword)
  2350. (let ((ht (or (quack-doc-get-kw-hashtable doc)
  2351. (progn (quack-doc-import-keywords doc)
  2352. (quack-doc-get-kw-hashtable doc)))))
  2353. (if ht
  2354. (quack-gethash keyword ht nil)
  2355. (quack-warning "No keywords for document \"%S\"."
  2356. (quack-doc-get-sym doc))
  2357. nil)))
  2358. (defun quack-doc-import-keywords (doc)
  2359. (if (eq (quack-doc-get-loc doc) 'plt)
  2360. (quack-doc-import-plt-manual-keywords doc)
  2361. (quack-internal-error)))
  2362. (defun quack-doc-import-plt-manual-keywords (doc)
  2363. ;; Reads in the predetermined keywords file for PLT manual `doc' object,
  2364. ;; populating the `kw-hashtable' field of the `doc' object. The format of
  2365. ;; each entry in the PLT keywords file is a list of 5 strings:
  2366. ;;
  2367. ;; (KEYWORD SYNTAX FILE FRAGMENT SECTION)
  2368. ;;
  2369. ;; The hashtable is keyed on the KEYWORD string, for which the value is
  2370. ;; usually a vector:
  2371. ;;
  2372. ;; [SYNTAX FILE-CONST FRAGMENT]
  2373. ;;
  2374. ;; where FILE-CONST is the FILE string registered with the `quack-strconst'
  2375. ;; to save memory on redundant strings.
  2376. ;;
  2377. ;; When more there is more than one entry for a given keyword, then the value
  2378. ;; of the hashtable entry for that keyword is a list of vectors, in the order
  2379. ;; in which they were derived from the original keywords file.
  2380. ;;
  2381. ;; These duplicate values may be duplicated or conflicting, as in:
  2382. ;;
  2383. ;; (["(regexp-match pattern input-port [start-k end-k output-port])"
  2384. ;; "mzscheme-Z-H-10.html" "%_kw_definitionregexp-match"]
  2385. ;; ["(regexp-match pattern string [start-k end-k output-port])"
  2386. ;; "mzscheme-Z-H-10.html" "%_kw_definitionregexp-match"])
  2387. ;;
  2388. ;; No attempt is made here to weed out any duplicate/conflicting entries --
  2389. ;; that behavior left up to the code that accesses the hashtable. For the
  2390. ;; example above, a command to display the syntax for the keyword would need
  2391. ;; to display both values. However, a command to view the documentation for
  2392. ;; the keyword would need only to display one Web page without querying the
  2393. ;; user, since both entries above point to the same page and fragment.
  2394. (quack-activity
  2395. (format "Importing keywords for manual %S" (quack-doc-get-sym doc))
  2396. (let (sexp)
  2397. (garbage-collect)
  2398. (condition-case err
  2399. (setq sexp (quack-read-sexp-file
  2400. (or (quack-doc-get-kw-file doc)
  2401. (quack-warning "Manual %S has no keywords file."
  2402. (quack-doc-get-sym doc)))))
  2403. (error (quack-warning "Problem importing keywords for manual %S: %s"
  2404. (quack-doc-get-sym doc) err)))
  2405. (when sexp
  2406. (garbage-collect)
  2407. (let ((ht (quack-make-hash-table :test 'equal
  2408. :size (length sexp)
  2409. :rehash-threshold 1.0)))
  2410. ;; Note: We make the hashtable equal to the length of the read list of
  2411. ;; keyword forms so that it will be at least large enough for all the
  2412. ;; keywords without being excessively overlarge, and without having to
  2413. ;; do resizes or a counting pass or intermediate representation. The
  2414. ;; hashtable will be a little larger than necessary when there are
  2415. ;; multiple keyword forms for the same keyword. In a test with
  2416. ;; MzScheme 200.2, the hashtable used/size for "mzscheme" manual was
  2417. ;; 489/502; for "mzlib", 245/257.
  2418. (quack-doc-set-kw-hashtable doc ht)
  2419. (mapcar (function
  2420. (lambda (raw-entry)
  2421. (let* ((kw (nth 0 raw-entry))
  2422. (new (vector (nth 1 raw-entry)
  2423. (quack-strconst (nth 2 raw-entry))
  2424. (nth 3 raw-entry)))
  2425. (old (quack-gethash kw ht nil)))
  2426. (quack-puthash
  2427. kw
  2428. (cond ((not old) new)
  2429. ((vectorp old) (list old new))
  2430. ((listp old) (nconc old (list new))))
  2431. ht))))
  2432. sexp))))))
  2433. (defun quack-read-sexp-file (filename)
  2434. (save-excursion
  2435. (let* ((buf (generate-new-buffer "*quack-read-sexp-file*")))
  2436. (set-buffer buf)
  2437. (unwind-protect
  2438. (progn (insert-file-contents-literally filename)
  2439. (goto-char (point-min))
  2440. (read buf))
  2441. ;; unwind-protect cleanup
  2442. (kill-buffer buf)))))
  2443. ;; Documentation Database:
  2444. (defvar quack-docs 'invalid)
  2445. (defun quack-docs ()
  2446. (when (eq quack-docs 'invalid)
  2447. (quack-docs-build))
  2448. quack-docs)
  2449. (defun quack-docs-build ()
  2450. (quack-activity
  2451. "Building Quack docs database"
  2452. (quack-invalidate-manuals-caches)
  2453. (setq quack-docs (mapcar 'quack-manual-to-doc quack-manuals))))
  2454. (defun quack-docs-manual-lookup (sym)
  2455. (let ((docs (quack-docs))
  2456. (found nil))
  2457. (while (and docs (not found))
  2458. (let ((doc (car docs)))
  2459. (setq docs (cdr docs))
  2460. (when (eq (quack-doc-get-sym doc) sym)
  2461. (setq found doc))))
  2462. found))
  2463. (defun quack-docs-manual-keyword-lookup (keyword)
  2464. (let ((results '()))
  2465. (mapcar (function
  2466. (lambda (doc)
  2467. (cond
  2468. ((not (quack-doc-get-kw-p doc)) nil)
  2469. ((not (quack-doc-get-kw-base-url doc))
  2470. (quack-warning "Manual %S has no HTML."
  2471. (quack-doc-get-sym doc)))
  2472. (t (let ((match (quack-doc-keyword-lookup doc keyword)))
  2473. (cond
  2474. ((not match) nil)
  2475. ((vectorp match)
  2476. (setq results (cons (cons doc match) results)))
  2477. ((listp match)
  2478. (mapcar (function
  2479. (lambda (m)
  2480. (setq results (cons (cons doc m) results))))
  2481. match))
  2482. (t (quack-internal-error))))))))
  2483. (quack-docs))
  2484. (reverse results)))
  2485. ;; Keyword Lookup Match Object:
  2486. (defmacro quack-kwmatch-get-doc (o) `(car ,o))
  2487. (defmacro quack-kwmatch-get-kw (o) `(cdr ,o))
  2488. (defun quack-kwmatch-url (kwmatch)
  2489. (let ((doc (car kwmatch))
  2490. (kw (cdr kwmatch)))
  2491. (concat (quack-doc-get-kw-base-url doc)
  2492. (quack-quote-url-substring (quack-kw-get-file kw))
  2493. "#"
  2494. (quack-quote-url-substring (quack-kw-get-fragment kw) t))))
  2495. ;; Manual Viewing:
  2496. (defun quack-view-manual (&optional sym)
  2497. "View a manual."
  2498. (interactive
  2499. (list
  2500. (let* ((completes (or (quack-manuals-completes)
  2501. (error
  2502. "Sorry, variable \"quack-manuals\" is empty.")))
  2503. (default "R5RS")
  2504. (input (let ((completion-ignore-case t))
  2505. (completing-read
  2506. (format "Quack Manual (default %S): " default)
  2507. completes nil t nil nil default))))
  2508. (cdr (or (assoc input completes)
  2509. (error "No manual %S." input))))))
  2510. (quack-activity
  2511. (format "Viewing manual \"%S\"" sym)
  2512. (quack-browse-url (or (quack-doc-get-start-url
  2513. (or (quack-docs-manual-lookup sym)
  2514. (error "Manual \"%S\" not found." sym)))
  2515. (error "Don't know a URL for manual \"%S\"." sym)))))
  2516. (defvar quack-manuals-menu-cache 'invalid)
  2517. (defvar quack-manuals-completes-cache 'invalid)
  2518. (defun quack-invalidate-manuals-caches ()
  2519. (setq quack-docs 'invalid)
  2520. (setq quack-manuals-completes-cache 'invalid)
  2521. (setq quack-manuals-menu-cache 'invalid))
  2522. ;;(quack-invalidate-manuals-caches)
  2523. ;; This version maps completion strings to URLs.
  2524. ;; (defun quack-manuals-completes ()
  2525. ;; (when (eq quack-manuals-completes-cache 'invalid)
  2526. ;; (let ((completes '()))
  2527. ;; (mapcar (function
  2528. ;; (lambda (doc)
  2529. ;; (let ((sym (quack-doc-get-sym doc))
  2530. ;; (url (quack-doc-get-start-url doc)))
  2531. ;; (setq completes
  2532. ;; (cons (cons (quack-doc-get-title doc) url)
  2533. ;; (cons (cons (symbol-name sym) url)
  2534. ;; completes))))))
  2535. ;; (quack-docs))
  2536. ;; (setq quack-manuals-completes-cache (reverse completes))))
  2537. ;; quack-manuals-completes-cache)
  2538. (defun quack-manuals-completes ()
  2539. (when (eq quack-manuals-completes-cache 'invalid)
  2540. (let ((completes '()))
  2541. (mapcar (function
  2542. (lambda (doc)
  2543. (let ((sym (quack-doc-get-sym doc))
  2544. ;;(url (quack-doc-get-start-url doc))
  2545. )
  2546. (setq completes
  2547. (cons (cons (quack-doc-get-title doc) sym)
  2548. ;;(cons (cons (symbol-name sym) sym)
  2549. completes
  2550. ;;)
  2551. )))))
  2552. (quack-docs))
  2553. (setq quack-manuals-completes-cache (reverse completes))))
  2554. quack-manuals-completes-cache)
  2555. (defun quack-manuals-menu ()
  2556. (when (eq quack-manuals-menu-cache 'invalid)
  2557. (setq quack-manuals-menu-cache
  2558. (mapcar (function
  2559. (lambda (manual)
  2560. (let ((sym (nth 0 manual))
  2561. (title (nth 1 manual)))
  2562. `[,title (quack-view-manual (quote ,sym))])))
  2563. quack-manuals)))
  2564. quack-manuals-menu-cache)
  2565. (defun quack-manuals-webjump-sites ()
  2566. "Returns `webjump' entries for manuals in `quack-manuals'.
  2567. Can be used in your `~/.emacs' file something like this:
  2568. (require 'quack)
  2569. (require 'webjump)
  2570. (require 'webjump-plus)
  2571. (setq webjump-sites
  2572. (append my-own-manually-maintained-webjump-sites
  2573. (quack-manuals-webjump-sites)
  2574. webjump-plus-sites
  2575. webjump-sample-sites))"
  2576. ;; TODO: Note what they should do if they are adding to plt collectsion dirs
  2577. ;; via custom settings but quack-manuals-webjump-sites is getting
  2578. ;; called before then.
  2579. (let ((result '())
  2580. (quack-quiet-warnings-p t))
  2581. (mapcar (function
  2582. (lambda (doc)
  2583. (let ((url (quack-doc-get-start-url doc)))
  2584. (when url
  2585. (setq result (cons (cons (quack-doc-get-title doc) url)
  2586. result))))))
  2587. (quack-docs))
  2588. result))
  2589. ;; Keyword Docs Viewing:
  2590. ;; TODO: Add doc lookup in PLT "doc.txt" files. A little tricky. Maybe make
  2591. ;; sure doc.txt is a long-term format first.
  2592. (defun quack-view-keyword-docs (keyword)
  2593. ;; TODO: Don't prompt if all choices would result in the same URL.
  2594. (interactive (list (quack-prompt-for-keyword "View docs for keyword")))
  2595. (when (and keyword (stringp keyword) (not (string= keyword "")))
  2596. (let ((matches (quack-docs-manual-keyword-lookup keyword)))
  2597. (if (not matches)
  2598. (message "Sorry, no documentation found for keyword %S." keyword)
  2599. (quack-browse-url
  2600. (quack-kwmatch-url
  2601. (if (cdr matches)
  2602. (quack-prompt-for-kwmatch-choice "Which" matches)
  2603. (car matches))))))))
  2604. (defun quack-keyword-at-point ()
  2605. ;; TODO: Make sure this reads all Scheme symbols -- it may currently only
  2606. ;; read valid Elisp symbols.
  2607. (let ((bounds (bounds-of-thing-at-point 'symbol)))
  2608. ;; In some cases (point at beginning of empty buffer?), `bounds' will be
  2609. ;; the bounds of an empty string, so check this.
  2610. (when bounds
  2611. (let ((beg (car bounds))
  2612. (end (cdr bounds)))
  2613. (when (/= beg end)
  2614. (buffer-substring-no-properties beg end))))))
  2615. (defun quack-prompt-for-keyword (prompt)
  2616. (let* ((default (quack-keyword-at-point))
  2617. (history (list default)))
  2618. (read-string (if default
  2619. (format "%s (default %S): " prompt default)
  2620. (concat prompt ": "))
  2621. nil
  2622. ;; Note: Gratuitous reference to `history' eliminates warning
  2623. ;; from XEmacs 21 byte-compiler.
  2624. (if (and default history) 'history nil)
  2625. default)))
  2626. (defun quack-prompt-for-kwmatch-choice (prompt kwmatch-list)
  2627. (let ((completes '()))
  2628. ;; Build the completion alist, ensure each key is unique.
  2629. (mapcar
  2630. (function
  2631. (lambda (kwmatch)
  2632. (let* ((kw (quack-kwmatch-get-kw kwmatch))
  2633. (orig-name (or (quack-kw-get-syntax kw)
  2634. (progn (quack-warning "No keyword syntax: %s"
  2635. kw)
  2636. "???")))
  2637. (name orig-name)
  2638. (name-tries 1))
  2639. ;; Ensure the name is unique within the completion list thus far.
  2640. (while (assoc name completes)
  2641. (setq name-tries (1+ name-tries))
  2642. (setq name (format "%s #%d" orig-name name-tries)))
  2643. ;; Prepend to the completion list (we'll reverse the list later).
  2644. (setq completes (cons (cons name kwmatch) completes)))))
  2645. kwmatch-list)
  2646. (setq completes (reverse completes))
  2647. ;; Prompt user and return selection.
  2648. (let* ((default (car (car completes)))
  2649. (read (let ((completion-ignore-case t))
  2650. (completing-read
  2651. (format "%s (default %S): " prompt default)
  2652. completes nil t nil nil default))))
  2653. (cdr (assoc read completes)))))
  2654. ;; Inferior Process:
  2655. (defvar quack-run-scheme-prompt-history '())
  2656. (defun quack-remember-program-maybe (program)
  2657. (when (and quack-remember-new-programs-p
  2658. (not (member program quack-programs)))
  2659. (quack-option-set 'quack-programs (cons program quack-programs) t)
  2660. (message "Remembering program %S." program)))
  2661. (defun quack-run-scheme-prompt ()
  2662. (let* ((last (car quack-run-scheme-prompt-history))
  2663. (default (or (and quack-run-scheme-prompt-defaults-to-last-p
  2664. last)
  2665. quack-default-program
  2666. scheme-program-name
  2667. last
  2668. "mzscheme"))
  2669. (program (let ((minibuffer-allow-text-properties nil))
  2670. (completing-read
  2671. (concat "Run Scheme"
  2672. (if default
  2673. (format " (default %S)" default)
  2674. "")
  2675. ": ")
  2676. (quack-run-scheme-prompt-completion-collection)
  2677. nil nil nil
  2678. 'quack-run-scheme-prompt-history
  2679. default))))
  2680. (quack-remember-program-maybe program)
  2681. program))
  2682. (defun quack-run-scheme-prompt-completion-collection ()
  2683. (let ((program-list quack-programs))
  2684. (mapcar (function (lambda (program)
  2685. (and program
  2686. (not (member program program-list))
  2687. (setq program-list (cons program program-list)))))
  2688. (list quack-default-program
  2689. scheme-program-name))
  2690. (mapcar (function (lambda (program) (cons program nil)))
  2691. program-list)))
  2692. (defadvice run-scheme (around quack-ad-run first nil activate)
  2693. "Adds prompting for which Scheme interpreter program to run."
  2694. ;; We don't want to prompt if there's already a Scheme running, but it's
  2695. ;; possible for process to die between the comint check in `interactive' form
  2696. ;; of this advice and the comint check in the `run-scheme' function. We
  2697. ;; should override `run-scheme' altogether, but for now let's only call the
  2698. ;; original in the case that we do not detect a running Scheme.
  2699. (interactive (list (cond ((comint-check-proc "*scheme*") nil)
  2700. ((or current-prefix-arg
  2701. quack-run-scheme-always-prompts-p)
  2702. (quack-run-scheme-prompt))
  2703. (t quack-default-program))))
  2704. (if cmd
  2705. ;; We will assume there is no running Scheme, so... Since `run-scheme'
  2706. ;; calls `pop-to-buffer' rather than `switch-to-scheme', our options for
  2707. ;; Scheme process window management, such as putting the process buffer
  2708. ;; window in its own frame, do not take effect when the process buffer is
  2709. ;; displayed by `run-scheme'. So, unless we are using the `cmuscheme'
  2710. ;; window management behavior, we attempt to undo whatever window changes
  2711. ;; and buffer changes `run-scheme' makes, then just call
  2712. ;; `switch-to-scheme'. (This code will be revisited once we decide how
  2713. ;; to handle multiple Schemes, if not before then.)
  2714. (let ((buf (current-buffer))
  2715. (wg (current-window-configuration)))
  2716. ad-do-it
  2717. (unless (or (not quack-switch-to-scheme-method)
  2718. (eq quack-switch-to-scheme-method 'cmuscheme))
  2719. (set-window-configuration wg)
  2720. (set-buffer buf)
  2721. (switch-to-scheme t))
  2722. (message "Started Scheme: %s" scheme-program-name))
  2723. ;; There is a running Scheme, so don't call the `run-scheme' function at
  2724. ;; all -- just call `switch-to-scheme' or duplicate the `cmuscheme'
  2725. ;; package's `pop-to-buffer' behavior.
  2726. (if (or (not quack-switch-to-scheme-method)
  2727. (eq quack-switch-to-scheme-method 'cmuscheme))
  2728. (pop-to-buffer "*scheme*")
  2729. (switch-to-scheme t))
  2730. (message "Switched to running Scheme: %s" scheme-program-name)))
  2731. (defadvice scheme-interactively-start-process (around
  2732. quack-ad-sisp
  2733. first
  2734. (&optional cmd)
  2735. activate)
  2736. ;; (save-window-excursion
  2737. (call-interactively 'run-scheme)
  2738. ;; )
  2739. )
  2740. (defadvice scheme-proc (around quack-ad-scheme-proc first nil activate)
  2741. (condition-case nil
  2742. ad-do-it
  2743. (error (message "Oops, we must start a Scheme process!")
  2744. (call-interactively 'run-scheme)
  2745. (setq ad-return-value (scheme-proc)))))
  2746. ;; Switch-to-Scheme:
  2747. (defun quack-force-frame-switch-to-window (win)
  2748. (let ((frame (window-frame win)))
  2749. (unless (eq frame (selected-frame))
  2750. (and window-system
  2751. quack-warp-pointer-to-frame-p
  2752. (set-mouse-position frame 0 0))
  2753. (select-frame frame))
  2754. (select-window win)))
  2755. (defadvice switch-to-scheme (before quack-ad-switch last nil activate)
  2756. "Adds support for the `quack-switch-to-scheme-method' option."
  2757. ;; This can be done as before-advice since the `pop-to-buffer' that
  2758. ;; `switch-to-scheme' is using appears to always be a no-op when the target
  2759. ;; buffer is already the current buffer.
  2760. (require 'cmuscheme)
  2761. ;; The `eval' below is to avoid problems with the byte-compiler and advising.
  2762. ;; It doesn't seem to like: (and (boundp 'SYM) SYM)
  2763. (let ((repl-buf (eval '(and (boundp 'scheme-buffer)
  2764. scheme-buffer
  2765. (get-buffer scheme-buffer)))))
  2766. (cond ((not repl-buf)
  2767. (error (concat "No process current buffer."
  2768. " Set `scheme-buffer' or execute `run-scheme'")))
  2769. ((or (not quack-switch-to-scheme-method)
  2770. (eq quack-switch-to-scheme-method 'cmuscheme))
  2771. nil)
  2772. ((eq (current-buffer) repl-buf) nil)
  2773. ((eq quack-switch-to-scheme-method 'other-window)
  2774. (switch-to-buffer-other-window repl-buf))
  2775. ;; The following code may be revived if anyone reports problems with
  2776. ;; the use of `special-display-popup-frame'.
  2777. ;;
  2778. ;; ((eq quack-switch-to-scheme-method 'own-frame)
  2779. ;; (let ((pop-up-frames t)
  2780. ;; (same-window-buffer-names nil)
  2781. ;; (same-window-regexps nil)
  2782. ;; (special-display-buffer-names nil)
  2783. ;; (special-display-regexps nil))
  2784. ;; (switch-to-buffer (pop-to-buffer repl-buf))))
  2785. ((eq quack-switch-to-scheme-method 'own-frame)
  2786. (quack-force-frame-switch-to-window
  2787. (special-display-popup-frame repl-buf)))
  2788. (t (error "Invalid quack-switch-to-scheme-method: %S"
  2789. quack-switch-to-scheme-method)))))
  2790. ;; Customize:
  2791. (defun quack-customize ()
  2792. "Customize the Quack package."
  2793. (interactive)
  2794. (customize-group 'quack))
  2795. ;; Auto Modes:
  2796. (defun quack-add-auto-mode-alist (alist)
  2797. (setq auto-mode-alist
  2798. (append alist
  2799. (let ((retained '()))
  2800. (mapcar (function (lambda (pair)
  2801. (unless (assoc (car pair) alist)
  2802. (setq retained (cons pair retained)))))
  2803. auto-mode-alist)
  2804. (reverse retained)))))
  2805. (quack-add-auto-mode-alist '(("\\.ccl\\'" . scheme-mode)
  2806. ("\\.rkt\\'" . scheme-mode)
  2807. ("\\.rktd\\'" . scheme-mode)
  2808. ("\\.sch\\'" . scheme-mode)
  2809. ("\\.scm\\'" . scheme-mode)
  2810. ("\\.ss\\'" . scheme-mode)
  2811. ("\\.stk\\'" . scheme-mode)
  2812. ("\\.stklos\\'" . scheme-mode)
  2813. ;;
  2814. ("/\\.mzschemerc\\'" . scheme-mode)
  2815. ;; Non-Scheme:
  2816. ("\\.plt\\'" . quack-pltfile-mode)))
  2817. ;; Syntax Table:
  2818. (defmacro quack-str-syntax (str)
  2819. `(,(if (and quack-gnuemacs-p (>= emacs-major-version 21))
  2820. 'string-to-syntax
  2821. 'quack-kludged-string-to-syntax)
  2822. ,str))
  2823. (defun quack-kludged-string-to-syntax (str)
  2824. (let* ((str-len (length str))
  2825. (code (aref str 0))
  2826. (matches (if (> str-len 1) (aref str 1)))
  2827. (result (cond ((= code 32) 0)
  2828. ((= code ?_) 3)
  2829. (t (quack-internal-error))))
  2830. (i 2))
  2831. (while (< i str-len)
  2832. (let ((c (aref str i)))
  2833. (setq i (1+ i))
  2834. (setq result (logior result
  2835. (lsh 1 (cond ((= c ?1) 16)
  2836. ((= c ?2) 17)
  2837. ((= c ?3) 18)
  2838. ((= c ?4) 19)
  2839. ((= c ?p) 20)
  2840. ((= c ?b) 21)
  2841. ((= c ?n) 21)
  2842. (t (quack-internal-error))))))))
  2843. (cons result (if (= matches 32) nil matches))))
  2844. ;; Note: We are assuming that it is better to endeavor to fontify all "#|"
  2845. ;; block comments as nestable rather than as unnestable, regardless of
  2846. ;; whether or not a user's target Scheme dialect supports nested.
  2847. (defconst quack-pound-syntax-string (if quack-gnuemacs-p "_ p14bn" "_ p14b"))
  2848. ;; (defconst quack-bar-syntax-string (if quack-gnuemacs-p " 23bn" " 23b"))
  2849. (defconst quack-bar-syntax-string (if quack-gnuemacs-p "_ 23bn" "_ 23b"))
  2850. (defconst quack-pound-syntax (quack-str-syntax quack-pound-syntax-string))
  2851. (defconst quack-bar-syntax (quack-str-syntax quack-bar-syntax-string))
  2852. (modify-syntax-entry ?# quack-pound-syntax-string scheme-mode-syntax-table)
  2853. (modify-syntax-entry ?| quack-bar-syntax-string scheme-mode-syntax-table)
  2854. ;; Note: Unclear why, but `scheme.el' in GNU Emacs 21.2 is doing
  2855. ;; `(set-syntax-table scheme-mode-syntax-table)' in whatever buffer is
  2856. ;; active at the time the Elisp package is loaded.
  2857. ;; Indent Properties:
  2858. (put 'begin0 'scheme-indent-function 1)
  2859. (put 'c-declare 'scheme-indent-function 0)
  2860. (put 'c-lambda 'scheme-indent-function 2)
  2861. (put 'call-with-input-file 'scheme-indent-function 1)
  2862. (put 'call-with-input-file* 'scheme-indent-function 1)
  2863. (put 'call-with-output-file 'scheme-indent-function 1)
  2864. (put 'call-with-output-file* 'scheme-indent-function 1)
  2865. (put 'call-with-semaphore 'scheme-indent-function 1)
  2866. (put 'case-lambda 'scheme-indent-function 0)
  2867. (put 'catch 'scheme-indent-function 1)
  2868. (put 'chicken-setup 'scheme-indent-function 1)
  2869. (put 'class 'scheme-indent-function 'defun)
  2870. (put 'class* 'scheme-indent-function 'defun)
  2871. (put 'compound-unit/sig 'scheme-indent-function 0)
  2872. (put 'defboolparam 'scheme-indent-function 2)
  2873. (put 'defform 'scheme-indent-function 1)
  2874. (put 'defform* 'scheme-indent-function 1)
  2875. (put 'defform*/subs 'scheme-indent-function 2)
  2876. (put 'defform/none 'scheme-indent-function 1)
  2877. (put 'defform/subs 'scheme-indent-function 2)
  2878. (put 'defidform 'scheme-indent-function 1)
  2879. (put 'define-runtime-path 'scheme-indent-function 1)
  2880. (put 'define-sequence-id 'scheme-indent-function 1)
  2881. (put 'define: 'scheme-indent-function 3)
  2882. (put 'defparam 'scheme-indent-function 3)
  2883. (put 'defproc 'scheme-indent-function 2)
  2884. (put 'defproc* 'scheme-indent-function 1)
  2885. (put 'defstruct 'scheme-indent-function 2)
  2886. (put 'defstruct* 'scheme-indent-function 2)
  2887. (put 'defthing 'scheme-indent-function 2)
  2888. (put 'deftogether 'scheme-indent-function 1)
  2889. (put 'do 'scheme-indent-function 2)
  2890. (put 'dynamic-wind 'scheme-indent-function 0)
  2891. (put 'filebox 'scheme-indent-function 1)
  2892. (put 'for 'scheme-indent-function 1)
  2893. (put 'for* 'scheme-indent-function 1)
  2894. (put 'for*/and 'scheme-indent-function 1)
  2895. (put 'for*/first 'scheme-indent-function 1)
  2896. (put 'for*/fold 'scheme-indent-function 2)
  2897. (put 'for*/fold/derived 'scheme-indent-function 3)
  2898. (put 'for*/hash 'scheme-indent-function 1)
  2899. (put 'for*/hasheq 'scheme-indent-function 1)
  2900. (put 'for*/hasheqv 'scheme-indent-function 1)
  2901. (put 'for*/last 'scheme-indent-function 1)
  2902. (put 'for*/list 'scheme-indent-function 1)
  2903. (put 'for*/lists 'scheme-indent-function 2)
  2904. (put 'for*/or 'scheme-indent-function 1)
  2905. (put 'for*/product 'scheme-indent-function 1)
  2906. (put 'for*/sum 'scheme-indent-function 1)
  2907. (put 'for*/vector 'scheme-indent-function 1)
  2908. (put 'for*/vector 'scheme-indent-function 1)
  2909. (put 'for/and 'scheme-indent-function 1)
  2910. (put 'for/first 'scheme-indent-function 1)
  2911. (put 'for/fold 'scheme-indent-function 2)
  2912. (put 'for/fold 'scheme-indent-function 2)
  2913. (put 'for/fold/derived 'scheme-indent-function 3)
  2914. (put 'for/hash 'scheme-indent-function 1)
  2915. (put 'for/hasheq 'scheme-indent-function 1)
  2916. (put 'for/hasheqv 'scheme-indent-function 1)
  2917. (put 'for/last 'scheme-indent-function 1)
  2918. (put 'for/list 'scheme-indent-function 1)
  2919. (put 'for/lists 'scheme-indent-function 2)
  2920. (put 'for/or 'scheme-indent-function 1)
  2921. (put 'for/product 'scheme-indent-function 1)
  2922. (put 'for/sum 'scheme-indent-function 1)
  2923. (put 'for/vector 'scheme-indent-function 1)
  2924. (put 'instantiate 'scheme-indent-function 2)
  2925. (put 'interface 'scheme-indent-function 1)
  2926. (put 'lambda/kw 'scheme-indent-function 1)
  2927. (put 'let*-values 'scheme-indent-function 1)
  2928. (put 'let*: 'scheme-indent-function 'quack-let-colon-indent)
  2929. (put 'let+ 'scheme-indent-function 1)
  2930. (put 'let-values 'scheme-indent-function 1)
  2931. (put 'let/ec 'scheme-indent-function 1)
  2932. (put 'let: 'scheme-indent-function 'quack-let-colon-indent)
  2933. (put 'letrec-values 'scheme-indent-function 1)
  2934. (put 'match 'scheme-indent-function 1)
  2935. (put 'match-let 'scheme-indent-function 1)
  2936. (put 'mixin 'scheme-indent-function 2)
  2937. (put 'module 'scheme-indent-function 'defun)
  2938. (put 'module 'scheme-indent-function 2)
  2939. (put 'module* 'scheme-indent-function 2)
  2940. (put 'module+ 'scheme-indent-function 1)
  2941. (put 'opt-lambda 'scheme-indent-function 1)
  2942. (put 'parameterize 'scheme-indent-function 1)
  2943. (put 'parameterize* 'scheme-indent-function 1)
  2944. (put 'parameterize-break 'scheme-indent-function 1)
  2945. (put 'quasisyntax/loc 'scheme-indent-function 1)
  2946. (put 'receive 'scheme-indent-function 2)
  2947. (put 'send* 'scheme-indent-function 1)
  2948. (put 'sigaction 'scheme-indent-function 1)
  2949. (put 'specform 'scheme-indent-function 1)
  2950. (put 'specspecsubform 'scheme-indent-function 1)
  2951. (put 'specspecsubform/subs 'scheme-indent-function 2)
  2952. (put 'specsubform 'scheme-indent-function 1)
  2953. (put 'specsubform/subs 'scheme-indent-function 2)
  2954. (put 'struct 'scheme-indent-function 1)
  2955. (put 'sxml-match 'scheme-indent-function 1)
  2956. (put 'syntax-case 'scheme-indent-function 2)
  2957. (put 'syntax-parse 'scheme-indent-function 1)
  2958. (put 'syntax/loc 'scheme-indent-function 1)
  2959. (put 'test-section 'scheme-indent-function 1)
  2960. (put 'unit 'scheme-indent-function 'defun)
  2961. (put 'unit/sig 'scheme-indent-function 2)
  2962. (put 'unless 'scheme-indent-function 1)
  2963. (put 'when 'scheme-indent-function 1)
  2964. (put 'while 'scheme-indent-function 1)
  2965. (put 'with-handlers 'scheme-indent-function 1)
  2966. (put 'with-handlers* 'scheme-indent-function 1)
  2967. (put 'with-method 'scheme-indent-function 1)
  2968. (put 'with-syntax 'scheme-indent-function 1)
  2969. (defun quack-let-colon-indent (state indent-point normal-indent)
  2970. ;; Note: This was adapted from "scheme.el" "scheme-let-indent".
  2971. (skip-chars-forward " \t")
  2972. (if (looking-at "[-a-zA-Z0-9+*/?!@$%^&_:~]")
  2973. (lisp-indent-specform 4 state indent-point normal-indent)
  2974. (lisp-indent-specform 1 state indent-point normal-indent)))
  2975. ;; Keymaps:
  2976. (defvar quack-scheme-mode-keymap nil)
  2977. (setq quack-scheme-mode-keymap (make-sparse-keymap))
  2978. ;; TODO: Maybe have an option to also map the Ctrl variants of each of these
  2979. ;; keys to their respective bindings. As Eli pointed out, `C-c C-q C-x'
  2980. ;; is arguably easier to type than `C-c C-q x'. Actually, though, I
  2981. ;; don't like the `C-c C-q' prefix at all -- it signifies everything that
  2982. ;; is wrong with traditional modifier-happy Emacs keybindings. Maybe we
  2983. ;; should encourage users to set the prefix to some other key, like an
  2984. ;; unmodified function key.
  2985. (define-key quack-scheme-mode-keymap "f" 'quack-find-file)
  2986. (define-key quack-scheme-mode-keymap "k" 'quack-view-keyword-docs)
  2987. (define-key quack-scheme-mode-keymap "m" 'quack-view-manual)
  2988. (define-key quack-scheme-mode-keymap "r" 'run-scheme)
  2989. (define-key quack-scheme-mode-keymap "s" 'quack-view-srfi)
  2990. (define-key quack-scheme-mode-keymap "l" 'quack-toggle-lambda)
  2991. (define-key quack-scheme-mode-keymap "t" 'quack-tidy-buffer)
  2992. ;; Menus:
  2993. (defmacro quack-bool-menuitem (title var &rest rest)
  2994. (unless (stringp title) (quack-internal-error))
  2995. (unless (symbolp var) (quack-internal-error))
  2996. `[,title (quack-option-toggle (quote ,var)) :style toggle :selected ,var
  2997. ,@rest])
  2998. (defmacro quack-radio-menuitems (var alist)
  2999. (unless (symbolp var) (quack-internal-error))
  3000. (unless (listp alist) (quack-internal-error))
  3001. `(quote ,(mapcar
  3002. (function (lambda (pair)
  3003. (let ((title (car pair))
  3004. (value (cdr pair)))
  3005. (unless (stringp title) (quack-internal-error))
  3006. (unless (symbolp value) (quack-internal-error))
  3007. `[,title
  3008. (quack-option-set (quote ,var) (quote ,value))
  3009. :style radio
  3010. :selected (eq ,var (quote ,value))])))
  3011. alist)))
  3012. (defconst quack-browser-radio-alist
  3013. '((nil . "(Browse-URL Default)")
  3014. (browse-url-galeon . "Galeon")
  3015. (browse-url-mozilla . "Mozilla")
  3016. (browse-url-kde . "KDE Konqueror")
  3017. (browse-url-netscape . "Netscape Navigator")
  3018. (browse-url-w3 . "Emacs W3")
  3019. (w3m-browse-url . "W3M")
  3020. (quack-w3m-browse-url-other-window . "W3M (in other window)")
  3021. (browse-url-lynx-xterm . "Lynx in Xterm")
  3022. (browse-url-lynx-emacs . "Lynx in Emacs")
  3023. (browse-url-default-windows-browser . "MS Windows Default")))
  3024. (defconst quack-global-menuspec
  3025. `("Quack"
  3026. ["About Quack..." quack-about]
  3027. ("Options"
  3028. ("Startup Options"
  3029. "These settings take full effect"
  3030. "once Emacs is restarted."
  3031. "---"
  3032. ,(quack-bool-menuitem "Put Quack on Global Menu Bar" quack-global-menu-p)
  3033. ,(quack-bool-menuitem "Remap Find-File Bindings"
  3034. quack-remap-find-file-bindings-p)
  3035. "---"
  3036. ["Quack Directory..." (customize-option 'quack-dir)]
  3037. ["Quack Scheme Mode Keymap Prefix..."
  3038. (customize-option 'quack-scheme-mode-keymap-prefix)])
  3039. "---"
  3040. ("Default Program" :filter quack-defaultprogram-menufilter)
  3041. ,(quack-bool-menuitem "Always Prompt for Program"
  3042. quack-run-scheme-always-prompts-p)
  3043. ,(quack-bool-menuitem "Program Prompt Defaults to Last"
  3044. quack-run-scheme-prompt-defaults-to-last-p)
  3045. ,(quack-bool-menuitem "Remember New Programs"
  3046. quack-remember-new-programs-p)
  3047. "---"
  3048. ("Newline Behavior"
  3049. ,@(quack-radio-menuitems
  3050. quack-newline-behavior
  3051. (("Newline" . newline)
  3052. ("Newline-Indent" . newline-indent)
  3053. ("Indent-Newline-Indent" . indent-newline-indent))))
  3054. ,(quack-bool-menuitem "Smart Open-Paren"
  3055. quack-smart-open-paren-p)
  3056. ("Switch-to-Scheme Method"
  3057. ,@(quack-radio-menuitems quack-switch-to-scheme-method
  3058. (("Other Window" . other-window)
  3059. ("Own Frame" . own-frame)
  3060. ("Cmuscheme Behavior" . cmuscheme)))
  3061. "---"
  3062. ,(quack-bool-menuitem
  3063. "Warp Pointer to Frame"
  3064. quack-warp-pointer-to-frame-p
  3065. :active (eq quack-switch-to-scheme-method 'own-frame)))
  3066. ("Fontification"
  3067. ,@(quack-radio-menuitems quack-fontify-style
  3068. (("PLT Style" . plt)
  3069. ("Extended GNU Emacs Style" . emacs)
  3070. ("Emacs Default" . nil)))
  3071. "---"
  3072. ,(quack-bool-menuitem "Pretty Lambda \(in PLT Style\)"
  3073. quack-pretty-lambda-p
  3074. :active (and quack-pretty-lambda-supported-p
  3075. (memq quack-fontify-style '(plt))))
  3076. ,(quack-bool-menuitem "Fontify Definition Names \(in PLT Style\)"
  3077. quack-pltish-fontify-definition-names-p
  3078. :active (eq quack-fontify-style 'plt))
  3079. ,(quack-bool-menuitem "Fontify Syntax Keywords \(in PLT Style\)"
  3080. quack-pltish-fontify-keywords-p
  3081. :active (eq quack-fontify-style 'plt))
  3082. ;; TODO: Add menuitem here for "Fontify #: Keywords \(in PLT Style\)"
  3083. ,(quack-bool-menuitem "Fontify 3-Semicolon Comments \(in PLT Style\)"
  3084. quack-fontify-threesemi-p
  3085. :active (memq quack-fontify-style '(plt)))
  3086. )
  3087. ("Web Browser"
  3088. ,@(mapcar (function
  3089. (lambda (n)
  3090. (let ((func (car n))
  3091. (title (cdr n)))
  3092. `[,title
  3093. (quack-option-set 'quack-browse-url-browser-function
  3094. (quote ,func))
  3095. :style radio
  3096. :selected ,(if (not func)
  3097. '(not quack-browse-url-browser-function)
  3098. `(eq quack-browse-url-browser-function
  3099. (quote ,func)))])))
  3100. quack-browser-radio-alist)
  3101. ["(Other)..."
  3102. (customize-option 'quack-browse-url-browser-function)
  3103. :style radio
  3104. :selected (not (assq quack-browse-url-browser-function
  3105. quack-browser-radio-alist))])
  3106. ,(quack-bool-menuitem "Tab Characters are Evil" quack-tabs-are-evil-p)
  3107. ("Local Keywords for Remote Manuals"
  3108. ,@(quack-radio-menuitems
  3109. quack-local-keywords-for-remote-manuals-p
  3110. (("Permit" . t)
  3111. ("Forbid" . nil)
  3112. ("Always" . always))))
  3113. ["PLT Collection Directories..."
  3114. (customize-option 'quack-pltcollect-dirs)]
  3115. "---"
  3116. ["Customize..." quack-customize])
  3117. "---"
  3118. ["Run Scheme" run-scheme]
  3119. ["Switch to Scheme Buffer" switch-to-scheme]
  3120. "---"
  3121. ("View Manual" :filter quack-view-manual-menufilter)
  3122. ("View SRFI" :filter quack-view-srfi-menufilter)
  3123. ["View Keyword Docs..." quack-view-keyword-docs]
  3124. ["Dired on PLT Collection..." quack-dired-pltcollect]))
  3125. (defun quack-install-global-menu ()
  3126. (when quack-global-menu-p
  3127. (quack-when-gnuemacs
  3128. (unless (assq 'Quack menu-bar-final-items)
  3129. (setq menu-bar-final-items (cons 'Quack menu-bar-final-items)))
  3130. (easy-menu-define quack-global-menu global-map ""
  3131. quack-global-menuspec))
  3132. (quack-when-xemacs
  3133. ;; Die! Die! Die!
  3134. ;;(mapcar (function (lambda (n)
  3135. ;;(delete-menu-item '("Quack") n)
  3136. ;;(add-submenu nil quack-global-menuspec "Help" n)))
  3137. ;;(list
  3138. ;;;;current-menubar
  3139. ;;default-menubar
  3140. ;;))
  3141. (delete-menu-item '("Quack") current-menubar)
  3142. (add-submenu nil quack-global-menuspec "Help" current-menubar)
  3143. (set-menubar-dirty-flag))))
  3144. ;; TODO: We should make sure the user's custom settings have been loaded
  3145. ;; before we do this.
  3146. (quack-install-global-menu)
  3147. ;; And die some more!
  3148. ;;(quack-when-xemacs (add-hook 'after-init-hook 'quack-install-global-menu))
  3149. (defconst quack-scheme-mode-menuspec
  3150. `("Scheme"
  3151. ("Quack Global" ,@(cdr quack-global-menuspec))
  3152. "---"
  3153. ["Toggle Lambda Syntax" quack-toggle-lambda]
  3154. ["Tidy Buffer Formatting" quack-tidy-buffer]
  3155. ["Comment-Out Region" comment-region]
  3156. ["Un-Comment-Out Region" quack-uncomment-region]
  3157. "---"
  3158. ["Evaluate Last S-expression" scheme-send-last-sexp]
  3159. ["Evaluate Region" scheme-send-region]
  3160. ["Evaluate Region & Go" scheme-send-region-and-go]
  3161. ["Evaluate Last Definition" scheme-send-definition]
  3162. ["Evaluate Last Definition & Go" scheme-send-definition-and-go]
  3163. ["Compile Definition" scheme-compile-definition]
  3164. ["Compile Definition & Go" scheme-compile-definition-and-go]
  3165. ["Load Scheme File" scheme-load-file]
  3166. ["Compile Scheme File" scheme-compile-file]
  3167. "---"
  3168. ["View Keyword Docs..." quack-view-keyword-docs]
  3169. ["Quack Find File" quack-find-file]))
  3170. (defvar quack-scheme-mode-menu)
  3171. (quack-when-gnuemacs
  3172. (let ((map (make-sparse-keymap)))
  3173. (setq quack-scheme-mode-menu nil)
  3174. (easy-menu-define quack-scheme-mode-menu map ""
  3175. quack-scheme-mode-menuspec)
  3176. (define-key scheme-mode-map [menu-bar scheme]
  3177. (cons "Scheme"
  3178. (or (lookup-key map [menu-bar Scheme])
  3179. (lookup-key map [menu-bar scheme]))))))
  3180. (defun quack-view-manual-menufilter (arg)
  3181. (quack-menufilter-return "quack-view-manual-menufilter-menu"
  3182. (quack-manuals-menu)))
  3183. (defun quack-view-srfi-menufilter (arg)
  3184. (quack-menufilter-return
  3185. "quack-view-srfi-menufilter-menu"
  3186. (condition-case nil
  3187. (quack-srfi-menu t)
  3188. ;; TODO: Move the generation of this fallback menu down to
  3189. ;; quack-srfi-menu.
  3190. (error '(["Update SRFI Index" quack-update-srfi-index]
  3191. "---"
  3192. ("Draft" :active nil "")
  3193. ("Final" :active nil "")
  3194. ("Withdrawn" :active nil "")
  3195. ["Other SRFI..." quack-view-srfi])))))
  3196. (defun quack-defaultprogram-menufilter (arg)
  3197. (quack-menufilter-return
  3198. "quack-defaultprogram-menufilter-menu"
  3199. `(,@(quack-optionmenu-items-setdefaultprogram)
  3200. "---"
  3201. ["Other Program..." quack-set-other-default-program]
  3202. "---"
  3203. ("Forget Program"
  3204. ,@(mapcar
  3205. (function
  3206. (lambda (program)
  3207. `[,(format "Forget %s" program)
  3208. (quack-forget-program ,program)]))
  3209. quack-programs)))))
  3210. (defun quack-optionmenu-items-setdefaultprogram ()
  3211. (let* ((programs (quack-sort-string-list-copy quack-programs))
  3212. (add-default-p (and quack-default-program
  3213. (not (member quack-default-program programs)))))
  3214. (and add-default-p
  3215. (setq programs (cons quack-default-program programs)))
  3216. (mapcar
  3217. (function
  3218. (lambda (program)
  3219. (let* ((selected-p (and quack-default-program
  3220. (equal program quack-default-program))))
  3221. `[,(format "%s%s"
  3222. program
  3223. (if (and add-default-p
  3224. (equal program quack-default-program))
  3225. " (temporary)"
  3226. ""))
  3227. (quack-option-set 'quack-default-program ,program)
  3228. :style radio :selected ,selected-p])))
  3229. programs)))
  3230. (mapcar (function (lambda (sym) (put sym 'menu-enable 'mark-active)))
  3231. '(comment-region
  3232. indent-region
  3233. quack-uncomment-region
  3234. scheme-send-region
  3235. scheme-send-region-and-go))
  3236. ;; Option Menu Callbacks:
  3237. (defun quack-set-other-default-program ()
  3238. (interactive)
  3239. (let* ((minibuffer-allow-text-properties nil)
  3240. (program (quack-without-side-whitespace
  3241. (read-string "Other Default Program: "))))
  3242. (if (string= program "")
  3243. (message "Default program unchanged.")
  3244. (quack-remember-program-maybe program)
  3245. (quack-option-set 'quack-default-program
  3246. program))))
  3247. (defun quack-forget-program (program)
  3248. (setq quack-programs (delete program quack-programs))
  3249. (quack-option-set 'quack-programs quack-programs t)
  3250. (message "Forgot program %S." program))
  3251. (defun quack-custom-set (sym value)
  3252. ;; Clean up the value based on the variable symbol.
  3253. (cond ((eq sym 'quack-programs)
  3254. (setq value (quack-sort-string-list-copy value))))
  3255. ;; Set default binding. Set local binding just for the halibut, although if
  3256. ;; there are local bindings, then other things will likely break. \(We used
  3257. ;; to have a check here, but removed it while porting to XEmacs.\)
  3258. (set sym value)
  3259. (set-default sym value)
  3260. ;; TODO: Probably don't do this during Emacs initialization time, to avoid
  3261. ;; unnecessary behavior like:
  3262. ;;
  3263. ;; Loading ~/emacs/my-custom.el (source)...
  3264. ;; Updating Scheme Mode buffers...done
  3265. ;; Updating Scheme Mode buffers...done
  3266. ;; Updating Scheme Mode buffers...done
  3267. ;; Updating Scheme Mode buffers...done
  3268. ;; Updating Scheme Mode buffers...done
  3269. ;; Loading ~/emacs/my-custom.el (source)...done
  3270. ;; Update dependent program state.
  3271. (cond ((memq sym '(quack-emacsish-keywords-to-fontify
  3272. quack-fontify-style
  3273. quack-fontify-threesemi-p
  3274. quack-pltish-fontify-definition-names-p
  3275. quack-pltish-fontify-keywords-p
  3276. quack-pltish-keywords-to-fontify
  3277. quack-pretty-lambda-p))
  3278. (quack-update-scheme-mode-buffers))
  3279. ((eq sym 'quack-local-keywords-for-remote-manuals-p)
  3280. (quack-invalidate-manuals-caches))
  3281. ((eq sym 'quack-pltcollect-dirs)
  3282. (quack-invalidate-pltcollects-caches))))
  3283. (defun quack-option-set (sym value &optional silently)
  3284. (if quack-options-persist-p
  3285. (customize-save-variable sym value)
  3286. (quack-custom-set sym value))
  3287. (or silently
  3288. (message "Set %s%s to: %S"
  3289. sym
  3290. (if quack-options-persist-p "" " (non-persistently)")
  3291. value)))
  3292. (defun quack-option-toggle (sym &optional silently)
  3293. (quack-option-set sym (not (symbol-value sym)) t)
  3294. (or silently
  3295. (message "Set %s%s %s."
  3296. sym
  3297. (if quack-options-persist-p "" " (non-persistently)")
  3298. (if (symbol-value sym) "ON" "OFF"))))
  3299. (defun quack-update-scheme-mode-buffers ()
  3300. (save-excursion
  3301. (quack-activity
  3302. "Updating Scheme Mode buffers"
  3303. (mapcar (function
  3304. (lambda (buf)
  3305. (set-buffer buf)
  3306. (when (eq major-mode 'scheme-mode)
  3307. (quack-activity (format "Updating buffer %S" (buffer-name))
  3308. (scheme-mode)))))
  3309. (buffer-list)))))
  3310. ;; Pretty Lambda:
  3311. (defconst quack-lambda-char (make-char 'greek-iso8859-7 107))
  3312. (defconst quack-pretty-lambda-supported-p
  3313. (and quack-gnuemacs-p (>= emacs-major-version 21)))
  3314. ;; Font Lock:
  3315. (defconst quack-emacsish1-font-lock-keywords
  3316. `((,(concat "[[(]"
  3317. "\\(" ; #<1
  3318. "define\\*?"
  3319. ; #=2 #=3
  3320. (quack-re-alt (quack-re-alt ""
  3321. "-generic"
  3322. "-generic-procedure"
  3323. "-method"
  3324. "-public"
  3325. "/kw"
  3326. "/override"
  3327. "/private"
  3328. "/public")
  3329. ; #=4
  3330. (quack-re-alt "-macro"
  3331. "-syntax")
  3332. "-class"
  3333. "-module"
  3334. "-signature"
  3335. "-struct")
  3336. "\\)" ; #>1
  3337. "\\>"
  3338. "[ \t]*[[(]?"
  3339. ; #=5
  3340. "\\(\\sw+\\)?")
  3341. (1 font-lock-keyword-face)
  3342. (5 (cond ((match-beginning 3) font-lock-function-name-face)
  3343. ((match-beginning 4) font-lock-variable-name-face)
  3344. (t font-lock-type-face))
  3345. nil t))
  3346. ;; PLT module definitions.
  3347. ("[[(]\\(module\\)\\>[ \t]+\\(\\sw+\\)?"
  3348. (1 font-lock-keyword-face)
  3349. (2 font-lock-type-face nil t))))
  3350. (defconst quack-emacsish2-font-lock-keywords
  3351. (append quack-emacsish1-font-lock-keywords
  3352. `(
  3353. ;; Misc. keywords.
  3354. (,(concat
  3355. "[[(]\\("
  3356. (regexp-opt quack-emacsish-keywords-to-fontify)
  3357. "\\)\\>")
  3358. . 1)
  3359. ;; Class specifiers in SOS, Stklos, Goops.
  3360. ("\\<<\\sw+>\\>" . font-lock-type-face)
  3361. ;; Colon keywords.
  3362. ("\\<:\\sw+\\>" . font-lock-builtin-face))))
  3363. (defvar quack-pltish-font-lock-keywords nil)
  3364. (defun quack-pltish-num-re (radix digit base16-p)
  3365. ;; These regexps started as a transliteration of the R5RS BNF to regular
  3366. ;; expressions, adapted for PLTisms, and with a few optimizations.
  3367. ;;
  3368. ;; PLTisms are that 'e' is not permitted as an exponent marker in base-16
  3369. ;; literals, and that "decimal-point" forms are permitted in any radix.
  3370. ;;
  3371. ;; There's obvious opportunity for further optimization, especially if we
  3372. ;; relax the accepted syntax a little. These regexps have not been tested
  3373. ;; much, but, since this is only Emacs syntax fontification, false-positives
  3374. ;; and false-negatives will be obvious yet benign.
  3375. (let* ((uint (concat digit "+#*"))
  3376. (sign "[-+]?")
  3377. (suffix (quack-re-optional (if base16-p "[sSfFdDlL]" "[eEsSfFdDlL]")
  3378. sign
  3379. "[0-9]+"))
  3380. (decimal (quack-re-alt
  3381. (concat uint suffix)
  3382. (concat "\\." digit "+#*" suffix)
  3383. (concat digit
  3384. "+"
  3385. (quack-re-alt (concat "\\." digit "*")
  3386. "#+\\.")
  3387. "#*")))
  3388. (ureal (quack-re-alt uint
  3389. (concat uint "/" uint)
  3390. decimal))
  3391. (real (concat sign ureal))
  3392. (complex (quack-re-alt
  3393. (concat real
  3394. (quack-re-alt (concat "@" real)
  3395. (quack-re-optional
  3396. "[-+]"
  3397. (quack-re-optional ureal)
  3398. "i")
  3399. ""))
  3400. (concat "[-+]" (quack-re-optional ureal) "i")))
  3401. (exact (quack-re-optional "#[eEiI]"))
  3402. (prefix (quack-re-alt (concat radix exact)
  3403. (concat exact radix))))
  3404. (concat "\\<" prefix complex "\\>")))
  3405. (defconst quack-pltish-fls-base
  3406. `(
  3407. ("\\`\\(MrEd\\|Welcome to MzScheme\\) v[^\n]+" . quack-banner-face)
  3408. ("\\`Gambit Version 4\\.0[^\n]*" . quack-banner-face)
  3409. ("\\`Welcome to scsh [0-9][^\n]+\nType ,\\? for help[^\n]+"
  3410. . quack-banner-face)
  3411. ("\\`MIT/GNU Scheme running under [^\n]+" . quack-banner-face)
  3412. ;;("\\`; This is the CHICKEN interpreter - Version [^\n]+\n; (c)[^\n]+"
  3413. ;; . quack-banner-face)
  3414. ;;("\\`Scheme Microcode Version[^\n]+\nMIT Scheme[^\n]+\n\\([^\n]+\n\\)+" .
  3415. ;;quack-banner-face)
  3416. ;; Unix cookie line.
  3417. ("\\`#![^\r\n]*" . quack-pltish-comment-face)
  3418. ;; Colon keywords:
  3419. ("\\<#:\\sw+\\>" . quack-pltish-colon-keyword-face)
  3420. ;; Self-evals:
  3421. ("'\\sw+\\>" . quack-pltish-selfeval-face)
  3422. ("'|\\(\\sw\\| \\)+|" . quack-pltish-selfeval-face)
  3423. ;; Note: The first alternative in the following rule will misleadingly
  3424. ;; fontify some invalid syntax, such as "#\(x".
  3425. ("\\<#\\\\\\([][-`~!@#$%&*()_+=^{}\;:'\"<>,.?/|\\\\]\\|\\sw+\\>\\)"
  3426. . quack-pltish-selfeval-face)
  3427. ("[][()]" . quack-pltish-paren-face)
  3428. ("\\<#\\(t\\(?:rue\\)?\\|f\\(?:alse\\)?\\)\\>" . quack-pltish-selfeval-face)
  3429. ("\\<+\\(inf.0\\|nan\\)\\>" . quack-pltish-selfeval-face)
  3430. ("\\<-inf.0\\>" . quack-pltish-selfeval-face)
  3431. ,@(mapcar (function (lambda (args)
  3432. (cons (apply 'quack-pltish-num-re args)
  3433. 'quack-pltish-selfeval-face)))
  3434. '(("#b" "[01]" nil)
  3435. ("#o" "[0-7]" nil)
  3436. ("\\(#d\\)?" "[0-9]" nil)
  3437. ("#x" "[0-9a-fA-F]" t)))))
  3438. (defconst quack-pltish-fls-defnames
  3439. ;; TODO: Optimize these once they're fairly complete and correct.
  3440. ;; TODO: Would be nice to fontify binding names everywhere they are
  3441. ;; introduced, such as in `let' and `lambda' forms. That may require
  3442. ;; real parsing to do reasonably well -- the kludges get too bad and
  3443. ;; slow, and font-lock gets in the way more than it helps.
  3444. `(
  3445. ;,@quack-pltish-font-lock-keywords
  3446. ;; Lots of definition forms that start with "define".
  3447. (,(concat "[[(]"
  3448. "define\\*?"
  3449. ;; TODO: make this into regexp-opt
  3450. (quack-re-alt ""
  3451. ":"
  3452. "-class"
  3453. "-class"
  3454. "-const-structure"
  3455. "-constant"
  3456. "-embedded"
  3457. "-entry-point"
  3458. "-external"
  3459. "-for-syntax"
  3460. "-foreign-record"
  3461. "-foreign-type"
  3462. "-foreign-variable"
  3463. "-generic"
  3464. "-generic-procedure"
  3465. "-inline"
  3466. "-location"
  3467. "-macro"
  3468. "-method"
  3469. "-opt"
  3470. "-parameters"
  3471. "-public"
  3472. "-reader-ctor"
  3473. "-record"
  3474. "-record-printer"
  3475. "-record-type"
  3476. "-signature"
  3477. "-structure"
  3478. "-syntax"
  3479. "-values"
  3480. "-values-for-syntax"
  3481. "/contract"
  3482. "/override"
  3483. "/private"
  3484. "/public")
  3485. "\\>"
  3486. "[ \t]*[[(]?"
  3487. "\\(\\sw+\\)")
  3488. (2 (let ((name (quack-match-string-no-properties 2)))
  3489. (if (= (aref name (1- (length name))) ?%)
  3490. quack-pltish-class-defn-face
  3491. quack-pltish-defn-face))
  3492. nil t))
  3493. ;; Racket "struct" and "define-struct" forms:
  3494. (,(concat "[[(]"
  3495. "\\(?:define-\\)?"
  3496. "struct"
  3497. "\\>"
  3498. "[ \t]*[[(]?"
  3499. "\\(\\sw+\\)")
  3500. ;; TODO: Use a struct face rather than the class face.
  3501. (1 quack-pltish-class-defn-face nil t))
  3502. ;; `defmacro' and related SCM forms.
  3503. (,(concat "[[(]def"
  3504. (quack-re-alt (concat "macro"
  3505. (quack-re-alt "" "-public"))
  3506. "syntax")
  3507. "\\>[ \t]+\\(\\sw+\\)")
  3508. 3 quack-pltish-defn-face nil t)
  3509. ;; `defmac' from SIOD.
  3510. ("[[(]defmac[ \t]+[[(][ \t]*\\(\\sw+\\)"
  3511. 1 quack-pltish-defn-face nil t)
  3512. ;; `defvar' and `defun' from SIOD.
  3513. (,(concat "[[(]def"
  3514. (quack-re-alt "un"
  3515. "var")
  3516. "[ \t]+\\(\\sw+\\)")
  3517. 2 quack-pltish-defn-face nil t)
  3518. ;; Guile and Chicken `define-module'.
  3519. ("[[(]define-module\\>[ \t]+[[(][ \t]*\\(\\sw+\\([ \t]+\\sw+\\)*\\)"
  3520. 1 quack-pltish-module-defn-face nil t)
  3521. ;; PLT `define-values', `define-syntaxes', and `define-syntax-set'.
  3522. (,(concat "[[(]define-"
  3523. (quack-re-alt "values" "syntax-set" "syntaxes")
  3524. "\\>[ \t]+[[(][ \t]*\\(\\sw+\\([ \t]+\\sw+\\)*\\)")
  3525. 2 quack-pltish-defn-face nil t)
  3526. ;; PLT `module'.
  3527. ("[[(]module\\>[ \t]+\\(\\sw+\\)"
  3528. 1 quack-pltish-module-defn-face nil t)
  3529. ;; Named `let'. (Note: This is disabled because it's too incongruous.)
  3530. ;;("[[(]let\\>[ \t]+\\(\\sw+\\)"
  3531. ;; 1 quack-pltish-defn-face nil t)
  3532. ))
  3533. ;; TODO: Adding PLT-style (quasi)quoted list fontifying is obviously not doable
  3534. ;; with just regexps. Probably requires either cloning
  3535. ;; `font-lock-default-fontify-region' just to get it to call our
  3536. ;; replacement syntactic pass fontification function, *or*
  3537. ;; before-advising `font-lock-fontify-keywords-region' to perform our
  3538. ;; syntactic pass when in scheme-mode, and around-advising
  3539. ;; `font-lock-fontify-syntactically-region' to not do anything for
  3540. ;; scheme-mode (or maybe setting `font-lock-keywords-only' to non-nil,
  3541. ;; unless that breaks something else). Or just ditch font-lock. See
  3542. ;; `font-lock-fontify-region-function' variable in font-lock specs.
  3543. ;; (defconst quack-pltish-fls-keywords
  3544. ;; `((,(concat
  3545. ;; "[[(]\\("
  3546. ;; (regexp-opt quack-pltish-keywords-to-fontify)
  3547. ;; "\\)\\>")
  3548. ;; (1 quack-pltish-keyword-face))))
  3549. (defun quack-install-fontification ()
  3550. (when (eq quack-fontify-style 'plt)
  3551. (set (make-local-variable 'font-lock-comment-face)
  3552. 'quack-pltish-comment-face)
  3553. (set (make-local-variable 'font-lock-string-face)
  3554. 'quack-pltish-selfeval-face))
  3555. (let* ((sk `(("\\(#\\)\\(|\\)"
  3556. (1 ,quack-pound-syntax)
  3557. (2 ,quack-bar-syntax))
  3558. ("\\(|\\)\\(#\\)"
  3559. (1 ,quack-bar-syntax)
  3560. (2 ,quack-pound-syntax))))
  3561. (pl (if (and quack-pretty-lambda-supported-p quack-pretty-lambda-p)
  3562. '(("[[(]\\(case-\\|match-\\|opt-\\)?\\(lambda\\)\\>"
  3563. 2
  3564. (progn (compose-region (match-beginning 2)
  3565. (match-end 2)
  3566. quack-lambda-char)
  3567. nil)))
  3568. '()))
  3569. (threesemi
  3570. (if quack-fontify-threesemi-p
  3571. `(
  3572. (,(concat "^\\(\;\;\;\\)"
  3573. ;; TODO: Make this enforce space or newline after the
  3574. ;; three semicolons.
  3575. "\\("
  3576. "[ \t]*"
  3577. "\\("
  3578. "[^\r\n]*"
  3579. "\\)"
  3580. "\r?\n?\\)")
  3581. (1 quack-threesemi-semi-face prepend)
  3582. (2 quack-threesemi-text-face prepend)
  3583. ;;(4 quack-threesemi-h1-face prepend)
  3584. ;;(5 quack-threesemi-h2-face prepend)
  3585. )
  3586. ;; Funcelit:
  3587. ("^\;\;\; @\\(Package\\|section\\|unnumberedsec\\)[ \t]+\\([^\r\n]*\\)"
  3588. (2 quack-threesemi-h1-face prepend))
  3589. ("^\;\;\; @subsection[ \t]+\\([^\r\n]*\\)"
  3590. (1 quack-threesemi-h2-face prepend))
  3591. ("^\;\;\; @section\\(?:\\[[^]]*\\]\\)?{\\([^\r\n]*\\)}"
  3592. (1 quack-threesemi-h1-face prepend))
  3593. ("^\;\;\; @subsection\\(?:\\[[^]]*\\]\\)?{\\([^\r\n]*\\)}"
  3594. (1 quack-threesemi-h2-face prepend))
  3595. )
  3596. '()))
  3597. (fld `(,(cond
  3598. ((eq quack-fontify-style 'plt)
  3599. (set (make-local-variable
  3600. 'quack-pltish-font-lock-keywords)
  3601. `(,@quack-pltish-fls-base
  3602. ,@(if quack-pltish-fontify-definition-names-p
  3603. quack-pltish-fls-defnames
  3604. '())
  3605. ,@pl
  3606. ,@(if quack-pltish-fontify-keywords-p
  3607. ;; quack-pltish-fls-keywords
  3608. `((,(concat
  3609. "[[(]\\("
  3610. (regexp-opt
  3611. quack-pltish-keywords-to-fontify)
  3612. "\\)\\>")
  3613. (1 quack-pltish-keyword-face)))
  3614. '())
  3615. ,@threesemi
  3616. ))
  3617. 'quack-pltish-font-lock-keywords)
  3618. ((eq quack-fontify-style 'emacs)
  3619. ;; TODO: Do pretty-lambda here too. But first get rid of
  3620. ;; this font-lock style "degrees of general gaudiness"
  3621. ;; and switch to separate options for each property of
  3622. ;; fontification.
  3623. '(quack-emacsish1-font-lock-keywords
  3624. quack-emacsish1-font-lock-keywords
  3625. quack-emacsish2-font-lock-keywords))
  3626. (t (quack-internal-error)))
  3627. nil
  3628. t
  3629. ((?! . "w") (?$ . "w") (?% . "w") (?& . "w") (?* . "w")
  3630. (?+ . "w") (?- . "w") (?. . "w") (?/ . "w") (?: . "w")
  3631. (?< . "w") (?= . "w") (?> . "w") (?? . "w") (?@ . "w")
  3632. (?^ . "w") (?_ . "w") (?~ . "w")
  3633. ,@(if (eq quack-fontify-style 'plt)
  3634. '((?# . "w"))
  3635. '()))
  3636. ;; TODO: Using `beginning-of-defun' here could be very slow,
  3637. ;; say, when you have a large buffer that is wrapped in a
  3638. ;; `module' form. Look into whether this is a problem.
  3639. beginning-of-defun
  3640. ,@(if t ; quack-gnuemacs-p
  3641. `((font-lock-mark-block-function . mark-defun)
  3642. (font-lock-syntactic-keywords . ,sk))
  3643. '()))))
  3644. ;; TODO: Figure out why `font-lock-syntactic-keywords' just doesn't work in
  3645. ;; XEmacs 21, even though the syntax text properties seem to get set.
  3646. ;; We have already beaten it like an egg-sucking dog.
  3647. ;;(if quack-xemacs-p
  3648. ;;(put 'scheme-mode 'font-lock-defaults fld)
  3649. (set (make-local-variable 'font-lock-defaults) fld)
  3650. ;;)
  3651. ;;(when quack-xemacs-p
  3652. ;; (set (make-local-variable 'font-lock-syntactic-keywords)
  3653. ;; syntactic-keywords))
  3654. ))
  3655. ;; Scheme Mode Startup Hook:
  3656. (defun quack-locally-steal-key-bindings (old-func new-func)
  3657. (mapcar (function (lambda (key)
  3658. (unless (and (vectorp key)
  3659. (eq (aref key 0) 'menu-bar))
  3660. (local-set-key key new-func))))
  3661. (where-is-internal old-func)))
  3662. (defun quack-shared-mode-hookfunc-stuff ()
  3663. ;; Install the Quack keymap and menu items.
  3664. (local-set-key quack-scheme-mode-keymap-prefix quack-scheme-mode-keymap)
  3665. (quack-when-xemacs
  3666. (when (featurep 'menubar)
  3667. ;;(set-buffer-menubar current-menubar)
  3668. ;; TODO: For XEmacs, we could have two versions of this menu -- the popup
  3669. ;; one would have the Global submenu, but the menubar one would have
  3670. ;; the Global submenu only if quack-global-menu-p were nil.
  3671. (add-submenu nil quack-scheme-mode-menuspec)
  3672. (set-menubar-dirty-flag)
  3673. (setq mode-popup-menu quack-scheme-mode-menuspec)))
  3674. ;; Bind the paren-matching keys.
  3675. (local-set-key ")" 'quack-insert-closing-paren)
  3676. (local-set-key "]" 'quack-insert-closing-bracket)
  3677. (local-set-key "(" 'quack-insert-opening-paren)
  3678. (local-set-key "[" 'quack-insert-opening-bracket)
  3679. ;; Steal any find-file bindings.
  3680. (when quack-remap-find-file-bindings-p
  3681. (quack-locally-steal-key-bindings 'find-file 'quack-find-file)
  3682. (quack-locally-steal-key-bindings 'ido-find-file 'quack-find-file))
  3683. ;; Fight against tabs.
  3684. (when quack-tabs-are-evil-p
  3685. (setq indent-tabs-mode nil))
  3686. ;; Remove character compositions, to get rid of any pretty-lambda. (Note:
  3687. ;; This is bad, if it turns out compositions are used for other purposes in
  3688. ;; buffers that are edited with Scheme Mode.)
  3689. (when quack-pretty-lambda-supported-p
  3690. (eval '(decompose-region (point-min) (point-max))))
  3691. ;; Install fontification
  3692. (when quack-fontify-style
  3693. (when (and (boundp 'font-lock-keywords)
  3694. (symbol-value 'font-lock-keywords)
  3695. (not (featurep 'noweb-mode)))
  3696. ;; This warning is not given if the `noweb-mode' package is installed.
  3697. (quack-warning "`font-lock-keywords' already set when hook ran."))
  3698. (quack-install-fontification))
  3699. ;; Die! Die! Die!
  3700. (quack-when-xemacs
  3701. (quack-install-global-menu)))
  3702. (defun quack-inferior-scheme-mode-hookfunc ()
  3703. (quack-shared-mode-hookfunc-stuff))
  3704. (defun quack-scheme-mode-hookfunc ()
  3705. (quack-shared-mode-hookfunc-stuff)
  3706. ;; Bind Return/Enter key.
  3707. (local-set-key "\r" 'quack-newline)
  3708. ;; Install toolbar.
  3709. ;;(unless quack-xemacs-p
  3710. ;;(when (display-graphic-p)
  3711. ;;(quack-install-tool-bar)))
  3712. )
  3713. (add-hook 'scheme-mode-hook 'quack-scheme-mode-hookfunc)
  3714. (add-hook 'inferior-scheme-mode-hook 'quack-inferior-scheme-mode-hookfunc)
  3715. ;; Compilation Mode:
  3716. ;; TODO: Add compilation-directory-matcher support for "setup-plt: in".
  3717. (defvar quack-saved-compilation-error-regexp-alist nil)
  3718. (defconst quack-compilation-error-regexp-alist-additions
  3719. (let ((no-line (if quack-xemacs-p
  3720. (let ((m (make-marker))) (set-marker m 0) m)
  3721. 'quack-compile-no-line-number)))
  3722. `(
  3723. ;; Racket 5.1.1 "raco" compile error (which can have multiple spaces):
  3724. ("^raco\\(?:cgc\\)?: +\\([^: ][^:]*\\):\\([0-9]+\\):\\([0-9]+\\):"
  3725. 1 2 3)
  3726. ;; Racket 5.1.1 entries without line number info in "=== context ===":
  3727. ("^\\(/[^:]+\\): \\[running body\\]$" 1 nil nil 0)
  3728. ;; PLT MzScheme 4.1.4 "=== context ===" traceback when there is only file,
  3729. ;; line, and column info, but potentially no following ":" and additional
  3730. ;; info like procedure name.
  3731. ("^\\([^:\n\" ]+\\):\\([0-9]+\\):\\([0-9]+\\)" 1 2 3)
  3732. ;; PLT MzScheme 205 "setup-plt"
  3733. ;; load-handler: expected a `module' declaration for `bar-unit' in
  3734. ;; "/u/collects/bar/bar-unit.ss", but found something else
  3735. (,(concat "load-handler: expected a `module' declaration for `[^']+' in "
  3736. "\"\\([^:\n\"]+\\)\", but found something else")
  3737. 1 ,no-line)
  3738. ;; PLT MzScheme 205 "setup-plt".
  3739. ;; setup-plt: Error during Compiling .zos for Foo Bar (/u/collects/fb)
  3740. ("setup-plt: Error during Compiling .zos for [^\n]+ \(\\([^\n\)]+\\)\)"
  3741. 1 ,no-line)
  3742. ;; PLT MzScheme 4.0.1 "setup-plt".
  3743. ("setup-plt: +\\(?:WARNING: +\\)\\([^:\n]+\\)::"
  3744. 1 ,no-line)
  3745. ;; PLT MzScheme 4.0.1 "setup-plt".
  3746. ("setup-plt: +\\(?:WARNING: +\\)\\([^:\n ][^:\n]*\\):\\([0-9]+\\):\\([0-9]+\\)"
  3747. 1 2 3)
  3748. ;; PLT MzScheme 4.0.1 "setup-plt":
  3749. ("load-handler: expected a `module' declaration for `[^'\n]+' in #<path:\\([^>\n]+\\)>[^\n]+"
  3750. 1 ,no-line)
  3751. ;; PLT Scheme 4.1.2 "default-load-handler" error without useful filename:
  3752. ("default-load-handler: cannot open input-file: "
  3753. nil ,no-line)
  3754. )))
  3755. (defun quack-compile-no-line-number (filename column)
  3756. (list (point-marker) filename 1 (and column (string-to-number column))))
  3757. (defun quack-install-compilation-mode-stuff ()
  3758. (unless quack-saved-compilation-error-regexp-alist
  3759. (setq quack-saved-compilation-error-regexp-alist
  3760. compilation-error-regexp-alist))
  3761. (setq compilation-error-regexp-alist
  3762. (append quack-compilation-error-regexp-alist-additions
  3763. quack-saved-compilation-error-regexp-alist)))
  3764. (quack-install-compilation-mode-stuff)
  3765. ;; Interpreter-mode-alist:
  3766. (defvar quack-saved-interpreter-mode-alist nil)
  3767. (defvar quack-interpreter-mode-alist-additions
  3768. (mapcar (function (lambda (x)
  3769. (cons x 'scheme-mode)))
  3770. '("bigloo"
  3771. "csi"
  3772. "gosh"
  3773. "gsi"
  3774. "guile"
  3775. "kawa"
  3776. "mit-scheme"
  3777. "mred"
  3778. "mred3m"
  3779. "mredcgc"
  3780. "mzscheme"
  3781. "mzscheme3m"
  3782. "mzschemecgc"
  3783. "r5rs"
  3784. "r6rs"
  3785. "rs"
  3786. "rs"
  3787. "scheme"
  3788. "scheme48"
  3789. "scsh"
  3790. "sisc"
  3791. "stklos"
  3792. "sxi")))
  3793. (defun quack-install-interpreter-mode-alist ()
  3794. (unless quack-saved-interpreter-mode-alist
  3795. (setq quack-saved-interpreter-mode-alist
  3796. interpreter-mode-alist))
  3797. (setq interpreter-mode-alist
  3798. (append quack-interpreter-mode-alist-additions
  3799. quack-saved-interpreter-mode-alist)))
  3800. (quack-install-interpreter-mode-alist)
  3801. ;; PLT Package Mode:
  3802. ;; TODO: Do some simple checking and summarize what directories and files are
  3803. ;; getting modified by this package.
  3804. ;; TODO: Maybe don't worry about preserving the decompressed text verbatim in
  3805. ;; the buffer -- set markers and generate headings, and be able to
  3806. ;; construct valid package.
  3807. ;; TODO: Command to install package from original file using "setup-plt".
  3808. ;; TODO: Fontify Scheme code file contents.
  3809. (defvar quack-pltfile-mode-hook nil)
  3810. (defvar quack-hiding-ovlcat)
  3811. (put 'quack-hiding-ovlcat 'face 'default)
  3812. (put 'quack-hiding-ovlcat 'intangible t)
  3813. (put 'quack-hiding-ovlcat 'invisible t)
  3814. (defvar quack-pltfile-mode-map (make-sparse-keymap))
  3815. (define-key quack-pltfile-mode-map "q" 'quack-pltfile-quit)
  3816. (define-key quack-pltfile-mode-map "r" 'quack-pltfile-raw)
  3817. (define-key quack-pltfile-mode-map " " 'scroll-up)
  3818. ;; TODO: Make a menu map for pltfile-mode.
  3819. (defun quack-pltfile-mode ()
  3820. (interactive)
  3821. "Major mode for viewing PLT Scheme `.plt' package files.
  3822. \\{quack-pltfile-mode-map}
  3823. Provided by Quack: http://www.neilvandyke.org/quack/"
  3824. (kill-all-local-variables)
  3825. (put 'quack-pltfile-mode 'mode-class 'special)
  3826. (setq major-mode 'quack-pltfile-mode)
  3827. (setq mode-name "PLT Package")
  3828. (use-local-map quack-pltfile-mode-map)
  3829. ;; Note: Currently, the `font-lock' feature is always defined, since we
  3830. ;; require it.
  3831. (when (featurep 'font-lock)
  3832. (setq font-lock-defaults nil))
  3833. (buffer-disable-undo)
  3834. (let ((saved-bmp (buffer-modified-p)))
  3835. (quack-activity "Decoding PLT package" (quack-pltfile-decode-buffer))
  3836. (setq buffer-read-only t)
  3837. (set-buffer-modified-p saved-bmp))
  3838. (quack-when-xemacs
  3839. (make-variable-buffer-local 'write-contents-hooks))
  3840. (add-hook 'write-contents-hooks 'quack-prevent-pltfile-write)
  3841. (run-hooks 'quack-pltfile-mode-hook)
  3842. (message "Decoded PLT package. %s"
  3843. (substitute-command-keys
  3844. (concat "`\\[quack-pltfile-quit]' to quit"
  3845. ", `\\[quack-pltfile-raw]' for raw format."))))
  3846. (defun quack-prevent-pltfile-write ()
  3847. (unless (yes-or-no-p
  3848. "Write a decoded PLT package buffer?! Are you *sure*?!")
  3849. (error "Aborted write of decoded PLT package buffer.")))
  3850. (defun quack-pltfile-raw ()
  3851. (interactive)
  3852. (let ((auto-mode-alist '()))
  3853. (setq buffer-read-only nil)
  3854. (widen)
  3855. (delete-region (point-min) (point-max))
  3856. (fundamental-mode)
  3857. (revert-buffer t t)))
  3858. (defun quack-pltfile-quit ()
  3859. (interactive)
  3860. (kill-buffer (current-buffer)))
  3861. (defun quack-skip-whitespace-to-nonblank-line-beginning ()
  3862. (save-match-data
  3863. (while (looking-at "[ \t\r\f]*\n")
  3864. (goto-char (match-end 0)))))
  3865. (defun quack-pltfile-decode-buffer ()
  3866. ;; MIME Base-64 decode. (Note: an error is signaled if this fails.)
  3867. (base64-decode-region (point-min) (point-max))
  3868. ;; Gzip decompress.
  3869. (let ((coding-system-for-write (if quack-xemacs-p 'binary 'raw-text-unix))
  3870. (coding-system-for-read (if quack-xemacs-p 'binary 'raw-text-unix))
  3871. (inhibit-eol-conversion t)
  3872. status)
  3873. (unless (= (setq status (call-process-region (point-min) (point-max)
  3874. "gzip" t t nil "-d")) 0)
  3875. (error "Could not decompress PLT package: gzip process status %s"
  3876. status)))
  3877. ;; Move past the "PLT" cookie, and the two sexp forms.
  3878. (goto-char (point-min))
  3879. (unless (looking-at "PLT")
  3880. (error "This does not appear to be a PLT package file."))
  3881. (goto-char (match-end 0))
  3882. (forward-list 2)
  3883. (quack-skip-whitespace-to-nonblank-line-beginning)
  3884. (quack-make-face-ovlext (point-min) (point) 'quack-pltfile-prologue-face)
  3885. ;; Process the buffer contents.
  3886. (let ((standard-input (current-buffer)))
  3887. (while (not (eobp))
  3888. (let ((step-beg (point)))
  3889. ;; TODO: This read will fail if we just had whitespace at the end of
  3890. ;; the file, which it shouldn't, but maybe we should check, just
  3891. ;; in case.
  3892. (let ((sym (read)))
  3893. (unless (symbolp sym)
  3894. (error "Expected a symbol, but saw: %S" sym))
  3895. (cond
  3896. ((eq sym 'dir)
  3897. (forward-list)
  3898. (quack-skip-whitespace-to-nonblank-line-beginning)
  3899. (quack-make-face-ovlext step-beg
  3900. (point)
  3901. 'quack-pltfile-dir-face))
  3902. ((memq sym '(file file-replace))
  3903. (forward-list)
  3904. (let ((size (read)))
  3905. (unless (and (integerp size) (>= size 0))
  3906. (error "Expected a file size, but saw: %S" size))
  3907. (unless (looking-at "[ \t\r\n\f]*\\*")
  3908. (error "Expected a `*' after file size."))
  3909. (goto-char (match-end 0))
  3910. ;; Fontify the file header.
  3911. (quack-make-face-ovlext step-beg
  3912. (1- (point))
  3913. 'quack-pltfile-file-face)
  3914. ;; Hide the file contents asterisk.
  3915. (quack-make-hiding-ovlext (1- (point)) (point))
  3916. ;; Set the coding region for the content.
  3917. (let* ((content-beg (point))
  3918. (content-end (+ content-beg size))
  3919. (cs (detect-coding-region content-beg
  3920. content-end)))
  3921. (goto-char content-end)
  3922. (when (listp cs)
  3923. (setq cs (car cs)))
  3924. (unless (eq cs 'undecided)
  3925. (cond ((eq cs 'undecided-dos) (setq cs 'raw-text-dos))
  3926. ((eq cs 'undecided-mac) (setq cs 'raw-text-mac))
  3927. ((eq cs 'undecided-unix) (setq cs 'raw-text-unix)))
  3928. (decode-coding-region content-beg content-end cs))
  3929. ;; TODO: XEmacs 21 `decode-coding-region' seems to lose the
  3930. ;; point position. This is disconcerting, since the
  3931. ;; point semantics under coding system changes do not
  3932. ;; currently seem to be well-specified, so resetting the
  3933. ;; point here *might* not always be the right thing to
  3934. ;; do. Verify.
  3935. (quack-when-xemacs
  3936. (goto-char content-end)))))
  3937. (t (error "Expected `dir', `file', or `file-replace', but saw: %S"
  3938. sym)))))))
  3939. ;; Return point to top of buffer.
  3940. (goto-char (point-min)))
  3941. ;; The rest of this file except for the `provide' form is TODO comments.
  3942. ;; TODO: Add tool bar support later.
  3943. ;;
  3944. ;; (defvar quack-toolbarimage-width 24)
  3945. ;; (defvar quack-toolbarimage-height 24)
  3946. ;;
  3947. ;; (defun quack-create-image (&rest args)
  3948. ;; (if (and quack-gnuemacs-p (>= emacs-major-version 21))
  3949. ;; (apply 'create-image args)
  3950. ;; nil))
  3951. ;;
  3952. ;; (defun quack-make-toolbarimage (&rest lines)
  3953. ;; ;; TODO: We really should make an efficient function to print N spaces
  3954. ;; ;; or to return a string of N spaces. Or at least keep 1-2
  3955. ;; ;; strings for the left and right padding here, which will
  3956. ;; ;; usually be the same for the duration of this function.
  3957. ;; (quack-create-image
  3958. ;; (let* ((lines-count (length lines))
  3959. ;; (blank-line (make-string quack-toolbarimage-width 32)))
  3960. ;; (and (> lines-count quack-toolbarimage-height) (quack-internal-error))
  3961. ;; (with-output-to-string
  3962. ;; (princ "/* XPM */\nstatic char *magick[] = {\n")
  3963. ;; ;;(princ "/* columns rows colors chars-per-pixel */\n")
  3964. ;; (princ (format "\"%d %d 5 1\",\n"
  3965. ;; quack-toolbarimage-width quack-toolbarimage-height))
  3966. ;; (princ "\". c #f0f0f0\",\n")
  3967. ;; (princ "\"@ c #0f0f0f\",\n")
  3968. ;; (princ "\"g c #00b000\",\n")
  3969. ;; (princ "\"r c #d00000\",\n")
  3970. ;; (princ "\" c None\",\n")
  3971. ;; ;;(princ "/* pixels */\n")
  3972. ;; (let ((line-num 0))
  3973. ;; (mapcar (function
  3974. ;; (lambda (line)
  3975. ;; (princ "\"")
  3976. ;; (if line
  3977. ;; (let* ((c (length line))
  3978. ;; (l (/ (- quack-toolbarimage-width c) 2)))
  3979. ;; (and (> c quack-toolbarimage-width)
  3980. ;; (quack-internal-error))
  3981. ;; (princ (make-string l 32))
  3982. ;; (princ line)
  3983. ;; (princ (make-string (- quack-toolbarimage-width
  3984. ;; c l)
  3985. ;; 32)))
  3986. ;; (princ blank-line))
  3987. ;; (if (< (setq line-num (1+ line-num))
  3988. ;; quack-toolbarimage-height)
  3989. ;; (princ "\",\n")
  3990. ;; (princ "\"\n"))))
  3991. ;; (let ((rows-before (/ (- quack-toolbarimage-width
  3992. ;; lines-count)
  3993. ;; 2)))
  3994. ;; `(,@(make-list rows-before nil)
  3995. ;; ,@lines
  3996. ;; ,@(make-list (- quack-toolbarimage-height
  3997. ;; lines-count rows-before)
  3998. ;; nil)))))
  3999. ;; (princ "};\n")))
  4000. ;; 'xpm t))
  4001. ;;
  4002. ;; (defvar quack-tbi-evalbuf
  4003. ;; (quack-make-toolbarimage
  4004. ;; "@@@@@@@@@@ "
  4005. ;; "@........@@ "
  4006. ;; "@........@.@ ggg "
  4007. ;; "@........@..@ ggg "
  4008. ;; "@........@@@@@ ggg "
  4009. ;; "@............@ ggg "
  4010. ;; "@..@@........@ ggg "
  4011. ;; "@...@@.......@ ggg "
  4012. ;; "@....@@......@ ggg "
  4013. ;; "@.....@@.....@ ggg "
  4014. ;; "@....@@@@....@ ggg "
  4015. ;; "@...@@..@@...@ ggg "
  4016. ;; "@..@@....@@..@ ggg "
  4017. ;; "@............@ ggg "
  4018. ;; "@@@@@@@@@@@@@@ ggg "
  4019. ;; " ggg "
  4020. ;; " ggggggg"
  4021. ;; " ggggg "
  4022. ;; " ggg "
  4023. ;; " g "))
  4024. ;;
  4025. ;; (defvar quack-tbi-adoc
  4026. ;; (quack-make-toolbarimage
  4027. ;; "@@@@@@@@@@ "
  4028. ;; "@........@@ "
  4029. ;; "@........@.@ "
  4030. ;; "@........@..@ "
  4031. ;; "@........@@@@@"
  4032. ;; "@...@@@......@"
  4033. ;; "@..@@@@@@....@"
  4034. ;; "@..@....@@...@"
  4035. ;; "@...@@@.@@...@"
  4036. ;; "@..@@@@@@@...@"
  4037. ;; "@..@@...@@...@"
  4038. ;; "@..@@..@@@...@"
  4039. ;; "@...@@@@.@@..@"
  4040. ;; "@............@"
  4041. ;; "@@@@@@@@@@@@@@"))
  4042. ;;
  4043. ;; (defvar quack-tbi-manual
  4044. ;; (quack-make-toolbarimage
  4045. ;; "@@@@@@@@@@ "
  4046. ;; "@........@@ "
  4047. ;; "@........@.@ "
  4048. ;; "@........@..@ "
  4049. ;; "@........@@@@@"
  4050. ;; "@............@"
  4051. ;; "@..@@.@.@@...@"
  4052. ;; "@..@@@@@@@@..@"
  4053. ;; "@..@@.@@.@@..@"
  4054. ;; "@..@@.@@.@@..@"
  4055. ;; "@..@@.@@.@@..@"
  4056. ;; "@..@@.@@.@@..@"
  4057. ;; "@..@@.@@.@@..@"
  4058. ;; "@............@"
  4059. ;; "@@@@@@@@@@@@@@"))
  4060. ;;
  4061. ;; (defvar quack-tbi-manuallookup
  4062. ;; (quack-make-toolbarimage
  4063. ;; "@@@@@@@@@@ "
  4064. ;; "@........@@ "
  4065. ;; "@........@.@ "
  4066. ;; "@........@..@ "
  4067. ;; "@........@@@@@ "
  4068. ;; "@............@ "
  4069. ;; "@..@@.@@@@@@@@@@ "
  4070. ;; "@...@@@........@@ "
  4071. ;; "@....@@........@.@ "
  4072. ;; "@.....@........@..@ "
  4073. ;; "@....@@........@@@@@"
  4074. ;; "@...@@@............@"
  4075. ;; "@..@@.@..@@.@.@@...@"
  4076. ;; "@.....@..@@@@@@@@..@"
  4077. ;; "@@@@@@@..@@.@@.@@..@"
  4078. ;; " @..@@.@@.@@..@"
  4079. ;; " @..@@.@@.@@..@"
  4080. ;; " @..@@.@@.@@..@"
  4081. ;; " @..@@.@@.@@..@"
  4082. ;; " @............@"
  4083. ;; " @@@@@@@@@@@@@@"))
  4084. ;;
  4085. ;; (defvar quack-tbi-stop
  4086. ;; (quack-make-toolbarimage
  4087. ;; " @@@@@ "
  4088. ;; " @@rrrrr@@ "
  4089. ;; " @rrrrrrrrr@ "
  4090. ;; " @rrrrrrrrr@ "
  4091. ;; "@rr@@rrr@@rr@"
  4092. ;; "@rrr@@r@@rrr@"
  4093. ;; "@rrrr@@@rrrr@"
  4094. ;; "@rrr@@r@@rrr@"
  4095. ;; "@rr@@rrr@@rr@"
  4096. ;; " @rrrrrrrrr@ "
  4097. ;; " @rrrrrrrrr@ "
  4098. ;; " @@rrrrr@@ "
  4099. ;; " @@@@@ "))
  4100. ;;
  4101. ;; (defun quack-install-tool-bar ()
  4102. ;; (require 'tool-bar)
  4103. ;; (let ((map (make-sparse-keymap)))
  4104. ;;
  4105. ;; (quack-define-key-after map [quack-load-file]
  4106. ;; `(menu-item "quack-evalbuffer" scheme-load-file
  4107. ;; :image ,quack-tbi-evalbuf
  4108. ;; :help "Load File"))
  4109. ;;
  4110. ;; (quack-define-key-after map [quack-alpha]
  4111. ;; `(menu-item "quack-alpha" quack-alpha
  4112. ;; :image ,quack-tbi-adoc
  4113. ;; :help "alpha"))
  4114. ;;
  4115. ;; (quack-define-key-after map [quack-manual]
  4116. ;; `(menu-item "quack-manual" quack-manual
  4117. ;; :image ,quack-tbi-manual
  4118. ;; :help "View Manual"))
  4119. ;;
  4120. ;; (quack-define-key-after map [quack-view-keyword-docs]
  4121. ;; `(menu-item "quack-view-keyword-docs"
  4122. ;; quack-view-keyword-docs
  4123. ;; :image ,quack-tbi-manuallookup
  4124. ;; :help "View Keyword Docs"))
  4125. ;;
  4126. ;; (quack-define-key-after map [quack-stop]
  4127. ;; `(menu-item "quack-stop" quack-stop
  4128. ;; :image ,quack-tbi-stop
  4129. ;; :help "Stop"))
  4130. ;;
  4131. ;; (set (make-local-variable 'tool-bar-map) map)))
  4132. ;; TODO: Extend `scheme-imenu-generic-expression' for PLT-specific definition
  4133. ;; forms and for definitions within modules.
  4134. ;; TODO: Clickable URLs
  4135. ;;
  4136. ;; (defvar quack-url-keymap)
  4137. ;;
  4138. ;; (setq quack-url-keymap (make-sparse-keymap))
  4139. ;; (define-key quack-url-keymap "\r" 'quack-browse-overlaid-url)
  4140. ;; (define-key quack-url-keymap "q" 'quack-browse-overlaid-url)
  4141. ;;
  4142. ;; (defun quack-make-url-overlay (beg end &optional url)
  4143. ;; (let ((ovl (make-overlay beg end nil t)))
  4144. ;; (overlay-put ovl 'face 'underline)
  4145. ;; (overlay-put ovl 'local-map 'quack-url-keymap)
  4146. ;; (overlay-put ovl 'help-echo "Press RET to browse this URL.")
  4147. ;; (overlay-put ovl 'quack-url
  4148. ;; (or url (buffer-substring-no-properties beg end)))
  4149. ;; ovl))
  4150. ;;
  4151. ;; (defun quack-insert-url (url)
  4152. ;; (let* ((beg (point)))
  4153. ;; (insert url)
  4154. ;; (quack-make-url-overlay beg (point))))
  4155. ;;
  4156. ;; (defun quack-overlaid-url-at-point (&optional pt)
  4157. ;; (let ((overlays (overlays-at (or pt (point))))
  4158. ;; (url nil))
  4159. ;; (while overlays
  4160. ;; (setq overlays (if (setq url (overlay-get (car overlays) 'quack-url))
  4161. ;; (cdr overlays)
  4162. ;; '())))
  4163. ;; url))
  4164. ;;
  4165. ;; (defun quack-browse-overlaid-url (pt)
  4166. ;; ;; Dehydration.
  4167. ;; (interactive "d")
  4168. ;; (quack-browse-url (quack-overlaid-url-at-point pt)))
  4169. ;; TODO: Possible Future Inferior Process I/O Stuff. Make encoding with
  4170. ;; inferior process disambiguate REPL values, port output, error info,
  4171. ;; etc. Start of code commented out below. This may require rewriting
  4172. ;; chunks of `cmuscheme' and `comint'.
  4173. ;;
  4174. ;; Try to use ELI protocol first. http://www.cliki.net/ELI
  4175. ;;
  4176. ;; (defface quack-output-face
  4177. ;; '((((class color)) (:foreground "purple4" :background "lavender"))
  4178. ;; (t (:inverse-video t)))
  4179. ;; "Face used for..."
  4180. ;; :group 'quack)
  4181. ;;
  4182. ;; (defface quack-value-face
  4183. ;; '((((class color)) (:foreground "blue4" :background "light sky blue"))
  4184. ;; (t (:inverse-video t)))
  4185. ;; "Face used for..."
  4186. ;; :group 'quack)
  4187. ;;
  4188. ;; Escape Codes:
  4189. ;; REPL State:
  4190. ;; R repl read begin
  4191. ;; r repl read end
  4192. ;; E repl eval begin
  4193. ;; e repl eval end
  4194. ;; P repl print begin
  4195. ;; p repl print end
  4196. ;; Stream Change:
  4197. ;; O output stream
  4198. ;; E error stream
  4199. ;; Error Info?
  4200. ;;
  4201. ;; (defconst quack-mzscheme-init-string
  4202. ;; (let ((print-length nil)
  4203. ;; (print-level nil))
  4204. ;; (prin1-to-string
  4205. ;; '(let ((o (current-output-port))
  4206. ;; (i (current-input-port))
  4207. ;; (e (current-eval)))
  4208. ;; ;; TODO: Define custom escaping output and error ports here.
  4209. ;; (current-prompt-read
  4210. ;; (lambda ()
  4211. ;; (display "\eR" o)
  4212. ;; (begin0 (read-syntax "quack-repl" i)
  4213. ;; (display "\er" o))))
  4214. ;; (current-eval
  4215. ;; (lambda (n)
  4216. ;; (display "\eE" o)
  4217. ;; (begin0 (e n)
  4218. ;; (display "\ee" o))))
  4219. ;; (current-print
  4220. ;; (lambda (n)
  4221. ;; (display "\eP" o)
  4222. ;; (begin0 (print n o)
  4223. ;; (display "\ep" o))))))))
  4224. ;;
  4225. ;; In `quack' function, after call to `run-scheme':
  4226. ;;
  4227. ;; (add-hook 'comint-preoutput-filter-functions
  4228. ;; 'quack-comint-preoutput-filter-func)
  4229. ;; (comint-send-string (scheme-proc) quack-mzscheme-init-string)
  4230. ;; (comint-send-string (scheme-proc) "\n")
  4231. ;; TODO: If we do that, then add pretty-printing of REPL results.
  4232. ;; TODO: Maybe provide utilities for converting to/from PLT-style
  4233. ;; square-bracket paren conventions.
  4234. ;; TODO: Populate abbrevs table from keywords extracted from manuals, and from
  4235. ;; definitions in current buffer. Or maybe query running MzScheme
  4236. ;; process for bound symbols.
  4237. ;; TODO: Maybe use `compile-zos' to do error-checking for PLT (look up person
  4238. ;; to credit with idea of using that to get more warnings). Need to know
  4239. ;; more about a particular Scheme implementation than just the command
  4240. ;; line to start its REPL, though.
  4241. ;; TODO: Perhaps put some initialization code that depends on user's custom
  4242. ;; settings into after-init-hook. See if this works in XEmacs.
  4243. ;; TODO: Set `interpreter-mode-alist' based on interpreter list.
  4244. ;; TODO: "I think it would be good if the quack menu showed up only when emacs
  4245. ;; was in Scheme mode."
  4246. ;; TODO: Support this:
  4247. ;;
  4248. ;; * Added 'addon-dir for `find-system-path':
  4249. ;; Unix: "~/.plt-scheme"
  4250. ;; Windows: "PLT Scheme" in the user's Application Data folder.
  4251. ;; Mac OS X: "~/Library/PLT Scheme"
  4252. ;; Mac OS Classic: "PLT Scheme" in the preferences folder.
  4253. ;;
  4254. ;; The version string for "~/.plt-scheme/<version>/collects/" might be:
  4255. ;; mzscheme -mqe '(begin (display (version)) (exit))'
  4256. ;; Double-check PLT source first.
  4257. ;; TODO: Add autoindenting to inferior Scheme buffer when pressing RET on an
  4258. ;; incomplete sexp -- iff we can do this reliably enough.
  4259. ;; TODO: When tidying and point is within a series of multiple blank lines that
  4260. ;; are reduced to a single blank line, leave point at the beginning of
  4261. ;; the single blank line.
  4262. ;; TODO: Riastradh says: Do you suppose you could add a feature to Quack that
  4263. ;; indents lists beginning with symbols of the form WITH-... &
  4264. ;; CALL-WITH-... as if their SCHEME-INDENT-FUNCTION property were DEFUN?
  4265. ;; TODO: Matt Dickerson asks " Also, the command history appears to be based on
  4266. ;; newlines -- I work with blocks of code in the REPL and would like C-p
  4267. ;; to give me the last block, not the last line of the previous block."
  4268. ;; TODO: Maybe get appropriate PLT collection path from the default for
  4269. ;; whatever "mzscheme" executable is picked up.
  4270. ;;
  4271. ;; mzscheme -emq '(begin (write (current-library-collection-paths)) (exit 0))'
  4272. ;; ("/home/neil/collects" "/home/neil/.plt-scheme/208/collects"
  4273. ;; "/usr/lib/plt/collects")
  4274. ;; TODO: Bind M-[ to quack-insert-parentheses
  4275. ;; TODO: Peter Barabas reports that `quack-global-menu-p' set to nil doesn't
  4276. ;; disable the menu.
  4277. ;; TODO: Way to get default collects directories. From Matthew Flatt,
  4278. ;; 2006-04-22:
  4279. ;;
  4280. ;; env PLTCOLLECTS="" mzscheme -mvqe '(printf "~s\n" (map path->string
  4281. ;; (current-library-collection-paths)))'
  4282. ;; TODO: Have key binding to insert "lambda" (for use with pretty-lambda).
  4283. ;; Suggested by Olwe Bottorff on 2006-04-20.
  4284. ;; TODO: Jerry van Dijk writes: "I would like to try out quack, but I do not
  4285. ;; like its menu constantly on the main menu bar (as I use emacs for a lot of
  4286. ;; things). Unfortunately sofar quack has bravely defied all my attempts to
  4287. ;; remove it. From desecting the customize option to adding (define-key
  4288. ;; global-map [menu-bar quack] nil)"
  4289. ;; TODO: We could do this:
  4290. ;;
  4291. ;; mzscheme -m -e "(begin (display #\') (write (map path->string (current-library-collection-paths))) (newline) (exit))"
  4292. ;; '("/home/neil/collects"
  4293. ;; "/home/neil/.plt-scheme/360/collects"
  4294. ;; "/usr/lib/plt/collects")
  4295. ;; emacs22 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
  4296. ;; emacs21 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
  4297. ;; emacs20 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
  4298. ;; xemacs21 -batch -no-site-file -f batch-byte-compile quack.el ; rm quack.elc
  4299. ;; End:
  4300. (provide 'quack)
  4301. ;; quack.el ends here