diff options
| author | Vedang Manerikar <ved.manerikar@gmail.com> | 2023-06-11 08:06:33 +0530 |
|---|---|---|
| committer | Vedang Manerikar <ved.manerikar@gmail.com> | 2023-06-11 08:06:33 +0530 |
| commit | d1d331a57e03fa141cb2ebb1bb80f96ab70d0721 (patch) | |
| tree | 162dbaa9a7eece6d8b554575df98a7454fb6eb92 | |
| parent | 70865fb38ddf97023e7d23a7cc8ff22b13b643b0 (diff) | |
[v2] Auto enable pdf-view-dark-minor-mode if the theme is dark
The first attempt at this workaround was
c451c0e3db5b367d191bddf428e38fd8a21c0102 , which did not work
because (my guess) `pdf-tools-enabled-modes` would be evaluated before
the theme was loaded. This is attempt 2, which sets this value in the
`pdf-view-mode` function itself.
This is meant as a workaround for #166 (which see).
Best guess about what is happening and why this workaround works comes
from @d8660091 (lightly edited):
> I'm using M2 and I can reproduce the issue with just the following
> snippets I extracted from pdf-isearch-current-colors, which was
> invoked during a pdf isearch:
(add-hook 'pdf-tools-enabled-hook
(lambda ()
(pdf-util-face-colors 'pdf-isearch-match nil)
(pdf-util-face-colors 'pdf-isearch-lazy nil)))
> And run `pdf-tools-install`
> I tried adding `(sit-for 1)` before `(delete-frame f)`, the crash
> was gone.
> But I am still not sure what's really happening.
> I think `pdf-view-dark-minor-mode` works because new frame is not
> created and `delete-frame` doesn't happen.
If anyone has an idea about what is happening here and what the
correct way to fix it is, please get in touch via the linked issue!
| -rw-r--r-- | lisp/pdf-tools.el | 31 | ||||
| -rw-r--r-- | lisp/pdf-view.el | 10 |
2 files changed, 22 insertions, 19 deletions
diff --git a/lisp/pdf-tools.el b/lisp/pdf-tools.el index 382d5b6..6211369 100644 --- a/lisp/pdf-tools.el +++ b/lisp/pdf-tools.el @@ -134,25 +134,18 @@ In order to customize dark and light colors use pdf-virtual-global-minor-mode)) (defcustom pdf-tools-enabled-modes - (append '(pdf-history-minor-mode - pdf-isearch-minor-mode - pdf-links-minor-mode - pdf-misc-minor-mode - pdf-outline-minor-mode - pdf-misc-size-indication-minor-mode - pdf-misc-menu-bar-minor-mode - pdf-annot-minor-mode - pdf-sync-minor-mode - pdf-misc-context-menu-minor-mode - pdf-cache-prefetch-minor-mode - pdf-occur-global-minor-mode) - ;; See an interesting discussion at: - ;; https://github.com/vedang/pdf-tools/issues/166 about how - ;; this avoids a segfault crash in MacOS Ventura. IF you - ;; know why this happens, please get in touch via the linked - ;; issue. - (when (eq 'dark (frame-parameter nil 'background-mode)) - '(pdf-view-dark-minor-mode))) + '(pdf-history-minor-mode + pdf-isearch-minor-mode + pdf-links-minor-mode + pdf-misc-minor-mode + pdf-outline-minor-mode + pdf-misc-size-indication-minor-mode + pdf-misc-menu-bar-minor-mode + pdf-annot-minor-mode + pdf-sync-minor-mode + pdf-misc-context-menu-minor-mode + pdf-cache-prefetch-minor-mode + pdf-occur-global-minor-mode) "A list of automatically enabled minor-modes. PDF Tools is build as a series of minor-modes. This variable and diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el index 9253721..697fbb7 100644 --- a/lisp/pdf-view.el +++ b/lisp/pdf-view.el @@ -332,6 +332,7 @@ regarding display of the region in the later function.") map) "Keymap used by `pdf-view-mode' when displaying a doc as a set of images.") +(defvar pdf-tools-enabled-modes) (define-derived-mode pdf-view-mode special-mode "PDFView" "Major mode in PDF buffers. @@ -368,6 +369,15 @@ PNG images in Emacs buffers." (if (boundp 'mwheel-coalesce-scroll-events) (setq-local mwheel-coalesce-scroll-events t)) + ;; If the Emacs theme is dark, add `pdf-view-dark-minor-mode' to the + ;; list of `pdf-tools-enabled-modes'. See an interesting discussion + ;; at: https://github.com/vedang/pdf-tools/issues/166 about how this + ;; avoids a segfault crash in MacOS Ventura. IF you know why this + ;; happens, please get in touch via the linked issue. + + (when (eq 'dark (frame-parameter nil 'background-mode)) + (add-to-list 'pdf-tools-enabled-modes 'pdf-view-dark-minor-mode)) + ;; Clearing overlays (add-hook 'change-major-mode-hook (lambda () |
