From 80d0d40a341ef6b5791561333939f1b83b538d56 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Fri, 22 Mar 2019 02:19:25 +0800 Subject: [PATCH] [Performance] Improve the performance of pdf-pages segment. --- doom-modeline-segments.el | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index 7be8850..5208910 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -1831,15 +1831,21 @@ mouse-1: Toggle Debug on Quit" ;; pdf pages ;; +(defvar-local doom-modeline--pdf-pages nil) +(defun doom-modeline-update-pdf-pages () + (setq doom-modeline--pdf-pages + (propertize + (format " P%d/%d " + (eval `(pdf-view-current-page)) + (pdf-cache-number-of-pages)) + 'face (if (doom-modeline--active) + 'mode-line + 'mode-line-inactive)))) +(add-hook 'pdf-view-change-page-hook #'doom-modeline-update-pdf-pages) + (doom-modeline-def-segment pdf-pages (when (eq major-mode 'pdf-view-mode) - (propertize - (format " P%d/%d " - (eval `(pdf-view-current-page)) - (pdf-cache-number-of-pages)) - 'face (if (doom-modeline--active) - 'mode-line - 'mode-line-inactive)))) + doom-modeline--pdf-pages)) ;;