How to stop VS code from unfolding everything on block open syntax? - visual-studio-code

Not exactly sure how to phrase this but it is incredibly annoying that when I'm writing js for example and open a comment block (/*) or a template string(`) and everything that I have folded in the following lines gets unfolded because it thinks that my comment or template string block might just extend to the very end of the whole file.
At this point I'm already in the habit of writing the end of a comment block before the beginning and copy-pasting my template strings and then editing them rather than making new ones but it would be so much nicer if I could just write without having to worry about such things, notepad++ handled it well, is there any way to make vs code behave decently too?

Related

Folding of Scala imports in Vim

I'm trying to have my Vim setup automatically fold import statements when I open a Scala file. This is similar to what Intellij does when you open a file. I currently have the following lines in my .vimrc file from the wiki.
set foldmethod=syntax
set foldenable
syn region foldImports start=/(^\s*^import\) .\+/ end=/^\s*$/ transparent fold keepend
However when I open a .scala file it doesn't fold the imports but the body of objects. I am also using the vim-scala plugin. Thanks for the help!
You were pretty close to getting this to work. There are a few funky factors at play that we should consider.
setting foldmethod to syntax (btw this is not documented on learn Vimscript the Hardway..so :help foldmethod was key to figure this out)
SYNTAX fold-syntax
A fold is defined by syntax items that have the "fold" argument.
|:syn-fold|
The fold level is defined by nesting folds. The nesting of folds is
limited with 'foldnestmax'.
Be careful to specify proper syntax syncing. If this is not done
right, folds may differ from the displayed highlighting. This is
especially relevant when using patterns that match more than one line.
In case of doubt, try using brute-force syncing:
:syn sync fromstart
The main thing to note is the sync fromstart this is a useful helper if you have regex that would match throughout the file and only want to catch the header. In your case you should be able to ignore this but just something to be aware of.
top down regex scanning
Since the import block is fairly predictable we can simplify the start and end to look something like this:
syn region foldImports start="import" end=/import.*\n^$/ fold keepend
Since the region is just looking for some string to start the matching on we can just use "import"(or /import/) and then for the end value we want to use a little bit more carefully crafted statement. The key is that we want have the end be the last line of the import with a blank line following it (/import.*\n^$/)
Hopefully that does the trick for you (I do not work with scala so you may have to adjust the regex a bit as needed)

Multi-line commenting in VB

Something that has always burned me up in programming, not just VB, is how inefficient it is to make multi-line comments. I'm not exactly a neat freak, but I do like comments to all be about the same length, around 80 characters including leading whitespace. But, to do this, I have to manually control how long the comments are. And the really frustrating part is when the change to only a few words requires an unreasonable amount of work.
I have found many questions on StackOverflow asking about multi-line commenting, but none to actually address this feature.
Wouldn't it make sense to have a commenting feature in VB, Eclipse, etc. to enter a a mini word processing mode mode that would low simple features like word wrap that would format the comment automatically? Is there one available that I'm just missing?
Or am I just being lazy? But, if it is a good idea, how can it be suggested to Microsoft, Eclipse.org, and others.
The only way to do multi-line comments in VB.NET is to do a lot of single line comments.
Really, the only option you have is the single tick (') in front of a line.
You can use Ctrl+K, Ctrl+C and Ctrl+K, Ctrl+U to comment or uncomment selected lines of text. In C# you can use /* ... */ to comment an entire block of code.
Look for more information on Custom Writing

New Lines at the End of Code Files

I've noticed what seems to be a very strong convention among IDEs and code-oriented text editors. Almost any time I create a new code file, regardless of the language, IDE, or platform on which I create the file, they almost always have a trailing new line at the end.
For example:
C++ and C# class wizards in Visual Studio always have this new line after the last curly brace.
The nano editor in the Linux terminal does not allow you to remove the last new line.
Git version control makes a specific point to point out files which do not end with a new line.
So, why is this a common practice? I've never had a problem with scripts where I intentionally remove this new line. Does it have significance for legacy purposes?
Thank you for your time.
While you would be hard pressed to find a modern editor or compiler which has issues with unterminated lines, this wasn't always the case. If you need to manipulate your source code programmatically, there are probably still e.g. sed implementations out there which are buggy in this respect.
At a minimum, you should make a conscious decision about which way you want things; if you are authoring, say, a company coding style guideline, it probably makes sense to require or recommend source files to have a final newline, because it helps avoid religious wars and supports the lowest common denominator.

Why does eclipse CDT extract function feature want to reformat unrelated code in my .cc file?

I have some C++ code that contains 5 or so lines of code that I want to refactor into a function. When I right-click->refactor->extract function, the refactor generates the function correctly, but it insists also on reformatting a large chunk of code that has nothing to do with the code I'm refactoring. Furthermore, neither the reformatted code nor the generated function fits my current style (K&R modified by me) as near as I can tell.
Why does it do this?
Is there a way to get it to follow my code style?
Is there a way to turn it off?

Can indenting affect Matlab code?

Is this possible? It shouldn't be but sometimes its behavior is quite against ordinary programming sense.
No, Matlab isn't affected by indentation.
They do have editors that will automatically indent the code for you, but it is for readability purposes only. Keeping your code readable with smart-indenting is always a good idea not only for yourself, but for others who may have to read through your code.
Note: Warnings can occur (depending on the IDE) if the indentation isn't consistent, but even sporadic indentation won't affect how your code executes in Matlab.
It'll give you warnings if you don't indent properly. If you make a if or for loop or something like that and the end block isn't inline with it you'll get a possible warning that says the statement might not be aligned with its end block. CRTL+A CTRL+I is easy enough though.