删除 ediff-trees 会话中所有文件的尾随空格

发布于 2024-09-26 16:16:40 字数 861 浏览 1 评论 0原文

我正在使用非常方便的 ediff-trees.el http:// /www.emacswiki.org/emacs/ediff-trees.el 来比较我的一个项目合作伙伴提供的一堆 Python 代码的两个版本。

不幸的是,这些人签入的代码中带有尾随空格(到处都有额外的选项卡......),这会产生大量误报差异,这使得识别更改并逐一修补它们变得不可行。

有谁知道一种巧妙的方法,使 emacs 在访问我在执行 Mx ediff-trees 期间比较的两个目录中的每个文件时自动从行中删除所有尾随空格。

如果这不能在 emacs 中自动实现,那么一个遍历目录结构并从所有 Python 源文件 (*.py) 中删除尾随空格的 shell 脚本就足够了。然后,我可以在执行差异之前在两个目录上运行它。

显然这些选项有助于缓解空白问题。

(setq ediff-diff-options "-w")
(setq-default ediff-ignore-similar-regions t)

但是,经过测试,他们似乎并没有解决问题。

另外,在我的 .emacs 配置中启用了以下功能:

;; Strip trailing whitespace
(require 'ws-trim)
(global-ws-trim-mode t)
(set-default 'ws-trim-level 2)

但这不会影响 ediff-tree 目录遍历中访问的文件。

I am using the very handy ediff-trees.el http://www.emacswiki.org/emacs/ediff-trees.el to compare two versions of a pile of Python code provided by one of my project partners.

Unfortunately, these guys are checkin in code with trailing whitespace (extra tabs here and there...) which is creating a ton of false positive diffs, which makes identifying the changes and patching them over one-by-one unworkable.

Does anyone know of a neat way of making emacs strip all trailing whitespace from lines automatically as it visits each of the files in the two directories I am comparing during the execution of M-x ediff-trees.

If this cannot be achieved auto-magically in emacs, a shell script that traverses a directory structure and removes trailing whitespace from all Python source files (*.py) would suffice. I can then run this on both directories before performing the diff.

Apparently these options help mitigate the whitespace issue.

(setq ediff-diff-options "-w")
(setq-default ediff-ignore-similar-regions t)

But, after testing they do not appear to solve the problem.

Also, the following is enabled in my .emacs configuration:

;; Strip trailing whitespace
(require 'ws-trim)
(global-ws-trim-mode t)
(set-default 'ws-trim-level 2)

But that is not effecting files visited within the ediff-tree directory traversal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毅然前行 2024-10-03 16:16:40

[A] 外壳
遍历目录的脚本
结构并删除尾随
所有 Python 源代码中的空格
文件(*.py)就足够了。

这应该可以做到:

find . -name '*.py' -print0 | xargs -0 sed -i -e 's/\s\s*$//'

[A] shell
script that traverses a directory
structure and removes trailing
whitespace from all Python source
files (*.py) would suffice.

This should do it:

find . -name '*.py' -print0 | xargs -0 sed -i -e 's/\s\s*$//'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文