(require (quote TeX-mode)) (defconst tex-spell-dict-buff "--- TeX Dictionary ---") (defconst tex-spell-help-buff "--- TeX Spelling Help ---") (defconst tex-spell-error-buff "--- TeX Spelling Errors ---") (defconst tex-spell-hsl-suffix ".hsl" "\ Default filename extension for hashed spelling list.") (defconst tex-spell-usl-suffix ".usl" "\ Default filename extension for unhashed spelling list.") (defun tex-spell-document (&optional prefix) "\ Check spelling of every file included in current document. With prefix argument, check spelling using a customized hashed spelling list, if any, without query. A customized hashed spelling list is either current document master filename base concatenated with \".hsl\", or the file bound to the variable tex-hsl-default." (interactive "P") (byte-code "Ĉ  ͍\".)" [doc-type lst tex-include-files asknot nil =slok= msg fn fnnd tex-visit-master-file tex-check-document-type tex-get-include-files finish (byte-code "H@!q Q ! \"A\" . P!C ! #!!)" [lst fn msg doc-type fnnd asknot prefix find-file-noselect "Checking " " spelling for entire document" file-name-nondirectory append tex-get-input-files tex-confirm "Check spelling for " find-file message "%s, doing %s..." sit-for 1 tex-spell-buffer] 11) message "%s...done"] 9)) (defun tex-spell-buffer (&optional prefix) "\ Check spelling of every word in the buffer. With prefix argument, check spelling using a customized hashed spelling list, if any, without query. A customized hashed spelling list is either current document master filename base concatenated with \".hsl\", or the file bound to the variable tex-hsl-default." (interactive "P") (byte-code "d $" [prefix nil tex-spell-region 1 buffer-name] 6)) (defun tex-spell-paragraph (&optional prefix) "\ Check spelling of every word in the current paragraph. With prefix argument, check spelling using a customized hashed spelling list, if any, without query. A customized hashed spelling list is either current document master filename base concatenated with \".hsl\", or the file bound to the variable tex-hsl-default." (interactive "P") (byte-code " `) `)$" [prefix nil tex-spell-region backward-paragraph forward-paragraph "paragraph"] 7)) (defun tex-spell-region (&optional prefix start end &optional description) "\ Like tex-buffer-spell but applies only to region. From program, applies from START to END. With prefix argument, check spelling using a customized hashed spelling list, if any, without query. A customized hashed spelling list is either current document master filename base concatenated with \".hsl\", or the file bound to the variable tex-hsl-default." (interactive "P r") (byte-code "Ȉ \" \"  !\"8 \"O!/Ȃ3 \"ދ-" [sm start em end doc-type filter-string tex-formatter-specs filter-file nil =err= tex-spell-error-buff =cmd= =buff= =fn= =msgs= description =again= speller set-marker make-marker tex-check-document-type 6 assoc downcase 0 string-match " " file-exists-p error "Spelling filter \"%s\" does not exist" ((byte-code " !!p R ҍ! !." [=err= tex-spell-error-buff =cmd= =buff= =fn= =msgs= doc-type description =again= nil speller get-buffer-create "*Shell Command Output*" buffer-file-name "Checking " " spelling for " "region" all-done (byte-code " ! !Ɖq ) ! SfUV   &qd &)  q #cd  &d &)) !" [t start sm end em tex-spell-small-window nil =err= speller prefix shell-file-name filter-string filter =buff= marker-position widen erase-buffer tex-spell-get-speller 10 call-process-region "-c" 1 insert-buffer-substring tex-spell-examine] 19) kill-buffer] 11))] 12)) (defun tex-spell-examine (prefix) (byte-code "      qb V)L !!҉q U pmp \"kp!҆ ? \"?)q` `)\") 6P!\"\"\"\"." [case-fold-search t case-replace down first master word msgs reg-word new-word selected-word cmd next-cmd last-pos old-pos =err= tex-spell-small-window tex-slow-win-lines nil =msgs= =again= tex-check-master-file 1 buffer-size 0 delete-window other-window -1 enlarge-window tex-spell-exit "next" previous-line "previous" buffer-substring end-of-line tex-spell-get-cmd y-or-n-p ", try again? " message "%s...done" throw all-done "%s...done (no errors found)"] 19)) (defun tex-spell-get-cmd nil (byte-code " Q !Q bƉȉ΍" [msgs word reg-word last-pos start next-cmd t selected-word nil "Erroneous `" "' [SPC DEL n p r R w C-r ?=help]" "\\b" regexp-quote get-cmd (byte-code "  !r U3 q!Ɖ)\" UX qoGJ!Ɖ)\" U` b  \"|` !bb!! b  \"` !b U  #!b` )!! b  #!b` ) UQ\" ) UQ\" ) U! U!!`!  !=!!`)!c`!`\"c!Ɖ !r! * ) U \"!" [t next-cmd msgs cmd =err= first nil down old-pos last-pos reg-word end start new-word word selected-word win tex-spell-dict-buff pos left =buff= message 32 next-line 1 throw get-cmd 127 previous-line 110 tex-spell-search match-beginning 0 "Wrapping around..." sit-for 112 match-end 114 read-string "Replacing `" "' by: " abort (byte-code " & q`!`\"oĉ)\"" [end reg-word word new-word t =err= down tex-spell-replace abort delete-region next-line 1 throw get-cmd] 7) 82 (byte-code " & q`!`\"oĉ)\"" [end reg-word word new-word t =err= down tex-spell-replace abort delete-region next-line 1 throw get-cmd] 7) 119 (byte-code "\"" [word tex-spell-word abort] 3) 18 "Entering recursive edit...(return to spelling checking by ESC C-c)" get-buffer-window pop-to-buffer recursive-edit buffer-name forward-word backward-word 91 buffer-substring 93 delete-window 63 ((byte-code "  !r" [next-cmd nil msgs cmd tex-spell-help message] 4)) ding "%s...WHAT?"] 40)] 4)) (defun tex-spell-help nil (byte-code "! V! Z!b!" [tex-spell-help-buff nil pop-to-buffer buffer-size 0 insert-string "SPC -- Ignore current erroneous word, try next error, if any. DEL -- Ignore current erroneous word and try the previous, if any. n -- Go to next instance of the word in buffer, wrap around if necessary. p -- Go to previous instance of the word in buffer, wrap around if necessary. r -- Replace all instances of the word below dot. A repetition of current erroneous word appears at replacement prompt. R -- Replace all instances of the word below dot. If a word is selected in --- TeX Dictionary ---, it is repeated at prompt; otherwise nothing is repeated. w -- Dictionary lookup for words containing the specified substring. Result displayed in the other window called --- TeX Dictionary ---. C-r -- Enter recursive edit. Return to spelling checking by ESC C-c. ? -- This help message. C-g -- Abort to top level." enlarge-window 15 window-height 1 other-window] 7)) (defun tex-spell-exit (master scroll) (byte-code "! Qʍ+" [=gbl= msg scroll cmd get-buffer-create "--- TeX Global Spelling List ---" "No more " " entry, exit? [SPC=(y)es DEL=(n)o RET=(s)ave]" nil done (byte-code "\\ !r U U\"X U( U2\"X U; UI !\"XÉ \"!" [t msg cmd nil master message 32 121 throw done 127 110 13 115 tex-spell-save-hsl ding "%s...WHAT?" sit-for 1] 10)] 5)) (defun tex-spell-check-hsl (fn fnnd msgs) (byte-code " # q P& U%łI \"r\"P!\"!\")" [msgs fnnd =cmd= shell-file-name nil t fn message "%s, verifying spelling list %s..." erase-buffer call-process "-c" "echo \"am\" | spellout " buffer-size 0 "Spelling list is corrupted, type any key to continue" "Removing corrupted spelling list %s..." shell-command "\\rm -f" "Removing corrupted spelling list %s...done" sit-for 1 "%s..."] 12)) (defun tex-spell-get-speller (prefix) "\ Make a hashed spelling list." (byte-code "  \" ! \" !! e* e !G G !!G e \"e \\ Q!e  #qΉ Ή  !# Q, !!! Q!Ή Ή  $!  && # Q, \"!*Q,." [master-file hl tex-spell-hsl-suffix hlnd ul tex-spell-usl-suffix ulnd slokp default =again= =slok= tex-hsl-default prefix =msgs= t tex-speller tex-usl-default shell-file-name nil =cmd= tex-spellout tex-hsl-global tex-spellin tex-check-master-file tex-spell-ext file-name-nondirectory boundp "" file-exists-p expand-file-name file-newer-than-file-p y-or-n-p "Use " " as hashed spelling list? " tex-spell-check-hsl message "%s, using %s as spelling list..." " -d " " as unhashed spelling list? " "%s, creating %s from %s..." call-process "-cf" concat "cat " " " "|" ">" "%s..."] 41)) (defun tex-spell-ext (fn suffix) (byte-code " ! !\"  V%  O Q( P+" [fnnd fn dir pos suffix file-name-nondirectory file-name-directory string-match "\\." 0 ""] 7)) (defun tex-spell-check-words nil (byte-code "qb V)\" q )̍*.!!\"" [=err= msgs chr =gbl= t 1 buffer-size 0 "Save words in spelling list. [RET=(g)lobal SPC=(l)ocal DEL=(e)xamine]" nil erase-buffer right (byte-code "e !r U U\" \"a U+ U5\"a U> UV q d# )\"a \"!" [t msgs chr =err= =gbl= message 127 101 tex-spell-process-uw throw right 32 108 13 103 copy-to-buffer 1 erase-buffer ding "%s...WHAT?" sit-for] 12) message "No uncorrected words left." sit-for throw done] 7)) (defun tex-spell-process-uw nil (byte-code " qbȍ)," [word msgs cmd next-cmd =err= nil 1 checked (byte-code " V< m!\"!` `)\" \"5! q U)U!!\"" [t word =gbl= buffer-size 0 beginning-of-line y-or-n-p "No more next word, done? " throw checked previous-line 1 buffer-substring end-of-line string-equal "" kill-line tex-spell-cw-cmd message "No uncorrected words left." sit-for done] 16)] 4)) (defun tex-spell-cw-cmd nil (byte-code " Pč" [msgs word "? [SPC=(n)ext DEL=(p)rev RET=(g)lobal LFD=(r)emove ESC=(d)one]" get-cmd (byte-code " !r U U\"! U+ UEo?!<\"B! UN Ug!m\\! q ) Up U!m~! U U\"ʼn \"! \"" [t msgs next-cmd cmd =gbl= nil message 32 110 next-line 1 127 112 y-or-n-p "No more previous word, done? " throw checked previous-line 13 103 kill-line yank 10 114 27 100 ding "%s...WHAT?" sit-for get-cmd] 18)] 2)) (defun tex-spell-save-hsl (master) (byte-code " q V) " [=gbl= tex-spell-check-words buffer-size 0 tex-spell-save-global tex-spell-save-local] 5)) (defun tex-spell-save-global nil (byte-code "f! P P q!L\"d %  & &\"!a\"d%\"!)+p !!" [tex-usl-default ulnd tmp tmp= =gbl= nil shell-file-name =cmd= file-name-nondirectory "/tmp/" "=" file-exists-p message "Extending default unhashed spelling list %s..." write-region 1 no-message call-process "-c" concat "cat " " " " | sort -u > " "; rm " "; mv " "Extending default unhashed spelling list %s...done" sit-for "Creating default unhashed spelling list %s..." "Creating default unhashed spelling list %s...done" ding "Default unhashed spelling list `tex-usl-default' not set."] 23)) (defun tex-spell-save-local nil (byte-code " \"!! \" ! !P  P  \" = = # {\"d %    & &\" V\"d %\"  \"d &&!Չ \"!& \"! &&!Չ \"!. " [hl master tex-spell-hsl-suffix hlnd hl-p ul tex-spell-usl-suffix ulnd ul-p tmp tmp= newer hl-g =again= default nil shell-file-name =cmd= tex-spellout tex-spellin =slok= t tex-usl-default tex-hsl-global tex-spell-ext file-name-nondirectory file-exists-p "/tmp/" "=" file-newer-than-file-p tex-spell-check-hsl "Saving spelling list" "" message "Extending unhashed spelling list %s..." write-region 1 no-message call-process "-c" concat "cat " " " " | sort -u > " "; rm " "; mv " " ." "Extending unhashed spelling list %s...done" buffer-size 0 "Creating unhashed spelling list %s..." "Creating unhashed spelling list %s...done" "Extending hashed spelling list %s..." call-process-region "cat |" "|" ">" "; mv /tmp/" boundp "Extending hashed spelling list %s...done" sit-for "Creating hashed spelling list %s..." "Creating hashed spelling list %s...done"] 46)) (defun tex-spell-word (&optional pre &optional abort) "\ Check the spelling of a word. If PRE is non-nil, use it as default. If pre is a non-string and is set by prefix argument, then use the preceding word as default." (interactive "P") (byte-code "ňp !     ׍1;?K!` ! `\") Q\"\"{u !\"x! &   Q ! q &% U  \"!Abm? i\\]! \"bm?4ىWm?, ! \"TjT!b ! \"!. " [old tmp tex-spell-dict-buff offset dict nil key m i fix prefix suffix msg bow pre abort tex-dictionary tex-egrep t tex-look get-buffer-create 0 loop (byte-code "s!r U U+ɉɉʉ\"o UHɉɉΉ\"o UeЉщ҉\"o !!" [t fix prefix suffix dict message "Lookup string as prefix, infix, or suffix? [RET/p i s]" 13 112 "" "prefix" throw loop 105 "infix" 115 "^.*" "$" "suffix" ding "Lookup string as prefix, infix, or suffix [RET/p i s], WHAT?" sit-for 1] 9) backward-word 1 forward-word buffer-substring read-string "String as " ": " string-equal "" ding message "Don't know how to lookup a null string." throw error concat "Looking up `" "' as " " in \"" "\"..." erase-buffer call-process buffer-size "%sfailed" sit-for end-of-line 5 next-line / window-width delete-char * pop-to-buffer "%sdone"] 31)) (defun tex-spell-replace (cont bound from-regexp from-string to-string query-flag) (byte-code "   !\"? /m?/`! \"f  ?D  #b   ?a  #rUv !!\"]Uʼnlj ]U blj ]U   #lj ]U   #ʼnlj ] ?U  #lj ]U    # ʼn ]Ulj ]U- )!]UN!!\" )!lj ]ʼnlj J*+" [nocasify case-fold-search case-replace from-string literal nil keep-going t from-regexp bound query-flag to-string done replaced char cont unread-command-char string-equal downcase push-mark set-mark tex-spell-search undo-boundary replace-match message "Query replacing `%s' with `%s' (^C if to quit prematurely)..." 3 ding "Quitting query replacing...(return to previous level)" sit-for 1 throw 27 94 mark 32 46 44 33 127 18 store-match-data match-data recursive-edit 23 delete-region match-beginning 0 match-end] 31)) (defvar tex-slow-speed 2400) (defvar tex-slow-win-lines 1) (defvar tex-spell-small-window nil "\ Flag designating small window") (defvar tex-spell-large-window-begin 0) (defvar tex-spell-large-window-end 0) (defun tex-spell-search (regexp bound &optional backward) (byte-code " ΂ X T^ $` ?H! `) ! `) U T ?mʉ ! TZ\"!b  Y Xlj ! !b," [search-fun backward slow-terminal-mode tex-slow-speed window-min-height tex-slow-win-lines found-dot nil regexp bound t tex-spell-small-window tex-spell-large-window-begin tex-spell-large-window-end re-search-backward re-search-forward baud-rate funcall move-to-window-line 0 beginning-of-line -1 end-of-line pos-visible-in-window-p split-window window-height other-window 1 delete-window enlarge-window] 15)) (defun tex-spell-complete nil "\ Complete the current word by doing a dictionary lookup using the word as prefix. Prompt the user if more than one instance is found. When the user confirms a match, it replaces the original prefix." (interactive) (byte-code "! \" !!)!,!`!`) \"!S \" bc)!]! !," [tex-look nil =err= tex-spell-error-buff bow eow word file-exists-p error "Spelling filter \"%s\" does not exist. Rebind tex-look." get-buffer-create looking-at "\\w" forward-word 1 skip-chars-backward "[ ,.!?:;')}]" backward-word tex-spell-match buffer-substring delete-region kill-buffer] 14)) (defun tex-spell-match (key) (byte-code " \"q  %bd\" V8Ӎ@ !)," [asknot nil wd col nol key =err= tex-look t 1 0 message "Completing %s..." widen erase-buffer call-process count-lines buffer-size finish (byte-code "` `)\" &$R - \"O! UK!!bӉO T~ Us!!db !p!{! S " [t wd col nol asknot buffer-substring end-of-line tex-confirm concat "Confirm (" ":" ") `" "'" 110 112 121 throw finish next-line 1 beginning-of-line message "Wrapping around..." sit-for looking-at "^$" previous-line] 17) ding "No match."] 9))