GNU bug report logs -
#2405
Flyspell patch - Provide users with a way to specify their own sort function
Previous Next
Reported by: Sebastien Delafond <sdelafond <at> gmx.net>
Date: Fri, 20 Feb 2009 06:20:02 UTC
Severity: wishlist
Tags: patch
Fixed in version 26.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 2405 in the body.
You can then email your comments to 2405 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report stored
:
bug#2405
; Package
emacs
.
(Fri, 20 Feb 2009 06:20:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Sebastien Delafond <sdelafond <at> gmx.net>
:
New bug report received and filed, but not forwarded.
(Fri, 20 Feb 2009 06:20:03 GMT)
Full text and
rfc822 format available.
Message #5 received at quiet <at> emacsbugs.donarmstrong.com (full text, mbox):
Severity: wishlist
[ resent from
http://lists.gnu.org/archive/html/emacs-devel/2009-02/msg00757.html ]
Hi,
at the end of this message is my attempt at writing a patch for
flyspell, so users can define their own function to sort potential
corrections.
I type French on a US keyboard, so I personally use it to favor
accentuated corrections of the same length as the word to be corrected,
with the following in my .emacs:
(setq my-flyspell-regular-letters
(split-string "abcdefghijklmnoprstuvwxyz" "" t))
(setq my-flyspell-regular-letters
(append my-flyspell-regular-letters
(map 'list 'capitalize my-flyspell-regular-letters)))
(defun flyspell-word-distance (word1 word2)
"Difference in length between WORD1 and WORD2."
(abs (- (length word1) (length word2))))
(defun flyspell-accent-count (word)
(let ((count 0))
(dolist (x (split-string word "" t) count)
(when (not (member x my-flyspell-regular-letters))
(setq count (1+ count))))))
(defun my-flyspell-sort-corrections-function (word1 word2 word)
"Sort WORD1 and WORD2 as corrections of WORD: favor the
corrections having the same length as WORD, and use
number of 'special' characters as an additional
criteria."
(let ((distance1 (flyspell-word-distance word1 word))
(distance2 (flyspell-word-distance word2 word)))
(if (= distance1 distance2)
(let ((accents-count1 (flyspell-accent-count word1))
(accents-count2 (flyspell-accent-count word2)))
(> accents-count1 accents-count2))
(< distance1 distance2))))
(setq flyspell-sort-corrections-function 'my-flyspell-sort-corrections-function)
(setq flyspell-sort-corrections t)
All comments and remarks are *most* welcome, either on the general
coding style, or on the usefulness of the patch itself; probably on
other things too.
Cheers,
--Seb
========================================================================
--- flyspell.el 2009-02-18 21:53:52.000000000 -0800
+++ flyspell.el 2009-02-19 19:27:52.000000000 -0800
@@ -81,11 +81,34 @@
:type '(alist :key-type string :value-type (repeat string)))
(defcustom flyspell-sort-corrections nil
- "Non-nil means, sort the corrections alphabetically before popping them."
+ "Non-nil means, sort the corrections using
+flyspell-sort-corrections-function (which does alphabetical
+sorting by default) before popping them."
:group 'flyspell
:version "21.1"
:type 'boolean)
+(defcustom flyspell-sort-corrections-function
+ (lambda (correction1 correction2 corrected)
+ (string< correction1 correction2))
+ "Function used to sort the corrections when
+flyspell-sort-corrections is non-nil. It gets passed the 2
+corrections being sorted out, and the word to correct. By
+default, it simply sorts the corrections alphabetically,
+altogether ignoring the word to be corrected. If for instance you
+wanted to favor corrections of the same length as the corrected
+word, you could use:
+
+ (lambda (correction1 correction2 corrected)
+ (let ((distance1 (abs (- (length correction1) (length corrected))))
+ (distance2 (abs (- (length correction2) (length corrected)))))
+ (if (= distance1 distance2)
+ (string< correction1 correction2)
+ (< distance1 distance2))))"
+ :group 'flyspell
+ :version "21.1"
+ :type 'function)
+
(defcustom flyspell-duplicate-distance -1
"The maximum distance for finding duplicates of unrecognized words.
This applies to the feature that when a word is not found in the dictionary,
@@ -532,6 +555,16 @@
(and (consp ws) (window-minibuffer-p (car ws)))))
;;*---------------------------------------------------------------------*/
+;;* flyspell-sort-corrections-function-generator */
+;;* ------------------------------------------------------------- */
+;;* Return the corrections-sorting function for a specific word */
+;;* to be corrected */
+;;*---------------------------------------------------------------------*/
+(defun flyspell-sort-corrections-function-generator (word)
+ (lambda (word1 word2)
+ (funcall flyspell-sort-corrections-function word1 word2 word)))
+
+;;*---------------------------------------------------------------------*/
;;* flyspell-accept-buffer-local-defs ... */
;;*---------------------------------------------------------------------*/
(defvar flyspell-last-buffer nil
@@ -979,7 +1012,8 @@
(let ((replacements (if (stringp poss)
poss
(if flyspell-sort-corrections
- (sort (car (cdr (cdr poss))) 'string<)
+ (sort (car (cdr (cdr poss)))
+ (flyspell-sort-corrections-function-generator word))
(car (cdr (cdr poss)))))))
(if flyspell-issue-message-flag
(message "misspelling `%s' %S" word replacements))))
@@ -1926,7 +1960,8 @@
(t
;; the word is incorrect, we have to propose a replacement
(let ((replacements (if flyspell-sort-corrections
- (sort (car (cdr (cdr poss))) 'string<)
+ (sort (car (cdr (cdr poss)))
+ (flyspell-sort-corrections-function-generator word))
(car (cdr (cdr poss))))))
(setq flyspell-auto-correct-region nil)
(if (consp replacements)
@@ -2176,7 +2211,8 @@
(1+ (cdr (cdr mouse-pos))))
(car mouse-pos)))))
(let* ((corrects (if flyspell-sort-corrections
- (sort (car (cdr (cdr poss))) 'string<)
+ (sort (car (cdr (cdr poss)))
+ (flyspell-sort-corrections-function-generator word))
(car (cdr (cdr poss)))))
(cor-menu (if (consp corrects)
(mapcar (lambda (correct)
@@ -2209,7 +2245,8 @@
(defun flyspell-xemacs-popup (poss word cursor-location start end save)
"The XEmacs popup menu."
(let* ((corrects (if flyspell-sort-corrections
- (sort (car (cdr (cdr poss))) 'string<)
+ (sort (car (cdr (cdr poss)))
+ (flyspell-sort-corrections-function-generator word))
(car (cdr (cdr poss)))))
(cor-menu (if (consp corrects)
(mapcar (lambda (correct)
========================================================================
Tags added: patch
Request was from
Sebastien Delafond <sdelafond <at> gmx.net>
to
control <at> emacsbugs.donarmstrong.com
.
(Fri, 20 Feb 2009 15:35:06 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#2405
; Package
emacs
.
(Mon, 29 Feb 2016 04:15:01 GMT)
Full text and
rfc822 format available.
Message #10 received at 2405 <at> debbugs.gnu.org (full text, mbox):
Sebastien Delafond <sdelafond <at> gmx.net> writes:
> Severity: wishlist
>
> [ resent from
> http://lists.gnu.org/archive/html/emacs-devel/2009-02/msg00757.html ]
>
> Hi,
>
> at the end of this message is my attempt at writing a patch for
> flyspell, so users can define their own function to sort potential
> corrections.
>
> I type French on a US keyboard, so I personally use it to favor
> accentuated corrections of the same length as the word to be corrected,
> with the following in my .emacs:
I've now implemented flyspell sorting inspired by your patch, but not
directly based on it, and it should appear in Emacs 26.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug marked as fixed in version 25.2, send any further explanations to
2405 <at> debbugs.gnu.org and Sebastien Delafond <sdelafond <at> gmx.net>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 29 Feb 2016 04:15:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 28 Mar 2016 11:24:03 GMT)
Full text and
rfc822 format available.
bug unarchived.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Sun, 04 Dec 2016 02:50:02 GMT)
Full text and
rfc822 format available.
bug Marked as fixed in versions 26.1.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Sun, 04 Dec 2016 02:50:02 GMT)
Full text and
rfc822 format available.
bug No longer marked as fixed in versions 25.2.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Sun, 04 Dec 2016 02:50:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 01 Jan 2017 12:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 8 years and 175 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.