From 8ffe236deb9eb41ad4510f663ce44435d654a6ae Mon Sep 17 00:00:00 2001 From: Kisaragi Hiu Date: Wed, 2 Oct 2019 03:37:27 +0900 Subject: [PATCH] prevent errors buffer-file-name can become nil even when opened through find-file. For example, [nov.el] (an EPUB reader) does this to disable autosaves. Instead of emitting the error, treat encountering an error as the file not being a junk file, and proceed. nov.el: https://github.com/wasamasa/nov.el --- open-junk-file.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/open-junk-file.el b/open-junk-file.el index 27d01ff..f7b1d1f 100644 --- a/open-junk-file.el +++ b/open-junk-file.el @@ -119,9 +119,10 @@ Whether the file is a JUNK or not is infered by `open-junk-file-format'.") ;;;###autoload (defun find-file-hook--open-junk-file () "Run `open-junk-file-hook' when the file is a JUNK file." - (when (string-prefix-p - (file-truename (replace-regexp-in-string "%.+$" "" open-junk-file-format)) - (file-truename buffer-file-name)) + (when (ignore-errors + (string-prefix-p + (file-truename (replace-regexp-in-string "%.+$" "" open-junk-file-format)) + (file-truename buffer-file-name))) (run-hooks 'open-junk-file-hook))) ;;;###autoload