Skip to content

Commit 37bad60

Browse files
committed
unicode fonts: multiple improvements
- Removed unnecessary package `persistent-soft`. This is never actually used by Spacemacs. And it's automatically installed as a dependancy package of unicode-fonts anyway. - Properly use `use-package` to initiate `ligature` package. - Improved README.org and config.el.
1 parent 9010d8d commit 37bad60

File tree

3 files changed

+88
-62
lines changed

3 files changed

+88
-62
lines changed

layers/+fonts/unicode-fonts/README.org

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,77 @@
66
- [[#description][Description]]
77
- [[#features][Features:]]
88
- [[#install][Install]]
9-
- [[#ligature-fonts][Ligature Fonts]]
9+
- [[#configuration][Configuration]]
1010

1111
* Description
1212
This layer adds support for [[https://github.com/rolandwalker/unicode-fonts][unicode-fonts]] package. It is recommended to
1313
install the fonts listed in the [[https://github.com/rolandwalker/unicode-fonts#quickstart][Quickstart]] section of the unicode-fonts README.
1414

1515
** Features:
16-
- Display unicode glyphs using the best available font.
16+
- Display Unicode glyphs using the best available font.
1717
- Easily override glyphs or sections of glyphs.
18-
- Display color emoji on both the macOS port version of Emacs and emacs-plus (with
19-
=unicode-fonts-force-multi-color-on-mac= set to non nil).
18+
- Display color emoji on both the macOS port version of Emacs and emacs-plus
19+
(with =unicode-fonts-force-multi-color-on-mac= set to non nil).
2020
- Enable support for font ligature in Emacs 27 + via [[https://github.com/mickeynp/ligature.el][ligatures.el]].
2121

2222
* Install
2323
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
24-
add =unicode-fonts= to the existing =dotspacemacs-configuration-layers= list in this
25-
file.
24+
add =unicode-fonts= to the existing =dotspacemacs-configuration-layers= list in
25+
this file.
26+
27+
#+BEGIN_SRC emacs-lisp
28+
(setq-default dotspacemacs-configuration-layers '(unicode-fonts))
29+
#+END_SRC
2630

2731
If using [[https://github.com/d12frosted/homebrew-emacs-plus/][emacs-plus]], you can set =unicode-fonts-force-multi-color-on-mac= to
2832
enable color emoji.
2933

3034
#+BEGIN_SRC elisp
31-
(unicode-fonts :variables unicode-fonts-force-multi-color-on-mac t)
35+
(setq-default dotspacemacs-configuration-layers
36+
'(unicode-fonts :variables
37+
unicode-fonts-force-multi-color-on-mac t))
3238
#+END_SRC
3339

40+
* Configuration
41+
3442
If you want ligature support Emacs must be built with =Harfbuzz= and a ligature
35-
font must be installed and configured you can see the [[https://github.com/mickeynp/ligature.el#compatibility-and-version-requirements][upstream]] docs for a full
36-
list of requirements. By default this is not enabled you can enable it with
43+
font must be installed and configured. You can see the [[https://github.com/mickeynp/ligature.el#compatibility-and-version-requirements][upstream]] docs for a full
44+
list of requirements. By default this is not enabled, and you can enable it with
3745
=unicode-fonts-enable-ligatures=.
3846

3947
#+BEGIN_SRC elisp
40-
(unicode-fonts :variables unicode-fonts-enable-ligatures t)
48+
(setq-default dotspacemacs-configuration-layers
49+
'(unicode-fonts :variables
50+
unicode-fonts-enable-ligatures t))
4151
#+END_SRC
4252

43-
By default ligatures will be enabled in all programing modes.
44-
You can enable ligatures for specific modes with
45-
=unicode-fonts-ligature-modes= variable.
53+
By default ligatures will be enabled in all programming modes. You can enable
54+
ligatures for specific modes with =unicode-fonts-ligature-modes= variable. For
55+
example, to enable ligatures only in PHP and Javascript files:
4656

4757
#+BEGIN_SRC elisp
48-
(unicode-fonts :variables unicode-fonts-ligature-modes '(php-mode js-mode))
58+
(setq-default dotspacemacs-configuration-layers
59+
'(unicode-fonts :variables
60+
unicode-fonts-enable-ligatures t
61+
unicode-fonts-ligature-modes '(php-mode js-mode)))
4962
#+END_SRC
5063

51-
To enable only for text modes you can use =text-mode=
64+
Or to enable ligatures only for text files:
5265

5366
#+BEGIN_SRC elisp
54-
(unicode-fonts :variables unicode-fonts-ligature-modes '(text-mode))
67+
(setq-default dotspacemacs-configuration-layers
68+
'(unicode-fonts :variables
69+
unicode-fonts-enable-ligatures t
70+
unicode-fonts-ligature-modes '(text-mode)))
5571
#+END_SRC
5672

5773
To configure the ligature set that gets used with your font there is a
58-
=unicode-fonts-ligature-set= variable. To only enable the ligatures in
59-
=if= statements you can limit the =unicode-fonts-ligature-set=
74+
=unicode-fonts-ligature-set= variable. For example To only enable the ligatures
75+
in =if= statements you can set the =unicode-fonts-ligature-set= as:
6076

6177
#+BEGIN_SRC elisp
62-
(unicode-fonts :variables unicode-fonts-ligature-set '("==" "===" "!=" "!==" "||" "&&"))
78+
(setq-default dotspacemacs-configuration-layers
79+
'(unicode-fonts :variables
80+
unicode-fonts-enable-ligatures t
81+
unicode-fonts-ligature-set '("==" "===" "!=" "!==" "||" "&&")))
6382
#+END_SRC
64-
65-
* Ligature Fonts
66-
- [[https://github.com/tonsky/FiraCode][Fira Code]]
67-
- [[https://github.com/microsoft/cascadia-code][Cascadia Code]]
68-
- [[https://github.com/be5invis/Iosevka/][Iosevka]]

layers/+fonts/unicode-fonts/config.el

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; config.el --- unicode-fonts configuration file for Spacemacs.
1+
;;; config.el --- unicode-fonts configuration file for Spacemacs. -*- lexical-binding: t -*-
22
;;
33
;; Copyright (c) 2012-2022 Sylvain Benner & Contributors
44
;;
@@ -20,31 +20,41 @@
2020
;; You should have received a copy of the GNU General Public License
2121
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2222

23+
;;; Commentary:
2324

24-
(defvar unicode-fonts-force-multi-color-on-mac nil
25-
"If non nil unicode-fonts will enable multi-color fonts (emoji)
26-
on macs.
25+
;;; Code:
2726

28-
This should only be set when using the multi-color patch as
29-
emacs-plus does. It is unnecessary to set this when using the
30-
macOS port version.")
31-
(defvar unicode-fonts-enable-ligatures nil
32-
"If you want to enable font ligatures")
27+
(spacemacs|defc unicode-fonts-force-multi-color-on-mac nil
28+
"If non nil unicode-fonts will enable multi-color Emoji.
29+
This is only needed in emacs-plus.
30+
The Emacs macOS port automatically turns multi-color Emoji support on and
31+
so it's unnecessary."
32+
'(boolean))
3333

34-
(defvar unicode-fonts-ligature-set '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
35-
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
36-
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
37-
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
38-
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
39-
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
40-
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
41-
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
42-
">=" ">>" ">-" "-~" "-|" "->" "-<" "<~" "<*" "<|" "<:" "<$"
43-
"<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!" "##"
44-
"#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:" "?="
45-
"?." "??" ";;" "/*" "/**" "/=" "/>" "__" "~~" "(*" "*)"
46-
"://")
47-
"List of ligatures you would like enabled")
34+
(spacemacs|defc unicode-fonts-enable-ligatures nil
35+
"If non-nil, enable unicode-fonts.
36+
By default it's enabled only for `prog-mode' buffers.
37+
For a finer control of the behavior, see `unicode-fonts-ligature-modes'."
38+
'(boolean))
4839

49-
(defvar unicode-fonts-ligature-modes '(prog-mode)
50-
"The modes ligatures are enabled in, default is prog-mode")
40+
(spacemacs|defc unicode-fonts-ligature-set '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
41+
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
42+
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
43+
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
44+
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
45+
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
46+
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
47+
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
48+
">=" ">>" ">-" "-~" "-|" "->" "-<" "<~" "<*" "<|" "<:" "<$"
49+
"<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!" "##"
50+
"#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:" "?="
51+
"?." "??" ";;" "/*" "/**" "/=" "/>" "__" "~~" "(*" "*)"
52+
"://")
53+
"List of ligatures to enable."
54+
'(repeat string))
55+
56+
(spacemacs|defc unicode-fonts-ligature-modes '(prog-mode)
57+
"This only takes effect when `unicode-fonts-enable-ligatures' is non-nil."
58+
'(repeat symbol))
59+
60+
;;; config.el ends here

layers/+fonts/unicode-fonts/packages.el

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; packages.el --- unicode-fonts layer packages file for Spacemacs.
1+
;;; packages.el --- unicode-fonts layer packages file for Spacemacs. -*- lexical-binding: t -*-
22
;;
33
;; Copyright (c) 2012-2022 Sylvain Benner & Contributors
44
;;
@@ -20,30 +20,32 @@
2020
;; You should have received a copy of the GNU General Public License
2121
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
2222

23+
;;; Commentary:
24+
25+
;;; Code:
2326

2427
(defconst unicode-fonts-packages
2528
'(unicode-fonts
26-
persistent-soft
2729
(ligature :location (recipe
2830
:fetcher github
2931
:repo "mickeynp/ligature.el")
30-
:toggle (and (> emacs-major-version 26) unicode-fonts-enable-ligatures))))
31-
32-
(defun unicode-fonts/init-persistent-soft ()
33-
(use-package persistent-soft
34-
:defer t))
32+
:toggle unicode-fonts-enable-ligatures)))
3533

3634
(defun unicode-fonts/init-unicode-fonts ()
3735
(use-package unicode-fonts
3836
:init
3937
(progn
4038
(when (and unicode-fonts-force-multi-color-on-mac
4139
(eq window-system 'ns))
42-
(setq unicode-fonts-skip-font-groups '(decorative low-quality-glyphs)))
43-
(unicode-fonts-setup))))
40+
(setq unicode-fonts-skip-font-groups
41+
(delq 'multi-color unicode-fonts-skip-font-groups)))
42+
(unicode-fonts//setup-fonts (selected-frame)))))
4443

4544
(defun unicode-fonts/init-ligature ()
46-
"Initialise the ligatures for emacs 27+"
47-
(dolist (mode unicode-fonts-ligature-modes)
48-
(ligature-set-ligatures mode unicode-fonts-ligature-set))
49-
(global-ligature-mode t))
45+
(use-package ligature
46+
:init
47+
(dolist (mode unicode-fonts-ligature-modes)
48+
(ligature-set-ligatures mode unicode-fonts-ligature-set))
49+
(global-ligature-mode t)))
50+
51+
;;; packages.el ends here

0 commit comments

Comments
 (0)