code-formatting

Indenting #defines

北城以北 提交于 2019-11-26 12:38:53
问题 I know that #define s, etc. are normally never indented. Why? I\'m working in some code at the moment which has a horrible mixture of #define s, #ifdef s, #else s, #endif s, etc. All these often mixed in with normal C code. The non-indenting of the #define s makes them hard to read. And the mixture of indented code with non-indented #define s is a nightmare. What is the benefit of not indenting #define s? Does it make me a bad person if I indent them? Isn\'t this much nicer? #ifdef SDCC #if

ReSharper formatting: align equal operands

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 12:31:09
问题 Note to Googlers , this question is somewhat out of date as the requested feature is now supported in the current version of ReSharper 2017.3.1 I like to formatting my code to align right side of equal operands. Like here: bool canRead = false; bool canReadClass = true; string className = boType.Name; I\'ve switch to ReSharper recently and found it very useful but cannot find option allowing me format code in described way. Do you know if there is such option / plugin? Maybe you know other

Most idiomatic way to print a time difference in Java?

本小妞迷上赌 提交于 2019-11-26 12:18:01
问题 I\'m familiar with printing time difference in milliseconds: long time = System.currentTimeMillis(); //do something that takes some time... long completedIn = System.currentTimeMillis() - time; But, is there a nice way print a complete time in a specified format (eg: HH:MM:SS) either using Apache Commons or even the dreaded platform API\'s Date/Time objects? In other words, what is the shortest, simplest, no nonsense way to write a time format derived from milliseconds in Java? 回答1: Apache

What is the proper way to format a multi-line dict in Python?

南楼画角 提交于 2019-11-26 11:50:39
问题 In Python, I want to write a multi-line dict in my code. There are a couple of ways one could format it. Here are a few that I could think of: mydict = { \"key1\": 1, \"key2\": 2, \"key3\": 3, } mydict = { \"key1\": 1, \"key2\": 2, \"key3\": 3, } mydict = { \"key1\": 1, \"key2\": 2, \"key3\": 3, } I know that any of the above is syntactically correct, but I assume that there is one preferred indentation and line-break style for Python dicts. What is it? Note: This is not an issue of syntax.

How can I autoformat/indent C code in vim?

柔情痞子 提交于 2019-11-26 11:43:31
问题 When I copy code from another file, the formatting is messed up, like this: fun() { for(...) { for(...) { if(...) { } } } } How can I autoformat this code in vim? 回答1: Try the following keystrokes: gg=G Explanation: gg goes to the top of the file, = is a command to fix the indentation and G tells it to perform the operation to the end of the file. 回答2: I like to use the program Artistic Style. According to their website: Artistic Style is a source code indenter, formatter, and beautifier for

Online code beautifier and formatter [closed]

心不动则不痛 提交于 2019-11-26 11:43:03
问题 What are the best online code beautifier and formatter out there? I\'m not asking for highlighters. Any language will do. 回答1: CSS: code beautifier HTML: HTML Tidy, CleanUp HTML or the general purpose Pretty Diff Javascript: http://jsbeautifier.org/ PHP: http://beta.phpformatter.com/ SQL: http://dpriver.com/pp/sqlformat.htm XML: http://chris.photobooks.com/xml/default.htm Colour all: http://quickhighlighter.com/ 回答2: For PHP, Java, C++, C, Perl, JavaScript, CSS you can try: http://www

Formatting code in Notepad++

ⅰ亾dé卋堺 提交于 2019-11-26 10:10:24
问题 Is there a keyboard shortcut to format code in Notepad++ ? I\'m mainly working with HTML, CSS and Python code. For example: <title>{% block title %} {% endblock %}</title> <link rel=\"stylesheet\" href=\"/media/style.css\" type=\"text/css\" media=\"screen\" /> </head> To: <head> <title> {% block title %} {% endblock %} </title> <link rel=\"stylesheet\" href=\"/media/style.css\" type=\"text/css\" media=\"screen\" /> </head> I remember Visual Studio doing it with Ctrl + K + D and NetBeans

IntelliJ IDEA code format from checkstyle configuration

北战南征 提交于 2019-11-26 09:44:28
问题 I\'ve decided to contribute to android maven plugin. They use quite specific code style format. It will take some time for me to modify IDEA code format rules to satisfy their requirements. Fortunately there is checkstyle configuration. I\'ve already installed check-style plugin for IDEA and immediately see where my current formatting is wrong. Unfortunately I didn\'t find way to import checkstyle configuration into IDEA formatting rules. I\'m interested if it\'s possible. 回答1: UPDATE :

Auto-indent in Notepad++

你说的曾经没有我的故事 提交于 2019-11-26 08:46:58
问题 We always write code like this formal: void main(){ if(){ if() } But when I use Notepad++, the display is: void main(){ if(){ if() } How do I use Notepad++ to auto indent? Thanks to Jonathan, I have set it, but it does not take any effect. The snapshot is below: I am using Notepad++ version 5.1.3. 回答1: Notepad++ will only auto-insert subsequent indents if you manually indent the first line in a block; otherwise you can re-indent your code after the fact using TextFX > TextFX Edit > Reindent C

Delphi code formatter

大兔子大兔子 提交于 2019-11-26 08:18:33
问题 Are there any utilities that reformat Delphi code ? EDIT I am using Delphi 2006 Some feedback Thanks to all that answered this question I have been using the JCF code formatter - it works well and my code is been formated to Object Pascal Style Guide 回答1: You can try the "Jedi code Format". See more information here: http://jedicodeformat.sourceforge.net/ The formatting engine of DelForExp has been integrated into the code base of GExperts. An experimental version of GExperts including a