-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hasklig-mode.el
67 lines (55 loc) · 2.05 KB
/
hasklig-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
;;; hasklig-mode.el --- Hasklig ligatures -*- lexical-binding: t -*-
;; Copyright (C) 2018-2024 Daniel Mendler
;; Author: Daniel Mendler
;; Created: 2018
;; License: GPL-3.0-or-later
;; Version: 0.2
;; Package-Requires: ((emacs "25"))
;; Homepage: https://github.com/minad/hasklig-mode
;;; Commentary:
;; Minor mode for Hasklig ligatures
;;; Code:
(defun hasklig-mode--make-alist (list)
"Generate prettify-symbols alist from LIST."
(let ((idx -1))
(mapcar
(lambda (s)
(setq idx (1+ idx))
(let* ((code (+ #Xe100 idx))
(width (string-width s))
(prefix ())
(suffix '(?\s (Br . Br)))
(n 1))
(while (< n width)
(setq prefix (append prefix '(?\s (Br . Bl))))
(setq n (1+ n)))
(cons s (append prefix suffix (list (decode-char 'ucs code))))))
list)))
;; Hasklig ligatures. See https://github.com/i-tu/Hasklig/blob/master/GlyphOrderAndAliasDB.
(defconst hasklig-mode--ligatures
'("&&" "***" "*>" "\\\\" "||" "|>" "::"
"==" "===" "==>" "=>" "=<<" "!!" ">>"
">>=" ">>>" ">>-" ">-" "->" "-<" "-<<"
"<*" "<*>" "<|" "<|>" "<$>" "<>" "<-"
"<<" "<<<" "<+>" ".." "..." "++" "+++"
"/=" ":::" ">=>" "->>" "<=>" "<=<" "<->"))
(defvar hasklig-mode--old-prettify-alist)
(defun hasklig-mode--enable ()
"Enable Hasklig ligatures in current buffer."
(setq-local hasklig-mode--old-prettify-alist prettify-symbols-alist)
(setq-local prettify-symbols-alist (append (hasklig-mode--make-alist hasklig-mode--ligatures) hasklig-mode--old-prettify-alist))
(prettify-symbols-mode t))
(defun hasklig-mode--disable ()
"Disable Hasklig ligatures in current buffer."
(setq-local prettify-symbols-alist hasklig-mode--old-prettify-alist)
(prettify-symbols-mode -1))
;;;###autoload
(define-minor-mode hasklig-mode
"Hasklig Ligatures minor mode."
:lighter " Hasklig"
(setq-local prettify-symbols-unprettify-at-point 'right-edge)
(if hasklig-mode
(hasklig-mode--enable)
(hasklig-mode--disable)))
(provide 'hasklig-mode)
;;; hasklig-mode.el ends here