-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemacs-rc-pretty-lambda.el
More file actions
130 lines (118 loc) · 4.74 KB
/
emacs-rc-pretty-lambda.el
File metadata and controls
130 lines (118 loc) · 4.74 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;; emacs-rc-pretty-lambda.el ---
;; Copyright (C) Alex Ott
;;
;; Author: Alex Ott <alexott@gmail.com>
;; Keywords:
;; Requirements:
;; Status: not intended to be distributed yet
;; Unicode symbols in buffer
(defun unicode-symbol (name)
"Translate a symbolic name for a Unicode character -- e.g., LEFT-ARROW
or GREATER-THAN into an actual Unicode character code. "
(decode-char 'ucs (case name
('right-triangle #X22b3)
('left-triangle #X22b2)
('left-arrow 8592)
('up-arrow 8593)
('right-arrow 8594)
('down-arrow 8595)
('right-double-arrow 8658)
('left-double-arrow 8656)
('double-vertical-bar #X2551)
('equal #X003d)
('not-equal #X2260)
('identical #X2261)
('not-identical #X2262)
('much-less-than #X226a)
('much-greater-than #X226b)
('less-than #X003c)
('greater-than #X003e)
('less-than-or-equal-to #X2264)
('greater-than-or-equal-to #X2265)
('logical-and #X2227)
('logical-or #X2228)
('logical-neg #X00AC)
('nil #X2205)
('horizontal-ellipsis #X2026)
('double-exclamation #X203C)
('prime #X2032)
('double-prime #X2033)
('for-all #X2200)
('there-exists #X2203)
('element-of #X2208)
('square-root #X221A)
('squared #X00B2)
('cubed #X00B3)
('lambda #X03BB)
('alpha #X03B1)
('beta #X03B2)
('gamma #X03B3)
('delta #X03B4))))
(defun substitute-pattern-with-unicode (pattern symbol)
"Add a font lock hook to replace the matched part of PATTERN with the
Unicode symbol SYMBOL looked up with UNICODE-SYMBOL."
(interactive)
(font-lock-add-keywords
nil `((,pattern
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(unicode-symbol symbol)
'decompose-region)
nil))))))
(defun substitute-patterns-with-unicode (patterns)
"Call SUBSTITUTE-PATTERN-WITH-UNICODE repeatedly."
(mapcar #'(lambda (x)
(substitute-pattern-with-unicode (car x)
(cdr x)))
patterns))
;; symbol replacements for erlang
(defun erlang-unicode ()
(interactive)
(substitute-patterns-with-unicode
(list
;; (cons "\\(<<\\)" 'left-arrow)
;; (cons "\\(>>\\)" 'left-arrow)
(cons "\\s \\(->\\)\\(\\s \\|$\\)" 'right-arrow))))
(add-hook 'erlang-mode-hook 'erlang-unicode)
(defun graphviz-dot-unicode ()
(interactive)
(substitute-patterns-with-unicode
(list
;; (cons "\\(<<\\)" 'left-arrow)
;; (cons "\\(>>\\)" 'left-arrow)
;;(cons "\\s \\(->\\)\\(\\s \\|$\\)" 'right-arrow))))
(cons "\\(->\\)" 'right-arrow))))
(add-hook 'graphviz-dot-mode-hook 'graphviz-dot-unicode)
(defun fsharp-unicode ()
(interactive)
(substitute-patterns-with-unicode
(list (cons "\\(<-\\)" 'left-arrow)
(cons "\\(->\\)" 'right-arrow)
(cons "\\[^=\\]\\(=\\)\\[^=\\]" 'equal)
(cons "\\(==\\)" 'identical)
(cons "\\(\\!=\\)" 'not-identical)
(cons "\\(<>\\)" 'not-equal)
(cons "\\(()\\)" 'nil)
(cons "\\<\\(sqrt\\)\\>" 'square-root)
(cons "\\(&&\\)" 'logical-and)
(cons "\\(||\\)" 'logical-or)
(cons "\\<\\(not\\)\\>" 'logical-neg)
(cons "\\(>\\)\\[^=\\]" 'greater-than)
(cons "\\(<\\)\\[^=\\]" 'less-than)
(cons "\\(>=\\)" 'greater-than-or-equal-to)
(cons "\\(<=\\)" 'less-than-or-equal-to)
(cons "\\<\\(alpha\\)\\>" 'alpha)
(cons "\\<\\(beta\\)\\>" 'beta)
(cons "\\<\\(gamma\\)\\>" 'gamma)
(cons "\\<\\(delta\\)\\>" 'delta)
(cons "\\(''\\)" 'double-prime)
(cons "\\('\\)" 'prime)
(cons "\\<\\(List.forall\\)\\>" 'for-all)
(cons "\\<\\(List.exists\\)\\>" 'there-exists)
(cons "\\(>>\\)" 'much-greater-than)
(cons "\\(<<\\)" 'much-less-than)
;;(cons "\\(|>\\)" 'right-triangle)
;;(cons "\\(<|\\)" 'left-triangle)
;;(cons "\\<\\(List.mem\\)\\>" 'element-of)
(cons "^ +\\(|\\)" 'double-vertical-bar))))
(add-hook 'fsharp-mode-hook 'fsharp-unicode)
;;; emacs-rc-pretty-lambda.el ends here