如何在 emacs 的新垂直拆分 window 中创建 org-capture 打开缓冲区?

How to make org-capture open buffers in new vertical split window in emacs?

如何修改 org-capture 的行为并使其在选择模板后将新打开的缓冲区放置在 Emacs 上新的垂直分割 window 中?更准确地说,如何使捕获的模板 window 放置在当前焦点下方(split-window-下方)或最左侧 window?

这是一个复杂的主题(我不完全理解 - 买者自负!)。问题在于 org-capture 与实际执行 window 拆分的函数之间存在很长的概念距离,该函数称为 split-window-sensibly。所以有很多地方你可以想像地插入行为的变化,但问题是无论你做什么,都可能破坏很多与捕获无关的其他东西。

split-window-sensibly 的文档字符串(执行 C-h f split-window-sensibly RET 阅读)确实提到了两个变量:

By default display-buffer routines call this function to split the largest or least recently used window. To change the default customize the option split-window-preferred-function.

You can enforce this function to not split WINDOW horizontally, by setting (or binding) the variable split-width-threshold to nil. If, in addition, you set split-height-threshold to zero, chances increase that this function does split WINDOW vertically.

In order to not split WINDOW vertically, set (or bind) the variable split-height-threshold to nil. Additionally, you can set `split-width-threshold' to zero to make a horizontal split more likely to occur.

所以我建议您定义自己的 org-capture 函数,在调用 "real" `org-capture:

之前使用 let-bind 设置这些变量
(defun my-org-capture ()
  (interactive)
  (let ((split-width-threshold nil)
        (split-height-threshold 0))
     (org-capture)))

并使用 it 而不是 "real"。例如。你可以通过做

将它绑定到 Org 模式手册推荐的内容
     (global-set-key (kbd "C-c c") 'my-org-capture)

(或修改您使用的任何键绑定)。

这样做的好处是它修改了你调用org-capture的方式,所以几乎没有机会破坏其他任何东西。如果需要,您可以轻松撤消更改。