Display PDF pages with Telephone Line
Table of Contents
EDIT: updated 2018.06.01 to be done properly
Upon switching over to the excellent Telephone Line modeline theme from my previous Smart Mode Line, I was generally pleased by the exceptional look and feel of it. That is, until I fired up a PDF a while later and found I’d lost my page-numbers that had always been there. Eventually I was able to solve this problem by adding two items to my use-package
statements, one for pdf-tools and a subsequent one for telephone-line. I just had to reload my emacs and it worked.
(use-package pdf-tools
:ensure t
:demand t
:bind (:map pdf-view-mode-map
("G" . pdf-view-goto-page))
:config
(pdf-tools-install)
(setq pdf-view-continuous t ; don't automatically jump to next page
pdf-misc-print-programm "/usr/bin/lp"
pdf-misc-print-programm-args '( ;"-d ODH_Workroom"
"-o media=letter"
"-o sides=two-sided-long-edge"))
(add-hook 'pdf-view-mode-hook 'auto-revert-mode)
(define-pdf-cache-function pagelabels)
(defun pdf-view-page-number ()
(interactive)
(if (called-interactively-p)
(message "[pg %s/%s/%s]"
(nth (1- (pdf-view-current-page))
(pdf-cache-pagelabels))
(number-to-string (pdf-view-current-page))
(number-to-string (pdf-cache-number-of-pages)))
(format "[pg %s/%s/%s]"
(nth (1- (pdf-view-current-page))
(pdf-cache-pagelabels))
(number-to-string (pdf-view-current-page))
(number-to-string (pdf-cache-number-of-pages))))))
and then:
(use-package telephone-line
:ensure t
:after (pdf-view)
:config
;;;;;;;;; THE CORRECT WAY
(telephone-line-defsegment telephone-line-pdf-segment ()
(if (eq major-mode 'pdf-view-mode)
(propertize (pdf-view-page-number)
'face '(:inherit)
'display '(raise 0.0)
'mouse-face '(:box 1)
'local-map (make-mode-line-mouse-map
'mouse-1 (lambda ()
(interactive)
(pdf-view-goto-page))))))
;;;;;;
(setq telephone-line-primary-left-separator 'telephone-line-cubed-left
telephone-line-secondary-left-separator 'telephone-line-cubed-hollow-left
telephone-line-primary-right-separator 'telephone-line-cubed-right
telephone-line-secondary-right-separator 'telephone-line-cubed-hollow-right
telephone-line-height 24
telephone-line-evil-use-short-tag t)
;;; And this, including it as the first item in the mode-line
(setq telephone-line-lhs '((accent telephone-line-vc-segment telephone-line-erc-modified-channels-segment telephone-line-process-segment telephone-line-pdf-segment)
(nil telephone-line-projectile-segment telephone-line-buffer-segment)))
(telephone-line-mode t))