

在Spacemacs中配置Fira Code并启用ligatures特性
source link: https://xiaozhou.net/setup-spacemacs-with-fira-code-ligatures-2019-09-09.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在Spacemacs中配置Fira Code并启用ligatures特性
Fira是Mozilla主推的字体系列。Fira Code是其中的一员,专为写程序而生。出来具有等宽等基本属性外,还加入了编程连字特性(ligatures)。编程连字特性,其实就是利用这个特性对编程中的常用符号进行优化,比如把输入的「!=」直接显示成「≠」或者把「>=」变成「≥ 」等等,以此来提高代码的可读性。
作为传说中的程序员,Fira Code也早已称为我的各大常用编辑器标配字体。Fira Code在其他编辑器和终端上配置较为简单,选中字体过后,启用Ligatures Feature即可。Spacemacs和Emacs的配置稍微复杂一些,这里分享一下Fira Code在Spacemacs下的配置。
获取并安装 Fira Code Symbol Font。对于Linux系统,可以直接把字体解压并放到 /usr/share/fonts
目录,并重载字体的cache,使其生效。
在Spacemacs中,使用<SPC> f e d
编辑 ~/.spacemacs
配置文件。对于Emacs用户来说,可以编辑 ~/.emacs.d/init.el
。
在配置文件中,加入如下设置:
dotspacemacs-default-font '(("FuraCode Nerd Font Mono"
:size 16
:weight medium
:width normal
:powerline-scale 1.1)
("Fira Code Symbol"
:size 16
:weight normal
:width normal
:powerline-scale 1.1))
同样是编辑配置文件,在Spacemacs的配置项dotspacemacs-user-config
中加入如下配置:
(defun dotspacemacs/user-config()
"Configuration function for user code."
;; Font Ligatures
(defun my-correct-symbol-bounds (pretty-alist)
"Prepend a TAB character to each symbol in this alist,
this way compose-region called by prettify-symbols-mode
will use the correct width of the symbols
instead of the width measured by char-width."
(mapcar (lambda (el)
(setcdr el (string ?\t (cdr el)))
el)
pretty-alist))
(defun my-ligature-list (ligatures codepoint-start)
"Create an alist of strings to replace with
codepoints starting from codepoint-start."
(let ((codepoints (-iterate '1+ codepoint-start (length ligatures))))
(-zip-pair ligatures codepoints)))
(setq my-fira-code-ligatures
(let* ((ligs '("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\"
"{-" "[]" "::" ":::" ":=" "!!" "!=" "!==" "-}"
"--" "---" "-->" "->" "->>" "-<" "-<<" "-~"
"#{" "#[" "##" "###" "####" "#(" "#?" "#_" "#_("
".-" ".=" ".." "..<" "..." "?=" "??" ";;" "/*"
"/**" "/=" "/==" "/>" "//" "///" "&&" "||" "||="
"|=" "|>" "^=" "$>" "++" "+++" "+>" "=:=" "=="
"===" "==>" "=>" "=>>" "<=" "=<<" "=/=" ">-" ">="
">=>" ">>" ">>-" ">>=" ">>>" "<*" "<*>" "<|" "<|>"
"<$" "<$>" "<!--" "<-" "<--" "<->" "<+" "<+>" "<="
"<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<" "<~"
"<~~" "</" "</>" "~@" "~-" "~=" "~>" "~~" "~~>" "%%"
"x" ":" "+" "+" "*")))
(my-correct-symbol-bounds (my-ligature-list ligs #Xe100))))
(defun my-set-fira-code-ligatures ()
"Add fira code ligatures for use with prettify-symbols-mode."
(setq prettify-symbols-alist
(append my-fira-code-ligatures prettify-symbols-alist))
(prettify-symbols-mode))
(add-hook 'prog-mode-hook 'my-set-fira-code-ligatures))
最后,重载Spacemacs/Emacs的配置文件,使配置生效,即可启用Fira Code字体的Ligatures连字特性。
Recommend
-
27
Ligatures are typographic eye-candy where a special glyph replaces a combination of two or more letters or signs.Some ligatures have been used for a so long time they’ve entered the realm of symbols, for example the ampersand & is a ligature...
-
28
Last time I showed you how to emulate ligatures using unicode glyphs, then concluded by telling you against using this method! What was the point then?Well, first of all, I did use this method for a couple weeks, because I used rxvt-unicode and...
-
78
Ligatures in programming fonts—a misguided trend I was hoping would collapse under its own illogic. But it persists. Let me save you some time— Ligatures in programming fonts are a t...
-
39
README.md fira-code-emacs Some code to make Fira Code 2.0 work in Emacs. To install, first run make. Copy some or all of...
-
53
Fira Code: free monospaced font with programming ligatures
-
54
README.md
-
41
Welcome! This repository contains th...
-
32
README.md fira-code-mode Minor mode for Fira Code ligatures using prettify-symbols.
-
8
【vscode高级玩家】设置酷炫字体Fira Code发表于2021-12-20更新于2023-05-04字数统计794阅读次数654阅读次数136
-
6
How I falling in love with Fira Code Font – – I'm a developer, son, big brother and husband.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK