Jon Claus
Jon Claus

Reputation: 2932

Binding RET to newline in Emacs

In Emacs, while the major mode ESS[S] (Emacs speaks statistics) is in effect, RET is automatically bound to newline-and-ident but I would prefer it to be bound to just newline. Following the advice here, I bound RET to newline. This works for editing while in ESS, but it has the undesired effect of also affecting commands in the mini-buffer. I cannot use RET to finish commands in the mini-buffer; instead, it just inserts a new line into the mini-buffer rather than executing the command.

Is there a way to bind the key in a minor mode, but also have it not affect the mini-buffer whatsoever?

Even turning the minor-mode off doesn't seem to work and it would be cumbersome to constantly switch the minor mode on and off even if it did.

This is the relevant part of my .emacs file:

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")

(define-key my-keys-minor-mode-map (kbd "RET") 'newline)

(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  t " my-keys" 'my-keys-minor-mode-map)

(my-keys-minor-mode 1)

Upvotes: 1

Views: 255

Answers (1)

VitoshKa
VitoshKa

Reputation: 8533

You have the answer in your question:

(define-key ess-mode-map (kbd "RET") 'newline)

Upvotes: 1

Related Questions