如何告诉eclipse不格式化一些代码文件的部分(按Strg + Shift + F) [英] How to tell eclipse to not format parts of a codefile (pressing Strg + Shift + F)
问题描述
但有时格式化使代码更难读。例如当它把一个长阵列的化身化成一条线。在这种情况下,我不希望他格式化它,而是让它多行。
例如
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'
],
函数(
$,
Aloha,
插件,
Ui,
范围,
按钮,
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不格式化代码?
好的,我花了一些时间找到正确的设置,所以我将在这里发布一个toturial。
转到窗口首选项并搜索您正在使用的格式化程序。在我的情况下,它是在Aptana Studia - >Formatter。 (根据您的软件包,这不同,例如,Java格式化程序在Java - >代码样式 - >Formater下)。
Noww创建一个新的Build配置文件,因为您可以' t覆盖旧的。
现在启用Formatter标签。
现在,您可以使用
- @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艺术不是
学分:
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) {
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.
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.
Now you can use the
- @formatter:on
- @formatter:off
tags to disable code formatting.
Example: this code:
function hello() { return 'hello';
}
//@formatter:off
/*
|\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_) fL
*/
//@formatter:on
function
world() {
return 'world';
}
Will get formatted to like this
function hello() {
return 'hello';
}
//@formatter:off
/*
|\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_) fL
*/
//@formatter:on
function world() {
return 'world';
}
Note how the function definition is formatted correct, while the ascii art isn't
Credits:
- Katja Christiansen for his comment
- https://stackoverflow.com/a/3353765/639035 : for a similar answer
这篇关于如何告诉eclipse不格式化一些代码文件的部分(按Strg + Shift + F)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!