我可以让 emacs grep windows 只使用另一个窗口来打开文件吗?

Joh*_*den 5 windows emacs find-grep

我面前有 emacs。

我运行了 find-grep,它有很多命中,这些命中显示在一个窗口中。文件名以绿色显示为超链接。

我将其设为唯一的窗口,Cx 1。

如果我单击文件名,窗口会垂直分割,并且包含找到的文本的文件将显示在另一个窗口中。

如果我单击更多文件名,则新文件将替换旧文件,这就是我想要发生的情况。

到目前为止,一切都很好...

但是,如果我调整窗口大小,则 emacs 会定期(当我单击时)再次分割两个窗口之一,从而使显示难以阅读。然后它将在两个新窗口之间循环打开新文件。有时它会打开更多的窗户,使情况变得更糟。如果我关闭任何这些新窗口,它们就会再次重新打开。

事实上,有时即使我不调整任何东西的大小,这种不正常的行为也会发生。如果我这样做的话,这种情况似乎会更频繁地发生。

我希望 emacs 停止胡闹,只有一个 find-grep 窗口和一个“显示”窗口,并且始终用新文件替换显示窗口。我还希望能够将这些窗口设置为看起来最方便的尺寸。

有什么办法可以实现这一点吗?

或者任何人都可以向我指出一篇关于整个事情(替换此窗口的内容/替换不同窗口的内容/通过拆分创建另一个窗口)的工作原理的文章,这样我就可以理智地破解它。

spk*_*spk 3

简短的修复:尝试这样做

(setq split-height-threshold nil
      split-width-threshold nil)
Run Code Online (Sandbox Code Playgroud)

这将阻止 Emacs 自动分割窗口(水平或垂直)。在其他情况下这可能是不可取的,但这应该可以完成工作。尝试一周左右,看看它是否会扰乱你的流程。

另外,我发现如果该点位于其中一个窗口中,并且单击链接,该文件将在下一个窗口(如果有)中打开。

所以,如果你想让文件在正确的窗口中打开(当你有多个窗口时),你可以确保该点位于你想要的窗口之前的窗口中。

更长的答案:

OK. I was able to reproduce the problem. The thing is the window showing the files is pretty big (wide or tall) because you resized it and Emacs sees that the width or height is greater than the respective threshold and splits it likewise. So, we have to either make the threshold higher or disallow the behaviour completely.

And, just to answer the last few questions:

  • To get current window - (selected-window)
  • To get next window - (next-window)
  • To select a window - (select-window foo-window)
  • To get the buffer of the current window - (current-buffer)
  • To get the buffer of some window - (window-buffer foo-window)
  • To set a buffer for a window - (set-window-buffer foo-window bar-buffer)

I'm sure you can hack together decent window/buffer management functions using these functions.

You can use C-h f to get more details on each of these functions. Also check out the Elisp manual - http://www.chemie.fu-berlin.de/chemnet/use/info/elisp/elisp_26.html