Skip to content

Use faces directly. #583

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
Apr 18, 2015
Merged
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
91 changes: 41 additions & 50 deletions haskell-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,56 +86,47 @@ This is the case if the \".\" is part of a \"forall <tvar> . <type>\"."
(line-beginning-position) t)))

(defface haskell-keyword-face
'((t :inherit font-lock-keyword-face))
'((t :inherit 'font-lock-keyword-face))
"Face used to highlight Haskell keywords."
:group 'haskell)

(defface haskell-constructor-face
'((t :inherit font-lock-type-face))
'((t :inherit 'font-lock-type-face))
"Face used to highlight Haskell constructors."
:group 'haskell)

;; This used to be `font-lock-variable-name-face' but it doesn't result in
;; a highlighting that's consistent with other modes (it's mostly used
;; for function defintions).
(defface haskell-definition-face
'((t :inherit font-lock-function-name-face))
'((t :inherit 'font-lock-function-name-face))
"Face used to highlight Haskell definitions."
:group 'haskell)

;; This is probably just wrong, but it used to use
;; `font-lock-function-name-face' with a result that was not consistent with
;; other major modes, so I just exchanged with `haskell-definition-face'.
(defface haskell-operator-face
'((t :inherit font-lock-variable-name-face))
'((t :inherit 'font-lock-variable-name-face))
"Face used to highlight Haskell operators."
:group 'haskell)

(defface haskell-pragma-face
'((t :inherit font-lock-preprocessor-face))
'((t :inherit 'font-lock-preprocessor-face))
"Face used to highlight Haskell pragmas."
:group 'haskell)

(defface haskell-default-face
'((t :inherit default))
'((t :inherit 'default))
"Face used to highlight ordinary Haskell code."
:group 'haskell)

(defface haskell-literate-comment-face
'((t :inherit font-lock-doc-face))
'((t :inherit 'font-lock-doc-face))
"Face with which to fontify literate comments.
Inherit from `default' to avoid fontification of them."
:group 'haskell)

;; These variables exist only for backward compatibility.
(defvar haskell-keyword-face 'haskell-keyword-face)
(defvar haskell-constructor-face 'haskell-constructor-face)
(defvar haskell-definition-face 'haskell-definition-face)
(defvar haskell-operator-face 'haskell-operator-face)
(defvar haskell-pragma-face 'haskell-pragma-face)
(defvar haskell-default-face 'haskell-default-face)
(defvar haskell-literate-comment-face 'haskell-literate-comment-face)

(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 @@ -234,55 +225,55 @@ Returns keywords suitable for `font-lock-keywords'."

,@(haskell-font-lock-symbols-keywords)

(,reservedid 1 haskell-keyword-face)
(,reservedid 1 'haskell-keyword-face)

;; Special case for `as', `hiding', `safe' and `qualified', which are
;; keywords in import statements but are not otherwise reserved.
("\\<import[ \t]+\\(?:\\(safe\\>\\)[ \t]*\\)?\\(?:\\(qualified\\>\\)[ \t]*\\)?\\(?:\"[^\"]*\"[\t ]*\\)?[^ \t\n()]+[ \t]*\\(?:\\(\\<as\\>\\)[ \t]*[^ \t\n()]+[ \t]*\\)?\\(\\<hiding\\>\\)?"
(1 haskell-keyword-face nil lax)
(2 haskell-keyword-face nil lax)
(3 haskell-keyword-face nil lax)
(4 haskell-keyword-face nil lax))
(1 'haskell-keyword-face nil lax)
(2 'haskell-keyword-face nil lax)
(3 'haskell-keyword-face nil lax)
(4 'haskell-keyword-face nil lax))

;; Special case for `foreign import'
;; keywords in foreign import statements but are not otherwise reserved.
("\\<\\(foreign\\)[ \t]+\\(import\\)[ \t]+\\(?:\\(ccall\\|stdcall\\|cplusplus\\|jvm\\|dotnet\\)[ \t]+\\)?\\(?:\\(safe\\|unsafe\\|interruptible\\)[ \t]+\\)?"
(1 haskell-keyword-face nil lax)
(2 haskell-keyword-face nil lax)
(3 haskell-keyword-face nil lax)
(4 haskell-keyword-face nil lax))
(1 'haskell-keyword-face nil lax)
(2 'haskell-keyword-face nil lax)
(3 'haskell-keyword-face nil lax)
(4 'haskell-keyword-face nil lax))

;; Special case for `foreign export'
;; keywords in foreign export statements but are not otherwise reserved.
("\\<\\(foreign\\)[ \t]+\\(export\\)[ \t]+\\(?:\\(ccall\\|stdcall\\|cplusplus\\|jvm\\|dotnet\\)[ \t]+\\)?"
(1 haskell-keyword-face nil lax)
(2 haskell-keyword-face nil lax)
(3 haskell-keyword-face nil lax))
(1 'haskell-keyword-face nil lax)
(2 'haskell-keyword-face nil lax)
(3 'haskell-keyword-face nil lax))

;; Toplevel Declarations.
;; Place them *before* generic id-and-op highlighting.
(,topdecl-var (1 haskell-definition-face))
(,topdecl-var2 (2 haskell-definition-face))
(,topdecl-bangpat (1 haskell-definition-face))
(,topdecl-sym (2 haskell-definition-face))
(,topdecl-sym2 (1 haskell-definition-face))
(,topdecl-var (1 'haskell-definition-face))
(,topdecl-var2 (2 'haskell-definition-face))
(,topdecl-bangpat (1 'haskell-definition-face))
(,topdecl-sym (2 'haskell-definition-face))
(,topdecl-sym2 (1 'haskell-definition-face))

;; These four are debatable...
("(\\(,*\\|->\\))" 0 haskell-constructor-face)
("\\[\\]" 0 haskell-constructor-face)
("(\\(,*\\|->\\))" 0 'haskell-constructor-face)
("\\[\\]" 0 'haskell-constructor-face)

(,(concat "`" varid "`") 0 haskell-operator-face)
(,(concat "`" conid "`") 0 haskell-operator-face)
(,(concat "`" qvarid "`") 0 haskell-operator-face)
(,(concat "`" qconid "`") 0 haskell-operator-face)
(,qvarid 0 haskell-default-face)
(,qconid 0 haskell-constructor-face)
(,(concat "`" varid "`") 0 'haskell-operator-face)
(,(concat "`" conid "`") 0 'haskell-operator-face)
(,(concat "`" qvarid "`") 0 'haskell-operator-face)
(,(concat "`" qconid "`") 0 'haskell-operator-face)
(,qvarid 0 'haskell-default-face)
(,qconid 0 'haskell-constructor-face)

(,conid 0 haskell-constructor-face)
(,conid 0 'haskell-constructor-face)

(,sym 0 (if (eq (char-after (match-beginning 0)) ?:)
haskell-constructor-face
haskell-operator-face))))
'haskell-constructor-face
'haskell-operator-face))))
keywords))

(defvar haskell-font-lock-latex-cache-pos nil
Expand Down Expand Up @@ -382,12 +373,12 @@ that should be commented under LaTeX-style literate scripts."
(defun haskell-syntactic-face-function (state)
"`font-lock-syntactic-face-function' for Haskell."
(cond
((nth 3 state) font-lock-string-face) ; as normal
((nth 3 state) 'font-lock-string-face) ; as normal
;; Else comment. If it's from syntax table, use default face.
((or (eq 'syntax-table (nth 7 state))
(and (eq haskell-literate 'bird)
(memq (char-before (nth 8 state)) '(nil ?\n))))
haskell-literate-comment-face)
'haskell-literate-comment-face)
;; Detect pragmas. A pragma is enclosed in special comment
;; delimeters {-# .. #-}.
((save-excursion
Expand All @@ -396,7 +387,7 @@ that should be commented under LaTeX-style literate scripts."
(forward-comment 1)
(goto-char (- (point) 3))
(looking-at-p "#-}")))
haskell-pragma-face)
'haskell-pragma-face)
;; Haddock comment start with either "-- [|^*$]" or "{- ?[|^*$]"
;; (note space optional for nested comments and mandatory for
;; double dash comments).
Expand All @@ -415,12 +406,12 @@ that should be commented under LaTeX-style literate scripts."
(and (looking-at-p "--") ; are we at double dash comment
(forward-line -1) ; this is nil on first line
(eq (get-text-property (line-end-position) 'face)
font-lock-doc-face) ; is a doc face
'font-lock-doc-face) ; is a doc face
(forward-line)
(skip-syntax-forward "-") ; see if there is only whitespace
(eq (point) (nth 8 state))))) ; we are back in position
font-lock-doc-face)
(t font-lock-comment-face)))
'font-lock-doc-face)
(t 'font-lock-comment-face)))

(defconst haskell-font-lock-keywords
(haskell-font-lock-keywords-create nil)
Expand Down