Skip to content

Commit 6541e24

Browse files
committed
Modernize haskell-font-lock-symbols.
1 parent 1766c26 commit 6541e24

File tree

1 file changed

+46
-76
lines changed

1 file changed

+46
-76
lines changed

haskell-font-lock.el

Lines changed: 46 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -93,70 +93,50 @@
9393

9494
(defcustom haskell-font-lock-symbols nil
9595
"Display \\ and -> and such using symbols in fonts.
96+
9697
This may sound like a neat trick, but be extra careful: it changes the
97-
alignment and can thus lead to nasty surprises w.r.t layout.
98-
If t, try to use whichever font is available. Otherwise you can
99-
set it to a particular font of your preference among `japanese-jisx0208'
100-
and `unicode'."
98+
alignment and can thus lead to nasty surprises w.r.t layout."
10199
:group 'haskell
102-
:type '(choice (const nil)
103-
(const t)
104-
(const unicode)
105-
(const japanese-jisx0208)))
100+
:type 'boolean)
106101

107102
(defconst haskell-font-lock-symbols-alist
108-
(append
109-
;; Prefer single-width Unicode font for lambda.
110-
(and (fboundp 'decode-char)
111-
(memq haskell-font-lock-symbols '(t unicode))
112-
(list (cons "\\" (decode-char 'ucs 955))))
113-
;; The symbols can come from a JIS0208 font.
114-
(and (fboundp 'make-char) (fboundp 'charsetp) (charsetp 'japanese-jisx0208)
115-
(memq haskell-font-lock-symbols '(t japanese-jisx0208))
116-
(list (cons "not" (make-char 'japanese-jisx0208 34 76))
117-
(cons "\\" (make-char 'japanese-jisx0208 38 75))
118-
(cons "->" (make-char 'japanese-jisx0208 34 42))
119-
(cons "<-" (make-char 'japanese-jisx0208 34 43))
120-
(cons "=>" (make-char 'japanese-jisx0208 34 77))
121-
;; FIXME: I'd like to either use ∀ or ∃ depending on how the
122-
;; `forall' keyword is used, but currently the rest of the
123-
;; code assumes that such ambiguity doesn't happen :-(
124-
(cons "forall" (make-char 'japanese-jisx0208 34 79))))
125-
;; Or a unicode font.
126-
(and (fboundp 'decode-char)
127-
(memq haskell-font-lock-symbols '(t unicode))
128-
(list (cons "not" (decode-char 'ucs 172))
129-
(cons "->" (decode-char 'ucs 8594))
130-
(cons "<-" (decode-char 'ucs 8592))
131-
(cons "=>" (decode-char 'ucs 8658))
132-
(cons "()" (decode-char 'ucs #X2205))
133-
(cons "==" (decode-char 'ucs #X2261))
134-
(cons "/=" (decode-char 'ucs #X2262))
135-
(cons ">=" (decode-char 'ucs #X2265))
136-
(cons "<=" (decode-char 'ucs #X2264))
137-
(cons "!!" (decode-char 'ucs #X203C))
138-
(cons "&&" (decode-char 'ucs #X2227))
139-
(cons "||" (decode-char 'ucs #X2228))
140-
(cons "sqrt" (decode-char 'ucs #X221A))
141-
(cons "undefined" (decode-char 'ucs #X22A5))
142-
(cons "pi" (decode-char 'ucs #X3C0))
143-
(cons "~>" (decode-char 'ucs 8669)) ;; Omega language
144-
;; (cons "~>" (decode-char 'ucs 8605)) ;; less desirable
145-
(cons "-<" (decode-char 'ucs 8610)) ;; Paterson's arrow syntax
146-
;; (cons "-<" (decode-char 'ucs 10521)) ;; nicer but uncommon
147-
(cons "::" (decode-char 'ucs 8759))
148-
(list "." (decode-char 'ucs 8728) ; (decode-char 'ucs 9675)
149-
;; Need a predicate here to distinguish the . used by
150-
;; forall <foo> . <bar>.
151-
'haskell-font-lock-dot-is-not-composition)
152-
(cons "forall" (decode-char 'ucs 8704)))))
103+
'(("\\" . "λ")
104+
("not" . "¬")
105+
("->" . "")
106+
("<-" . "")
107+
("=>" . "")
108+
("()" . "")
109+
("==" . "")
110+
("/=" . "")
111+
(">=" . "")
112+
("<=" . "")
113+
("!!" . "")
114+
("&&" . "")
115+
("||" . "")
116+
("sqrt" . "")
117+
("undefined" . "")
118+
("pi" . "π")
119+
("~>" . "") ;; Omega language
120+
;; ("~>" "↝") ;; less desirable
121+
("-<" . "") ;; Paterson's arrow syntax
122+
;; ("-<" "⤙") ;; nicer but uncommon
123+
("::" . "")
124+
("." "" ; "○"
125+
;; Need a predicate here to distinguish the . used by
126+
;; forall <foo> . <bar>.
127+
haskell-font-lock-dot-is-not-composition)
128+
("forall" . ""))
153129
"Alist mapping Haskell symbols to chars.
154-
Each element has the form (STRING . CHAR) or (STRING CHAR PREDICATE).
130+
131+
Each element has the form (STRING . COMPONENTS) or (STRING
132+
COMPONENTS PREDICATE).
133+
155134
STRING is the Haskell symbol.
156-
CHAR is the character with which to represent this symbol.
135+
COMPONENTS is a representation specification suitable as an argument to
136+
`compose-region'.
157137
PREDICATE if present is a function of one argument (the start position
158-
of the symbol) which should return non-nil if this mapping should be disabled
159-
at that position.")
138+
of the symbol) which should return non-nil if this mapping should
139+
be disabled at that position.")
160140

161141
(defun haskell-font-lock-dot-is-not-composition (start)
162142
"Return non-nil if the \".\" at START is not a composition operator.
@@ -246,25 +226,15 @@ Regexp match data 0 points to the chars."
246226
nil)
247227

248228
(defun haskell-font-lock-symbols-keywords ()
249-
(when (fboundp 'compose-region)
250-
(let ((alist nil))
251-
(dolist (x haskell-font-lock-symbols-alist)
252-
(when (and (if (fboundp 'char-displayable-p)
253-
(char-displayable-p (if (consp (cdr x)) (cadr x) (cdr x)))
254-
(if (fboundp 'latin1-char-displayable-p)
255-
(latin1-char-displayable-p (if (consp (cdr x))
256-
(cadr x)
257-
(cdr x)))
258-
t))
259-
(not (assoc (car x) alist))) ; Not yet in alist.
260-
(push x alist)))
261-
(when alist
262-
`((,(regexp-opt (mapcar 'car alist) t)
263-
(0 (haskell-font-lock-compose-symbol ',alist)
264-
;; In Emacs-21, if the `override' field is nil, the face
265-
;; expressions is only evaluated if the text has currently
266-
;; no face. So force evaluation by using `keep'.
267-
keep)))))))
229+
(when (and haskell-font-lock-symbols
230+
haskell-font-lock-symbols-alist
231+
(fboundp 'compose-region))
232+
`((,(regexp-opt (mapcar 'car haskell-font-lock-symbols-alist) t)
233+
(0 (haskell-font-lock-compose-symbol ',haskell-font-lock-symbols-alist)
234+
;; In Emacs-21, if the `override' field is nil, the face
235+
;; expressions is only evaluated if the text has currently
236+
;; no face. So force evaluation by using `keep'.
237+
keep)))))
268238

269239
(defun haskell-font-lock-find-pragma (end)
270240
(catch 'haskell-font-lock-find-pragma

0 commit comments

Comments
 (0)