标签: code-formatting

如何应用新的Emacs C样式来重新格式化所有源文件?

我想使用emacs的Google格式化功能重新格式化我的所有源文件:google-c-style.el(请参阅此处).

如何将此函数同时应用于我的所有源文件,以便根据Google样式将它们全部格式化并缩进?

lisp emacs elisp code-formatting

7
推荐指数
1
解决办法
4420
查看次数

如何防止HTML源格式影响输出?

看起来HTML代码中的额外换行符可能会在最终输出中添加不需要的空格.我一直认为无论我如何布局我的HTML代码,它都不会影响渲染结果的样子.但这是一个例子:

<h2>
    <a href="#">Hello.</a>World
</h2>
Run Code Online (Sandbox Code Playgroud)

将展示:" Hello.World " - 所有看起来都很好

<h2>
    <a href="#">Hello.</a>
    World
</h2>
Run Code Online (Sandbox Code Playgroud)

将显示:" Hello.World " - 点后面有一个额外的空格!

有没有机会摆脱这种影响?我希望将代码放在不同的行上 - 而不是产生额外的空间.

html whitespace code-formatting

7
推荐指数
2
解决办法
3991
查看次数

NetBeans中的Javascript是否有任何隐藏的代码格式设置?

我在NetBeans中进行PHP/Javascript开发,我真的很喜欢环境,除了一件事 - 在Javascript中,当我在语句后按ENTER键,然后键入左括号时,它是缩进的.像这样:

if ( a == b )
    {}
Run Code Online (Sandbox Code Playgroud)

我希望大括号保持在同一水平,如下所示:

if ( a == b )
{}
Run Code Online (Sandbox Code Playgroud)

所以,当我再次按下ENTER时,我会得到这个:

if ( a == b )
{

}
Run Code Online (Sandbox Code Playgroud)

可以这样做,怎么做?

formatting settings netbeans code-formatting netbeans-6.9

7
推荐指数
1
解决办法
2183
查看次数

如何正确缩进clojure/lisp?

我想缩进下面的一段代码.一个lisper如何缩进呢?我特别担心在哪里放新线.

(defn primes [n]
  (letfn [(sieve [table removal]
                 (assoc table removal false))
          (primebools [i table]
                       (cond 
                         (= i n) table 
                         (table i) (recur (inc i) 
                                          (reduce sieve 
                                                  table 
                                                  (range (* i i) n i))) 
                         :else (recur (inc i) 
                                      table)))]
    (let [prime? (primebools 2 (apply vector (repeat n true)))]
      (filter prime? (range 2 n)))))
Run Code Online (Sandbox Code Playgroud)

lisp primes code-formatting clojure indentation

7
推荐指数
1
解决办法
1460
查看次数

在Visual Studio中多行自动缩进参数列表

当方法的参数列表增长到它们不适合在一行上时,我喜欢格式化代码,使得每个参数都在一个单独的行上(遵循StyleCop建议),如下所示:

public void MyMethod(
   int someArgument,
   double someOtherArgument,
   int someMoreArguments)
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是这种格式是"脆弱的",并且在使用Ctrl + K + D时不会自动重新格式化.例如,如果我碰巧在其中一个参数前面插入一些空格,它就不会被删除,我最终会做一些繁琐的手动重新格式化.如果我复制一个方法(比如,提供一个重载的签名),副本中的参数缩进变得非常混乱.
我在LINQ语句中遇到了类似的问题,我也喜欢在多行格式化,例如:

myEnumerable.
   .Where(this and that)
   .Where(this and that)
   .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

我意识到这是完整的强迫性格式化,并且是一个非常小的问题,但有没有办法让Visual Studio 2010在错位时自动重新缩进该模式后面的多行参数?

code-formatting visual-studio-2010

7
推荐指数
2
解决办法
2117
查看次数

如何使Eclipse对齐?:三元运算符?

我需要与此问题完全相同的效果,但在Eclipse中.

如果我在":"之前插入一个新行或者第二个操作数("true"表达式)太长,它应该只进行对齐.

例:

a = cond ? "a veeeeeeeeeeeeeeeery loooooooooooooooooooooooooooong string"
         : "";
      // ^ put the colon here
Run Code Online (Sandbox Code Playgroud)

java eclipse code-formatting

7
推荐指数
1
解决办法
2610
查看次数

Netbeans代码模板格式化语法

我想知道netbeans ide中用于格式化代码模板的语法或语言是什么.我的意思是,在默认模板中我可以看到类似的东西;

while (${EXP default="exp"})
{ 
   ${selection line}${cursor} 
}
Run Code Online (Sandbox Code Playgroud)

和:

// <editor-fold defaultstate="collapsed" desc="${comment}">
${selection}${cursor}// </editor-fold>
Run Code Online (Sandbox Code Playgroud)

我试验并做到了这一点:

int ${IDX newVarName default="loop"};

for (${IDX} = 0; ${IDX} < ${SIZE int default="size"}; ${IDX}++)
{
   ${cursor}
}
Run Code Online (Sandbox Code Playgroud)

它有效,但我真的不知道"$ {IDX}""$ {SIZE int default ="size"}""$ {selection} $ {cursor}"来自哪里以及其他什么陈述我可以用来格式化我的模板.

这是一些脚本或编程语言吗?

我在哪里可以找到这些信息?

syntax netbeans code-formatting

7
推荐指数
1
解决办法
5804
查看次数

如何在IntelliJ IDEA中为Scala配置代码样式

IntelliJ格式化我的测试代码如下:

  test("a configuration without classpath to analyze is not valid") {
                                                                  Configuration(
                                                                    None,
                                                                    Seq(),
                                                                    Seq(),
                                                                    Map(),
                                                                        Some(PrintConfiguration(print = Always("output")))
                                                                  ) should not be ('valid)
                                                                }
Run Code Online (Sandbox Code Playgroud)

我希望我们都同意这是一个相当愚蠢的方法来做到这一点.

如何配置IntelliJ以使其移动Configuration并且属于它的所有内容都向左移动,两个空格相对于test

澄清一下:大多数代码都是正确缩进的,只是花括号中的代码块,即参数相对于开始大括号而言相对于函数调用的开头而言是相对的.

scala code-formatting indentation intellij-idea

7
推荐指数
1
解决办法
6319
查看次数

如何为iOS编码配置Allman风格的Clang格式?

关于Clang Format API,我有很多困惑.

  1. 我无法打开.clangformat文件,以便我可以查看并根据我进行配置.
  2. 我需要以Allman风格格式化我的代码.
  3. 我在Google和Stack Overflow上看到了很多文档,但我没有得到任何帮助来实现Allman样式格式化.

我遇到了http://clangformat.com/但是我也没有得到任何帮助来实现Allman风格.

这是我想要的问题和解决方案.

问题#1:

[[NSNotificationCenter defaultCenter]
      addObserver:self
         selector:@selector(captureSearchFiltersNotificationWithSelection:)
             name:kSearchFiltersNotificationWithSelection
           object:nil];
Run Code Online (Sandbox Code Playgroud)

需要#1:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSearchFiltersNotificationWithSelection:)name:kSearchFiltersNotificationWithSelection object:nil];
Run Code Online (Sandbox Code Playgroud)

问题#2:

- (id)initWithNibName:(NSString *)nibNameOrNil
               bundle:(NSBundle *)nibBundleOrNil {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {
                //        listings = [NSMutableArray new];
                self.navTitle = @"Buy";
                searchFilters = [SearchFilter new];

                if ([LocationManager locationManager].location == nil) {
                        selectedSortOption = kSortBuyRefineOptionUndefined;
                }

                else {
                        selectedSortOption = kSortBuyRefineOptionNearMeAsc;
                }
        }
        return self;
}
Run Code Online (Sandbox Code Playgroud)

需要#2:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil 
{
    self = [super …
Run Code Online (Sandbox Code Playgroud)

code-formatting ios clang-format

7
推荐指数
1
解决办法
1623
查看次数

Android Studio:如何重新格式化整个项目的代码?

我正在寻找一种方法来重新格式化整个项目的代码,通过code- > 可用于单个文件reformat code.

code-formatting intellij-idea android-studio

7
推荐指数
2
解决办法
2039
查看次数