Skip to content
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

Add 'function_wrap' wrap shortcut #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add 'function_wrap' wrap shortcut #63

wants to merge 3 commits into from

Conversation

whtns
Copy link

@whtns whtns commented Aug 23, 2019

Add a function called 'function_wrap' that places parentheses around a given text selection and moves to cursor to a position immediately before the newly added parentheses

I often would like to wrap a text selection in a function call. One extremely common case is a call to View for a given R object from the console. This pull request makes this process smoother. I accomplish this with a slight modification to the enclose function (returning the selection)

R/internal.R Outdated
enclose <- function(prefix, postfix = prefix) {
a <- rstudioapi::getSourceEditorContext()
for (s in a$selection)
rstudioapi::insertText(location = s$range, text = sprintf("%s%s%s", prefix, s$text, postfix))

return(a)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you return this as invisible(a) please. It shouldn't bother with your addin and will not have any unintended outputs in other functions.

R/internal.R Outdated
return(a)
}

#' Function Wrap
Copy link
Collaborator

@yonicd yonicd Aug 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fill in the documentation in the same fashion as other exported functions in the package including an example. you can see one here to mimic. There must be an example for the package to be updated in CRAN.

@yonicd
Copy link
Collaborator

yonicd commented Aug 23, 2019

thank you for the pull request. please follow the contribution instructions and add all relevant files to the pull request.

@whtns
Copy link
Author

whtns commented Aug 23, 2019

Thank you for the feedback; will update and resubmit

@ColinFay
Copy link
Member

ColinFay commented Sep 3, 2019

From my perspective it would make sense to have something that allows that behaviour with other symbol like " — selecting the content, and returning before the first ".

Also, I wonder if we could pimp this with an

rstudioapi::showPrompt("Name", "What's the function name?")

So that the user is interactively asked for the function name, and it is pasted back in the document.

What do you folks think?

On another hand, it might be out of scope for {remedy} as the package is Rmd-focused 🤔

@whtns
Copy link
Author

whtns commented Sep 3, 2019

Yes, maybe this is beyond the focus of rmarkdown. It seems useful to allow this function with multiple different symbols. Besides ( and ", maybe also { as applicable in shiny development.

I really wish I could do this in the console, but can't see how.

This sounds analogous to rstudio 'extract function' and 'extract variable' shortcuts.

Thanks for the consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants