Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Org Capture buffer in specific window?

Tags:

emacs

org-mode

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.

like image 668
James Avatar asked Jun 13 '26 02:06

James


2 Answers

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...

like image 93
legoscia Avatar answered Jun 17 '26 23:06

legoscia


You could also use https://github.com/raxod502/el-patch and patch org-capture after loading (look for the (el-patch-remove (delete-other-windows))):

  (el-patch-feature org-capture) 
  (with-eval-after-load 'org-capture
    (el-patch-defun org-capture-place-template  (&optional inhibit-wconf-store)
      "Insert the template at the target location, and display the buffer.
When `inhibit-wconf-store', don't store the window configuration, as it
may have been stored before."
      (unless inhibit-wconf-store
    (org-capture-put :return-to-wconf (current-window-configuration)))
      (el-patch-remove (delete-other-windows))
      (org-switch-to-buffer-other-window
       (org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
      (widen)
      (org-show-all)
      (goto-char (org-capture-get :pos))
      (setq-local outline-level 'org-outline-level)
      (pcase (org-capture-get :type)
    ((or `nil `entry) (org-capture-place-entry))
    (`table-line (org-capture-place-table-line))
    (`plain (org-capture-place-plain-text))
    (`item (org-capture-place-item))
    (`checkitem (org-capture-place-item)))
      (org-capture-mode 1)
      (setq-local org-capture-current-plist org-capture-plist)) ) 
like image 32
mathiasp Avatar answered Jun 18 '26 00:06

mathiasp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!