Move :ui pretty-code to :ui ligatures
Includes a major refactor of the module.
This commit is contained in:
parent
ed264dcdb2
commit
7081d833f6
32 changed files with 899 additions and 920 deletions
58
modules/ui/ligatures/autoload/install.el
Normal file
58
modules/ui/ligatures/autoload/install.el
Normal file
|
@ -0,0 +1,58 @@
|
|||
;;; ui/ligatures/autoload/install.el -*- lexical-binding: t; -*-
|
||||
;;;###if (or (featurep! +fira) (featurep! +hasklig) (featurep! +iosevka))
|
||||
|
||||
(defun +ligatures--install-font (prefix name url-format fonts-alist &optional extra-fonts)
|
||||
"Install fonts to the local system.
|
||||
|
||||
If PREFIX is nil, will prompt whether or not to download. NAME is informational
|
||||
only. URL-FORMAT is a format string that should be a url and have a single %s,
|
||||
which is expanded for each font in FONTS-ALIST. FONTS-ALIST should be the
|
||||
filename of each font. It is used as the source and destination filename."
|
||||
(unless (or prefix
|
||||
(yes-or-no-p
|
||||
(format "This will download and install the %s fonts, continue?"
|
||||
name)))
|
||||
(user-error "Aborted"))
|
||||
(let* ((font-dest
|
||||
(cond (IS-LINUX
|
||||
(expand-file-name
|
||||
"fonts/" (or (getenv "XDG_DATA_HOME")
|
||||
"~/.local/share")))
|
||||
(IS-MAC
|
||||
(expand-file-name "~/Library/Fonts/"))))
|
||||
(known-dest-p (stringp font-dest))
|
||||
(font-dest (or font-dest (read-directory-name "Font installation directory: " "~/"))))
|
||||
(unless (file-directory-p font-dest)
|
||||
(mkdir font-dest t))
|
||||
(dolist (font fonts-alist)
|
||||
(url-copy-file (format url-format font)
|
||||
(expand-file-name font font-dest)
|
||||
t))
|
||||
(when known-dest-p
|
||||
(message "Font downloaded, updating font cache... <fc-cache -f -v> ")
|
||||
(shell-command-to-string "fc-cache -f -v"))
|
||||
(if IS-WINDOW
|
||||
(when (y-or-n-p "The %S font was downloaded, but Windows users must install them manually.\n\nShow files in windows explorer?")
|
||||
(call-process "explorer.exe" nil nil nil font-dest))
|
||||
(message "Successfully %s %S fonts to %S!"
|
||||
(if known-dest-p "installed" "downloaded")
|
||||
name font-dest))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +ligatures/install-patched-font (font-id &optional arg)
|
||||
"Install the font FONT-ID on your system.
|
||||
FONT-ID must be a key from `+ligatures--font-alist'.
|
||||
If PREFIX is non-nil, don't ask for confirmation and install it."
|
||||
(interactive
|
||||
(list
|
||||
(car (cl-find (completing-read
|
||||
"Install font: "
|
||||
(mapcar #'cadr +ligatures--font-alist))
|
||||
+ligatures--font-alist
|
||||
:key #'cadr
|
||||
:test #'equal))
|
||||
current-prefix-arg))
|
||||
(cl-destructuring-bind (font-name &keys _range url files)
|
||||
(or (alist-get font-id +ligatures--font-alist)
|
||||
(user-error "%S is not a valid font" font-id))
|
||||
(+ligatures--install-font prefix font-name url files)))
|
50
modules/ui/ligatures/autoload/ligatures.el
Normal file
50
modules/ui/ligatures/autoload/ligatures.el
Normal file
|
@ -0,0 +1,50 @@
|
|||
;;; ui/ligatures/autoload/ligatures.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; DEPRECATED
|
||||
;;;###autodef
|
||||
(define-obsolete-function-alias 'set-pretty-symbols! 'set-ligatures! "3.0.0")
|
||||
|
||||
;;;###autodef
|
||||
(defun set-ligatures! (modes &rest plist)
|
||||
"Associates string patterns with icons in certain major-modes.
|
||||
|
||||
MODES is a major mode symbol or a list of them.
|
||||
PLIST is a property list whose keys must match keys in `+ligatures-classes',
|
||||
and whose values are strings representing the text to be replaced with that
|
||||
symbol. If the car of PLIST is nil, then unset any pretty symbols previously
|
||||
defined for MODES.
|
||||
|
||||
This function accepts one special property:
|
||||
|
||||
:alist ALIST
|
||||
Appends ALIST to `prettify-symbols-alist' literally, without mapping text to
|
||||
`+ligatures-classes'.
|
||||
|
||||
For example, the rule for emacs-lisp-mode is very simple:
|
||||
|
||||
(set-ligatures! 'emacs-lisp-mode
|
||||
:lambda \"lambda\")
|
||||
|
||||
This will replace any instances of \"lambda\" in emacs-lisp-mode with the symbol
|
||||
assicated with :lambda in `+ligatures-classes'.
|
||||
|
||||
Pretty symbols can be unset for emacs-lisp-mode with:
|
||||
|
||||
(set-ligatures! 'emacs-lisp-mode nil)"
|
||||
(declare (indent defun))
|
||||
(if (null (car-safe plist))
|
||||
(dolist (mode (doom-enlist modes))
|
||||
(assq-delete-all mode +ligatures-extra-alist))
|
||||
(let (results)
|
||||
(while plist
|
||||
(let ((key (pop plist)))
|
||||
(if (eq key :alist)
|
||||
(prependq! results (pop plist))
|
||||
(when-let (char (plist-get +ligatures-classes key))
|
||||
(push (cons (pop plist) char) results)))))
|
||||
(dolist (mode (doom-enlist modes))
|
||||
(setf (alist-get mode +ligatures-extra-alist)
|
||||
(if-let (old-results (alist-get mode +ligatures-extra-alist))
|
||||
(dolist (cell results old-results)
|
||||
(setf (alist-get (car cell) old-results) (cdr cell)))
|
||||
results))))))
|
Loading…
Add table
Add a link
Reference in a new issue