From 48eb022debb85ec3b844e6833194bb05d35cb5c5 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 22 Aug 2023 12:35:33 +0800 Subject: [PATCH] Avoid errors in posn-col-row if fonts disappear from an X server * lisp/window.el (window-font-width, window-font-height): Resort to frame-char-width/height should the font returned by font-info be unavailable. --- lisp/window.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lisp/window.el b/lisp/window.el index d91bbabc010..b0970cfb064 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -2121,12 +2121,16 @@ remapped (see `face-remapping-alist'), the function returns the information for the remapped face." (with-selected-window (window-normalize-window window t) (if (display-multi-font-p) - (let* ((face (if face face 'default)) - (info (font-info (face-font face))) - (width (aref info 11))) - (if (> width 0) - width - (aref info 10))) + ;; Opening the XLFD returned by `font-info' may be + ;; unsuccessful. Use `frame-char-width' as a recourse if + ;; such a situation transpires. + (or (when-let* ((face (if face face 'default)) + (info (font-info (face-font face))) + (width (aref info 11))) + (if (> width 0) + width + (aref info 10))) + (frame-char-width)) (frame-char-width)))) (defun window-font-height (&optional window face) @@ -2138,9 +2142,10 @@ remapped (see `face-remapping-alist'), the function returns the information for the remapped face." (with-selected-window (window-normalize-window window t) (if (display-multi-font-p) - (let* ((face (if face face 'default)) - (info (font-info (face-font face)))) - (aref info 3)) + (or (when-let* ((face (if face face 'default)) + (info (font-info (face-font face)))) + (aref info 3)) + (frame-char-height)) (frame-char-height)))) (defvar overflow-newline-into-fringe) -- 2.39.2