I want to add a rule to display-buffer-alist
, that splits the frame to the right when opening a .pdf
file if and only if there is a corresponding .tex
file in the same folder.
According to the documentation of display-buffer-alist
, I can specify a predicate function which takes a buffer name and an action. I can't get it to work however, and I don't understand what the action argument of the predicate function is supposed to do.
My code looks like this:
(setq display-buffer-alist
`((#'cst/latex-pdf-p . ((display-buffer-reuse-window display-buffer-in-side-window)
(side . right)
(slot . 1)
(window-width . 0.33)
(reusable-frames . nil)))))
(defun cst/latex-pdf-p (buffer-name action)
"Determine if there is a corresponding .tex file in the current folder."
(when (string= "pdf" (file-name-extension buffer-name))
(file-exists-p (concat (file-name-base buffer-name) ".tex"))))
The predicate function seems to work as expected when I evaluate it from a buffer split.pdf
with split.tex
in the same folder it returns t
, on other pdfs it returns nil
. When using the regexp \\.pdf$
the split works, but on all pdfs. Using the rule with the predicate function it does not work on any pdf.
I feel like I misunderstand how the predicate function should work.