简体   繁体   中英

Redefining keys in emacs' ENSIME scala mode

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

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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM