Can I add quarto snippets in the RStudio IDE? - rstudio

I would like to add these Quarto code snippets to the RStudio IDE:
# quarto callout note
snippet con
:::{.callout-note appearance=minimal}
${1:text}
:::
# quarto callout warning
snippet cow
:::{.callout-warning appearance=simple}
${1:text}
:::
The editor will only expand the snippets if the text is inside a code chunk. Is there a fix/work-around to allow snippets in plain text?

These snippets are expanding only inside the r-code chunk for your case, probably because you have defined these snippets in the R snippet. Instead, You need to add these snippets for Markdown to get these work.
So go to Tools > Global Options > Code > Editing > Edit Snippets, and then go to the section Markdown and paste these snippets there. Save, OK, apply.
Now after writing con in qmd file and then press shift + Tab.
Also be careful about pasting the snippet, so that any extra space doesn't get pasted with these. (While I tried to paste these snippets, these didn't work at first, because of extra spaces were pasted before :::)

Related

Setup PhpStorm's to reformat code based on phpcs (codesniffer-rules from Squizlabs)

I've taken over a code base, where most of the code is following the codesniffer settings from squizlabs/PHP_CodeSniffer.
How do I setup PhpStorm to automatically reformat the code upon saving files; so I always follow those standards. Ideally I would only reformat files that I save (and not unchanged files).
I'm imagining that I'm looking for a 'Import code style from phpcs.xml.dist' or something like that. But I'm not sure.
I'm trying to avoid having going to through all the code styles line for line, figuring out if it should be if ( $blah ) { or if($blah){, and adjusting the values in Settings one setting at the time.
And bonus points, if one can point out how to do this is VSCode, while I'm at it (to help my colleagues).
Attempt 1: Read online ressources
Reformat and rearrange code
Configuring code style
EditorConfig for PhpStorm
Copy code style settings
Attempt 2: Read around 'Settings'
I went to 'Settings' >> 'Editor' >> 'Code Style' (and also >> 'PHP'). I found the 'Set from'-button, so I could set it to follow Symfony2's code style. But I'm not sure if that follows squidlabs conventions.
I also read around, to see if I could find a 'Generate code styles from code'.
Attempt 3: Generate code style from code
I know that it's a tall order, but I would have been cool, if I could have pointed PhpStorm to a couple of correctly formatted files - and then get PhpStorm to automatically generate the code style from those files. I couldn't find this.
I tried this by trying to copy some of the well-formatted code from the project into the editor in the settings-box, to see if a 'Adjust values based on example code'. But I couldn't find this.
I found the answer by carefully reading this post here: PHP_CodeSniffer.
There are several steps to it - and it's highly customizable:
Only 'flag' editted lines
Only 'flag' editted files
Which standards to use
Should it show it as a warning or an error.
Etc...
That combined with: The 'reformat on save' I found in 'Settings' >> 'Actions on save'.

Matlab script not displaying images (imshow)

As the title says, I have looked over my code and I don't see a reason that my script is not printing out the images. In particular, I have solution code that does print out the images and I don't see any differences in the code so I'm at a bit of a loss. The code does throw errors at unfinished lines, however there should still be printed images in the first few sections, the errors shouldn't interfere with that so I still don't know why they don't print out. My code is as follows:
EDIT: Some of my classmates have the same error, I suspect it might be a path issue but I'm not sure how to address that.
EDIT2: I've reformatted the post to be clearer, sorry for including extraneous parts of this code. The document is a .mlx file, hence where there is code and text interspersed. The code did not run when I used the "Run section" button, however if I copied and pasted the coded into the Command Window it would run without issue.
P = phantom('Modified Shepp-Logan',300);
figure
imshow(P);
imwrite(P, 'raw1.tif');
This section of the code seems to be working as expected when I tested it on MATLAB R2019b.
P = phantom('Modified Shepp-Logan',300);
figure
imshow(P);
imwrite(P, 'raw1.tif');
As an aside, all files will be saved to the current working directory unless otherwise specified.
Steps Taken:
To Run Script
Home Tab → New Script → Paste Script → Editor Tab → Run
and Give Script Save Name
To Easily Open Exported/Saved File:
Current Folder Side Panel → Right Click On File → Open Outside MATLAB
Results
Extension: Other Cool Tricks (to avoid running unfinished lines)
Using %% can be used to separate the script into sections. Each section can be run using the Run Section Button in the EDITOR tab or can be run using the command:
Windows: Ctrl + r
MacOS: ⌘ + r
Section 1 Code
%%
Section 2 Code
%%
Section 3 Code
Using MATLAB version: R2019b

commenting out rmarkdown in Rstudio

Duplicate question because I can not comment (Shortcut for commenting in Rmarkdown?)
in Rstudio using shift-cmd(ctrl)-c or the 'comment/uncomment' line option produces a '#' that comments out the line in the editor, but upon compiling does not comment out the line.
using " " comments out the line when compiled, but does not change the Rstudio font, making it difficult to use Rstudio for editing.
Am I missing something?
You can use cmd-shift-c (or ctrl-shift-c on Windows) to produce the comment symbol. The comment tag added varies depending on which section of the document you are working in.
If you are working inside an RMarkdown chunk then # will appear.
To comment out text outside the code chunk with <!-- --> you first need to have some text entered on the line you wish to comment then, with the cursor located anywhere on the same line, try using the shortcut.
<!-- RMarkdown text wrapped in a comment -->
```{r}
# Comment inside code chunk
```
Note commenting outside a code chunk using the shortcut doesn't work for me on a line containing only whitespace. I don't think this was the case in the previous version of RStudio (I'm using Version 1.1.383) but perhaps it's my memory that's faulty!

PyCharm: Automatically align in-line comments

I use PyCharm 2016.2 to write my Python programs. Some of my in-line comments look a little messe:
code # comment
code # comment
more code # comment
Is there a way to have PyCharm automatically align all in-line comments in a section or file on a vertical line. So it looks like this:
code # comment
code # comment
more code # comment
Related to that: I tried doing it manually, but PyCharm sometimes messes up my indentation of comments, e.g., when copying code. How can I change that?
In Pycharm, do this while your script is open: Click on Code, then click on Reformat Code (or use the shortcut). I tried it on your example and it worked.
Note: If you only want to reformat part of your script, first run your mouse over the desired portion of the script to select it. Then follow above procedure.

Visual Studio 2010 Code snippet

i have managed to make a code snippet and its all good, the question is i dont want to use ctrl+k ctrl +S then click on the snippet , instead i want to use a combination of keys to just use the snippet right away , or at least pressing ctrl+k ctrl + S then another combination ?
is that possible ?
thanks in advance...
If you say you're pressing Ctrl+K, Ctrl+S is because the snippet you added was a Surround With snippet, isn't it?
I suggest you installing ReSharper for this purpose. You can easily add all kind of snippets (called templates in ReSharper), and of course, Surround-With snippets.
After adding a template, you can give it the number you want.
Then all you have to do is press: Ctrl+Alt+J and you will see the following:
And all you have to do is press the number of the snippet you want.
For example, if you want to surround some code with an if, you press: Ctrl+Alt+J, 1.
Note:
In this moment, I don't really remember if Ctrl+Alt+J is the keyboard shortcut by default, because I have changed many of them, but you can check it in ReSharper > Edit > Surround With Template...
Easier than typing a key-combination is just typing the name+[Tab]+[Tab]. Visual Studio is pretty good at remembering the last ones used to make it even easier.
"f+[tab]+[tab]" creates a for loop snippet.
In your code snippet file, you can set up a shortcut element. Your code snippets are located under(depending on language):
"\Documents\Visual Studio 2010\Code
Snippets\Visual C#\My Code Snippets"
Under the CodeSnippet\Header\Shortcut section in the code snippet file, type a unique short relevant series of characters.
<CodeSnippet>
<Header>
<Shortcut>spi</Shortcut>
</Header>
Typing these characters followed by tab in the code window will insert your code snippet.

Resources