aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2006-11-06 16:06:11 +0000
committerRichard M. Stallman2006-11-06 16:06:11 +0000
commit4071cac7eb5c167a267c611a6980db22b360c78e (patch)
treeb39300dbe6ede37010a506875b2ad534afd70b33
parent708ca5aaaf60344ae2aa31f01a5e427620f7a6ad (diff)
downloademacs-4071cac7eb5c167a267c611a6980db22b360c78e.tar.gz
emacs-4071cac7eb5c167a267c611a6980db22b360c78e.zip
(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.
-rw-r--r--lisp/textmodes/flyspell.el91
1 files changed, 51 insertions, 40 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 189b398cb46..5268988f427 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -412,6 +412,7 @@ property of the major mode name.")
412 (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word) 412 (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
413 (define-key map [(control ?\,)] 'flyspell-goto-next-error) 413 (define-key map [(control ?\,)] 'flyspell-goto-next-error)
414 (define-key map [(control ?\.)] 'flyspell-auto-correct-word) 414 (define-key map [(control ?\.)] 'flyspell-auto-correct-word)
415 (define-key map [(meta ?\^m)] 'flyspell-correct-word-before-point)
415 map) 416 map)
416 "Minor mode keymap for Flyspell mode--for the whole buffer.") 417 "Minor mode keymap for Flyspell mode--for the whole buffer.")
417 418
@@ -1999,52 +2000,62 @@ But don't look beyond what's visible on the screen."
1999;;*---------------------------------------------------------------------*/ 2000;;*---------------------------------------------------------------------*/
2000;;* flyspell-correct-word ... */ 2001;;* flyspell-correct-word ... */
2001;;*---------------------------------------------------------------------*/ 2002;;*---------------------------------------------------------------------*/
2003
2002(defun flyspell-correct-word (event) 2004(defun flyspell-correct-word (event)
2003 "Pop up a menu of possible corrections for a misspelled word. 2005 "Pop up a menu of possible corrections for a misspelled word.
2004The word checked is the word at the mouse position." 2006The word checked is the word at the mouse position."
2005 (interactive "e") 2007 (interactive "e")
2006 ;; use the correct dictionary
2007 (flyspell-accept-buffer-local-defs)
2008 ;; retain cursor location (I don't know why but save-excursion here fails).
2009 (let ((save (point))) 2008 (let ((save (point)))
2010 (mouse-set-point event) 2009 (mouse-set-point event)
2011 (let ((cursor-location (point)) 2010 (flyspell-correct-word-before-point event save)))
2012 (word (flyspell-get-word nil))) 2011
2013 (if (consp word) 2012(defun flyspell-correct-word-before-point (&optional event opoint)
2014 (let ((start (car (cdr word))) 2013 "Pop up a menu of possible corrections for misspelled word before point.
2015 (end (car (cdr (cdr word)))) 2014If EVENT is non-nil, it is the mouse event that invoked this operation;
2016 (word (car word)) 2015that controls where to put the menu.
2017 poss ispell-filter) 2016If OPOINT is non-nil, restore point there after adjusting it for replacement."
2018 ;; now check spelling of word. 2017 (interactive)
2019 (ispell-send-string "%\n") ;put in verbose mode 2018 (unless (mouse-position)
2020 (ispell-send-string (concat "^" word "\n")) 2019 (error "Pop-up menus do not work on this terminal"))
2021 ;; wait until ispell has processed word 2020 ;; use the correct dictionary
2022 (while (progn 2021 (flyspell-accept-buffer-local-defs)
2023 (accept-process-output ispell-process) 2022 (let ((cursor-location (point))
2024 (not (string= "" (car ispell-filter))))) 2023 (word (flyspell-get-word nil)))
2025 ;; Remove leading empty element 2024 (if (consp word)
2026 (setq ispell-filter (cdr ispell-filter)) 2025 (let ((start (car (cdr word)))
2027 ;; ispell process should return something after word is sent. 2026 (end (car (cdr (cdr word))))
2028 ;; Tag word as valid (i.e., skip) otherwise 2027 (word (car word))
2029 (or ispell-filter 2028 poss ispell-filter)
2030 (setq ispell-filter '(*))) 2029 ;; now check spelling of word.
2031 (if (consp ispell-filter) 2030 (ispell-send-string "%\n") ;put in verbose mode
2032 (setq poss (ispell-parse-output (car ispell-filter)))) 2031 (ispell-send-string (concat "^" word "\n"))
2033 (cond 2032 ;; wait until ispell has processed word
2034 ((or (eq poss t) (stringp poss)) 2033 (while (progn
2035 ;; don't correct word 2034 (accept-process-output ispell-process)
2036 t) 2035 (not (string= "" (car ispell-filter)))))
2037 ((null poss) 2036 ;; Remove leading empty element
2038 ;; ispell error 2037 (setq ispell-filter (cdr ispell-filter))
2039 (error "Ispell: error in Ispell process")) 2038 ;; ispell process should return something after word is sent.
2040 ((featurep 'xemacs) 2039 ;; Tag word as valid (i.e., skip) otherwise
2041 (flyspell-xemacs-popup 2040 (or ispell-filter
2042 poss word cursor-location start end save)) 2041 (setq ispell-filter '(*)))
2043 (t 2042 (if (consp ispell-filter)
2044 ;; The word is incorrect, we have to propose a replacement. 2043 (setq poss (ispell-parse-output (car ispell-filter))))
2045 (flyspell-do-correct (flyspell-emacs-popup event poss word) 2044 (cond
2046 poss word cursor-location start end save))) 2045 ((or (eq poss t) (stringp poss))
2047 (ispell-pdict-save t)))))) 2046 ;; don't correct word
2047 t)
2048 ((null poss)
2049 ;; ispell error
2050 (error "Ispell: error in Ispell process"))
2051 ((featurep 'xemacs)
2052 (flyspell-xemacs-popup
2053 poss word cursor-location start end opoint))
2054 (t
2055 ;; The word is incorrect, we have to propose a replacement.
2056 (flyspell-do-correct (flyspell-emacs-popup event poss word)
2057 poss word cursor-location start end opoint)))
2058 (ispell-pdict-save t)))))
2048 2059
2049;;*---------------------------------------------------------------------*/ 2060;;*---------------------------------------------------------------------*/
2050;;* flyspell-do-correct ... */ 2061;;* flyspell-do-correct ... */