Eike P.
Eike P.

Reputation: 3493

How to change smart assign key ("_" to "<-") binding in ESS

In emacs ESS, how do I correctly change the keybinding for ess-smart-S-assign?

What I tried is adding

(custom-set-variables
    '(ess-smart-S-assign-key ":"))

to my .emacs, but that made weird things happen: When I press :, just a normal : appears. On the other hand, pressing _ once yields <- as usual, whereas pressing _ a second time then converts this to :. The desired behavior would be to be able to use _ as a normal key, with : being converted to <-.

I am using the official emacs 24.3 for windows and the latest development version of ESS (14.06).

Upvotes: 2

Views: 1875

Answers (3)

maxechstack
maxechstack

Reputation: 78

Another solution is

(eval-after-load "ess-mode" '(define-key ess-mode-map (kbd "C-;") "<-"))
(eval-after-load "ess-mode" '(define-key inferior-ess-mode-map (kbd "C-;") "<-"))

This allows to restrict the binding change to ess-mode. Note that the second line defines the binding for the inferior R process.

Upvotes: 3

Drummermean
Drummermean

Reputation: 209

The accepted answer didn't work for me, but the following did:

(global-set-key (kbd "C-;")  (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)

Insert your shortkey choice instead of C-;.

Upvotes: 2

Dan
Dan

Reputation: 5369

Here's the docstring for ess-smart-S-assign-key:

Documentation:
Key used by `ess-smart-S-assign'. By default bound to
underscore, but can be set to any key. If this key is customized,
you must add

 (ess-toggle-S-assign nil)
 (ess-toggle-S-assign nil)

after the line that sets the customization and evaluate these
lines or reboot emacs. The first call clears the default
`ess-smart-S-assign' assignment and the second line re-assigns
it to the customized setting. 

So: put this in your .emacs file to get the desired behavior:

(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)

Kind of ugly, but it works.

Upvotes: 5

Related Questions