9191(require 'font-lock )
9292(require 'cl-lib )
9393
94- (defcustom purescript-font-lock-symbols nil
95- " Display \\ and -> and such using symbols in fonts.
96- 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' ."
101- :group 'purescript
102- :type '(choice (const nil )
103- (const t )
104- (const unicode)
105- (const japanese-jisx0208)))
106-
107- (defconst purescript-font-lock-symbols-alist
108- (append
109- ; ; Prefer single-width Unicode font for lambda.
110- (and (fboundp 'decode-char )
111- (memq purescript-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 purescript-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 purescript-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- 'purescript-font-lock-dot-is-not-composition )
152- (cons " forall" (decode-char 'ucs 8704 )))))
153- " Alist mapping PureScript symbols to chars.
154- Each element has the form (STRING . CHAR) or (STRING CHAR PREDICATE).
155- STRING is the PureScript symbol.
156- CHAR is the character with which to represent this symbol.
157- 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." )
160-
161- (defun purescript-font-lock-dot-is-not-composition (start )
162- " Return non-nil if the \" .\" at START is not a composition operator.
163- This is the case if the \" .\" is part of a \" forall <tvar> . <type>\" ."
164- (save-excursion
165- (goto-char start)
166- (re-search-backward " \\ <forall\\ >[^.\" ]*\\= "
167- (line-beginning-position ) t )))
94+ (defcustom purescript-font-lock-prettify-symbols-alist
95+ `((" /\\ " . ,(decode-char 'ucs #X2227 ))
96+ (" \\ " . ,(decode-char 'ucs 955 ))
97+ (" not" . ,(decode-char 'ucs 172 ))
98+ (" ->" . ,(decode-char 'ucs 8594 ))
99+ (" <-" . ,(decode-char 'ucs 8592 ))
100+ (" =>" . ,(decode-char 'ucs 8658 ))
101+ (" ()" . ,(decode-char 'ucs #X2205 ))
102+ (" ==" . ,(decode-char 'ucs #X2261 ))
103+ (" <<<" . ,(decode-char 'ucs 9675 ))
104+ (" /=" . ,(decode-char 'ucs #X2262 ))
105+ (" >=" . ,(decode-char 'ucs #X2265 ))
106+ (" <=" . ,(decode-char 'ucs #X2264 ))
107+ (" !!" . ,(decode-char 'ucs #X203C ))
108+ (" &&" . ,(decode-char 'ucs #X2227 ))
109+ (" ||" . ,(decode-char 'ucs #X2228 ))
110+ (" sqrt" . ,(decode-char 'ucs #X221A ))
111+ (" undefined" . ,(decode-char 'ucs #X22A5 )) ; ; Not really needed for Purescript
112+ (" pi" . ,(decode-char 'ucs #X3C0 ))
113+ (" ~>" . ,(decode-char 'ucs 8669 )) ; ; Omega language
114+ (" -<" . ,(decode-char 'ucs 8610 )) ; ; Paterson's arrow syntax
115+ (" ::" . ,(decode-char 'ucs 8759 ))
116+ (" forall" . ,(decode-char 'ucs 8704 )))
117+ " A set of symbol compositions for use as `prettify-symbols-alist' ."
118+ :group 'purescript )
168119
169120; ; Use new vars for the font-lock faces. The indirection allows people to
170121; ; use different faces than in other modes, as before.
@@ -187,57 +138,6 @@ Set to `default' to avoid fontification of them.")
187138 " Non-nil if we have regexp char classes.
188139Assume this means we have other useful features from Emacs 21." )
189140
190- (defun purescript-font-lock-compose-symbol (alist )
191- " Compose a sequence of ascii chars into a symbol.
192- Regexp match data 0 points to the chars."
193- ; ; Check that the chars should really be composed into a symbol.
194- (let* ((start (match-beginning 0 ))
195- (end (match-end 0 ))
196- (syntaxes (cond
197- ((eq (char-syntax (char-after start)) ?w ) '(?w ))
198- ; ; Special case for the . used for qualified names.
199- ((and (eq (char-after start) ?\. ) (= end (1+ start)))
200- '(?_ ?\\ ?w ))
201- (t '(?_ ?\\ ))))
202- sym-data)
203- (if (or (memq (char-syntax (or (char-before start) ?\ )) syntaxes)
204- (memq (char-syntax (or (char-after end) ?\ )) syntaxes)
205- (memq (get-text-property start 'face )
206- '(font-lock-doc-face font-lock-string-face
207- font-lock-comment-face ))
208- (and (consp (setq sym-data (cdr (assoc (match-string 0 ) alist))))
209- (let ((pred (cadr sym-data)))
210- (setq sym-data (car sym-data))
211- (funcall pred start))))
212- ; ; No composition for you. Let's actually remove any composition
213- ; ; we may have added earlier and which is now incorrect.
214- (remove-text-properties start end '(composition))
215- ; ; That's a symbol alright, so add the composition.
216- (compose-region start end sym-data)))
217- ; ; Return nil because we're not adding any face property.
218- nil )
219-
220- (defun purescript-font-lock-symbols-keywords ()
221- (when (fboundp 'compose-region )
222- (let ((alist nil ))
223- (dolist (x purescript-font-lock-symbols-alist)
224- (when (and (if (fboundp 'char-displayable-p )
225- (char-displayable-p (if (consp (cdr x)) (cadr x) (cdr x)))
226- (if (fboundp 'latin1-char-displayable-p )
227- (latin1-char-displayable-p (if (consp (cdr x))
228- (cadr x)
229- (cdr x)))
230- t ))
231- (not (assoc (car x) alist))) ; Not yet in alist.
232- (push x alist)))
233- (when alist
234- `((,(regexp-opt (mapcar 'car alist) t )
235- (0 (purescript-font-lock-compose-symbol ', alist )
236- ; ; In Emacs-21, if the `override' field is nil, the face
237- ; ; expressions is only evaluated if the text has currently
238- ; ; no face. So force evaluation by using `keep' .
239- keep)))))))
240-
241141; ; The font lock regular expressions.
242142(defun purescript-font-lock-keywords-create (literate )
243143 " Create fontification definitions for PureScript scripts.
@@ -326,13 +226,6 @@ Returns keywords suitable for `font-lock-keywords'."
326226 ; ; Expensive.
327227 `((, string-and-char 1 font-lock-string-face )))
328228
329- ; ; This was originally at the very end (and needs to be after
330- ; ; all the comment/string/doc highlighting) but it seemed to
331- ; ; trigger a bug in Emacs-21.3 which caused the compositions to
332- ; ; be "randomly" dropped. Moving it earlier seemed to reduce
333- ; ; the occurrence of the bug.
334- ,@(purescript-font-lock-symbols-keywords)
335-
336229 (, reservedid 1 (symbol-value 'purescript-keyword-face ))
337230 (, reservedsym 1 (symbol-value 'purescript-operator-face ))
338231 ; ; Special case for `as' , `hiding' , `safe' and `qualified' , which are
0 commit comments