[ESS] Changing keybindings in the interactive R shell
Vincent Goulet
vincent.goulet at me.com
Mon Nov 3 01:16:44 CET 2014
This is common on non-US Mac keyboards. I use a French-Canadian one and some quite non-unimportant characters are obtained using the Alt/Option key: [, ] {, } and, yes, ~, to name a few.
Here's my solution that I recommend to Lucas: use the Command key as Meta and leave Option as is. Of course, this will disable some usual Mac keybindings in Emacs, but I've found that I can easily live without them and always use the Emacs keystrokes.
To achieve this, use the following in your ~/.emacs file:
;;; ===========================
;;; Assign Meta key to Command
;;; ===========================
(setq-default ns-command-modifier 'meta) ; Command is Meta
(setq-default ns-option-modifier 'none) ; Option is Option
Hope this helps!
v.
> Le 2014-10-31 à 04:33, Vitalie Spinu <spinuvit at gmail.com> a écrit :
>
>
> That makes total sense, of course. How do other Mac users solve this
> issue?
>
> Vitalie
>
>>>> Lucas Holland on Fri, 31 Oct 2014 09:14:56 +0100 wrote:
>
>> 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
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
More information about the ESS-help
mailing list