标签: autoformatting

Vim有用的Python命令列表?

我前几天在Vim中寻找一种快速自动格式化/漂亮打印JSON的方法,并在Stack Overflow上找到了这个很棒的小命令: :%!python -m json.tool

这让我找到了一个其他Python工具的列表来打印常见的网络文件,但我找不到多少.是否有一个很好的资源/ Python工具列表,他们发现这些工具对于清理Vim中格式不正确的Web内容特别有用(例如HTML,XML,JavaScript等)?

python vim pretty-print autoformatting

18
推荐指数
2
解决办法
2524
查看次数

自动格式化R代码的工具

有没有可以自动重新格式化R代码的工具(编辑器,脚本,等等......)?它不需要是可自定义的,但它必须能够识别由分号或换行符分隔的语句,因为此代码具有两者.如果它可以将所有语句放在一个单独的行上,一致地缩进代码块并始终如一地放置括号,我将非常高兴.

编辑:总结调查结果

谢谢你的答案.这是我发现的.

  • ESS和StatET都是优秀的R编辑器,并且可以很好地自动缩进代码块.StatET允许您一次选择全部并重新缩进文件中的所有内容.从我可以告诉ESS允许你一次缩进整个函数def而不是整个文件(如果我错过了,请纠正我).这些都不会修复大括号放置或分解多语句行.(例如:i = n*b; a = i + 1)
  • formatR太棒了.除了修复缩进之外,它还将一致地放置大括号并拆分多语句行.

这是我编写的一个小函数,以便我可以转换整个源目录(使用与formatR相同的底层函数,这在动画包中很奇怪).

library("animation")

tidy.all <- function(inDir = NULL, outDir = NULL, ...) {
    if (is.null(inDir) || is.na(outDir)) 
        stop("inDir can't be null or NA")
    if (!file.info(inDir)$isdir) 
        stop("inDir must be a directory")

    if (is.null(outDir) || is.na(outDir)) 
        stop("outDir can't be null or NA")
    if (!file.exists(outDir)) 
        dir.create(outDir)
    if (!file.info(outDir)$isdir) 
        stop("outDir must be a directory")

    for (f in dir(inDir)) {
        currFile <- file.path(inDir, f)
        if (length(grep(".*\\.R$", currFile, perl = T))) {
            outFile <- file.path(outDir, …
Run Code Online (Sandbox Code Playgroud)

formatting r autoformatting

17
推荐指数
3
解决办法
8796
查看次数

如何自动整理Perl源代码?

我公司的一只猫走过键盘,留下了有效的1000多行可执行Perl代码供我维护.

感谢Perl的TMTOWTDI理念,我发现自己正在搜索Google,以了解她所生成的每一行代码.

为了增加我的痛苦,代码没有缩进,并且在一行中发现两个语句频繁出现,无法确定循环是外/内.

如何自动将此Perl代码置于健全状态?是的,我打赌会有一些CPAN模块可以做到这一点.一些外部工具怎么样?有线索吗?

perl autoformatting perl-tidy

16
推荐指数
3
解决办法
4902
查看次数

在Vim中自动注释新行仅用于块注释

当我在.{cpp,h}文件中的单行注释结束时开始一个新行时,vim会自动对其进行注释.例如:

// This is a comment<CR>
// | <- Cursor is moved to `|`, `//` is automatically inserted. 
Run Code Online (Sandbox Code Playgroud)

我不确定这是插件还是设置.我看不到任何看起来像是在我这样做的东西,~/.vimrc下面列出了加载的插件.

喜欢这种for- /* */style 多行注释,但我不希望我的单行注释默认在多行上运行.

哪个设置(或插件)可以执行此操作,是否可以仅为此注释类型将其关闭?

:scriptnames 给出这个:


  1: /Users/simont/.vimrc
  2: /usr/local/share/vim/vim73/syntax/syntax.vim
  3: /usr/local/share/vim/vim73/syntax/synload.vim
  4: /usr/local/share/vim/vim73/syntax/syncolor.vim
  5: /usr/local/share/vim/vim73/filetype.vim
  6: /usr/local/share/vim/vim73/ftplugin.vim
  7: /usr/local/share/vim/vim73/syntax/nosyntax.vim
  8: /Users/simont/repositories/config-files/vim/colors/solarized.vim
  9: /usr/local/share/vim/vim73/plugin/getscriptPlugin.vim
 10: /usr/local/share/vim/vim73/plugin/gzip.vim
 11: /usr/local/share/vim/vim73/plugin/matchparen.vim
 12: /usr/local/share/vim/vim73/plugin/netrwPlugin.vim
 13: /usr/local/share/vim/vim73/plugin/rrhelper.vim
 14: /usr/local/share/vim/vim73/plugin/spellfile.vim
 15: /usr/local/share/vim/vim73/plugin/tarPlugin.vim
 16: /usr/local/share/vim/vim73/plugin/tohtml.vim
 17: /usr/local/share/vim/vim73/plugin/vimballPlugin.vim
 18: /usr/local/share/vim/vim73/plugin/zipPlugin.vim
 19: /usr/local/share/vim/vim73/scripts.vim
 20: /usr/local/share/vim/vim73/ftplugin/vim.vim …
Run Code Online (Sandbox Code Playgroud)

vim comments autoformatting

16
推荐指数
2
解决办法
3448
查看次数

在emacs Python模式下,如何为docstrings和代码设置不同的自动填充宽度?

我希望自动填充设置为79列代码段,72代表文档字符串,以获得自动PEP8合规性.似乎有一个选项可以为Lisp模式(emacs-lisp-docstring-fill-column)执行此操作,但不适用于Python.

是否有一个增强的python-mode.el在某处包含这个?

python emacs docstring pep8 autoformatting

13
推荐指数
1
解决办法
1894
查看次数

Vim:没有前导字符的Textwrap

我正在VIM中编写一个弹出的列表,并设置textwidth = 79来硬包装线.当我写清单时,我希望每个回车都能产生一个新的子弹,并且包裹的线条没有子弹.然而,VIM正在做相反的事情(包裹线上的子弹,回车后没有子弹).我想要:

* Item 1 - The text for this line is too long and
  so is wrapped to the next line.
* Item 2 - Typing a carriage return after item 1
  should produce the bullet for this item.
Run Code Online (Sandbox Code Playgroud)

但是,VIM会这样做:

* Item 1 - The text for this line is too long and
* so is wrapped to the next line.
Item 2 - Typing a carriage return after item 1
should produce the bullet for this line. …
Run Code Online (Sandbox Code Playgroud)

vim word-wrap autoformatting

11
推荐指数
1
解决办法
322
查看次数

使逐字字符串文字自动缩进以保持与附近代码保持一致

在C#中,我经常使用逐字字符串文字(例如@"Arrr!")来跨越多行来断开长字符串,同时保留布局.例如,我使用它来分解内联SQL,如下所示:

var sqlString = @" 
    SELECT 
        Column1
        , ...
    FROM
        Table1 INNER JOIN ...
    WHERE 
        Column2 = @Value2
        , ...
    ";
Run Code Online (Sandbox Code Playgroud)

...或者打破这样的正则表达式模式:

var regexPattern = @"
    (?<state>\w+)[.]?                       (?#*** Matches state {optionally having a period at the end} ***)
    (\s+|,|,\s+|\s*\u2022\s*)               (?#*** Matches space between state and zip {can include a comma or bullet point} ***)
    (?<zip>(\d{5}-\d{4}\b|\d{5}(?![\w-])))  (?#*** Matches zip code ***)
    ";
Run Code Online (Sandbox Code Playgroud)

 

但是,如果此代码稍后自动缩进,则逐字字符串文字不会自动缩进.当它上方和下方的代码行向右移动时,它会被遗忘.结果是它与其他一切都不一致.例如:

之前:

verbatim = @"               ___
    I likes my                 |
    strings purty              | indented the way …
Run Code Online (Sandbox Code Playgroud)

c# string auto-indent autoformatting visual-studio-2013

11
推荐指数
1
解决办法
962
查看次数

make Clang-Format忽略换行符的注释

是否有可能告诉Clang-Format忽略换行操作的注释?我们的想法是遵循"代码格式正确,即使评论超出换行余量"的风格.代码不应分成多行,如果它不超过保证金,但注释会.

例如

//desired behaviour:
short code = shortCode + 
        longlonglongCode;
short code = shortCode; //long comment without a line break

//not desired behaviour:
short code =
    shortCode;  //long comment without a line break
Run Code Online (Sandbox Code Playgroud)

c++ clang autoformatting clang-format

11
推荐指数
1
解决办法
1261
查看次数

在 Xcode 中为盲人开发人员自动格式化 Swift

如何在 Xcode 中为 Swift 使用代码格式化程序的答案建议 Xcode 具有自动格式化 swift 代码的能力,并且可以使用?+ I(Ctrl-I)调用该功能

当我在以下 Swift 函数上尝试时绝对没有任何变化

func displayGuesses(){
    replaceWord = ""
    for character in chosenWord!{
        if guesses.contains(String(character)) {
            replaceWord.append(character)
        }
        else{
            replaceWord.append("_")
        }
            }

    guessLabel.text = replaceWord
}
Run Code Online (Sandbox Code Playgroud)

我希望它将关闭 for 循环的花括号与打开语句对齐。

Xcode 中是否有可以正确格式化此 Swift 函数的功能?如何从键盘调用它?

请注意,这不是关于首先选择代码。如果我先选择整个文件——使用?+ A(Cmd-A)——那么仍然没有效果。

(注意,你可能想知道为什么我要编写格式奇怪的代码。我正在和一个盲童一起工作,他正在从 PC 上的 Python 切换到 Mac 上的 Swift。Python 使用缩进来确定范围。我很高兴能像他一样教他 Swift不用太担心缩进。但是,如果他想与有视力的开发人员共享代码,那么如果 Xcode 为他整理格式,那将很方便。)

xcode autoformatting

11
推荐指数
1
解决办法
5198
查看次数

为什么eclipse总是在JavaDoc中的@param myParameter之后换行?

我有这段Java代码:

/**
 * Initializes the Levenshtein Object with the two given words.
 * 
 * @param word1 first word
 * @param word2 second word
 */
public Levenshtein(String word1, String word2) {
    this.word1 = "." + word1.toLowerCase();
    this.word2 = "." + word2.toLowerCase();
    this.distance = new int[this.word2.length()][this.word1
            .length()];
}
Run Code Online (Sandbox Code Playgroud)

如果我按Ctrl + Shift + F,我得到这个:

/**
 * Initializes the Levenshtein Object with the two given words.
 * 
 * @param word1
 *            first word
 * @param word2
 *            second word
 */
public Levenshtein(String word1, String …
Run Code Online (Sandbox Code Playgroud)

eclipse autoformatting

10
推荐指数
1
解决办法
2893
查看次数