branch: master commit 8ca1209df6a3b7278f359cd188af74bc41f59845 Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Don't error if fontification starts before buffer is shown in window --- .../visual-filename-abbrev/visual-filename-abbrev.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/visual-filename-abbrev/visual-filename-abbrev.el b/packages/visual-filename-abbrev/visual-filename-abbrev.el index c1b1b1c..26706f3 100644 --- a/packages/visual-filename-abbrev/visual-filename-abbrev.el +++ b/packages/visual-filename-abbrev/visual-filename-abbrev.el @@ -106,13 +106,18 @@ Shorter means less characters here." (defun visual-filename-abbrev--abbrev-visually-shorter-p (buffer pos filename abbrev) "Return non-nil if ABBREV's display representation is shorter than FILENAME. This takes the font into account." - ;; NOTE: The docs say that object in an conditional display spec is always a - ;; buffer, but actually it sometimes is a window. See bug#34771. - (let ((font (font-at pos (if (windowp buffer) - buffer - (get-buffer-window buffer))))) - (< (visual-filename-abbrev--get-visual-width abbrev font) - (visual-filename-abbrev--get-visual-width filename font)))) + ;; When activated from a hook, this function may run before the current + ;; buffer is shown in a window. In that case, `font-at' would error with + ;; "Specified window is not displaying the current buffer". + (when (eq buffer (current-buffer)) + ;; NOTE: The docs say that object in an conditional display spec is always + ;; a buffer, but actually it sometimes is a window. See the already fixed + ;; bug#34771. + (let ((font (font-at pos (if (windowp buffer) + buffer + (get-buffer-window buffer))))) + (< (visual-filename-abbrev--get-visual-width abbrev font) + (visual-filename-abbrev--get-visual-width filename font))))) (defcustom visual-filename-abbrev-predicates (list #'visual-filename-abbrev--abbrev-visually-shorter-p)