ui/pretty-code: general refactor & fix premature )
This commit is contained in:
parent
2a125000ae
commit
fc87a72904
5 changed files with 153 additions and 151 deletions
|
@ -1,131 +1,134 @@
|
||||||
;;; ui/pretty-code/+fira.el -*- lexical-binding: t; -*-
|
;;; ui/pretty-code/+fira.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +pretty-code-fira-code-font-name "Fira Code Symbol"
|
||||||
|
"Name of the fira code ligature font.")
|
||||||
|
|
||||||
|
(defvar +pretty-code-fira-code-font-ligatures
|
||||||
|
'(("www" . #Xe100)
|
||||||
|
("**" . #Xe101)
|
||||||
|
("***" . #Xe102)
|
||||||
|
("**/" . #Xe103)
|
||||||
|
("*>" . #Xe104)
|
||||||
|
("*/" . #Xe105)
|
||||||
|
("\\\\" . #Xe106)
|
||||||
|
("\\\\\\" . #Xe107)
|
||||||
|
("{-" . #Xe108)
|
||||||
|
("[]" . #Xe109)
|
||||||
|
("::" . #Xe10a)
|
||||||
|
(":::" . #Xe10b)
|
||||||
|
(":=" . #Xe10c)
|
||||||
|
("!!" . #Xe10d)
|
||||||
|
("!=" . #Xe10e)
|
||||||
|
("!==" . #Xe10f)
|
||||||
|
("-}" . #Xe110)
|
||||||
|
("--" . #Xe111)
|
||||||
|
("---" . #Xe112)
|
||||||
|
("-->" . #Xe113)
|
||||||
|
("->" . #Xe114)
|
||||||
|
("->>" . #Xe115)
|
||||||
|
("-<" . #Xe116)
|
||||||
|
("-<<" . #Xe117)
|
||||||
|
("-~" . #Xe118)
|
||||||
|
("#{" . #Xe119)
|
||||||
|
("#[" . #Xe11a)
|
||||||
|
("##" . #Xe11b)
|
||||||
|
("###" . #Xe11c)
|
||||||
|
("####" . #Xe11d)
|
||||||
|
("#(" . #Xe11e)
|
||||||
|
("#?" . #Xe11f)
|
||||||
|
("#_" . #Xe120)
|
||||||
|
("#_(" . #Xe121)
|
||||||
|
(".-" . #Xe122)
|
||||||
|
(".=" . #Xe123)
|
||||||
|
(".." . #Xe124)
|
||||||
|
("..<" . #Xe125)
|
||||||
|
("..." . #Xe126)
|
||||||
|
("?=" . #Xe127)
|
||||||
|
("??" . #Xe128)
|
||||||
|
(";;" . #Xe129)
|
||||||
|
("/*" . #Xe12a)
|
||||||
|
("/**" . #Xe12b)
|
||||||
|
("/=" . #Xe12c)
|
||||||
|
("/==" . #Xe12d)
|
||||||
|
("/>" . #Xe12e)
|
||||||
|
("//" . #Xe12f)
|
||||||
|
("///" . #Xe130)
|
||||||
|
("&&" . #Xe131)
|
||||||
|
("||" . #Xe132)
|
||||||
|
("||=" . #Xe133)
|
||||||
|
("|=" . #Xe134)
|
||||||
|
("|>" . #Xe135)
|
||||||
|
("^=" . #Xe136)
|
||||||
|
("$>" . #Xe137)
|
||||||
|
("++" . #Xe138)
|
||||||
|
("+++" . #Xe139)
|
||||||
|
("+>" . #Xe13a)
|
||||||
|
("=:=" . #Xe13b)
|
||||||
|
("==" . #Xe13c)
|
||||||
|
("===" . #Xe13d)
|
||||||
|
("==>" . #Xe13e)
|
||||||
|
("=>" . #Xe13f)
|
||||||
|
("=>>" . #Xe140)
|
||||||
|
("<=" . #Xe141)
|
||||||
|
("=<<" . #Xe142)
|
||||||
|
("=/=" . #Xe143)
|
||||||
|
(">-" . #Xe144)
|
||||||
|
(">=" . #Xe145)
|
||||||
|
(">=>" . #Xe146)
|
||||||
|
(">>" . #Xe147)
|
||||||
|
(">>-" . #Xe148)
|
||||||
|
(">>=" . #Xe149)
|
||||||
|
(">>>" . #Xe14a)
|
||||||
|
("<*" . #Xe14b)
|
||||||
|
("<*>" . #Xe14c)
|
||||||
|
("<|" . #Xe14d)
|
||||||
|
("<|>" . #Xe14e)
|
||||||
|
("<$" . #Xe14f)
|
||||||
|
("<$>" . #Xe150)
|
||||||
|
("<!--" . #Xe151)
|
||||||
|
("<-" . #Xe152)
|
||||||
|
("<--" . #Xe153)
|
||||||
|
("<->" . #Xe154)
|
||||||
|
("<+" . #Xe155)
|
||||||
|
("<+>" . #Xe156)
|
||||||
|
("<=" . #Xe157)
|
||||||
|
("<==" . #Xe158)
|
||||||
|
("<=>" . #Xe159)
|
||||||
|
("<=<" . #Xe15a)
|
||||||
|
("<>" . #Xe15b)
|
||||||
|
("<<" . #Xe15c)
|
||||||
|
("<<-" . #Xe15d)
|
||||||
|
("<<=" . #Xe15e)
|
||||||
|
("<<<" . #Xe15f)
|
||||||
|
("<~" . #Xe160)
|
||||||
|
("<~~" . #Xe161)
|
||||||
|
("</" . #Xe162)
|
||||||
|
("</>" . #Xe163)
|
||||||
|
("~@" . #Xe164)
|
||||||
|
("~-" . #Xe165)
|
||||||
|
("~=" . #Xe166)
|
||||||
|
("~>" . #Xe167)
|
||||||
|
("~~" . #Xe168)
|
||||||
|
("~~>" . #Xe169)
|
||||||
|
("%%" . #Xe16a)))
|
||||||
|
|
||||||
(defun +pretty-code--correct-symbol-bounds (ligature-alist)
|
(defun +pretty-code--correct-symbol-bounds (ligature-alist)
|
||||||
"Prepend non-breaking spaces to a ligature.
|
"Prepend non-breaking spaces to a ligature.
|
||||||
|
|
||||||
This way `compose-region' (called by `prettify-symbols-mode') will use the
|
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'."
|
correct width of the symbols instead of the width measured by `char-width'."
|
||||||
(let ((len (length (car ligature-alist)))
|
(let ((len (length (car ligature-alist)))
|
||||||
(acc (list (cdr ligature-alist))))
|
(acc (list (cdr ligature-alist))))
|
||||||
(while (> len 1)
|
(while (> len 1)
|
||||||
(setq acc (cons #X00a0 (cons '(Br . Bl) acc))
|
(setq acc (cons #X00a0 (cons '(Br . Bl) acc))
|
||||||
len (1- len)))
|
len (1- len)))
|
||||||
(cons (car ligature-alist) acc)))
|
(cons (car ligature-alist) acc)))
|
||||||
|
|
||||||
(defconst +pretty-code-fira-code-font-ligatures
|
|
||||||
(mapcar #'+pretty-code--correct-symbol-bounds
|
|
||||||
'(("www" . #Xe100)
|
|
||||||
("**" . #Xe101)
|
|
||||||
("***" . #Xe102)
|
|
||||||
("**/" . #Xe103)
|
|
||||||
("*>" . #Xe104)
|
|
||||||
("*/" . #Xe105)
|
|
||||||
("\\\\" . #Xe106)
|
|
||||||
("\\\\\\" . #Xe107)
|
|
||||||
("{-" . #Xe108)
|
|
||||||
("[]" . #Xe109)
|
|
||||||
("::" . #Xe10a)
|
|
||||||
(":::" . #Xe10b)
|
|
||||||
(":=" . #Xe10c)
|
|
||||||
("!!" . #Xe10d)
|
|
||||||
("!=" . #Xe10e)
|
|
||||||
("!==" . #Xe10f)
|
|
||||||
("-}" . #Xe110)
|
|
||||||
("--" . #Xe111)
|
|
||||||
("---" . #Xe112)
|
|
||||||
("-->" . #Xe113)
|
|
||||||
("->" . #Xe114)
|
|
||||||
("->>" . #Xe115)
|
|
||||||
("-<" . #Xe116)
|
|
||||||
("-<<" . #Xe117)
|
|
||||||
("-~" . #Xe118)
|
|
||||||
("#{" . #Xe119)
|
|
||||||
("#[" . #Xe11a)
|
|
||||||
("##" . #Xe11b)
|
|
||||||
("###" . #Xe11c)
|
|
||||||
("####" . #Xe11d)
|
|
||||||
("#(" . #Xe11e)
|
|
||||||
("#?" . #Xe11f)
|
|
||||||
("#_" . #Xe120)
|
|
||||||
("#_(" . #Xe121)
|
|
||||||
(".-" . #Xe122)
|
|
||||||
(".=" . #Xe123)
|
|
||||||
(".." . #Xe124)
|
|
||||||
("..<" . #Xe125)
|
|
||||||
("..." . #Xe126)
|
|
||||||
("?=" . #Xe127)
|
|
||||||
("??" . #Xe128)
|
|
||||||
(";;" . #Xe129)
|
|
||||||
("/*" . #Xe12a)
|
|
||||||
("/**" . #Xe12b)
|
|
||||||
("/=" . #Xe12c)
|
|
||||||
("/==" . #Xe12d)
|
|
||||||
("/>" . #Xe12e)
|
|
||||||
("//" . #Xe12f)
|
|
||||||
("///" . #Xe130)
|
|
||||||
("&&" . #Xe131)
|
|
||||||
("||" . #Xe132)
|
|
||||||
("||=" . #Xe133)
|
|
||||||
("|=" . #Xe134)
|
|
||||||
("|>" . #Xe135)
|
|
||||||
("^=" . #Xe136)
|
|
||||||
("$>" . #Xe137)
|
|
||||||
("++" . #Xe138)
|
|
||||||
("+++" . #Xe139)
|
|
||||||
("+>" . #Xe13a)
|
|
||||||
("=:=" . #Xe13b)
|
|
||||||
("==" . #Xe13c)
|
|
||||||
("===" . #Xe13d)
|
|
||||||
("==>" . #Xe13e)
|
|
||||||
("=>" . #Xe13f)
|
|
||||||
("=>>" . #Xe140)
|
|
||||||
("<=" . #Xe141)
|
|
||||||
("=<<" . #Xe142)
|
|
||||||
("=/=" . #Xe143)
|
|
||||||
(">-" . #Xe144)
|
|
||||||
(">=" . #Xe145)
|
|
||||||
(">=>" . #Xe146)
|
|
||||||
(">>" . #Xe147)
|
|
||||||
(">>-" . #Xe148)
|
|
||||||
(">>=" . #Xe149)
|
|
||||||
(">>>" . #Xe14a)
|
|
||||||
("<*" . #Xe14b)
|
|
||||||
("<*>" . #Xe14c)
|
|
||||||
("<|" . #Xe14d)
|
|
||||||
("<|>" . #Xe14e)
|
|
||||||
("<$" . #Xe14f)
|
|
||||||
("<$>" . #Xe150)
|
|
||||||
("<!--" . #Xe151)
|
|
||||||
("<-" . #Xe152)
|
|
||||||
("<--" . #Xe153)
|
|
||||||
("<->" . #Xe154)
|
|
||||||
("<+" . #Xe155)
|
|
||||||
("<+>" . #Xe156)
|
|
||||||
("<=" . #Xe157)
|
|
||||||
("<==" . #Xe158)
|
|
||||||
("<=>" . #Xe159)
|
|
||||||
("<=<" . #Xe15a)
|
|
||||||
("<>" . #Xe15b)
|
|
||||||
("<<" . #Xe15c)
|
|
||||||
("<<-" . #Xe15d)
|
|
||||||
("<<=" . #Xe15e)
|
|
||||||
("<<<" . #Xe15f)
|
|
||||||
("<~" . #Xe160)
|
|
||||||
("<~~" . #Xe161)
|
|
||||||
("</" . #Xe162)
|
|
||||||
("</>" . #Xe163)
|
|
||||||
("~@" . #Xe164)
|
|
||||||
("~-" . #Xe165)
|
|
||||||
("~=" . #Xe166)
|
|
||||||
("~>" . #Xe167)
|
|
||||||
("~~" . #Xe168)
|
|
||||||
("~~>" . #Xe169)
|
|
||||||
("%%" . #Xe16a))))
|
|
||||||
|
|
||||||
(defun +pretty-code|setup-fira-ligatures ()
|
(defun +pretty-code|setup-fira-ligatures ()
|
||||||
(set-fontset-font t '(#Xe100 . #Xe16f) "Fira Code Symbol"))
|
(set-fontset-font t '(#Xe100 . #Xe16f) +pretty-code-fira-code-font-name)
|
||||||
(setq-default prettify-symbols-alist
|
(setq-default prettify-symbols-alist
|
||||||
(append prettify-symbols-alist
|
(append prettify-symbols-alist
|
||||||
+pretty-code-fira-code-font-ligatures))
|
(mapcar #'+pretty-code--correct-symbol-bounds
|
||||||
|
+pretty-code-fira-code-font-ligatures))))
|
||||||
|
|
||||||
(add-hook! 'doom-init-ui-hook #'+pretty-code|setup-fira-ligatures)
|
(add-hook 'doom-init-ui-hook #'+pretty-code|setup-fira-ligatures)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
;;; ui/pretty-code/+iosevka.el -*- lexical-binding: t; -*-
|
;;; ui/pretty-code/+iosevka.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defconst +pretty-code-iosevka-font-ligatures
|
(defvar +pretty-code-iosevka-font-name "Iosevka"
|
||||||
|
"Name of the iosevka ligature font.")
|
||||||
|
|
||||||
|
(defvar +pretty-code-iosevka-font-ligatures
|
||||||
'(;; Double-ended hyphen arrows
|
'(;; Double-ended hyphen arrows
|
||||||
("<->" . #Xe100)
|
("<->" . #Xe100)
|
||||||
("<-->" . #Xe101)
|
("<-->" . #Xe101)
|
||||||
|
@ -221,11 +224,10 @@
|
||||||
"Defines the character mappings for ligatures for Iosevka.")
|
"Defines the character mappings for ligatures for Iosevka.")
|
||||||
|
|
||||||
(defun +pretty-code|setup-iosevka-ligatures ()
|
(defun +pretty-code|setup-iosevka-ligatures ()
|
||||||
(set-fontset-font t '(#Xe100 . #Xe16f) "Iosevka")
|
(set-fontset-font t '(#Xe100 . #Xe16f) +pretty-code-iosevka-font-name)
|
||||||
(setq-default prettify-symbols-alist
|
(setq-default prettify-symbols-alist
|
||||||
(append prettify-symbols-alist
|
(append prettify-symbols-alist
|
||||||
+pretty-code-iosevka-font-ligatures)))
|
+pretty-code-iosevka-font-ligatures)))
|
||||||
|
|
||||||
(add-hook! 'doom-init-ui-hook #'+pretty-code|setup-iosevka-ligatures)
|
(add-hook 'doom-init-ui-hook #'+pretty-code|setup-iosevka-ligatures)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
;;; ui/pretty-code/autoload.el -*- lexical-binding: t; -*-
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defvar +pretty-code-enabled-modes t
|
|
||||||
"List of major modes in which `prettify-symbols-mode' should be enabled.
|
|
||||||
If t, enable it everywhere. If the first element is 'not, enable it in any mode
|
|
||||||
besides what is listed.")
|
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +pretty-code|init-pretty-symbols ()
|
|
||||||
"Enabled `prettify-symbols-mode'.
|
|
||||||
|
|
||||||
If the current major mode is disabled in `+pretty-code-enabled-modes', this
|
|
||||||
function does nothing. Otherwise, it sets the value of
|
|
||||||
`prettify-code-symbols-alist' according to `+pretty-code-symbols-alist' for the
|
|
||||||
current major mode."
|
|
||||||
(when (or (eq +pretty-code-enabled-modes 't)
|
|
||||||
(if (eq (car +pretty-code-enabled-modes 'not))
|
|
||||||
(not (memq major-mode (cdr +pretty-code-enabled-modes)))
|
|
||||||
(memq major-mode +pretty-code-enabled-modes)))
|
|
||||||
(setq prettify-symbols-alist
|
|
||||||
(append (alist-get major-mode +pretty-code-symbols-alist)
|
|
||||||
(default-value 'prettify-symbols-alist)))
|
|
||||||
(when prettify-symbols-mode
|
|
||||||
(prettify-symbols-mode -1))
|
|
||||||
(prettify-symbols-mode +1)))
|
|
|
@ -5,7 +5,31 @@
|
||||||
((featurep! +iosevka)
|
((featurep! +iosevka)
|
||||||
(load! "+iosevka")))
|
(load! "+iosevka")))
|
||||||
|
|
||||||
|
(defvar +pretty-code-enabled-modes t
|
||||||
|
"List of major modes in which `prettify-symbols-mode' should be enabled.
|
||||||
|
If t, enable it everywhere. If the first element is 'not, enable it in any mode
|
||||||
|
besides what is listed.")
|
||||||
|
|
||||||
;; When you get to the right edge, it goes back to how it normally prints
|
;; When you get to the right edge, it goes back to how it normally prints
|
||||||
(setq prettify-symbols-unprettify-at-point 'right-edge)
|
(setq prettify-symbols-unprettify-at-point 'right-edge)
|
||||||
|
|
||||||
(add-hook! 'after-change-major-mode-hook #'+pretty-code|init-pretty-symbols)
|
(defun +pretty-code|init-pretty-symbols ()
|
||||||
|
"Enabled `prettify-symbols-mode'.
|
||||||
|
|
||||||
|
If the current major mode is disabled in `+pretty-code-enabled-modes', this
|
||||||
|
function does nothing. Otherwise, it sets the value of
|
||||||
|
`prettify-code-symbols-alist' according to `+pretty-code-symbols-alist' for the
|
||||||
|
current major mode."
|
||||||
|
(unless (eq major-mode 'fundamental-mode)
|
||||||
|
(when (or (eq +pretty-code-enabled-modes 't)
|
||||||
|
(if (eq (car +pretty-code-enabled-modes 'not))
|
||||||
|
(not (memq major-mode (cdr +pretty-code-enabled-modes)))
|
||||||
|
(memq major-mode +pretty-code-enabled-modes)))
|
||||||
|
(setq prettify-symbols-alist
|
||||||
|
(append (alist-get major-mode +pretty-code-symbols-alist)
|
||||||
|
(default-value 'prettify-symbols-alist)))
|
||||||
|
(when prettify-symbols-mode
|
||||||
|
(prettify-symbols-mode -1))
|
||||||
|
(prettify-symbols-mode +1))))
|
||||||
|
|
||||||
|
(add-hook 'after-change-major-mode-hook #'+pretty-code|init-pretty-symbols)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue