Skip to content

Make quasi quote more visible #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions haskell-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ font faces assigned as if respective mode was enabled."
Inherit from `default' to avoid fontification of them."
:group 'haskell)

(defface haskell-quasi-quote-face
'((((background light)) :background "gray90")
(((background dark)) :background "gray10")
(t :inherit font-lock-string-face))
"Face for background with which to fontify quasi quotes that
are fontified according to other mode defined in
`haskell-font-lock-quasi-quote-modes'."
:group 'haskell)

(defun haskell-font-lock-compose-symbol (alist)
"Compose a sequence of ascii chars into a symbol.
Regexp match data 0 points to the chars."
Expand Down Expand Up @@ -480,11 +489,12 @@ that should be commented under LaTeX-style literate scripts."
;; find the end of the QuasiQuote
(parse-partial-sexp (point) (point-max) nil nil state
'syntax-table)
(haskell-font-lock-fontify-block lang-mode (nth 8 state) (point))
(haskell-font-lock-fontify-block lang-mode (1+ (nth 8 state)) (1- (point)))
(font-lock-prepend-text-property (nth 8 state) (point) 'face 'haskell-quasi-quote-face)
;; must return nil here so that it is not fontified again as string
nil)
;; fontify normally as string because lang-mode is not present
'font-lock-string-face))
'(haskell-quasi-quote-face font-lock-string-face)))
'font-lock-string-face))
;; Else comment. If it's from syntax table, use default face.
((or (eq 'syntax-table (nth 7 state))
Expand Down
42 changes: 21 additions & 21 deletions tests/haskell-font-lock-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,18 @@ if all of its characters have syntax and face. See
(check-properties
'("[qq| \\|] Cons")
'(("qq" "w" nil)
("\\" "." font-lock-string-face)
("\\" "." (haskell-quasi-quote-face font-lock-string-face))
("Cons" "w" haskell-constructor-face))))

(ert-deftest haskell-syntactic-quasiquote-three-punctuation ()
"Check string escape vs comment escape"
(check-properties
'("[qq| %\\|] Cons")
'(("qq" "w" nil)
("%\\" "." font-lock-string-face)
("%\\" "." (haskell-quasi-quote-face font-lock-string-face))
("Cons" "w" haskell-constructor-face))))

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

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

Expand All @@ -372,41 +372,41 @@ if all of its characters have syntax and face. See
" finishing line"
"|] Cons")
'(("[" t nil)
("|" t font-lock-string-face)
("string" t font-lock-string-face)
("line" t font-lock-string-face)
("|" t font-lock-string-face)
("|" t (haskell-quasi-quote-face font-lock-string-face))
("string" t (haskell-quasi-quote-face font-lock-string-face))
("line" t (haskell-quasi-quote-face font-lock-string-face))
("|" t (haskell-quasi-quote-face font-lock-string-face))
("]" t nil)
("Cons" "w" haskell-constructor-face))))

(ert-deftest haskell-syntactic-test-quasiquoter-2 ()
(ert-deftest haskell-syntactic-test-quasiquoter-3 ()
"QuasiQuote inside quasi quote"
(check-properties
'("v = [quoter| [inner| string {- -- |] Outside |]")
'(("[" t nil)
("|" t font-lock-string-face)
("inner" t font-lock-string-face)
("string" t font-lock-string-face)
("|" t font-lock-string-face)
("|" t (haskell-quasi-quote-face font-lock-string-face))
("inner" t (haskell-quasi-quote-face font-lock-string-face))
("string" t (haskell-quasi-quote-face font-lock-string-face))
("|" t (haskell-quasi-quote-face font-lock-string-face))
("]" t nil)
("Outside" "w" haskell-constructor-face)
)))

(ert-deftest haskell-syntactic-test-quasiquoter-3 ()
(ert-deftest haskell-syntactic-test-quasiquoter-4 ()
"QuasiQuote inside comment"
(check-properties
'("v = -- [quoter| "
" [inner| string {- -- |] Outside1 |] Outside2")
'(("quoter" t font-lock-comment-face)
("inner" t nil)
("string" t font-lock-string-face)
("|" t font-lock-string-face)
("string" t (haskell-quasi-quote-face font-lock-string-face))
("|" t (haskell-quasi-quote-face font-lock-string-face))
("]" t nil)
("Outside1" "w" haskell-constructor-face)
("Outside2" "w" haskell-constructor-face)
)))

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

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