[ESS] How to get the assign-key <- via command + return?

Kasper Daniel Hansen kasperdanielhansen at gmail.com
Sun Sep 11 15:46:12 CEST 2011


Step 1: figure out what function you want to bind to the key.  Here
you can use that you know the function is already bound to underscore,
so pressing
  C-h k _
(C-h k is "help on key"), tells me that the function is called
ess-smart-underscore.

Step 2: figure out what key you are pressing.  I have never seen the
'A' for the command key.  You know of 'meta' and 'control' and
'shift'.  Modern Emacs have two other keys 'hyper' and 'super' (abbr h
and s), which various keys on the keyboard can be bound to.  In my
experience the Apple key yields either super or hyper in Emacs, but
that may depend on Emacs version.

You figure this out by pressing C-h k again:
  on my apply laptop when I press
  C-h k Apple+Return
I get
  <H-return> is undefined.

So now I have the key and the function.  All that remains to do is
bind it.  Use something like
  (add-hook 'ess-mode-hook
	  (lambda ()
 	    (define-key ess-mode-map [(hyper return)] 'ess-smart-underscore)
))

This defines the key only in ess-mode.  If you have other modes where
you want to bind it, you need to figure out what the hook and mode-map
is called, but it is usually (always I think) the name of the mode.

Kasper


On Sun, Sep 11, 2011 at 8:20 AM, Hofert  Jan Marius
<marius.hofert at math.ethz.ch> wrote:
> Dear ess-experts,
>
> I am a new user of Aquamacs and it helps me a lot to have some "native Apple commands" available which I got used to over the last years. I was wondering how I can get ESS to accept the keystroke "Command (= Apple key) + Return" to give me the assignment arrow "<-".
> I read some posts I found and tried to adapt those, but Aquamacs reports errors on startup...
> I don't need/want to change the smart underscore behavior, I just want to add this additional way of putting in the assignment key "<-".
>
> Here are things I tried:
> ;; define command + return as arrow in R:
> (define-key osx-key-mode-map (kbd "A-<return>") 'ess-S-assign-key)
> (setq ess-S-assign-key (kbd "A-<return>"))
> (ess-toggle-S-assign-key t)
> (ess-toggle-underscore nil)
>
> Obviously, this does not work. I am not even sure if I address the keys correctly, I also tried <RET>, for example. For the Apple key, I am also not sure if "A" is correct (however, I found it under http://www.emacswiki.org/emacs/CustomizeAquamacs)
> I tried either one of the first two lines, the second I found online, the first is similar to what I found out to define a keystroke for "eval buffer till here" (which works well and even shows up in the menus):
> (define-key osx-key-mode-map (kbd "C-c C-<up>") 'ess-eval-buffer-from-beg-to-here)
>
> Cheers,
>
> Marius
>
>
>
> ETH Zurich
> Dr. Marius Hofert
> RiskLab, Department of Mathematics
> HG E 65.2
> Rämistrasse 101
> 8092 Zurich
> Switzerland
>
> Phone +41 44 632 2423
> marius.hofert at math.ethz.ch
> http://www.math.ethz.ch/~hofertj
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>



More information about the ESS-help mailing list