branch: elpa/pdf-tools
commit ffba5f7208a2cf36df80fac9a17731f514f40060
Author: Daniel Nicolai <dalanico...@gmail.com>
Commit: Vedang Manerikar <ved.maneri...@gmail.com>

    Guard against dead buffers in pdf-tools-install-noverify
    
    I am not sure how to 'consistently' reproduce the issue that this
    commit fixes. But I was experiencing the issue as reported at
    https://github.com/syl20bnr/spacemacs/issues/15106, where for some
    reason `pdf-view-mode` did not open in evil `evilified-state`.
    
    After (a long time of) hunting down the cause, I found that
    `pdf-tools` (silently) errors when the `buffer-list` contains killed
    buffers. The error occurs because `pdf-tools-install-noverify` calls
    `with-current-buffer` with the killed buffer. This commit simply adds
    the `buffer-live-p` check before the `with-current-buffer` form gets
    called.
    
    Closes: #93
    Potentially Fixes: syl20bnr/spacemacs#15106
    Author: @dalanicolai
---
 lisp/pdf-tools.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lisp/pdf-tools.el b/lisp/pdf-tools.el
index 6f64d1ef01..9d15269286 100644
--- a/lisp/pdf-tools.el
+++ b/lisp/pdf-tools.el
@@ -433,11 +433,15 @@ See `pdf-view-mode' and `pdf-tools-enabled-modes'."
     (pdf-virtual-global-minor-mode 1))
   (add-hook 'pdf-view-mode-hook #'pdf-tools-enable-minor-modes)
   (dolist (buf (buffer-list))
-    (with-current-buffer buf
-      (when (and (not (derived-mode-p 'pdf-view-mode))
-                 (pdf-tools-pdf-buffer-p)
-                 (buffer-file-name))
-        (pdf-view-mode)))))
+    ;; This when check should not be necessary, but somehow dead
+    ;; buffers are showing up here. See
+    ;; https://github.com/vedang/pdf-tools/pull/93
+    (when (buffer-live-p buf)
+      (with-current-buffer buf
+        (when (and (not (derived-mode-p 'pdf-view-mode))
+                   (pdf-tools-pdf-buffer-p)
+                   (buffer-file-name))
+          (pdf-view-mode))))))
 
 (defun pdf-tools-uninstall ()
   "Uninstall PDF-Tools in all current and future PDF buffers."

Reply via email to