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)
This commit is contained in:
Eli Zaretskii 2015-12-31 17:44:07 +02:00
parent bb83bb11f9
commit 6d11f6ed9a

View file

@ -399,6 +399,9 @@ like <img alt=\"Some thing.\">."
(interactive) (interactive)
(setq flyspell-generic-check-word-predicate (setq flyspell-generic-check-word-predicate
#'flyspell-generic-progmode-verify) #'flyspell-generic-progmode-verify)
(setq-local flyspell--prev-meta-tab-binding
(or (local-key-binding "\M-\t" t)
(global-key-binding "\M-\t" t)))
(flyspell-mode 1) (flyspell-mode 1)
(run-hooks 'flyspell-prog-mode-hook)) (run-hooks 'flyspell-prog-mode-hook))
@ -1904,6 +1907,15 @@ before point that's highlighted as misspelled."
"Correct the current word. "Correct the current word.
This command proposes various successive corrections for the current word." This command proposes various successive corrections for the current word."
(interactive) (interactive)
;; If we are not in the construct where flyspell should be active,
;; 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)
(not (funcall flyspell-generic-check-word-predicate))
(equal (where-is-internal 'flyspell-auto-correct-word nil t)
[?\M-\t]))
(call-interactively flyspell--prev-meta-tab-binding)
(let ((pos (point)) (let ((pos (point))
(old-max (point-max))) (old-max (point-max)))
;; Use the correct dictionary. ;; Use the correct dictionary.
@ -2002,7 +2014,7 @@ This command proposes various successive corrections for the current word."
(point) (point)
old-max)))))))))) old-max))))))))))
(setq flyspell-auto-correct-pos (point)) (setq flyspell-auto-correct-pos (point))
(ispell-pdict-save t))))))) (ispell-pdict-save t))))))))
;;*---------------------------------------------------------------------*/ ;;*---------------------------------------------------------------------*/
;;* flyspell-auto-correct-previous-pos ... */ ;;* flyspell-auto-correct-previous-pos ... */