简体   繁体   中英

Emacs: set key that is local to java mode.

I am inspired by this url .

It suggests setting a global key (global-set-key (kbd "RET") 'newline-and-indent) .

However, I would like to set RET to 'newline-and-indent ONLY in the Java mode. What code should I add to the init.el in order to achieve this ?

You need to apply it to the mode specific keymap. Something like the below should work.

(defun on-java-loaded ()
  (define-key java-mode-map (kbd "RET") 'newline-and-indent))

(add-hook 'java-mode-hook 'on-java-loaded)

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