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 XDG support to key bindings, snippets, themes, and file templates #5144

Merged
merged 9 commits into from Jul 26, 2019

Conversation

jmcphers
Copy link
Member

@jmcphers jmcphers commented Jul 25, 2019

This change continues the work started in #5069, continuing to further the 1.3 goal of (a) having all configuration data in a single, configurable folder and (b) supporting global customization of all settings.

Details

Prior to this change, these files were stored in hard-coded (and occasionally inconsistent) locations in the user's home dir:

  • Themes and keybindings were in ~/.R/rstudio
  • Snippets were just in ~/.R
  • File templates were in a built-in, read-only folder

Each of these has undergone similar work:

  • All of the resources are now stored in ~/.config/rstudio (configurable)
  • For interoperability with 1.2 and prior, we support both the old and new folders. If you have any of these resources in the legacy folder location, we will continue to read from that folder. However, new content you add will be only be placed in the new folder.
  • The system folder is now read in addition to the user folder, making all of these features admin-extensible (mostly for the first time). Merging or overriding is done as appropriate.

As an example, if a user has done some customization to RStudio, here's what their ~/.config/rstudio folder might look like: it contains their preferences, key bindings, snippets, templates, and themes, all in plain, user-friendly text files.

 .
├── keybindings
│   ├── addins.json
│   ├── editor_bindings.json
│   └── rstudio_bindings.json
├── rstudio-prefs.json
├── snippets
│   └── r.snippets
├── templates
│   ├── default.R
│   ├── default.Rmd
│   ├── default.cpp
│   ├── default.js
│   └── notebook.Rmd
└── themes
    └── Brogrammer.rstheme

Templates

The templates folder deserves some special mention since it was not previously customizable. You can now define the default content for any file type. For example, to set the default content for R scripts (what you see in the editor buffer when you click File -> New R Script), you can edit:

~/.config/rstudio/templates/default.R

Some file types, such as R Markdown, have non-default templates. These are also customizable via specially named files; for example default.Rmd sets the content for blank R Markdown documents, but notebook.Rmd sets the content for blank R Markdown notebooks.

The admin guide will document the full list of special templates.

@jmcphers jmcphers requested review from MariaSemple and kevinushey Jul 25, 2019
@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 25, 2019

The templates folder deserves some special mention since it was not previously customizable. You can now define the default content for any file type. For example, to set the default content for R scripts (what you see in the editor buffer when you click File -> New R Script), you can edit:

~/.config/rstudio/templates/default.R

Some file types, such as R Markdown, have non-default templates. These are also customizable via specially named files; for example default.Rmd sets the content for blank R Markdown documents, but notebook.Rmd sets the content for blank R Markdown notebooks.

YAGNI might apply, but what do you think about allowing for multiple user-defined templates for each filetype? For example, the user might want:

~/.config/rstudio/templates/R/shiny-template.R
~/.config/rstudio/templates/R/bookdown-template.R

Ie, different templates for different single-file purposes. For now we'd only accept one template, but some theoretical day in the future this would allow us to e.g. provide a list of templates for the user to choose from (e.g. New -> From Template...)

// Add user snippets files
dirs.push_back(getSnippetsDir());

for (const auto snippetsDir: dirs)
Copy link
Contributor

@kevinushey kevinushey Jul 25, 2019

Choose a reason for hiding this comment

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

nit: const auto&; prefer ref?

Copy link
Member Author

@jmcphers jmcphers Jul 26, 2019

Choose a reason for hiding this comment

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

good idea, done!

@jmcphers
Copy link
Member Author

@jmcphers jmcphers commented Jul 25, 2019

but what do you think about allowing for multiple user-defined templates for each filetype?

I think people would find it useful, but I don't think we need to build it now as it'd be meaningless without the UI. Is there something in the existing design that you think precludes us from taking this approach in the future?

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Jul 25, 2019

Is there something in the existing design that you think precludes us from taking this approach in the future?

I don't think so -- I guess at worst we might have to migrate the default template files into filetype-specific subfolders, but that wouldn't be too bad. (I just wanted to double-check that we're at least leaving that door open; not suggesting we should take that work on now)

Copy link
Contributor

@kevinushey kevinushey left a comment

LGTM!

@jmcphers
Copy link
Member Author

@jmcphers jmcphers commented Jul 25, 2019

we might have to migrate the default template files into filetype-specific subfolders

I don't think we'd even need to do that! The file extension is sufficient:

~/.config/rstudio/templates/shiny-template.R
~/.config/rstudio/templates/bookdown-template.R

Copy link
Collaborator

@MariaSemple MariaSemple left a comment

Looks good to me!

@samgreenbergBTO
Copy link

@samgreenbergBTO samgreenbergBTO commented Aug 21, 2019

Running R Studio Version 1.3.391 on OSX, my ~/.config/rstudio folder only contains rstudio-prefs.json and /dictionaries. Any idea why I'm not seeing /templates?

@gtritchie
Copy link
Member

@gtritchie gtritchie commented Aug 22, 2019

Running R Studio Version 1.3.391 on OSX, my ~/.config/rstudio folder only contains rstudio-prefs.json and /dictionaries. Any idea why I'm not seeing /templates?

@jmcphers can confirm, but my understanding is that the templates folder doesn't exist unless you create it and add your own default file templates to it.

@jmcphers
Copy link
Member Author

@jmcphers jmcphers commented Aug 22, 2019

@samgreenbergBTO @gtritchie is correct. The ~/.config folder contains only your own content (no RStudio defaults), so you'll need to create the templates folder yourself if you want to try this out.

@samgreenbergBTO
Copy link

@samgreenbergBTO samgreenbergBTO commented Aug 24, 2019

Ok, I got it working. It works for making a new R Notebook if the template is named default.Rmd or notebook.Rmd but doesn't seem to work for R Markdown. Not really a big problem since they're functionally identical but is there a specific name for markdown template? I tried markdown.Rmd.

@jmcphers
Copy link
Member Author

@jmcphers jmcphers commented Aug 26, 2019

It's document.Rmd. The complete list can be found in pre-release versions of the admin guide:

https://docs.rstudio.com/ide/server-pro/1.3.399-1/r-sessions.html#default-document-templates

@samgreenbergBTO
Copy link

@samgreenbergBTO samgreenbergBTO commented Aug 26, 2019

Great, thank you! Very happy this feature was added.

@samgreenbergBTO
Copy link

@samgreenbergBTO samgreenbergBTO commented Aug 26, 2019

@jmcphers OK one more thing. When I create a new R notebook it loads the template as is. When I create a new R markdown it asks for title and author but even if I leave those fields blank it generates a new empty header on top of my template. If I try to create an empty document it throws an error.

@jmcphers
Copy link
Member Author

@jmcphers jmcphers commented Aug 26, 2019

Yes, if you use the wizard it's going to generate a YAML header for you, so your template should not include its own YAML header. If you want to have a YAML template in your header, use default.Rmd and the new Empty Document link in the wizard.

If you're seeing an error when creating an empty doc, please file an issue here!

@samgreenbergBTO
Copy link

@samgreenbergBTO samgreenbergBTO commented Aug 26, 2019

OK, when I go File > New File > R Markdown.. > Create Empty Document I get Error: No Such File or Directory

@valerie-rstudio valerie-rstudio deleted the feature/xdg-standardization branch Jan 21, 2022
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.

None yet

5 participants