A journal   About

Setup Emacs to use Malayalam fonts and fcitx

I wanted to use the excellent Manjari font as my default font for Malayalam language in Emacs. Manjari has an English character set, but I wanted to use "Hack Nerd Font Mono" as my default font for all Latin scripts and Manjari just for Malayalam only. This would seem straight forward, but I had to spend some time doing figuring this out.

About my emacs setup

I run emacs in server mode when I login to my desktop, and then when I want to use emacs, I just launch a client window. This makes it possible for me to launch my heavily customised setup in an instant, since the startup scripts load only once.

Making fcitx work with Emacs.

This was an easy fix, but very odd. I had to modify my emacs server startup script like so.

#!/usr/local/bin/bash
source ~/.bash_profile
# Check if emacs server is running already. if yes, exit. else start emacs --server
if ! pgrep  "emacs" > /dev/null
then
   echo "Stopped"
   echo "Starting emacs"
   LC_CTYPE=zh_CN.UTF-8 emacs --daemon
fi

Notice the "LC_CTYPE=zh_CN.UTF-8" part ? That makes emacs work with fcitx. I tried setting it to ml_IN.UTF-8, but for some reason that did not work. If you don't want the daemon, just ignore the "--daemon" part.

Reference : Fcitx article in Arch Linux wiki

Using a Malayalam font.

This was actually a bit more complicated to figure out. But the fix was very simple. I just had to add the following to my emacs startup configuration.

(defun use-ml-font (&optional frame)
  "Call function to set fonts for FRAME with an override for malayalam."
  (when frame
    (select-frame frame))
  (set-face-font 'default "Hack Nerd Font Mono-12")
(set-fontset-font t
                      (cons (decode-char 'ucs #x0D00)
                            (decode-char 'ucs #x0D7f))
                      "Manjari"))

;; Make sure this function is called when frames are created
(add-hook 'after-make-frame-functions #'use-ml-font)

What this does is very simple. Whenever a new "frame" is created, it calls the "use-ml-font" function. This function sets the frame's default font as "Hack Nerd Font Mono" and then overrides the unicode range for Malayalam, and specifies that Manjari be used.

References:

Written on Feb 24, 2019.