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?

  • 1
    Could you add a recipe for reproducing the problem? – phils May 19 at 9:36
  • Dear phils, I edited my question, I hope it is now clearer. – PinkCollins May 19 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 May 19 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. – PinkCollins May 20 at 7:04
  • yes, C-c ), I fixed it – PinkCollins May 20 at 12:53
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.

| improve this answer | |

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.