Hi all I'm trying to stop the auto formatting in eclipse from indenting my opening and close brace after a function that has a throw() statement on the end.
e.g
void function(std::string param) throw()
{
}
after auto format will look like this:
void function(std::string param) throw()
{
}
But it will carry on adding another tab to the front of the brackets every time I autoformat my code. Anyone know how I can turn this feature off, or is it a bug
Eclipse info:
Version: Juno Release
Build id: 20120614-1722
using CDT
Note:
I am using my own code style profile.
The name of that style is Whitesmiths - Try to change it to Allman.
In C/C++ perspective mode, Goto Window > Preferences > C/C++ > Code Style
Choose BSD/Allman or whatever you want.
You might want to consider Astyle, this is a eclipse plguin, an interface to a wondeful code beautyfication command line tool. you can set the indentation, formatting, etc.
Very handy tool.
Related
I'd like for VSCode to indent automatically indent when I create a newline in the following case:
if(statement)
func();
The default functionality does the following when hitting newline:
if(statement)
func();
This is a longstanding issue in VSCode: https://github.com/microsoft/vscode/issues/43244
I'd appreciate any kind of hack/extension that can accomplish this behavior. There are other instances of indentation getting mangled in the github issue link, but I only really care about this simple case.
Figured out how to do this without installing an extension. There may be a better way that can be done in settings.json but I couldn't find it. You can modify a languages configuration directly from the source, which for me was C:\Program Files\Microsoft VS Code\resources\app\extensions\cpp\language-configuration.json. There is a guide for these files settings. I added the following to my c++ language configuration:
"onEnterRules": [
{
"beforeText": "^\\s*(?:if|while)\\(.*\\)\\s*$",
"action": {
"indent": "indent"
}
},
{
"beforeText": "(?=)",
"previousLineText": "^\\s*(?:if|while)\\(.*\\)\\s*$",
"action": {
"indent": "outdent"
}
}
]
This works, but unfortunately the official c++ vscode extension C/C++ for Visual Studio Code breaks it for some reason.
Below was my initial method of doing this, which breaks too many things to be useful.
"indentationRules": {
"increaseIndentPattern": "^\\s*if\\(.*\\)\\s*$",
"decreaseIndentPattern": "(?!)"
}
The field decreaseIndentPattern must be set (here the regex will never capture anything), otherwise it ignores the indentationRules field (I guess they never tested whether just one would be set?) Note that these edits need to be done with administrative privleges, and I found VSCode pretty convenient for making them. Also these changes do not take effect until VSCode is closed.
So as it turns out I've run into the same issues mentioned in this PR: https://github.com/microsoft/vscode/pull/115454. This fix breaks too much other vscode indentation behavior, such as deindenting after the first properly indented line in if statements.
Seems not relevant to some questions with similar titles.
//some other code
std::string s = Lookup->getName().str();
-> break here //some other code
Note: "Lookup" is clang::DirectoryLookup http://clang.llvm.org/doxygen/classclang_1_1DirectoryLookup.html, "Lookup->getName()" is llvm::StringRef http://llvm.org/doxygen/classllvm_1_1StringRef.html.
When break at the above place, in the "Watch" pane in VS2017, the string variable "s" is initialized successfully and its value can be shown in "Watch" pane.
But when try to show(watch) the expression "Lookup->getName().str()" which is just how "s" is initialized, it says:
Lookup->getName().str() | Function llvm::StringRef::str has no address, possibly due to compiler optimizations.
the source code of StringRef::str() is:
/// str - Get the contents as an std::string.
LLVM_NODISCARD
std::string str() const {
if (!Data) return std::string();
return std::string(Data, Length);
}
And all the libraries is in debug version. Based on the above fact, there seems to be no reason for this to happen.
Such thing happens in other situations during debuging a Clang Libtooling program and it make debugging very hard.
What is the possible reason and how to solve it?
I tried #user15331850 solution and it didn't help, but setting Linker-> Debugging-> Generate Debug Info to "/DEBUG:FULL" seems giving me all variables now.
This may be due to optimization option is enabled.
You can disable the same by following these steps:
Right click on the solution
Click on the "properties"
From the left pane, click on the "Configuration Properties"
Click on "C/C++" from the sub-option
Then click on the "optimization" and select "Disabled(/Od)" from the list
That's it. Hope it works for you!!
I had this issue. I needed to change the settings for: Linker-> Debugging-> Generate Debug Info from "/DEBUG:FASTLINK" to "/DEBUG".
How to customize Eclipse CDT to use Ratliff style for auto formatting?
Ratliff Style of formating code indents the terminating brace to the same level as the contents of the block:
for (i = 0; i < 10; i++) {
if (i % 2 == 0) {
doSomething(i);
}
else {
doSomethingElse(i);
}
}
Eclipse CDT allows a number of common styles to be selected for auto formatting. Ratliff is not in the list but you can modify them to meet your specific requirements:
except there is no option in the list of choices to have the end brace align with the block contents:
No one has implemented this option in CDT's formatter.
CDT is open source, you're welcome to contribute a patch that implements it.
However, given how little CDT's formatter is maintained in general these days, a better use of your time might be to contribute support for the Ratcliff style to clang-format (which also doesn't currently support it, as far as I can tell), and use clang-format in CDT via a plugin like CppStyle.
I am so used to code like this:
if (...)
{
//somecode
}
that I simply have to change the following to the above:
if (...){
//somecode
}
I get a lot of code from other people that I have to go through and sometimes this is what I get. Is it possible to auto-format that in Visual Studio 2008 for C++?
Now some may think I should get used to it. Believe me, I am trying, but it is very distracting and I hope there is a simple solution.
VS2008 has a simple formatter (Edit menu, Advanced, Format Selection), but it doesn't move braces.
Check out astyle and its --style=ansi flag.
In C++ Builder, how can I make sure that even correctly nested code like:
void func () {
...
..
)
C++ Builder correctly nested only doing so:
void func ()
{
...
...
}
This is very stressful, because I always have to correct by hand. So how can I make which indents code as well in the first instance?
The code formatter in C++Builder 2010 should do this automatically for you. (It is invoked with CTRL-D) You’ll have to set the preferences to how you like your code to be formatted, but this is a real time saver new with this most recent release.
Select the block, then press CTRL+SHIFT+I. This is in Borland C++ 6.
I am using this free tools:
http://www.cnpack.org/index.php?lang=en
using tabs to shift marked blocks to left or right.
I don't have a copy of this to run, but the documentation mentions "Indentation, Spaces, and Line breaks" as some of the options under the formatter tab of the "Tools > Options" dialog.
What you're looking for is probably under the "Line Breaks" section.