2012-09-12 26 views
0

我非常喜歡自動色彩功能。我讓你的代碼更具可讀性,並且在JavaScript的情況下告訴你,當有synatcs錯誤時(丟失括號等)。如何讓eclipse不格式化代碼文件的部分(按Strg + Shift + F)

但是有時格式化會使代碼難以閱讀。例如當它把一個長陣列inizalisation成一條線。在這種情況下,我不想讓他格式化,而是讓它多行。 例如

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) 
     { 

此陣應保持這樣的,不要變成這樣:

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不要格式化代碼?

+1

看看Eclipse的格式化代碼,請參閱回答http://stackoverflow.com/a/3353765/1288408 –

+0

感謝,這就是我一直在尋找對於。那麼我不想刪除這個querstion,因爲我沒有找到鏈接,我搜索了一段時間。你想要回答這個問題嗎?我接受了嗎? LG – Stefan

+0

對不起,我沒有注意到你的評論。我認爲你應該接受你自己的回答:) –

回答

3

好吧,我花了一些時間找到正確的設置,所以我會在這裏發佈toturial。

轉到窗口首選項並搜索您正在使用的格式器。在我的情況下,它是在'Aptana Studia' - >'Formatter'下。 (根據您的軟件包的不同,例如Java格式化程序在'Java' - >'代碼樣式' - >'Formater'下)。

Create new Formatter Proffile

Noww創建一個新的博客建立知名度,因爲你不能覆蓋舊的。

現在啓用Formatter標籤。現在 Enabale Formatter on/off tags

可以使用

- @formatter:on 
- @formatter:off 

標籤禁用代碼格式化。

例子: 此代碼:

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藝術不是

現金:

  1. Katja Christiansen他的評論
  2. https://stackoverflow.com/a/3353765/639035:一個類似的答案
+1

尼斯教程,我喜歡這個例子:) –

+0

坦克,困擾我很久,所以我不得不記錄它^^ – Stefan

+0

好吧,如果你正在使用[Aptana Studio](http: //www.aptana.com/)這個工作。在標準的eclipse安裝中,你不會有這個選項。 – Kai

2

儘量使每行後一個空評論:

define([ // 
    'jquery', // 
    'aloha', // 
    'aloha/plugin', // 
    'ui/ui', // 
    'ui/scopes', // 
    'ui/button', // 
    'ui/toggleButton', // 
... 

不是很好,但我認爲它會奏效。

+0

工程,但代碼變得很醜陋。它將它們格式化爲文檔的開頭 – Stefan

相關問題