From aae5b4c88c443e6105ba19dd9bc0fab58e8ae1b9 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Fri, 4 Sep 2020 21:03:16 +0100 Subject: [PATCH] Enable font ligatures for Emacs 27! Now that Emacs is capable a rendering font ligatures, I defined a function to enable them in fonts.el. Everything works, and it's beautiful. --- emacs/.emacs.d/wpc/fonts.el | 31 +++++++++++++++++++++++++++++++ emacs/.emacs.d/wpc/wpc-ui.el | 1 + 2 files changed, 32 insertions(+) diff --git a/emacs/.emacs.d/wpc/fonts.el b/emacs/.emacs.d/wpc/fonts.el index 55fd0eae2..1c8f2dee0 100644 --- a/emacs/.emacs.d/wpc/fonts.el +++ b/emacs/.emacs.d/wpc/fonts.el @@ -137,5 +137,36 @@ The size of the font is determined by `fonts-size'." (interactive) (fonts-whitelist-set (fonts-current))) +(defun fonts-enable-ligatures () + "Call this function to enable ligatures." + (interactive) + (let ((alist '((33 . ".\\(?:\\(?:==\\|!!\\)\\|[!=]\\)") + (35 . ".\\(?:###\\|##\\|_(\\|[#(?[_{]\\)") ;; + (36 . ".\\(?:>\\)") + (37 . ".\\(?:\\(?:%%\\)\\|%\\)") + (38 . ".\\(?:\\(?:&&\\)\\|&\\)") + (42 . ".\\(?:\\(?:\\*\\*/\\)\\|\\(?:\\*[*/]\\)\\|[*/>]\\)") ;; + (43 . ".\\(?:\\(?:\\+\\+\\)\\|[+>]\\)") + (45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)") + (46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=-]\\)") ;; + (47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)") + (48 . ".\\(?:x[a-zA-Z]\\)") + (58 . ".\\(?:::\\|[:=]\\)") + (59 . ".\\(?:;;\\|;\\)") + (60 . ".\\(?:\\(?:!--\\)\\|\\(?:~~\\|->\\|\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[*$+~/<=>|-]\\)") + (61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)") + (62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)") + (63 . ".\\(?:\\(\\?\\?\\)\\|[:=?]\\)") + (91 . ".\\(?:]\\)") + (92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)") + (94 . ".\\(?:=\\)") + (119 . ".\\(?:ww\\)") + (123 . ".\\(?:-\\)") + (124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)") + (126 . ".\\(?:~>\\|~~\\|[>=@~-]\\)")))) + (dolist (char-regexp alist) + (set-char-table-range composition-function-table (car char-regexp) + `([,(cdr char-regexp) 0 font-shape-gstring]))))) + (provide 'fonts) ;;; fonts.el ends here diff --git a/emacs/.emacs.d/wpc/wpc-ui.el b/emacs/.emacs.d/wpc/wpc-ui.el index cce217f03..35ca91876 100644 --- a/emacs/.emacs.d/wpc/wpc-ui.el +++ b/emacs/.emacs.d/wpc/wpc-ui.el @@ -164,6 +164,7 @@ (laptop-battery-display)) (fonts-whitelist-set "JetBrainsMono") +(fonts-enable-ligatures) (colorscheme-whitelist-set 'doom-solarized-light) (modeline-setup)