diff options
| author | Eli Zaretskii | 2015-12-31 17:44:07 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2015-12-31 17:44:07 +0200 |
| commit | 6d11f6ed9a1afa6f3903fffeb58159beedeb1d14 (patch) | |
| tree | 318cac683bad565a0cb7c91b45169079173f51c5 | |
| parent | bb83bb11f9c38199e413045300acf6ef04f67b4a (diff) | |
| download | emacs-6d11f6ed9a1afa6f3903fffeb58159beedeb1d14.tar.gz emacs-6d11f6ed9a1afa6f3903fffeb58159beedeb1d14.zip | |
Allow to invoke original M-TAB binding in 'flyspell-prog-mode'
* lisp/textmodes/flyspell.el (flyspell-prog-mode): Record the
original M-TAB binding in a buffer-local variable.
(flyspell-auto-correct-word): Invoke the original binding of M-TAB
if that is recorded, when point is in a place where flyspell
should not be active (e.g., because the user turned on
'flyspell-prog-mode'). (Bug#18533)
| -rw-r--r-- | lisp/textmodes/flyspell.el | 210 |
1 files changed, 111 insertions, 99 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 6c4a731629c..8d13aa1dd5b 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el | |||
| @@ -399,6 +399,9 @@ like <img alt=\"Some thing.\">." | |||
| 399 | (interactive) | 399 | (interactive) |
| 400 | (setq flyspell-generic-check-word-predicate | 400 | (setq flyspell-generic-check-word-predicate |
| 401 | #'flyspell-generic-progmode-verify) | 401 | #'flyspell-generic-progmode-verify) |
| 402 | (setq-local flyspell--prev-meta-tab-binding | ||
| 403 | (or (local-key-binding "\M-\t" t) | ||
| 404 | (global-key-binding "\M-\t" t))) | ||
| 402 | (flyspell-mode 1) | 405 | (flyspell-mode 1) |
| 403 | (run-hooks 'flyspell-prog-mode-hook)) | 406 | (run-hooks 'flyspell-prog-mode-hook)) |
| 404 | 407 | ||
| @@ -1904,105 +1907,114 @@ before point that's highlighted as misspelled." | |||
| 1904 | "Correct the current word. | 1907 | "Correct the current word. |
| 1905 | This command proposes various successive corrections for the current word." | 1908 | This command proposes various successive corrections for the current word." |
| 1906 | (interactive) | 1909 | (interactive) |
| 1907 | (let ((pos (point)) | 1910 | ;; If we are not in the construct where flyspell should be active, |
| 1908 | (old-max (point-max))) | 1911 | ;; invoke the original binding of M-TAB, if that was recorded. |
| 1909 | ;; Use the correct dictionary. | 1912 | (if (and (local-variable-p 'flyspell--prev-meta-tab-binding) |
| 1910 | (flyspell-accept-buffer-local-defs) | 1913 | (commandp flyspell--prev-meta-tab-binding t) |
| 1911 | (if (and (eq flyspell-auto-correct-pos pos) | 1914 | (fboundp flyspell-generic-check-word-predicate) |
| 1912 | (consp flyspell-auto-correct-region)) | 1915 | (not (funcall flyspell-generic-check-word-predicate)) |
| 1913 | ;; We have already been using the function at the same location. | 1916 | (equal (where-is-internal 'flyspell-auto-correct-word nil t) |
| 1914 | (let* ((start (car flyspell-auto-correct-region)) | 1917 | [?\M-\t])) |
| 1915 | (len (cdr flyspell-auto-correct-region))) | 1918 | (call-interactively flyspell--prev-meta-tab-binding) |
| 1916 | (flyspell-unhighlight-at start) | 1919 | (let ((pos (point)) |
| 1917 | (delete-region start (+ start len)) | 1920 | (old-max (point-max))) |
| 1918 | (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring)) | 1921 | ;; Use the correct dictionary. |
| 1919 | (let* ((word (car flyspell-auto-correct-ring)) | 1922 | (flyspell-accept-buffer-local-defs) |
| 1920 | (len (length word))) | 1923 | (if (and (eq flyspell-auto-correct-pos pos) |
| 1921 | (rplacd flyspell-auto-correct-region len) | 1924 | (consp flyspell-auto-correct-region)) |
| 1922 | (goto-char start) | 1925 | ;; We have already been using the function at the same location. |
| 1923 | (if flyspell-abbrev-p | 1926 | (let* ((start (car flyspell-auto-correct-region)) |
| 1924 | (if (flyspell-already-abbrevp (flyspell-abbrev-table) | 1927 | (len (cdr flyspell-auto-correct-region))) |
| 1925 | flyspell-auto-correct-word) | 1928 | (flyspell-unhighlight-at start) |
| 1926 | (flyspell-change-abbrev (flyspell-abbrev-table) | 1929 | (delete-region start (+ start len)) |
| 1927 | flyspell-auto-correct-word | 1930 | (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring)) |
| 1928 | word) | 1931 | (let* ((word (car flyspell-auto-correct-ring)) |
| 1929 | (flyspell-define-abbrev flyspell-auto-correct-word word))) | 1932 | (len (length word))) |
| 1930 | (funcall flyspell-insert-function word) | 1933 | (rplacd flyspell-auto-correct-region len) |
| 1931 | (flyspell-word) | 1934 | (goto-char start) |
| 1932 | (flyspell-display-next-corrections flyspell-auto-correct-ring)) | 1935 | (if flyspell-abbrev-p |
| 1933 | (flyspell-ajust-cursor-point pos (point) old-max) | 1936 | (if (flyspell-already-abbrevp (flyspell-abbrev-table) |
| 1934 | (setq flyspell-auto-correct-pos (point))) | 1937 | flyspell-auto-correct-word) |
| 1935 | ;; Fetch the word to be checked. | 1938 | (flyspell-change-abbrev (flyspell-abbrev-table) |
| 1936 | (let ((word (flyspell-get-word))) | 1939 | flyspell-auto-correct-word |
| 1937 | (if (consp word) | 1940 | word) |
| 1938 | (let ((start (car (cdr word))) | 1941 | (flyspell-define-abbrev flyspell-auto-correct-word word))) |
| 1939 | (end (car (cdr (cdr word)))) | 1942 | (funcall flyspell-insert-function word) |
| 1940 | (word (car word)) | 1943 | (flyspell-word) |
| 1941 | poss ispell-filter) | 1944 | (flyspell-display-next-corrections flyspell-auto-correct-ring)) |
| 1942 | (setq flyspell-auto-correct-word word) | 1945 | (flyspell-ajust-cursor-point pos (point) old-max) |
| 1943 | ;; Now check spelling of word.. | 1946 | (setq flyspell-auto-correct-pos (point))) |
| 1944 | (ispell-send-string "%\n") ;Put in verbose mode. | 1947 | ;; Fetch the word to be checked. |
| 1945 | (ispell-send-string (concat "^" word "\n")) | 1948 | (let ((word (flyspell-get-word))) |
| 1946 | ;; Wait until ispell has processed word. | 1949 | (if (consp word) |
| 1947 | (while (progn | 1950 | (let ((start (car (cdr word))) |
| 1948 | (accept-process-output ispell-process) | 1951 | (end (car (cdr (cdr word)))) |
| 1949 | (not (string= "" (car ispell-filter))))) | 1952 | (word (car word)) |
| 1950 | ;; Remove leading empty element. | 1953 | poss ispell-filter) |
| 1951 | (setq ispell-filter (cdr ispell-filter)) | 1954 | (setq flyspell-auto-correct-word word) |
| 1952 | ;; Ispell process should return something after word is sent. | 1955 | ;; Now check spelling of word.. |
| 1953 | ;; Tag word as valid (i.e., skip) otherwise. | 1956 | (ispell-send-string "%\n") ;Put in verbose mode. |
| 1954 | (or ispell-filter | 1957 | (ispell-send-string (concat "^" word "\n")) |
| 1955 | (setq ispell-filter '(*))) | 1958 | ;; Wait until ispell has processed word. |
| 1956 | (if (consp ispell-filter) | 1959 | (while (progn |
| 1957 | (setq poss (ispell-parse-output (car ispell-filter)))) | 1960 | (accept-process-output ispell-process) |
| 1958 | (cond | 1961 | (not (string= "" (car ispell-filter))))) |
| 1959 | ((or (eq poss t) (stringp poss)) | 1962 | ;; Remove leading empty element. |
| 1960 | ;; Don't correct word. | 1963 | (setq ispell-filter (cdr ispell-filter)) |
| 1961 | t) | 1964 | ;; Ispell process should return something after word is sent. |
| 1962 | ((null poss) | 1965 | ;; Tag word as valid (i.e., skip) otherwise. |
| 1963 | ;; Ispell error. | 1966 | (or ispell-filter |
| 1964 | (error "Ispell: error in Ispell process")) | 1967 | (setq ispell-filter '(*))) |
| 1965 | (t | 1968 | (if (consp ispell-filter) |
| 1966 | ;; The word is incorrect, we have to propose a replacement. | 1969 | (setq poss (ispell-parse-output (car ispell-filter)))) |
| 1967 | (let ((replacements (if flyspell-sort-corrections | 1970 | (cond |
| 1968 | (sort (car (cdr (cdr poss))) 'string<) | 1971 | ((or (eq poss t) (stringp poss)) |
| 1969 | (car (cdr (cdr poss)))))) | 1972 | ;; Don't correct word. |
| 1970 | (setq flyspell-auto-correct-region nil) | 1973 | t) |
| 1971 | (if (consp replacements) | 1974 | ((null poss) |
| 1972 | (progn | 1975 | ;; Ispell error. |
| 1973 | (let ((replace (car replacements))) | 1976 | (error "Ispell: error in Ispell process")) |
| 1974 | (let ((new-word replace)) | 1977 | (t |
| 1975 | (if (not (equal new-word (car poss))) | 1978 | ;; The word is incorrect, we have to propose a replacement. |
| 1976 | (progn | 1979 | (let ((replacements (if flyspell-sort-corrections |
| 1977 | ;; the save the current replacements | 1980 | (sort (car (cdr (cdr poss))) 'string<) |
| 1978 | (setq flyspell-auto-correct-region | 1981 | (car (cdr (cdr poss)))))) |
| 1979 | (cons start (length new-word))) | 1982 | (setq flyspell-auto-correct-region nil) |
| 1980 | (let ((l replacements)) | 1983 | (if (consp replacements) |
| 1981 | (while (consp (cdr l)) | 1984 | (progn |
| 1982 | (setq l (cdr l))) | 1985 | (let ((replace (car replacements))) |
| 1983 | (rplacd l (cons (car poss) replacements))) | 1986 | (let ((new-word replace)) |
| 1984 | (setq flyspell-auto-correct-ring | 1987 | (if (not (equal new-word (car poss))) |
| 1985 | replacements) | 1988 | (progn |
| 1986 | (flyspell-unhighlight-at start) | 1989 | ;; the save the current replacements |
| 1987 | (delete-region start end) | 1990 | (setq flyspell-auto-correct-region |
| 1988 | (funcall flyspell-insert-function new-word) | 1991 | (cons start (length new-word))) |
| 1989 | (if flyspell-abbrev-p | 1992 | (let ((l replacements)) |
| 1990 | (if (flyspell-already-abbrevp | 1993 | (while (consp (cdr l)) |
| 1991 | (flyspell-abbrev-table) word) | 1994 | (setq l (cdr l))) |
| 1992 | (flyspell-change-abbrev | 1995 | (rplacd l (cons (car poss) replacements))) |
| 1993 | (flyspell-abbrev-table) | 1996 | (setq flyspell-auto-correct-ring |
| 1994 | word | 1997 | replacements) |
| 1995 | new-word) | 1998 | (flyspell-unhighlight-at start) |
| 1996 | (flyspell-define-abbrev word | 1999 | (delete-region start end) |
| 1997 | new-word))) | 2000 | (funcall flyspell-insert-function new-word) |
| 1998 | (flyspell-word) | 2001 | (if flyspell-abbrev-p |
| 1999 | (flyspell-display-next-corrections | 2002 | (if (flyspell-already-abbrevp |
| 2000 | (cons new-word flyspell-auto-correct-ring)) | 2003 | (flyspell-abbrev-table) word) |
| 2001 | (flyspell-ajust-cursor-point pos | 2004 | (flyspell-change-abbrev |
| 2002 | (point) | 2005 | (flyspell-abbrev-table) |
| 2003 | old-max)))))))))) | 2006 | word |
| 2004 | (setq flyspell-auto-correct-pos (point)) | 2007 | new-word) |
| 2005 | (ispell-pdict-save t))))))) | 2008 | (flyspell-define-abbrev word |
| 2009 | new-word))) | ||
| 2010 | (flyspell-word) | ||
| 2011 | (flyspell-display-next-corrections | ||
| 2012 | (cons new-word flyspell-auto-correct-ring)) | ||
| 2013 | (flyspell-ajust-cursor-point pos | ||
| 2014 | (point) | ||
| 2015 | old-max)))))))))) | ||
| 2016 | (setq flyspell-auto-correct-pos (point)) | ||
| 2017 | (ispell-pdict-save t)))))))) | ||
| 2006 | 2018 | ||
| 2007 | ;;*---------------------------------------------------------------------*/ | 2019 | ;;*---------------------------------------------------------------------*/ |
| 2008 | ;;* flyspell-auto-correct-previous-pos ... */ | 2020 | ;;* flyspell-auto-correct-previous-pos ... */ |