Sublime text 4 curly bracket indentation problem - auto-indent

Sublime text 4 is giving weird indentation when pressing enter between curly braces
for(int i=0;i<10;++i){
}
In some already opened file it is working fine by indenting like this :
for(int i=0;i<10;++i){
}
I tried disabling packages and re enabling them but no success, can someone please help.
Thanks!

Related

Unexpected whitespace between function name and paren.(func-call-spacing), A space is required before '}'.(object-curly-spacing), webstorm quasar vue

I'm new to using stackoverflow and using WebStorm quasar,and vuejs, so let me know if you need any more details or if I did something wrong.
pictures of code errors:
https://drive.google.com/drive/folders/13oSjnK6Q21ztsihbcF0a-TUUAWAo0vcW?usp=sharing
errors:
ESLint: A space is required after '{'.(object-curly-spacing)
enter image description here
ESLint: Unexpected whitespace between function name and paren.(func-call-spacing)
I correct these errors by adding the correct spacing, but whenever I refresh the website, I'm working on, WebStorm changes them back.
I believe its some sort of a formatting error.
I've gone into,
Settings->Editor->Code Style -> JavaScript
Settings->Editor->Code Style -> TypeScript
and clicked on spaces, and check the appropriate boxes.
spaces - before parenthesis - function call parenthesis
spaces - within - object literal braces
but the problem still persists.
You should have disabled the Spaces > Before parentheses > Function call parentheses and enabled the Within > ES6 Import/Export Braces in Settings | Editor | Code Style | JavaScript; please also make sure that you don't have the IDE code style preferences overwritten by the settings in project .editorconfig (if any)

Intellij: add space after double slashes in line comment

Is there a way in Intellij IDEA (I'm using version 13) to automatically add a space to line comments between the two slashes and the text:
If I enter :
//This is a comment
I'd like to get the following when I run a code reformat (Ctrl-Alt-L on Windows)
// This is a comment
It's for Javascript files but should be working for other file types.
If you press CTRL / or CMD / it will put // at the beginning of the line and the comment will be properly indented.
// comment with two indents
For this to work Comment at first column must be checked in Editor->CodeStyle->Javascript->Wrapping and Braces->Keep when reformatting like mentioned in another answer.
This screenshot is for Java, but it works the same for Javascript. Just choose javascript in the menu
If you want to write multiline comment you can use CTRL SHIFT / or CMD SHIFT / That way when you go into new line, you will have one space after the comment start
/*
* there is space before this*/

Why can't I comment out this string?

I'm unable to comment-out and compile the following line of code with /* */, within the XCode editor. I distilled this example down from a more complex string used in an XPath query:
the string itself seems fine:
NSString* s = #"//*//";
won't compile for me:
/*
NSString* s = #"//*//";
*/
XCode 4.4. I'll file a radar if anyone can confirm I'm not being stupid.
EDIT: nice to see that the SO syntax highlighter also exhibits an issue with this...
EDIT: okay, I filed a bug report with Apple. Thanks.
EDIT: Per Rob's answer below, this is NOT a bug :) Thanks for explaining it, Rob; totally makes sense now.
This is not a compiler bug. The double-quote character " has no special meaning inside a comment, so the preprocessor doesn't pay any attention to it. The preprocessor just ends the comment as soon as it sees the */ characters.
The best way to comment out a section of code is to put // at the beginning of each line. A // comment ends at the next newline. Xcode has a menu command (shortcut: ⌘/) that will comment or uncomment your selected lines by inserting or removing // at the start of each line.
It detects and end comment in #"//*//"; I don't know of any editor that allows nesting of block comments (I know that's not what you're doing, but same issue). Notice how even the syntax highlighter on SO screws up.

unexpected '#' in program (Xcode)

All of the sudden Xcode is giving me an error "unexpected '#' in program" at the beginning of my object #interface.
This is happening in a bunch of my objects that were previously working...
Here's an example (with errors in comments)
#import <UIKit/UIKit.h>
#import "ONCOChordDiamond.h"
#interface ONCOChordView : UIView //// unexpected '#' in program
{
NSMutableArray* chordDiamonds;
NSUInteger diamondWidth, diamondHeight;
}
#end /////unexpected '#' in program'
So why is Xcode giving me this error? It seems like a bug.
I doubt you're still having the issue, but if you are check the header file. I pasted in code from the web in a class and the quotation marks weren't the standard " ". The marks were stylized with an opening quote and a closing quote because it came from a webpage. Retyping the quote marks fixed it.
You are including the header from a file that is not compiled as Objective C.
Check for syntax errors in the ONCOChordDiamond.h file. They may be highlighted for you if you run Product > Analyze in Xcode.
Importing a file with syntax errors could lead to the compiler not being able to parse the current file correctly, even if the current file's syntax is correct.
When encountering this problem with NSString literals, Check that you have used quotation marks, as required.
(eg. #"myString")
If you find your NSStrings are not correctly syntax coloured, you might check for the following offending characters.
" (QUOTATION MARK)
″ (DOUBLE PRIME)
“ (LEFT DOUBLE QUOTATION MARK)
” (RIGHT DOUBLE QUOTATION MARK)
For what it's worth, I had this issue and the offending line that was identified was nowhere near any string literals.
I did notice that some of the following lines were colored oddly (again, no string literals to blame), so I tested out putting a bogus string literal in the code just before the offending line.
NSString *whatever = #"";
Apparently, it convinced the compiler that the line wasn't screwed up, so it then compiled just fine without complaining. After that build, I was able to delete the bogus string variable and move on with my life.
I had a similar problem and it was because the last quote was getting escaped out. I was using a multiline string with a terminating "\" to eat up the end of line character.
[ string appendFormat:#"\n\
vec4 position;\n\
vec4 inputTextureCoordinate;\n\" ];
After I removed the mistaken "\" that ate up the last quote it worked.

Is there a way to reformat braces automatically with Vim?

I would like to reformat some code which looks like this :
if (cond) {
foo;
}
to
if (cond)
{
foo;
}
Since this is C code, I have been looking at cindent/cinoptions to use with = but it seems it does not deal with multiline rules.
I have been looking at formatoptionsto use with gq, and it does not seem to be possible either.
So is it possible using default Vim options or should I use a specific plugin or function ?
:%s/^\(\s*\).*\zs{\s*$/\r\1{/
Breakdown:
^\(\s*\) = capture the whitespace at the beginning of the line
.* = everything else
\zs = start replacement after this
{ = open curly brace
\s*$ = trailing whitespace before line end
\r\1{ = newline, captured whitespace, brace
I don't know if this completely solves your problem, but if this is a one-shot operation, you might want to try regular expressions:
:%s/^\(\s*\)\(.*)\)\s*{\s*$/\1\2^M\1{/
Note that ^M is a control character that is usually generated (depending on your terminal) by pressing CTRL-V followed by ENTER.
EDIT: As pointed out in the comments by Jay and Zyx, \r is a better way of inserting a line break into the replaced string. I wasn't aware of that, many thanks for the hint.
If you install Artistic Style you can do something like:
:set formatprg=astyle\ -b
Then use gq to reformat chunks of code.emphasized text
If you want this enabled every time you edit a C file,
you can add the following to your .vimrc file.
autocmd BufNewFile,BufRead *.c set formatprg=astyle\ -b
I don't know if you can do it within vim itself, but you can try the BSD indent command with the -bl option. With the cursor on the first {, you can type !%indent -blEnter.