Werden wir Helden für einen Tag

Home | About | Archive

Advent of emacs #6: How I use (and fix) GUI emacs

Posted on Dec 6, 2022 by Chung-hong Chan

After vi(m) vs emacs, the GUI vs terminal emacs debate is probably the second favorite past time of emacs Redditors.

I will tell you why this debate is pointless. However, the point is actually what is your preferred way of using emacs; not GUI versus terminal. For a long time, I preferred to use the terminal version of emacs. Why? The superficial reasons was that I wanted to have the same experience of emacs running on my desktop and on remote servers through ssh. But I don’t need to run emacs on remote servers that often now.

The practical reasons were two. First, I can’t use iBus to type a foreign language in the default GUI emacs. Second, the default GUI emacs doesn’t support programming ligatures. I won’t talk about the first issue here; There are plenty fixes online. But I rather “fix” it by fixing myself: I eschew writing in that foreign language in emacs. That’s easier. And I promise you I will come back to this point later.

Enabling programming ligatures

I love programming ligatures. If you don’t need know what programming ligatures are, let me show you some R code.


NB: Not my code

The figures display the same code in bat under gnome-terminal (left, no ligature support) and kitty (right, with ligature support) using the same font (Fira Code). I use Fira Code by Nikita Prokopov et al. because it is easily available through apt (sudo apt install fonts-firacode). I am lazy.

I enjoy looking at the nicely rendered <- and ==. And those, are programming ligatures (combining two or more symbols into one glyph).

If one is using the terminal version and your terminal emulator supports ligatures, it will display ligatures. At the moment I am writing this, the GUI version of emacs doesn’t support ligatures by default. I am using version 28.2 compiled on 2022-11-03. I really hope that ligature support will be built-in in the future.

But the Fira Code Wiki actually has a good article on how to make emacs support ligatures. If you are using version >= 28 of emacs 1, the easiest method is to use ligature.el by Mickey Petersen (of “Mastering Emacs” fame) et al.

I have this in my configuration file.

(setq master-font-family "FiraCode")
(use-package ligature
  :config
  (ligature-set-ligatures 't '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
							   ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
							   "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
							   "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
							   "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
							   "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
							   "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
							   "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
							   ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
							   "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
							   "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
							   "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
							   "\\\\" "://"))
  (global-ligature-mode t)
  )

As said, I really like looking at these programming ligatures. So, I don’t mind these programming ligatures are enabled everywhere. The above code renders all ligatures nicely:

If you don’t like it to be enabled everywhere, you can also enable it in per mode basis. Please refer to the README of ligature.el.

prettified-symbols-mode

On a similarly topic, you can actually replace some characters as “prettified symbols”. This is a built-in feature of emacs since 24.4 and it affects the prog-mode (by default). While almost all major modes (a major mode is a set of settings and commands that customize emacs to behave in a specific way for editing a particular kind of text) for all programming languages are probably derived from prog-mode, it can be used for displaying many languages.

Let’s say, this Lisp code.

(lambda (arg) (/ arg 50))(10)

You can replace the annonymous function name “lambda” with the Greek character λ.

(setq prettify-symbols-alist '(("lambda" . 955))) 
(global-prettify-symbols-mode 1)

The number 955 is actually the HTML4 character entity references. And it looks like this:

Do all these modifications justify? Well…

Why do I prefer GUI emacs?

For many people, the only reason to run GUI emacs is for displaying graphics and PDFs. To me, this feature is actually not very important.

To me, the most important feature of the GUI is that the displaying abilities of rich text (underline, italic), clipboard, and colors do not depend on the terminal emulator. For example, the GUI displays the most accurate colors (at least according to the author of the theme).


GUI emacs (left), emacs under gnome terminal (center), emacs under kitty (right); pay attention to the first color in the panel

This blog post is about displaying those programming symbols. But how about entering those symbols? Well, I will talk about it tomorrow.

Postscript: The pointlessness of GUI versus terminal

Don’t frame it as a zero-sum game of x vs y. You can use both. Use the terminal version if you need to edit a file in terminal, use GUI otherwise. Porque no los dos? No one (including yourself) forces you to use just one version. I might prefer the GUI, it doesn’t preclude me from using the terminal version.

As I said on day 4, I have the following aliases.

## why type emacs if I can just type e?
alias e='emacsclient --tty'
alias eg='emacsclient -c &'

If I need to edit a file in terminal, I can e index.html. If I need to use the GUI version, eg (or, as I said, C-. e). Why argue? Maybe I don’t understand the internet, hashtag facepalm.


  1. I used another method for emacs 27. 


Powered by Jekyll and profdr theme, a fork of true minimal theme