code-formatting

Intellij adding extra line in new blocks

扶醉桌前 提交于 2019-12-05 05:54:54
When I'm writing code in Intellij, I often create new blocks by typing these types of sequences: if (test) { Typing that open curly brace causes Intellij to automatically insert a closing brace and move the cursor between the two braces: if (test) {|} At this point, I simply press Enter and get a nicely formatted block with the cursor right where it should be: if (test) { | } However, today Intellij is adding an extra line to the block, like this: if (test) { | } I've looked all over the project and IDE settings, but I'm not sure what to change. FYI, it's happening in various file types (.java

How to prettify HTML so tag attributes will remain in one single line?

强颜欢笑 提交于 2019-12-05 01:27:17
I got this little piece of code: text = """<html><head></head><body> <h1 style=" text-align: center; ">Main site</h1> <div> <p style=" color: blue; text-align: center; ">text1 </p> <p style=" color: blueviolet; text-align: center; ">text2 </p> </div> <div> <p style="text-align:center"> <img src="./foo/test.jpg" alt="Testing static images" style=" "> </p> </div> </body></html> """ import sys import re import bs4 def prettify(soup, indent_width=4): r = re.compile(r'^(\s*)', re.MULTILINE) return r.sub(r'\1' * indent_width, soup.prettify()) soup = bs4.BeautifulSoup(text, "html.parser") print

Are there semicolon insertion dangers with continuing operators on next line?

你说的曾经没有我的故事 提交于 2019-12-04 23:43:46
Historically, I like to break expressions so that the "it's clearly incomplete" bias is shown on the continued line: var something = foo + bar + baz(mumble); This is an attitude that comes from working in languages which need semicolons to terminate expressions. The first line is already obviously incomplete due to no-semicolon, so it's better to make it clear to the reader that the second line is not complete. The alternative would be: var something = foo + bar + baz(mumble); That's not as good for me. Now the only way to tell that baz(mumble); isn't standalone (indentation aside) is to scan

Committing when changing source formatting?

老子叫甜甜 提交于 2019-12-04 23:00:43
Is it accepted practice to commit even when you're just changing things like whitespace, code formatting, etc.? Yes. If you need to do whitespace changes, doing them in a separate commit that contains only this kind of cleanup is the best practice. This avoids problems with trying to see what part of a giant diff is actual code changes, and what part is just formatting (cosmetic) changes. That said, you should try to keep these kind of changes to a minimum, and only do it at all when it is necessary and compatible with whatever coding standards are used in your company / community / project /

How can I strip comments and doc strings from python source code? [closed]

为君一笑 提交于 2019-12-04 22:05:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Is there a program which I can run like this: py2py.py < orig.py > smaller.py Where orig.py contains python source code with comments and doc strings, and smaller.py contains identical, runnable source code but without the comments and doc strings? Code which originally looked like this: #/usr/bin/python """Do

How to make Eclipse to format JSP code properly?

余生颓废 提交于 2019-12-04 20:15:25
问题 I use code formatting command ( Ctrl + Shift + F ) a lot in Eclipse IDE. While this works pretty well for Java / CSS source codes, the JSP formatting is just sucks . Is there any plug-in available to make the JSP formatting better in Eclipse IDE? By formatting I mean proper indenting of JSP/HTML tags. 回答1: A quick search with Google turns up this part of MyEclipse Enterprise Workbench. But a quick, if obvious, question: do you have the J2EE tools installed? 回答2: I think it is sucks for java

PHP HTML Formatter Beautifier [closed]

▼魔方 西西 提交于 2019-12-04 19:12:15
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am looking for a software which can beautify both PHP and HTML code. Dreamweaver seems to do a good job with html but not PHP PHP designer does a good job with PHP but messes up HTML. Any suggestions guys ? Eclipse with setted up by you formatting rules. Both HTML and PHP formatter. And it's free. You could always use the built in highlight-string function. Not sure if it does a particularly good job, but it's

Formatting multiple arguments passed to a function in Java

烈酒焚心 提交于 2019-12-04 18:40:15
问题 Often the number of arguments passed to a function can be large. Consider the following case: calculate(dataManager.getLastUpdate().getNumberOfChildren(), dataManager.getLastUpdate().getNumberOfParents(), dataManager.getLastUpdate().getNumberOfGrandChildren(), long milliseconds, int somethingelse) Is there a guideline in Java that offers a way to align the arguments? Fitting all arguments in a line would not look pretty. 回答1: According to the Sun's Java coding conventions, paragraph 4.1

Format Multiline code to single line in Visual Studio

断了今生、忘了曾经 提交于 2019-12-04 17:42:21
问题 Is there a keyboard shortcut or fast way to change the below code to a single line in Visual Studio 2013? I also have Resharper installed. Multi new XElement("Option", new XAttribute("Name", "FileDelete"), "1" ), Single new XElement("Option", new XAttribute("Name", "FileDelete"),"1" ), 回答1: Just select all the text and press (control + j) and it will become 1 line of code 回答2: I setup find/replace for quick use with a regex expression like so: (note: I use VS 2015, so your hotkeys may be

How do I align/format code in Android Studio?

十年热恋 提交于 2019-12-04 15:19:02
问题 Is there a way/shortcut/built-in feature that can align code for operands, like '=' signs? For example, there is a XAlign for Xcode (https://github.com/qfish/XAlign), allowing the user to select code that needs to be aligned and use a shortcut to align it automatically. There is a Fields Group feature in Android Studio which can "Align in columns", but it does not work for code that is already written. 回答1: Indent code in Android Studio: Windows Ctrl + Alt + L Mac: Option + Command + L 回答2: