Emacs: Font setup for displaying unicode characters in OSX

僤鯓⒐⒋嵵緔 提交于 2019-12-05 04:38:59

I believe there is a known bug with MacOS emacs and displaying characters beyond the BMP. See for example my (unanswered) bug report at Emacs bugs.

After reporting this bug, I had an e-mail suggesting use of the “Mac port” version of emacs. This apparently displays non-BMP characters.

Of course, it’d be nice if the bug was fixed in the main line of emacs development. It’d also be nice if the bug was officially acknowledged...

The function set-fontset-font may be used to specify which font to use for any range of characters; e.g.,

(set-fontset-font t '(#x1d4ee . #x1d4ee) (font-spec :family "FreeSerif"))

I have the same problem, and I don't have a general solution either. Here's my approach to fixing a single character (or potentially a range), assuming that you have the character in a buffer and it's not displaying.

Some experimentation showed that Menlo is a useful source of characters, like FreeSerif.

  1. Put the cursor before the non-displayed character.

  2. m-x describe-char. This gives you a lot of information about the character, including a line of the form "code point in charset: 0x2055".

    1. Somewhere in your .emacs or related files, use this function. It can potentially fix a whole range of characters by snagging them from the FreeSerif family or something else, but I don't have good choices for anything but a few characters.
    (defun bbextra-fix-fontset-font (from &optional to family)
      "Make characters FROM to TO come from FAMILY.  
    Default value of TO is FROM, and of FAMILY is FreeSerif (which 
    seems to have some of the characters)" 
     (set-fontset-font t (cons from (or to from))
                       (font-spec :family (or family "FreeSerif"))))

    ;; Here are the characters I have fixed.  
    (bbextra-fix-fontset-font #x2042)
    (bbextra-fix-fontset-font #x2023) 
    (bbextra-fix-fontset-font #x203D) 
    (bbextra-fix-fontset-font #x2055) 


     ;These come from Menlo
     (bbextra-fix-fontset-font #x2620 #x2620 "Menlo") ; skull and crossbones
     (bbextra-fix-fontset-font #x266C #x266C "Menlo") ; 16th notes
     (bbextra-fix-fontset-font #x2695 #x2695 "Menlo") ; asclepion
     (bbextra-fix-fontset-font #x2624 #x2624 "Menlo") ; caduceus
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!