Format C/C++ code on save
The formatting options of Eclipse avoids me lots of conflicts with other users, and ensure that my code always looks "clean" (especially r开发者_高级运维egarding my git commits).
I know about the "Format on save" option in Java editor, but I could not find one in C/C++.
Is this deliberate?
May I expect to see such option one day? Or maybe I haven't looked enough?
I know about the "Format on save" option in Java editor, but I could not find one in C/C++ ... Or maybe I haven't looked enough?
I'm afraid that option is simply not available for the CDT C++ editor (Eclipse CDT Juno Service Release 1):
That's everything that's available at Eclipses IDE Level.
There are two solutions you might consider to solve your concerns:
- You might consider adopting some discipline as mentioned in the other answers
- Running an appropriate script to format your source files before committing them. The AStyle tool might be helpful for this purpose.
One could also think about an automatic pre-checkin/-commit interception running a script for the actually used Revision Control System. Many revision/version control systems offer such feature.
May I expect to see such option one day?
Did you ask for this feature on the Eclipse/CDT community forum, or placed a feature request in the Eclipse CDT bugzilla tracking system? If no one knows about such feature demand and whether it is demanded by a majority of users, chances that this will be implemented by 'accident' are low.
You can use the keys "Ctrl+Shift+F" to format your edited c/c++ file.
Format on save in CDT is now implemented in Eclipse Mars.
I'm using AStyle program to format my code following a set of rules. At the moment I'm doing this from the CLI only but I know there's a plugin for eclipse, which I haven't used yet:
Astyle Eclipse is based on Astyle program, it aims to provide a C/C++ formatter for CDT plugin in eclipse. so all the supported format optional shall check astyle
There is no such default option in the eclipse cdt yet. You can try and write your own plugin This eclipse forum thread shows how to invoke the CDT formatter from an eclipse plugin. You only need to figure out how to trigger a plugin call on every save action.
Here is a plugin to fit the need: fos4cdt. Eclipse Mars may contain this feature, but many users will continue to use older versions for a while. So, it can be useful.
You can trying to select all code,and use Alt + F8 to format. This is way of VC IDE,but I don't sure that Eclipse can work.
精彩评论