PhpStorm code reformatter treatment of semi-colons - coding-style

I write:
$loggedInUser = new User();
$loggedInUser
->setFirstName("John")
->setLastName("Doe")
->setAge(42)
;
When I invoke PhpStorm's code reformatter, it moves the ; character up, and gives:
$loggedInUser = new User();
$loggedInUser
->setFirstName("John")
->setLastName("Doe")
->setAge(42);
Is there a way to make it use the first style, with the semi-colon in its own line, or at least not re-format it?
I looked through all the code-style settings and couldn't find anything that looked relevant, but maybe I missed some style definition, or a separate setting.
I am aware of the // #formatter:off technique, but I don't want to litter my code with it.

Please ensure that Chained method calls | Place ';' on new line option is checked:
Settings / Preferences
Editor | Code Style | PHP | Wrapping and Braces
NOTE: Currently it does not seem to work properly when such chaining is used in return statement (watch WI-34152 ticket for that).

Related

Does Sublime Text 2 have the ability to region code similar to Visual Studio?

In Visual Studio you can minimize huge chunks of code using regions; they essentially just surround the code and minimize it in the window.
Does Sublime have a feature similar to this?
By default, you can select some code the go to Edit > Code Folding > Fold. There are tons of plugins that leverage the code-folding api for more options.
There's a request on the official site to "ask for features" here.
But apparently:
FYI, Jon has stated that this is not possible in the current
implementation of the editor control. Looks like we're waiting till V3
guys.
Jon being the programmer behind Sublime Text 2.
There might be a way to fake it by creating a plugin that looks for markers and removes the code region in between the markers, but it probably wouldn't look good. With the current API, it's probably your best bet!
By the way, there is some code folding in Sublime Text, if you hover your mouse next to the line number, you will see some arrows appearing when you can fold / unfold.
I ended up using custom comment tags, indented one level less than the code I want to fold. It doesn't look best, though it serves its purpose.
class Foobar {
// ...some code
// <fold
function foo() {
}
function bar() {
}
// </fold
// more code...
}
This (at the moment) folds to:
class Foobar {
// ...some code
// <fold[...]
// </fold
// more code...
}
Having a native ST2 support for this would be nice.
This looks what you are looking for. You can define tags for #region and #endregion for each language, or a generic tag for all of them.
If you are obsessed with intendation, this solution may make you uncomfortable but here it is, once upon a time while I had been writing a semi-complex jQuery plugin I've had constants, variables, private and public functions sections and foldings like so;
;(function($, undefined, window) {...
/* Consts */
var FOO = "BAR";
/* Variables */
var m_Foo = "bar";
/* Functions */
/* Public Functions */
function foo() {...}
function bar() {...}
/* Private Functions */
function _foo() {...}
function _bar() {...}
})(jQuery, window);
As you can see it is all about intendation. Sections can be folded; Consts, Variables, Functions. And also inside Functions section, Public Functions and Private Functions are both can be folded.
You can also use one line comment (//) to name your fold. So the idea underneath that is simple; ST2 thinks that the more intended lines belongs to first less-intended comment above them, like C/C++ compilers how handle brackets as own unique code blocks.
To fold the code select the code and press
ctrl + shift + [
To unfold the code put the cursor there and press
ctrl + shift + ]
I think that like myself, the OP has come to appreciate a little-known feature in VS called regions that many equate to code-folding, but is FAR more powerful and above, Dio Phung provided the answer that I wanted, and I suspect the OP wanted, but he didn't share as an answer so here it is.
The difference between "code-folding" as it's provided in Sublime Text is that it's based on code/compiler syntax while "regions" and what this plugin does, allow you infinitely more freedom, though it's a freedom that's more or less dependant on the code you're working with to begin with (deeply nested, or properly modularized).
If you are on Sublime Text 3, here is a plugin that can do it :
github.com/jamalsenouci/sublimetext-syntaxfold – Dio Phung
In languages which support 3 types of comments (e.g. PHP) I use the hashtag comment for regions, as shown in the other answers. It's also good for keeping track of what's being done
# default options
$a = 3;
$b = 'bob';
$old_code = 1;
# bugfix #130
$result = magic_function($data);
fix_stuff($result);
$old_code = $result;
Otherwise use triple slash ///, or //# etc.
In sublime text, it works like this, it shades the lines you want to collapse and presses (Control + Shift +?)
I have the most recent version of sublimetext.

Modifying Xcode syntax highlighting to gray-out NSAssert lines

I want to modify Xcode syntax highlighting. Namely, I do a lot of 'NSAsserts', which I find visually distracting, and so I would like lines starting with 'NSAssert' to be a light gray. This way, I can focus upon my code logic instead of having to cognitively filter-out the NSAssert lines.
I use a lot of these too, and I liked your idea enough to work out the answer. Well, sort of: I have not worked out how to treat NSAsserts as a new item but I have worked out how to make them appear as comments in the syntax highlighter.
Create the directory ~/Library/Application Support/Developer/Shared/Xcode/Specifications
Copy BaseSupport.xclangspec from /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources to that directory
Apply this patch to the new copy:
--- /Developer/Library/PrivateFrameworks/XcodeEdit.framework/Versions/A/Resources/BaseSupport.xclangspec 2010-10-05 00:27:45.000000000 +0100
+++ /Users/philwill/Library/Application Support/Developer/Shared/Xcode/Specifications/BaseSupport.xclangspec 2010-12-14 11:36:51.000000000 +0000
## -100,9 +100,8 ##
Identifier = "xcode.lang.comment.singleline";
BasedOn = "xcode.lang.comment"; // for text macros
Syntax = {
- Start = "//";
- EscapeChar = "\\";
- Until = "\n";
+ StartChars = "/N";
+ Match=("//.*$","NSC?Assert[12345]?[[:space:]]*\\([^;]*\\)[[:space:]]*;");
IncludeRules = ( "xcode.lang.url", "xcode.lang.url.mail", "xcode.lang.comment.mark" );
Type = "xcode.syntax.comment";
};
Caveats:
This will mess up any //-comments
which contain escaped newline
characters. Don't do that.
This will theoretically slow down
syntax highlighting a little. I
haven't noticed any difference.
This will affect all languages you use in Xcode which normally allow //-comments.
This is the best that Xcode currently permits you to do.

Is there a shortcut to swap/reorder parameters in visual studio IDE?

I have a common issue when working with code in the IDE:
string.Concat("foo", "bar");
and I need to change it to:
string.Concat("bar", "foo");
Often I have several of these that need to be swapped at once. I would like to avoid all the typing. Is there a way to automate this? Either a shortcut or some sort of macro would be great if I knew where to start.
Edit: changed to string.Concat to show that you can't always modify the method signature. I am only looking to change the order of the params in the method call, and nothing else.
<Ctrl> + <Shift> + <t> will transpose two words, so it would work in your case. Unfortunately I don't see this working (without multiple presses) for functions with larger parameter lists...
I had a lot of code with this function:
SetInt(comboBox1.Value + 1, "paramName", ...
SetInt(comboBoxOther.Value, "paramName", ...
And I needed to swap only the first two parameters;
I ended up using some text editor with regular expression management (like Scite), and using this one saved me hours:
Find: SetInt(\([.a-z0-9]+[ + 1]*\), \("[a-z0-9]+"\)
Replace: SetInt(\2, \1

New line or Carraige Return syntax problems

Im pretty new to coding, heres my problem.
Results->Text = "G55 > Y" + System::Convert::ToString(destY);
"Results" is a System.Windows.Forms.Textbox "multiline btw", or so says VS.
That line works fine, but i need a "new line or CR" at the end, so that i can repeat that line with different Literals and a different var in ToString.
For days now ive tried different syntax's ive read about, and i cant get it to take any of them.
Or even a complete different way to input text into Results->Text that would allow for tidy multiline use.
Sidenote: since im using ->Text and System::Convert::ToString in VC, would this code be considered just c++ or .net or CLI? to tighten my searches.
Have you tried System::Environment::NewLine? This will give you CrLf on Windows and whatever is correct for Linux/OS X on those platforms.
Being completely unfamiliar with .NET, I could be completely wrong, but surely adding a + "\n" to the end of your line would do the job? Or failing that, a + "\r\n"?

Remove a keyboard shortcut binding in Visual Studio using Macros

I have a lot of custom keyboard shortcuts set up. To avoid having to set them up every time I install a new visual studio (happens quite a lot currectly, with VS2010 being in beta/RC) I have created a macro, that sets up all my custom commands, like this:
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"
My main problem is that Ctrl+T is set up to map to the transpose char command by default. So I want to remove that default value in my macro.
I have tried the following two lines, but both throw an exception
DTE.Commands.Item("Edit.CharTranspose").Bindings = ""
DTE.Commands.Item("Edit.CharTranspose").Bindings = Nothing
Although they kind of work, because they actually remove the binding ;) But I would prefer the solution that doesn't throw an exception.
How is that done?
I have coped with the same issue. I use a macro to assign key bindings for a set of align macros.
Dim NewBindings() = {"Global::Alt+="}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignEquals").Bindings = NewBindings
NewBindings(0) = "Global::Alt+Num -"
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignMinus").Bindings = NewBindings
...
And to remove key bindings i use the following statements :
Dim DelBindings() = {}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignPlus").Bindings = DelBindings
It works fine under Visual Studio 2005.
I followed a little more pragmatic way (using your example):
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T"
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"
With the first assignment Ctrl+T is unassigned from any other function and then becomes unbound with the second assignment.
Works like a charm for me.
You do not need to change it with macro, Just go to
Menu>Tools>Options -- Keyboard and then select what you want to change the shortcut from the dropdown and assignyour desiered short cut

Resources