5

I have this little problem, I have some key bindings like so C-. C-x or C-. C-m. After I activate the flyspell-mode, I cannot use these commands. In my .emacs file I have the next 2 lines before

(global-unset-key (kbd "C-."))
(define-key (current-global-map) (kbd "C-.") nil)
(global-set-key (kbd "C-. C-l") 'global-linum-mode) 

Then, my C-. C-l works, but it does not when the flyspell-mode is activated. The command bound to C-. is flyspell-auto-correct-word. I tried to deactivate it as follows:

;; first try
(defun flyspell-auto-correct-word-disable() (define-key (current-local-map) (kbd "C-.") nil))
(add-hook 'flyspell-mode-hook 'flyspell-auto-correct-word-disable)
;; second try
(define-key (current-global-map) [remap flyspell-auto-correct-word] nil)

None of the tries work, what can I do? I tried in Emacs 23 and 24 and I have the same issue.

François Févotte
  • 19,520
  • 4
  • 51
  • 74
silgon
  • 6,890
  • 7
  • 46
  • 67

1 Answers1

12

What about:

(eval-after-load "flyspell"
  '(define-key flyspell-mode-map (kbd "C-.") nil))

Your first solution is almost correct, but you have to remember that the current local map is set up by the major mode, not minor modes. The best option you have it to directly access flyspell-mode-map and modify it (another option would be to find it in minor-mode-map-alist but I think it would be needlessly complicated).

Also, I prefer putting such mode-specific settings within eval-after-load (which means they will be evaluated once) rather than in a hook (in which case the settings are evaluated multiple times: each time one buffer activates flyspell-mode). But this is a matter of preference and either way is fine.

François Févotte
  • 19,520
  • 4
  • 51
  • 74
  • I'm having the same issue but now with php-mode, this time I tried (eval-after-load "php" '(define-key php-mode-map (kbd "C-.") nil)) but it's not working. I know, I should change my keybinding but I'd like to know why it's not working, thanks! – silgon Apr 21 '13 at 16:58
  • I don't have `php-mode` installed on my system; is it standard? You should check which library defines `php-mode` and `php-mode-map`. This can be done by accessing emacs' documentation system with `C-h v php-mode-map` or `C-h f php-mode`. The name which you should put in the `eval-after-load` form is the library name without its ".el" suffix. – François Févotte Apr 21 '13 at 18:17
  • Thanks a lot, I was doing something wrong in my code, finally it was `(eval-after-load "php-mode" '(define-key php-mode-map (kbd "C-.") nil))`, and yes, it exists the php-mode-map – silgon Apr 21 '13 at 19:53