r-lib / styler

Non-invasive pretty printing of R code
https://styler.r-lib.org
Other
701 stars 71 forks source link

different keyboard shortcuts for different styles #1221

Open rinkjames opened 3 days ago

rinkjames commented 3 days ago

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?

lorenzwalthert commented 3 days ago

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}.

rinkjames commented 3 days ago

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.