[ESS] Changing keybindings in the interactive R shell
Lucas Holland
hollandlucas at gmail.com
Fri Oct 31 09:40:31 CET 2014
I use something like this which I’ve seen in the emacs wiki:
(global-set-key "\M-n" 'insert-tilde)
where insert-tilde is a function I wrote that inserts the '~' character. This solves the problem for most applications. For ESS / comint-mode I haven’t seen a clean solution. What I now have is:
(defun my-comint-bindings ()
(define-key comint-mode-map [(meta ?n)] 'insert-tilde)
(define-key comint-mode-map [(meta ?ü)] 'comint-next-matching-input-from-input)
)
and then
(add-hook 'comint-mode-hook 'my-comint-bindings)
That seems to work. Shouldn’t meta-ü (in my case) be bound to comint-next-input instead of comint-next-matching-input-from-input? According to the documentation M-n is bound to comint-next-input by default. That seems to deviate from the recommended bindings you provided.
Thanks again!
> Am 31.10.2014 um 09:33 schrieb Vitalie Spinu <spinuvit at gmail.com>:
>
>
> 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
>
[[alternative HTML version deleted]]
More information about the ESS-help
mailing list