Closed fmichonneau closed 5 years ago
Do you need to (require 'ess-r-mode)
before binding the key?
Or put it in the :config
section of use-package?
I do use use-package
. This below makes it work. Is this the correct approach?
(use-package ess
:ensure t
:bind
(:map ess-r-mode-map
("_" . ess-insert-assign))
(:map inferior-ess-r-mode-map
("_" . ess-insert-assign))
:config
(require 'ess-r-mode)
)
I think you'd create a (use-package ess-r-mode)
block instead.
@jabranham Shouldn't this key be binded in ess-mode-map
rather than ess-r-mode-map
, since it's generic?
@fmichonneau this should work:
(use-package ess-r-mode
:bind
(:map ess-r-mode-map
("_" . ess-insert-assign))
(:map inferior-ess-r-mode-map
("_" . ess-insert-assign)))
The reason for the error you got is that you hadn't required ess-r-mode
yet, which defines ess-r-mode-map
.
@lionel- that was just meant as an example. The function (as of now, anyway) isn't /really/ generic since in any non-S-language buffer it just calls self-insert-command
.
@jabranham with just the code you included above I get the error message:
Error (use-package): ess/:catch: Symbol’s value as variable is void: ess-r-mode-map
@fmichonneau Sorry, had a typo. See the update, which should work.
Thanks that did it!
Note for others who might stumble upon this, if you were using :ensure t
, it needs to be changed to :ensure ess
.
@jabranham @lionel- @fmichonneau Why is the previous behavior (underscore setting <-
) no longer the default? Does R encourage to use =
instead of <-
as an assignment operator now?
If not, what is the preferred way of typing <-
in ESS?
We never encouraged using =
instead of <-
. Now we also don't discourage using underscores in variable names.
If not, what is the preferred way of typing <- in ESS?
You can bind ess-insert-assign
to a key that suits you, including a single key like _
, to reproduce the previous behaviour. Or use C-c C-=
which calls the more featureful ess-cycle-assign
(cycles through assignment operators rather than typed key).
Or -- what I now try to train myself to use {still have the "" working as ' <- ' and twice `as
_` on one of two computers} is the
M--
i.e. [Alt]
plus -
which directly inserts the desired "space <- space".
We had added that key combination quite a while ago ... almost simultaneously IIRC after talking with Rstudio people or seeing they use it by default.
We had added that key combination quite a while ago
hmm, I see it iness-add-MM-keys
but I don't think this is a default keybinding.
.... I'm time pressed already ... but was really unaware of that... I have told students and others about it, in the past ...
Would it be ok to move it to general? "cycle-assign" maybe a bit too sophisticated for people starting to use emacs and ESS just because they want to try using it for a "low weight" R IDE.
I'm not sure we should override the default of M--
(negative-argument).
Agreed we can't override default keybindings. Also I don't think the cycling version is too sophisticated, since beginners probably won't notice the cycling behaviour.
The cycling behaviour of C-c C-=
is nice, but I don't think it's a net win to type that key combination versus <-
. It would be nice to have a standard default binding for ess-insert-assign
given that it's such a ubiquitous operator and other R IDEs do have a shortcut.
@solna86 We're open to suggestions. The keybinding should not override anything that's standard in Emacs, should not get in the way of typing code (like _
), and should follow https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html.
Even if we find something appropriate, it will probably be tailored to the American keyboard anyway, leaving all other users needing to define their own keybinding to comfortably type <-
.
@lionel- Thanks for the detailed explanation.
Perhaps binding it to M--
as @mmaechler suggested previously? While it is true that M--
is currently used by negative-argument
, that function is also bound to C--
and C-M--
. Not sure if that makes a difference.
Some people prefer using C for prefix arguments, some M, and some C-M. I don't think we should inconvenience anyone if we can help it. It's trivial to bind ess-insert-assign
to M--
in ess-r-mode-map
for users who want it there.
We could bind it to C-c <
I suppose?
I'd be really happy if we get M--
as ess-insert-assign
in ess-r-mode-map
Additionally bind it to C-c <
is a nice idea too.
We should really entice ESS users to use either ess-insert-assign
or ess-cycle-assign
"all the time". Having it available in several ways may help getting there.
[BTW: Is ess-r-mode-map
properly activated in polymode for *.Rd
files in the '\examples{..}` section?]
[BTW: Is ess-r-mode-map properly activated in polymode for *.Rd files in the '\examples{..}` section?]
Poly Rd mode wasn't working at all. It's fixed now and R-mode is activated in \usage as well. It broke after the rewrite and, as I am not using it and no one reported issues, it stayed unnoticed. I have added a few Rd specific tests to avoid such issues in the future.
I couldn't get the options above to work, but putting this in my init file did the trick:
(require 'ess-r-mode)
(define-key ess-r-mode-map "_" 'ess-insert-assign)
(define-key inferior-ess-r-mode-map "_" 'ess-insert-assign)
For future reference, here is my snippet to enable M--
for assignment:
;; use M-- as assignment operator
;; search ess-s-lang.el for ess-add-MM-keys to get snippets for the following:
(eval-after-load "ess-mode"
'(define-key ess-mode-map [?\M--] #'ess-insert-assign)
)
(eval-after-load "ess-mode"
'(define-key inferior-ess-mode-map [?\M--] #'ess-insert-assign)
)
(If this doesn't follow good/best practice, let me know)
I'm using ess-20190110.2156. The docs say:
However if I do this, I get "Symbol’s value as variable is void: ess-r-mode-map" at startup.