2

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

Dan
  • 5,209
  • 1
  • 25
  • 37
Eike P.
  • 3,333
  • 1
  • 27
  • 38

3 Answers3

5

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.

Dan
  • 5,209
  • 1
  • 25
  • 37
  • Perfect, thanks for the hint! Should've found that myself, though. I just hope this will help others having the same problem, as I did not find anything really related on google. – Eike P. Aug 20 '14 at 12:34
  • This solves the issue both for R scripts and for R interactive process, thanks. – ggll Dec 02 '15 at 13:52
2

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-;.

Drummermean
  • 209
  • 3
  • 6
2

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.