Search code examples
emacsorg-mode

Open Org Capture buffer in specific window?


I've been an Emacs user for about a year or so. I routinely have the same window set up each session (four windows).

I've set up capture templates and can capture what I want, but: instead of capture mode temporarily jerking me out of my window setup, I'd like the chosen capture template to open in a new (fifth) window, preserving my existing layout. I typically want the capture template open for a while, so it's disruptive.

This seems like it would be an obvious option, but I can't figure it out. Thanks in advance to all the Emacs heads out there.


Solution

  • I came up with a easier-to-use version of Dan's answer to the linked question:

    (defun my-org-capture-place-template-dont-delete-windows (oldfun &rest args)
      (cl-letf (((symbol-function 'delete-other-windows) 'ignore))
        (apply oldfun args)))
    
    (with-eval-after-load "org-capture"
      (advice-add 'org-capture-place-template :around 'my-org-capture-place-template-dont-delete-windows))
    

    That is, instead of having to modify Org-mode code and remove the call to delete-other-windows, this piece of code temporarily redefines delete-other-windows to ignore while org-capture-place-template is being called.

    It doesn't do quite what you want: it picks one of the existing windows and puts the capture buffer there. At least it's better than the default behaviour of removing all previous windows but one.

    There's probably a way to do what you want by customising the variable display-buffer-alist, but I couldn't figure it out...