Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

How to config intellij-idea not format some part of the code?

In a html file, there is some code used custom template-language:

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

Is it possible to configure intellij-idea not to format it(but format the other part of the document)? Since idea will make it hard to read after formatting:

<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>
question from:https://stackoverflow.com/questions/14020200/how-to-config-intellij-idea-not-format-some-part-of-the-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This feature has been implemented and you can now disable formatting for the regions of code using the special comments.

markers

After enabling this feature in the settings, add //@formatter:off at the start of your region, and //@formatter:on at the end of it.

These are the default markers, and they are configurable.

You can find more details and examples in the documentation:


Original answer from 2012:

It's not possible yet, please vote for this feature request:

  • IDEA-56995 Disable code formatting per region using comments

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...