Emacs diff-mode 移动非常慢

Emacs Unicode branch 用 diff-mode 浏览 diff 或者 patch 文件时候,在使用 M-n 或者 M-p 的时候,常常会停在那里,然后 Emacs 完全就没有反应了,大概能过十几秒到半分钟左右才到下一个块,而文件操作 M-N 或者 M-P 就没有问题。似乎是跟特定的块有关系,随便用一个 diff 文件基本上都能碰得到。看起来有问题的块有一个共同的特点,就是有复杂的修改,而不是简单的 + 或者 -,那么 Emacs 就要试图把修改精确地表示出来,比如一行中加了一个词或者改了什么字符,可能需要计算时间,但是两三行的修改也会有这个问题,让人比较讨厌。如下文件所示:

  1. --- t1.txt      Sun Nov 25 22:02:20 2007
  2. +++ t2.txt      Sun Nov 25 22:02:28 2007
  3. @@ -1,3 +1,3 @@
  4.  ther are random characters
  5. -this is a test file, haha, take a look
  6. +this is another test file, hehe, take a look
  7.  ther are random characters

渲染出来如图所示:

解决方法

这个似乎在 win32 上有问题,Linux 下还可以。刚才研究了一下 diff-mode 的配置,看到一个选项 Diff Auto Refine

  1. Diff Auto Refine: on (non-nil)
  2.    Automatically highlight changes in detail as the user visits hunks.

将其设置为 nil,那些高亮区域就不会显示出来,速度就快许多了。

看起来似乎跟 diff-mode.el:diff-refine-hunk()smerge-mode:smerge-refine-subst() 有点关系。

更正确的解决方法

上次只是把 Diff Auto Refine 禁掉了,并不是完全地解决了问题。最后是发现跟 [MinGW] 有关系。diff-mode 显示 diff 的时候,如果 Diff Auto Refine 开启,会调用 smerge-refine-subst 进行显示调整,在这个函数中,会调用 diff 命令。问题就来了,在我的系统中,使用 MinGW 自己的 diff 命令在非 MinGW 环境中调用非常慢,比如开启一个 CMD 窗口中运行,那么 Emacs 中也一样很慢。然后就去换了 [GnuWin32] 中的 diff,运行起来就非常快了。但是 MinGW 中其他的一些包是没有问题的。很奇怪。

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You can use BBCode tags in the text.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
  _    __     __  __       _   _   _       _____   ____  
(_) / /_ | \/ | | | | | | |__ | ____| | _ \
| | | '_ \ | |\/| | _ | | | | | '_ \ | _| | |_) |
| | | (_) | | | | | | |_| | | | | | | | | |___ | __/
|_| \___/ |_| |_| \___/ |_| |_| |_| |_____| |_|
Enter the code depicted in ASCII art style.