diff options
| author | Lars Ingebrigtsen | 2016-02-29 15:13:30 +1100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2016-02-29 15:13:30 +1100 |
| commit | 04289d1cd863fa8cc0c8a9b976a8e27d9a0b4dd1 (patch) | |
| tree | 6e3588e331c949d0b7fa428e798b1a25febe06a9 | |
| parent | 9671650a7c76b4dc2c74a6ae6258def228a26d95 (diff) | |
| download | emacs-04289d1cd863fa8cc0c8a9b976a8e27d9a0b4dd1.tar.gz emacs-04289d1cd863fa8cc0c8a9b976a8e27d9a0b4dd1.zip | |
Allow sorting flyspell corrections
* lisp/textmodes/flyspell.el (flyspell-sort): New function (bug#2405).
(flyspell-sort-corrections-functionx): New variable.
(flyspell-sort-corrections-alphabetically): New function.
(flyspell-notify-misspell): Use them.
(flyspell-auto-correct-word): Ditto.
(flyspell-emacs-popup): Ditto.
(flyspell-xemacs-popup): Ditto. Suggested by Sebastien Delafond.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/textmodes/flyspell.el | 42 |
2 files changed, 33 insertions, 13 deletions
| @@ -2010,6 +2010,10 @@ This is used by Google's Native Client (NaCl). | |||
| 2010 | ** `read-color' will now display the color names using the color itself | 2010 | ** `read-color' will now display the color names using the color itself |
| 2011 | as the background color. | 2011 | as the background color. |
| 2012 | 2012 | ||
| 2013 | --- | ||
| 2014 | ** There is now a new variable `flyspell-sort-corrections-function' | ||
| 2015 | that allows changing the way corrections are sorted. | ||
| 2016 | |||
| 2013 | ** Miscellaneous name change | 2017 | ** Miscellaneous name change |
| 2014 | 2018 | ||
| 2015 | --- | 2019 | --- |
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 3b1a805f51b..5db0d987a0f 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el | |||
| @@ -88,11 +88,34 @@ downcased before comparing with these exceptions." | |||
| 88 | :version "24.1") | 88 | :version "24.1") |
| 89 | 89 | ||
| 90 | (defcustom flyspell-sort-corrections nil | 90 | (defcustom flyspell-sort-corrections nil |
| 91 | "Non-nil means, sort the corrections alphabetically before popping them." | 91 | "If non-nil, sort the corrections before popping them. |
| 92 | The sorting is controlled by the `flyspell-sort-corrections-function' | ||
| 93 | variable, and defaults to sorting alphabetically." | ||
| 92 | :group 'flyspell | 94 | :group 'flyspell |
| 93 | :version "21.1" | 95 | :version "21.1" |
| 94 | :type 'boolean) | 96 | :type 'boolean) |
| 95 | 97 | ||
| 98 | (defcustom flyspell-sort-corrections-function | ||
| 99 | 'flyspell-sort-corrections-alphabetically | ||
| 100 | "The function used to sort corrections. | ||
| 101 | This only happens if `flyspell-sort-corrections' is non-nil. The | ||
| 102 | function takes three parameters -- the two correction candidates | ||
| 103 | to be sorted, and the third parameter is the word that's being | ||
| 104 | corrected." | ||
| 105 | :version "25.2" | ||
| 106 | :type 'function | ||
| 107 | :group 'flyspell) | ||
| 108 | |||
| 109 | (defun flyspell-sort-corrections-alphabetically (corr1 corr2 _) | ||
| 110 | (string< corr1 corr2)) | ||
| 111 | |||
| 112 | (defun flyspell-sort (corrs word) | ||
| 113 | (if flyspell-sort-corrections | ||
| 114 | (sort corrs | ||
| 115 | (lambda (c1 c2) | ||
| 116 | (funcall flyspell-sort-corrections-function c1 c2 word))) | ||
| 117 | corrs)) | ||
| 118 | |||
| 96 | (defcustom flyspell-duplicate-distance 400000 | 119 | (defcustom flyspell-duplicate-distance 400000 |
| 97 | "The maximum distance for finding duplicates of unrecognized words. | 120 | "The maximum distance for finding duplicates of unrecognized words. |
| 98 | This applies to the feature that when a word is not found in the dictionary, | 121 | This applies to the feature that when a word is not found in the dictionary, |
| @@ -1007,9 +1030,7 @@ Mostly we check word delimiters." | |||
| 1007 | (defun flyspell-notify-misspell (word poss) | 1030 | (defun flyspell-notify-misspell (word poss) |
| 1008 | (let ((replacements (if (stringp poss) | 1031 | (let ((replacements (if (stringp poss) |
| 1009 | poss | 1032 | poss |
| 1010 | (if flyspell-sort-corrections | 1033 | (flyspell-sort (car (cdr (cdr poss))) word)))) |
| 1011 | (sort (car (cdr (cdr poss))) 'string<) | ||
| 1012 | (car (cdr (cdr poss))))))) | ||
| 1013 | (if flyspell-issue-message-flag | 1034 | (if flyspell-issue-message-flag |
| 1014 | (message "misspelling `%s' %S" word replacements)))) | 1035 | (message "misspelling `%s' %S" word replacements)))) |
| 1015 | 1036 | ||
| @@ -1979,9 +2000,8 @@ This command proposes various successive corrections for the current word." | |||
| 1979 | (error "Ispell: error in Ispell process")) | 2000 | (error "Ispell: error in Ispell process")) |
| 1980 | (t | 2001 | (t |
| 1981 | ;; The word is incorrect, we have to propose a replacement. | 2002 | ;; The word is incorrect, we have to propose a replacement. |
| 1982 | (let ((replacements (if flyspell-sort-corrections | 2003 | (let ((replacements (flyspell-sort (car (cdr (cdr poss))) |
| 1983 | (sort (car (cdr (cdr poss))) 'string<) | 2004 | word))) |
| 1984 | (car (cdr (cdr poss)))))) | ||
| 1985 | (setq flyspell-auto-correct-region nil) | 2005 | (setq flyspell-auto-correct-region nil) |
| 1986 | (if (consp replacements) | 2006 | (if (consp replacements) |
| 1987 | (progn | 2007 | (progn |
| @@ -2229,9 +2249,7 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." | |||
| 2229 | (setq event (list (list (car (cdr mouse-pos)) | 2249 | (setq event (list (list (car (cdr mouse-pos)) |
| 2230 | (1+ (cdr (cdr mouse-pos)))) | 2250 | (1+ (cdr (cdr mouse-pos)))) |
| 2231 | (car mouse-pos))))) | 2251 | (car mouse-pos))))) |
| 2232 | (let* ((corrects (if flyspell-sort-corrections | 2252 | (let* ((corrects (flyspell-sort (car (cdr (cdr poss))) word)) |
| 2233 | (sort (car (cdr (cdr poss))) 'string<) | ||
| 2234 | (car (cdr (cdr poss))))) | ||
| 2235 | (cor-menu (if (consp corrects) | 2253 | (cor-menu (if (consp corrects) |
| 2236 | (mapcar (lambda (correct) | 2254 | (mapcar (lambda (correct) |
| 2237 | (list correct correct)) | 2255 | (list correct correct)) |
| @@ -2262,9 +2280,7 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." | |||
| 2262 | ;;*---------------------------------------------------------------------*/ | 2280 | ;;*---------------------------------------------------------------------*/ |
| 2263 | (defun flyspell-xemacs-popup (poss word cursor-location start end save) | 2281 | (defun flyspell-xemacs-popup (poss word cursor-location start end save) |
| 2264 | "The XEmacs popup menu." | 2282 | "The XEmacs popup menu." |
| 2265 | (let* ((corrects (if flyspell-sort-corrections | 2283 | (let* ((corrects (flyspell-sort (car (cdr (cdr poss))) word)) |
| 2266 | (sort (car (cdr (cdr poss))) 'string<) | ||
| 2267 | (car (cdr (cdr poss))))) | ||
| 2268 | (cor-menu (if (consp corrects) | 2284 | (cor-menu (if (consp corrects) |
| 2269 | (mapcar (lambda (correct) | 2285 | (mapcar (lambda (correct) |
| 2270 | (vector correct | 2286 | (vector correct |