branch: externals/show-font commit f6239ae7b843a513b4238506eb57f98485f75d79 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Fix the file handler to also deal with insert-file-contents The previous code was faulty. The idea is that we want to show preview text only when we are visiting the file, but otherwise the functions insert-file-contents and insert-file-contents-literally should work as expected. Thanks to Zhengyi Fu for reporting an error on the Emacs bug tracker bug#78990: <https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-07/msg00444.html>. --- README.org | 3 ++- show-font.el | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.org b/README.org index 597f97c550..aff1cee024 100644 --- a/README.org +++ b/README.org @@ -220,7 +220,8 @@ matters. + Contributions to code or the manual :: Eli Zaretskii, Philip Kaludercic, Swapnil Mahajan. -+ Ideas and/or user feedback :: Darryl Hebbes, Perry Metzger. ++ Ideas and/or user feedback :: Darryl Hebbes, Perry Metzger, Zhengyi + Fu. * COPYING :PROPERTIES: diff --git a/show-font.el b/show-font.el index a526d9c3af..7c34b3d8ff 100644 --- a/show-font.el +++ b/show-font.el @@ -218,21 +218,20 @@ return nil." (defun show-font-handler (operation &rest args) "Handle the given I/O `file-name-handler-alist' OPERATION with ARGS. Determine how to render the font file contents in a buffer." - (cond - ((eq operation 'insert-file-contents) - (when-let* ((filename (car args)) - (visit (cadr args))) - (setq buffer-file-name filename) - (list buffer-file-name (point-max))) - (show-font--add-text)) - ;; Handle any operation we do not know about. This is copied from - ;; the example shown in (info "(elisp) Magic File Names"). - (t (let ((inhibit-file-name-handlers - (cons #'show-font-handler - (and (eq inhibit-file-name-operation operation) - inhibit-file-name-handlers))) - (inhibit-file-name-operation operation)) - (apply operation args))))) + ;; Handle any operation we do not know about. This is copied from + ;; the example shown in (info "(elisp) Magic File Names"). + (if-let* ((_ (eq operation 'insert-file-contents)) + (filename (car args)) + (visit (cadr args))) + (progn + (setq buffer-file-name filename) + (show-font--add-text)) + (let ((inhibit-file-name-handlers + (cons #'show-font-handler + (and (eq inhibit-file-name-operation operation) + inhibit-file-name-handlers))) + (inhibit-file-name-operation operation)) + (apply operation args)))) (defun show-font--get-attribute-from-file (attribute &optional file) "Get font family ATTRIBUTE from the current file or given FILE.