diff options
Diffstat (limited to 'lisp/textmodes/flyspell.el')
-rw-r--r-- | lisp/textmodes/flyspell.el | 167 |
1 files changed, 41 insertions, 126 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index f7683d96790..0edf9b1a47e 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -88,11 +88,34 @@ downcased before comparing with these exceptions." :version "24.1") (defcustom flyspell-sort-corrections nil - "Non-nil means, sort the corrections alphabetically before popping them." + "If non-nil, sort the corrections before popping them. +The sorting is controlled by the `flyspell-sort-corrections-function' +variable, and defaults to sorting alphabetically." :group 'flyspell :version "21.1" :type 'boolean) +(defcustom flyspell-sort-corrections-function + 'flyspell-sort-corrections-alphabetically + "The function used to sort corrections. +This only happens if `flyspell-sort-corrections' is non-nil. The +function takes three parameters -- the two correction candidates +to be sorted, and the third parameter is the word that's being +corrected." + :version "26.1" + :type 'function + :group 'flyspell) + +(defun flyspell-sort-corrections-alphabetically (corr1 corr2 _) + (string< corr1 corr2)) + +(defun flyspell-sort (corrs word) + (if flyspell-sort-corrections + (sort corrs + (lambda (c1 c2) + (funcall flyspell-sort-corrections-function c1 c2 word))) + corrs)) + (defcustom flyspell-duplicate-distance 400000 "The maximum distance for finding duplicates of unrecognized words. This applies to the feature that when a word is not found in the dictionary, @@ -424,12 +447,7 @@ like <img alt=\"Some thing.\">." ;;* The minor mode declaration. */ ;;*---------------------------------------------------------------------*/ (defvar flyspell-mouse-map - (let ((map (make-sparse-keymap))) - (if (featurep 'xemacs) - (define-key map [button2] #'flyspell-correct-word) - (define-key map [down-mouse-2] #'flyspell-correct-word) - (define-key map [mouse-2] 'undefined)) - map) + (make-sparse-keymap) "Keymap for Flyspell to put on erroneous words.") (defvar flyspell-mode-map @@ -629,9 +647,7 @@ in your init file. ;; the welcome message (if (and flyspell-issue-message-flag flyspell-issue-welcome-flag - (if (featurep 'xemacs) - (interactive-p) ;; XEmacs does not have (called-interactively-p) - (called-interactively-p 'interactive))) + (called-interactively-p 'interactive)) (let ((binding (where-is-internal 'flyspell-auto-correct-word nil 'non-ascii))) (message "%s" @@ -1007,9 +1023,7 @@ Mostly we check word delimiters." (defun flyspell-notify-misspell (word poss) (let ((replacements (if (stringp poss) poss - (if flyspell-sort-corrections - (sort (car (cdr (cdr poss))) 'string<) - (car (cdr (cdr poss))))))) + (flyspell-sort (car (cdr (cdr poss))) word)))) (if flyspell-issue-message-flag (message "misspelling `%s' %S" word replacements)))) @@ -1097,8 +1111,8 @@ misspelling and skips redundant spell-checking step." (flyspell-word (flyspell-get-word following)) start end poss word ispell-filter) (if (or (eq flyspell-word nil) - (and (fboundp flyspell-generic-check-word-predicate) - (not (funcall flyspell-generic-check-word-predicate)))) + (and (functionp flyspell-generic-check-word-predicate) + (not (funcall flyspell-generic-check-word-predicate)))) t (progn ;; destructure return flyspell-word info list. @@ -1158,9 +1172,7 @@ misspelling and skips redundant spell-checking step." (ispell-send-string (concat "^" word "\n")) ;; we mark the ispell process so it can be killed ;; when emacs is exited without query - (if (featurep 'xemacs) - (process-kill-without-query ispell-process) - (set-process-query-on-exit-flag ispell-process nil)) + (set-process-query-on-exit-flag ispell-process nil) ;; Wait until ispell has processed word. (while (progn (accept-process-output ispell-process) @@ -1695,15 +1707,7 @@ FLYSPELL-BUFFER." ;;*---------------------------------------------------------------------*/ (defun flyspell-delete-region-overlays (beg end) "Delete overlays used by flyspell in a given region." - (if (featurep 'emacs) - (remove-overlays beg end 'flyspell-overlay t) - ;; XEmacs does not have `remove-overlays' - (let ((l (overlays-in beg end))) - (while (consp l) - (progn - (if (flyspell-overlay-p (car l)) - (delete-overlay (car l))) - (setq l (cdr l))))))) + (remove-overlays beg end 'flyspell-overlay t)) (defun flyspell-delete-all-overlays () "Delete all the overlays used by flyspell." @@ -1914,7 +1918,7 @@ This command proposes various successive corrections for the current word." ;; invoke the original binding of M-TAB, if that was recorded. (if (and (local-variable-p 'flyspell--prev-meta-tab-binding) (commandp flyspell--prev-meta-tab-binding t) - (fboundp flyspell-generic-check-word-predicate) + (functionp flyspell-generic-check-word-predicate) (not (funcall flyspell-generic-check-word-predicate)) (equal (where-is-internal 'flyspell-auto-correct-word nil t) [?\M-\t])) @@ -1945,7 +1949,7 @@ This command proposes various successive corrections for the current word." (funcall flyspell-insert-function word) (flyspell-word) (flyspell-display-next-corrections flyspell-auto-correct-ring)) - (flyspell-ajust-cursor-point pos (point) old-max) + (flyspell-adjust-cursor-point pos (point) old-max) (setq flyspell-auto-correct-pos (point))) ;; Fetch the word to be checked. (let ((word (flyspell-get-word))) @@ -1979,9 +1983,8 @@ This command proposes various successive corrections for the current word." (error "Ispell: error in Ispell process")) (t ;; The word is incorrect, we have to propose a replacement. - (let ((replacements (if flyspell-sort-corrections - (sort (car (cdr (cdr poss))) 'string<) - (car (cdr (cdr poss)))))) + (let ((replacements (flyspell-sort (car (cdr (cdr poss))) + word))) (setq flyspell-auto-correct-region nil) (if (consp replacements) (progn @@ -2013,7 +2016,7 @@ This command proposes various successive corrections for the current word." (flyspell-word) (flyspell-display-next-corrections (cons new-word flyspell-auto-correct-ring)) - (flyspell-ajust-cursor-point pos + (flyspell-adjust-cursor-point pos (point) old-max)))))))))) (setq flyspell-auto-correct-pos (point)) @@ -2136,10 +2139,7 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." ((null poss) ;; ispell error (error "Ispell: error in Ispell process")) - ((featurep 'xemacs) - (flyspell-xemacs-popup - poss word cursor-location start end opoint)) - (t + (t ;; The word is incorrect, we have to propose a replacement. (flyspell-do-correct (flyspell-emacs-popup event poss word) poss word cursor-location start end opoint))) @@ -2150,17 +2150,12 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." ;;*---------------------------------------------------------------------*/ (defun flyspell-do-correct (replace poss word cursor-location start end save) "The popup menu callback." - ;; Originally, the XEmacs code didn't do the (goto-char save) here and did - ;; it instead right after calling the function. (cond ((eq replace 'ignore) (goto-char save) nil) ((eq replace 'save) (goto-char save) (ispell-send-string (concat "*" word "\n")) - ;; This was added only to the XEmacs side in revision 1.18 of - ;; flyspell. I assume its absence on the Emacs side was an - ;; oversight. --Stef (ispell-send-string "#\n") (flyspell-unhighlight-at cursor-location) (setq ispell-pdict-modified-p '(t))) @@ -2177,8 +2172,6 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." (if (eq replace 'buffer) (ispell-add-per-file-word-list word))) (replace - ;; This was added only to the Emacs side. I assume its absence on - ;; the XEmacs side was an oversight. --Stef (flyspell-unhighlight-at cursor-location) (let ((old-max (point-max)) (new-word (if (atom replace) @@ -2192,17 +2185,15 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." (funcall flyspell-insert-function new-word) (if flyspell-abbrev-p (flyspell-define-abbrev word new-word))) - ;; In the original Emacs code, this was only called in the body - ;; of the if. I arbitrarily kept the XEmacs behavior instead. - (flyspell-ajust-cursor-point save cursor-location old-max))) + (flyspell-adjust-cursor-point save cursor-location old-max))) (t (goto-char save) nil))) ;;*---------------------------------------------------------------------*/ -;;* flyspell-ajust-cursor-point ... */ +;;* flyspell-adjust-cursor-point ... */ ;;*---------------------------------------------------------------------*/ -(defun flyspell-ajust-cursor-point (save cursor-location old-max) +(defun flyspell-adjust-cursor-point (save cursor-location old-max) (if (>= save cursor-location) (let ((new-pos (+ save (- (point-max) old-max)))) (goto-char (cond @@ -2229,9 +2220,7 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." (setq event (list (list (car (cdr mouse-pos)) (1+ (cdr (cdr mouse-pos)))) (car mouse-pos))))) - (let* ((corrects (if flyspell-sort-corrections - (sort (car (cdr (cdr poss))) 'string<) - (car (cdr (cdr poss))))) + (let* ((corrects (flyspell-sort (car (cdr (cdr poss))) word)) (cor-menu (if (consp corrects) (mapcar (lambda (correct) (list correct correct)) @@ -2258,80 +2247,6 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement." menu))))) ;;*---------------------------------------------------------------------*/ -;;* flyspell-xemacs-popup ... */ -;;*---------------------------------------------------------------------*/ -(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<) - (car (cdr (cdr poss))))) - (cor-menu (if (consp corrects) - (mapcar (lambda (correct) - (vector correct - (list 'flyspell-do-correct - correct - (list 'quote poss) - word - cursor-location - start - end - save) - t)) - corrects) - '())) - (affix (car (cdr (cdr (cdr poss))))) - show-affix-info - (menu (let ((save (if (and (consp affix) show-affix-info) - (vector - (concat "Save affix: " (car affix)) - (list 'flyspell-do-correct - ''save - (list 'quote poss) - word - cursor-location - start - end - save) - t) - (vector - "Save word" - (list 'flyspell-do-correct - ''save - (list 'quote poss) - word - cursor-location - start - end - save) - t))) - (session (vector "Accept (session)" - (list 'flyspell-do-correct - ''session - (list 'quote poss) - word - cursor-location - start - end - save) - t)) - (buffer (vector "Accept (buffer)" - (list 'flyspell-do-correct - ''buffer - (list 'quote poss) - word - cursor-location - start - end - save) - t))) - (if (consp cor-menu) - (append cor-menu (list "-" save session buffer)) - (list save session buffer))))) - (popup-menu (cons (format "%s [%s]" word (or ispell-local-dictionary - ispell-dictionary)) - menu)))) - -;;*---------------------------------------------------------------------*/ ;;* Some example functions for real autocorrecting */ ;;*---------------------------------------------------------------------*/ (defun flyspell-maybe-correct-transposition (beg end poss) |