summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Gentry <ngentry1@liberty.edu>2020-02-09 12:50:33 -0500
committerVedang Manerikar <ved.manerikar@gmail.com>2021-02-21 11:23:39 +0530
commita8c48cdb7b14134df2f5abc18093621024ab5384 (patch)
tree4b7b1e3046d00127c43f2dbf337e8c66f50031d2
parent500191c9e102674c66f60eb8fa6594b10ac9c7e6 (diff)
Add themed colour mode
Note that this mode does not keep updated with theme changes; it only applies the colors of the current theme. Hook into `enable-theme` and `disable-theme` for that.
-rw-r--r--lisp/pdf-view.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index 56fad66..3d39079 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -321,6 +321,7 @@ regarding display of the region in the later function.")
(define-key map (kbd "C-c C-i") 'pdf-view-extract-region-image)
;; Rendering
(define-key map (kbd "C-c C-r m") 'pdf-view-midnight-minor-mode)
+ (define-key map (kbd "C-c C-r t") 'pdf-view-themed-minor-mode)
(define-key map (kbd "C-c C-r p") 'pdf-view-printer-minor-mode)
map)
"Keymap used by `pdf-view-mode' when displaying a doc as a set of images.")
@@ -1219,6 +1220,43 @@ The colors are determined by the variable
(pdf-cache-clear-images)
(pdf-view-redisplay t))
+(defun pdf-view-refresh-themed-buffer (&optional get-theme)
+ "Refresh the current buffer to activate applied colors.
+
+When GET-THEME is non-nil, also reset the applied colors to the
+current theme's colors."
+ (pdf-tools-assert-pdf-buffer)
+ (pdf-cache-clear-images)
+ (when get-theme
+ (pdf-view-set-theme-background))
+ (pdf-view-redisplay t))
+
+(defun pdf-view-set-theme-background ()
+ "Set the buffer's color filter to correspond to the current Emacs theme."
+ (pdf-tools-assert-pdf-buffer)
+ (pdf-info-setoptions
+ :render/foreground (face-foreground 'default nil)
+ :render/background (face-background 'default nil)
+ :render/usecolors t))
+
+(define-minor-mode pdf-view-themed-minor-mode
+ "Synchronize color filter with the present Emacs theme.
+
+The colors are determined by the `face-foreground' and
+`face-background' of the currently active theme."
+
+ nil " Thm" nil
+ (pdf-util-assert-pdf-buffer)
+ (cond
+ (pdf-view-themed-minor-mode
+ (add-hook 'after-save-hook #'pdf-view-set-theme-background nil t)
+ (add-hook 'after-revert-hook #'pdf-view-set-theme-background nil t))
+ (t
+ (remove-hook 'after-save-hook #'pdf-view-set-theme-background t)
+ (remove-hook 'after-revert-hook #'pdf-view-set-theme-background t)
+ (pdf-info-setoptions :render/usecolors nil)))
+ (pdf-view-refresh-themed-buffer pdf-view-themed-minor-mode))
+
(when pdf-view-use-unicode-ligther
;; This check uses an implementation detail, which hopefully gets the
;; right answer.