2012-12-24 89 views
20

在HTML文件中,有一些代碼中使用自定義模板語言:如何配置intellij-idea不格式化一部分代碼?

<script type="text/javascript"> 
    function ($scope, JsRoutes) { 
     $scope.rows = [ 
      ${"#{list rows, as: 'row', separator: ','}"} 
      { 
      #{list fieldConfigs, as: 'f', separator: ','} 
      ${f.name} : ${'$'}{row.${f.name}.toJson()}#{/list} 
      } 
      ${'#{/list}'} 
     ] 
    } 
</script> 

是否有可能配置的IntelliJ,先不要格式化(但格式化文檔的其他部分)?由於想法將很難在格式化後讀:

<script type="text/javascript"> 
    function ($scope, JsRoutes) { 
     $scope.rows = [ 
      ${"#{list rows, as: 'row', separator: ','}"} 
      { 
    #{list fieldConfigs, as: 'f', separator: ','} 
    ${f.name} : 
     ${'$'}{ 
      row.${f.name}.toJson() 
     }#{/list} 
    } 
    ${'#{/list}'} 
    ] 
    } 
</script> 
+1

可能重複的[如何禁用代碼的一部分代碼格式化?](http://stackoverflow.com/questions/3375307/how-to-disable-code-formatter-for-some-part-of代碼) –

回答

15

此功能已經實現,現在您可以禁用格式化使用特殊註釋的代碼區域。

markers

你可以找到more details and examples in the documentation


從2012

原來的答覆:

這是不可能的呢,請投票支持此功能要求:

  • IDEA-56995禁用代碼每個區域的格式化使用註釋
+1

我不想在intellij上使用我的代碼的註釋,而不是爲了銷燬我的縮進我已經非常努力地進行對齊,例如定義屬性。 該設置應該在整個項目中可用,無需評論。 但我希望能夠在格式化或縮進時重新格式化。 現在我剩下可能通過遍歷Java代碼樣式和複選框完全關閉功能。 – momomo

+0

這已得到修復 - 請參閱以下有關如何啓用它。 – homaxto

+0

@homaxto謝謝,我已經更新了答案 – CrazyCoder

8

由於EAP 13你可以用下面的評論觸發格式:

// @formatter:off 
... 
// @formatter:on 

要在「surround with」中啓用它,您可以在部分「s urround」有: - >Code Style -

// @formatter:off 
$SELECTION$ 
// @formatter:off 

可以在Settings找到這些設置>General並設置自己的觸發字。

37

在我的版本EAP 13.1,則必須在設置中啓用下面的選項,

Preferences - >Code Style - >General - >Formatter Control - >Enable formatter markers in comments

纔可以使用這些意見,

// @formatter:off 

// @formatter:on 

或這些(取決於語言):

<[email protected]:off--> 

<[email protected]:on--> 

截圖:

Screenshot highlighting the checkbox for Enable formatter markers in comments under Preferences

+0

這對我來說詭計,謝謝! 我認爲這應該是被接受的答案,因爲它同時被添加爲IntelliJ IDE的一個功能。 – McLovin

+0

伸縮式施工人員真棒... –

1

值得一提的是,格式化控件不會出現在javadoc註釋工作。它需要使用常規的C或C++風格的註釋。所以// @formatter:off作品/* @formatter:off */也有效,但/** @formatter:off */沒有。