Skip to content

Commit

Permalink
Add themed colour mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
npjg authored and vedang committed Feb 21, 2021
1 parent 500191c commit a8c48cd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lisp/pdf-view.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a8c48cd

Please sign in to comment.