[ESS] Changing keybindings in the interactive R shell

Lucas Holland hollandlucas at gmail.com
Fri Oct 31 09:14:56 CET 2014


Hi Vitalie,

thanks for your reply. The reason I want to do such a foolish thing is because my keyboard (Mac) doesn’t have a tilde key. By default, Alt-n produces a tilde (this is OS-wide). That’s why I thought it would make sense to stick with that convention for Emacs (so I don’t have a different keybinding for one program) and to bind comint-next-matching-input-from-input to something else other than M-n. 

What would you do in such a situation?

Thanks!



> 
> 
>>>> Lucas Holland on Thu, 30 Oct 2014 11:52:26 +0100 wrote:
> 
> [...]
> 
>> (add-hook 'inferior-ess-mode-hook
>> 	    '(lambda()
>> 	       (local-set-key [\M-n] '(lambda () (interactive) (insert "~")))
>> 	       ))
> 
> This is a wrong syntax. A couple of related points first:
> 
> - Don't overwrite useful keys like M-n to unrelated commands. If you
>   go to that path you will have to overwrite them for all other
>   repls.
> 
> - How is pressing M-n better than "~"? You are forgoing a handy key for
>   the sake of a symbol which is already on the keyboard.
> 
> - M-n is a comint key so you will probably want to hook it into
>   comint-mode-map to have the same functionality across all repls.
> 
> So, the right syntax and recommended bindings are:
> 
>   (define-key comint-mode-map [(meta ?p)] 'comint-previous-matching-input-from-input)
>   (define-key comint-mode-map [(meta ?n)] 'comint-next-matching-input-from-input)
>   (define-key comint-mode-map [(control meta ?n)] 'comint-next-prompt)
>   (define-key comint-mode-map [(control meta ?p)] 'comint-previous-prompt)
> 
> For ess use `inferior-ess-mode-map` instead of `comint-mode-map`.
> 
> For most people `comint-previous-matching-input-from-input` is one of
> the most commonly used commands. You better get used to it also.
> 
> 
>  Vitalie



More information about the ESS-help mailing list