0

I want to use SourceCodePro as my default font but it doesn't cover persian characters which are in the scope of for example #x0600 untill #x06FF. I tried somthing like this

(set-fontset-font t
          'ascii
          "Source Code Pro-12")
(set-fontset-font t
          (cons (decode-char 'ucs #x0600)
            (decode-char 'ucs #x6FF))
          "Roya-13")

but it didn't worked. Also I tried to use fontset-standard and fontset-default like this

(set-face-font 'default "fontset-default")
 (set-fontset-font "fontset-default"
      'emacs (font-spec :name "Source Code Pro"))
(set-fontset-font "fontset-default"
          'iso-8859-1 (font-spec :name "Source Code Pro"))
(set-face-attribute 'font-lock-comment-face nil
            :family "Inconsolata" :height 140)
(set-fontset-font "fontset-default"
          '(#x0600 . #x06FF) (font-spec :name "Roya:pixelsize=16:foundry=farsiweb:weight=normal:slant=normal:width=normal:scalable=true"))
(set-fontset-font "fontset-default"
          '(#x0750 . #x075F) (font-spec :name "Roya:pixelsize=16:foundry=farsiweb:weight=normal:slant=normal:width=normal:scalable=true"))
(set-fontset-font "fontset-default"
          '(#x08A0 . #x08FF) (font-spec :name "Roya:pixelsize=16:foundry=farsiweb:weight=normal:slant=normal:width=normal:scalable=true"))
(set-fontset-font "fontset-default"
          '(#xFB50 . #xFDFF) (font-spec :name "Roya:pixelsize=16:foundry=farsiweb:weight=normal:slant=normal:width=normal:scalable=true"))
(set-fontset-font "fontset-default"
          '(#xFD70 . #xFEFF) (font-spec :name "Roya:pixelsize=16:foundry=farsiweb:weight=normal:slant=normal:width=normal:scalable=true"))
(set-fontset-font "fontset-default"
          '(#x1EE00 . #x1EEFF) (font-spec :name "Roya:pixelsize=16:foundry=farsiweb:weight=normal:slant=normal:width=normal:scalable=true"))

this didn't work either.

Update: thanks to guidance from @legoscia using `after-make-frame-functions' makes it work for me

(defun zzgraph/fix-fontset (&optional frame)
(set-fontset-font "fontset-default" 'arabic "Roya"))
(add-hook 'after-make-frame-functions 'zzgraph/fix-fontset)
Community
  • 1
  • 1
  • [Here](http://superuser.com/a/778348/4542) and [here](https://github.com/legoscia/dotemacs/blob/master/dotemacs.org#fix-the-display-of-emoji) are snippets that worked for me. – legoscia Oct 12 '15 at 10:48
  • @legoscia Thanks! the second one worked fine. So we always have to call the hook when make new frames! that's strange, and it didn't work for latin script, for that I used `(add-to-list 'default-frame-alist '(font . "Source Code Pro"))` outside of function to change the default face for latin characters – Shahab Shahsavari Alavidjeh Oct 13 '15 at 06:56
  • @legoscia can you make your comment an answer please? and also do you have any idea why using `after-make-frame-functions` is necessary? does it have something to do with running Emacs in daemon mode? – Shahab Shahsavari Alavidjeh Oct 15 '15 at 03:16
  • Go ahead and write an answer yourself! I used two different approaches, so put the one that worked for you. Answering your own question [is encouraged](http://stackoverflow.com/help/self-answer). As for `after-make-frame-functions`, I've never used the daemon but still needed it, so it's not related to that. – legoscia Oct 15 '15 at 10:00

1 Answers1

0

In Emacs 24, you don't need to set the frame's font to "fontset-default". Just modifying fontset-default will be enough to alter the default fallback behaviour. In the snippet you posted, the font :name property includes a lot of extra baggage that is not part of the name. Try eliminating this, and using just "Roya". If you have other fonts called "Roya" that are unsuitable, you might need to include more than just the font name to differentiate which font, but you should use separate properties to do this, not bundle them in as part of the :name property.

So in summary:

(set-face-font 'default "SourceCodePro")
(set-fontset-font "fontset-default"
                  '(#x0600 . #x06FF) (font-spec :name "Roya"))
(set-fontset-font "fontset-default"
                  '(#x0750 . #x075F) (font-spec :name "Roya"))
(set-fontset-font "fontset-default"
                  '(#x08A0 . #x08FF) (font-spec :name "Roya"))
(set-fontset-font "fontset-default"
                  '(#xFB50 . #xFEFF) (font-spec :name "Roya"))
(set-fontset-font "fontset-default"
                  '(#x1EE00 . #x1EEFF) (font-spec :name "Roya"))
JSON
  • 4,487
  • 22
  • 26
  • I tried that, it just does not work, and I think it might have something to do with me running daemon mode, but @legoscia [suggestion](http://stackoverflow.com/questions/33074370/how-can-i-use-a-different-ttf-fonts-for-certain-utf-8-characters-in-emacs/33116025#comment53975001_33074370) to use `after-make-frame-functions` hook, works very well. – Shahab Shahsavari Alavidjeh Oct 15 '15 at 03:12