2

I'm trying to redefine the "M-." in the ENSIME mode so that it runs auto-complete instead of ensime-edit-definition. Which is the default binding. I have the following code in the .emacs:

(defun my-scala-mode()
  (ensime-mode)
  (local-set-key [return] 'newline-and-indent)
  (local-unset-key (kbd "M-."))
  (local-set-key (kbd "M-.") 'auto-complete)
  (global-unset-key (kbd "M-."))
  (global-set-key (kbd "M-.") 'auto-complete)
  ;(scala-electric-mode)
  (yas/minor-mode-on))
(add-hook 'scala-mode-hook 'my-scala-mode)

However, once ensime mode loads, and somehow redefines the keys back to the default. If I comment out "(ensime-mode)" then it maps correctly.

What should I do here? Is there another mode hook I'm missing? Or should the order be different?

Thank you

oneself
  • 38,641
  • 34
  • 96
  • 120

1 Answers1

5

Apparently ensime-mode is a minor-mode, so its bindings take precedence over the major-mode's bindings. And local-set-key affects the major mode's bindings. You might want to do something like the following (guarantedd 100% untested) instead:

(require 'ensime)
(define-key ensime-mode-map (kbd "M-.") 'auto-complete)

or

(add-hook 'ensime-mode-hook (lambda () (define-key ensime-mode-map (kbd "M-.") nil)))
Stefan
  • 141
  • 1
  • It's better to define separate function for hook - it's easier to modify it, because if you'll change anonymous function and put it into hook once again, you'll have 2 copies of it, while named function will always have one entry... – Alex Ott Feb 23 '12 at 07:41