問題描述
我真的很喜歡 autofromat 功能.我讓你的代碼更具可讀性,如果 JavaScript 會告訴你什么時候出現語法錯誤(缺少括號等).
I really love the autofromat feature. I makes your code more readable and in case of JavaScript tells you, when there are synatcs errors (missing brackets etc.).
但有時格式會使代碼更難閱讀.例如當它將長數組初始化放入一行時.在那種情況下,我不希望他格式化它,而是讓它提供多行.例如
However sometimes the formatting makes the code harder to read. e.g. when it puts a long array inizalisation into a single line. In that case I don't want him to format it, but rather leave it ofer multiple lines. E.g.
define([
'jquery',
'aloha',
'aloha/plugin',
'ui/ui',
'ui/scopes',
'ui/button',
'ui/toggleButton',
'ui/port-helper-attribute-field',
'ui/text'
// 'css!youtube/css/youtube.css'
],
function(
$,
Aloha,
Plugin,
Ui,
Scopes,
Button,
ToggleButton,
AttributeField)
{
這個數組應該保持這樣,不要變成這樣:
this array should stay like this and don't become this:
define(['jquery', 'aloha', 'aloha/plugin', 'ui/ui', 'ui/scopes', 'ui/button', 'ui/toggleButton', 'ui/port-helper-attribute-field', 'ui/text' ], function($, Aloha, Plugin, Ui, Scopes, Button, ToggleButton, AttributeField) {
有沒有特殊的標簽,告訴eclipse不要格式化代碼?
Is there a special tag, to tell eclipse not to format the code?
推薦答案
好的,我花了一些時間才找到正確的設置,所以我將在這里發布一個教程.
OK, it took me some time to find the right setting so I will post a toturial here.
轉到窗口首選項并搜索您正在使用的格式化程序.就我而言,它位于Aptana Studia"->格式化程序"下.(取決于您的包,這會有所不同,例如 Java 格式化程序位于Java"->代碼樣式"->格式化程序"下).
Go to Window Preferences and Search the Formatter you are using. In my case it was under 'Aptana Studia' -> 'Formatter'. (Depending on your Package this differs, e.g. the Java Formatter is under 'Java' -> 'Code Style' -> 'Formater').
現在創建一個新的構建配置文件,因為您無法覆蓋舊配置文件.
Noww create a new Build profile since you can't override the old one.
現在啟用格式化程序標簽.
Now enable the Formatter tags.
現在你可以使用
- @formatter:on
- @formatter:off
用于禁用代碼格式化的標簽.
tags to disable code formatting.
示例:這段代碼:
function hello() { return 'hello';
}
//@formatter:off
/*
| _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..; ( `'-'
'---''(_/--' `-'\_) fL
*/
//@formatter:on
function
world() {
return 'world';
}
會被格式化成這樣
function hello() {
return 'hello';
}
//@formatter:off
/*
| _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..; ( `'-'
'---''(_/--' `-'\_) fL
*/
//@formatter:on
function world() {
return 'world';
}
注意函數定義的格式是正確的,而 ascii 藝術不是
Note how the function definition is formatted correct, while the ascii art isn't
學分:
- Katja Christiansen 發表評論
- https://stackoverflow.com/a/3353765/639035:類似的答案
- Katja Christiansen for his comment
- https://stackoverflow.com/a/3353765/639035 : for a similar answer
這篇關于如何告訴 Eclipse 不格式化代碼文件的一部分(按 Strg + Shift + F)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!