2020-08-12 18:52:14 -04:00
|
|
|
;;; ui/ligatures/autoload/ligatures.el -*- lexical-binding: t; -*-
|
2018-07-05 19:37:06 -07:00
|
|
|
|
2020-08-12 18:52:14 -04:00
|
|
|
;; DEPRECATED
|
|
|
|
;;;###autodef
|
|
|
|
(define-obsolete-function-alias 'set-pretty-symbols! 'set-ligatures! "3.0.0")
|
2018-07-05 19:37:06 -07:00
|
|
|
|
2018-07-06 19:59:16 +02:00
|
|
|
;;;###autodef
|
2020-08-12 18:52:14 -04:00
|
|
|
(defun set-ligatures! (modes &rest plist)
|
2018-07-06 19:59:16 +02:00
|
|
|
"Associates string patterns with icons in certain major-modes.
|
|
|
|
|
|
|
|
MODES is a major mode symbol or a list of them.
|
2020-08-20 02:40:57 -04:00
|
|
|
PLIST is a property list whose keys must match keys in
|
|
|
|
`+ligatures-extra-symbols', and whose values are strings representing the text
|
2021-05-23 11:27:57 +02:00
|
|
|
to be replaced with that symbol.
|
2018-07-06 19:59:16 +02:00
|
|
|
|
2021-05-23 11:27:57 +02:00
|
|
|
If the car of PLIST is nil, then unset any
|
|
|
|
pretty symbols and ligatures previously defined for MODES.
|
2018-07-06 19:59:16 +02:00
|
|
|
|
|
|
|
For example, the rule for emacs-lisp-mode is very simple:
|
|
|
|
|
2024-09-12 23:18:30 -04:00
|
|
|
(after! elisp-mode
|
|
|
|
(set-ligatures! \\='emacs-lisp-mode
|
|
|
|
:lambda \"lambda\"))
|
2018-07-06 19:59:16 +02:00
|
|
|
|
|
|
|
This will replace any instances of \"lambda\" in emacs-lisp-mode with the symbol
|
2021-05-23 11:27:57 +02:00
|
|
|
associated with :lambda in `+ligatures-extra-symbols'.
|
2018-07-06 19:59:16 +02:00
|
|
|
|
2024-09-12 23:18:30 -04:00
|
|
|
Pretty symbols can be unset by passing `nil':
|
2018-07-06 19:59:16 +02:00
|
|
|
|
2024-09-12 23:18:30 -04:00
|
|
|
(after! rustic
|
|
|
|
(set-ligatures! \\='rustic-mode nil))
|
2021-05-23 11:27:57 +02:00
|
|
|
|
|
|
|
Note that this will keep all ligatures in `+ligatures-prog-mode-list' active, as
|
|
|
|
`emacs-lisp-mode' is derived from `prog-mode'."
|
2018-07-06 19:59:16 +02:00
|
|
|
(declare (indent defun))
|
2018-10-16 17:32:41 -04:00
|
|
|
(if (null (car-safe plist))
|
2022-08-07 12:24:14 +02:00
|
|
|
(dolist (mode (ensure-list modes))
|
2020-10-15 16:12:57 -04:00
|
|
|
(delq! mode +ligatures-extra-alist 'assq))
|
2021-05-23 11:27:57 +02:00
|
|
|
(let ((results))
|
2018-10-16 17:32:41 -04:00
|
|
|
(while plist
|
2020-01-04 04:55:57 -05:00
|
|
|
(let ((key (pop plist)))
|
2020-08-20 02:40:57 -04:00
|
|
|
(when-let (char (plist-get +ligatures-extra-symbols key))
|
2021-05-23 11:27:57 +02:00
|
|
|
(push (cons (pop plist) char) results))))
|
2022-08-07 12:24:14 +02:00
|
|
|
(dolist (mode (ensure-list modes))
|
2020-08-12 18:52:14 -04:00
|
|
|
(setf (alist-get mode +ligatures-extra-alist)
|
|
|
|
(if-let (old-results (alist-get mode +ligatures-extra-alist))
|
2020-01-04 04:55:57 -05:00
|
|
|
(dolist (cell results old-results)
|
|
|
|
(setf (alist-get (car cell) old-results) (cdr cell)))
|
|
|
|
results))))))
|
2021-05-23 11:27:57 +02:00
|
|
|
|
|
|
|
;;;###autodef
|
|
|
|
(defun set-font-ligatures! (modes &rest ligatures)
|
|
|
|
"Associates string patterns with ligatures in certain major-modes.
|
|
|
|
|
|
|
|
MODES is a major mode symbol or a list of them.
|
|
|
|
LIGATURES is a list of ligatures that should be handled by the font,
|
|
|
|
like \"==\" or \"-->\". LIGATURES is a list of strings.
|
|
|
|
|
|
|
|
For example, the rule for emacs-lisp-mode is very simple:
|
|
|
|
|
|
|
|
(set-font-ligatures! \\='emacs-lisp-mode \"->\")
|
|
|
|
|
|
|
|
This will ligate \"->\" into the arrow of choice according to your font.
|
|
|
|
|
2024-08-20 00:01:12 -04:00
|
|
|
All font ligatures for emacs-lisp-mode can be unset with:
|
2021-05-23 11:27:57 +02:00
|
|
|
|
|
|
|
(set-font-ligatures! \\='emacs-lisp-mode nil)
|
|
|
|
|
2024-08-20 00:01:12 -04:00
|
|
|
However, ligatures for any parent modes (like `prog-mode') will still be in
|
|
|
|
effect, as `emacs-lisp-mode' is derived from `prog-mode'."
|
2021-05-23 11:27:57 +02:00
|
|
|
(declare (indent defun))
|
2024-08-20 00:01:12 -04:00
|
|
|
(after! ligature
|
|
|
|
(if (or (null ligatures) (equal ligatures '(nil)))
|
|
|
|
(dolist (table ligature-composition-table)
|
|
|
|
(let ((modes (ensure-list modes))
|
|
|
|
(tmodes (car table)))
|
|
|
|
(cond ((and (listp tmodes) (cl-intersection modes tmodes))
|
|
|
|
(let ((tmodes (cl-nset-difference tmodes modes)))
|
|
|
|
(setq ligature-composition-table
|
|
|
|
(if tmodes
|
|
|
|
(cons tmodes (cdr table))
|
|
|
|
(delete table ligature-composition-table)))))
|
|
|
|
((memq tmodes modes)
|
|
|
|
(setq ligature-composition-table (delete table ligature-composition-table))))))
|
|
|
|
(ligature-set-ligatures modes ligatures))))
|