Emacs ediff 错误“文件末尾没有换行符”

发布于 2025-01-04 06:29:23 字数 274 浏览 1 评论 0原文

在 Debian Wheezy、Emacs 23.3.1 上,运行 ediff-files 时文件末尾缺少换行符会导致错误 \ No newline at end of file (我希望这是正确的翻译;它是德语 \ Kein Zeilenumbruch am Dateiende。 在我的计算机上。)

是否可以只显示一个警告,以便我可以看到差异并对其进行处理(并且修复丢失的换行符)?首先让 ediff 失败,然后打开文件,添加换行符,再次 ediff 有点乏味。

On Debian Wheezy, Emacs 23.3.1, running ediff-files with a file that is missing a newline at the end results in the error \ No newline at end of file (I hope that's the correct translation; it's German \ Kein Zeilenumbruch am Dateiende. on my computer.)

Is it possible to have just a warning instead, so that I can see the diff and work on it (and fix the missing newline)? It's just a bit tedious to first have ediff fail, then open the file, add the newline, ediff again.

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

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

发布评论

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

评论(2

够钟 2025-01-11 06:29:23

尝试更改变量 ediff-diff-ok-lines-regexp 的值以包含德语文本(“Kein Zeilenumbruch am Dateiende”):

(setq ediff-diff-ok-lines-regexp
      (concat
       "^\\("
       "[0-9,]+[acd][0-9,]+\C-m?$"
       "\\|[] "
       "\\|---"
       "\\|.*Warning *:"
       "\\|.*No +newline"
       "\\|.*missing +newline"
       "\\|.*Kein +Zeilenumbruch +am +Dateiende"
       "\\|^\C-m?$"
       "\\)"))

更新: 查看源代码代码中,Ediff 似乎没有尝试处理来自 diff 的消息本地化问题。还应该可以通过将 diff 包装在 shell 脚本中来解决此问题,例如:

#!/bin/bash
LANG=C diff $*

..然后自定义 ediff-diff-program 来调用包装器:

(setq ediff-diff-program "~/bin/my-diff.sh")

其他Emacs 源目录 lisp/vc 中的代码似乎确实可以处理此问题,例如 vc-hg-state

(defun vc-hg-state (file)
  "Hg-specific version of `vc-state'."
   ...
        (with-output-to-string
          (with-current-buffer
              standard-output
            (setq status
                  (condition-case nil
                      ;; Ignore all errors.
              (let ((process-environment
                 ;; Avoid localization of messages so we
                 ;; can parse the output.
                 (append (list "TERM=dumb" "LANGUAGE=C")
                     process-environment)))
   ...

Ediff 不也这样做似乎有点奇怪,但也许我错过了某物。

Try changing the value of the variable ediff-diff-ok-lines-regexp to include the German text ("Kein Zeilenumbruch am Dateiende"):

(setq ediff-diff-ok-lines-regexp
      (concat
       "^\\("
       "[0-9,]+[acd][0-9,]+\C-m?$"
       "\\|[] "
       "\\|---"
       "\\|.*Warning *:"
       "\\|.*No +newline"
       "\\|.*missing +newline"
       "\\|.*Kein +Zeilenumbruch +am +Dateiende"
       "\\|^\C-m?$"
       "\\)"))

Update: Looking at the source code, it does seem that Ediff doesn't make any attempt to deal with the issue of localization of messages from diff. It should also be possible to work around this by wrapping diff in a shell script, e.g:

#!/bin/bash
LANG=C diff $*

..then customising the ediff-diff-program to call the wrapper instead:

(setq ediff-diff-program "~/bin/my-diff.sh")

Other code in the Emacs source directory lisp/vc does seem to handle this, for example vc-hg-state:

(defun vc-hg-state (file)
  "Hg-specific version of `vc-state'."
   ...
        (with-output-to-string
          (with-current-buffer
              standard-output
            (setq status
                  (condition-case nil
                      ;; Ignore all errors.
              (let ((process-environment
                 ;; Avoid localization of messages so we
                 ;; can parse the output.
                 (append (list "TERM=dumb" "LANGUAGE=C")
                     process-environment)))
   ...

It seems a bit strange that Ediff doesn't also do this, but perhaps I'm missing something.

你对谁都笑 2025-01-11 06:29:23

好吧,我发现出了什么问题,可悲的是,这很明显:我的环境有 LANG=de,因此当 Emacs 调用 diff 时,警告消息会以德语返回:好吧,Emacs 没有识别出这个“未知”消息,因此失败了。

使用 LANG=C emacs 启动 emacs 可以解决这个问题。然而,我认为假设用户的语言是英语是 emacs 的一个(非常愚蠢的)错误。

Ok, I found out what's wrong, and sadly, it's quite obvious: my environment has LANG=de, therefore when Emacs invokes diff, the warning message is returned in German as well, and Emacs, not recognising this “unkown” message, fails.

Starting emacs with LANG=C emacs works around this problem. However, I consider it a (quite silly) bug of emacs to make assumption on the user's language being English.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文