代码之家  ›  专栏  ›  技术社区  ›  Roberto Aloi

递归地识别Emacs中超过80个字符的行

  •  4
  • Roberto Aloi  · 技术社区  · 16 年前

    it may be a good idea to have lines that are not wider than 80 characters in code files ,使用Emacs递归标识现有项目中这些行的最有效方法是什么?

    更新:

    根据Trey的建议,我目前正在使用以下代码:

    (defun find-long-lines (base-dir)
      "Recursively look for lines longer than 80 characters files"
      (interactive "DPath:")
      (grep-compute-defaults)
      (rgrep "^................................................................................." "*" base-dir))
    

    空白模式 .

    2 回复  |  直到 9 年前
        1
  •  3
  •   animuson    12 年前

    你可以用 igrep-find 并使用与81个(+)字符匹配的正则表达式,如下所示:

    M-x igrep-find ^.................................................................................. RET /path/to/area/to/search/* RET
    

    然后在编译模式下得到一个缓冲区,它可以让您轻松地跳转到每一个有问题的行(通过鼠标单击,或者 C-x型` M-x下一个错误 ).

    M-x grep-find 并使用相同的正则表达式。

    进入81 . .

    而且,如果希望将所有这些内容都包含在一个命令中(提示您输入文件的路径),可以使用以下命令:

    (defun find-lines-longer-than-80 (files)
      "Recursively look for lines longer than 80 characters files"
      (interactive (list (igrep-read-files)))
      (igrep igrep-program "^................................................................................." files igrep-options))
    

    在Emacs Wiki上还有一些其他的提示 Find Long Lines ,包括几个选项,用于在访问文件时突出显示超过80个字符的行。

        2
  •  4
  •   Drew    15 年前

    我不能顶EMACS特定的解决方案,但您可以稍微更改命令以包含文件名(并且键入更少的文件名)。

    rgrep "^.\{81\}" . -n (include line numbers)
    
    
    rgrep "^.\{81\}" . -c (summary view per file)
    

    交互式rgrep提示不需要引号。

    rgrep公司 RET ^.{81} 文件类型 雷特