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.
This commit is contained in:
Lucius Hu 2022-08-05 00:11:56 -04:00
parent 9010d8d3ca
commit 37bad602e2
No known key found for this signature in database
GPG Key ID: 7E474E82E29B5A7A
3 changed files with 88 additions and 62 deletions

View File

@ -6,63 +6,77 @@
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
- [[#ligature-fonts][Ligature Fonts]]
- [[#configuration][Configuration]]
* Description
This layer adds support for [[https://github.com/rolandwalker/unicode-fonts][unicode-fonts]] package. It is recommended to
install the fonts listed in the [[https://github.com/rolandwalker/unicode-fonts#quickstart][Quickstart]] section of the unicode-fonts README.
** Features:
- Display unicode glyphs using the best available font.
- Display Unicode glyphs using the best available font.
- Easily override glyphs or sections of glyphs.
- Display color emoji on both the macOS port version of Emacs and emacs-plus (with
=unicode-fonts-force-multi-color-on-mac= set to non nil).
- Display color emoji on both the macOS port version of Emacs and emacs-plus
(with =unicode-fonts-force-multi-color-on-mac= set to non nil).
- Enable support for font ligature in Emacs 27 + via [[https://github.com/mickeynp/ligature.el][ligatures.el]].
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =unicode-fonts= to the existing =dotspacemacs-configuration-layers= list in this
file.
add =unicode-fonts= to the existing =dotspacemacs-configuration-layers= list in
this file.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(unicode-fonts))
#+END_SRC
If using [[https://github.com/d12frosted/homebrew-emacs-plus/][emacs-plus]], you can set =unicode-fonts-force-multi-color-on-mac= to
enable color emoji.
#+BEGIN_SRC elisp
(unicode-fonts :variables unicode-fonts-force-multi-color-on-mac t)
(setq-default dotspacemacs-configuration-layers
'(unicode-fonts :variables
unicode-fonts-force-multi-color-on-mac t))
#+END_SRC
* Configuration
If you want ligature support Emacs must be built with =Harfbuzz= and a ligature
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
list of requirements. By default this is not enabled you can enable it with
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
list of requirements. By default this is not enabled, and you can enable it with
=unicode-fonts-enable-ligatures=.
#+BEGIN_SRC elisp
(unicode-fonts :variables unicode-fonts-enable-ligatures t)
(setq-default dotspacemacs-configuration-layers
'(unicode-fonts :variables
unicode-fonts-enable-ligatures t))
#+END_SRC
By default ligatures will be enabled in all programing modes.
You can enable ligatures for specific modes with
=unicode-fonts-ligature-modes= variable.
By default ligatures will be enabled in all programming modes. You can enable
ligatures for specific modes with =unicode-fonts-ligature-modes= variable. For
example, to enable ligatures only in PHP and Javascript files:
#+BEGIN_SRC elisp
(unicode-fonts :variables unicode-fonts-ligature-modes '(php-mode js-mode))
(setq-default dotspacemacs-configuration-layers
'(unicode-fonts :variables
unicode-fonts-enable-ligatures t
unicode-fonts-ligature-modes '(php-mode js-mode)))
#+END_SRC
To enable only for text modes you can use =text-mode=
Or to enable ligatures only for text files:
#+BEGIN_SRC elisp
(unicode-fonts :variables unicode-fonts-ligature-modes '(text-mode))
(setq-default dotspacemacs-configuration-layers
'(unicode-fonts :variables
unicode-fonts-enable-ligatures t
unicode-fonts-ligature-modes '(text-mode)))
#+END_SRC
To configure the ligature set that gets used with your font there is a
=unicode-fonts-ligature-set= variable. To only enable the ligatures in
=if= statements you can limit the =unicode-fonts-ligature-set=
=unicode-fonts-ligature-set= variable. For example To only enable the ligatures
in =if= statements you can set the =unicode-fonts-ligature-set= as:
#+BEGIN_SRC elisp
(unicode-fonts :variables unicode-fonts-ligature-set '("==" "===" "!=" "!==" "||" "&&"))
(setq-default dotspacemacs-configuration-layers
'(unicode-fonts :variables
unicode-fonts-enable-ligatures t
unicode-fonts-ligature-set '("==" "===" "!=" "!==" "||" "&&")))
#+END_SRC
* Ligature Fonts
- [[https://github.com/tonsky/FiraCode][Fira Code]]
- [[https://github.com/microsoft/cascadia-code][Cascadia Code]]
- [[https://github.com/be5invis/Iosevka/][Iosevka]]

View File

@ -1,4 +1,4 @@
;;; config.el --- unicode-fonts configuration file for Spacemacs.
;;; config.el --- unicode-fonts configuration file for Spacemacs. -*- lexical-binding: t -*-
;;
;; Copyright (c) 2012-2022 Sylvain Benner & Contributors
;;
@ -20,31 +20,41 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(defvar unicode-fonts-force-multi-color-on-mac nil
"If non nil unicode-fonts will enable multi-color fonts (emoji)
on macs.
;;; Code:
This should only be set when using the multi-color patch as
emacs-plus does. It is unnecessary to set this when using the
macOS port version.")
(defvar unicode-fonts-enable-ligatures nil
"If you want to enable font ligatures")
(spacemacs|defc unicode-fonts-force-multi-color-on-mac nil
"If non nil unicode-fonts will enable multi-color Emoji.
This is only needed in emacs-plus.
The Emacs macOS port automatically turns multi-color Emoji support on and
so it's unnecessary."
'(boolean))
(defvar unicode-fonts-ligature-set '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
">=" ">>" ">-" "-~" "-|" "->" "-<" "<~" "<*" "<|" "<:" "<$"
"<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!" "##"
"#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:" "?="
"?." "??" ";;" "/*" "/**" "/=" "/>" "__" "~~" "(*" "*)"
"://")
"List of ligatures you would like enabled")
(spacemacs|defc unicode-fonts-enable-ligatures nil
"If non-nil, enable unicode-fonts.
By default it's enabled only for `prog-mode' buffers.
For a finer control of the behavior, see `unicode-fonts-ligature-modes'."
'(boolean))
(defvar unicode-fonts-ligature-modes '(prog-mode)
"The modes ligatures are enabled in, default is prog-mode")
(spacemacs|defc unicode-fonts-ligature-set '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
"<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
"..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
"~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
"[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
">=" ">>" ">-" "-~" "-|" "->" "-<" "<~" "<*" "<|" "<:" "<$"
"<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!" "##"
"#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:" "?="
"?." "??" ";;" "/*" "/**" "/=" "/>" "__" "~~" "(*" "*)"
"://")
"List of ligatures to enable."
'(repeat string))
(spacemacs|defc unicode-fonts-ligature-modes '(prog-mode)
"This only takes effect when `unicode-fonts-enable-ligatures' is non-nil."
'(repeat symbol))
;;; config.el ends here

View File

@ -1,4 +1,4 @@
;;; packages.el --- unicode-fonts layer packages file for Spacemacs.
;;; packages.el --- unicode-fonts layer packages file for Spacemacs. -*- lexical-binding: t -*-
;;
;; Copyright (c) 2012-2022 Sylvain Benner & Contributors
;;
@ -20,18 +20,16 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(defconst unicode-fonts-packages
'(unicode-fonts
persistent-soft
(ligature :location (recipe
:fetcher github
:repo "mickeynp/ligature.el")
:toggle (and (> emacs-major-version 26) unicode-fonts-enable-ligatures))))
(defun unicode-fonts/init-persistent-soft ()
(use-package persistent-soft
:defer t))
:toggle unicode-fonts-enable-ligatures)))
(defun unicode-fonts/init-unicode-fonts ()
(use-package unicode-fonts
@ -39,11 +37,15 @@
(progn
(when (and unicode-fonts-force-multi-color-on-mac
(eq window-system 'ns))
(setq unicode-fonts-skip-font-groups '(decorative low-quality-glyphs)))
(unicode-fonts-setup))))
(setq unicode-fonts-skip-font-groups
(delq 'multi-color unicode-fonts-skip-font-groups)))
(unicode-fonts//setup-fonts (selected-frame)))))
(defun unicode-fonts/init-ligature ()
"Initialise the ligatures for emacs 27+"
(dolist (mode unicode-fonts-ligature-modes)
(ligature-set-ligatures mode unicode-fonts-ligature-set))
(global-ligature-mode t))
(use-package ligature
:init
(dolist (mode unicode-fonts-ligature-modes)
(ligature-set-ligatures mode unicode-fonts-ligature-set))
(global-ligature-mode t)))
;;; packages.el ends here