[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/visual-filename-abbrev c06c963 3/5: Don't error if font
From: |
Stefan Monnier |
Subject: |
[elpa] externals/visual-filename-abbrev c06c963 3/5: Don't error if fontification starts before buffer is shown in window |
Date: |
Sat, 28 Nov 2020 15:04:59 -0500 (EST) |
branch: externals/visual-filename-abbrev
commit c06c9639010d08a048d749b3c43e14a13d3530e7
Author: Tassilo Horn <tsdh@gnu.org>
Commit: Tassilo Horn <tsdh@gnu.org>
Don't error if fontification starts before buffer is shown in window
---
visual-filename-abbrev.el | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/visual-filename-abbrev.el b/visual-filename-abbrev.el
index c1b1b1c..26706f3 100644
--- a/visual-filename-abbrev.el
+++ b/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)