ispell.el 172 KB

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