当前位置: 动力学知识库 > 问答 > 编程问答 >

shell - removing trailing whitespace for all files in ediff-trees session

问题描述:

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.

网友答案:

[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*$//'
分享给朋友:
您可能感兴趣的文章:
随机阅读: