-
Notifications
You must be signed in to change notification settings - Fork 73
Handle styling of an unsaved active file #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
R/addins.R
Outdated
@@ -3,7 +3,15 @@ | |||
#' Helper function for RStudio Addin. | |||
style_active_file <- function() { | |||
context <- get_rstudio_context() | |||
style_file(context$path, style = tidyverse_style) | |||
if (context$path != "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of case distinction here? Can't we just use rstudioapi
to handle all cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just assumed I should avoid changing the current behaviour for the case when the active file has been saved (i.e that it is styled and saved).
Was your intention with #235 to just modify (without saving) in all cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, I suggest to stick with rstudioapi
throughout. See #235 (comment).
Thanks for working on that Jon. |
Let's do away with these startup messages and implement the default to not save after styling. We can maybe add a help file "styler_addins" (with an alias "style_fule" and friends) where we describe each addin and the option quickly and make reference to .Rprofile. |
On that note, I've noticed that styling a chunk in an The name of the menu item "Style active region" may be confusing, can we change to "Style selection"? |
Thanks for picking that up @krlmlr - was that using the add-in implementation from this branch or an earlier version? I didn't do extensive testing and haven't looked at this recently so will need to check again later when I'm home. I agree with the suggested name change - @lorenzwalthert if you are happy with that too can I include it in this PR? |
This was with styler from master. |
Yes, I am happy with the name change in this PR |
As far as the lost end-of-chuck line breaks goes, I think that's not related primarily to this PR, but styler drop lines at the end anyways, reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-10-26
styler::style_text("1++1\n")
#> 1 + +1 That stems from the fact that we don't have an end token. See discussions around start tokens in #218, #44 and #4. We always have a final line blank if we use functions that use |
@jonmcalder please take note of #264 and adapt the PR accordingly. |
The closing backticks in a |
Also @jonmcalder can you please rebase on master because then we can test on |
5a59832
to
3f07d8d
Compare
Ok @krlmlr now I get what you mean. If I recall correctly we had that problem with |
Ok documentation added/updated - I think this should be ready for review now @lorenzwalthert. My understanding is that the above conversation around refining the usage of So just to summarize the content of this PR again:
|
R/addins.R
Outdated
#' @section Auto-Save Option: | ||
#' By default, both of the RStudio Addins will apply styling to the (selected) | ||
#' file contents without saving changes. Automatic saving can be enabled by | ||
#' setting the environment variable \code{save_after_styling} to \code{TRUE}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use markdown roxygen, so can you please change
\code{...}
to
`...`
here and elsewhere in the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Sorry, old habits...
R/addins.R
Outdated
#' Helper function for RStudio Addin. This function is complicated because of | ||
#' one thing: You can highlight also just parts of lines. | ||
|
||
#' @describeIn styler_addins Styles the highlighted region | ||
#' @importFrom rlang seq2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the rlang
import is redundant. Can you remove as part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
Ok, thanks @jonmcalder. For me it's ok to solve the problem with the back-ticks brought up by @krlmlr later. I already solved it in some branch, so I will add the commits after we merged this PR. One last thing: Would you mind updating |
…tyler_addins docs
@@ -7,7 +7,8 @@ | |||
#' * [style_file()] to style a single .R file. | |||
#' * [style_dir()] to style all .R files in a directory. | |||
#' * [style_pkg()] to style the source files of an R package. | |||
#' * An RStudio Addin to style the active file .R file and the current package. | |||
#' * [styler_addins] (RStudio Addins) to style either selected code or the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add two braces after styler_addins
(as it is done with style_pkg()
etc. above) to not just make a reference, but also use code font markup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was deliberately trying to avoid making the reference look like a function since it's not. Does that distinction not really matter here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that actually makes sense. You are right.
Thanks |
- Adapt documentation (#290). - Add roundtrip (#287). - Fix AppVeyor builds. - Fix token insertion / comment interaction (#279). - Clarify labelling strategy (#285). - Fixing and extending Rstudioaddins (#283). - Fix eq assign parsing (#276). - style_files -> vectorized style_file (#273). - Refactoring (#270). - Fix CI (#275). - Fix covr (#274). - Renaming files (#271). - Handle styling of an unsaved active file (#243). - Test R 3.1 and R 3.2 (#249). - Allow empty {} without line break (#261). - Wrap expr in expr before enclosing with curly braces (#263). - Avoid checking for hard-coded dot (#262). - Account for dependency renaming (utf8 changed to enc) (#264). - Indention of function declaration and closing braces (#260). - Only remove line break before closing with strict option (#252).
Fixes #235