Mercurial > emacs
comparison lisp/textmodes/flyspell.el @ 37008:f4b355161455
Some doc fixes.
(flyspell-maybe-correct-transposition)
(flyspell-maybe-correct-doubling): Use a temporary buffer
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 26 Mar 2001 16:31:20 +0000 |
parents | 2fa95954d8de |
children | b174db545cfd |
comparison
equal
deleted
inserted
replaced
37007:4caced3e865e | 37008:f4b355161455 |
---|---|
45 | 45 |
46 ;*---------------------------------------------------------------------*/ | 46 ;*---------------------------------------------------------------------*/ |
47 ;* Group ... */ | 47 ;* Group ... */ |
48 ;*---------------------------------------------------------------------*/ | 48 ;*---------------------------------------------------------------------*/ |
49 (defgroup flyspell nil | 49 (defgroup flyspell nil |
50 "Spellchecking on the fly." | 50 "Spell checking on the fly." |
51 :tag "FlySpell" | 51 :tag "FlySpell" |
52 :prefix "flyspell-" | 52 :prefix "flyspell-" |
53 :group 'processes) | 53 :group 'processes) |
54 | 54 |
55 ;*---------------------------------------------------------------------*/ | 55 ;*---------------------------------------------------------------------*/ |
146 | 146 |
147 (defcustom flyspell-incorrect-hook nil | 147 (defcustom flyspell-incorrect-hook nil |
148 "*List of functions to be called when incorrect words are encountered. | 148 "*List of functions to be called when incorrect words are encountered. |
149 Each function is given three arguments: the beginning and the end | 149 Each function is given three arguments: the beginning and the end |
150 of the incorrect region. The third is either the symbol 'doublon' or the list | 150 of the incorrect region. The third is either the symbol 'doublon' or the list |
151 of possible corrections returned as returned by 'ispell-parse-output'. | 151 of possible corrections as returned by 'ispell-parse-output'. |
152 | 152 |
153 If any of the functions return non-Nil, the word is not highligted as | 153 If any of the functions return non-Nil, the word is not highlighted as |
154 incorrect." | 154 incorrect." |
155 :group 'flyspell | 155 :group 'flyspell |
156 :version "21.1" | 156 :version "21.1" |
157 :type 'hook) | 157 :type 'hook) |
158 | 158 |
172 :group 'flyspell | 172 :group 'flyspell |
173 :version "21.1" | 173 :version "21.1" |
174 :type 'string) | 174 :type 'string) |
175 | 175 |
176 (defcustom flyspell-check-tex-math-command nil | 176 (defcustom flyspell-check-tex-math-command nil |
177 "*Non nils means check even inside TeX math environement. | 177 "*Non nil means check even inside TeX math environment. |
178 TeX math environments are discovered by the TEXMATHP that implemented | 178 TeX math environments are discovered by the TEXMATHP that implemented |
179 inside the texmathp.el Emacs package. That package may be found at: | 179 inside the texmathp.el Emacs package. That package may be found at: |
180 http://strw.leidenuniv.nl/~dominik/Tools" | 180 http://strw.leidenuniv.nl/~dominik/Tools" |
181 :group 'flyspell | 181 :group 'flyspell |
182 :type 'boolean) | 182 :type 'boolean) |
586 ;* flyspell-delay-command ... */ | 586 ;* flyspell-delay-command ... */ |
587 ;*---------------------------------------------------------------------*/ | 587 ;*---------------------------------------------------------------------*/ |
588 (defun flyspell-delay-command (command) | 588 (defun flyspell-delay-command (command) |
589 "Set COMMAND to be delayed, for Flyspell. | 589 "Set COMMAND to be delayed, for Flyspell. |
590 When flyspell `post-command-hook' is invoked because a delayed command | 590 When flyspell `post-command-hook' is invoked because a delayed command |
591 as been used the current word is not immediatly checked. | 591 as been used the current word is not immediately checked. |
592 It will be checked only after `flyspell-delay' seconds." | 592 It will be checked only after `flyspell-delay' seconds." |
593 (interactive "SDelay Flyspell after Command: ") | 593 (interactive "SDelay Flyspell after Command: ") |
594 (put command 'flyspell-delayed t)) | 594 (put command 'flyspell-delayed t)) |
595 | 595 |
596 ;*---------------------------------------------------------------------*/ | 596 ;*---------------------------------------------------------------------*/ |
1173 (defun flyspell-get-word (following) | 1173 (defun flyspell-get-word (following) |
1174 "Return the word for spell-checking according to Ispell syntax. | 1174 "Return the word for spell-checking according to Ispell syntax. |
1175 If argument FOLLOWING is non-nil or if `ispell-following-word' | 1175 If argument FOLLOWING is non-nil or if `ispell-following-word' |
1176 is non-nil when called interactively, then the following word | 1176 is non-nil when called interactively, then the following word |
1177 \(rather than preceding\) is checked when the cursor is not over a word. | 1177 \(rather than preceding\) is checked when the cursor is not over a word. |
1178 Optional second argument contains otherchars that can be included in word | 1178 Optional second argument contains other chars that can be included in word |
1179 many times. | 1179 many times. |
1180 | 1180 |
1181 Word syntax described by `ispell-dictionary-alist' (which see)." | 1181 Word syntax described by `ispell-dictionary-alist' (which see)." |
1182 (let* ((flyspell-casechars (flyspell-get-casechars)) | 1182 (let* ((flyspell-casechars (flyspell-get-casechars)) |
1183 (flyspell-not-casechars (flyspell-get-not-casechars)) | 1183 (flyspell-not-casechars (flyspell-get-not-casechars)) |
1312 (setq flyspell-large-region-buffer curbuf) | 1312 (setq flyspell-large-region-buffer curbuf) |
1313 (setq flyspell-large-region-beg beg) | 1313 (setq flyspell-large-region-beg beg) |
1314 (setq flyspell-large-region-end end) | 1314 (setq flyspell-large-region-end end) |
1315 (set-buffer buffer) | 1315 (set-buffer buffer) |
1316 (erase-buffer) | 1316 (erase-buffer) |
1317 ;; this is done, we can start ckecking... | 1317 ;; this is done, we can start checking... |
1318 (message "Checking region...") | 1318 (message "Checking region...") |
1319 (set-buffer curbuf) | 1319 (set-buffer curbuf) |
1320 (let ((c (apply 'call-process-region beg | 1320 (let ((c (apply 'call-process-region beg |
1321 end | 1321 end |
1322 ispell-program-name | 1322 ispell-program-name |
1418 (if (flyspell-overlay-p (car ovs)) | 1418 (if (flyspell-overlay-p (car ovs)) |
1419 (setq r t) | 1419 (setq r t) |
1420 (setq ovs (cdr ovs)))) | 1420 (setq ovs (cdr ovs)))) |
1421 (not r))) | 1421 (not r))) |
1422 (setq pos (1+ pos))) | 1422 (setq pos (1+ pos))) |
1423 ;; save the current location for next invokation | 1423 ;; save the current location for next invocation |
1424 (setq flyspell-old-pos-error pos) | 1424 (setq flyspell-old-pos-error pos) |
1425 (setq flyspell-old-buffer-error (current-buffer)) | 1425 (setq flyspell-old-buffer-error (current-buffer)) |
1426 (goto-char pos) | 1426 (goto-char pos) |
1427 (if (= pos max) | 1427 (if (= pos max) |
1428 (message "No more miss-spelled word!")))) | 1428 (message "No more miss-spelled word!")))) |
1556 | 1556 |
1557 ;*---------------------------------------------------------------------*/ | 1557 ;*---------------------------------------------------------------------*/ |
1558 ;* flyspell-check-previous-highlighted-word ... */ | 1558 ;* flyspell-check-previous-highlighted-word ... */ |
1559 ;*---------------------------------------------------------------------*/ | 1559 ;*---------------------------------------------------------------------*/ |
1560 (defun flyspell-check-previous-highlighted-word (&optional arg) | 1560 (defun flyspell-check-previous-highlighted-word (&optional arg) |
1561 "Correct the closer mispelled word. | 1561 "Correct the closer misspelled word. |
1562 This function scans a mis-spelled word before the cursor. If it finds one | 1562 This function scans a mis-spelled word before the cursor. If it finds one |
1563 it proposes replacement for that word. With prefix arg, count that many | 1563 it proposes replacement for that word. With prefix arg, count that many |
1564 misspelled words backwards." | 1564 misspelled words backwards." |
1565 (interactive) | 1565 (interactive) |
1566 (let ((pos1 (point)) | 1566 (let ((pos1 (point)) |
2016 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary | 2016 (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary |
2017 ispell-dictionary)) | 2017 ispell-dictionary)) |
2018 menu)))) | 2018 menu)))) |
2019 | 2019 |
2020 ;*---------------------------------------------------------------------*/ | 2020 ;*---------------------------------------------------------------------*/ |
2021 ;* Some example functions for real autocrrecting */ | 2021 ;* Some example functions for real autocorrecting */ |
2022 ;*---------------------------------------------------------------------*/ | 2022 ;*---------------------------------------------------------------------*/ |
2023 | |
2023 (defun flyspell-maybe-correct-transposition (beg end poss) | 2024 (defun flyspell-maybe-correct-transposition (beg end poss) |
2024 "Apply 'transpose-chars' to all points in the region BEG to END. | 2025 "Check replacements for transposed characters. |
2025 Return t if any those result in a possible replacement suggested by Ispell | 2026 |
2026 in POSS. Otherwise the change is undone. | 2027 If the text between BEG and END is equal to a correction suggested by |
2027 | 2028 Ispell, after transposing two adjacent characters, correct the text, |
2028 This function is meant to be added to 'flyspell-incorrect-hook'." | 2029 and return t. |
2029 (when (consp poss) | 2030 |
2030 (catch 'done | 2031 The third arg POSS is either the symbol 'doublon' or a list of |
2031 (save-excursion | 2032 possible corrections as returned by 'ispell-parse-output'. |
2032 (goto-char (1+ beg)) | |
2033 (while (< (point) end) | |
2034 (transpose-chars 1) | |
2035 (when (member (buffer-substring beg end) (nth 2 poss)) | |
2036 (throw 'done t)) | |
2037 (transpose-chars -1) | |
2038 (forward-char)) | |
2039 nil)))) | |
2040 | |
2041 (defun flyspell-maybe-correct-doubling (beg end poss) | |
2042 "For each doubled charachter in the region BEG to END, remove one. | |
2043 Return t if any those result in a possible replacement suggested by | |
2044 Ispell in POSS. Otherwise the change is undone. | |
2045 | 2033 |
2046 This function is meant to be added to 'flyspell-incorrect-hook'." | 2034 This function is meant to be added to 'flyspell-incorrect-hook'." |
2047 (when (consp poss) | 2035 (when (consp poss) |
2048 (catch 'done | 2036 (let ((temp-buffer (get-buffer-create " *flyspell-temp*")) |
2037 found) | |
2038 (save-excursion | |
2039 (copy-to-buffer temp-buffer beg end) | |
2040 (set-buffer temp-buffer) | |
2041 (goto-char (1+ (point-min))) | |
2042 (while (and (not (eobp)) (not found)) | |
2043 (transpose-chars 1) | |
2044 (if (member (buffer-string) (nth 2 poss)) | |
2045 (setq found (point)) | |
2046 (transpose-chars -1) | |
2047 (forward-char)))) | |
2048 (when found | |
2049 (save-excursion | 2049 (save-excursion |
2050 (let ((last (char-after beg)) | 2050 (goto-char (+ beg found -1)) |
2051 this) | 2051 (transpose-chars -1) |
2052 (goto-char (1+ beg)) | 2052 t))))) |
2053 (while (< (point) end) | 2053 |
2054 (setq this (char-after)) | 2054 (defun flyspell-maybe-correct-doubling (beg end poss) |
2055 (if (not (char-equal this last)) | 2055 "Check replacements for doubled characters. |
2056 (forward-char) | 2056 |
2057 (delete-char 1) | 2057 If the text between BEG and END is equal to a correction suggested by |
2058 (when (member (buffer-substring beg (1- end)) (nth 2 poss)) | 2058 Ispell, after removing a pair of doubled characters, correct the text, |
2059 (throw 'done t)) | 2059 and return t. |
2060 ;; undo | 2060 |
2061 (insert-char this 1)) | 2061 The third arg POSS is either the symbol 'doublon' or a list of |
2062 (setq last this)) | 2062 possible corrections as returned by 'ispell-parse-output'. |
2063 nil))))) | 2063 |
2064 This function is meant to be added to 'flyspell-incorrect-hook'." | |
2065 (when (consp poss) | |
2066 (let ((temp-buffer (get-buffer-create " *flyspell-temp*")) | |
2067 found) | |
2068 (save-excursion | |
2069 (copy-to-buffer temp-buffer beg end) | |
2070 (set-buffer temp-buffer) | |
2071 (goto-char (1+ (point-min))) | |
2072 (while (and (not (eobp)) (not found)) | |
2073 (when (char-equal (char-after) (char-before)) | |
2074 (delete-char 1) | |
2075 (if (member (buffer-string) (nth 2 poss)) | |
2076 (setq found (point)) | |
2077 (insert-char (char-before) 1))) | |
2078 (forward-char))) | |
2079 (when found | |
2080 (save-excursion | |
2081 (goto-char (+ beg found -1)) | |
2082 (delete-char 1) | |
2083 t))))) | |
2064 | 2084 |
2065 ;*---------------------------------------------------------------------*/ | 2085 ;*---------------------------------------------------------------------*/ |
2066 ;* flyspell-already-abbrevp ... */ | 2086 ;* flyspell-already-abbrevp ... */ |
2067 ;*---------------------------------------------------------------------*/ | 2087 ;*---------------------------------------------------------------------*/ |
2068 (defun flyspell-already-abbrevp (table word) | 2088 (defun flyspell-already-abbrevp (table word) |