# HG changeset patch # User Richard M. Stallman # Date 1162829171 0 # Node ID ab47574757339e8b02c4e551d217ea0f7bfc17b9 # Parent 7e762349b1c32952e1cec5075af29f311ba2423e (flyspell-correct-word-before-point): New function broken out of flyspell-correct-word. (flyspell-mode-map): Bind it to M-RET. (flyspell-correct-word): Call it. diff -r 7e762349b1c3 -r ab4757475733 lisp/textmodes/flyspell.el --- a/lisp/textmodes/flyspell.el Mon Nov 06 16:01:53 2006 +0000 +++ b/lisp/textmodes/flyspell.el Mon Nov 06 16:06:11 2006 +0000 @@ -412,6 +412,7 @@ (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word) (define-key map [(control ?\,)] 'flyspell-goto-next-error) (define-key map [(control ?\.)] 'flyspell-auto-correct-word) + (define-key map [(meta ?\^m)] 'flyspell-correct-word-before-point) map) "Minor mode keymap for Flyspell mode--for the whole buffer.") @@ -1999,52 +2000,62 @@ ;;*---------------------------------------------------------------------*/ ;;* flyspell-correct-word ... */ ;;*---------------------------------------------------------------------*/ + (defun flyspell-correct-word (event) "Pop up a menu of possible corrections for a misspelled word. The word checked is the word at the mouse position." (interactive "e") - ;; use the correct dictionary - (flyspell-accept-buffer-local-defs) - ;; retain cursor location (I don't know why but save-excursion here fails). (let ((save (point))) (mouse-set-point event) - (let ((cursor-location (point)) - (word (flyspell-get-word nil))) - (if (consp word) - (let ((start (car (cdr word))) - (end (car (cdr (cdr word)))) - (word (car word)) - poss ispell-filter) - ;; now check spelling of word. - (ispell-send-string "%\n") ;put in verbose mode - (ispell-send-string (concat "^" word "\n")) - ;; wait until ispell has processed word - (while (progn - (accept-process-output ispell-process) - (not (string= "" (car ispell-filter))))) - ;; Remove leading empty element - (setq ispell-filter (cdr ispell-filter)) - ;; ispell process should return something after word is sent. - ;; Tag word as valid (i.e., skip) otherwise - (or ispell-filter - (setq ispell-filter '(*))) - (if (consp ispell-filter) - (setq poss (ispell-parse-output (car ispell-filter)))) - (cond - ((or (eq poss t) (stringp poss)) - ;; don't correct word - t) - ((null poss) - ;; ispell error - (error "Ispell: error in Ispell process")) - ((featurep 'xemacs) - (flyspell-xemacs-popup - poss word cursor-location start end save)) - (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 save))) - (ispell-pdict-save t)))))) + (flyspell-correct-word-before-point event save))) + +(defun flyspell-correct-word-before-point (&optional event opoint) + "Pop up a menu of possible corrections for misspelled word before point. +If EVENT is non-nil, it is the mouse event that invoked this operation; +that controls where to put the menu. +If OPOINT is non-nil, restore point there after adjusting it for replacement." + (interactive) + (unless (mouse-position) + (error "Pop-up menus do not work on this terminal")) + ;; use the correct dictionary + (flyspell-accept-buffer-local-defs) + (let ((cursor-location (point)) + (word (flyspell-get-word nil))) + (if (consp word) + (let ((start (car (cdr word))) + (end (car (cdr (cdr word)))) + (word (car word)) + poss ispell-filter) + ;; now check spelling of word. + (ispell-send-string "%\n") ;put in verbose mode + (ispell-send-string (concat "^" word "\n")) + ;; wait until ispell has processed word + (while (progn + (accept-process-output ispell-process) + (not (string= "" (car ispell-filter))))) + ;; Remove leading empty element + (setq ispell-filter (cdr ispell-filter)) + ;; ispell process should return something after word is sent. + ;; Tag word as valid (i.e., skip) otherwise + (or ispell-filter + (setq ispell-filter '(*))) + (if (consp ispell-filter) + (setq poss (ispell-parse-output (car ispell-filter)))) + (cond + ((or (eq poss t) (stringp poss)) + ;; don't correct word + t) + ((null poss) + ;; ispell error + (error "Ispell: error in Ispell process")) + ((featurep 'xemacs) + (flyspell-xemacs-popup + poss word cursor-location start end opoint)) + (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))) + (ispell-pdict-save t))))) ;;*---------------------------------------------------------------------*/ ;;* flyspell-do-correct ... */