Better org-mode Agenda display-buffer-alist Settings

In the previous post I showed some settings to manage a tab dedicated to Org Agenda and its related org files.

I also mentioned that I didn’t like how that tab was actually handled, e.g. when I wanted to break out into other tabs.

The following settings work much better for me, 99% thanks to a comment by @dme.

Org Agenda with a split at default widths.

The behavior now is this:

  • Org Agenda shows in the “Org Files” tab exclusively. It’s a dedicated window so that it stays open when I interact with the agends: selecting items on the agenda will force a split window.
  • Org Agenda-related .org files, i.e. the details that will show when I select something from the agenda, will prefer to share the same split instead of making a new split every time.
  • If I’m alreayd in another tab, i.e. not the “Org Files” tab, visiting an .org file, then switching buffers to another org buffer will show the buffer in the current window. (Previously, it would take me to the “Org Files” tab and add a new split there, which was quite jarring.)
(defun ct/display-buffer-org-agenda-managed-p (buffer-name action)
  "Determine whether BUFFER-NAME is an org-agenda managed buffer."
  (with-current-buffer buffer-name
    (and (derived-mode-p 'org-mode)
         (member (buffer-file-name) (org-agenda-files)))))

(add-to-list 'display-buffer-alist
             `("\\*Org Agenda\\*"
               (display-buffer-in-tab  ;; Make sure to use the "Org Files" tab
                display-buffer-reuse-mode-window)
               (ignore-current-tab . t)
               (tab-name . "Org Files")
               (window-width . ,ct/org-agenda-width)
               (dedicated . side)  ;; Make the Agenda a dedicated side-window
               (side . left)       ;; to the left so it always stays open.
               (inhibit-same-window . nil)))
(add-to-list 'display-buffer-alist
             '(ct/display-buffer-org-agenda-managed-p
               (display-buffer-reuse-mode-window  ;; Prioritize reuse of current window
                display-buffer-in-tab)            ;; over switching to the Org tab.
               (tab-name . "Org Files")))

I’m pretty happy with thse settings since the original post 3 weeks ago!