I'm running auctex and pdf-tools to view pdf's within emacs. My problem is that I'd like to scale the pdf window horizontally after running
So far, I've created a hook to execute the settings I want in the buffer.
(add-hook 'pdf-view-mode-hook (lambda () ;; key-bindings (my/pdf-view-keys) ;; dark mode (setq pdf-view-midnight-colors '("#f6f3e8" . "#242424")) (pdf-view-midnight-minor-mode) ;; open pdfs scaled to fit page (setq-default pdf-view-display-size 'fit-page) ;; more fine-grained zooming (setq pdf-view-resize-factor 1.1) ;; disable line-numbering (display-line-numbers-mode 0) ;; resize horizontally (setq right-margin-width 0) (setq left-margin-width 0) (setq fit-window-to-buffer-horizontally 0) (fit-window-to-buffer) ))
Now, the issue is that the window does not scale correctly at first. If I run
fit-window-to-buffer manually (a few times), it scales the window nicely, but I'd like to avoid having to manually do this every time.
I'm guessing that the problem is that it's trying to scale before the pdf has loaded? If so, is there a way to delay the call to fit the window? If not, what am I doing wrong?
It appears that the following partially works.
(defun test-after () (fit-window-to-buffer) (fit-window-to-buffer) ) (add-hook 'pdf-view-after-change-page-hook 'test-after)
fit-window-to-buffer call has to be made several times, but it doesn't seem to completely fit correctly. After scrolling through to the next page, however, it calls it again and scales it to the right size.
Thanks to NickD for the suggestion.