Subject: bug#43177: Bug: Emacs 27.1 hangs forever in `FcCharSetSubtractCount' from '/usr/lib/libfontconfig.so.1'

From: Alexander Shukaev <[email-masked]>
Date: Thu, 3 Sep 2020 12:24:30 +0200

On 03/09/2020 12:06, Robert Pluim wrote:
>>>>>> On Thu, 3 Sep 2020 11:53:05 +0200, Alexander Shukaev <[email-masked]> said:
> 
>      Alexander> On 03/09/2020 11:50, Alexander Shukaev wrote:
>      >> On 03/09/2020 11:40, Alexander Shukaev wrote:
>      >>> (gdb) f 7
>      >>> #7  0x0000555555a8d875 in xfont_supported_scripts
>      >>> (display=0x555556594940, fontname=0x55556a79e428 "-misc-trirong
>      >>> medium-medium-i-normal--0-0-0-0-p-0-iso10646-1",
>      >>> props=XIL(0x7ffff27926e5),
>      >>>      encoding=0x7ffff23ab8d0) at xfont.c:266
>      >>> 266          xfont = XLoadQueryFont (display, fontname);
>      >>> (gdb) pp fontname
>      >>> #<INVALID_LISP_OBJECT 0x55556a79e428>
>      >>> (gdb) pp fontname
>      >>> #<INVALID_LISP_OBJECT 0x55556a79e428>
>      >>> (gdb) p fontname
>      >>> $3 = 0x55556a79e428 "-misc-trirong
>      >>> medium-medium-i-normal--0-0-0-0-p-0-iso10646-1"
>      >>> (gdb)
>      >> It appears to always be different `fontname' here as I try multiple
>      >> times to reproduce.  Maybe it's not really hanging but is merely
>      >> ultra-slow somehow in looping over the fonts here.  Any ideas?
> 
>      Alexander> Hmm, right, waited for about a minute or so, and the file got opened
>      Alexander> finally.  Reopening it was instant as well as if something got
>      Alexander> cached/loaded already.  So any ideas how to speed things up here?  I
>      Alexander> don't think I've encountered that with 26.3...
> 
> You can check easily enough by building emacs-27 --without-cairo, that
> should get you back to emacs-26's font handling.
> 
> The issue is: why is Emacs falling back to the 'x' backend?
> 
> Robert
> 

The only related font configurations that I can think of are the following:

(defcustom init-font-families
   '("Powerline Consolas"
     "Consolas for Powerline"
     "Consolas"
     ;;
     "Powerline Inconsolata-g"
     "Inconsolata-g for Powerline"
     "Inconsolata-g"
     ;;
     "Powerline Source Code Pro"
     "Source Code Pro for Powerline"
     "Source Code Pro"
     ;;
     "Powerline DejaVu Sans Mono"
     "DejaVu Sans Mono for Powerline"
     "DejaVu Sans Mono"
     ;;
     "Monospace")
   "List of font families."
   :group 'init
   :type 'list)

(defcustom init-font-size
   12
   "Size of font."
   :group 'init
   :type 'integer)

   (defun init-frame-font-setup
       (&optional frame)
     (unless frame (setq frame (selected-frame)))
     (with-selected-frame frame
       (when (and (not noninteractive) (init-display-graphic-p))
         (let ((font (assoc 'font default-frame-alist)))
           (if font
               (when (eq frame frame-initial-frame)
                 (set-frame-font font t t)
                 (unless noninteractive
                   (message "Font: `%s'" font)))
             (let ((font-family (catch 'break
                                  (dolist (font-family init-font-families)
                                    (when (member font-family
                                                  (font-family-list))
                                      (throw 'break font-family))))))
               (setq font (when font-family
                            (format "%s-%d" font-family init-font-size))))
             (when font
               (add-to-list 'default-frame-alist `(font . ,font))
               (set-frame-font font t t)
               (unless noninteractive
                 (message "Font: `%s'" font))))))))

   (unless (or noninteractive (daemonp))
     (when (init-display-graphic-p)
       (init-frame-font-setup)))

   (dolist (hook '(after-make-frame-functions
                   focus-in-hook))
     (add-hook hook #'init-frame-font-setup))

With what I consistently get output

Font: ‘Consolas-12’

for several years already on various Linux systems that I'm using so far.