Subject: Re: 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 21:47:41 +0200

On 03/09/2020 18:39, Alexander Shukaev wrote:
> On 03/09/2020 17:10, Robert Pluim wrote:
>>>>>>> On Thu, 03 Sep 2020 16:48:04 +0200, Andreas Schwab 
>>>>>>> <[email-masked]> said:
>>
>>      Andreas> On Sep 03 2020, Robert Pluim wrote:
>>      >> Does it go away if you set font-backend . ftcrhb in your frame
>>      >> parameters (assuming youʼre using Cairo)?
>>
>>      Andreas> That completely removes the delay.
>>
>> So the solution is easy: just deprecate and remove the 'x' backend :-)
>>
>> Robert
>>
> 
> Love that tip, man!  Confirming the speed up.  Thanks a lot!

For future visitors and for completeness sake, my per-frame font setup 
function now looks like this:

   (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-backend (assoc 'font-backend default-frame-alist)))
           (if font-backend
               (when (eq frame frame-initial-frame)
                 (modify-frame-parameters frame
                                          `((font-backend . ,font-backend)))
                 (unless noninteractive
                   (message "Font Backend: `%s'" font-backend)))
             (when (and (> emacs-major-version 26)
                        (boundp 'cairo-version-string))
               (setq font-backend "ftcrhb"))
             (when font-backend
               (add-to-list 'default-frame-alist
                            `(font-backend . ,font-backend))
               (modify-frame-parameters frame
                                        `((font-backend . ,font-backend)))
               (unless noninteractive
                 (message "Font Backend: `%s'" font-backend)))))
         (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))))))))

Typical usage is to add the following stanza to Emacs Lisp 
initialization file(s):

   (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))