Skip to content

Commit 1c43bbf

Browse files
committed
Merge pull request #1051 from gracjan/pr-more-visible-quasi-quotes
Make quasi quote more visible
2 parents 78e6d50 + ce884af commit 1c43bbf

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

haskell-font-lock.el

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ font faces assigned as if respective mode was enabled."
152152
Inherit from `default' to avoid fontification of them."
153153
:group 'haskell)
154154

155+
(defface haskell-quasi-quote-face
156+
'((((background light)) :background "gray90")
157+
(((background dark)) :background "gray10")
158+
(t :inherit font-lock-string-face))
159+
"Face for background with which to fontify quasi quotes that
160+
are fontified according to other mode defined in
161+
`haskell-font-lock-quasi-quote-modes'."
162+
:group 'haskell)
163+
155164
(defun haskell-font-lock-compose-symbol (alist)
156165
"Compose a sequence of ascii chars into a symbol.
157166
Regexp match data 0 points to the chars."
@@ -480,11 +489,12 @@ that should be commented under LaTeX-style literate scripts."
480489
;; find the end of the QuasiQuote
481490
(parse-partial-sexp (point) (point-max) nil nil state
482491
'syntax-table)
483-
(haskell-font-lock-fontify-block lang-mode (nth 8 state) (point))
492+
(haskell-font-lock-fontify-block lang-mode (1+ (nth 8 state)) (1- (point)))
493+
(font-lock-prepend-text-property (nth 8 state) (point) 'face 'haskell-quasi-quote-face)
484494
;; must return nil here so that it is not fontified again as string
485495
nil)
486496
;; fontify normally as string because lang-mode is not present
487-
'font-lock-string-face))
497+
'(haskell-quasi-quote-face font-lock-string-face)))
488498
'font-lock-string-face))
489499
;; Else comment. If it's from syntax table, use default face.
490500
((or (eq 'syntax-table (nth 7 state))

tests/haskell-font-lock-tests.el

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,18 @@ if all of its characters have syntax and face. See
248248
(check-properties
249249
'("[qq| \\|] Cons")
250250
'(("qq" "w" nil)
251-
("\\" "." font-lock-string-face)
251+
("\\" "." (haskell-quasi-quote-face font-lock-string-face))
252252
("Cons" "w" haskell-constructor-face))))
253253

254254
(ert-deftest haskell-syntactic-quasiquote-three-punctuation ()
255255
"Check string escape vs comment escape"
256256
(check-properties
257257
'("[qq| %\\|] Cons")
258258
'(("qq" "w" nil)
259-
("%\\" "." font-lock-string-face)
259+
("%\\" "." (haskell-quasi-quote-face font-lock-string-face))
260260
("Cons" "w" haskell-constructor-face))))
261261

262-
(ert-deftest haskell-syntactic-test-11 ()
262+
(ert-deftest haskell-syntactic-test-11a ()
263263
"Syntax for haddock comments"
264264
(check-properties
265265
'(" -- | Dcom1" ; haddocks
@@ -304,7 +304,7 @@ if all of its characters have syntax and face. See
304304
("Dcom17" "w" font-lock-doc-face)
305305
)))
306306

307-
(ert-deftest haskell-syntactic-test-11 ()
307+
(ert-deftest haskell-syntactic-test-11b ()
308308
"Syntax for haddock comments"
309309
;; Note: all of these are prefixed with space so that
310310
;; top-level definition detection does not kick in.
@@ -358,9 +358,9 @@ if all of its characters have syntax and face. See
358358
(check-properties
359359
'("v = [quoter| string |] Cons")
360360
'(("[" t nil)
361-
("|" t font-lock-string-face)
362-
("string" t font-lock-string-face)
363-
("|" t font-lock-string-face)
361+
("|" t (haskell-quasi-quote-face font-lock-string-face))
362+
("string" t (haskell-quasi-quote-face font-lock-string-face))
363+
("|" t (haskell-quasi-quote-face font-lock-string-face))
364364
("]" t nil)
365365
("Cons" "w" haskell-constructor-face))))
366366

@@ -372,41 +372,41 @@ if all of its characters have syntax and face. See
372372
" finishing line"
373373
"|] Cons")
374374
'(("[" t nil)
375-
("|" t font-lock-string-face)
376-
("string" t font-lock-string-face)
377-
("line" t font-lock-string-face)
378-
("|" t font-lock-string-face)
375+
("|" t (haskell-quasi-quote-face font-lock-string-face))
376+
("string" t (haskell-quasi-quote-face font-lock-string-face))
377+
("line" t (haskell-quasi-quote-face font-lock-string-face))
378+
("|" t (haskell-quasi-quote-face font-lock-string-face))
379379
("]" t nil)
380380
("Cons" "w" haskell-constructor-face))))
381381

382-
(ert-deftest haskell-syntactic-test-quasiquoter-2 ()
382+
(ert-deftest haskell-syntactic-test-quasiquoter-3 ()
383383
"QuasiQuote inside quasi quote"
384384
(check-properties
385385
'("v = [quoter| [inner| string {- -- |] Outside |]")
386386
'(("[" t nil)
387-
("|" t font-lock-string-face)
388-
("inner" t font-lock-string-face)
389-
("string" t font-lock-string-face)
390-
("|" t font-lock-string-face)
387+
("|" t (haskell-quasi-quote-face font-lock-string-face))
388+
("inner" t (haskell-quasi-quote-face font-lock-string-face))
389+
("string" t (haskell-quasi-quote-face font-lock-string-face))
390+
("|" t (haskell-quasi-quote-face font-lock-string-face))
391391
("]" t nil)
392392
("Outside" "w" haskell-constructor-face)
393393
)))
394394

395-
(ert-deftest haskell-syntactic-test-quasiquoter-3 ()
395+
(ert-deftest haskell-syntactic-test-quasiquoter-4 ()
396396
"QuasiQuote inside comment"
397397
(check-properties
398398
'("v = -- [quoter| "
399399
" [inner| string {- -- |] Outside1 |] Outside2")
400400
'(("quoter" t font-lock-comment-face)
401401
("inner" t nil)
402-
("string" t font-lock-string-face)
403-
("|" t font-lock-string-face)
402+
("string" t (haskell-quasi-quote-face font-lock-string-face))
403+
("|" t (haskell-quasi-quote-face font-lock-string-face))
404404
("]" t nil)
405405
("Outside1" "w" haskell-constructor-face)
406406
("Outside2" "w" haskell-constructor-face)
407407
)))
408408

409-
(ert-deftest haskell-syntactic-test-quasiquoter-3 ()
409+
(ert-deftest haskell-syntactic-test-quasiquoter-5 ()
410410
"QuasiQuote should not conflict with TemplateHaskell"
411411
(check-properties
412412
'("nope = [| Cons |]"
@@ -420,7 +420,7 @@ if all of its characters have syntax and face. See
420420
("Cons_t" t haskell-constructor-face)
421421
("Cons_d" t haskell-constructor-face)
422422
("Cons_p" t haskell-constructor-face)
423-
("Cons_x" t font-lock-string-face))))
423+
("Cons_x" t (haskell-quasi-quote-face font-lock-string-face)))))
424424

425425
(ert-deftest haskell-syntactic-test-special-not-redefined ()
426426
"QuasiQuote should not conflict with TemplateHaskell"

0 commit comments

Comments
 (0)