172 |
"*List of functions to be called when incorrect words are encountered. |
"*List of functions to be called when incorrect words are encountered. |
173 |
Each function is given three arguments: the beginning and the end |
Each function is given three arguments: the beginning and the end |
174 |
of the incorrect region. The third is either the symbol 'doublon' or the list |
of the incorrect region. The third is either the symbol 'doublon' or the list |
175 |
of possible corrections as returned by 'ispell-parse-output'. |
of possible corrections as returned by `ispell-parse-output'. |
176 |
|
|
177 |
If any of the functions return non-Nil, the word is not highlighted as |
If any of the functions return non-Nil, the word is not highlighted as |
178 |
incorrect." |
incorrect." |
982 |
(setq r p) |
(setq r p) |
983 |
(goto-char p)))) |
(goto-char p)))) |
984 |
r))) |
r))) |
985 |
|
|
986 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
987 |
;* flyspell-word-search-forward ... */ |
;* flyspell-word-search-forward ... */ |
988 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
996 |
(setq r p) |
(setq r p) |
997 |
(goto-char (1+ p))))) |
(goto-char (1+ p))))) |
998 |
r))) |
r))) |
999 |
|
|
1000 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1001 |
;* flyspell-word ... */ |
;* flyspell-word ... */ |
1002 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1026 |
flyspell-mark-duplications-flag |
flyspell-mark-duplications-flag |
1027 |
(save-excursion |
(save-excursion |
1028 |
(goto-char (1- start)) |
(goto-char (1- start)) |
1029 |
(let ((p (flyspell-word-search-backward |
(let ((p (flyspell-word-search-backward |
1030 |
word |
word |
1031 |
(- start (1+ (- end start)))))) |
(- start (1+ (- end start)))))) |
1032 |
(and p (/= p (1- start)))))) |
(and p (/= p (1- start)))))) |
1126 |
(flyspell-notify-misspell start end word poss)) |
(flyspell-notify-misspell start end word poss)) |
1127 |
nil)))) |
nil)))) |
1128 |
;; return to original location |
;; return to original location |
1129 |
(goto-char cursor-location) |
(goto-char cursor-location) |
1130 |
(if ispell-quit (setq ispell-quit nil)) |
(if ispell-quit (setq ispell-quit nil)) |
1131 |
res)))))))) |
res)))))))) |
1132 |
|
|
1839 |
(defun flyspell-auto-correct-previous-hook () |
(defun flyspell-auto-correct-previous-hook () |
1840 |
"Hook to track successive calls to `flyspell-auto-correct-previous-word'. |
"Hook to track successive calls to `flyspell-auto-correct-previous-word'. |
1841 |
Sets `flyspell-auto-correct-previous-pos' to nil" |
Sets `flyspell-auto-correct-previous-pos' to nil" |
1842 |
(interactive) |
(interactive) |
1843 |
(remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t) |
(remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t) |
1844 |
(unless (eq this-command (function flyspell-auto-correct-previous-word)) |
(unless (eq this-command (function flyspell-auto-correct-previous-word)) |
1845 |
(setq flyspell-auto-correct-previous-pos nil))) |
(setq flyspell-auto-correct-previous-pos nil))) |
1847 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1848 |
;* flyspell-auto-correct-previous-word ... */ |
;* flyspell-auto-correct-previous-word ... */ |
1849 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1850 |
(defun flyspell-auto-correct-previous-word (position) |
(defun flyspell-auto-correct-previous-word (position) |
1851 |
"*Auto correct the first mispelled word that occurs before point. |
"*Auto correct the first mispelled word that occurs before point. |
1852 |
But don't look beyond what's visible on the screen." |
But don't look beyond what's visible on the screen." |
1853 |
(interactive "d") |
(interactive "d") |
1863 |
(narrow-to-region top bot) |
(narrow-to-region top bot) |
1864 |
(overlay-recenter (point)) |
(overlay-recenter (point)) |
1865 |
|
|
1866 |
(add-hook 'pre-command-hook |
(add-hook 'pre-command-hook |
1867 |
(function flyspell-auto-correct-previous-hook) t t) |
(function flyspell-auto-correct-previous-hook) t t) |
1868 |
|
|
1869 |
(unless flyspell-auto-correct-previous-pos |
(unless flyspell-auto-correct-previous-pos |
1870 |
;; only reset if a new overlay exists |
;; only reset if a new overlay exists |
1871 |
(setq flyspell-auto-correct-previous-pos nil) |
(setq flyspell-auto-correct-previous-pos nil) |
1872 |
|
|
1873 |
(let ((overlay-list (overlays-in (point-min) position)) |
(let ((overlay-list (overlays-in (point-min) position)) |
1874 |
(new-overlay 'dummy-value)) |
(new-overlay 'dummy-value)) |
1875 |
|
|
1876 |
;; search for previous (new) flyspell overlay |
;; search for previous (new) flyspell overlay |
1877 |
(while (and new-overlay |
(while (and new-overlay |
1878 |
(or (not (flyspell-overlay-p new-overlay)) |
(or (not (flyspell-overlay-p new-overlay)) |
1879 |
;; check if its face has changed |
;; check if its face has changed |
1880 |
(not (eq (get-char-property |
(not (eq (get-char-property |
1881 |
(overlay-start new-overlay) 'face) |
(overlay-start new-overlay) 'face) |
1882 |
'flyspell-incorrect)))) |
'flyspell-incorrect)))) |
1883 |
(setq new-overlay (car-safe overlay-list)) |
(setq new-overlay (car-safe overlay-list)) |
1884 |
(setq overlay-list (cdr-safe overlay-list))) |
(setq overlay-list (cdr-safe overlay-list))) |
1885 |
|
|
1886 |
;; if nothing new exits new-overlay should be nil |
;; if nothing new exits new-overlay should be nil |
1887 |
(if new-overlay ;; the length of the word may change so go to the start |
(if new-overlay ;; the length of the word may change so go to the start |
1888 |
(setq flyspell-auto-correct-previous-pos |
(setq flyspell-auto-correct-previous-pos |
1889 |
(overlay-start new-overlay))))) |
(overlay-start new-overlay))))) |
1890 |
|
|
1891 |
(when flyspell-auto-correct-previous-pos |
(when flyspell-auto-correct-previous-pos |
2134 |
and return t. |
and return t. |
2135 |
|
|
2136 |
The third arg POSS is either the symbol 'doublon' or a list of |
The third arg POSS is either the symbol 'doublon' or a list of |
2137 |
possible corrections as returned by 'ispell-parse-output'. |
possible corrections as returned by `ispell-parse-output'. |
2138 |
|
|
2139 |
This function is meant to be added to 'flyspell-incorrect-hook'." |
This function is meant to be added to `flyspell-incorrect-hook'." |
2140 |
(when (consp poss) |
(when (consp poss) |
2141 |
(catch 'done |
(catch 'done |
2142 |
(let ((str (buffer-substring beg end)) |
(let ((str (buffer-substring beg end)) |
2164 |
and return t. |
and return t. |
2165 |
|
|
2166 |
The third arg POSS is either the symbol 'doublon' or a list of |
The third arg POSS is either the symbol 'doublon' or a list of |
2167 |
possible corrections as returned by 'ispell-parse-output'. |
possible corrections as returned by `ispell-parse-output'. |
2168 |
|
|
2169 |
This function is meant to be added to 'flyspell-incorrect-hook'." |
This function is meant to be added to `flyspell-incorrect-hook'." |
2170 |
(when (consp poss) |
(when (consp poss) |
2171 |
(catch 'done |
(catch 'done |
2172 |
(let ((str (buffer-substring beg end)) |
(let ((str (buffer-substring beg end)) |