ispell.el 161 KB

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