From f3d359ba69928ff8fe1b662629b40e6b425b459b Mon Sep 17 00:00:00 2001 From: Justus Piater Date: Wed, 31 Dec 2025 16:40:00 +0100 Subject: [PATCH 1/2] fix(pdf-view): read encrypted PDFs pdf-view-mode now identifies encrypted files by file name (perhaps not ideal but this is how epa does it) and treats them as remote. Fixes: #256 --- lisp/pdf-view.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el index 620e5269..33352557 100644 --- a/lisp/pdf-view.el +++ b/lisp/pdf-view.el @@ -383,7 +383,11 @@ PNG images in Emacs buffers." (when (and (or jka-compr-really-do-compress (let ((file-name-handler-alist nil)) (not (and buffer-file-name - (file-readable-p buffer-file-name))))) + (file-readable-p buffer-file-name) + (or (not (boundp 'epa-inhibit)) + epa-inhibit + (not (string-match epa-file-name-regexp + buffer-file-name))))))) (pdf-tools-pdf-buffer-p)) (let ((tempfile (pdf-util-make-temp-file))) (write-region nil nil tempfile nil 'no-message) From 16461835816179fdcc8218d84680eea3714586d6 Mon Sep 17 00:00:00 2001 From: Justus Piater Date: Wed, 31 Dec 2025 16:52:44 +0100 Subject: [PATCH 2/2] fix(pdf-view): write compressed, encrypted or inside-archive PDFs pdf-view--write-contents-function no longer copies the local changes directly to the destination file. Instead, it loads them into the buffer and returns nil, causing the chain of write-contents-functions to proceed. Thus, writing now is roughly the inverse of reading. Fixes: #257, #258 --- lisp/pdf-view.el | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el index 33352557..4cdca847 100644 --- a/lisp/pdf-view.el +++ b/lisp/pdf-view.el @@ -560,30 +560,21 @@ operating on a local copy of a remote file." (defun pdf-view--write-contents-function () "Function for `write-contents-functions' to save the buffer." (when (pdf-util-pdf-buffer-p) - (let ((tempfile (pdf-info-save pdf-view--server-file-name))) + (let ((tempfile (pdf-info-save pdf-view--server-file-name)) + (inhibit-read-only t)) (unwind-protect (progn - ;; Order matters here: We need to first copy the new - ;; content (tempfile) to the PDF, and then close the PDF. + ;; Order matters here: We need to first read the new + ;; content (tempfile) into the buffer, and then close the PDF. ;; Since while closing the file (and freeing its resources ;; in the process), it may be immediately reopened due to ;; redisplay happening inside the pdf-info-close function ;; (while waiting for a response from the process.). - (copy-file tempfile (or (buffer-file-name) - (read-file-name - "File name to save PDF to: ")) - t) - (pdf-info-close pdf-view--server-file-name) - - (when pdf-view--buffer-file-name - (copy-file tempfile pdf-view--buffer-file-name t)) - (clear-visited-file-modtime) - (set-buffer-modified-p nil) - (setq pdf-view--server-file-name - (pdf-view-buffer-file-name)) - t) + (insert-file-contents tempfile nil nil nil t) + (pdf-info-close pdf-view--server-file-name)) (when (file-exists-p tempfile) - (delete-file tempfile)))))) + (delete-file tempfile))))) + nil) (defun pdf-view--after-revert () "Reload the local copy in case of a remote file, and close the document."