'fold up' sections of code - like when you close a control structure - optimization

I remember that there was a tag which made it possible to fold multiple lines.
e.g. like if you would fold down a for loop:
to
Is there a tag which makes this possible? Or is this an IDE specific tag?

Depends on the language and ide/editor.
In C# there are #region's that can be used for this. In some editors you can enable folding on all scopes (brackets). In some editors you can teach the editor to enable folding on comments with brackets in them ("//{" "//}").
In most cases this is an editor option that has to be enabled and configured.
What editor are you using? (and what language is this, JavaScript?)
For netbeans checkout the following: (You don't need to go past the first one)
http://wiki.netbeans.org/FaqCustomCodeFolds - Manual method
http://wiki.netbeans.org/SurroundWithCodeFolding - Code Template
https://ui.netbeans.org/docs/ui/code_folding/cf_uispec.html#custom - Talks about the how they work.
Example from first article:
// <editor-fold>
Your code goes here...
// </editor-fold>

Related

Clang format for banner style

An open-source project I contribute to uses banner style (also called Ratliff style). It looks like that:
// In C
for (i = 0; i < 10; i++) {
if (i % 2 == 0) {
doSomething(i);
}
else {
doSomethingElse(i);
}
}
Some IDE's like QtCreator have their own configurations for formatting, but others, like Visual Studio Code, require a .clang-format file.
I looked online for existing configurations, and couldn't find any. Then I tried to make one from scratch using this clang-format generator, but I couldn't manage to indent the braces right.
So, is it possible to create a clang-format file for Ratliff/Banner style, or is there some missing configuration that will force us to use some other generator?
This answer is not going to be the "answer" that you were looking for, but it is what I've discovered over the last two days of digging through the code for clang-format. I, too, have been looking for a way to auto-format a variant of banner style with clang-format.
clang-format seems to be missing some capabilities that would enable it to auto-format banner style.
For instance, you need to indent ending (right) braces for code blocks. clang-format does not even appear to track ending braces, but it does track starting (left) braces within its internals.
I started out my studying streak thinking I could understand the way clang-format implements its formatter system, so I could add the features needed to do it. Sadly it was way too complicated for me.
Perhaps someday we will be able to auto-format banner style with clang-format, but not today.
If someone out there knows this answer is inaccurate, please don't hesitate to correct me.
edit: Instead of giving you just a verification of what can't be done with clang-format, perhaps you might find http://astyle.sourceforge.net useful.

How to fold custom region in CLion through comments?

I read this:
https://www.jetbrains.com/clion/help/folding-and-expanding-custom-blocks.html
and tried following this link:
https://www.jetbrains.com/clion/help/Folding_Custom_Regions_with_Line_Comments.html
but it appears to be broken, since it redirects to "Meet CLion" page.
How do I define custom folding regions in CLion using comments?
CLion is based on IntelliJ IDEA, and thus supports multiple ways, including:
//region Description
//endregion
and
//<editor-fold desc="Description">
//</editor-fold>
These can be easily accessed by selecting the code you wish to wrap in a region, and hitting Ctrl+Alt+T. You can alternatively access it by clicking Code > Surround with... in the menu bar.

IDEA Live template $SELECTION$ doesn't work when not used with surround template

I'm creating some live templates in IntellIJ IDEA 14 and I need to do something similar to sout live template where I can write
something.sout
and become
System.out.println(something);
The sout live template is
System.out.println($END$);
So I tried using $END$ (which, according to Docs, should just change the cursor position after the change) but my template instead of taking the value before the dot adds itself at the end without text inside
Assert.assertFalse($END$);
so something.af is replaced with something.Assert.assertFalse();.
Then I tried using $SELECTION$ and it worked if used with COMMAND+ALT+J (Surround generator) but I get the same effect if I use the normal syntax with something.af
It's not a Live Template you want in this case, you want to configure a new Postfix Completion. The sout case that you were looking at was the live template version, which is, confusingly, not the same as the postfix version.
I don't think you can create your own postfix completion templates yet, it looks like you can only enable or disable existing ones (Preferences -> Editor -> General -> Postfix Completion).
You might want to vote for or comment on this suggestion to allow creation of custom templates.

switching between languages in same file

I recently attended a user group meeting where the IntelliJ representative was demonstrating version 13.
He demonstrated how to switch the code completion view of a file. I do not exactly remember what the file extension of this particular file was, probably java.
The concept was that if the file is html with embedded javascript he could then switch the code completion between html and javascript with a shortcut. If he says treat the file as html then all code in file was treated for code completion purposes as html, and vice versa for javascript.
Does anybody know what shortcut he might have been using to enable the language switch?
Sounds like you may be referring to the IntelliLang feature. IntelliJ IDEA can be aware of other languages embedded within a file.
A simple example is in an HTML file that has CSS and JavaScript.
Notice when I am inside the HTML markup:
or inside an HTML element:
The code complete shows HTML completion options. However, when I am inside the style attribute, I get CSS code completion:
I also get CSS code completion if I am inside a <style> element. So even though I am in an HTML file, I see CSS code completion because of my location.
Same case with JavaScript. When I invoke code completion inside a <script> element, I get JavaScript completion, even though I am in an HTML file.
Anytime IntelliJ IDEA can determine that another embedded language is present, it provides, via IntelliLang, the appropriate syntax highlighting, error highlighting, and code completion. The same holds true for Java. Notice here that IDEA knows the method I am competing takes an SQL statement and therefore highlights the String value using SQL highlighting, and provides SQL code completion:
So even though I am in a .java file, I get SQL code completion. The reason is that IntelliLang comes pre-configured knowing the embedded language of some methods. You modify them, or add more, in File > Settings > [Project Settings] > Language Injections.
In addition, you can use an annotation to tell IntelliJ IDEA (as well as developers looking at the code) that a String must be valid in a particular language. For example, I can annotate a String field, variable, or parameter, to indicate it must be valid HTML:
Notice I get HTML syntax highlighting, HTML code completions, and the CSS color shows in the left gutter. If I annotate a method parameter, then any time I call the method, I get the appropriate syntax highlighting, code completion, and error/warning highlighting:
The #Language annotation is inside the annotations.jar that is contained in the redist directory inside the IntelliJ IDEA installation directory. It is also available in maven central, or IDEA will offer to attach it as a Library if you use the annotation without it being attached.
IntelliLang and the #Language annotation supports a large number of languages. Just use code Completion inside the quotes after typing #Language("") to see a list. (Inline search works in the list as well.) One of the most useful is Regexp. For example, if you have a method that expects the string passed in to be a valid Regular Expression, annotating it as such will give anyone that calls it Regex code completion and error highlighting if they are passing in an invalid Regex pattern. Even for developers using other IDEs it is useful as a form of documentation.
As for a shortcut to change the the language on the fly for code completion, the only thing I can think that you might be referring to is the "Inject Language" intention. If I am entering a String value, and I bring up the quick-fix/intention menu via Alt+Enter, I am given an option to inject a language:
If I select that, IntelliJ IDEA will ask me what language I want to use:
After making my selection, IntelliJ IDEA will give me temporary language injection (including code completion) for the selected language.
It also gives me an option to add the #Language annotation for permanent injection.
To the best of my knowledge (as a 10 year IntelliJ IDEA user) that is the only way to switch code completion language types. So hopefully that is what you are looking for. To me, IntelliLang is one of the coolest features in IntelliJ. (It actually started as a third party plug-in and JetBrains then absorbed it into the product.)

Creating Dijit > Editor > Plugins

I have been googling this subject for hours. Does anyone have an examples of a custom plugin being deployed in Dijit's Editor. I'd be really interested to look at it because I have been following this without much success and of the few examples that exist out there none of them come with working examples :(
(I'm looking to create a pulldown menu like the one for font selection)
There's no difference between a custom plugin and a "builtin" plugin, so I suggest just looking at a small builtin example like TabIndent, and then move on to the font selection itself.