0
votes

How can I modify org-capture's behavior and make it place the newly opened buffer, after selecting a template, in a new vertically split window on Emacs? More precisely, how to make capture's template window be placed below (split-window-below) current focused or leftmost window?

1
Do you mean that the capture window should be to the right (or left) of the original window or that it should be below (or above) it? If you are using the "correct" emacs terminology then you mean the latter, but I find that terminology confusing, so just making sure. - NickD
Sorry, I meant to place a new window below the actual window with focus or below the leftmost window. I tried with split-window-below, but nothing worked. I will edit the question to let this more clear. Thanks. - gfreytag

1 Answers

0
votes

This is a complicated subject (which I don't understand completely - caveat emptor!). The problem is that there is a long conceptual distance between org-capture and the function that actually does the window splitting, a function called split-window-sensibly. So there are many places where you could conceivably interject a change in the behavior, but the trouble is that whatever you do that way might break a lot of other things that have nothing to do with capture.

The doc string for split-window-sensibly (do C-h f split-window-sensibly RET to read it) does mention two variables however:

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.

So I would recommend that you define your own org-capture function that sets these variables using a let-bind before calling the "real" `org-capture:

(defun my-org-capture ()
  (interactive)
  (let ((split-width-threshold nil)
        (split-height-threshold 0))
     (org-capture)))

and use it instead of the "real" one. E.g. you can bind it to what the Org mode manual recommends by doing

     (global-set-key (kbd "C-c c") 'my-org-capture)

(or modify whatever key binding you use).

The advantage of this is that it only modifies how you call org-capture, so there is virtually no chance of breaking anything else. And you can easily undo the change if necessary.