0

I use emacs for latex, with pdf-tools. My layout is always a window with PDFView buffer on the right, any other buffer on the left.

I always want the right window that cannot be touched by anything, so I have a command anchor-buffer

;; custom function 'anchor-buffer'
(defun anchor-buffer ()
   "Anchor the current buffer to the current window."
   (interactive)
   (set-window-dedicated-p (selected-window) t))

that doesn't allow to modify a window. Consider the following case

  • I have two windows (vertical split): Left window: tex source file, Right window: pdf file, pdf-view-mode (using pdf-tools)

  • I select the pdf buffer (on the right), and I do M-x anchor-buffer. According to the function above this should "glue" the buffer in the right window. At least my anchor-buffer function works like this in all situations I tried.

  • Now suppose I want to search for a reference using RefTex on the tex source (left window), and I do C-c ). A selection buffer opens in the right window which replaces the pdf viewer.

The latter should not happen because I invoked set-window-dedicated-p on right window.

Any idea on how to solve this?

5
  • 2
    Could you add a recipe for reproducing the problem?
    – phils
    Commented May 19, 2020 at 9:36
  • Dear phils, I edited my question, I hope it is now clearer. Commented May 19, 2020 at 18:09
  • If pdf is in the left window, and you select it, how would that "fix" the right window? The question seems unclear to me.
    – Drew
    Commented May 19, 2020 at 23:45
  • @phils: C-c C-) is a RefTex command which is an example about how my anchor-function breaks. that breaks. @Drew: sorry I edited my question, you are right, thanks. Commented May 20, 2020 at 7:04
  • yes, C-c ), I fixed it Commented May 20, 2020 at 12:53

1 Answer 1

0

Solved. I replaced my anchor-buffer function with the toggle-current-window-dedication function shared here. Basically this toggle-current-window-dedication, that I report for clarity here

;; A toggle switch for set-window-dedicated-p
;; see: https://stackoverflow.com/a/2903358/2720781
;;
 (defun toggle-current-window-dedication ()
   (interactive)
   (let* ((window    (selected-window))
          (dedicated (window-dedicated-p window)))
     (set-window-dedicated-p window (not dedicated))
     (message "Window %sdedicated to %s"
              (if dedicated "no longer " "")
              (buffer-name))))
  (global-set-key [pause] 'toggle-current-window-dedication)

is supposed to do exactly what I wanted, it worked under all conditions included the nasty case described above.

Problem solved! Thanks for helping.

1
  • 1
    That's actually confusing, because it's exactly the same arguments to set-window-dedicated-p as you were using previously (when dedicating). I wouldn't expect this to deal with any edge cases that your old function couldn't cope with, so I would guess that the problem was caused by something else.
    – phils
    Commented Feb 16, 2021 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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