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.
Related
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'.
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 :::)
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!
Geany is the closest thing I can find to the perfect web development IDE. However, I can't find a way to automatically close curly brackets ({).
For example, typing:
function test()
{
..and pressing RETURN should cause this to happen:
function test()
{
// cursor ends up here (indented by 1 tab)
}
Is there anything that can make Geany do that?
This is a native feature of Geany,
Go to Preferences, then Completions, down there you can choose which one you want to auto close.
Check here for screenshots
You make something else:
If you want, open https://plugins.geany.org/autoclose.html and see "autoclose" plugin. You can install with :
sudo apt-get install geany-plugins-autoclose
and It is all
That isn't full answer to your question, but may be helpful.
I have Geany not in english, I make translations of menu's fields on my own.
Geany has a feature: when you type special text and press Tab, the text is going to be replaced with another text.
It works by default for if, else, for, while, do, switch and try.
Configuration of this feature is in [Tools]/[Config files]/[snippets.conf].
After doing some changes, save file and click [Tools]/[Reload configuration].
I added two lines to section C++:
class=class %cursor%%block%;\n
struct=struct %cursor%%block%;\n
With block=\s{\n\t%cursor%\n}
It doesn't let you press { Enter or { Tab to get
{
//cursor
}
because {=anything is ignored, I don't know why.
What you can do? You can have some another text, replaced using {\n\t%cursor%\n}, or define keybinding inserting it.
Geany can have user defined snippets. It is possible to open snippet configuration file from menu.
Tools ->
Configuration files ->
snippets.conf
Go to the language block where you want to add that feature.
For example:
[C]
if=if (%cursor%)%block_cursor%
else=else%block_cursor%
for=for (i = 0; i < %cursor%; i++)%block_cursor%
while=while (%cursor%)%block_cursor%
do=do\n{\n\t%cursor%\n} while (%cursor%)\n%cursor%
switch=switch (%cursor%)%brace_open%case %cursor%:\n\t\t%cursor%\n\t\tbreak;\n\tdefault:\n\t\t%cursor%\n%brace_close%%cursor%
At first it can be thought that the problem can be fixed just with adding this line
{=%\n{\n\t%cursor%\n}%
But Geany does not accept that when snippet is one non alphabetic character.
It will work for any other alphabetic character like this
b=%\n{\n\t%cursor%\n}% or bl=%\n{\n\t%cursor%\n}%
However I dont think it is what you want. The real solution you can find from geanys menu.
Edit
->Preferences
->Editor
->Completions
Tick the Auto-close quotes and brackets then click on apply and save
The Auto-close doesn't work if we place brackets inside another pair of brackets. For example, the inner bracket doesn't auto-close.{{|}
However, we can use the following snippet to create a block.
{={\n\t%cursor%\n}
But in order to use this snippet, we first have to include '{' char in our wordchars set by changing the below line in snippets.conf file.
wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{
I'd like to add comments to my code (NOT commenting out lines), specifically for the period of programming and not for later use as a documentation. I just want to chalk up some task for myself inline in the code, which should automagically disappear if I distribute only the source code file.
Aside from normal "comments" while these comment appear in the source code, I don't want them to take up any line numbers, and they should be collapsible with a single click of a button. You can think of it as a meta-document to the real document (stored in a separate text file).
The idea is from Github, where you can add comments to any line of code.