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,19 +1,9 @@
|
|||
;;; ui/pretty-code/+fira.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +pretty-code--correct-symbol-bounds (ligature-alist)
|
||||
"Prepend non-breaking spaces to a ligature.
|
||||
(defvar +pretty-code-fira-code-font-name "Fira Code Symbol"
|
||||
"Name of the fira code ligature font.")
|
||||
|
||||
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'."
|
||||
(let ((len (length (car ligature-alist)))
|
||||
(acc (list (cdr ligature-alist))))
|
||||
(while (> len 1)
|
||||
(setq acc (cons #X00a0 (cons '(Br . Bl) acc))
|
||||
len (1- len)))
|
||||
(cons (car ligature-alist) acc)))
|
||||
|
||||
(defconst +pretty-code-fira-code-font-ligatures
|
||||
(mapcar #'+pretty-code--correct-symbol-bounds
|
||||
(defvar +pretty-code-fira-code-font-ligatures
|
||||
'(("www" . #Xe100)
|
||||
("**" . #Xe101)
|
||||
("***" . #Xe102)
|
||||
|
@ -120,12 +110,25 @@ correct width of the symbols instead of the width measured by `char-width'."
|
|||
("~>" . #Xe167)
|
||||
("~~" . #Xe168)
|
||||
("~~>" . #Xe169)
|
||||
("%%" . #Xe16a))))
|
||||
("%%" . #Xe16a)))
|
||||
|
||||
(defun +pretty-code--correct-symbol-bounds (ligature-alist)
|
||||
"Prepend non-breaking spaces to a ligature.
|
||||
|
||||
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'."
|
||||
(let ((len (length (car ligature-alist)))
|
||||
(acc (list (cdr ligature-alist))))
|
||||
(while (> len 1)
|
||||
(setq acc (cons #X00a0 (cons '(Br . Bl) acc))
|
||||
len (1- len)))
|
||||
(cons (car ligature-alist) acc)))
|
||||
|
||||
(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
|
||||
(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; -*-
|
||||
|
||||
(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
|
||||
("<->" . #Xe100)
|
||||
("<-->" . #Xe101)
|
||||
|
@ -221,11 +224,10 @@
|
|||
"Defines the character mappings for ligatures for Iosevka.")
|
||||
|
||||
(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
|
||||
(append prettify-symbols-alist
|
||||
+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)
|
||||
(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
|
||||
(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