2

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.

1
  • `((#'cst/latex-pdf-p should be `((cst/latex-pdf-p so that you're not double-quoting it. Your original form is the same as `(((function cst/latex-pdf-p) which would only provide a function if that condition were evaluated. You could use `((,#'cst/latex-pdf-p to do that evaluation, but I don't think it's beneficial here.
    – phils
    Jun 27 at 14:52
1

try :

(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))))

The predicate is evaluated by display-buffer-assq-regexp, which uses funcall on a variable with as value, your function. It won't work if you quote it. Also your alist was not well formed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.