简体   繁体   English

告诉Emacs在特定窗口中打开新缓冲区

[英]Tell Emacs to open new buffer in specific window

If an Emacs frame is split in several windows and a new buffer is opened, is there a possibility to tell Emacs in which window to open the buffer. 如果在几个窗口中拆分Emacs帧并打开一个新缓冲区,是否有可能告诉Emacs在哪个窗口中打开缓冲区。

Especially, if one window contains a dired buffer and I want to tell Emacs in which of the other opened windows a new file shall be displayed. 特别是,如果一个窗口包含一个dired缓冲区,并且我想告诉Emacs在哪个其他打开的窗口中应该显示一个新文件。

If the Emacs frame is for example split like this: 如果Emacs框架例如像这样拆分:

____________________
|        |         |
|        |         |
|   A    |    B    |
|        |         |
|        |         |
--------------------
|        |         |
|   C    |    D    |
|        |         |
--------------------

Where A,B,C and D are the windows. 其中A,B,C和D是窗户。 If A contains a dired buffer, can I tell Emacs to open a new file in a new buffer in window D? 如果A包含一个dired缓冲区,我可以告诉Emacs在窗口D的新缓冲区中打开一个新文件吗?

Here's another answer -- 这是另一个答案 -

You can do what you want using Icicles . 你可以用冰柱做你想做的事。 In Icicle mode, Cx o , which is normally other-window , is icicle-other-window-or-frame . Icicle模式中, Cx o (通常是other-window )是icicle-other-window-or-frame A prefix arg gives it several alternative behaviors, one of which (for Emacs 24 and later) is to choose a window that will be used by the next buffer-displaying operation (eg, Cx Cf , Cx b ). 前缀arg为其提供了几种替代行为,其中一种(对于Emacs 24及更高版本)是选择将由下一个缓冲区显示操作使用的窗口(例如, Cx CfCx b )。

That's what happens if you use a double plain prefix arg: Cu Cu Cx o . 如果你使用双普通前缀arg: Cu Cu Cx o会发生这种情况。 That invokes command icicle-choose-window-for-buffer-display , which you could of course also bind to any other key. 这会调用命令icicle-choose-window-for-buffer-display ,你当然也可以绑定到任何其他键。

You choose the target window by name (using completion or cycling etc.). 您可以按名称选择目标窗口(使用完成或循环等)。

All that command does is set variable icicle-next-window-for-display-buffer to the window that you choose. 所有该命令都将变量icicle-next-window-for-display-buffer设置为您选择的窗口。 Icicles advises commands display-buffer , switch-to-buffer , and switch-to-buffer-other-window so that the next time they are called they use the window that is the value of icicle-next-window-for-display-buffer . Icicles建议命令display-bufferswitch-to-bufferswitch-to-buffer-other-window以便下次调用它们时,它们使用的窗口是icicle-next-window-for-display-buffer (After that invocation they return to their normal behavior.) (在调用之后,它们会恢复正常行为。)

This means too that if you have another method of choosing a window, which you prefer (eg cycling using one of the other methods mentioned here ), then you could modify that method to set icicle-next-window-for-display-buffer to the chosen window, to get the same effect (in Icicle mode). 这也意味着,如果您有另一种选择窗口的方法,您更喜欢(例如使用此处提到的其他方法之一循环),那么您可以修改该方法以将icicle-next-window-for-display-buffer为选择的窗口,以获得相同的效果(在冰柱模式下)。 IOW, it does matter how you choose the window; IOW,你选择窗户的方式很重要; just set the variable value to it and the next buffer-displaying action will use it. 只需将变量值设置为它,下一个缓冲区显示操作将使用它。

Others will probably give you answers that more directly respond to your question. 其他人可能会给你更直接回答你问题的答案。 My answer is to just move the focus to the window you want and then use Cx Cf or whatever to open the file or display the buffer you want in that selected window. 我的答案是只需将焦点移动到您想要的窗口,然后使用Cx Cf或其他任何内容打开文件或在所选窗口中显示所需的缓冲区。

In order to do what you requested directly, you need anyway to use a key sequence that invokes the command you want. 为了直接执行您的请求,您无论如何都需要使用调用所需命令的键序列。 And if you want something general that works with different commands (eg find-file and switch-to-buffer ) then you need to use a prefix key or repurpose the prefix arg. 如果你想要一些适用于不同命令的通用(例如find-fileswitch-to-buffer ),那么你需要使用前缀键或重新设置前缀arg。 That is typically just as many key strokes as it is to switch to the window and then use the usual command. 这通常与切换到窗口然后使用常用命令一样多的关键笔划。

Of course, with my suggestion you need a command to quickly switch to the window you want. 当然,根据我的建议,您需要一个命令来快速切换到您想要的窗口。 There are various commands out there that let you cycle among windows or use completion to quickly pick a window by name or number. 有各种命令可以让你在窗口之间循环或使用完成来快速选择一个名称或数字的窗口。

So that's what I would suggest: switch to the window and then display whatever you want there, instead of trying to combine (a) designating the target window with (b) invoking the command that displays the buffer. 这就是我的建议:切换到窗口然后显示你想要的任何东西,而不是试图组合 (a)指定目标窗口和(b)调用显示缓冲区的命令。 IOW, just do it the old-school way: go to the window and then display there. 我只是按照老派的方式去做:去窗口然后在那里展示。

Of course, if you don't really want to end up in that newly displayed buffer, and you just want to keep the focus where you started, then with my suggestion you would need to cycle (eg) back to your starting window. 当然,如果你真的不想在新显示的缓冲区中结束,并且你只想将焦点保持在你开始的位置,那么根据我的建议你需要循环(例如)回到你的起始窗口。 It's not clear from your description whether this is your use case. 从您的描述中不清楚这是否是您的用例。 If it is, then my solution is probably not that helpful. 如果是,那么我的解决方案可能没那么有用。

But even in that case, it might still be useful to split things up: (a) a command to (only) designate the window to use for the following display-buffer command and (b) the display-buffer command. 但即使在这种情况下,拆分也可能仍然有用:(a)命令(仅)指定用于以下display-buffer命令的窗口和(b)display-buffer命令。 IOW, do essentially the same thing I suggested, but the first step would only designate the target window instead of switching to it, and the second step would use that designated window. IOW,基本上和我建议的一样,但第一步只会指定目标窗口而不是切换到它,第二步将使用指定的窗口。 (You would need to define (a) and (b), as a general mechanism.) (您需要将(a)和(b)定义为一般机制。)

In this case too my suggestion differs probably from what others might suggest, in that it does not try to combine window choice with display command. 在这种情况下,我的建议也可能与其他人的建议不同,因为它不会尝试窗口选择与显示命令相结合 They are coupled sequentially, but not combined in one command. 它们按顺序耦合,但不在一个命令中组合。

make the window that you would like to load the buffer in, 制作你想加载缓冲区的窗口,
activated and press: 激活并按下:

C-x b

and you will be prompted by: 并且您将被提示:

Switch to buffer (default *Buffer List*):

press enter(ret) without writing anything to choose the default. 按下输入(ret)而不写任何内容来选择默认值。 and then you will find buffer list loaded in that window. 然后你会在那个窗口中找到加载的缓冲区列表。 then choose the one you like to load and you will find it loaded in the same window. 然后选择你想要加载的那个,你会发现它加载在同一个窗口中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM