aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2005-06-06 21:06:19 +0000
committerStefan Monnier2005-06-06 21:06:19 +0000
commit7ad046405db028a9012aeacb8da7b32dc471c905 (patch)
tree60e357ce99ab331e34c9b0bf35d9df71abcec171
parentf5f870c03cd5cd6805b620cccf0aff4e9951e18c (diff)
downloademacs-7ad046405db028a9012aeacb8da7b32dc471c905.tar.gz
emacs-7ad046405db028a9012aeacb8da7b32dc471c905.zip
(flyspell-auto-correct-binding, flyspell-incorrect-face)
(flyspell-duplicate-face): Use (X)Emacs-agnostic code. (flyspell-mode-map): Don't overwrite at each load. Remove code redundant with the subsequent add-minor-mode. Merge Emacs and XEmacs code. (flyspell-word): Minor simplification. (flyspell-math-tex-command-p): Quieten the byte-compiler. (flyspell-external-point-words): Remove unused vars `size' and `start'. (flyspell-do-correct): Rename from flyspell-xemacs-correct. Merge the corresponding Emacs code. (flyspell-correct-word, flyspell-xemacs-popup): Use flyspell-do-correct.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/textmodes/flyspell.el194
2 files changed, 88 insertions, 119 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d6cfeab3d08..e18366bb692 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,18 @@
12005-06-06 Stefan Monnier <monnier@iro.umontreal.ca> 12005-06-06 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * textmodes/flyspell.el (flyspell-auto-correct-binding)
4 (flyspell-incorrect-face, flyspell-duplicate-face):
5 Use (X)Emacs-agnostic code.
6 (flyspell-mode-map): Don't overwrite at each load. Remove code
7 redundant with the subsequent add-minor-mode. Merge Emacs and
8 XEmacs code.
9 (flyspell-word): Minor simplification.
10 (flyspell-math-tex-command-p): Quieten the byte-compiler.
11 (flyspell-external-point-words): Remove unused vars `size' and `start'.
12 (flyspell-do-correct): Rename from flyspell-xemacs-correct.
13 Merge the corresponding Emacs code.
14 (flyspell-correct-word, flyspell-xemacs-popup): Use flyspell-do-correct.
15
3 * emacs-lisp/debug.el (debug): Don't bury the buffer unless it's in 16 * emacs-lisp/debug.el (debug): Don't bury the buffer unless it's in
4 a dedicated window. 17 a dedicated window.
5 18
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 500c9c4e113..8bd6c731e3c 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -268,11 +268,7 @@ If `flyspell-large-region' is nil, all regions are treated as small."
268 :type 'boolean) 268 :type 'boolean)
269 269
270(defcustom flyspell-auto-correct-binding 270(defcustom flyspell-auto-correct-binding
271 (cond 271 [(control ?\;)]
272 ((eq flyspell-emacs 'xemacs)
273 [(control \;)])
274 (t
275 [?\C-\;]))
276 "The key binding for flyspell auto correction." 272 "The key binding for flyspell auto correction."
277 :group 'flyspell) 273 :group 'flyspell)
278 274
@@ -425,26 +421,18 @@ property of the major mode name.")
425 (define-key map [(control \.)] 'flyspell-auto-correct-word) 421 (define-key map [(control \.)] 'flyspell-auto-correct-word)
426 map)) 422 map))
427 423
428;;;###autoload 424(defvar flyspell-mode-map
429(defvar flyspell-mode-map (make-sparse-keymap)) 425 (let ((map (make-sparse-keymap)))
430 426 ;; mouse, keyboard bindings and misc definition
431;; mouse, keyboard bindings and misc definition 427 (if flyspell-use-meta-tab
432(when (or (assoc 'flyspell-mode minor-mode-map-alist) 428 (define-key map "\M-\t" 'flyspell-auto-correct-word))
433 (setq minor-mode-map-alist 429 (cond
434 (cons (cons 'flyspell-mode flyspell-mode-map) 430 ;; I don't understand this test, so I left it as is. --Stef
435 minor-mode-map-alist))) 431 ((or (featurep 'xemacs) flyspell-use-local-map)
436 (if flyspell-use-meta-tab 432 (define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
437 (define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word)) 433 (define-key map [(control ?\,)] 'flyspell-goto-next-error)
438 (cond 434 (define-key map [(control ?\.)] 'flyspell-auto-correct-word)))
439 ((eq flyspell-emacs 'xemacs) 435 map))
440 (define-key flyspell-mode-map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
441 (define-key flyspell-mode-map [(control \,)] 'flyspell-goto-next-error)
442 (define-key flyspell-mode-map [(control \.)] 'flyspell-auto-correct-word))
443 (flyspell-use-local-map
444 (define-key flyspell-mode-map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
445 (define-key flyspell-mode-map [?\C-\,] 'flyspell-goto-next-error)
446 (define-key flyspell-mode-map [?\C-\.] 'flyspell-auto-correct-word))))
447
448 436
449;; the name of the overlay property that defines the keymap 437;; the name of the overlay property that defines the keymap
450(defvar flyspell-overlay-keymap-property-name 'keymap) 438(defvar flyspell-overlay-keymap-property-name 'keymap)
@@ -462,20 +450,14 @@ property of the major mode name.")
462;* Highlighting */ 450;* Highlighting */
463;*---------------------------------------------------------------------*/ 451;*---------------------------------------------------------------------*/
464(defface flyspell-incorrect-face 452(defface flyspell-incorrect-face
465 (if (eq flyspell-emacs 'xemacs) 453 '((((class color)) (:foreground "OrangeRed" :bold t :underline t))
466 '((((class color)) (:foreground "OrangeRed" :bold t :underline t)) 454 (t (:bold t)))
467 (t (:bold t)))
468 '((((class color)) (:foreground "OrangeRed" :weight bold :underline t))
469 (t (:weight bold))))
470 "Face used for marking a misspelled word in Flyspell." 455 "Face used for marking a misspelled word in Flyspell."
471 :group 'flyspell) 456 :group 'flyspell)
472 457
473(defface flyspell-duplicate-face 458(defface flyspell-duplicate-face
474 (if (eq flyspell-emacs 'xemacs) 459 '((((class color)) (:foreground "Gold3" :bold t :underline t))
475 '((((class color)) (:foreground "Gold3" :bold t :underline t)) 460 (t (:bold t)))
476 (t (:bold t)))
477 '((((class color)) (:foreground "Gold3" :weight bold :underline t))
478 (t (:weight bold))))
479 "Face used for marking a misspelled word that appears twice in the buffer. 461 "Face used for marking a misspelled word that appears twice in the buffer.
480See also `flyspell-duplicate-distance'." 462See also `flyspell-duplicate-distance'."
481 :group 'flyspell) 463 :group 'flyspell)
@@ -1057,8 +1039,7 @@ Mostly we check word delimiters."
1057 (cond 1039 (cond
1058 ((and (or (not (eq ispell-parser 'tex)) 1040 ((and (or (not (eq ispell-parser 'tex))
1059 (and (> start (point-min)) 1041 (and (> start (point-min))
1060 (not (eq (char-after (1- start)) ?})) 1042 (not (memq (char-after (1- start)) '(?\} ?\\)))))
1061 (not (eq (char-after (1- start)) ?\\))))
1062 flyspell-mark-duplications-flag 1043 flyspell-mark-duplications-flag
1063 (save-excursion 1044 (save-excursion
1064 (goto-char (1- start)) 1045 (goto-char (1- start))
@@ -1181,20 +1162,21 @@ Mostly we check word delimiters."
1181;* time that function is called. */ 1162;* time that function is called. */
1182;*---------------------------------------------------------------------*/ 1163;*---------------------------------------------------------------------*/
1183(defun flyspell-math-tex-command-p () 1164(defun flyspell-math-tex-command-p ()
1184 (cond 1165 (when (fboundp 'texmathp)
1185 (flyspell-check-tex-math-command 1166 (cond
1186 nil) 1167 (flyspell-check-tex-math-command
1187 ((eq flyspell-tex-math-initialized t) 1168 nil)
1188 (texmathp)) 1169 ((eq flyspell-tex-math-initialized t)
1189 ((eq flyspell-tex-math-initialized 'error) 1170 (texmathp))
1190 nil) 1171 ((eq flyspell-tex-math-initialized 'error)
1191 (t 1172 nil)
1192 (setq flyspell-tex-math-initialized t) 1173 (t
1193 (condition-case nil 1174 (setq flyspell-tex-math-initialized t)
1194 (texmathp) 1175 (condition-case nil
1195 (error (progn 1176 (texmathp)
1196 (setq flyspell-tex-math-initialized 'error) 1177 (error (progn
1197 nil)))))) 1178 (setq flyspell-tex-math-initialized 'error)
1179 nil)))))))
1198 1180
1199;*---------------------------------------------------------------------*/ 1181;*---------------------------------------------------------------------*/
1200;* flyspell-tex-command-p ... */ 1182;* flyspell-tex-command-p ... */
@@ -1381,9 +1363,7 @@ Word syntax described by `flyspell-dictionary-alist' (which see)."
1381 (let ((buffer flyspell-external-ispell-buffer)) 1363 (let ((buffer flyspell-external-ispell-buffer))
1382 (set-buffer buffer) 1364 (set-buffer buffer)
1383 (goto-char (point-min)) 1365 (goto-char (point-min))
1384 (let ((size (- flyspell-large-region-end flyspell-large-region-beg)) 1366 (let ((pword "")
1385 (start flyspell-large-region-beg)
1386 (pword "")
1387 (pcount 1)) 1367 (pcount 1))
1388 ;; now we are done with ispell, we have to find the word in 1368 ;; now we are done with ispell, we have to find the word in
1389 ;; the initial buffer 1369 ;; the initial buffer
@@ -1954,7 +1934,7 @@ The word checked is the word at the mouse position."
1954 (let ((start (car (cdr word))) 1934 (let ((start (car (cdr word)))
1955 (end (car (cdr (cdr word)))) 1935 (end (car (cdr (cdr word))))
1956 (word (car word)) 1936 (word (car word))
1957 poss replace) 1937 poss)
1958 ;; now check spelling of word. 1938 ;; now check spelling of word.
1959 (process-send-string ispell-process "%\n") ;put in verbose mode 1939 (process-send-string ispell-process "%\n") ;put in verbose mode
1960 (process-send-string ispell-process (concat "^" word "\n")) 1940 (process-send-string ispell-process (concat "^" word "\n"))
@@ -1972,89 +1952,65 @@ The word checked is the word at the mouse position."
1972 ((null poss) 1952 ((null poss)
1973 ;; ispell error 1953 ;; ispell error
1974 (error "Ispell: error in Ispell process")) 1954 (error "Ispell: error in Ispell process"))
1975 ((string-match "GNU" (emacs-version)) 1955 ((featurep 'xemacs)
1976 ;; the word is incorrect, we have to propose a replacement
1977 (setq replace (flyspell-emacs-popup event poss word))
1978 (cond ((eq replace 'ignore)
1979 (goto-char save)
1980 nil)
1981 ((eq replace 'save)
1982 (goto-char save)
1983 (process-send-string ispell-process
1984 (concat "*" word "\n"))
1985 (flyspell-unhighlight-at cursor-location)
1986 (setq ispell-pdict-modified-p '(t)))
1987 ((or (eq replace 'buffer) (eq replace 'session))
1988 (process-send-string ispell-process
1989 (concat "@" word "\n"))
1990 (if (null ispell-pdict-modified-p)
1991 (setq ispell-pdict-modified-p
1992 (list ispell-pdict-modified-p)))
1993 (flyspell-unhighlight-at cursor-location)
1994 (goto-char save)
1995 (if (eq replace 'buffer)
1996 (ispell-add-per-file-word-list word)))
1997 (replace
1998 (flyspell-unhighlight-at cursor-location)
1999 (let ((new-word (if (atom replace)
2000 replace
2001 (car replace)))
2002 (cursor-location
2003 (+ (- (length word) (- end start))
2004 cursor-location)))
2005 (if (not (equal new-word (car poss)))
2006 (let ((old-max (point-max)))
2007 (delete-region start end)
2008 (funcall flyspell-insert-function new-word)
2009 (if flyspell-abbrev-p
2010 (flyspell-define-abbrev word new-word))
2011 (flyspell-ajust-cursor-point save
2012 cursor-location
2013 old-max)))))
2014 (t
2015 (goto-char save)
2016 nil)))
2017 ((eq flyspell-emacs 'xemacs)
2018 (flyspell-xemacs-popup 1956 (flyspell-xemacs-popup
2019 event poss word cursor-location start end save) 1957 event poss word cursor-location start end save))
2020 (goto-char save))) 1958 (t
1959 ;; The word is incorrect, we have to propose a replacement.
1960 (flyspell-do-correct (flyspell-emacs-popup event poss word)
1961 poss word cursor-location start end save)))
2021 (ispell-pdict-save t)))))) 1962 (ispell-pdict-save t))))))
2022 1963
2023;*---------------------------------------------------------------------*/ 1964;*---------------------------------------------------------------------*/
2024;* flyspell-xemacs-correct ... */ 1965;* flyspell-do-correct ... */
2025;*---------------------------------------------------------------------*/ 1966;*---------------------------------------------------------------------*/
2026(defun flyspell-xemacs-correct (replace poss word cursor-location start end save) 1967(defun flyspell-do-correct (replace poss word cursor-location start end save)
2027 "The xemacs popup menu callback." 1968 "The popup menu callback."
1969 ;; Originally, the XEmacs code didn't do the (goto-char save) here and did
1970 ;; it instead right after calling the function.
2028 (cond ((eq replace 'ignore) 1971 (cond ((eq replace 'ignore)
1972 (goto-char save)
2029 nil) 1973 nil)
2030 ((eq replace 'save) 1974 ((eq replace 'save)
2031 (process-send-string ispell-process (concat "*" word "\n")) 1975 (goto-char save)
2032 (process-send-string ispell-process "#\n") 1976 (ispell-send-string (concat "*" word "\n"))
1977 ;; This was added only to the XEmacs side in revision 1.18 of
1978 ;; flyspell. I assume its absence on the Emacs side was an
1979 ;; oversight. --Stef
1980 (ispell-send-string "#\n")
2033 (flyspell-unhighlight-at cursor-location) 1981 (flyspell-unhighlight-at cursor-location)
2034 (setq ispell-pdict-modified-p '(t))) 1982 (setq ispell-pdict-modified-p '(t)))
2035 ((or (eq replace 'buffer) (eq replace 'session)) 1983 ((or (eq replace 'buffer) (eq replace 'session))
2036 (process-send-string ispell-process (concat "@" word "\n")) 1984 (ispell-send-string (concat "@" word "\n"))
2037 (flyspell-unhighlight-at cursor-location) 1985 (flyspell-unhighlight-at cursor-location)
2038 (if (null ispell-pdict-modified-p) 1986 (if (null ispell-pdict-modified-p)
2039 (setq ispell-pdict-modified-p 1987 (setq ispell-pdict-modified-p
2040 (list ispell-pdict-modified-p))) 1988 (list ispell-pdict-modified-p)))
1989 (goto-char save)
2041 (if (eq replace 'buffer) 1990 (if (eq replace 'buffer)
2042 (ispell-add-per-file-word-list word))) 1991 (ispell-add-per-file-word-list word)))
2043 (replace 1992 (replace
1993 ;; This was added only to the Emacs side. I assume its absence on
1994 ;; the XEmacs side was an oversight. --Stef
1995 (flyspell-unhighlight-at cursor-location)
2044 (let ((old-max (point-max)) 1996 (let ((old-max (point-max))
2045 (new-word (if (atom replace) 1997 (new-word (if (atom replace)
2046 replace 1998 replace
2047 (car replace))) 1999 (car replace)))
2048 (cursor-location (+ (- (length word) (- end start)) 2000 (cursor-location (+ (- (length word) (- end start))
2049 cursor-location))) 2001 cursor-location)))
2050 (if (not (equal new-word (car poss))) 2002 (unless (equal new-word (car poss))
2051 (progn 2003 (delete-region start end)
2052 (delete-region start end) 2004 (goto-char start)
2053 (goto-char start) 2005 (funcall flyspell-insert-function new-word)
2054 (funcall flyspell-insert-function new-word) 2006 (if flyspell-abbrev-p
2055 (if flyspell-abbrev-p 2007 (flyspell-define-abbrev word new-word)))
2056 (flyspell-define-abbrev word new-word)))) 2008 ;; In the original Emacs code, this was only called in the body
2057 (flyspell-ajust-cursor-point save cursor-location old-max))))) 2009 ;; of the if. I arbitrarily kept the XEmacs behavior instead.
2010 (flyspell-ajust-cursor-point save cursor-location old-max)))
2011 (t
2012 (goto-char save)
2013 nil)))
2058 2014
2059;*---------------------------------------------------------------------*/ 2015;*---------------------------------------------------------------------*/
2060;* flyspell-ajust-cursor-point ... */ 2016;* flyspell-ajust-cursor-point ... */
@@ -2123,7 +2079,7 @@ The word checked is the word at the mouse position."
2123 (cor-menu (if (consp corrects) 2079 (cor-menu (if (consp corrects)
2124 (mapcar (lambda (correct) 2080 (mapcar (lambda (correct)
2125 (vector correct 2081 (vector correct
2126 (list 'flyspell-xemacs-correct 2082 (list 'flyspell-do-correct
2127 correct 2083 correct
2128 (list 'quote poss) 2084 (list 'quote poss)
2129 word 2085 word
@@ -2138,7 +2094,7 @@ The word checked is the word at the mouse position."
2138 (menu (let ((save (if (consp affix) 2094 (menu (let ((save (if (consp affix)
2139 (vector 2095 (vector
2140 (concat "Save affix: " (car affix)) 2096 (concat "Save affix: " (car affix))
2141 (list 'flyspell-xemacs-correct 2097 (list 'flyspell-do-correct
2142 ''save 2098 ''save
2143 (list 'quote poss) 2099 (list 'quote poss)
2144 word 2100 word
@@ -2149,7 +2105,7 @@ The word checked is the word at the mouse position."
2149 t) 2105 t)
2150 (vector 2106 (vector
2151 "Save word" 2107 "Save word"
2152 (list 'flyspell-xemacs-correct 2108 (list 'flyspell-do-correct
2153 ''save 2109 ''save
2154 (list 'quote poss) 2110 (list 'quote poss)
2155 word 2111 word
@@ -2159,7 +2115,7 @@ The word checked is the word at the mouse position."
2159 save) 2115 save)
2160 t))) 2116 t)))
2161 (session (vector "Accept (session)" 2117 (session (vector "Accept (session)"
2162 (list 'flyspell-xemacs-correct 2118 (list 'flyspell-do-correct
2163 ''session 2119 ''session
2164 (list 'quote poss) 2120 (list 'quote poss)
2165 word 2121 word
@@ -2169,7 +2125,7 @@ The word checked is the word at the mouse position."
2169 save) 2125 save)
2170 t)) 2126 t))
2171 (buffer (vector "Accept (buffer)" 2127 (buffer (vector "Accept (buffer)"
2172 (list 'flyspell-xemacs-correct 2128 (list 'flyspell-do-correct
2173 ''buffer 2129 ''buffer
2174 (list 'quote poss) 2130 (list 'quote poss)
2175 word 2131 word