styler icon indicating copy to clipboard operation
styler copied to clipboard

different keyboard shortcuts for different styles

Open jatx50 opened this issue 1 year ago • 2 comments
trafficstars

Hi, not sure if this is possible. Sometimes I'd like to retain the (lack of) line breaks for certain lines of R code, because I think it's easier to read. I've learned how to set the style using options(styler::tidyverse_style(scope = I(c('spaces','indention','tokens')))), but it would be great to have a dedicated keyboard shortcut for styling a selection of code with this specified style. Then I can use one shortcut for invoking style_selection with the default tidyverse style, and another keyboard shortcut for invoking style_selection with the no-breaks tidyverse style.

Possible?

jatx50 avatar Jul 04 '24 19:07 jatx50

Hi, I am not sure that's easily possible due to {rstudioapi} current functionality. Technically, I think we could expose multiple addins and allow the user to parametrise each of them with a style guide (instead of relying on the options). Or make the behaviour of the styling addin dependent on some environment / option value. But I consider that out of scope for {styler.}. Also, consider using {codegrip}.

lorenzwalthert avatar Jul 05 '24 07:07 lorenzwalthert

Understood. Thanks for clarifying. I suppose I'll look into trying to achieve your first idea, with distinct addins for different styles that I can bind to different shortcuts. I looked at codegrip, but I didn't see anything that might be useful for this.

jatx50 avatar Jul 05 '24 09:07 jatx50