From ce884af073837af77619f28923ba43d37bffadab Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Mon, 4 Jan 2016 22:19:58 +0100 Subject: [PATCH] Make quasi quote more visible --- haskell-font-lock.el | 14 +++++++++-- tests/haskell-font-lock-tests.el | 42 ++++++++++++++++---------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/haskell-font-lock.el b/haskell-font-lock.el index 976273819..b5cc663e9 100644 --- a/haskell-font-lock.el +++ b/haskell-font-lock.el @@ -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." @@ -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)) diff --git a/tests/haskell-font-lock-tests.el b/tests/haskell-font-lock-tests.el index 40d64435b..4fa7d9bb6 100644 --- a/tests/haskell-font-lock-tests.el +++ b/tests/haskell-font-lock-tests.el @@ -248,7 +248,7 @@ 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 () @@ -256,10 +256,10 @@ 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-test-11 () +(ert-deftest haskell-syntactic-test-11a () "Syntax for haddock comments" (check-properties '(" -- | Dcom1" ; haddocks @@ -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. @@ -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)))) @@ -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 |]" @@ -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"