ispell.el 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407
  1. ;;; ispell.el --- interface to International Ispell Versions 3.1 and 3.2
  2. ;; Copyright (C) 1994-1995, 1997-2015 Free Software Foundation, Inc.
  3. ;; Author: Ken Stevens <k.stevens@ieee.org>
  4. ;; Maintainer: Ken Stevens <k.stevens@ieee.org>
  5. ;; Stevens Mod Date: Mon Jan 7 12:32:44 PST 2003
  6. ;; Stevens Revision: 3.6
  7. ;; Status : Release with 3.1.12+ and 3.2.0+ ispell.
  8. ;; Bug Reports : ispell-el-bugs@itcorp.com
  9. ;; Web Site : http://kdstevens.com/~stevens/ispell-page.html
  10. ;; Keywords: unix wp
  11. ;; This file is part of GNU Emacs.
  12. ;; GNU Emacs is free software: you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation, either version 3 of the License, or
  15. ;; (at your option) any later version.
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  22. ;; Note: version numbers and time stamp are not updated
  23. ;; when this file is edited for release with GNU Emacs.
  24. ;;; Commentary:
  25. ;; INSTRUCTIONS
  26. ;; This code contains a section of user-settable variables that you
  27. ;; should inspect prior to installation. Look past the end of the history
  28. ;; list. Set them up for your locale and the preferences of the majority
  29. ;; of the users. Otherwise the users may need to set a number of variables
  30. ;; themselves.
  31. ;; You particularly may want to change the default dictionary for your
  32. ;; country and language.
  33. ;; Most dictionary changes should be made in this file so all users can
  34. ;; enjoy them. Local or modified dictionaries are supported in your .emacs
  35. ;; file. Use the variable `ispell-local-dictionary-alist' to specify
  36. ;; your own dictionaries.
  37. ;; Depending on the mail system you use, you may want to include these:
  38. ;; (add-hook 'news-inews-hook 'ispell-message)
  39. ;; (add-hook 'mail-send-hook 'ispell-message)
  40. ;; (add-hook 'mh-before-send-letter-hook 'ispell-message)
  41. ;; Ispell has a TeX parser and a nroff parser (the default).
  42. ;; The parsing is controlled by the variable ispell-parser. Currently
  43. ;; it is just a "toggle" between TeX and nroff, but if more parsers are
  44. ;; added it will be updated. See the variable description for more info.
  45. ;; TABLE OF CONTENTS
  46. ;; ispell-word
  47. ;; ispell-region
  48. ;; ispell-buffer
  49. ;; ispell-message
  50. ;; ispell-comments-and-strings
  51. ;; ispell-continue
  52. ;; ispell-complete-word
  53. ;; ispell-complete-word-interior-frag
  54. ;; ispell-change-dictionary
  55. ;; ispell-kill-ispell
  56. ;; ispell-pdict-save
  57. ;; ispell-skip-region-alist
  58. ;; Commands in ispell-region:
  59. ;; Character replacement: Replace word with choice. May query-replace.
  60. ;; ` ': Accept word this time.
  61. ;; `i': Accept word and insert into private dictionary.
  62. ;; `a': Accept word for this session.
  63. ;; `A': Accept word and place in buffer-local dictionary.
  64. ;; `r': Replace word with typed-in value. Rechecked.
  65. ;; `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  66. ;; `?': Show these commands
  67. ;; `x': Exit spelling buffer. Move cursor to original point.
  68. ;; `X': Exit spelling buffer. Leaves cursor at the current point, and permits
  69. ;; the check to be completed later.
  70. ;; `q': Quit spelling session (Kills ispell process).
  71. ;; `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
  72. ;; `u': Like `i', but the word is lower-cased first.
  73. ;; `m': Place entered value in personal dictionary, then recheck current word.
  74. ;; `C-l': redraws screen
  75. ;; `C-r': recursive edit
  76. ;; `C-z': suspend Emacs or iconify frame
  77. ;; Buffer-Local features:
  78. ;; There are a number of buffer-local features that can be used to customize
  79. ;; ispell for the current buffer. This includes language dictionaries,
  80. ;; personal dictionaries, parsing, and local word spellings. Each of these
  81. ;; local customizations are done either through local variables, or by
  82. ;; including the keyword and argument(s) at the end of the buffer (usually
  83. ;; prefixed by the comment characters). See the end of this file for
  84. ;; examples. The local keywords and variables are:
  85. ;; ispell-dictionary-keyword language-dictionary
  86. ;; uses local variable ispell-local-dictionary
  87. ;; ispell-pdict-keyword personal-dictionary
  88. ;; uses local variable ispell-local-pdict
  89. ;; ispell-parsing-keyword mode-arg extended-char-arg
  90. ;; ispell-words-keyword any number of local word spellings
  91. ;; Region skipping:
  92. ;; Place new regular expression definitions of regions you prefer not to
  93. ;; spell check in `ispell-skip-region-alist'. Mode-dependent features can
  94. ;; be added to latex by modifying `ispell-tex-skip-alists'.
  95. ;; `ispell-message' contains some custom skipping code for e-mail messages.
  96. ;; BUGS:
  97. ;; Need a way to select between different character mappings without separate
  98. ;; dictionary entries.
  99. ;; Multi-byte characters if not defined by current dictionary may result in the
  100. ;; evil "misalignment error" in some versions of MULE Emacs.
  101. ;; On some versions of Emacs, growing the minibuffer fails.
  102. ;; see `ispell-help-in-bufferp'.
  103. ;; Recursive edits (?C-r or ?R) inside a keyboard text replacement check (?r)
  104. ;; can cause misalignment errors.
  105. ;; HISTORY
  106. ;; Modifications made in latest versions:
  107. ;; Revision 3.6 2003/01/07 12:32:44 kss
  108. ;; Removed extra -d LIB in dictionary defs. (Pavel Janik)
  109. ;; Filtered process calls with duplicate dictionary entries.
  110. ;; Fixed bug where message-text-end is inside a mime skipped region.
  111. ;; Minor fixes to get ispell menus right in XEmacs
  112. ;; Fixed skip regexp so it doesn't match stuff like `/.\w'.
  113. ;; Detecting dictionary change not working. Fixed. kss
  114. ;; function `ispell-change-dictionary' now only completes valid dicts.
  115. ;; Revision 3.5 2001/7/11 18:43:57 kss
  116. ;; Added fix for aspell to work in XEmacs (ispell-check-version).
  117. ;; Added Portuguese dictionary definition.
  118. ;; New feature: MIME mail message support, Fcc support.
  119. ;; Bug fix: retain comment syntax on lines with region skipping. (TeX $ bug...)
  120. ;; Improved allocation for graphic mode lines. (Miles Bader)
  121. ;; Support -v flag for old versions of aspell. (Eli Zaretskii)
  122. ;; Clear minibuffer on ^G from ispell-help (Tak Ota)
  123. ;; Revision 3.4 2000/8/4 09:41:50 kss
  124. ;; Support new color display functions.
  125. ;; Fixed misalignment offset bug when replacing a string after a shift made.
  126. ;; Set to standard Author/Maintainer heading,
  127. ;; ensure localwords lists are separated from the text by newline. (Dave Love)
  128. ;; Added dictionary definition for Italian (William Deakin)
  129. ;; HTML region skipping greatly improved. (Chuck D. Phillips)
  130. ;; improved menus. Fixed regexp matching http/email addresses.
  131. ;; one arg always for XEmacs sleep-for (gunnar Evermann)
  132. ;; support for synchronous processes (Eli Zaretskii)
  133. ;; Revision 3.3 1999/11/29 11:38:34 kss
  134. ;; Only word replacements entered in from the keyboard are rechecked.
  135. ;; This fixes a bug in tex parsing and misalignment.
  136. ;; Exceptions exist for recursive edit and query-replace, with tex error
  137. ;; condition tested. Recursive editing improved.
  138. ;; XEmacs repair for when `enable-multibyte-characters' defined - Didier Verna.
  139. ;; ispell-help fixed for XEmacs. Choices minibuffer now displayed in XEmacs.
  140. ;; Only list valid dictionaries in Spell menu. Russian dictionary doesn't allow
  141. ;; run-together words, and uses koi8-r font. Don't skip text in html <TT>
  142. ;; fonts.
  143. ;; Revision 3.2 1999/5/7 14:25:14 kss
  144. ;; Accept ispell versions 3.X.Y where X>=1
  145. ;; fine tuned latex region skipping. Fixed bug in ispell-word that did not
  146. ;; point in right place on words < 2 chars. Simplified ispell-minor-mode.
  147. ;; Fixed bug in TeX parsing when math commands are in the comments.
  148. ;; Removed calls to `when' macro.
  149. ;; Revision 3.1 1998/12/1 13:21:52 kss
  150. ;; Improved and fixed customize support.
  151. ;; Improved and fixed comments in variables and messages.
  152. ;; A coding system is now required for all languages.
  153. ;; casechars improved for castellano, castellano8, and norsk dictionaries.
  154. ;; Dictionary norsk7-tex removed. Dictionary polish added.
  155. ;; Dictionaries redefined at load-time to support dictionary changes.
  156. ;; Menu redefined at load time to support dictionary changes.
  157. ;; ispell-check-version added as an alias for `check-ispell-version'.
  158. ;; Spelling suggestions returned in order generated by ispell.
  159. ;; Small bug fixed in matching ispell error messages.
  160. ;; Robustness added to ensure `case-fold-search' doesn't get redefined.
  161. ;; Fixed bug that didn't respect case of word in `ispell-complete-word'.
  162. ;; Multibyte character coding support added for process interactions.
  163. ;; Ensure ispell process has terminated before starting new process.
  164. ;; This can otherwise confuse process filters and hang ispell.
  165. ;; Improved skipping support for SGML.
  166. ;; Fixed bug using ^M rather than \r in `ispell-minor-check'.
  167. ;; Improved message reference matching in `ispell-message'.
  168. ;; Fixed bug in returning to nroff mode from tex mode.
  169. ;;; Compatibility code for XEmacs and (not too) older emacsen:
  170. (eval-and-compile ;; Protect against declare-function undefined in XEmacs
  171. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
  172. (declare-function ispell-check-minver "ispell" (v1 v2))
  173. (declare-function ispell-looking-back "ispell"
  174. (regexp &optional limit &rest ignored))
  175. (if (fboundp 'version<=)
  176. (defalias 'ispell-check-minver 'version<=)
  177. (defun ispell-check-minver (minver version)
  178. "Check if string VERSION is at least string MINVER.
  179. Both must be in [0-9]+.[0-9]+... format. This is a fallback
  180. compatibility function in case `version<=' is not available."
  181. (let ((pending t)
  182. (return t)
  183. start-ver start-mver)
  184. ;; Loop until an absolute greater or smaller condition is reached
  185. ;; or until no elements are left in any of version and minver. In
  186. ;; this case version is exactly the minimal, so return OK.
  187. (while pending
  188. (let (ver mver)
  189. (if (string-match "[0-9]+" version start-ver)
  190. (setq start-ver (match-end 0)
  191. ver (string-to-number (match-string 0 version))))
  192. (if (string-match "[0-9]+" minver start-mver)
  193. (setq start-mver (match-end 0)
  194. mver (string-to-number (match-string 0 minver))))
  195. (if (or ver mver)
  196. (progn
  197. (or ver (setq ver 0))
  198. (or mver (setq mver 0))
  199. ;; If none of below conditions match, this element is the
  200. ;; same. Go checking next element.
  201. (if (> ver mver)
  202. (setq pending nil)
  203. (if (< ver mver)
  204. (setq pending nil
  205. return nil))))
  206. (setq pending nil))))
  207. return)))
  208. ;; XEmacs does not have looking-back
  209. (if (fboundp 'looking-back)
  210. (defalias 'ispell-looking-back 'looking-back)
  211. (defun ispell-looking-back (regexp &optional limit &rest ignored)
  212. "Return non-nil if text before point matches regular expression REGEXP.
  213. Like `looking-at' except matches before point, and is slower.
  214. LIMIT if non-nil speeds up the search by specifying a minimum
  215. starting position, to avoid checking matches that would start
  216. before LIMIT.
  217. This is a stripped down compatibility function for use when
  218. full featured `looking-back' function is missing."
  219. (save-excursion
  220. (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t))))
  221. ;;; XEmacs21 does not have `with-no-warnings'. Taken from org mode.
  222. (defmacro ispell-with-no-warnings (&rest body)
  223. (cons (if (fboundp 'with-no-warnings) 'with-no-warnings 'progn) body))
  224. ;;; Code:
  225. (defvar mail-yank-prefix)
  226. (defgroup ispell nil
  227. "User variables for Emacs ispell interface."
  228. :group 'applications)
  229. (if (not (fboundp 'buffer-substring-no-properties))
  230. (defun buffer-substring-no-properties (start end)
  231. (buffer-substring start end)))
  232. (defalias 'check-ispell-version 'ispell-check-version)
  233. ;;; **********************************************************************
  234. ;;; The following variables should be set according to personal preference
  235. ;;; and location of binaries:
  236. ;;; **********************************************************************
  237. ;;; ******* THIS FILE IS WRITTEN FOR ISPELL VERSION 3.1+
  238. (defcustom ispell-highlight-p 'block
  239. "Highlight spelling errors when non-nil.
  240. When set to `block', assumes a block cursor with TTY displays."
  241. :type '(choice (const block) (const :tag "off" nil) (const :tag "on" t))
  242. :group 'ispell)
  243. (defcustom ispell-lazy-highlight (boundp 'lazy-highlight-cleanup)
  244. "Controls the lazy-highlighting of spelling errors.
  245. When non-nil, all text in the buffer matching the current spelling
  246. error is highlighted lazily using isearch lazy highlighting (see
  247. `lazy-highlight-initial-delay' and `lazy-highlight-interval')."
  248. :type 'boolean
  249. :group 'lazy-highlight
  250. :group 'ispell
  251. :version "22.1")
  252. (defcustom ispell-highlight-face (if ispell-lazy-highlight 'isearch 'highlight)
  253. "Face used for Ispell highlighting.
  254. This variable can be set by the user to whatever face they desire.
  255. It's most convenient if the cursor color and highlight color are
  256. slightly different."
  257. :type 'face
  258. :group 'ispell)
  259. (defcustom ispell-check-comments t
  260. "Spelling of comments checked when non-nil.
  261. When set to `exclusive', ONLY comments are checked. (For code comments).
  262. Warning! Not checking comments, when a comment start is embedded in strings,
  263. may produce undesired results."
  264. :type '(choice (const exclusive) (const :tag "off" nil) (const :tag "on" t))
  265. :group 'ispell)
  266. ;;;###autoload
  267. (put 'ispell-check-comments 'safe-local-variable
  268. (lambda (a) (memq a '(nil t exclusive))))
  269. (defcustom ispell-query-replace-choices nil
  270. "Corrections made throughout region when non-nil.
  271. Uses `query-replace' (\\[query-replace]) for corrections."
  272. :type 'boolean
  273. :group 'ispell)
  274. (defcustom ispell-skip-tib nil
  275. "Does not spell check `tib' bibliography references when non-nil.
  276. Skips any text between strings matching regular expressions
  277. `ispell-tib-ref-beginning' and `ispell-tib-ref-end'.
  278. TeX users beware: Any text between [. and .] will be skipped -- even if
  279. that's your whole buffer -- unless you set `ispell-skip-tib' to nil.
  280. That includes the [.5mm] type of number..."
  281. :type 'boolean
  282. :group 'ispell)
  283. (defvar ispell-tib-ref-beginning "[[<]\\."
  284. "Regexp matching the beginning of a Tib reference.")
  285. (defvar ispell-tib-ref-end "\\.[]>]"
  286. "Regexp matching the end of a Tib reference.")
  287. (defcustom ispell-keep-choices-win t
  288. "If non-nil, keep the `*Choices*' window for the entire spelling session.
  289. This minimizes redisplay thrashing."
  290. :type 'boolean
  291. :group 'ispell)
  292. (defcustom ispell-choices-win-default-height 2
  293. "The default size of the `*Choices*' window, including the mode line.
  294. Must be greater than 1."
  295. :type 'integer
  296. :group 'ispell)
  297. (defcustom ispell-program-name
  298. (or (executable-find "aspell")
  299. (executable-find "ispell")
  300. (executable-find "hunspell")
  301. "ispell")
  302. "Program invoked by \\[ispell-word] and \\[ispell-region] commands."
  303. :type 'string
  304. :set (lambda (symbol value)
  305. (set-default symbol value)
  306. (if (featurep 'ispell)
  307. (ispell-set-spellchecker-params)))
  308. :group 'ispell)
  309. (defcustom ispell-alternate-dictionary
  310. (cond ((file-readable-p "/usr/dict/web2") "/usr/dict/web2")
  311. ((file-readable-p "/usr/share/dict/web2") "/usr/share/dict/web2")
  312. ((file-readable-p "/usr/dict/words") "/usr/dict/words")
  313. ((file-readable-p "/usr/lib/dict/words") "/usr/lib/dict/words")
  314. ((file-readable-p "/usr/share/dict/words") "/usr/share/dict/words")
  315. ((file-readable-p "/usr/share/lib/dict/words")
  316. "/usr/share/lib/dict/words")
  317. ((file-readable-p "/sys/dict") "/sys/dict"))
  318. "Alternate plain word-list dictionary for spelling help."
  319. :type '(choice file (const :tag "None" nil))
  320. :group 'ispell)
  321. (defcustom ispell-complete-word-dict nil
  322. "Plain word-list dictionary used for word completion if
  323. different from `ispell-alternate-dictionary'."
  324. :type '(choice file (const :tag "None" nil))
  325. :group 'ispell)
  326. (defcustom ispell-message-dictionary-alist nil
  327. "List used by `ispell-message' to select a new dictionary.
  328. It consists of pairs (REGEXP . DICTIONARY). If REGEXP is found
  329. in the message headers, `ispell-local-dictionary' will be set to
  330. DICTIONARY if `ispell-local-dictionary' is not buffer-local.
  331. E.g. you may use the following value:
  332. ((\"^Newsgroups:[ \\t]*de\\\\.\" . \"deutsch8\")
  333. (\"^To:[^\\n,]+\\\\.de[ \\t\\n,>]\" . \"deutsch8\"))"
  334. :type '(repeat (cons regexp string))
  335. :group 'ispell)
  336. (defcustom ispell-message-fcc-skip 50000
  337. "Query before saving Fcc message copy if attachment larger than this value.
  338. Always stores Fcc copy of message when nil."
  339. :type '(choice integer (const :tag "off" nil))
  340. :group 'ispell)
  341. (defcustom ispell-grep-command
  342. ;; MS-Windows/MS-DOS have `egrep' as a Unix shell script, so they
  343. ;; cannot invoke it. Use "grep -E" instead (see ispell-grep-options
  344. ;; below).
  345. (if (memq system-type '(windows-nt ms-dos)) "grep" "egrep")
  346. "Name of the grep command for search processes."
  347. :type 'string
  348. :group 'ispell)
  349. (defcustom ispell-grep-options
  350. (if (memq system-type '(windows-nt ms-dos)) "-Ei" "-i")
  351. "String of options to use when running the program in `ispell-grep-command'.
  352. Should probably be \"-i\" or \"-e\".
  353. Some machines (like the NeXT) don't support \"-i\"."
  354. :type 'string
  355. :group 'ispell)
  356. (defcustom ispell-look-command
  357. (cond ((file-exists-p "/bin/look") "/bin/look")
  358. ((file-exists-p "/usr/local/bin/look") "/usr/local/bin/look")
  359. ((file-exists-p "/usr/bin/look") "/usr/bin/look")
  360. (t "look"))
  361. "Name of the look command for search processes.
  362. This must be an absolute file name."
  363. :type 'file
  364. :group 'ispell)
  365. (defcustom ispell-look-p (file-exists-p ispell-look-command)
  366. "Non-nil means use `look' rather than `grep'.
  367. Default is based on whether `look' seems to be available."
  368. :type 'boolean
  369. :group 'ispell)
  370. (defcustom ispell-have-new-look nil
  371. "Non-nil means use the `-r' option (regexp) when running `look'."
  372. :type 'boolean
  373. :group 'ispell)
  374. (defcustom ispell-look-options (if ispell-have-new-look "-dfr" "-df")
  375. "String of command options for `ispell-look-command'."
  376. :type 'string
  377. :group 'ispell)
  378. (defcustom ispell-use-ptys-p nil
  379. "When non-nil, Emacs uses ptys to communicate with Ispell.
  380. When nil, Emacs uses pipes."
  381. :type 'boolean
  382. :group 'ispell)
  383. (defcustom ispell-following-word nil
  384. "Non-nil means `ispell-word' checks the word around or after point.
  385. Otherwise `ispell-word' checks the preceding word."
  386. :type 'boolean
  387. :group 'ispell)
  388. (defcustom ispell-help-in-bufferp nil
  389. "Non-nil means display interactive keymap help in a buffer.
  390. The following values are supported:
  391. nil Expand the minibuffer and display a short help message
  392. there for a couple of seconds.
  393. t Pop up a new buffer and display a short help message there
  394. for a couple of seconds.
  395. electric Pop up a new buffer and display a long help message there.
  396. User can browse and then exit the help mode."
  397. :type '(choice (const electric) (const :tag "off" nil) (const :tag "on" t))
  398. :group 'ispell)
  399. (defcustom ispell-quietly nil
  400. "Non-nil means suppress messages in `ispell-word'."
  401. :type 'boolean
  402. :group 'ispell)
  403. (defcustom ispell-format-word-function (function upcase)
  404. "Formatting function for displaying word being spell checked.
  405. The function must take one string argument and return a string."
  406. :type 'function
  407. :group 'ispell)
  408. (defvaralias 'ispell-format-word 'ispell-format-word-function)
  409. (defcustom ispell-use-framepop-p nil
  410. "When non-nil ispell uses framepop to display choices in a dedicated frame.
  411. You can set this variable to dynamically use framepop if you are in a
  412. window system by evaluating the following on startup to set this variable:
  413. (and window-system (condition-case () (require \\='framepop) (error nil)))"
  414. :type 'boolean
  415. :group 'ispell)
  416. ;;;###autoload
  417. (defcustom ispell-personal-dictionary nil
  418. "File name of your personal spelling dictionary, or nil.
  419. If nil, the default personal dictionary, (\"~/.ispell_DICTNAME\" for ispell or
  420. \"~/.aspell.LANG.pws\" for Aspell) is used, where DICTNAME is the name of your
  421. default dictionary and LANG the two letter language code."
  422. :type '(choice file
  423. (const :tag "default" nil))
  424. :group 'ispell)
  425. (defcustom ispell-silently-savep nil
  426. "When non-nil, save personal dictionary without asking for confirmation."
  427. :type 'boolean
  428. :group 'ispell)
  429. (defvar ispell-local-dictionary-overridden nil
  430. "Non-nil means the user has explicitly set this buffer's Ispell dictionary.")
  431. (make-variable-buffer-local 'ispell-local-dictionary-overridden)
  432. (defcustom ispell-local-dictionary nil
  433. "If non-nil, the dictionary to be used for Ispell commands in this buffer.
  434. The value must be a string dictionary name,
  435. or nil, which means use the global setting in `ispell-dictionary'.
  436. Dictionary names are defined in `ispell-local-dictionary-alist'
  437. and `ispell-dictionary-alist'.
  438. Setting `ispell-local-dictionary' to a value has the same effect as
  439. calling \\[ispell-change-dictionary] with that value. This variable
  440. is automatically set when defined in the file with either
  441. `ispell-dictionary-keyword' or the Local Variable syntax."
  442. :type '(choice string
  443. (const :tag "default" nil))
  444. :group 'ispell)
  445. ;;;###autoload
  446. (put 'ispell-local-dictionary 'safe-local-variable 'string-or-null-p)
  447. (make-variable-buffer-local 'ispell-local-dictionary)
  448. (defcustom ispell-dictionary nil
  449. "Default dictionary to use if `ispell-local-dictionary' is nil."
  450. :type '(choice string
  451. (const :tag "default" nil))
  452. :group 'ispell)
  453. (defcustom ispell-extra-args nil
  454. "If non-nil, a list of extra switches to pass to the Ispell program.
  455. For example, (\"-W\" \"3\") to cause it to accept all 1-3 character
  456. words as correct. See also `ispell-dictionary-alist', which may be used
  457. for language-specific arguments."
  458. :type '(repeat string)
  459. :group 'ispell)
  460. (defcustom ispell-skip-html 'use-mode-name
  461. "Indicates whether ispell should skip spell checking of SGML markup.
  462. If t, always skip SGML markup; if nil, never skip; if non-t and non-nil,
  463. guess whether SGML markup should be skipped according to the name of the
  464. buffer's major mode."
  465. :type '(choice (const :tag "always" t) (const :tag "never" nil)
  466. (const :tag "use-mode-name" use-mode-name))
  467. :group 'ispell)
  468. (make-variable-buffer-local 'ispell-skip-html)
  469. (defcustom ispell-local-dictionary-alist nil
  470. "List of local or customized dictionary definitions.
  471. These can override the values in `ispell-dictionary-alist'.
  472. To make permanent changes to your dictionary definitions, you
  473. will need to make your changes in this variable, save, and then
  474. re-start Emacs."
  475. :type '(repeat (list (choice :tag "Dictionary"
  476. (string :tag "Dictionary name")
  477. (const :tag "default" nil))
  478. (regexp :tag "Case characters")
  479. (regexp :tag "Non case characters")
  480. (regexp :tag "Other characters")
  481. (boolean :tag "Many other characters")
  482. (repeat :tag "Ispell command line args"
  483. (string :tag "Arg"))
  484. (choice :tag "Extended character mode"
  485. (const "~tex") (const "~plaintex")
  486. (const "~nroff") (const "~list")
  487. (const "~latin1") (const "~latin3")
  488. (const :tag "default" nil))
  489. (coding-system :tag "Coding System")))
  490. :group 'ispell)
  491. (defvar ispell-dictionary-base-alist
  492. '((nil ; default
  493. ;; The default dictionary. It may be English.aff, or any other
  494. ;; dictionary depending on locale and such things. We should probably
  495. ;; ask ispell what dictionary it's using, but until we do that, let's
  496. ;; just use a minimal regexp. [:alpha:] will later be set if possible.
  497. "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
  498. ("american" ; Yankee English
  499. "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
  500. ("brasileiro" ; Brazilian mode
  501. "[A-Z\301\311\315\323\332\300\310\314\322\331\303\325\307\334\302\312\324a-z\341\351\355\363\372\340\350\354\362\371\343\365\347\374\342\352\364]"
  502. "[^A-Z\301\311\315\323\332\300\310\314\322\331\303\325\307\334\302\312\324a-z\341\351\355\363\372\340\350\354\362\371\343\365\347\374\342\352\364]"
  503. "[']" nil nil nil iso-8859-1)
  504. ("british" ; British version
  505. "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
  506. ("castellano" ; Spanish mode
  507. "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
  508. "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
  509. "[-]" nil ("-B") "~tex" iso-8859-1)
  510. ("castellano8" ; 8 bit Spanish mode
  511. "[A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
  512. "[^A-Z\301\311\315\321\323\332\334a-z\341\351\355\361\363\372\374]"
  513. "[-]" nil ("-B" "-d" "castellano") "~latin1" iso-8859-1)
  514. ("czech"
  515. "[A-Za-z\301\311\314\315\323\332\331\335\256\251\310\330\317\253\322\341\351\354\355\363\372\371\375\276\271\350\370\357\273\362]"
  516. "[^A-Za-z\301\311\314\315\323\332\331\335\256\251\310\330\317\253\322\341\351\354\355\363\372\371\375\276\271\350\370\357\273\362]"
  517. "" nil ("-B") nil iso-8859-2)
  518. ("dansk" ; Dansk.aff
  519. "[A-Z\306\330\305a-z\346\370\345]" "[^A-Z\306\330\305a-z\346\370\345]"
  520. "[']" nil ("-C") nil iso-8859-1)
  521. ("deutsch" ; Deutsch.aff
  522. "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
  523. ("deutsch8"
  524. "[a-zA-Z\304\326\334\344\366\337\374]"
  525. "[^a-zA-Z\304\326\334\344\366\337\374]"
  526. "[']" t ("-C" "-d" "deutsch") "~latin1" iso-8859-1)
  527. ("english" ; make English explicitly selectable
  528. "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
  529. ("esperanto"
  530. "[A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
  531. "[^A-Za-z\246\254\266\274\306\330\335\336\346\370\375\376]"
  532. "[-']" t ("-C") "~latin3" iso-8859-3)
  533. ("esperanto-tex"
  534. "[A-Za-z^\\]" "[^A-Za-z^\\]"
  535. "[-'`\"]" t ("-C" "-d" "esperanto") "~tex" iso-8859-3)
  536. ("finnish"
  537. "[A-Za-z\345\344\366\305\304\326]"
  538. "[^A-Za-z\345\344\366\305\304\326]"
  539. "[:]" nil ("-C") "~list" iso-8859-1)
  540. ("francais7"
  541. "[A-Za-z]" "[^A-Za-z]" "[`'^-]" t nil nil iso-8859-1)
  542. ("francais" ; Francais.aff
  543. "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
  544. "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374]"
  545. "[-'.@]" t nil "~list" iso-8859-1)
  546. ("francais-tex" ; Francais.aff
  547. "[A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
  548. "[^A-Za-z\300\302\306\307\310\311\312\313\316\317\324\331\333\334\340\342\347\350\351\352\353\356\357\364\371\373\374\\]"
  549. "[-'^`\".@]" t nil "~tex" iso-8859-1)
  550. ("german" ; german.aff
  551. "[a-zA-Z\"]" "[^a-zA-Z\"]" "[']" t ("-C") "~tex" iso-8859-1)
  552. ("german8" ; german.aff
  553. "[a-zA-Z\304\326\334\344\366\337\374]"
  554. "[^a-zA-Z\304\326\334\344\366\337\374]"
  555. "[']" t ("-C" "-d" "german") "~latin1" iso-8859-1)
  556. ("italiano" ; Italian.aff
  557. "[A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
  558. "[^A-Z\300\301\310\311\314\315\322\323\331\332a-z\340\341\350\351\354\355\363\371\372]"
  559. "[-.]" nil ("-B" "-d" "italian") "~tex" iso-8859-1)
  560. ("nederlands" ; Nederlands.aff
  561. "[A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
  562. "[^A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
  563. "[']" t ("-C") nil iso-8859-1)
  564. ("nederlands8" ; Dutch8.aff
  565. "[A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
  566. "[^A-Za-z\300\301\302\303\304\305\307\310\311\312\313\314\315\316\317\322\323\324\325\326\331\332\333\334\340\341\342\343\344\345\347\350\351\352\353\354\355\356\357\361\362\363\364\365\366\371\372\373\374]"
  567. "[']" t ("-C") nil iso-8859-1)
  568. ("norsk" ; 8 bit Norwegian mode
  569. "[A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
  570. "[^A-Za-z\305\306\307\310\311\322\324\330\345\346\347\350\351\362\364\370]"
  571. "[\"]" nil nil "~list" iso-8859-1)
  572. ("norsk7-tex" ; 7 bit Norwegian TeX mode
  573. "[A-Za-z{}\\'^`]" "[^A-Za-z{}\\'^`]"
  574. "[\"]" nil ("-d" "norsk") "~plaintex" iso-8859-1)
  575. ("polish" ; Polish mode
  576. "[A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
  577. "[^A-Za-z\241\243\246\254\257\261\263\266\274\277\306\312\321\323\346\352\361\363]"
  578. "[.]" nil nil nil iso-8859-2)
  579. ("portugues" ; Portuguese mode
  580. "[a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
  581. "[^a-zA-Z\301\302\307\311\323\340\341\342\351\352\355\363\343\347\372]"
  582. "[']" t ("-C") "~latin1" iso-8859-1)
  583. ("russian" ; Russian.aff (KOI8-R charset)
  584. "[\341\342\367\347\344\345\263\366\372\351\352\353\354\355\356\357\360\362\363\364\365\346\350\343\376\373\375\370\371\377\374\340\361\301\302\327\307\304\305\243\326\332\311\312\313\314\315\316\317\320\322\323\324\325\306\310\303\336\333\335\330\331\337\334\300\321]"
  585. "[^\341\342\367\347\344\345\263\366\372\351\352\353\354\355\356\357\360\362\363\364\365\346\350\343\376\373\375\370\371\377\374\340\361\301\302\327\307\304\305\243\326\332\311\312\313\314\315\316\317\320\322\323\324\325\306\310\303\336\333\335\330\331\337\334\300\321]"
  586. "" nil nil nil koi8-r)
  587. ("russianw" ; russianw.aff (CP1251 charset)
  588. "[\300\301\302\303\304\305\250\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\334\333\332\335\336\337\340\341\342\343\344\345\270\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\374\373\372\375\376\377]"
  589. "[^\300\301\302\303\304\305\250\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\334\333\332\335\336\337\340\341\342\343\344\345\270\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\374\373\372\375\376\377]"
  590. "" nil nil nil windows-1251)
  591. ("slovak" ; Slovakian
  592. "[A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
  593. "[^A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
  594. "" nil ("-B") nil iso-8859-2)
  595. ("slovenian" ; Slovenian
  596. "[A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
  597. "[^A-Za-z\301\304\311\315\323\332\324\300\305\245\335\256\251\310\317\253\322\341\344\351\355\363\372\364\340\345\265\375\276\271\350\357\273\362]"
  598. "" nil ("-B" "-d" "slovenian") nil iso-8859-2)
  599. ("svenska" ; Swedish mode
  600. "[A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
  601. "[^A-Za-z\345\344\366\351\340\374\350\346\370\347\305\304\326\311\300\334\310\306\330\307]"
  602. "[']" nil ("-C") "~list" iso-8859-1)
  603. ("hebrew" "[\340\341\342\343\344\345\346\347\350\351\353\352\354\356\355\360\357\361\362\364\363\367\366\365\370\371\372]" "[^\340\341\342\343\344\345\346\347\350\351\353\352\354\356\355\360\357\361\362\364\363\367\366\365\370\371\372]" "" nil ("-B") nil cp1255))
  604. "Base value for `ispell-dictionary-alist'.")
  605. (defvar ispell-dictionary-alist nil
  606. "An alist of dictionaries and their associated parameters.
  607. Each element of this list is also a list:
  608. (DICTIONARY-NAME CASECHARS NOT-CASECHARS OTHERCHARS MANY-OTHERCHARS-P
  609. ISPELL-ARGS EXTENDED-CHARACTER-MODE CHARACTER-SET)
  610. DICTIONARY-NAME is a possible string value of variable `ispell-dictionary',
  611. nil means the default dictionary.
  612. CASECHARS is a regular expression of valid characters that comprise a word.
  613. NOT-CASECHARS is the opposite regexp of CASECHARS.
  614. OTHERCHARS is a regexp of characters in the NOT-CASECHARS set but which can be
  615. used to construct words in some special way. If OTHERCHARS characters follow
  616. and precede characters from CASECHARS, they are parsed as part of a word,
  617. otherwise they become word-breaks. As an example in English, assume the
  618. regular expression \"[']\" for OTHERCHARS. Then \"they're\" and
  619. \"Steven's\" are parsed as single words including the \"'\" character, but
  620. \"Stevens'\" does not include the quote character as part of the word.
  621. If you want OTHERCHARS to be empty, use the empty string.
  622. Hint: regexp syntax requires the hyphen to be declared first here.
  623. CASECHARS, NOT-CASECHARS, and OTHERCHARS must be unibyte strings
  624. containing bytes of CHARACTER-SET. In addition, if they contain
  625. non-ASCII bytes, the regular expression must be a single
  626. `character set' construct that doesn't specify a character range
  627. for non-ASCII bytes.
  628. MANY-OTHERCHARS-P is non-nil when multiple OTHERCHARS are allowed in a word.
  629. Otherwise only a single OTHERCHARS character is allowed to be part of any
  630. single word.
  631. ISPELL-ARGS is a list of additional arguments passed to the ispell
  632. subprocess.
  633. EXTENDED-CHARACTER-MODE should be used when dictionaries are used which
  634. have been configured in an Ispell affix file. (For example, umlauts
  635. can be encoded as \\\"a, a\\\", \"a, ...) Defaults are ~tex and ~nroff
  636. in English. This has the same effect as the command-line `-T' option.
  637. The buffer Major Mode controls Ispell's parsing in tex or nroff mode,
  638. but the dictionary can control the extended character mode.
  639. Both defaults can be overruled in a buffer-local fashion. See
  640. `ispell-parsing-keyword' for details on this.
  641. CHARACTER-SET used to encode text sent to the ispell subprocess
  642. when the language uses non-ASCII characters.
  643. Note that with \"ispell\" as the speller, the CASECHARS and
  644. OTHERCHARS slots of the alist should contain the same character
  645. set as casechars and otherchars in the LANGUAGE.aff file \(e.g.,
  646. english.aff). Aspell and Hunspell don't have this limitation.")
  647. (defvar ispell-really-aspell nil
  648. "Non-nil if we can use Aspell extensions.")
  649. (defvar ispell-really-hunspell nil
  650. "Non-nil if we can use Hunspell extensions.")
  651. (defvar ispell-encoding8-command nil
  652. "Command line option prefix to select encoding if supported, nil otherwise.
  653. If setting the encoding is supported by spellchecker and is selectable from
  654. the command line, this variable will contain \"--encoding=\" for Aspell
  655. and \"-i \" for Hunspell, so the appropriate mime charset can be selected.
  656. That will be set in `ispell-check-version' for Hunspell >= 1.1.6 and
  657. Aspell >= 0.60.
  658. For Aspell, non-nil also means to try to automatically find its dictionaries.
  659. Earlier Aspell versions do not consistently support charset encoding. Handling
  660. this would require some extra guessing in `ispell-aspell-find-dictionary'.")
  661. (defvar ispell-aspell-supports-utf8 nil
  662. "Non-nil if Aspell has consistent command line UTF-8 support. Obsolete.
  663. ispell.el and flyspell.el will use for this purpose the more generic
  664. variable `ispell-encoding8-command' for both Aspell and Hunspell. Is left
  665. here just for backwards compatibility.")
  666. (make-obsolete-variable 'ispell-aspell-supports-utf8
  667. 'ispell-encoding8-command "23.1")
  668. (defvar ispell-dicts-name2locale-equivs-alist
  669. '(("american" "en_US")
  670. ("brasileiro" "pt_BR")
  671. ("british" "en_GB")
  672. ("castellano" "es_ES")
  673. ("castellano8" "es_ES")
  674. ("czech" "cs_CZ")
  675. ("dansk" "da_DK")
  676. ("deutsch" "de_DE")
  677. ("deutsch8" "de_DE")
  678. ("english" "en_US")
  679. ("esperanto" "eo")
  680. ("esperanto-tex" "eo")
  681. ("finnish" "fi_FI")
  682. ("francais7" "fr_FR")
  683. ("francais" "fr_FR")
  684. ("francais-tex" "fr_FR")
  685. ("german" "de_DE")
  686. ("german8" "de_DE")
  687. ("italiano" "it_IT")
  688. ("nederlands" "nl_NL")
  689. ("nederlands8" "nl_NL")
  690. ("norsk" "nn_NO")
  691. ("norsk7-tex" "nn_NO")
  692. ("polish" "pl_PL")
  693. ("portugues" "pt_PT")
  694. ("russian" "ru_RU")
  695. ("russianw" "ru_RU")
  696. ("slovak" "sk_SK")
  697. ("slovenian" "sl_SI")
  698. ("svenska" "sv_SE")
  699. ("hebrew" "he_IL"))
  700. "Alist with known matching locales for standard dict names in
  701. `ispell-dictionary-base-alist'.")
  702. (defvar ispell-emacs-alpha-regexp
  703. (if (string-match "^[[:alpha:]]+$" "abcde")
  704. "[[:alpha:]]"
  705. nil)
  706. "[[:alpha:]] if Emacs supports [:alpha:] regexp, nil
  707. otherwise (current XEmacs does not support it).")
  708. ;;; **********************************************************************
  709. ;;; The following are used by ispell, and should not be changed.
  710. ;;; **********************************************************************
  711. ;; The version must be 3.1 or greater for this version of ispell.el
  712. ;; There is an incompatibility between version 3.1.12 and lower versions.
  713. (defconst ispell-required-version '(3 1 12)
  714. "Ispell versions with which this version of ispell.el is known to work.")
  715. (defvar ispell-offset -1
  716. "Offset that maps protocol differences between ispell 3.1 versions.")
  717. (defconst ispell-version "ispell.el 3.6 - 7-Jan-2003")
  718. (defun ispell-check-version (&optional interactivep)
  719. "Ensure that `ispell-program-name' is valid and has the correct version.
  720. Returns version number if called interactively.
  721. Otherwise returns the library directory name, if that is defined."
  722. ;; This is a little wasteful as we actually launch ispell twice: once
  723. ;; to make sure it's the right version, and once for real. But people
  724. ;; get confused by version mismatches *all* the time (and I've got the
  725. ;; email to prove it) so I think this is worthwhile. And the -v[ersion]
  726. ;; option is the only way I can think of to do this that works with
  727. ;; all versions, since versions earlier than 3.0.09 didn't identify
  728. ;; themselves on startup.
  729. (interactive "p")
  730. (let ((default-directory (or (and (boundp 'temporary-file-directory)
  731. temporary-file-directory)
  732. default-directory))
  733. result status ispell-program-version)
  734. (with-temp-buffer
  735. (setq status (ispell-call-process
  736. ispell-program-name nil t nil
  737. ;; aspell doesn't accept the -vv switch.
  738. (let ((case-fold-search
  739. (memq system-type '(ms-dos windows-nt)))
  740. (speller
  741. (file-name-nondirectory ispell-program-name)))
  742. ;; Assume anything that isn't `aspell' is Ispell.
  743. (if (string-match "\\`aspell" speller) "-v" "-vv"))))
  744. (goto-char (point-min))
  745. (if interactivep
  746. ;; Report version information of ispell and ispell.el
  747. (progn
  748. (end-of-line)
  749. (setq result (concat (buffer-substring-no-properties (point-min)
  750. (point))
  751. ", "
  752. ispell-version))
  753. (message "%s" result))
  754. ;; return library directory.
  755. (if (re-search-forward "LIBDIR = \\\"\\([^ \t\n]*\\)\\\"" nil t)
  756. (setq result (match-string 1))))
  757. (goto-char (point-min))
  758. (if (not (memq status '(0 nil)))
  759. (error "%s exited with %s %s" ispell-program-name
  760. (if (stringp status) "signal" "code") status))
  761. ;; Get relevant version strings. Only xx.yy.... format works well
  762. (let (case-fold-search)
  763. (setq ispell-program-version
  764. (and (search-forward-regexp "\\([0-9]+\\.[0-9\\.]+\\)" nil t)
  765. (match-string 1)))
  766. ;; Make sure these variables are (re-)initialized to the default value
  767. (setq ispell-really-aspell nil
  768. ispell-aspell-supports-utf8 nil
  769. ispell-really-hunspell nil
  770. ispell-encoding8-command nil)
  771. (goto-char (point-min))
  772. (or (setq ispell-really-aspell
  773. (and (search-forward-regexp
  774. "(but really Aspell \\([0-9]+\\.[0-9\\.-]+\\)?)" nil t)
  775. (match-string 1)))
  776. (setq ispell-really-hunspell
  777. (and (search-forward-regexp
  778. "(but really Hunspell \\([0-9]+\\.[0-9\\.-]+\\)?)"
  779. nil t)
  780. (match-string 1)))))
  781. (let ((aspell-minver "0.50")
  782. (aspell8-minver "0.60")
  783. (ispell0-minver "3.1.0")
  784. (ispell-minver "3.1.12")
  785. (hunspell8-minver "1.1.6"))
  786. (if (ispell-check-minver ispell0-minver ispell-program-version)
  787. (or (ispell-check-minver ispell-minver ispell-program-version)
  788. (setq ispell-offset 0))
  789. (error "%s release %s or greater is required"
  790. ispell-program-name
  791. ispell-minver))
  792. (cond
  793. (ispell-really-aspell
  794. (if (ispell-check-minver aspell-minver ispell-really-aspell)
  795. (if (ispell-check-minver aspell8-minver ispell-really-aspell)
  796. (progn
  797. (setq ispell-aspell-supports-utf8 t)
  798. (setq ispell-encoding8-command "--encoding=")))
  799. (setq ispell-really-aspell nil)))
  800. (ispell-really-hunspell
  801. (if (ispell-check-minver hunspell8-minver ispell-really-hunspell)
  802. (setq ispell-encoding8-command "-i")
  803. (setq ispell-really-hunspell nil))))))
  804. result))
  805. (defun ispell-call-process (&rest args)
  806. "Like `call-process' but defend against bad `default-directory'."
  807. (let ((default-directory default-directory))
  808. (unless (file-accessible-directory-p default-directory)
  809. (setq default-directory (expand-file-name "~/")))
  810. (apply 'call-process args)))
  811. (defun ispell-call-process-region (&rest args)
  812. "Like `call-process-region' but defend against bad `default-directory'."
  813. (let ((default-directory default-directory))
  814. (unless (file-accessible-directory-p default-directory)
  815. (setq default-directory (expand-file-name "~/")))
  816. (apply 'call-process-region args)))
  817. (defun ispell-create-debug-buffer (&optional append)
  818. "Create an ispell debug buffer for debugging output.
  819. If APPEND is non-nil, append the info to previous buffer if exists,
  820. otherwise is reset. Returns name of ispell debug buffer.
  821. See `ispell-buffer-with-debug' for an example of use."
  822. (let ((ispell-debug-buffer (get-buffer-create "*ispell-debug*")))
  823. (with-current-buffer ispell-debug-buffer
  824. (if append
  825. (insert
  826. (format "-----------------------------------------------\n"))
  827. (erase-buffer)))
  828. ispell-debug-buffer))
  829. (defsubst ispell-print-if-debug (format &rest args)
  830. "Print message using FORMAT and ARGS to `ispell-debug-buffer' buffer if enabled."
  831. (if (boundp 'ispell-debug-buffer)
  832. (with-current-buffer ispell-debug-buffer
  833. (goto-char (point-max))
  834. (insert (apply #'format format args)))))
  835. ;; The preparation of the menu bar menu must be autoloaded
  836. ;; because otherwise this file gets autoloaded every time Emacs starts
  837. ;; so that it can set up the menus and determine keyboard equivalents.
  838. ;;;###autoload
  839. (defvar ispell-menu-map nil "Key map for ispell menu.")
  840. ;; Redo menu when loading ispell to get dictionary modifications
  841. (setq ispell-menu-map nil)
  842. ;;;###autoload
  843. (defvar ispell-menu-xemacs nil
  844. "Spelling menu for XEmacs.
  845. If nil when package is loaded, a standard menu will be set,
  846. and added as a submenu of the \"Edit\" menu.")
  847. ;; Break out XEmacs menu and split into several calls to avoid having
  848. ;; long lines in loaddefs.el. Detect need off following constant.
  849. ;;; Set up dictionary
  850. ;;;###autoload
  851. (defvar ispell-menu-map-needed
  852. ;; only needed when not version 18 and not XEmacs.
  853. (and (not ispell-menu-map)
  854. (not (featurep 'xemacs))
  855. 'reload))
  856. (defvar ispell-library-directory (condition-case ()
  857. (ispell-check-version)
  858. (error nil))
  859. "Directory where ispell dictionaries reside.")
  860. (defvar ispell-process nil
  861. "The process object for Ispell.")
  862. (defvar ispell-async-processp (and (fboundp 'delete-process)
  863. (fboundp 'process-send-string)
  864. (fboundp 'accept-process-output)
  865. ;;(fboundp 'start-process)
  866. ;;(fboundp 'set-process-filter)
  867. ;;(fboundp 'process-kill-without-query)
  868. )
  869. "Non-nil means that the OS supports asynchronous processes.")
  870. ;; Make ispell.el work better with aspell.
  871. (defvar ispell-aspell-dictionary-alist nil
  872. "An alist of parsed Aspell dicts and associated parameters.
  873. Internal use.")
  874. (defun ispell-find-aspell-dictionaries ()
  875. "Find Aspell's dictionaries, and record in `ispell-dictionary-alist'."
  876. (unless (and ispell-really-aspell ispell-encoding8-command)
  877. (error "This function only works with Aspell >= 0.60"))
  878. (let* ((dictionaries
  879. (split-string
  880. (with-temp-buffer
  881. (ispell-call-process ispell-program-name nil t nil "dicts")
  882. (buffer-string))))
  883. ;; Search for the named dictionaries.
  884. (found
  885. (delq nil
  886. (mapcar #'ispell-aspell-find-dictionary dictionaries))))
  887. ;; Ensure aspell's alias dictionary will override standard
  888. ;; definitions.
  889. (setq found (ispell-aspell-add-aliases found))
  890. ;; Merge into FOUND any elements from the standard ispell-dictionary-base-alist
  891. ;; which have no element in FOUND at all.
  892. (dolist (dict ispell-dictionary-base-alist)
  893. (unless (assoc (car dict) found)
  894. (setq found (nconc found (list dict)))))
  895. (setq ispell-aspell-dictionary-alist found)
  896. ;; Add a default entry
  897. (let ((default-dict
  898. '(nil "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-B") nil utf-8)))
  899. (push default-dict ispell-aspell-dictionary-alist))))
  900. (defvar ispell-aspell-data-dir nil
  901. "Data directory of Aspell.")
  902. (defvar ispell-aspell-dict-dir nil
  903. "Dictionary directory of Aspell.")
  904. (defun ispell-get-aspell-config-value (key)
  905. "Return value of Aspell configuration option KEY.
  906. Assumes that value contains no whitespace."
  907. (with-temp-buffer
  908. (ispell-call-process ispell-program-name nil t nil "config" key)
  909. (car (split-string (buffer-string)))))
  910. (defun ispell-aspell-find-dictionary (dict-name)
  911. "For Aspell dictionary DICT-NAME, return a list of parameters if an
  912. associated data file is found or nil otherwise. List format is that
  913. of `ispell-dictionary-base-alist' elements."
  914. ;; Make sure `ispell-aspell-dict-dir' is defined
  915. (or ispell-aspell-dict-dir
  916. (setq ispell-aspell-dict-dir
  917. (ispell-get-aspell-config-value "dict-dir")))
  918. ;; Make sure `ispell-aspell-data-dir' is defined
  919. (or ispell-aspell-data-dir
  920. (setq ispell-aspell-data-dir
  921. (ispell-get-aspell-config-value "data-dir")))
  922. ;; Try finding associated datafile. aspell will look for master .dat
  923. ;; file in `dict-dir' and `data-dir'. Associated .dat files must be
  924. ;; in the same directory as master file.
  925. (let ((data-file
  926. (catch 'datafile
  927. (dolist ( tmp-path (list ispell-aspell-dict-dir
  928. ispell-aspell-data-dir ))
  929. ;; Try xx.dat first, strip out variant, country code, etc,
  930. ;; then try xx_YY.dat (without stripping country code),
  931. ;; then try xx-alt.dat, for de-alt etc.
  932. (dolist (tmp-regexp (list "^[[:alpha:]]+"
  933. "^[[:alpha:]_]+"
  934. "^[[:alpha:]]+-\\(alt\\|old\\)"))
  935. (let ((fullpath
  936. (concat tmp-path "/"
  937. (and (string-match tmp-regexp dict-name)
  938. (match-string 0 dict-name)) ".dat")))
  939. (if (file-readable-p fullpath)
  940. (throw 'datafile fullpath)))))))
  941. otherchars)
  942. (if data-file
  943. (with-temp-buffer
  944. (insert-file-contents data-file)
  945. ;; There is zero or one line with special characters declarations.
  946. (when (search-forward-regexp "^special" nil t)
  947. (let ((specials (split-string
  948. (buffer-substring (point)
  949. (progn (end-of-line) (point))))))
  950. ;; The line looks like: special ' -** - -** . -** : -*-
  951. ;; -** means that this character
  952. ;; - doesn't appear at word start
  953. ;; * may appear in the middle of a word
  954. ;; * may appear at word end
  955. ;; `otherchars' is about the middle case.
  956. (while specials
  957. (when (eq (aref (cadr specials) 1) ?*)
  958. (push (car specials) otherchars))
  959. (setq specials (cddr specials)))))
  960. (list dict-name
  961. "[[:alpha:]]"
  962. "[^[:alpha:]]"
  963. (regexp-opt otherchars)
  964. t ; We can't tell, so set this to t
  965. (list "-d" dict-name)
  966. nil ; aspell doesn't support this
  967. ;; Here we specify the encoding to use while communicating with
  968. ;; aspell. This doesn't apply to command line arguments, so
  969. ;; just don't pass words to spellcheck as arguments...
  970. 'utf-8)))))
  971. (defun ispell-aspell-add-aliases (alist)
  972. "Find Aspell's dictionary aliases and add them to dictionary ALIST.
  973. Return the new dictionary alist."
  974. (let ((aliases
  975. (file-expand-wildcards
  976. (concat (or ispell-aspell-dict-dir
  977. (setq ispell-aspell-dict-dir
  978. (ispell-get-aspell-config-value "dict-dir")))
  979. "/*.alias"))))
  980. (dolist (alias-file aliases)
  981. (with-temp-buffer
  982. (insert-file-contents alias-file)
  983. ;; Look for a line "add FOO.multi", extract FOO
  984. (when (search-forward-regexp "^add \\([^.]+\\)\\.multi" nil t)
  985. (let* ((aliasname (file-name-base alias-file))
  986. (already-exists-p (assoc aliasname alist))
  987. (realname (match-string 1))
  988. (realdict (assoc realname alist)))
  989. (when (and realdict (not already-exists-p))
  990. (push (cons aliasname (cdr realdict)) alist))))))
  991. ;; Add entries for standard dict-names with found locale-matching entry
  992. (dolist (dict-map-entry ispell-dicts-name2locale-equivs-alist)
  993. (let ((name (car dict-map-entry))
  994. (locale (cadr dict-map-entry)))
  995. (unless (assoc name alist) ;; skip if already present
  996. (if (assoc locale alist)
  997. (push (cons name (cdr (assoc locale alist))) alist)))))
  998. alist))
  999. ;; Make ispell.el work better with hunspell.
  1000. (defvar ispell-hunspell-dict-paths-alist nil
  1001. "Alist of parsed Hunspell dicts and associated affix files.
  1002. Will be used to parse corresponding .aff file and create associated
  1003. parameters to be inserted into `ispell-hunspell-dictionary-alist'.
  1004. Internal use.")
  1005. (defvar ispell-hunspell-dictionary-alist nil
  1006. "Alist of parsed Hunspell dicts and associated parameters.
  1007. This alist will initially contain names of found dicts. Associated
  1008. parameters will be added when dict is used for the first time.
  1009. Internal use.")
  1010. (defun ispell-hunspell-fill-dictionary-entry (dict)
  1011. "Fill uninitialized entries in `ispell-dictionary-alist' for DICT and aliases.
  1012. Value of those entries will be extracted from Hunspell affix file and used for
  1013. all uninitialized dicts using that affix file."
  1014. (if (cadr (assoc dict ispell-dictionary-alist))
  1015. (message "ispell-hfde: Non void entry for %s. Skipping.\n" dict)
  1016. (let ((dict-alias
  1017. (cadr (assoc dict ispell-dicts-name2locale-equivs-alist)))
  1018. (use-for-dicts (list dict))
  1019. (dict-args-cdr (cdr (ispell-parse-hunspell-affix-file dict)))
  1020. newlist)
  1021. ;; Get a list of uninitialized dicts using the same affix file.
  1022. (dolist (dict-equiv-alist-entry ispell-dicts-name2locale-equivs-alist)
  1023. (let ((dict-equiv-key (car dict-equiv-alist-entry))
  1024. (dict-equiv-value (cadr dict-equiv-alist-entry)))
  1025. (if (or (member dict dict-equiv-alist-entry)
  1026. (member dict-alias dict-equiv-alist-entry))
  1027. (dolist (tmp-dict (list dict-equiv-key dict-equiv-value))
  1028. (if (cadr (assoc tmp-dict ispell-dictionary-alist))
  1029. (ispell-print-if-debug
  1030. "ispell-hfde: %s already expanded; skipping.\n" tmp-dict)
  1031. (add-to-list 'use-for-dicts tmp-dict))))))
  1032. (ispell-print-if-debug
  1033. "ispell-hfde: Filling %s entry. Use for %s.\n" dict use-for-dicts)
  1034. ;; The final loop.
  1035. (dolist (entry ispell-dictionary-alist)
  1036. (if (member (car entry) use-for-dicts)
  1037. (add-to-list 'newlist
  1038. (append (list (car entry)) dict-args-cdr))
  1039. (add-to-list 'newlist entry)))
  1040. (setq ispell-dictionary-alist newlist))))
  1041. (defun ispell-parse-hunspell-affix-file (dict-key)
  1042. "Parse Hunspell affix file to extract parameters for DICT-KEY.
  1043. Return a list in `ispell-dictionary-alist' format.
  1044. DICT_KEY can be in the \"DICT1,DICT2,DICT3\" format, to invoke Hunspell
  1045. with a list of dictionaries. The first dictionary in the list must have
  1046. a corresponding .aff affix file; the rest are allowed to have no affix
  1047. files, and will then use the affix file of the preceding dictionary that
  1048. did."
  1049. (let ((dict-list (split-string dict-key "," t))
  1050. (first-p t)
  1051. (dict-arg "")
  1052. otherchars-list)
  1053. (dolist (dict-key dict-list)
  1054. (let ((affix-file
  1055. (cadr (assoc dict-key ispell-hunspell-dict-paths-alist))))
  1056. (unless affix-file
  1057. (error "ispell-phaf: No matching entry for %s in `ispell-hunspell-dict-paths-alist'.\n" dict-key))
  1058. (if (and first-p (not (file-exists-p affix-file)))
  1059. (error "ispell-phaf: File \"%s\" not found.\n" affix-file))
  1060. (and first-p (setq first-p nil))
  1061. (let ((dict-name (file-name-sans-extension
  1062. (file-name-nondirectory affix-file)))
  1063. otherchars-string)
  1064. (with-temp-buffer
  1065. (insert-file-contents affix-file)
  1066. (setq otherchars-string
  1067. (save-excursion
  1068. (goto-char (point-min))
  1069. (if (search-forward-regexp "^WORDCHARS +" nil t )
  1070. (buffer-substring (point)
  1071. (progn (end-of-line) (point))))))
  1072. ;; Remove trailing whitespace and extra stuff. Make list
  1073. ;; if non-nil.
  1074. (if otherchars-string
  1075. (let* ((otherchars-string
  1076. ;; Remove trailing junk.
  1077. (substring otherchars-string
  1078. 0 (string-match " +" otherchars-string)))
  1079. (chars-list (append otherchars-string nil)))
  1080. (setq chars-list (delq ?\ chars-list))
  1081. (dolist (ch chars-list)
  1082. (add-to-list 'otherchars-list ch)))))
  1083. ;; Cons the argument for the -d switch.
  1084. (setq dict-arg (concat dict-arg
  1085. (if (> (length dict-arg) 0) ",")
  1086. dict-name)))))
  1087. ;; Fill dict entry
  1088. (list dict-key
  1089. "[[:alpha:]]"
  1090. "[^[:alpha:]]"
  1091. (if otherchars-list
  1092. (regexp-opt (mapcar 'char-to-string otherchars-list))
  1093. "")
  1094. t ; many-otherchars-p: We can't tell, set to t.
  1095. (list "-d" dict-arg)
  1096. nil ; extended-char-mode: not supported by hunspell!
  1097. 'utf-8)))
  1098. (defun ispell-hunspell-add-multi-dic (dict)
  1099. "Add DICT of the form \"DICT1,DICT2,...\" to `ispell-dictionary-alist'.
  1100. Invoke this command before you want to start Hunspell for the first time
  1101. with a particular combination of dictionaries. The first dictionary
  1102. in the list must have an affix file where Hunspell affix files are kept."
  1103. (interactive "sMulti-dictionary combination: ")
  1104. ;; Make sure the first dictionary in the list is known to us.
  1105. (let ((first-dict (car (split-string dict "," t))))
  1106. (unless ispell-hunspell-dictionary-alist
  1107. (ispell-find-hunspell-dictionaries)
  1108. (setq ispell-dictionary-alist ispell-hunspell-dictionary-alist))
  1109. (or (assoc first-dict ispell-local-dictionary-alist)
  1110. (assoc first-dict ispell-dictionary-alist)
  1111. (error "Unknown dictionary: %s" first-dict)))
  1112. (add-to-list 'ispell-dictionary-alist (list dict '()))
  1113. (ispell-hunspell-fill-dictionary-entry dict))
  1114. (defun ispell-find-hunspell-dictionaries ()
  1115. "Look for installed Hunspell dictionaries.
  1116. Will initialize `ispell-hunspell-dictionary-alist' and
  1117. `ispell-hunspell-dictionary-alist' after values found
  1118. and remove `ispell-dicts-name2locale-equivs-alist'
  1119. entries if a specific dictionary was found."
  1120. (let ((hunspell-found-dicts
  1121. (split-string
  1122. (with-temp-buffer
  1123. (ispell-call-process ispell-program-name
  1124. null-device
  1125. t
  1126. nil
  1127. "-D")
  1128. (buffer-string))
  1129. "[\n\r]+"
  1130. t))
  1131. hunspell-default-dict
  1132. hunspell-default-dict-entry)
  1133. (dolist (dict hunspell-found-dicts)
  1134. (let* ((full-name (file-name-nondirectory dict))
  1135. (basename (file-name-sans-extension full-name))
  1136. (affix-file (concat dict ".aff")))
  1137. (if (string-match "\\.aff$" dict)
  1138. ;; Found default dictionary
  1139. (if hunspell-default-dict
  1140. (error "ispell-fhd: Default dict already defined as %s. Not using %s.\n"
  1141. hunspell-default-dict dict)
  1142. (setq affix-file dict)
  1143. (setq hunspell-default-dict (list basename affix-file)))
  1144. (if (and (not (assoc basename ispell-hunspell-dict-paths-alist))
  1145. (file-exists-p affix-file))
  1146. ;; Entry has an associated .aff file and no previous value.
  1147. (let ((affix-file (expand-file-name affix-file)))
  1148. (ispell-print-if-debug
  1149. "++ ispell-fhd: dict-entry:%s name:%s basename:%s affix-file:%s\n"
  1150. dict full-name basename affix-file)
  1151. (add-to-list 'ispell-hunspell-dict-paths-alist
  1152. (list basename affix-file)))
  1153. (ispell-print-if-debug
  1154. "-- ispell-fhd: Skipping entry: %s\n" dict)))))
  1155. ;; Remove entry from aliases alist if explicit dict was found.
  1156. (let (newlist)
  1157. (dolist (dict ispell-dicts-name2locale-equivs-alist)
  1158. (if (assoc (car dict) ispell-hunspell-dict-paths-alist)
  1159. (ispell-print-if-debug
  1160. "-- ispell-fhd: Excluding %s alias. Standalone dict found.\n"
  1161. (car dict))
  1162. (add-to-list 'newlist dict)))
  1163. (setq ispell-dicts-name2locale-equivs-alist newlist))
  1164. ;; Add known hunspell aliases
  1165. (dolist (dict-equiv ispell-dicts-name2locale-equivs-alist)
  1166. (let ((dict-equiv-key (car dict-equiv))
  1167. (dict-equiv-value (cadr dict-equiv))
  1168. (exclude-aliases (list ;; Exclude TeX aliases
  1169. "esperanto-tex"
  1170. "francais7"
  1171. "francais-tex"
  1172. "norsk7-tex")))
  1173. (if (and (assoc dict-equiv-value ispell-hunspell-dict-paths-alist)
  1174. (not (assoc dict-equiv-key ispell-hunspell-dict-paths-alist))
  1175. (not (member dict-equiv-key exclude-aliases)))
  1176. (let ((affix-file (cadr (assoc dict-equiv-value
  1177. ispell-hunspell-dict-paths-alist))))
  1178. (ispell-print-if-debug "++ ispell-fhd: Adding alias %s -> %s.\n"
  1179. dict-equiv-key affix-file)
  1180. (add-to-list
  1181. 'ispell-hunspell-dict-paths-alist
  1182. (list dict-equiv-key affix-file))))))
  1183. ;; Parse and set values for default dictionary.
  1184. (setq hunspell-default-dict (car hunspell-default-dict))
  1185. (setq hunspell-default-dict-entry
  1186. (ispell-parse-hunspell-affix-file hunspell-default-dict))
  1187. ;; Create an alist of found dicts with only names, except for default dict.
  1188. (setq ispell-hunspell-dictionary-alist
  1189. (list (append (list nil) (cdr hunspell-default-dict-entry))))
  1190. (dolist (dict (mapcar 'car ispell-hunspell-dict-paths-alist))
  1191. (if (string= dict hunspell-default-dict)
  1192. (add-to-list 'ispell-hunspell-dictionary-alist
  1193. hunspell-default-dict-entry)
  1194. (add-to-list 'ispell-hunspell-dictionary-alist
  1195. (list dict))))))
  1196. ;; Set params according to the selected spellchecker
  1197. (defvar ispell-last-program-name nil
  1198. "Last value of `ispell-program-name'. Internal use.")
  1199. (defvar ispell-initialize-spellchecker-hook nil
  1200. "Normal hook run on spellchecker initialization.
  1201. This hook is run when a spellchecker is used for the first
  1202. time, before `ispell-dictionary-alist' is set. It is intended for
  1203. sysadmins to override entries in `ispell-dictionary-base-alist'
  1204. by putting those overrides in `ispell-base-dicts-override-alist', which is
  1205. a dynamically scoped var with same format as `ispell-dictionary-alist'.
  1206. This alist will not override the auto-detected values (e.g. if a recent
  1207. aspell is used along with Emacs).")
  1208. (defun ispell-set-spellchecker-params ()
  1209. "Initialize some spellchecker parameters when changed or first used."
  1210. (unless (eq ispell-last-program-name ispell-program-name)
  1211. (setq ispell-last-program-name ispell-program-name)
  1212. (ispell-kill-ispell t)
  1213. (if (and (condition-case ()
  1214. (progn
  1215. (setq ispell-library-directory (ispell-check-version))
  1216. t)
  1217. (error nil))
  1218. ispell-encoding8-command
  1219. ispell-emacs-alpha-regexp)
  1220. ;; auto-detection will only be used if spellchecker is not
  1221. ;; ispell, supports a way to set communication to UTF-8 and
  1222. ;; Emacs flavor supports [:alpha:]
  1223. (if ispell-really-aspell
  1224. (or ispell-aspell-dictionary-alist
  1225. (ispell-find-aspell-dictionaries))
  1226. (if ispell-really-hunspell
  1227. (or ispell-hunspell-dictionary-alist
  1228. (ispell-find-hunspell-dictionaries)))))
  1229. ;; Substitute ispell-dictionary-alist with the list of
  1230. ;; dictionaries corresponding to the given spellchecker.
  1231. ;; If a recent aspell or hunspell, use the list of really
  1232. ;; installed dictionaries and add to it elements of the original
  1233. ;; list that are not present there. Allow distro info.
  1234. (let ((found-dicts-alist
  1235. (if (and ispell-encoding8-command
  1236. ispell-emacs-alpha-regexp)
  1237. (if ispell-really-aspell
  1238. ispell-aspell-dictionary-alist
  1239. (if ispell-really-hunspell
  1240. ispell-hunspell-dictionary-alist))
  1241. nil))
  1242. (ispell-dictionary-base-alist ispell-dictionary-base-alist)
  1243. ispell-base-dicts-override-alist ; Override only base-dicts-alist
  1244. all-dicts-alist)
  1245. ;; While ispell and aspell (through aliases) use the traditional
  1246. ;; dict naming originally expected by ispell.el, hunspell
  1247. ;; uses locale based names with no alias. We need to map
  1248. ;; standard names to locale based names to make default dict
  1249. ;; definitions available for hunspell.
  1250. (if ispell-really-hunspell
  1251. (let (tmp-dicts-alist)
  1252. (dolist (adict ispell-dictionary-base-alist)
  1253. (let* ((dict-name (nth 0 adict))
  1254. (dict-equiv
  1255. (cadr (assoc dict-name
  1256. ispell-dicts-name2locale-equivs-alist)))
  1257. (ispell-args (nth 5 adict))
  1258. (ispell-args-has-d (member "-d" ispell-args))
  1259. skip-dict)
  1260. ;; Remove "-d" option from `ispell-args' if present
  1261. (if ispell-args-has-d
  1262. (let ((ispell-args-after-d
  1263. (cdr (cdr ispell-args-has-d)))
  1264. (ispell-args-before-d
  1265. (butlast ispell-args (length ispell-args-has-d))))
  1266. (setq ispell-args
  1267. (nconc ispell-args-before-d
  1268. ispell-args-after-d))))
  1269. ;; Unless default dict, re-add "-d" option with the mapped value
  1270. (if dict-name
  1271. (if dict-equiv
  1272. (setq ispell-args
  1273. (nconc ispell-args (list "-d" dict-equiv)))
  1274. (message
  1275. "ispell-set-spellchecker-params: Missing Hunspell equiv for \"%s\". Skipping."
  1276. dict-name)
  1277. (setq skip-dict t)))
  1278. (unless skip-dict
  1279. (add-to-list 'tmp-dicts-alist
  1280. (list
  1281. dict-name ; dict name
  1282. (nth 1 adict) ; casechars
  1283. (nth 2 adict) ; not-casechars
  1284. (nth 3 adict) ; otherchars
  1285. (nth 4 adict) ; many-otherchars-p
  1286. ispell-args ; ispell-args
  1287. (nth 6 adict) ; extended-character-mode
  1288. (nth 7 adict) ; dict encoding
  1289. ))))
  1290. (setq ispell-dictionary-base-alist tmp-dicts-alist))))
  1291. (run-hooks 'ispell-initialize-spellchecker-hook)
  1292. ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
  1293. (dolist (dict (append found-dicts-alist
  1294. ispell-base-dicts-override-alist
  1295. ispell-dictionary-base-alist))
  1296. (unless (assoc (car dict) all-dicts-alist)
  1297. (add-to-list 'all-dicts-alist dict)))
  1298. (setq ispell-dictionary-alist all-dicts-alist))
  1299. ;; If Emacs flavor supports [:alpha:] use it for global dicts. If
  1300. ;; spellchecker also supports UTF-8 via command-line option use it
  1301. ;; in communication. This does not affect definitions in your
  1302. ;; init file.
  1303. (if ispell-emacs-alpha-regexp
  1304. (let (tmp-dicts-alist)
  1305. (dolist (adict ispell-dictionary-alist)
  1306. (if (cadr adict) ;; Do not touch hunspell uninitialized entries
  1307. (add-to-list 'tmp-dicts-alist
  1308. (list
  1309. (nth 0 adict) ; dict name
  1310. "[[:alpha:]]" ; casechars
  1311. "[^[:alpha:]]" ; not-casechars
  1312. (nth 3 adict) ; otherchars
  1313. (nth 4 adict) ; many-otherchars-p
  1314. (nth 5 adict) ; ispell-args
  1315. (nth 6 adict) ; extended-character-mode
  1316. (if ispell-encoding8-command
  1317. 'utf-8
  1318. (nth 7 adict))))
  1319. (add-to-list 'tmp-dicts-alist adict)))
  1320. (setq ispell-dictionary-alist tmp-dicts-alist)))))
  1321. (defun ispell-valid-dictionary-list ()
  1322. "Return a list of valid dictionaries.
  1323. The variable `ispell-library-directory' defines their location."
  1324. ;; Initialize variables and dictionaries alists for desired spellchecker.
  1325. ;; Make sure ispell.el is loaded to avoid some autoload loops in XEmacs
  1326. ;; (and may be others)
  1327. (if (featurep 'ispell)
  1328. (ispell-set-spellchecker-params))
  1329. (let ((dicts (append ispell-local-dictionary-alist ispell-dictionary-alist))
  1330. (dict-list (cons "default" nil))
  1331. name dict-bname)
  1332. (dolist (dict dicts)
  1333. (setq name (car dict)
  1334. dict-bname (or (car (cdr (member "-d" (nth 5 dict))))
  1335. name))
  1336. ;; Include if the dictionary is in the library, or dir not defined.
  1337. (if (and
  1338. name
  1339. ;; For Aspell, we already know which dictionaries exist.
  1340. (or ispell-really-aspell
  1341. ;; Include all dictionaries if lib directory not known.
  1342. ;; Same for Hunspell, where ispell-library-directory is nil.
  1343. (not ispell-library-directory)
  1344. (file-exists-p (concat ispell-library-directory
  1345. "/" dict-bname ".hash"))
  1346. (file-exists-p (concat ispell-library-directory
  1347. "/" dict-bname ".has"))))
  1348. (push name dict-list)))
  1349. dict-list))
  1350. ;; Define commands in menu in opposite order you want them to appear.
  1351. ;;;###autoload
  1352. (if ispell-menu-map-needed
  1353. (progn
  1354. (setq ispell-menu-map (make-sparse-keymap "Spell"))
  1355. (define-key ispell-menu-map [ispell-change-dictionary]
  1356. `(menu-item ,(purecopy "Change Dictionary...") ispell-change-dictionary
  1357. :help ,(purecopy "Supply explicit dictionary file name")))
  1358. (define-key ispell-menu-map [ispell-kill-ispell]
  1359. `(menu-item ,(purecopy "Kill Process")
  1360. (lambda () (interactive) (ispell-kill-ispell nil 'clear))
  1361. :enable (and (boundp 'ispell-process) ispell-process
  1362. (eq (ispell-process-status) 'run))
  1363. :help ,(purecopy "Terminate Ispell subprocess")))
  1364. (define-key ispell-menu-map [ispell-pdict-save]
  1365. `(menu-item ,(purecopy "Save Dictionary")
  1366. (lambda () (interactive) (ispell-pdict-save t t))
  1367. :help ,(purecopy "Save personal dictionary")))
  1368. (define-key ispell-menu-map [ispell-customize]
  1369. `(menu-item ,(purecopy "Customize...")
  1370. (lambda () (interactive) (customize-group 'ispell))
  1371. :help ,(purecopy "Customize spell checking options")))
  1372. (define-key ispell-menu-map [ispell-help]
  1373. ;; use (x-popup-menu last-nonmenu-event(list "" ispell-help-list)) ?
  1374. `(menu-item ,(purecopy "Help")
  1375. (lambda () (interactive) (describe-function 'ispell-help))
  1376. :help ,(purecopy "Show standard Ispell keybindings and commands")))
  1377. (define-key ispell-menu-map [flyspell-mode]
  1378. `(menu-item ,(purecopy "Automatic spell checking (Flyspell)")
  1379. flyspell-mode
  1380. :help ,(purecopy "Check spelling while you edit the text")
  1381. :button (:toggle . (bound-and-true-p flyspell-mode))))
  1382. (define-key ispell-menu-map [ispell-complete-word]
  1383. `(menu-item ,(purecopy "Complete Word") ispell-complete-word
  1384. :help ,(purecopy "Complete word at cursor using dictionary")))
  1385. (define-key ispell-menu-map [ispell-complete-word-interior-frag]
  1386. `(menu-item ,(purecopy "Complete Word Fragment")
  1387. ispell-complete-word-interior-frag
  1388. :help ,(purecopy "Complete word fragment at cursor")))))
  1389. ;;;###autoload
  1390. (if ispell-menu-map-needed
  1391. (progn
  1392. (define-key ispell-menu-map [ispell-continue]
  1393. `(menu-item ,(purecopy "Continue Spell-Checking") ispell-continue
  1394. :enable (and (boundp 'ispell-region-end)
  1395. (marker-position ispell-region-end)
  1396. (equal (marker-buffer ispell-region-end)
  1397. (current-buffer)))
  1398. :help ,(purecopy "Continue spell checking last region")))
  1399. (define-key ispell-menu-map [ispell-word]
  1400. `(menu-item ,(purecopy "Spell-Check Word") ispell-word
  1401. :help ,(purecopy "Spell-check word at cursor")))
  1402. (define-key ispell-menu-map [ispell-comments-and-strings]
  1403. `(menu-item ,(purecopy "Spell-Check Comments")
  1404. ispell-comments-and-strings
  1405. :help ,(purecopy "Spell-check only comments and strings")))))
  1406. ;;;###autoload
  1407. (if ispell-menu-map-needed
  1408. (progn
  1409. (define-key ispell-menu-map [ispell-region]
  1410. `(menu-item ,(purecopy "Spell-Check Region") ispell-region
  1411. :enable mark-active
  1412. :help ,(purecopy "Spell-check text in marked region")))
  1413. (define-key ispell-menu-map [ispell-message]
  1414. `(menu-item ,(purecopy "Spell-Check Message") ispell-message
  1415. :visible (eq major-mode 'mail-mode)
  1416. :help ,(purecopy "Skip headers and included message text")))
  1417. (define-key ispell-menu-map [ispell-buffer]
  1418. `(menu-item ,(purecopy "Spell-Check Buffer") ispell-buffer
  1419. :help ,(purecopy "Check spelling of selected buffer")))
  1420. ;;(put 'ispell-region 'menu-enable 'mark-active)
  1421. (fset 'ispell-menu-map (symbol-value 'ispell-menu-map))))
  1422. ;;; XEmacs versions 19 & 20
  1423. (if (and (featurep 'xemacs)
  1424. (featurep 'menubar)
  1425. ;;(null ispell-menu-xemacs)
  1426. (not (and (boundp 'infodock-version) infodock-version)))
  1427. (let ((dicts (if (fboundp 'ispell-valid-dictionary-list)
  1428. (reverse (ispell-valid-dictionary-list))))
  1429. (current-menubar (or current-menubar default-menubar))
  1430. (menu
  1431. '(["Help" (describe-function 'ispell-help) t]
  1432. ;;["Help" (popup-menu ispell-help-list) t]
  1433. ["Check Message" ispell-message t]
  1434. ["Check Buffer" ispell-buffer t]
  1435. ["Check Comments" ispell-comments-and-strings t]
  1436. ["Check Word" ispell-word t]
  1437. ["Check Region" ispell-region (or (not zmacs-regions) (mark))]
  1438. ["Continue Check" ispell-continue t]
  1439. ["Complete Word Frag"ispell-complete-word-interior-frag t]
  1440. ["Complete Word" ispell-complete-word t]
  1441. ["Kill Process" (ispell-kill-ispell nil 'clear) t]
  1442. ["Customize..." (customize-group 'ispell) t]
  1443. ;; flyspell-mode may not be bound...
  1444. ;;["flyspell" flyspell-mode
  1445. ;; :style toggle :selected flyspell-mode ]
  1446. "-"
  1447. ["Save Personal Dict"(ispell-pdict-save t t) t]
  1448. ["Change Dictionary" ispell-change-dictionary t])))
  1449. (if (null dicts)
  1450. (setq dicts (cons "default" nil)))
  1451. (dolist (name dicts)
  1452. (setq menu (append menu
  1453. (list
  1454. (vector
  1455. (concat "Select " (capitalize name))
  1456. (list 'ispell-change-dictionary name)
  1457. t)))))
  1458. (setq ispell-menu-xemacs menu)
  1459. (if current-menubar
  1460. (progn
  1461. (if (car (find-menu-item current-menubar '("Cmds")))
  1462. (progn
  1463. ;; XEmacs 21.2
  1464. (delete-menu-item '("Cmds" "Spell-Check"))
  1465. (add-menu '("Cmds") "Spell-Check" ispell-menu-xemacs))
  1466. ;; previous
  1467. (delete-menu-item '("Edit" "Spell")) ; in case already defined
  1468. (add-menu '("Edit") "Spell" ispell-menu-xemacs))))))
  1469. (defalias 'ispell-int-char
  1470. ;; Allow incrementing characters as integers in XEmacs 20
  1471. (if (and (featurep 'xemacs)
  1472. (fboundp 'int-char))
  1473. 'int-char
  1474. ;; Emacs and XEmacs 19 or earlier
  1475. 'identity))
  1476. ;;; **********************************************************************
  1477. (defvar ispell-current-dictionary nil
  1478. "The name of the current dictionary, or nil for the default.
  1479. This is passed to the Ispell process using the `-d' switch and is
  1480. used as key in `ispell-local-dictionary-alist' and `ispell-dictionary-alist'.")
  1481. (defvar ispell-current-personal-dictionary nil
  1482. "The name of the current personal dictionary, or nil for the default.
  1483. This is passed to the Ispell process using the `-p' switch.")
  1484. (defun ispell-decode-string (str)
  1485. "Decodes multibyte character strings.
  1486. Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
  1487. ;; FIXME: enable-multibyte-characters is read-only, so bogus bindings are
  1488. ;; really nasty (they signal an error in Emacs): Who does that? --Stef
  1489. (if (and (or (featurep 'xemacs)
  1490. (and (boundp 'enable-multibyte-characters)
  1491. enable-multibyte-characters))
  1492. (fboundp 'decode-coding-string)
  1493. (ispell-get-coding-system))
  1494. (decode-coding-string str (ispell-get-coding-system))
  1495. str))
  1496. ;; Return a string decoded from Nth element of the current dictionary.
  1497. (defun ispell-get-decoded-string (n)
  1498. "Get the decoded string in slot N of the descriptor of the current dict."
  1499. (let* ((slot (or
  1500. (assoc ispell-current-dictionary ispell-local-dictionary-alist)
  1501. (assoc ispell-current-dictionary ispell-dictionary-alist)
  1502. (error "No data for dictionary \"%s\", neither in `ispell-local-dictionary-alist' nor in `ispell-dictionary-alist'"
  1503. ispell-current-dictionary)))
  1504. (str (nth n slot)))
  1505. (when (and (> (length str) 0)
  1506. (not (multibyte-string-p str)))
  1507. (setq str (ispell-decode-string str))
  1508. (or (multibyte-string-p str)
  1509. (setq str (string-to-multibyte str))))
  1510. str))
  1511. (defun ispell-get-casechars ()
  1512. (ispell-get-decoded-string 1))
  1513. (defun ispell-get-not-casechars ()
  1514. (ispell-get-decoded-string 2))
  1515. (defun ispell-get-otherchars ()
  1516. (ispell-get-decoded-string 3))
  1517. (defun ispell-get-many-otherchars-p ()
  1518. (nth 4 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
  1519. (assoc ispell-current-dictionary ispell-dictionary-alist))))
  1520. (defun ispell-get-ispell-args ()
  1521. (nth 5 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
  1522. (assoc ispell-current-dictionary ispell-dictionary-alist))))
  1523. (defun ispell-get-extended-character-mode ()
  1524. (if ispell-really-hunspell ;; hunspell treats ~word as ordinary words
  1525. nil ;; in pipe mode. Disable extended-char-mode
  1526. (nth 6 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
  1527. (assoc ispell-current-dictionary ispell-dictionary-alist)))))
  1528. (defun ispell-get-coding-system ()
  1529. (nth 7 (or (assoc ispell-current-dictionary ispell-local-dictionary-alist)
  1530. (assoc ispell-current-dictionary ispell-dictionary-alist))))
  1531. (defvar ispell-pdict-modified-p nil
  1532. "Non-nil means personal dictionary has modifications to be saved.")
  1533. ;; If you want to save the dictionary when quitting, must do so explicitly.
  1534. ;; When non-nil, the spell session is terminated.
  1535. ;; When numeric, contains cursor location in buffer, and cursor remains there.
  1536. (defvar ispell-quit nil)
  1537. (defvar ispell-process-directory nil
  1538. "The directory where `ispell-process' was started.")
  1539. (defvar ispell-filter nil
  1540. "Output filter from piped calls to Ispell.")
  1541. (defvar ispell-filter-continue nil
  1542. "Control variable for Ispell filter function.")
  1543. (defvar ispell-output-buffer nil
  1544. "Buffer used for reading output of a synchronous Ispell subprocess.")
  1545. (defvar ispell-session-buffer nil
  1546. "Buffer used for passing input to a synchronous Ispell subprocess.")
  1547. (defvar ispell-cmd-args nil
  1548. "Command-line arguments to pass to a synchronous Ispell subprocess.")
  1549. (defvar ispell-query-replace-marker (make-marker)
  1550. "Marker for `query-replace' processing.")
  1551. (defvar ispell-recursive-edit-marker (make-marker)
  1552. "Marker for return point from recursive edit.")
  1553. (defvar ispell-checking-message nil
  1554. "Non-nil when we're checking a mail message.
  1555. Set to the MIME boundary locations when checking messages.")
  1556. (defconst ispell-choices-buffer "*Choices*")
  1557. (defvar ispell-overlay nil "Overlay variable for Ispell highlighting.")
  1558. ;;; *** Buffer Local Definitions ***
  1559. (defconst ispell-words-keyword "LocalWords: "
  1560. "The keyword for local oddly-spelled words to accept.
  1561. The keyword will be followed by any number of local word spellings.
  1562. There can be multiple instances of this keyword in the file.")
  1563. (defconst ispell-dictionary-keyword "Local IspellDict: "
  1564. "The keyword for a local dictionary to use.
  1565. The keyword must be followed by a valid dictionary name, defined in
  1566. `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
  1567. When multiple occurrences exist, the last keyword
  1568. definition is used.")
  1569. (defconst ispell-pdict-keyword "Local IspellPersDict: "
  1570. "The keyword for defining buffer local dictionaries.
  1571. Keyword must be followed by the filename of a personal dictionary.
  1572. The last occurring definition in the buffer will be used.")
  1573. (defconst ispell-parsing-keyword "Local IspellParsing: "
  1574. "The keyword for overriding default Ispell parsing.
  1575. The above keyword string should be followed by `latex-mode' or
  1576. `nroff-mode' to put the current buffer into the desired parsing mode.
  1577. Extended character mode can be changed for this buffer by placing
  1578. a `~' followed by an extended-character mode -- such as `~.tex'.
  1579. The last occurring definition in the buffer will be used.")
  1580. ;;;###autoload
  1581. (defvar ispell-skip-region-alist
  1582. `((ispell-words-keyword forward-line)
  1583. (ispell-dictionary-keyword forward-line)
  1584. (ispell-pdict-keyword forward-line)
  1585. (ispell-parsing-keyword forward-line)
  1586. (,(purecopy "^---*BEGIN PGP [A-Z ]*--*")
  1587. . ,(purecopy "^---*END PGP [A-Z ]*--*"))
  1588. ;; assume multiline uuencoded file? "\nM.*$"?
  1589. (,(purecopy "^begin [0-9][0-9][0-9] [^ \t]+$") . ,(purecopy "\nend\n"))
  1590. (,(purecopy "^%!PS-Adobe-[123].0") . ,(purecopy "\n%%EOF\n"))
  1591. (,(purecopy "^---* \\(Start of \\)?[Ff]orwarded [Mm]essage")
  1592. . ,(purecopy "^---* End of [Ff]orwarded [Mm]essage"))
  1593. ;; Matches e-mail addresses, file names, http addresses, etc. The
  1594. ;; `-+' `_+' patterns are necessary for performance reasons when
  1595. ;; `-' or `_' part of word syntax.
  1596. (,(purecopy "\\(--+\\|_+\\|\\(/\\w\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)"))
  1597. ;; above checks /.\w sequences
  1598. ;;("\\(--+\\|\\(/\\|\\(\\(\\w\\|[-_]\\)+[.:@]\\)\\)\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_~=?&]\\)+\\)+\\)")
  1599. ;; This is a pretty complex regexp. It can be simplified to the following:
  1600. ;; "\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
  1601. ;; but some valid text will be skipped, e.g. "his/her". This could be
  1602. ;; fixed up (at the expense of a moderately more complex regexp)
  1603. ;; by not allowing "/" to be the character which triggers the
  1604. ;; identification of the computer name, e.g.:
  1605. ;; "\\(\\w\\|[-_]\\)+[.:@]\\(\\w\\|[-_]\\)*\\([.:/@]+\\(\\w\\|[-_]\\|~\\)+\\)+"
  1606. )
  1607. "Alist expressing beginning and end of regions not to spell check.
  1608. The alist key must be a regular expression.
  1609. Valid forms include:
  1610. (KEY) - just skip the key.
  1611. (KEY . REGEXP) - skip to the end of REGEXP. REGEXP may be string or symbol.
  1612. (KEY REGEXP) - skip to end of REGEXP. REGEXP must be a string.
  1613. (KEY FUNCTION ARGS) - FUNCTION called with ARGS returns end of region.")
  1614. (put 'ispell-skip-region-alist 'risky-local-variable t)
  1615. ;;;###autoload
  1616. (defvar ispell-tex-skip-alists
  1617. (purecopy
  1618. '((;;("%\\[" . "%\\]") ; AMStex block comment...
  1619. ;; All the standard LaTeX keywords from L. Lamport's guide:
  1620. ;; \cite, \hspace, \hspace*, \hyphenation, \include, \includeonly, \input,
  1621. ;; \label, \nocite, \rule (in ispell - rest included here)
  1622. ("\\\\addcontentsline" ispell-tex-arg-end 2)
  1623. ("\\\\add\\(tocontents\\|vspace\\)" ispell-tex-arg-end)
  1624. ("\\\\\\([aA]lph\\|arabic\\)" ispell-tex-arg-end)
  1625. ;;("\\\\author" ispell-tex-arg-end)
  1626. ("\\\\bibliographystyle" ispell-tex-arg-end)
  1627. ("\\\\makebox" ispell-tex-arg-end 0)
  1628. ("\\\\e?psfig" ispell-tex-arg-end)
  1629. ("\\\\document\\(class\\|style\\)" .
  1630. "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
  1631. (;; delimited with \begin. In ispell: displaymath, eqnarray, eqnarray*,
  1632. ;; equation, minipage, picture, tabular, tabular* (ispell)
  1633. ("\\(figure\\|table\\)\\*?" ispell-tex-arg-end 0)
  1634. ("list" ispell-tex-arg-end 2)
  1635. ("program" . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
  1636. ("verbatim\\*?" . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))
  1637. "Lists of regions to be skipped in TeX mode.
  1638. First list is used raw.
  1639. Second list has key placed inside \\begin{}.
  1640. Delete or add any regions you want to be automatically selected
  1641. for skipping in latex mode.")
  1642. (put 'ispell-tex-skip-alist 'risky-local-variable t)
  1643. ;;;###autoload
  1644. (defconst ispell-html-skip-alists
  1645. '(("<[cC][oO][dD][eE]\\>[^>]*>" "</[cC][oO][dD][eE]*>")
  1646. ("<[sS][cC][rR][iI][pP][tT]\\>[^>]*>" "</[sS][cC][rR][iI][pP][tT]>")
  1647. ("<[aA][pP][pP][lL][eE][tT]\\>[^>]*>" "</[aA][pP][pP][lL][eE][tT]>")
  1648. ("<[vV][eE][rR][bB]\\>[^>]*>" "<[vV][eE][rR][bB]\\>[^>]*>")
  1649. ;;("<[tT][tT]\\>[^>]*>" "<[tT][tT]\\>[^>]*>")
  1650. ("<[tT][tT]/" "/")
  1651. ("<[^ \t\n>]" ">")
  1652. ("&[^ \t\n;]" "[; \t\n]"))
  1653. "Lists of start and end keys to skip in HTML buffers.
  1654. Same format as `ispell-skip-region-alist'.
  1655. Note - substrings of other matches must come last
  1656. (e.g. \"<[tT][tT]/\" and \"<[^ \\t\\n>]\").")
  1657. (put 'ispell-html-skip-alists 'risky-local-variable t)
  1658. (defvar ispell-local-pdict ispell-personal-dictionary
  1659. "A buffer local variable containing the current personal dictionary.
  1660. If non-nil, the value must be a string, which is a file name.
  1661. If you specify a personal dictionary for the current buffer which is
  1662. different from the current personal dictionary, the effect is similar
  1663. to calling \\[ispell-change-dictionary]. This variable is automatically
  1664. set when defined in the file with either `ispell-pdict-keyword' or the
  1665. local variable syntax.")
  1666. (make-variable-buffer-local 'ispell-local-pdict)
  1667. ;;;###autoload(put 'ispell-local-pdict 'safe-local-variable 'stringp)
  1668. (defvar ispell-buffer-local-name nil
  1669. "Contains the buffer name if local word definitions were used.
  1670. Ispell is then restarted because the local words could conflict.")
  1671. (defvar ispell-buffer-session-localwords nil
  1672. "List of words accepted for session in this buffer.")
  1673. (make-variable-buffer-local 'ispell-buffer-session-localwords)
  1674. (defvar ispell-parser 'use-mode-name
  1675. "Indicates whether ispell should parse the current buffer as TeX Code.
  1676. Special value `use-mode-name' tries to guess using the name of `major-mode'.
  1677. Default parser is `nroff'.
  1678. Currently the only other valid parser is `tex'.
  1679. You can set this variable in hooks in your init file -- eg:
  1680. \(add-hook \\='tex-mode-hook (lambda () (setq ispell-parser \\='tex)))")
  1681. (defvar ispell-region-end (make-marker)
  1682. "Marker that allows spelling continuations.")
  1683. (defvar ispell-check-only nil
  1684. "If non-nil, `ispell-word' does not try to correct the word.")
  1685. ;;; **********************************************************************
  1686. ;;; **********************************************************************
  1687. ;;;###autoload (define-key esc-map "$" 'ispell-word)
  1688. (defun ispell-accept-output (&optional timeout-secs timeout-msecs)
  1689. "Wait for output from Ispell process, or TIMEOUT-SECS and TIMEOUT-MSECS.
  1690. If asynchronous subprocesses are not supported, call function `ispell-filter'
  1691. and pass it the output of the last Ispell invocation."
  1692. (if ispell-async-processp
  1693. (accept-process-output ispell-process timeout-secs timeout-msecs)
  1694. (if (null ispell-process)
  1695. (error "No Ispell process to read output from!")
  1696. (let ((buf ispell-output-buffer)
  1697. ispell-output)
  1698. (if (not (bufferp buf))
  1699. (setq ispell-filter nil)
  1700. (with-current-buffer buf
  1701. (setq ispell-output (buffer-substring-no-properties
  1702. (point-min) (point-max))))
  1703. (ispell-filter t ispell-output)
  1704. (with-current-buffer buf
  1705. (erase-buffer)))))))
  1706. (defun ispell-send-replacement (misspelled replacement)
  1707. "Notify Aspell that MISSPELLED should be spelled REPLACEMENT.
  1708. This allows to improve the suggestion list based on actual misspellings."
  1709. (and ispell-really-aspell
  1710. (ispell-send-string (concat "$$ra " misspelled "," replacement "\n"))))
  1711. (defun ispell-send-string (string)
  1712. "Send the string STRING to the Ispell process."
  1713. (if ispell-async-processp
  1714. (process-send-string ispell-process string)
  1715. ;; Asynchronous subprocesses aren't supported on this losing system.
  1716. ;; We keep all the directives passed to Ispell during the entire
  1717. ;; session in a buffer, and pass them anew each time we invoke
  1718. ;; Ispell to process another chunk of text. (Yes, I know this is a
  1719. ;; terrible kludge, and it's a bit slow, but it does get the work done.)
  1720. (let ((cmd (aref string 0))
  1721. ;; The following commands are not passed to Ispell until
  1722. ;; we have a *real* reason to invoke it.
  1723. (cmds-to-defer '(?* ?@ ?~ ?+ ?- ?! ?%))
  1724. (session-buf ispell-session-buffer)
  1725. (output-buf ispell-output-buffer)
  1726. (ispell-args ispell-cmd-args)
  1727. (defdir ispell-process-directory)
  1728. prev-pos)
  1729. (with-current-buffer session-buf
  1730. (setq prev-pos (point))
  1731. (setq default-directory defdir)
  1732. (insert string)
  1733. (if (not (memq cmd cmds-to-defer))
  1734. (let (coding-system-for-read coding-system-for-write status)
  1735. (if (and (boundp 'enable-multibyte-characters)
  1736. enable-multibyte-characters)
  1737. (setq coding-system-for-read (ispell-get-coding-system)
  1738. coding-system-for-write (ispell-get-coding-system)))
  1739. (set-buffer output-buf)
  1740. (erase-buffer)
  1741. (set-buffer session-buf)
  1742. (setq status
  1743. (apply 'ispell-call-process-region
  1744. (point-min) (point-max)
  1745. ispell-program-name nil
  1746. output-buf nil
  1747. "-a"
  1748. ;; hunspell -m option means something different
  1749. (if ispell-really-hunspell "" "-m")
  1750. ispell-args))
  1751. (set-buffer output-buf)
  1752. (goto-char (point-min))
  1753. (save-match-data
  1754. (if (not (looking-at "@(#) "))
  1755. (error "Ispell error: %s"
  1756. (buffer-substring-no-properties
  1757. (point) (progn (end-of-line) (point)))))
  1758. ;; If STRING is "^Z\n", we just started Ispell and need
  1759. ;; to retain its version ID line in the output buffer.
  1760. ;; Otherwise, remove the ID line, as it will confuse
  1761. ;; `ispell-filter'.
  1762. (or (string= string "\032\n")
  1763. (progn
  1764. (forward-line)
  1765. (delete-region (point-min) (point))))
  1766. ;; If STRING begins with ^ or any normal character, we need
  1767. ;; to remove the last line from the session buffer, since it
  1768. ;; was just spell-checked, and we don't want to check it again.
  1769. ;; The same goes for the # command, since Ispell already saved
  1770. ;; the personal dictionary.
  1771. (set-buffer session-buf)
  1772. (delete-region prev-pos (point))
  1773. ;; Ispell run synchronously saves the personal dictionary
  1774. ;; after each successful command. So we can remove any
  1775. ;; lines in the session buffer that insert words into the
  1776. ;; dictionary.
  1777. (if (memq status '(0 nil))
  1778. (let ((more-lines t))
  1779. (goto-char (point-min))
  1780. (while more-lines
  1781. (if (looking-at "^\\*")
  1782. (let ((start (point)))
  1783. (forward-line)
  1784. (delete-region start (point)))
  1785. (setq more-lines (= 0 (forward-line))))))))))))))
  1786. ;;;###autoload
  1787. (defun ispell-word (&optional following quietly continue region)
  1788. "Check spelling of word under or before the cursor.
  1789. If the word is not found in dictionary, display possible corrections
  1790. in a window allowing you to choose one.
  1791. If optional argument FOLLOWING is non-nil or if `ispell-following-word'
  1792. is non-nil when called interactively, then the following word
  1793. \(rather than preceding) is checked when the cursor is not over a word.
  1794. When the optional argument QUIETLY is non-nil or `ispell-quietly' is non-nil
  1795. when called interactively, non-corrective messages are suppressed.
  1796. With a prefix argument (or if CONTINUE is non-nil),
  1797. resume interrupted spell-checking of a buffer or region.
  1798. Interactively, in Transient Mark mode when the mark is active, call
  1799. `ispell-region' to check the active region for spelling errors.
  1800. Word syntax is controlled by the definition of the chosen dictionary,
  1801. which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
  1802. This will check or reload the dictionary. Use \\[ispell-change-dictionary]
  1803. or \\[ispell-region] to update the Ispell process.
  1804. Return values:
  1805. nil word is correct or spelling is accepted.
  1806. 0 word is inserted into buffer-local definitions.
  1807. \"word\" word corrected from word list.
  1808. \(\"word\" arg) word is hand entered.
  1809. quit spell session exited."
  1810. (interactive (list ispell-following-word ispell-quietly current-prefix-arg t))
  1811. (cond
  1812. ((and region
  1813. (if (featurep 'emacs)
  1814. (use-region-p)
  1815. (and (boundp 'transient-mark-mode) transient-mark-mode
  1816. (boundp 'mark-active) mark-active
  1817. (not (eq (region-beginning) (region-end))))))
  1818. (ispell-region (region-beginning) (region-end)))
  1819. (continue (ispell-continue))
  1820. (t
  1821. (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
  1822. (ispell-accept-buffer-local-defs) ; use the correct dictionary
  1823. (let ((cursor-location (point)) ; retain cursor location
  1824. (word (ispell-get-word following))
  1825. start end poss new-word replace)
  1826. ;; De-structure return word info list.
  1827. (setq start (car (cdr word))
  1828. end (car (cdr (cdr word)))
  1829. word (car word))
  1830. ;; At this point it used to ignore 2-letter words.
  1831. ;; But that is silly; if the user asks for it, we should do it. - rms.
  1832. (or quietly
  1833. (message "Checking spelling of %s..."
  1834. (funcall ispell-format-word-function word)))
  1835. (ispell-send-string "%\n") ; put in verbose mode
  1836. (ispell-send-string (concat "^" word "\n"))
  1837. ;; wait until ispell has processed word
  1838. (while (progn
  1839. (ispell-accept-output)
  1840. (not (string= "" (car ispell-filter)))))
  1841. ;;(ispell-send-string "!\n") ;back to terse mode.
  1842. (setq ispell-filter (cdr ispell-filter)) ; remove extra \n
  1843. (if (and ispell-filter (listp ispell-filter))
  1844. (if (> (length ispell-filter) 1)
  1845. (error "Ispell and its process have different character maps")
  1846. (setq poss (ispell-parse-output (car ispell-filter)))))
  1847. (cond ((eq poss t)
  1848. (or quietly
  1849. (message "%s is correct"
  1850. (funcall ispell-format-word-function word)))
  1851. (and (featurep 'xemacs)
  1852. (extent-at start)
  1853. (and (fboundp 'delete-extent)
  1854. (delete-extent (extent-at start)))))
  1855. ((stringp poss)
  1856. (or quietly
  1857. (message "%s is correct because of root %s"
  1858. (funcall ispell-format-word-function word)
  1859. (funcall ispell-format-word-function poss)))
  1860. (and (featurep 'xemacs)
  1861. (extent-at start)
  1862. (and (fboundp 'delete-extent)
  1863. (delete-extent (extent-at start)))))
  1864. ((null poss)
  1865. (message "Error checking word %s using %s with %s dictionary"
  1866. (funcall ispell-format-word-function word)
  1867. (file-name-nondirectory ispell-program-name)
  1868. (or ispell-current-dictionary "default")))
  1869. (ispell-check-only ; called from ispell minor mode.
  1870. (if (fboundp 'make-extent)
  1871. (if (fboundp 'set-extent-property)
  1872. (let ((ext (make-extent start end)))
  1873. (set-extent-property ext 'face ispell-highlight-face)
  1874. (set-extent-property ext 'priority 2000)))
  1875. (beep)
  1876. (message "%s is incorrect"
  1877. (funcall ispell-format-word-function word))))
  1878. (t ; prompt for correct word.
  1879. (save-window-excursion
  1880. (setq replace (ispell-command-loop
  1881. (car (cdr (cdr poss)))
  1882. (car (cdr (cdr (cdr poss))))
  1883. (car poss) start end)))
  1884. (cond ((equal 0 replace)
  1885. (ispell-add-per-file-word-list (car poss)))
  1886. (replace
  1887. (setq new-word (if (atom replace) replace (car replace))
  1888. cursor-location (+ (- (length word) (- end start))
  1889. cursor-location))
  1890. (if (not (equal new-word (car poss)))
  1891. (progn
  1892. (goto-char start)
  1893. ;; Insert first and then delete,
  1894. ;; to avoid collapsing markers before and after
  1895. ;; into a single place.
  1896. (insert new-word)
  1897. (delete-region (point) end)
  1898. ;; It is meaningless to preserve the cursor position
  1899. ;; inside a word that has changed.
  1900. (setq cursor-location (point))
  1901. (setq end (point))))
  1902. (if (not (atom replace)) ;recheck spelling of replacement
  1903. (progn
  1904. (if (car (cdr replace)) ; query replace requested
  1905. (save-window-excursion
  1906. (query-replace word new-word t)))
  1907. (goto-char start)
  1908. ;; single word could be split into multiple words
  1909. (setq ispell-quit (not (ispell-region start end)))
  1910. ))))
  1911. ;; keep if rechecking word and we keep choices win.
  1912. (if (get-buffer ispell-choices-buffer)
  1913. (kill-buffer ispell-choices-buffer))))
  1914. (ispell-pdict-save ispell-silently-savep)
  1915. ;; NB: Cancels ispell-quit incorrectly if called from ispell-region
  1916. (if ispell-quit (setq ispell-quit nil replace 'quit))
  1917. (goto-char cursor-location) ; return to original location
  1918. replace))))
  1919. (defun ispell-get-word (following &optional extra-otherchars)
  1920. "Return the word for spell-checking according to ispell syntax.
  1921. If optional argument FOLLOWING is non-nil or if `ispell-following-word'
  1922. is non-nil when called interactively, then the following word
  1923. \(rather than preceding) is checked when the cursor is not over a word.
  1924. Optional second argument contains otherchars that can be included in word
  1925. many times (see the doc string of `ispell-dictionary-alist' for details
  1926. about otherchars).
  1927. Word syntax is controlled by the definition of the chosen dictionary,
  1928. which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'."
  1929. (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
  1930. (let* ((ispell-casechars (ispell-get-casechars))
  1931. (ispell-not-casechars (ispell-get-not-casechars))
  1932. (ispell-otherchars (ispell-get-otherchars))
  1933. (ispell-many-otherchars-p (ispell-get-many-otherchars-p))
  1934. (word-regexp (concat ispell-casechars
  1935. "+\\("
  1936. (if (not (string= "" ispell-otherchars))
  1937. (concat ispell-otherchars "?"))
  1938. (if extra-otherchars
  1939. (concat extra-otherchars "?"))
  1940. ispell-casechars
  1941. "+\\)"
  1942. (if (or ispell-many-otherchars-p
  1943. extra-otherchars)
  1944. "*" "?")))
  1945. did-it-once prevpt
  1946. start end word)
  1947. ;; find the word
  1948. (if (not (looking-at ispell-casechars))
  1949. (if following
  1950. (re-search-forward ispell-casechars (point-max) t)
  1951. (re-search-backward ispell-casechars (point-min) t)))
  1952. ;; move to front of word
  1953. (re-search-backward ispell-not-casechars (point-min) 'start)
  1954. (while (and (or (and (not (string= "" ispell-otherchars))
  1955. (looking-at ispell-otherchars))
  1956. (and extra-otherchars (looking-at extra-otherchars)))
  1957. (not (bobp))
  1958. (or (not did-it-once)
  1959. ispell-many-otherchars-p)
  1960. (not (eq prevpt (point))))
  1961. (if (and extra-otherchars (looking-at extra-otherchars))
  1962. (progn
  1963. (backward-char 1)
  1964. (if (looking-at ispell-casechars)
  1965. (re-search-backward ispell-not-casechars (point-min) 'move)))
  1966. (setq did-it-once t
  1967. prevpt (point))
  1968. (backward-char 1)
  1969. (if (looking-at ispell-casechars)
  1970. (re-search-backward ispell-not-casechars (point-min) 'move)
  1971. (backward-char -1))))
  1972. ;; Now mark the word and save to string.
  1973. (if (not (re-search-forward word-regexp (point-max) t))
  1974. (if ispell-check-only
  1975. ;; return dummy word when just flagging misspellings
  1976. (list "" (point) (point))
  1977. (error "No word found to check!"))
  1978. (setq start (copy-marker (match-beginning 0))
  1979. end (point-marker)
  1980. word (buffer-substring-no-properties start end))
  1981. (list word start end))))
  1982. ;; Global ispell-pdict-modified-p is set by ispell-command-loop and
  1983. ;; tracks changes in the dictionary. The global may either be
  1984. ;; a value or a list, whose value is the state of whether the
  1985. ;; dictionary needs to be saved.
  1986. ;;;###autoload
  1987. (defun ispell-pdict-save (&optional no-query force-save)
  1988. "Check to see if the personal dictionary has been modified.
  1989. If so, ask if it needs to be saved."
  1990. (interactive (list ispell-silently-savep t))
  1991. (if (and ispell-pdict-modified-p (listp ispell-pdict-modified-p))
  1992. (setq ispell-pdict-modified-p (car ispell-pdict-modified-p)))
  1993. (when (and (or ispell-pdict-modified-p force-save)
  1994. (or no-query
  1995. (y-or-n-p "Personal dictionary modified. Save? ")))
  1996. (ispell-send-string "#\n") ; save dictionary
  1997. (message "Personal dictionary saved.")
  1998. (when flyspell-mode
  1999. (flyspell-mode 0)
  2000. (flyspell-mode 1)))
  2001. ;; unassert variable, even if not saved to avoid questioning.
  2002. (setq ispell-pdict-modified-p nil))
  2003. (defun ispell-command-loop (miss guess word start end)
  2004. "Display possible corrections from list MISS.
  2005. GUESS lists possibly valid affix construction of WORD.
  2006. Returns nil to keep word.
  2007. Returns 0 to insert locally into buffer-local dictionary.
  2008. Returns string for new chosen word.
  2009. Returns list for new replacement word (will be rechecked).
  2010. Query-replace when list length is 2.
  2011. Automatic query-replace when second element is `query-replace'.
  2012. Highlights the word, which is assumed to run from START to END.
  2013. Global `ispell-pdict-modified-p' becomes a list where the only value
  2014. indicates whether the dictionary has been modified when option `a'
  2015. or `i' is used.
  2016. Global `ispell-quit' set to start location to continue spell session."
  2017. (let ((count ?0)
  2018. (choices miss)
  2019. (window-min-height (min window-min-height
  2020. ispell-choices-win-default-height))
  2021. (command-characters '( ? ?i ?a ?A ?r ?R ?? ?x ?X ?q ?l ?u ?m ))
  2022. (skipped 0)
  2023. char num result textwin)
  2024. ;; setup the *Choices* buffer with valid data.
  2025. (with-current-buffer (get-buffer-create ispell-choices-buffer)
  2026. (setq mode-line-format
  2027. (concat
  2028. "-- %b -- word: " word
  2029. " -- dict: " (or ispell-current-dictionary "default")
  2030. " -- prog: " (file-name-nondirectory ispell-program-name)))
  2031. ;; XEmacs: no need for horizontal scrollbar in choices window
  2032. (ispell-with-no-warnings
  2033. (and (fboundp 'set-specifier)
  2034. (boundp 'horizontal-scrollbar-visible-p)
  2035. (set-specifier horizontal-scrollbar-visible-p nil
  2036. (cons (current-buffer) nil))))
  2037. (ispell-with-no-warnings
  2038. (and (boundp 'horizontal-scroll-bar)
  2039. (setq horizontal-scroll-bar nil)))
  2040. (erase-buffer)
  2041. (if guess
  2042. (progn
  2043. (insert "Affix rules generate and capitalize "
  2044. "this word as shown below:\n\t")
  2045. (while guess
  2046. (when (> (+ 4 (current-column) (length (car guess)))
  2047. (window-width))
  2048. (insert "\n\t"))
  2049. (insert (car guess) " ")
  2050. (setq guess (cdr guess)))
  2051. (insert (substitute-command-keys
  2052. "\nUse option `i' to accept this spelling and put it in your private dictionary.\n"))))
  2053. (while choices
  2054. (when (> (+ 7 (current-column)
  2055. (length (car choices))
  2056. (if (> count ?~) 3 0))
  2057. (window-width))
  2058. (insert "\n"))
  2059. ;; not so good if there are over 20 or 30 options, but then, if
  2060. ;; there are that many you don't want to scan them all anyway...
  2061. (while (memq count command-characters) ; skip command characters.
  2062. (setq count (ispell-int-char (1+ count))
  2063. skipped (1+ skipped)))
  2064. (insert "(" count ") " (car choices) " ")
  2065. (setq choices (cdr choices)
  2066. count (ispell-int-char (1+ count))))
  2067. (setq count (ispell-int-char (- count ?0 skipped))))
  2068. ;; ensure word is visible
  2069. (if (not (pos-visible-in-window-p end))
  2070. (sit-for 0))
  2071. ;; Display choices for misspelled word.
  2072. (setq textwin (selected-window))
  2073. (ispell-show-choices)
  2074. (select-window textwin)
  2075. ;; highlight word, protecting current buffer status
  2076. (unwind-protect
  2077. (progn
  2078. (and ispell-highlight-p
  2079. (ispell-highlight-spelling-error start end t))
  2080. ;; Loop until a valid choice is made.
  2081. (while
  2082. (eq
  2083. t
  2084. (setq
  2085. result
  2086. (progn
  2087. (undo-boundary)
  2088. (let (message-log-max)
  2089. (message (concat "C-h or ? for more options; SPC to leave "
  2090. "unchanged, Character to replace word")))
  2091. (let ((inhibit-quit t)
  2092. (input-valid t))
  2093. (setq char nil skipped 0)
  2094. ;; If the user types C-g, or generates some other
  2095. ;; non-character event (such as a frame switch
  2096. ;; event), stop ispell. As a special exception,
  2097. ;; ignore mouse events occurring in the same frame.
  2098. (while (and input-valid (not (characterp char)))
  2099. (setq char (read-key))
  2100. (setq input-valid
  2101. (or (characterp char)
  2102. (and (mouse-event-p char)
  2103. (eq (selected-frame)
  2104. (window-frame
  2105. (posn-window (event-start char))))))))
  2106. (when (or quit-flag (not input-valid) (= char ?\C-g))
  2107. (setq char ?X quit-flag nil)))
  2108. ;; Adjust num to array offset skipping command characters.
  2109. (let ((com-chars command-characters))
  2110. (while com-chars
  2111. (if (and (> (car com-chars) ?0) (< (car com-chars) char))
  2112. (setq skipped (1+ skipped)))
  2113. (setq com-chars (cdr com-chars)))
  2114. (setq num (- char ?0 skipped)))
  2115. (cond
  2116. ((= char ? ) nil) ; accept word this time only
  2117. ((= char ?i) ; accept and insert word into pers dict
  2118. (ispell-send-string (concat "*" word "\n"))
  2119. (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
  2120. (and (fboundp 'flyspell-unhighlight-at)
  2121. (flyspell-unhighlight-at start))
  2122. nil)
  2123. ((or (= char ?a) (= char ?A)) ; accept word without insert
  2124. (ispell-send-string (concat "@" word "\n"))
  2125. (add-to-list 'ispell-buffer-session-localwords word)
  2126. (and (fboundp 'flyspell-unhighlight-at)
  2127. (flyspell-unhighlight-at start))
  2128. (or ispell-buffer-local-name ; session localwords might conflict
  2129. (setq ispell-buffer-local-name (buffer-name)))
  2130. (if (null ispell-pdict-modified-p)
  2131. (setq ispell-pdict-modified-p
  2132. (list ispell-pdict-modified-p)))
  2133. (if (= char ?A) 0)) ; return 0 for ispell-add buffer-local
  2134. ((or (= char ?r) (= char ?R)) ; type in replacement
  2135. (and (eq 'block ispell-highlight-p) ; refresh tty's
  2136. (ispell-highlight-spelling-error start end nil t))
  2137. (let ((result
  2138. (if (or (= char ?R) ispell-query-replace-choices)
  2139. (list (read-string
  2140. (format "Query-replacement for %s: "word)
  2141. word)
  2142. t)
  2143. (cons (read-string "Replacement for: " word)
  2144. nil))))
  2145. (and (eq 'block ispell-highlight-p)
  2146. (ispell-highlight-spelling-error start end nil
  2147. 'block))
  2148. result))
  2149. ((or (= char ??) (= char help-char) (= char ?\C-h))
  2150. (and (eq 'block ispell-highlight-p)
  2151. (ispell-highlight-spelling-error start end nil t))
  2152. (ispell-help)
  2153. (and (eq 'block ispell-highlight-p)
  2154. (ispell-highlight-spelling-error start end nil
  2155. 'block))
  2156. t)
  2157. ;; Quit and move point back.
  2158. ((= char ?x)
  2159. (ispell-pdict-save ispell-silently-savep)
  2160. (message "Exited spell-checking")
  2161. (setq ispell-quit t)
  2162. nil)
  2163. ;; Quit and preserve point.
  2164. ((= char ?X)
  2165. (ispell-pdict-save ispell-silently-savep)
  2166. (message "%s"
  2167. (substitute-command-keys
  2168. (concat "Spell-checking suspended;"
  2169. " use C-u \\[ispell-word] to resume")))
  2170. (setq ispell-quit start)
  2171. nil)
  2172. ((= char ?q)
  2173. (if (y-or-n-p "Really kill Ispell process? ")
  2174. (progn
  2175. (ispell-kill-ispell t) ; terminate process.
  2176. (setq ispell-quit (or (not ispell-checking-message)
  2177. (point))
  2178. ispell-pdict-modified-p nil))
  2179. t)) ; continue if they don't quit.
  2180. ((= char ?l)
  2181. (and (eq 'block ispell-highlight-p) ; refresh tty displays
  2182. (ispell-highlight-spelling-error start end nil t))
  2183. (let ((new-word (read-string
  2184. "Lookup string (`*' is wildcard): "
  2185. word)))
  2186. (if new-word
  2187. (progn
  2188. (with-current-buffer (get-buffer-create
  2189. ispell-choices-buffer)
  2190. (erase-buffer)
  2191. (setq count ?0
  2192. skipped 0
  2193. mode-line-format ;; setup the *Choices* buffer with valid data.
  2194. (concat "-- %b -- word: " new-word
  2195. " -- word-list: "
  2196. (or ispell-complete-word-dict
  2197. ispell-alternate-dictionary))
  2198. miss (ispell-lookup-words new-word)
  2199. choices miss)
  2200. (while choices
  2201. (when (> (+ 7 (current-column)
  2202. (length (car choices))
  2203. (if (> count ?~) 3 0))
  2204. (window-width))
  2205. (insert "\n"))
  2206. (while (memq count command-characters)
  2207. (setq count (ispell-int-char (1+ count))
  2208. skipped (1+ skipped)))
  2209. (insert "(" count ") " (car choices) " ")
  2210. (setq choices (cdr choices)
  2211. count (ispell-int-char (1+ count))))
  2212. (setq count (ispell-int-char
  2213. (- count ?0 skipped))))
  2214. (setq textwin (selected-window))
  2215. (ispell-show-choices)
  2216. (select-window textwin))))
  2217. (and (eq 'block ispell-highlight-p)
  2218. (ispell-highlight-spelling-error start end nil
  2219. 'block))
  2220. t) ; reselect from new choices
  2221. ((= char ?u) ; insert lowercase into dictionary
  2222. (ispell-send-string (concat "*" (downcase word) "\n"))
  2223. (setq ispell-pdict-modified-p '(t)) ; dictionary modified!
  2224. nil)
  2225. ((= char ?m) ; type in what to insert
  2226. (ispell-send-string
  2227. (concat "*" (read-string "Insert: " word) "\n"))
  2228. (setq ispell-pdict-modified-p '(t))
  2229. (cons word nil))
  2230. ((and (>= num 0) (< num count))
  2231. (if ispell-query-replace-choices ; Query replace flag
  2232. (list (nth num miss) 'query-replace)
  2233. (nth num miss)))
  2234. ((= char ?\C-l)
  2235. (redraw-display) t)
  2236. ((= char ?\C-r)
  2237. ;; This may have alignment errors if current line is edited
  2238. (if (marker-position ispell-recursive-edit-marker)
  2239. (progn
  2240. (message "Only one recursive edit session supported")
  2241. (beep)
  2242. (sit-for 2))
  2243. (set-marker ispell-recursive-edit-marker start)
  2244. ;;(set-marker ispell-region-end reg-end)
  2245. (and ispell-highlight-p ; unhighlight
  2246. (ispell-highlight-spelling-error start end))
  2247. (unwind-protect
  2248. (progn
  2249. (message
  2250. "%s"
  2251. (substitute-command-keys
  2252. (concat "Exit recursive edit with"
  2253. " \\[exit-recursive-edit]")))
  2254. (save-window-excursion (save-excursion
  2255. (recursive-edit))))
  2256. ;; protected
  2257. (goto-char ispell-recursive-edit-marker)
  2258. (if (not (equal (marker-buffer
  2259. ispell-recursive-edit-marker)
  2260. (current-buffer)))
  2261. (progn
  2262. (set-marker ispell-recursive-edit-marker nil)
  2263. (error
  2264. "Cannot continue ispell from this buffer.")))
  2265. (set-marker ispell-recursive-edit-marker nil)))
  2266. (list word nil)) ; recheck starting at this word.
  2267. ((= char ?\C-z)
  2268. (funcall (key-binding "\C-z"))
  2269. t)
  2270. (t (ding) t))))))
  2271. result)
  2272. ;; protected
  2273. (and ispell-highlight-p ; unhighlight
  2274. (save-window-excursion
  2275. (select-window textwin)
  2276. (ispell-highlight-spelling-error start end))))))
  2277. (defun ispell-show-choices ()
  2278. "Show the choices in another buffer or frame."
  2279. (if (and ispell-use-framepop-p (fboundp 'framepop-display-buffer))
  2280. (progn
  2281. (framepop-display-buffer (get-buffer ispell-choices-buffer))
  2282. ;; (get-buffer-window ispell-choices-buffer t)
  2283. (select-window (previous-window))) ; *Choices* window
  2284. ;; Display choices above selected window.
  2285. (ispell-display-buffer (get-buffer-create ispell-choices-buffer))))
  2286. ;;;###autoload
  2287. (defun ispell-help ()
  2288. "Display a list of the options available when a misspelling is encountered.
  2289. Selections are:
  2290. DIGIT: Replace the word with a digit offered in the *Choices* buffer.
  2291. SPC: Accept word this time.
  2292. `i': Accept word and insert into private dictionary.
  2293. `a': Accept word for this session.
  2294. `A': Accept word and place in `buffer-local dictionary'.
  2295. `r': Replace word with typed-in value. Rechecked.
  2296. `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  2297. `?': Show these commands.
  2298. `x': Exit spelling buffer. Move cursor to original point.
  2299. `X': Exit spelling buffer. Leaves cursor at the current point, and permits
  2300. the aborted check to be completed later.
  2301. `q': Quit spelling session (Kills ispell process).
  2302. `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
  2303. `u': Like `i', but the word is lower-cased first.
  2304. `m': Place typed-in value in personal dictionary, then recheck current word.
  2305. `C-l': Redraw screen.
  2306. `C-r': Recursive edit.
  2307. `C-z': Suspend Emacs or iconify frame."
  2308. (if (equal ispell-help-in-bufferp 'electric)
  2309. (progn
  2310. (require 'ehelp)
  2311. (with-electric-help
  2312. (function (lambda ()
  2313. ;;This shouldn't be necessary: with-electric-help needs
  2314. ;; an optional argument telling it about the smallest
  2315. ;; acceptable window-height of the help buffer.
  2316. ;;(if (< (window-height) 15)
  2317. ;; (enlarge-window
  2318. ;; (- 15 (ispell-adjusted-window-height))))
  2319. (princ "Selections are:
  2320. DIGIT: Replace the word with a digit offered in the *Choices* buffer.
  2321. SPC: Accept word this time.
  2322. `i': Accept word and insert into private dictionary.
  2323. `a': Accept word for this session.
  2324. `A': Accept word and place in `buffer-local dictionary'.
  2325. `r': Replace word with typed-in value. Rechecked.
  2326. `R': Replace word with typed-in value. Query-replaced in buffer. Rechecked.
  2327. `?': Show these commands.
  2328. `x': Exit spelling buffer. Move cursor to original point.
  2329. `X': Exit spelling buffer. Leaves cursor at the current point, and permits
  2330. the aborted check to be completed later.
  2331. `q': Quit spelling session (Kills ispell process).
  2332. `l': Look up typed-in replacement in alternate dictionary. Wildcards okay.
  2333. `u': Like `i', but the word is lower-cased first.
  2334. `m': Place typed-in value in personal dictionary, then recheck current word.
  2335. `C-l': Redraw screen.
  2336. `C-r': Recursive edit.
  2337. `C-z': Suspend Emacs or iconify frame.")
  2338. nil))))
  2339. (let ((help-1 (concat "[r/R]eplace word; [a/A]ccept for this session; "
  2340. "[i]nsert into private dictionary"))
  2341. (help-2 (concat "[l]ook a word up in alternate dictionary; "
  2342. "e[x/X]it; [q]uit session"))
  2343. (help-3 (concat "[u]ncapitalized insert into dict. "
  2344. "Type 'x C-h f ispell-help' for more help")))
  2345. (save-window-excursion
  2346. (if ispell-help-in-bufferp
  2347. (let ((buffer (get-buffer-create "*Ispell Help*")))
  2348. (with-current-buffer buffer
  2349. (insert (concat help-1 "\n" help-2 "\n" help-3)))
  2350. (ispell-display-buffer buffer)
  2351. (sit-for 5)
  2352. (kill-buffer "*Ispell Help*"))
  2353. (unwind-protect
  2354. (let ((resize-mini-windows 'grow-only))
  2355. (select-window (minibuffer-window))
  2356. (erase-buffer)
  2357. (message nil)
  2358. ;;(set-minibuffer-window (selected-window))
  2359. (enlarge-window 2)
  2360. (insert (concat help-1 "\n" help-2 "\n" help-3))
  2361. (sit-for 5))
  2362. (erase-buffer)))))))
  2363. (define-obsolete-function-alias 'lookup-words 'ispell-lookup-words "24.4")
  2364. (defun ispell-lookup-words (word &optional lookup-dict)
  2365. "Look up WORD in optional word-list dictionary LOOKUP-DICT.
  2366. A `*' serves as a wild card. If no wild cards, `look' is used if it exists.
  2367. Otherwise the variable `ispell-grep-command' contains the command used to
  2368. search for the words (usually egrep).
  2369. Optional second argument contains the dictionary to use; the default is
  2370. `ispell-alternate-dictionary', overridden by `ispell-complete-word-dict'
  2371. if defined."
  2372. ;; We don't use the filter for this function, rather the result is written
  2373. ;; into a buffer. Hence there is no need to save the filter values.
  2374. (if (null lookup-dict)
  2375. (setq lookup-dict (or ispell-complete-word-dict
  2376. ispell-alternate-dictionary)))
  2377. (if lookup-dict
  2378. (unless (file-readable-p lookup-dict)
  2379. (error "lookup-words error: Unreadable or missing plain word-list %s."
  2380. lookup-dict))
  2381. (error (concat "lookup-words error: No plain word-list found at system"
  2382. "default locations. "
  2383. "Customize `ispell-alternate-dictionary' to set yours.")))
  2384. (let* ((process-connection-type ispell-use-ptys-p)
  2385. (wild-p (string-match "\\*" word))
  2386. (look-p (and ispell-look-p ; Only use look for an exact match.
  2387. (or ispell-have-new-look (not wild-p))))
  2388. (prog (if look-p ispell-look-command ispell-grep-command))
  2389. (args (if look-p ispell-look-options ispell-grep-options))
  2390. status results loc)
  2391. (with-temp-buffer
  2392. (message "Starting \"%s\" process..." (file-name-nondirectory prog))
  2393. (if look-p
  2394. nil
  2395. (insert "^" word)
  2396. ;; When there are no wildcards, append one, for consistency
  2397. ;; with `look' behavior.
  2398. (unless wild-p (insert "*"))
  2399. (insert "$")
  2400. ;; Convert * to .*
  2401. (while (search-backward "*" nil t) (insert "."))
  2402. (setq word (buffer-string))
  2403. (erase-buffer))
  2404. (setq status (apply 'ispell-call-process prog nil t nil
  2405. (nconc (if (and args (> (length args) 0))
  2406. (list args)
  2407. (if look-p nil
  2408. (list "-e")))
  2409. (list word)
  2410. (if lookup-dict (list lookup-dict)))))
  2411. ;; `grep' returns status 1 and no output when word not found, which
  2412. ;; is a perfectly normal thing.
  2413. (if (stringp status)
  2414. (error "error: %s exited with signal %s"
  2415. (file-name-nondirectory prog) status)
  2416. ;; Else collect words into `results' in FIFO order.
  2417. (goto-char (point-max))
  2418. ;; Assure we've ended with \n.
  2419. (or (bobp) (= (preceding-char) ?\n) (insert ?\n))
  2420. (while (not (bobp))
  2421. (setq loc (point))
  2422. (forward-line -1)
  2423. (push (buffer-substring-no-properties (point)
  2424. (1- loc))
  2425. results))))
  2426. (if (and results (string-match ".+: " (car results)))
  2427. (error "%s error: %s" ispell-grep-command (car results)))
  2428. results))
  2429. ;; "ispell-filter" is a list of output lines from the generating function.
  2430. ;; Each full line (ending with \n) is a separate item on the list.
  2431. ;; "output" can contain multiple lines, part of a line, or both.
  2432. ;; "start" and "end" are used to keep bounds on lines when "output" contains
  2433. ;; multiple lines.
  2434. ;; "ispell-filter-continue" is true when we have received only part of a
  2435. ;; line as output from a generating function ("output" did not end with \n)
  2436. ;; THIS FUNCTION WILL FAIL IF THE PROCESS OUTPUT DOESN'T END WITH \n!
  2437. ;; This is the case when a process dies or fails. The default behavior
  2438. ;; in this case treats the next input received as fresh input.
  2439. (defun ispell-filter (process output)
  2440. "Output filter function for ispell, grep, and look."
  2441. (let ((start 0)
  2442. (continue t)
  2443. end)
  2444. (while continue
  2445. (setq end (string-match "\n" output start)) ; get text up to the newline.
  2446. ;; If we get out of sync and ispell-filter-continue is asserted when we
  2447. ;; are not continuing, treat the next item as a separate list. When
  2448. ;; ispell-filter-continue is asserted, ispell-filter *should* always be a
  2449. ;; list!
  2450. ;; Continue with same line (item)?
  2451. (if (and ispell-filter-continue ispell-filter (listp ispell-filter))
  2452. ;; Yes. Add it to the prev item
  2453. (setcar ispell-filter
  2454. (concat (car ispell-filter) (substring output start end)))
  2455. ;; No. This is a new line and item.
  2456. (setq ispell-filter
  2457. (cons (substring output start end) ispell-filter)))
  2458. (if (null end)
  2459. ;; We've completed reading the output, but didn't finish the line.
  2460. (setq ispell-filter-continue t continue nil)
  2461. ;; skip over newline, this line complete.
  2462. (setq ispell-filter-continue nil end (1+ end))
  2463. (if (= end (length output)) ; No more lines in output
  2464. (setq continue nil) ; so we can exit the filter.
  2465. (setq start end)))))) ; else move start to next line of input
  2466. ;; This function destroys the mark location if it is in the word being
  2467. ;; highlighted.
  2468. (defun ispell-highlight-spelling-error-generic (start end &optional highlight
  2469. refresh)
  2470. "Highlight the word from START to END with a kludge using `inverse-video'.
  2471. When the optional third arg HIGHLIGHT is set, the word is highlighted;
  2472. otherwise it is displayed normally.
  2473. Uses block cursor to highlight one character.
  2474. Optional REFRESH will unhighlighted then highlight, using block cursor
  2475. highlighting when REFRESH is equal to `block'."
  2476. (and (eq 'block ispell-highlight-p)
  2477. (or (eq 'block refresh)
  2478. (setq start (1+ start)))) ; On block non-refresh, inc start.
  2479. (let ((modified (buffer-modified-p)) ; don't allow this fn to modify buffer
  2480. (buffer-read-only nil) ; Allow highlighting read-only buffers.
  2481. (text (buffer-substring-no-properties start end))
  2482. ; Save highlight region.
  2483. (inhibit-quit t) ; inhibit interrupt processing here.
  2484. (buffer-undo-list t)) ; don't clutter the undo list.
  2485. (goto-char end)
  2486. (delete-region start end)
  2487. (insert-char ? (- end start)) ; minimize amount of redisplay
  2488. (sit-for 0) ; update display
  2489. (if highlight (setq inverse-video (not inverse-video))) ; toggle video
  2490. (delete-region start end) ; delete whitespace
  2491. (insert text) ; insert text in inverse video.
  2492. (sit-for 0) ; update display showing inverse video.
  2493. (if (not highlight)
  2494. (goto-char end)
  2495. (setq inverse-video (not inverse-video)) ; toggle video
  2496. (and (eq 'block ispell-highlight-p)
  2497. (goto-char (1- start)))) ; use block cursor to "highlight" char
  2498. (set-buffer-modified-p modified) ; don't modify if flag not set.
  2499. (and refresh ; re-highlight
  2500. (ispell-highlight-spelling-error-generic
  2501. (if (eq 'block refresh) start (- start 2)) end t))))
  2502. (defun ispell-highlight-spelling-error-xemacs (start end &optional highlight)
  2503. "Highlight the word from START to END using `isearch-highlight'.
  2504. When the optional third arg HIGHLIGHT is set, the word is highlighted,
  2505. otherwise it is displayed normally."
  2506. (if highlight
  2507. (isearch-highlight start end)
  2508. (isearch-dehighlight))
  2509. ;;(sit-for 0)
  2510. )
  2511. (defun ispell-highlight-spelling-error-overlay (start end &optional highlight)
  2512. "Highlight the word from START to END using overlays.
  2513. When the optional third arg HIGHLIGHT is set, the word is highlighted
  2514. otherwise it is displayed normally.
  2515. The variable `ispell-highlight-face' selects the face to use for highlighting."
  2516. (if highlight
  2517. (if ispell-overlay
  2518. (move-overlay ispell-overlay start end (current-buffer))
  2519. (setq ispell-overlay (make-overlay start end))
  2520. (overlay-put ispell-overlay 'priority 1001) ;higher than lazy overlays
  2521. (overlay-put ispell-overlay 'face ispell-highlight-face))
  2522. (if ispell-overlay
  2523. (delete-overlay ispell-overlay)))
  2524. (if (and ispell-lazy-highlight (boundp 'lazy-highlight-cleanup))
  2525. (if highlight
  2526. (let ((isearch-string
  2527. (concat
  2528. "\\b"
  2529. (regexp-quote (buffer-substring-no-properties start end))
  2530. "\\b"))
  2531. (isearch-regexp t)
  2532. (isearch-case-fold-search nil)
  2533. (isearch-forward t)
  2534. (isearch-other-end start)
  2535. (isearch-error nil))
  2536. (isearch-lazy-highlight-new-loop
  2537. (if (boundp 'reg-start) reg-start)
  2538. (if (boundp 'reg-end) reg-end)))
  2539. (lazy-highlight-cleanup lazy-highlight-cleanup)
  2540. (setq isearch-lazy-highlight-last-string nil))))
  2541. (defun ispell-highlight-spelling-error (start end &optional highlight refresh)
  2542. (cond
  2543. ((featurep 'xemacs)
  2544. (ispell-highlight-spelling-error-xemacs start end highlight))
  2545. ((and (featurep 'faces)
  2546. (or (and (fboundp 'display-color-p) (display-color-p))
  2547. window-system))
  2548. (ispell-highlight-spelling-error-overlay start end highlight))
  2549. (t (ispell-highlight-spelling-error-generic start end highlight refresh))))
  2550. (defun ispell-display-buffer (buffer)
  2551. "Show BUFFER in new window above selected one.
  2552. Also position fit window to BUFFER and select it."
  2553. (let* ((unsplittable
  2554. (cdr (assq 'unsplittable (frame-parameters (selected-frame)))))
  2555. (window
  2556. (or (get-buffer-window buffer)
  2557. (and unsplittable
  2558. ;; If frame is unsplittable, temporarily disable that...
  2559. (let ((frame (selected-frame)))
  2560. (modify-frame-parameters frame '((unsplittable . nil)))
  2561. (prog1
  2562. (condition-case nil
  2563. (split-window
  2564. nil (- ispell-choices-win-default-height) 'above)
  2565. (error nil))
  2566. (modify-frame-parameters frame '((unsplittable . t))))))
  2567. (and (not unsplittable)
  2568. (condition-case nil
  2569. (split-window
  2570. nil (- ispell-choices-win-default-height) 'above)
  2571. (error nil)))
  2572. (display-buffer buffer))))
  2573. (if (not window)
  2574. (error "Couldn't make window for *Choices*")
  2575. (select-window window)
  2576. (set-window-buffer window buffer)
  2577. (set-window-point window (point-min))
  2578. (fit-window-to-buffer window nil nil nil nil t))))
  2579. ;; Should we add a compound word match return value?
  2580. (defun ispell-parse-output (output &optional accept-list shift)
  2581. "Parse the OUTPUT string from Ispell process and return:
  2582. 1: t for an exact match.
  2583. 2: A string containing the root word matched via suffix removal.
  2584. 3: A list of possible correct spellings of the format:
  2585. (\"ORIGINAL-WORD\" OFFSET MISS-LIST GUESS-LIST)
  2586. ORIGINAL-WORD is a string of the possibly misspelled word.
  2587. OFFSET is an integer giving the line offset of the word.
  2588. MISS-LIST and GUESS-LIST are possibly null lists of guesses and misses.
  2589. 4: nil when an error has occurred.
  2590. Optional second arg ACCEPT-LIST is list of words already accepted.
  2591. Optional third arg SHIFT is an offset to apply based on previous corrections."
  2592. (cond
  2593. ((string= output "") t) ; for startup with pipes...
  2594. ((string= output "*") t) ; exact match
  2595. ((string= output "-") t) ; compound word match
  2596. ((eq (aref output 0) ?+) ; found because of root word
  2597. (substring output 2)) ; return root word
  2598. ((equal 0 (string-match "[\ra-zA-Z]" output))
  2599. (ding) ; error message from ispell!
  2600. (message "Ispell error: %s" output)
  2601. (sit-for 5)
  2602. nil)
  2603. (t ; need to process &, ?, and #'s
  2604. (let ((type (aref output 0)) ; &, ?, or #
  2605. (original-word (substring output 2 (string-match " " output 2)))
  2606. (cur-count 0) ; contains number of misses + guesses
  2607. count miss-list guess-list offset)
  2608. (setq output (substring output (match-end 0))) ; skip over misspelling
  2609. (if (eq type ?#)
  2610. (setq count 0) ; no misses for type #
  2611. (setq count (string-to-number output) ; get number of misses.
  2612. output (substring output (1+ (string-match " " output 1)))))
  2613. (setq offset (string-to-number output))
  2614. (setq output (if (eq type ?#) ; No miss or guess list.
  2615. nil
  2616. (substring output (1+ (string-match " " output 1)))))
  2617. (while output
  2618. (let ((end (string-match ", \\|\\($\\)" output))) ; end of miss/guess.
  2619. (setq cur-count (1+ cur-count))
  2620. (if (> cur-count count)
  2621. (push (substring output 0 end) guess-list)
  2622. (push (substring output 0 end) miss-list))
  2623. (setq output (if (match-end 1) ; True only when at end of line.
  2624. nil ; No more misses or guesses.
  2625. (substring output (+ end 2))))))
  2626. ;; return results. Accept word if it was already accepted.
  2627. ;; adjust offset.
  2628. (if (member original-word accept-list)
  2629. t
  2630. (list original-word
  2631. (if (numberp shift) (+ shift offset) offset)
  2632. (nreverse miss-list) (nreverse guess-list)))))))
  2633. (defun ispell-process-status ()
  2634. "Return the status of the Ispell process.
  2635. When asynchronous processes are not supported, `run' is always returned."
  2636. (if ispell-async-processp
  2637. (process-status ispell-process)
  2638. (and ispell-process 'run)))
  2639. (defun ispell-start-process ()
  2640. "Start the Ispell process, with support for no asynchronous processes.
  2641. Keeps argument list for future Ispell invocations for no async support."
  2642. ;; `ispell-current-dictionary' and `ispell-current-personal-dictionary'
  2643. ;; are properly set in `ispell-internal-change-dictionary'.
  2644. ;; Parse hunspell affix file if using hunspell and entry is uninitialized.
  2645. (if ispell-really-hunspell
  2646. (or (cadr (assoc ispell-current-dictionary ispell-dictionary-alist))
  2647. (ispell-hunspell-fill-dictionary-entry ispell-current-dictionary)))
  2648. (let* ((default-directory
  2649. (if (file-accessible-directory-p default-directory)
  2650. default-directory
  2651. ;; Defend against bad `default-directory'.
  2652. (expand-file-name "~/")))
  2653. (orig-args (ispell-get-ispell-args))
  2654. (args
  2655. (append
  2656. (if (and ispell-current-dictionary ; Not for default dict (nil)
  2657. (not (member "-d" orig-args))) ; Only define if not overridden.
  2658. (list "-d" ispell-current-dictionary))
  2659. orig-args
  2660. (if ispell-current-personal-dictionary ; Use specified pers dict.
  2661. (list "-p" ispell-current-personal-dictionary))
  2662. ;; If we are using recent aspell or hunspell, make sure we use the
  2663. ;; right encoding for communication. ispell or older aspell/hunspell
  2664. ;; does not support this.
  2665. (if ispell-encoding8-command
  2666. (if ispell-really-hunspell
  2667. (list ispell-encoding8-command
  2668. (upcase (symbol-name (ispell-get-coding-system))))
  2669. (list
  2670. (concat ispell-encoding8-command
  2671. (symbol-name (ispell-get-coding-system))))))
  2672. ispell-extra-args)))
  2673. ;; Initially we don't know any buffer's local words.
  2674. (setq ispell-buffer-local-name nil)
  2675. (if ispell-async-processp
  2676. (let ((process-connection-type ispell-use-ptys-p))
  2677. (apply 'start-process
  2678. "ispell" nil ispell-program-name
  2679. "-a" ; Accept single input lines.
  2680. ;; Make root/affix combos not in dict.
  2681. ;; hunspell -m option means different.
  2682. (if ispell-really-hunspell "" "-m")
  2683. args))
  2684. (setq ispell-cmd-args args
  2685. ispell-output-buffer (generate-new-buffer " *ispell-output*")
  2686. ispell-session-buffer (generate-new-buffer " *ispell-session*"))
  2687. (ispell-send-string "\032\n") ; so Ispell prints version and exits
  2688. t)))
  2689. (defun ispell-init-process ()
  2690. "Check status of Ispell process and start if necessary."
  2691. (let* (;; Basename of dictionary used by the spell-checker
  2692. (dict-bname (or (car (cdr (member "-d" (ispell-get-ispell-args))))
  2693. ispell-current-dictionary))
  2694. ;; The directory where process was started.
  2695. (current-ispell-directory default-directory)
  2696. ;; The default directory for the process.
  2697. ;; Use "~/" as default-directory unless using Ispell with per-dir
  2698. ;; personal dictionaries and not in a minibuffer under XEmacs
  2699. (default-directory
  2700. (if (or ispell-really-aspell
  2701. ispell-really-hunspell
  2702. ;; Protect against bad default-directory
  2703. (not (file-accessible-directory-p default-directory))
  2704. ;; Ispell and per-dir personal dicts available
  2705. (not (or (file-readable-p (concat default-directory
  2706. ".ispell_words"))
  2707. (file-readable-p (concat default-directory
  2708. ".ispell_"
  2709. (or dict-bname
  2710. "default")))))
  2711. ;; Ispell, in a minibuffer, and XEmacs
  2712. (and (window-minibuffer-p)
  2713. (not (fboundp 'minibuffer-selected-window))))
  2714. (expand-file-name "~/")
  2715. (expand-file-name default-directory))))
  2716. ;; Check if process needs restart
  2717. (if (and ispell-process
  2718. (eq (ispell-process-status) 'run)
  2719. ;; Unless we are using an explicit personal dictionary, ensure
  2720. ;; we're in the same default directory! Restart check for
  2721. ;; personal dictionary is done in
  2722. ;; `ispell-internal-change-dictionary', called from
  2723. ;; `ispell-buffer-local-dict'
  2724. (or (or ispell-local-pdict ispell-personal-dictionary)
  2725. (equal ispell-process-directory default-directory)))
  2726. (setq ispell-filter nil ispell-filter-continue nil)
  2727. ;; may need to restart to select new personal dictionary.
  2728. (ispell-kill-ispell t)
  2729. (message "Starting new Ispell process %s with %s dictionary..."
  2730. ispell-program-name
  2731. (or ispell-local-dictionary ispell-dictionary "default"))
  2732. (sit-for 0)
  2733. (setq ispell-library-directory (ispell-check-version)
  2734. ;; Assign a non-nil value to ispell-process-directory
  2735. ;; before calling ispell-start-process, since that
  2736. ;; function needs it to set default-directory when
  2737. ;; ispell-async-processp is nil.
  2738. ispell-process-directory default-directory
  2739. ispell-process (ispell-start-process)
  2740. ispell-filter nil
  2741. ispell-filter-continue nil)
  2742. (unless (equal ispell-process-directory (expand-file-name "~/"))
  2743. ;; At this point, `ispell-process-directory' will be "~/" unless using
  2744. ;; Ispell with directory-specific dicts and not in XEmacs minibuffer.
  2745. ;; If not, kill ispell process when killing buffer. It may be in a
  2746. ;; removable device that would otherwise become un-mountable.
  2747. (with-current-buffer
  2748. (if (and (window-minibuffer-p) ;; In minibuffer
  2749. (fboundp 'minibuffer-selected-window)) ;; Not XEmacs.
  2750. ;; In this case kill ispell only when parent buffer is killed
  2751. ;; to avoid over and over ispell kill.
  2752. (window-buffer (minibuffer-selected-window))
  2753. (current-buffer))
  2754. ;; 'local does not automatically make hook buffer-local in XEmacs.
  2755. (if (featurep 'xemacs)
  2756. (make-local-hook 'kill-buffer-hook))
  2757. (add-hook 'kill-buffer-hook
  2758. (lambda () (ispell-kill-ispell t)) nil 'local)))
  2759. (if ispell-async-processp
  2760. (set-process-filter ispell-process 'ispell-filter))
  2761. ;; Protect against XEmacs bogus binding of `enable-multibyte-characters'.
  2762. (if (and (or (featurep 'xemacs)
  2763. (and (boundp 'enable-multibyte-characters)
  2764. enable-multibyte-characters))
  2765. (fboundp 'set-process-coding-system)
  2766. ;; Evidently, some people use the synchronous mode even
  2767. ;; when async subprocesses are supported, in which case
  2768. ;; set-process-coding-system is bound, but
  2769. ;; ispell-process is not a process object.
  2770. ispell-async-processp)
  2771. (set-process-coding-system ispell-process (ispell-get-coding-system)
  2772. (ispell-get-coding-system)))
  2773. ;; Get version ID line
  2774. (ispell-accept-output 3)
  2775. ;; get more output if filter empty?
  2776. (if (null ispell-filter) (ispell-accept-output 3))
  2777. (cond ((null ispell-filter)
  2778. (error "%s did not output version line" ispell-program-name))
  2779. ((and
  2780. (stringp (car ispell-filter))
  2781. (if (string-match "warning: " (car ispell-filter))
  2782. (progn
  2783. (ispell-accept-output 3) ; was warn msg.
  2784. (stringp (car ispell-filter)))
  2785. (null (cdr ispell-filter)))
  2786. (string-match "^@(#) " (car ispell-filter)))
  2787. ;; got the version line as expected (we already know it's the right
  2788. ;; version, so don't bother checking again.)
  2789. nil)
  2790. (t
  2791. ;; Otherwise, it must be an error message. Show the user.
  2792. ;; But first wait to see if some more output is going to arrive.
  2793. ;; Otherwise we get cool errors like "Can't open ".
  2794. (sleep-for 1)
  2795. (ispell-accept-output 3)
  2796. (error "%s" (mapconcat 'identity ispell-filter "\n"))))
  2797. (setq ispell-filter nil) ; Discard version ID line
  2798. (let ((extended-char-mode (ispell-get-extended-character-mode)))
  2799. (if extended-char-mode ; ~ extended character mode
  2800. (ispell-send-string (concat extended-char-mode "\n"))))
  2801. (if ispell-async-processp
  2802. (if (featurep 'emacs)
  2803. (set-process-query-on-exit-flag ispell-process nil)
  2804. (if (fboundp 'set-process-query-on-exit-flag)
  2805. (set-process-query-on-exit-flag ispell-process nil)
  2806. (process-kill-without-query ispell-process)))))))
  2807. ;;;###autoload
  2808. (defun ispell-kill-ispell (&optional no-error clear)
  2809. "Kill current Ispell process (so that you may start a fresh one).
  2810. With NO-ERROR, just return non-nil if there was no Ispell running.
  2811. With CLEAR, buffer session localwords are cleaned."
  2812. (interactive)
  2813. ;; This hook is typically used by flyspell to flush some variables used
  2814. ;; to optimize the common cases.
  2815. (run-hooks 'ispell-kill-ispell-hook)
  2816. (if (or clear
  2817. (if (featurep 'xemacs)
  2818. (interactive-p)
  2819. (called-interactively-p 'interactive)))
  2820. (setq ispell-buffer-session-localwords nil))
  2821. (if (not (and ispell-process
  2822. (eq (ispell-process-status) 'run)))
  2823. (or no-error
  2824. (error "There is no Ispell process running!"))
  2825. (if ispell-async-processp
  2826. (delete-process ispell-process)
  2827. ;; Synchronous processes.
  2828. (ispell-send-string "\n") ; Make sure side effects occurred.
  2829. (kill-buffer ispell-output-buffer)
  2830. (kill-buffer ispell-session-buffer)
  2831. (setq ispell-output-buffer nil
  2832. ispell-session-buffer nil))
  2833. (setq ispell-process nil)
  2834. (message "Ispell process killed")
  2835. nil))
  2836. ;; ispell-change-dictionary is set in some people's hooks. Maybe this should
  2837. ;; call ispell-init-process rather than wait for a spell checking command?
  2838. ;;;###autoload
  2839. (defun ispell-change-dictionary (dict &optional arg)
  2840. "Change to dictionary DICT for Ispell.
  2841. With a prefix arg, set it \"globally\", for all buffers.
  2842. Without a prefix arg, set it \"locally\", just for this buffer.
  2843. By just answering RET you can find out what the current dictionary is."
  2844. (interactive
  2845. (list (completing-read
  2846. "Use new dictionary (RET for current, SPC to complete): "
  2847. (and (fboundp 'ispell-valid-dictionary-list)
  2848. (mapcar 'list (ispell-valid-dictionary-list)))
  2849. nil t)
  2850. current-prefix-arg))
  2851. (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
  2852. (unless arg (ispell-buffer-local-dict 'no-reload))
  2853. (if (equal dict "default") (setq dict nil))
  2854. ;; This relies on completing-read's bug of returning "" for no match
  2855. (cond ((equal dict "")
  2856. (ispell-internal-change-dictionary)
  2857. (message "Using %s dictionary"
  2858. (or (and (not arg) ispell-local-dictionary)
  2859. ispell-dictionary "default")))
  2860. ((equal dict (or (and (not arg) ispell-local-dictionary)
  2861. ispell-dictionary "default"))
  2862. ;; Specified dictionary is the default already. Could reload
  2863. ;; the dictionaries if needed.
  2864. (ispell-internal-change-dictionary)
  2865. (and (if (featurep 'xemacs)
  2866. (interactive-p)
  2867. (called-interactively-p 'interactive))
  2868. (message "No change, using %s dictionary" dict)))
  2869. (t ; reset dictionary!
  2870. (if (or (assoc dict ispell-local-dictionary-alist)
  2871. (assoc dict ispell-dictionary-alist))
  2872. (if arg
  2873. ;; set default dictionary
  2874. (setq ispell-dictionary dict)
  2875. ;; set local dictionary
  2876. (setq ispell-local-dictionary dict)
  2877. (setq ispell-local-dictionary-overridden t))
  2878. (error "Undefined dictionary: %s" dict))
  2879. (ispell-internal-change-dictionary)
  2880. (setq ispell-buffer-session-localwords nil)
  2881. (message "%s Ispell dictionary set to %s"
  2882. (if arg "Global" "Local")
  2883. dict))))
  2884. (defun ispell-internal-change-dictionary ()
  2885. "Update the dictionary and the personal dictionary used by Ispell.
  2886. This may kill the Ispell process; if so, a new one will be started
  2887. when needed."
  2888. (let* ((dict (or ispell-local-dictionary ispell-dictionary))
  2889. (pdict (or ispell-local-pdict ispell-personal-dictionary))
  2890. (expanded-pdict (if pdict (expand-file-name pdict))))
  2891. (unless (and (equal ispell-current-dictionary dict)
  2892. (equal ispell-current-personal-dictionary
  2893. expanded-pdict))
  2894. (ispell-kill-ispell t)
  2895. (setq ispell-current-dictionary dict
  2896. ispell-current-personal-dictionary expanded-pdict))))
  2897. ;; Avoid error messages when compiling for these dynamic variables.
  2898. (defvar ispell-start)
  2899. (defvar ispell-end)
  2900. ;; Spelling of comments are checked when ispell-check-comments is non-nil.
  2901. ;;;###autoload
  2902. (defun ispell-region (reg-start reg-end &optional recheckp shift)
  2903. "Interactively check a region for spelling errors.
  2904. Return nil if spell session was terminated, otherwise returns shift offset
  2905. amount for last line processed."
  2906. (interactive "r") ; Don't flag errors on read-only bufs.
  2907. (ispell-set-spellchecker-params) ; Initialize variables and dicts alists
  2908. (if (not recheckp)
  2909. (ispell-accept-buffer-local-defs)) ; set up dictionary, local words, etc.
  2910. (let ((skip-region-start (make-marker))
  2911. (rstart (make-marker))
  2912. (region-type (if (and (= reg-start (point-min)) (= reg-end (point-max)))
  2913. (buffer-name) "region"))
  2914. (program-basename (file-name-nondirectory ispell-program-name))
  2915. (dictionary (or ispell-current-dictionary "default")))
  2916. (unwind-protect
  2917. (save-excursion
  2918. (message "Spell-checking %s using %s with %s dictionary..."
  2919. region-type program-basename dictionary)
  2920. ;; Returns cursor to original location.
  2921. (save-window-excursion
  2922. (goto-char reg-start)
  2923. (let ((transient-mark-mode)
  2924. (case-fold-search case-fold-search)
  2925. (query-fcc t)
  2926. in-comment key)
  2927. (ispell-print-if-debug
  2928. "ispell-region: (ispell-skip-region-list):\n%s
  2929. ispell-region: (ispell-begin-skip-region-regexp):\n%s
  2930. ispell-region: Search for first region to skip after (ispell-begin-skip-region-regexp)\n"
  2931. (ispell-skip-region-list)
  2932. (ispell-begin-skip-region-regexp))
  2933. (if (re-search-forward (ispell-begin-skip-region-regexp) reg-end t)
  2934. (progn
  2935. (setq key (match-string-no-properties 0))
  2936. (set-marker skip-region-start (- (point) (length key)))
  2937. (goto-char reg-start)
  2938. (ispell-print-if-debug
  2939. "ispell-region: First skip: %s at (pos,line,column): (%s,%s,%s).\n"
  2940. key
  2941. (save-excursion (goto-char skip-region-start) (point))
  2942. (line-number-at-pos skip-region-start)
  2943. (save-excursion (goto-char skip-region-start) (current-column)))))
  2944. (ispell-print-if-debug
  2945. "ispell-region: Continue spell-checking with %s and %s dictionary...\n"
  2946. program-basename dictionary)
  2947. (set-marker rstart reg-start)
  2948. (set-marker ispell-region-end reg-end)
  2949. (while (and (not ispell-quit)
  2950. (< (point) ispell-region-end))
  2951. ;; spell-check region with skipping
  2952. (if (and (marker-position skip-region-start)
  2953. (<= skip-region-start (point)))
  2954. (progn
  2955. ;; If region inside line comment, must keep comment start.
  2956. (setq in-comment (point)
  2957. in-comment
  2958. (and comment-start
  2959. (or (null comment-end) (string= "" comment-end))
  2960. (save-excursion
  2961. (beginning-of-line)
  2962. (re-search-forward comment-start in-comment t))
  2963. comment-start))
  2964. ;; Can change skip-regexps (in ispell-message)
  2965. (ispell-skip-region key) ; moves pt past region.
  2966. (set-marker rstart (point))
  2967. ;; check for saving large attachments...
  2968. (setq query-fcc (and query-fcc
  2969. (ispell-ignore-fcc skip-region-start
  2970. rstart)))
  2971. (if (and (< rstart ispell-region-end)
  2972. (re-search-forward
  2973. (ispell-begin-skip-region-regexp)
  2974. ispell-region-end t))
  2975. (progn
  2976. (setq key (match-string-no-properties 0))
  2977. (set-marker skip-region-start
  2978. (- (point) (length key)))
  2979. (goto-char rstart)
  2980. (ispell-print-if-debug
  2981. "ispell-region: Next skip: %s at (pos,line,column): (%s,%s,%s).\n"
  2982. key
  2983. (save-excursion (goto-char skip-region-start) (point))
  2984. (line-number-at-pos skip-region-start)
  2985. (save-excursion (goto-char skip-region-start) (current-column))))
  2986. (set-marker skip-region-start nil))))
  2987. (setq reg-end (max (point)
  2988. (if (marker-position skip-region-start)
  2989. (min skip-region-start ispell-region-end)
  2990. (marker-position ispell-region-end))))
  2991. (let* ((ispell-start (point))
  2992. (ispell-end (min (point-at-eol) reg-end))
  2993. ;; See if line must be prefixed by comment string to let ispell know this is
  2994. ;; part of a comment string. This is only supported in some modes.
  2995. ;; In particular, this is not supported in autoconf mode where adding the
  2996. ;; comment string messes everything up because ispell tries to spellcheck the
  2997. ;; `dnl' string header causing misalignments in some cases (debbugs.gnu.org: #12768).
  2998. (add-comment (and in-comment
  2999. (not (string= in-comment "dnl "))
  3000. in-comment))
  3001. (string (ispell-get-line
  3002. ispell-start ispell-end add-comment)))
  3003. (ispell-print-if-debug
  3004. "ispell-region: string pos (%s->%s), eol: %s, [in-comment]: [%s], [add-comment]: [%s], [string]: [%s]\n"
  3005. ispell-start ispell-end (point-at-eol) in-comment add-comment string)
  3006. (if add-comment ; account for comment chars added
  3007. (setq ispell-start (- ispell-start (length add-comment))
  3008. ;; Reset `in-comment' (and indirectly `add-comment') for new line
  3009. in-comment nil))
  3010. (setq ispell-end (point)) ; "end" tracks region retrieved.
  3011. (if string ; there is something to spell check!
  3012. ;; (special start end)
  3013. (setq shift (ispell-process-line string
  3014. (and recheckp shift))))
  3015. (goto-char ispell-end)))))
  3016. (if ispell-quit
  3017. nil
  3018. (or shift 0)))
  3019. ;; protected
  3020. (if (and (not (and recheckp ispell-keep-choices-win))
  3021. (get-buffer ispell-choices-buffer))
  3022. (kill-buffer ispell-choices-buffer))
  3023. (set-marker skip-region-start nil)
  3024. (set-marker rstart nil)
  3025. (if ispell-quit
  3026. (progn
  3027. ;; preserve or clear the region for ispell-continue.
  3028. (if (not (numberp ispell-quit))
  3029. (set-marker ispell-region-end nil)
  3030. ;; Ispell-continue enabled - ispell-region-end is set.
  3031. (goto-char ispell-quit))
  3032. ;; Check for aborting
  3033. (if (and ispell-checking-message (numberp ispell-quit))
  3034. (progn
  3035. (setq ispell-quit nil)
  3036. (error "Message send aborted")))
  3037. (if (not recheckp) (setq ispell-quit nil)))
  3038. (if (not recheckp) (set-marker ispell-region-end nil))
  3039. ;; Only save if successful exit.
  3040. (ispell-pdict-save ispell-silently-savep)
  3041. (message "Spell-checking %s using %s with %s dictionary...done"
  3042. region-type program-basename dictionary)))))
  3043. (defun ispell-begin-skip-region-regexp ()
  3044. "Return a regexp of the search keys for region skipping.
  3045. Includes `ispell-skip-region-alist' plus tex, tib, html, and comment keys.
  3046. Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
  3047. (mapconcat
  3048. 'identity
  3049. (delq nil
  3050. (list
  3051. ;; messages
  3052. (if (and ispell-checking-message
  3053. (not (eq t ispell-checking-message)))
  3054. (mapconcat #'car ispell-checking-message "\\|"))
  3055. ;; tex
  3056. (if (eq ispell-parser 'tex)
  3057. (ispell-begin-tex-skip-regexp))
  3058. ;; html stuff
  3059. (if ispell-skip-html
  3060. (ispell-begin-skip-region ispell-html-skip-alists))
  3061. ;; tib
  3062. (if ispell-skip-tib ispell-tib-ref-beginning)
  3063. ;; Comments
  3064. (if (and (eq 'exclusive ispell-check-comments) comment-start)
  3065. ;; search from end of current comment to start of next comment.
  3066. (if (string= "" comment-end) "^" (regexp-quote comment-end)))
  3067. (if (and (null ispell-check-comments) comment-start)
  3068. (regexp-quote comment-start))
  3069. (ispell-begin-skip-region ispell-skip-region-alist)))
  3070. "\\|"))
  3071. (defun ispell-begin-skip-region (skip-alist)
  3072. "Regular expression for start of regions to skip generated from SKIP-ALIST.
  3073. Each selection should be a key of SKIP-ALIST;
  3074. otherwise, the current line is skipped."
  3075. (mapconcat (lambda (lst) (if (stringp (car lst)) (car lst) (eval (car lst))))
  3076. skip-alist
  3077. "\\|"))
  3078. (defun ispell-begin-tex-skip-regexp ()
  3079. "Regular expression of tex commands to skip.
  3080. Generated from `ispell-tex-skip-alists'."
  3081. (concat
  3082. ;; raw tex keys
  3083. (mapconcat (function (lambda (lst) (car lst)))
  3084. (car ispell-tex-skip-alists)
  3085. "\\|")
  3086. "\\|"
  3087. ;; keys wrapped in begin{}
  3088. (mapconcat (function (lambda (lst)
  3089. (concat "\\\\begin[ \t\n]*{[ \t\n]*"
  3090. (car lst)
  3091. "[ \t\n]*}")))
  3092. (car (cdr ispell-tex-skip-alists))
  3093. "\\|")))
  3094. (defun ispell-skip-region-list ()
  3095. "Return a list describing key and body regions to skip for this buffer.
  3096. Includes regions defined by `ispell-skip-region-alist', tex mode,
  3097. `ispell-html-skip-alists', and `ispell-checking-message'.
  3098. Manual checking must include comments and tib references.
  3099. The list is of the form described by variable `ispell-skip-region-alist'.
  3100. Must be called after `ispell-buffer-local-parsing' due to dependence on mode."
  3101. (let ((skip-alist ispell-skip-region-alist))
  3102. ;; only additional explicit region definition is tex.
  3103. (if (eq ispell-parser 'tex)
  3104. (setq case-fold-search nil
  3105. skip-alist (append (car ispell-tex-skip-alists)
  3106. (car (cdr ispell-tex-skip-alists))
  3107. skip-alist)))
  3108. (if ispell-skip-html
  3109. (setq skip-alist (append ispell-html-skip-alists skip-alist)))
  3110. (if (and ispell-checking-message
  3111. (not (eq t ispell-checking-message)))
  3112. (setq skip-alist (append ispell-checking-message skip-alist)))
  3113. skip-alist))
  3114. (defun ispell-tex-arg-end (&optional arg)
  3115. "Skip across ARG number of braces."
  3116. (condition-case nil
  3117. (progn
  3118. (while (looking-at "[ \t\n]*\\[") (forward-sexp))
  3119. (forward-sexp (or arg 1)))
  3120. (error
  3121. (message "Error skipping s-expressions at point %d." (point))
  3122. (beep)
  3123. (sit-for 2))))
  3124. (defun ispell-ignore-fcc (start end)
  3125. "Delete the Fcc: message header when large attachments are included.
  3126. Return value nil if file with large attachments is saved.
  3127. This can be used to avoid multiple questions for multiple large attachments.
  3128. Returns point to starting location afterwards."
  3129. (let ((result t))
  3130. (if (and ispell-checking-message ispell-message-fcc-skip)
  3131. (if (< ispell-message-fcc-skip (- end start))
  3132. (let (case-fold-search head-end)
  3133. (goto-char (point-min))
  3134. (setq head-end
  3135. (or (re-search-forward
  3136. (concat "^" (regexp-quote mail-header-separator) "$")
  3137. nil t)
  3138. (re-search-forward "^$" nil t)
  3139. (point-min)))
  3140. (goto-char (point-min))
  3141. (if (re-search-forward "^Fcc:" head-end t)
  3142. (if (y-or-n-p
  3143. "Save copy of this message with large attachments? ")
  3144. (setq result nil)
  3145. (beginning-of-line)
  3146. (kill-line 1)))
  3147. (goto-char end))))
  3148. result))
  3149. (defun ispell-skip-region (key)
  3150. "Skip across KEY and then to end of region.
  3151. Key lookup determines region to skip.
  3152. Point is placed at end of skipped region."
  3153. ;; move over key to begin checking.
  3154. (forward-char (length key))
  3155. (let ((start (point))
  3156. ;; Regenerate each call... This function can change region definition.
  3157. (alist (ispell-skip-region-list))
  3158. alist-key null-skip)
  3159. (cond
  3160. ;; what about quoted comment, or comment inside strings?
  3161. ((and (null ispell-check-comments) comment-start
  3162. (string= key comment-start))
  3163. (if (string= "" comment-end)
  3164. (forward-line)
  3165. (search-forward comment-end ispell-region-end t)))
  3166. ((and (eq 'exclusive ispell-check-comments) comment-start
  3167. (string= key comment-end))
  3168. (search-forward comment-start ispell-region-end :end))
  3169. ((and ispell-skip-tib (string-match ispell-tib-ref-beginning key))
  3170. (re-search-forward ispell-tib-ref-end ispell-region-end t))
  3171. ;; markings from alist
  3172. (t
  3173. (while alist
  3174. (setq alist-key (eval (car (car alist))))
  3175. (if (string-match alist-key key)
  3176. (progn
  3177. (setq alist (cdr (car alist)))
  3178. (cond
  3179. ((null alist) (setq null-skip t)) ; done! Just skip key.
  3180. ((not (consp alist))
  3181. ;; Search past end of spell region to find this region end.
  3182. (re-search-forward (eval alist) (point-max) t))
  3183. ((and (= 1 (length alist))
  3184. (stringp (car alist)))
  3185. (re-search-forward (car alist) (point-max) t))
  3186. (t
  3187. (setq null-skip t) ; error handling in functions!
  3188. (if (consp (cdr alist))
  3189. (apply (car alist) (cdr alist))
  3190. (funcall (car alist)))))
  3191. (setq alist nil))
  3192. (setq alist (cdr alist))))))
  3193. (if (and (= start (point)) (null null-skip))
  3194. (progn
  3195. (message "Matching region end for `%s' point %d not found"
  3196. key (point))
  3197. (beep)
  3198. (sit-for 2)))))
  3199. (defun ispell-get-line (start end in-comment)
  3200. "Grab the next line of data.
  3201. Returns a string with the line data."
  3202. (let ((ispell-casechars (ispell-get-casechars))
  3203. string)
  3204. (cond ; LOOK AT THIS LINE AND SKIP OR PROCESS
  3205. ((eolp) ; END OF LINE, just go to next line.
  3206. (forward-line))
  3207. ;;((looking-at "[-#@*+!%~^]") ; SKIP SPECIAL ISPELL CHARACTERS
  3208. ;; (forward-char 1)) ; not needed as quoted below.
  3209. ((or (re-search-forward ispell-casechars end t) ; TEXT EXISTS
  3210. (re-search-forward "[][()${}]" end t)) ; or MATH COMMANDS
  3211. (setq string (concat "^" in-comment
  3212. (buffer-substring-no-properties start end)
  3213. "\n"))
  3214. (goto-char end))
  3215. (t (goto-char end))) ; EMPTY LINE, skip it.
  3216. string))
  3217. (defun ispell-looking-at (string)
  3218. (let ((coding (ispell-get-coding-system))
  3219. (len (length string)))
  3220. (and (<= (+ (point) len) (point-max))
  3221. (equal (encode-coding-string string coding)
  3222. (encode-coding-string (buffer-substring-no-properties
  3223. (point) (+ (point) len))
  3224. coding)))))
  3225. (defun ispell-process-line (string shift)
  3226. "Send STRING, a line of text, to ispell and process the result.
  3227. This will modify the buffer for spelling errors.
  3228. Requires variables ISPELL-START and ISPELL-END to be defined in its
  3229. dynamic scope.
  3230. Returns the sum SHIFT due to changes in word replacements."
  3231. ;;(declare special ispell-start ispell-end)
  3232. (let (poss accept-list)
  3233. (if (not (numberp shift))
  3234. (setq shift 0))
  3235. ;; send string to spell process and get input.
  3236. (ispell-send-string string)
  3237. (while (progn
  3238. (ispell-accept-output)
  3239. ;; Last item of output contains a blank line.
  3240. (not (string= "" (car ispell-filter)))))
  3241. ;; parse all inputs from the stream one word at a time.
  3242. ;; Place in FIFO order and remove the blank item.
  3243. (setq ispell-filter (nreverse (cdr ispell-filter)))
  3244. (while (and (not ispell-quit) ispell-filter)
  3245. ;; get next word, accounting for accepted words and start shifts
  3246. (setq poss (ispell-parse-output (car ispell-filter)
  3247. accept-list shift))
  3248. (if (and poss (listp poss)) ; spelling error occurred.
  3249. ;; Whenever we have misspellings, we can change
  3250. ;; the buffer. Keep boundaries as markers.
  3251. ;; Markers can move with highlighting! This destroys
  3252. ;; end of region markers line-end and ispell-region-end
  3253. (let ((word-start
  3254. (copy-marker (+ ispell-start ispell-offset (car (cdr poss)))))
  3255. (word-len (length (car poss)))
  3256. (line-end (copy-marker ispell-end))
  3257. (line-start (copy-marker ispell-start))
  3258. recheck-region replace)
  3259. (goto-char word-start)
  3260. ;; Adjust the horizontal scroll & point
  3261. (ispell-horiz-scroll)
  3262. (goto-char (+ word-len word-start))
  3263. (ispell-horiz-scroll)
  3264. (goto-char word-start)
  3265. (ispell-horiz-scroll)
  3266. ;; Alignment cannot be tracked and this error will occur when
  3267. ;; `query-replace' makes multiple corrections on the starting line.
  3268. (or (ispell-looking-at (car poss))
  3269. ;; This error occurs due to filter pipe problems
  3270. (let* ((ispell-pipe-word (car poss))
  3271. (actual-point (marker-position word-start))
  3272. (actual-line (line-number-at-pos actual-point))
  3273. (actual-column (save-excursion (goto-char actual-point)
  3274. (current-column))))
  3275. (ispell-print-if-debug
  3276. "ispell-process-line: Ispell misalignment error:
  3277. [Word from ispell pipe]: [%s], actual (point,line,column): (%s,%s,%s)\n"
  3278. ispell-pipe-word actual-point actual-line actual-column)
  3279. (error (concat "Ispell misalignment: word "
  3280. "`%s' point %d; probably incompatible versions")
  3281. ispell-pipe-word actual-point)))
  3282. ;; ispell-cmd-loop can go recursive & change buffer
  3283. (if ispell-keep-choices-win
  3284. (setq replace (ispell-command-loop
  3285. (car (cdr (cdr poss)))
  3286. (car (cdr (cdr (cdr poss))))
  3287. (car poss) (marker-position word-start)
  3288. (+ word-len (marker-position word-start))))
  3289. (save-window-excursion
  3290. (setq replace (ispell-command-loop
  3291. (car (cdr (cdr poss)))
  3292. (car (cdr (cdr (cdr poss))))
  3293. (car poss) (marker-position word-start)
  3294. (+ word-len (marker-position word-start))))))
  3295. (goto-char word-start)
  3296. ;; Recheck when query replace edit changes misspelled word.
  3297. ;; Error in tex mode when a potential math mode change exists.
  3298. (if (and replace (listp replace) (= 2 (length replace)))
  3299. (if (and (eq ispell-parser 'tex)
  3300. (string-match "[\\\\][]()[]\\|\\\\begin\\|\\$"
  3301. (regexp-quote string)))
  3302. (error
  3303. "Don't start query replace on a line with math characters"
  3304. )
  3305. (set-marker line-end (point))
  3306. (setq ispell-filter nil
  3307. recheck-region t)))
  3308. ;; Insert correction if needed.
  3309. (cond
  3310. ((or (null replace)
  3311. (equal 0 replace)) ; ACCEPT/INSERT
  3312. (if (equal 0 replace) ; BUFFER-LOCAL DICT ADD
  3313. (ispell-add-per-file-word-list (car poss)))
  3314. ;; Do not recheck accepted word on this line.
  3315. (setq accept-list (cons (car poss) accept-list)))
  3316. (t ; Replacement word selected or entered.
  3317. (delete-region (point) (+ word-len (point)))
  3318. (if (not (listp replace))
  3319. (progn
  3320. (insert replace) ; Insert dictionary word.
  3321. (ispell-send-replacement (car poss) replace)
  3322. (setq accept-list (cons replace accept-list)))
  3323. (let ((replace-word (car replace)))
  3324. ;; Recheck hand entered replacement word.
  3325. (insert replace-word)
  3326. (ispell-send-replacement (car poss) replace-word)
  3327. (if (car (cdr replace))
  3328. (save-window-excursion
  3329. (delete-other-windows) ; to correctly show help.
  3330. ;; Assume case-replace &
  3331. ;; case-fold-search correct?
  3332. (query-replace (car poss) (car replace) t)))
  3333. (goto-char word-start)
  3334. ;; Do not recheck if already accepted.
  3335. (if (member replace-word accept-list)
  3336. (setq accept-list (cons replace-word accept-list)
  3337. replace replace-word)
  3338. (let ((region-end (copy-marker ispell-region-end)))
  3339. (setq recheck-region ispell-filter
  3340. ispell-filter nil ; Save filter.
  3341. shift 0 ; Already accounted.
  3342. shift (ispell-region
  3343. word-start
  3344. (+ word-start (length replace-word))
  3345. t shift))
  3346. (if (null shift) ; Quitting check.
  3347. (setq shift 0))
  3348. (set-marker ispell-region-end region-end)
  3349. (set-marker region-end nil)
  3350. (setq ispell-filter recheck-region
  3351. recheck-region nil
  3352. replace replace-word)))))
  3353. (setq shift (+ shift (- (length replace) word-len)))
  3354. ;; Move line-start across word...
  3355. ;; new shift function does this now...
  3356. ;;(set-marker line-start (+ line-start
  3357. ;; (- (length replace)
  3358. ;; (length (car poss)))))
  3359. ))
  3360. (if (not ispell-quit)
  3361. ;; FIXME: remove redundancy with identical code above.
  3362. (let (message-log-max)
  3363. (message
  3364. "Continuing spelling check using %s with %s dictionary..."
  3365. (file-name-nondirectory ispell-program-name)
  3366. (or ispell-current-dictionary "default"))))
  3367. (sit-for 0)
  3368. (setq ispell-start (marker-position line-start)
  3369. ispell-end (marker-position line-end))
  3370. ;; Adjust markers when end of region lost from highlighting.
  3371. (if (and (not recheck-region)
  3372. (< ispell-end (+ word-start word-len)))
  3373. (setq ispell-end (+ word-start word-len)))
  3374. (if (= word-start ispell-region-end)
  3375. (set-marker ispell-region-end (+ word-start word-len)))
  3376. ;; Going out of scope - unneeded.
  3377. (set-marker line-start nil)
  3378. (set-marker word-start nil)
  3379. (set-marker line-end nil)))
  3380. ;; Finished with misspelling!
  3381. (setq ispell-filter (cdr ispell-filter)))
  3382. shift))
  3383. ;;;###autoload
  3384. (defun ispell-comments-and-strings ()
  3385. "Check comments and strings in the current buffer for spelling errors."
  3386. (interactive)
  3387. (goto-char (point-min))
  3388. (let (state done)
  3389. (while (not done)
  3390. (setq done t)
  3391. (setq state (parse-partial-sexp (point) (point-max)
  3392. nil nil state 'syntax-table))
  3393. (if (or (nth 3 state) (nth 4 state))
  3394. (let ((start (point)))
  3395. (setq state (parse-partial-sexp start (point-max)
  3396. nil nil state 'syntax-table))
  3397. (if (or (nth 3 state) (nth 4 state))
  3398. (error "Unterminated string or comment"))
  3399. (save-excursion
  3400. (setq done (not (ispell-region start (point))))))))))
  3401. ;;;###autoload
  3402. (defun ispell-buffer ()
  3403. "Check the current buffer for spelling errors interactively."
  3404. (interactive)
  3405. (ispell-region (point-min) (point-max)))
  3406. ;;;###autoload
  3407. (defun ispell-buffer-with-debug (&optional append)
  3408. "`ispell-buffer' with some output sent to `ispell-debug-buffer' buffer.
  3409. If APPEND is non-n il, append the info to previous buffer if exists."
  3410. (interactive)
  3411. (let ((ispell-debug-buffer (ispell-create-debug-buffer append)))
  3412. (ispell-buffer)))
  3413. ;;;###autoload
  3414. (defun ispell-continue ()
  3415. "Continue a halted spelling session beginning with the current word."
  3416. (interactive)
  3417. (if (not (marker-position ispell-region-end))
  3418. (message "No session to continue. Use 'X' command when checking!")
  3419. (if (not (equal (marker-buffer ispell-region-end) (current-buffer)))
  3420. (message "Must continue ispell from buffer %s"
  3421. (buffer-name (marker-buffer ispell-region-end)))
  3422. (ispell-region
  3423. ;; find beginning of current word:
  3424. (car (cdr (ispell-get-word t)))
  3425. (marker-position ispell-region-end)))))
  3426. ;;; Horizontal scrolling
  3427. (defun ispell-horiz-scroll ()
  3428. "Place point within the horizontal visibility of its window area."
  3429. (if truncate-lines ; display truncating lines?
  3430. ;; See if display needs to be scrolled.
  3431. (let ((column (- (current-column) (max (window-hscroll) 1))))
  3432. (if (and (< column 0) (> (window-hscroll) 0))
  3433. (scroll-right (max (- column) 10))
  3434. (if (>= column (- (window-width) 2))
  3435. (scroll-left (max (- column (window-width) -3) 10)))))))
  3436. ;;; Interactive word completion.
  3437. ;; Forces "previous-word" processing. Do we want to make this selectable?
  3438. ;;;###autoload
  3439. (defun ispell-complete-word (&optional interior-frag)
  3440. "Try to complete the word before or at point.
  3441. If optional INTERIOR-FRAG is non-nil, then the word may be a character
  3442. sequence inside of a word.
  3443. Standard ispell choices are then available."
  3444. ;; FIXME: completion-at-point-function.
  3445. (interactive "P")
  3446. (let ((cursor-location (point))
  3447. (case-fold-search-val case-fold-search)
  3448. (word (ispell-get-word nil "\\*")) ; force "previous-word" processing.
  3449. start end possibilities replacement)
  3450. (setq start (car (cdr word))
  3451. end (car (cdr (cdr word)))
  3452. word (car word)
  3453. possibilities
  3454. (or (string= word "") ; Will give you every word
  3455. (ispell-lookup-words
  3456. (concat (and interior-frag "*") word
  3457. (and interior-frag "*"))
  3458. (or ispell-complete-word-dict
  3459. ispell-alternate-dictionary))))
  3460. (cond ((eq possibilities t)
  3461. (message "No word to complete"))
  3462. ((null possibilities)
  3463. (message "No match for \"%s\"" word))
  3464. (t ; There is a modification...
  3465. (setq case-fold-search nil) ; Try and respect case of word.
  3466. (cond
  3467. ((string-equal (upcase word) word)
  3468. (setq possibilities (mapcar 'upcase possibilities)))
  3469. ((eq (upcase (aref word 0)) (aref word 0))
  3470. (setq possibilities (mapcar (function
  3471. (lambda (pos)
  3472. (if (eq (aref word 0) (aref pos 0))
  3473. pos
  3474. (capitalize pos))))
  3475. possibilities))))
  3476. (setq case-fold-search case-fold-search-val)
  3477. (save-window-excursion
  3478. (setq replacement
  3479. (ispell-command-loop possibilities nil word start end)))
  3480. (cond
  3481. ((equal 0 replacement) ; BUFFER-LOCAL ADDITION
  3482. (ispell-add-per-file-word-list word))
  3483. (replacement ; REPLACEMENT WORD
  3484. (delete-region start end)
  3485. (setq word (if (atom replacement) replacement (car replacement))
  3486. cursor-location (+ (- (length word) (- end start))
  3487. cursor-location))
  3488. (insert word)
  3489. (if (not (atom replacement)) ; recheck spelling of replacement.
  3490. (progn
  3491. (goto-char cursor-location)
  3492. (ispell-word nil t)))))
  3493. (if (get-buffer ispell-choices-buffer)
  3494. (kill-buffer ispell-choices-buffer))))
  3495. (ispell-pdict-save ispell-silently-savep)
  3496. (goto-char cursor-location)))
  3497. ;;;###autoload
  3498. (defun ispell-complete-word-interior-frag ()
  3499. "Completes word matching character sequence inside a word."
  3500. (interactive)
  3501. (ispell-complete-word t))
  3502. ;;;###autoload
  3503. (defun ispell ()
  3504. "Interactively check a region or buffer for spelling errors.
  3505. If `transient-mark-mode' is on, and a region is active, spell-check
  3506. that region. Otherwise spell-check the buffer.
  3507. Ispell dictionaries are not distributed with Emacs. If you are
  3508. looking for a dictionary, please see the distribution of the GNU ispell
  3509. program, or do an Internet search; there are various dictionaries
  3510. available on the net."
  3511. (interactive)
  3512. (if (and (boundp 'transient-mark-mode) transient-mark-mode
  3513. (boundp 'mark-active) mark-active)
  3514. (ispell-region (region-beginning) (region-end))
  3515. (ispell-buffer)))
  3516. ;;; **********************************************************************
  3517. ;;; Ispell Minor Mode
  3518. ;;; **********************************************************************
  3519. (defvar ispell-minor-keymap
  3520. (let ((map (make-sparse-keymap)))
  3521. (define-key map " " 'ispell-minor-check)
  3522. (define-key map "\r" 'ispell-minor-check)
  3523. map)
  3524. "Keymap used for Ispell minor mode.")
  3525. ;;;###autoload
  3526. (define-minor-mode ispell-minor-mode
  3527. "Toggle last-word spell checking (Ispell minor mode).
  3528. With a prefix argument ARG, enable Ispell minor mode if ARG is
  3529. positive, and disable it otherwise. If called from Lisp, enable
  3530. the mode if ARG is omitted or nil.
  3531. Ispell minor mode is a buffer-local minor mode. When enabled,
  3532. typing SPC or RET warns you if the previous word is incorrectly
  3533. spelled.
  3534. All the buffer-local variables and dictionaries are ignored. To
  3535. read them into the running Ispell process, type \\[ispell-word]
  3536. SPC.
  3537. For spell-checking \"on the fly\", not just after typing SPC or
  3538. RET, use `flyspell-mode'."
  3539. nil " Spell" ispell-minor-keymap)
  3540. (defun ispell-minor-check ()
  3541. "Check previous word, then continue with the normal binding of this key.
  3542. Don't check previous word when character before point is a space or newline.
  3543. Don't read buffer-local settings or word lists."
  3544. (interactive "*")
  3545. (let ((ispell-minor-mode nil)
  3546. (ispell-check-only t)
  3547. (last-char (char-after (1- (point)))))
  3548. (command-execute (key-binding (this-command-keys)))
  3549. (if (not (or (eq last-char ?\ ) (eq last-char ?\n)
  3550. (and ispell-skip-html (eq last-char ?>))
  3551. (and ispell-skip-html (eq last-char ?\;))))
  3552. (ispell-word nil t))))
  3553. ;;; **********************************************************************
  3554. ;;; Ispell Message
  3555. ;;; **********************************************************************
  3556. (defvar ispell-message-text-end
  3557. (mapconcat (function identity)
  3558. '(
  3559. ;; Don't spell check signatures
  3560. "^-- $"
  3561. ;; Matches PostScript files.
  3562. ;;"^%!PS-Adobe-[123].0"
  3563. ;; Matches uuencoded text
  3564. ;;"^begin [0-9][0-9][0-9] .*\nM.*\nM.*\nM"
  3565. ;; Matches shell files (especially auto-decoding)
  3566. "^#! /bin/[ck]?sh"
  3567. ;; Matches context difference listing
  3568. "\\(\\(^cd .*\n\\)?diff -c .*\\)?\n\\*\\*\\* .*\n--- .*\n\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*"
  3569. ;; Matches unidiff difference listing
  3570. "\\(diff -u .*\\)?\n--- .*\n\\+\\+\\+ .*\n@@ [-+][0-9]+,[0-9]+ [-+][0-9]+,[0-9]+ @@"
  3571. ;; Matches reporter.el bug report
  3572. "^current state:\n==============\n"
  3573. ;; Matches commonly used "cut" boundaries
  3574. "^\\(- \\)?[-=_]+\\s ?\\(cut here\\|Environment Follows\\)")
  3575. "\\|")
  3576. "Text beyond which `ispell-message' will not spell-check.
  3577. If it is a string, limit is the first occurrence of that regular expression.
  3578. Otherwise, it must be a function which is called to get the limit.")
  3579. (put 'ispell-message-text-end 'risky-local-variable t)
  3580. (defun ispell-mime-multipartp (&optional limit)
  3581. "Return multipart message start boundary or nil if none."
  3582. ;; caller must ensure `case-fold-search' is set to t
  3583. (and
  3584. (re-search-forward
  3585. "Content-Type: *multipart/\\([^ \t\n]*;[ \t]*[\n]?[ \t]*\\)+boundary="
  3586. limit t)
  3587. (let (boundary)
  3588. (if (looking-at "\"")
  3589. (let (start)
  3590. (forward-char)
  3591. (setq start (point))
  3592. (while (not (looking-at "\""))
  3593. (forward-char 1))
  3594. (setq boundary (buffer-substring-no-properties start (point))))
  3595. (let ((start (point)))
  3596. (while (looking-at "[-0-9a-zA-Z'()+_,./:=?]")
  3597. (forward-char))
  3598. (setq boundary (buffer-substring-no-properties start (point)))))
  3599. (if (< (length boundary) 1)
  3600. (setq boundary nil)
  3601. (concat "--" boundary)))))
  3602. (defun ispell-mime-skip-part (boundary)
  3603. "Move point across header, or entire MIME part if message is encoded.
  3604. All specified types except `7bit' `8bit' and `quoted-printable' are considered
  3605. encoded and therefore skipped. See rfc 1521, 2183, ...
  3606. If no boundary is given, then entire message is skipped.
  3607. This starts one line ABOVE the MIME content messages, on the boundary marker,
  3608. for operation with the generic region-skipping code.
  3609. This places new MIME boundaries into variable `ispell-checking-message'."
  3610. (forward-line) ; skip over boundary to headers
  3611. (let ((save-case-fold-search case-fold-search)
  3612. (continuep t)
  3613. textp)
  3614. (setq case-fold-search t
  3615. ispell-skip-html nil)
  3616. (while continuep
  3617. (setq continuep nil)
  3618. (if (looking-at "Content-Type: *text/")
  3619. (progn
  3620. (goto-char (match-end 0))
  3621. (if (looking-at "html")
  3622. (setq ispell-skip-html t))
  3623. (setq textp t
  3624. continuep t)
  3625. (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
  3626. (forward-line)))
  3627. (if (looking-at "Content-Transfer-Encoding: *\\([^ \t\n]*\\)")
  3628. (let ((match (buffer-substring (match-beginning 1) (match-end 1))))
  3629. (setq textp (member (upcase match)
  3630. ;; only spell check the following encodings:
  3631. '("7BIT" "8BIT" "QUOTED-PRINTABLE" "BINARY"))
  3632. continuep t)
  3633. (goto-char (match-end 0))
  3634. (re-search-forward "\\(.*;[ \t]*[\n]\\)*.*$" nil t)
  3635. (forward-line)))
  3636. ;; hierarchical boundary definition
  3637. (if (looking-at "Content-Type: *multipart/")
  3638. (let ((new-boundary (ispell-mime-multipartp)))
  3639. (if (string-match new-boundary boundary)
  3640. (setq continuep t)
  3641. ;; first pass redefine skip function to include new boundary
  3642. ;;(re-search-backward boundary nil t)
  3643. (forward-line)
  3644. (setq ispell-checking-message
  3645. (cons
  3646. (list new-boundary 'ispell-mime-skip-part new-boundary)
  3647. (if (eq t ispell-checking-message) nil
  3648. ispell-checking-message))
  3649. textp t
  3650. continuep t)))
  3651. ;; Skip all MIME headers that don't affect spelling
  3652. (if (looking-at "Content-[^ \t]*: *\\(.*;[ \t]*[\n]\\)*.*$")
  3653. (progn
  3654. (setq continuep t)
  3655. (goto-char (match-end 0))
  3656. (forward-line)))))
  3657. (setq case-fold-search save-case-fold-search)
  3658. (if textp
  3659. (point)
  3660. ;; encoded message. Skip to boundary, or entire message.
  3661. (if (not boundary)
  3662. (goto-char (point-max))
  3663. (re-search-forward boundary nil t)
  3664. (beginning-of-line)
  3665. (point)))))
  3666. ;;;###autoload
  3667. (defun ispell-message ()
  3668. "Check the spelling of a mail message or news post.
  3669. Don't check spelling of message headers except the Subject field.
  3670. Don't check included messages.
  3671. To abort spell checking of a message region and send the message anyway,
  3672. use the `x' command. (Any subsequent regions will be checked.)
  3673. The `X' command aborts sending the message so that you can edit the buffer.
  3674. To spell-check whenever a message is sent, include the appropriate lines
  3675. in your init file:
  3676. (add-hook \\='message-send-hook \\='ispell-message) ;; GNUS 5
  3677. (add-hook \\='news-inews-hook \\='ispell-message) ;; GNUS 4
  3678. (add-hook \\='mail-send-hook \\='ispell-message)
  3679. (add-hook \\='mh-before-send-letter-hook \\='ispell-message)
  3680. You can bind this to the key C-c i in GNUS or mail by adding to
  3681. `news-reply-mode-hook' or `mail-mode-hook' the following lambda expression:
  3682. (function (lambda () (local-set-key \"\\C-ci\" \\='ispell-message)))"
  3683. (interactive)
  3684. (save-excursion
  3685. (goto-char (point-min))
  3686. (let* (boundary mimep
  3687. (ispell-skip-region-alist-save ispell-skip-region-alist)
  3688. ;; Nil when message came from outside (eg calling Emacs as editor)
  3689. ;; Non-nil marker of end of headers.
  3690. (internal-messagep
  3691. (re-search-forward
  3692. (concat "^" (regexp-quote mail-header-separator) "$") nil t))
  3693. (end-of-headers ; Start of body.
  3694. (copy-marker
  3695. (or internal-messagep
  3696. (re-search-forward "^$" nil t)
  3697. (point-min))))
  3698. (limit (copy-marker ; End of region we will spell check.
  3699. (cond
  3700. ((not ispell-message-text-end) (point-max))
  3701. ((char-or-string-p ispell-message-text-end)
  3702. (if (re-search-forward ispell-message-text-end nil t)
  3703. (match-beginning 0)
  3704. (point-max)))
  3705. (t (min (point-max) (funcall ispell-message-text-end))))))
  3706. (default-prefix ; Vanilla cite prefix (just used for cite-regexp)
  3707. (if (and (boundp 'mail-yank-prefix) mail-yank-prefix)
  3708. (ispell-non-empty-string mail-yank-prefix)
  3709. " \\|\t"))
  3710. (cite-regexp ;Prefix of quoted text
  3711. (cond
  3712. ((functionp 'sc-cite-regexp) ; sc 3.0
  3713. (ispell-with-no-warnings
  3714. (concat "\\(" (sc-cite-regexp) "\\)" "\\|"
  3715. (ispell-non-empty-string sc-reference-tag-string))))
  3716. ((boundp 'sc-cite-regexp) ; sc 2.3
  3717. (concat "\\(" sc-cite-regexp "\\)" "\\|"
  3718. (ispell-with-no-warnings
  3719. (ispell-non-empty-string sc-reference-tag-string))))
  3720. ((or (equal major-mode 'news-reply-mode) ;GNUS 4 & below
  3721. (equal major-mode 'message-mode)) ;GNUS 5
  3722. (concat "In article <" "\\|"
  3723. "[^,;&+=\n]+ <[^,;&+=]+> writes:" "\\|"
  3724. (ispell-with-no-warnings message-cite-prefix-regexp)
  3725. "\\|"
  3726. default-prefix))
  3727. ((equal major-mode 'mh-letter-mode) ; mh mail message
  3728. (concat "[^,;&+=\n]+ writes:" "\\|"
  3729. (ispell-with-no-warnings
  3730. (ispell-non-empty-string mh-ins-buf-prefix))))
  3731. ((not internal-messagep) ; Assume nn sent us this message.
  3732. (concat "In [a-zA-Z.]+ you write:" "\\|"
  3733. "In <[^,;&+=]+> [^,;&+=]+ writes:" "\\|"
  3734. " *> *"))
  3735. ((boundp 'vm-included-text-prefix) ; VM mail message
  3736. (concat "[^,;&+=\n]+ writes:" "\\|"
  3737. (ispell-non-empty-string vm-included-text-prefix)))
  3738. (t default-prefix)))
  3739. (ispell-skip-region-alist
  3740. (cons (list (concat "^\\(" cite-regexp "\\)")
  3741. (function forward-line))
  3742. ispell-skip-region-alist))
  3743. (old-case-fold-search case-fold-search)
  3744. (dictionary-alist ispell-message-dictionary-alist)
  3745. (ispell-checking-message t))
  3746. ;; Select dictionary for message
  3747. (or (local-variable-p 'ispell-local-dictionary (current-buffer))
  3748. (while dictionary-alist
  3749. (goto-char (point-min))
  3750. (if (re-search-forward (car (car dictionary-alist))
  3751. end-of-headers t)
  3752. (setq ispell-local-dictionary (cdr (car dictionary-alist))
  3753. dictionary-alist nil)
  3754. (setq dictionary-alist (cdr dictionary-alist)))))
  3755. (unwind-protect
  3756. (progn
  3757. ;; Spell check any original Subject:
  3758. (goto-char (point-min))
  3759. (setq case-fold-search t
  3760. mimep (re-search-forward "MIME-Version:" end-of-headers t))
  3761. (goto-char (point-min))
  3762. (if (re-search-forward "^Subject: *" end-of-headers t)
  3763. (progn
  3764. (goto-char (match-end 0))
  3765. (if (and (not (looking-at ".*Re\\>"))
  3766. (not (looking-at "\\[")))
  3767. (progn
  3768. (setq case-fold-search old-case-fold-search)
  3769. (ispell-region (point)
  3770. (progn ;Tab-initiated continuation lns.
  3771. (end-of-line)
  3772. (while (looking-at "\n[ \t]")
  3773. (end-of-line 2))
  3774. (point)))))))
  3775. (if mimep
  3776. (progn
  3777. (goto-char (point-min))
  3778. (setq boundary (ispell-mime-multipartp end-of-headers))))
  3779. ;; Adjust message limit to MIME message if necessary.
  3780. (and boundary
  3781. (re-search-forward (concat boundary "--") nil t)
  3782. (re-search-backward boundary nil t)
  3783. (< (point) (marker-position limit))
  3784. (set-marker limit (point)))
  3785. (goto-char (point-min))
  3786. ;; Select type or skip checking if this is a non-multipart message
  3787. ;; Point moved to end of buffer if region is encoded.
  3788. (when (and mimep (not boundary))
  3789. (goto-char (point-min))
  3790. (re-search-forward "Content-[^ \t]*:" end-of-headers t)
  3791. (forward-line -1) ; following fn starts one line above
  3792. (ispell-mime-skip-part nil)
  3793. ;; if message-text-end region, limit may be less than point.
  3794. (if (> (point) limit)
  3795. (set-marker limit (point))))
  3796. (goto-char (max end-of-headers (point)))
  3797. (forward-line 1)
  3798. (setq case-fold-search old-case-fold-search)
  3799. ;; Define MIME regions to skip.
  3800. (if boundary
  3801. (setq ispell-checking-message
  3802. (list (list boundary 'ispell-mime-skip-part boundary))))
  3803. (ispell-region (point) limit))
  3804. (set-marker end-of-headers nil)
  3805. (set-marker limit nil)
  3806. (setq ispell-skip-region-alist ispell-skip-region-alist-save
  3807. ispell-skip-html nil
  3808. case-fold-search old-case-fold-search)))))
  3809. (defun ispell-non-empty-string (string)
  3810. (if (or (not string) (string-equal string ""))
  3811. "\\'\\`" ; An unmatchable string if string is null.
  3812. (regexp-quote string)))
  3813. ;;; **********************************************************************
  3814. ;;; Buffer Local Functions
  3815. ;;; **********************************************************************
  3816. (defun ispell-accept-buffer-local-defs ()
  3817. "Load all buffer-local information, restarting Ispell when necessary."
  3818. (ispell-buffer-local-dict) ; May kill ispell-process.
  3819. (ispell-buffer-local-words) ; Will initialize ispell-process.
  3820. (ispell-buffer-local-parsing))
  3821. (defun ispell-buffer-local-parsing ()
  3822. "Place Ispell into parsing mode for this buffer.
  3823. Overrides the default parsing mode.
  3824. Includes LaTeX/Nroff modes and extended character mode."
  3825. ;; (ispell-init-process) must already be called.
  3826. (ispell-send-string "!\n") ; Put process in terse mode.
  3827. ;; We assume all major modes with "tex-mode" in them should use latex parsing
  3828. ;; When exclusively checking comments, set to raw text mode (nroff).
  3829. (if (and (not (eq 'exclusive ispell-check-comments))
  3830. (or (and (eq ispell-parser 'use-mode-name)
  3831. (string-match "[Tt][Ee][Xx]-mode"
  3832. (symbol-name major-mode)))
  3833. (eq ispell-parser 'tex)))
  3834. (progn
  3835. (ispell-send-string "+\n") ; set ispell mode to tex
  3836. (if (not (eq ispell-parser 'tex))
  3837. (set (make-local-variable 'ispell-parser) 'tex)))
  3838. (ispell-send-string "-\n")) ; set mode to normal (nroff)
  3839. ;; If needed, test for SGML & HTML modes and set a buffer local nil/t value.
  3840. (if (and ispell-skip-html (not (eq ispell-skip-html t)))
  3841. (setq ispell-skip-html
  3842. (not (null (string-match "sgml\\|html\\|xml"
  3843. (downcase (symbol-name major-mode)))))))
  3844. ;; Set default extended character mode for given buffer, if any.
  3845. (let ((extended-char-mode (ispell-get-extended-character-mode)))
  3846. (if extended-char-mode
  3847. (ispell-send-string (concat extended-char-mode "\n"))))
  3848. ;; Set buffer-local parsing mode and extended character mode, if specified.
  3849. (save-excursion
  3850. (goto-char (point-max))
  3851. ;; Uses last occurrence of ispell-parsing-keyword
  3852. (if (search-backward ispell-parsing-keyword nil t)
  3853. (let ((end (point-at-eol))
  3854. string)
  3855. (search-forward ispell-parsing-keyword)
  3856. (while (re-search-forward " *\\([^ \"]+\\)" end t)
  3857. ;; space separated definitions.
  3858. (setq string (downcase (match-string-no-properties 1)))
  3859. (cond ((and (string-match "latex-mode" string)
  3860. (not (eq 'exclusive ispell-check-comments)))
  3861. (ispell-send-string "+\n~tex\n"))
  3862. ((string-match "nroff-mode" string)
  3863. (ispell-send-string "-\n~nroff\n"))
  3864. ((string-match "~" string) ; Set extended character mode.
  3865. (ispell-send-string (concat string "\n")))
  3866. (t (message "Invalid Ispell Parsing argument!")
  3867. (sit-for 2))))))))
  3868. ;; Can kill the current ispell process
  3869. (defun ispell-buffer-local-dict (&optional no-reload)
  3870. "Initializes local dictionary and local personal dictionary.
  3871. If optional NO-RELOAD is non-nil, do not reload any dictionary.
  3872. When a dictionary is defined in the buffer (see variable
  3873. `ispell-dictionary-keyword'), it will override the local setting
  3874. from \\[ispell-change-dictionary].
  3875. Both should not be used to define a buffer-local dictionary."
  3876. (save-excursion
  3877. (goto-char (point-min))
  3878. (let (end)
  3879. ;; Override the local variable definition.
  3880. ;; Uses last occurrence of ispell-dictionary-keyword.
  3881. (goto-char (point-max))
  3882. (unless ispell-local-dictionary-overridden
  3883. (if (search-backward ispell-dictionary-keyword nil t)
  3884. (progn
  3885. (search-forward ispell-dictionary-keyword)
  3886. (setq end (point-at-eol))
  3887. (if (re-search-forward " *\\([^ \"]+\\)" end t)
  3888. (setq ispell-local-dictionary
  3889. (match-string-no-properties 1))))))
  3890. (goto-char (point-max))
  3891. (if (search-backward ispell-pdict-keyword nil t)
  3892. (progn
  3893. (search-forward ispell-pdict-keyword)
  3894. (setq end (point-at-eol))
  3895. (if (re-search-forward " *\\([^ \"]+\\)" end t)
  3896. (setq ispell-local-pdict
  3897. (match-string-no-properties 1)))))))
  3898. (unless no-reload
  3899. ;; Reload if new dictionary (maybe the personal one) defined.
  3900. (ispell-internal-change-dictionary)))
  3901. (defun ispell-buffer-local-words ()
  3902. "Load the buffer-local dictionary in the current buffer."
  3903. ;; If there's an existing ispell process that's wrong for this use,
  3904. ;; kill it.
  3905. (if (and ispell-buffer-local-name
  3906. (not (equal ispell-buffer-local-name (buffer-name))))
  3907. (ispell-kill-ispell t))
  3908. ;; Actually start a new ispell process, because we need
  3909. ;; to send commands now to specify the local words to it.
  3910. (ispell-init-process)
  3911. (dolist (session-localword ispell-buffer-session-localwords)
  3912. (ispell-send-string (concat "@" session-localword "\n")))
  3913. (or ispell-buffer-local-name
  3914. (if ispell-buffer-session-localwords
  3915. (setq ispell-buffer-local-name (buffer-name))))
  3916. (save-excursion
  3917. (goto-char (point-min))
  3918. (while (search-forward ispell-words-keyword nil t)
  3919. (or ispell-buffer-local-name
  3920. (setq ispell-buffer-local-name (buffer-name)))
  3921. (let ((end (point-at-eol))
  3922. (ispell-casechars (ispell-get-casechars))
  3923. string)
  3924. ;; buffer-local words separated by a space, and can contain
  3925. ;; any character other than a space. Not rigorous enough.
  3926. (while (re-search-forward " *\\([^ ]+\\)" end t)
  3927. (setq string (match-string-no-properties 1))
  3928. ;; This can fail when string contains a word with invalid chars.
  3929. ;; Error handling needs to be added between ispell and Emacs.
  3930. (if (and (< 1 (length string))
  3931. (equal 0 (string-match ispell-casechars string)))
  3932. (ispell-send-string (concat "@" string "\n"))))))))
  3933. ;; Returns optionally adjusted region-end-point.
  3934. ;; If comment-padright is defined, newcomment must be loaded.
  3935. (declare-function comment-add "newcomment" (arg))
  3936. (defun ispell-add-per-file-word-list (word)
  3937. "Add WORD to the per-file word list."
  3938. (or ispell-buffer-local-name
  3939. (setq ispell-buffer-local-name (buffer-name)))
  3940. (save-excursion
  3941. (goto-char (point-min))
  3942. (let (line-okay search done found)
  3943. (while (not done)
  3944. (let ((case-fold-search nil))
  3945. (setq search (search-forward ispell-words-keyword nil 'move)
  3946. found (or found search)
  3947. line-okay (< (+ (length word) 1 ; 1 for space after word..
  3948. (progn (end-of-line) (current-column)))
  3949. fill-column)))
  3950. (if (or (and search line-okay)
  3951. (null search))
  3952. (progn
  3953. (setq done t)
  3954. (if (null search)
  3955. (progn
  3956. (open-line 1)
  3957. (unless found (newline))
  3958. (insert (if comment-start
  3959. (concat
  3960. (if (fboundp 'comment-padright)
  3961. ;; Try and use the proper comment marker,
  3962. ;; e.g. ";;" rather than ";".
  3963. (progn
  3964. ;; XEmacs: comment-normalize-vars
  3965. ;; (newcomment.el) only in >= 21.5
  3966. (and (fboundp 'comment-normalize-vars)
  3967. (comment-normalize-vars))
  3968. (comment-padright comment-start
  3969. (comment-add nil)))
  3970. comment-start)
  3971. " ")
  3972. "")
  3973. ispell-words-keyword)
  3974. (if (and comment-end (> (length comment-end) 0))
  3975. (save-excursion
  3976. (newline)
  3977. (insert comment-end)))))
  3978. (insert (concat " " word))))))))
  3979. (add-to-list 'debug-ignored-errors "^No word found to check!$")
  3980. (provide 'ispell)
  3981. ;;; LOCAL VARIABLES AND BUFFER-LOCAL VALUE EXAMPLES.
  3982. ;; Local Variable options:
  3983. ;; mode: name(-mode)
  3984. ;; eval: expression
  3985. ;; local-variable: value
  3986. ;; The following sets the buffer local dictionary to `american' English
  3987. ;; and spell checks only comments.
  3988. ;; Local Variables:
  3989. ;; mode: emacs-lisp
  3990. ;; comment-column: 40
  3991. ;; ispell-check-comments: exclusive
  3992. ;; ispell-local-dictionary: "american"
  3993. ;; End:
  3994. ;;; MORE EXAMPLES OF ISPELL BUFFER-LOCAL VALUES
  3995. ;; The following places this file in nroff parsing and extended char modes.
  3996. ;; Local IspellParsing: nroff-mode ~nroff
  3997. ;; Change IspellPersDict to IspellPersDict: to enable the following line.
  3998. ;; Local IspellPersDict ~/.ispell_lisp
  3999. ;; The following were automatically generated by ispell using the 'A' command:
  4000. ; LocalWords: settable alist inews mh frag pdict Wildcards iconify arg tex kss
  4001. ; LocalWords: alists minibuffer bufferp autoload loaddefs aff Dansk KOI SPC op
  4002. ; LocalWords: Francais Nederlands charset autoloaded popup nonmenu regexp num
  4003. ; LocalWords: AMStex hspace includeonly nocite epsfig displaymath eqnarray reg
  4004. ; LocalWords: minipage pers dict unhighlight buf grep sync prev inc
  4005. ; LocalWords: fn oldot NB AIX msg init read's bufs pt cmd Quinlan eg
  4006. ; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict
  4007. ; LocalWords: lns XEmacs HTML casechars Multibyte
  4008. ;;; ispell.el ends here