Skip to content

Cleanup pragma font lock {-# .. #-} #514

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 2 commits into from
Mar 20, 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
35 changes: 11 additions & 24 deletions haskell-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ This is the case if the \".\" is part of a \"forall <tvar> . <type>\"."
:group 'haskell)

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

Expand Down Expand Up @@ -236,26 +236,6 @@ Regexp match data 0 points to the chars."
;; no face. So force evaluation by using `keep'.
keep)))))

(defun haskell-font-lock-find-pragma (end)
(catch 'haskell-font-lock-find-pragma
(while (search-forward "{-#" end t)
(let* ((begin (match-beginning 0))
(ppss (save-excursion (syntax-ppss begin))))
;; We're interested only when it's not in a string or a comment.
(unless (or (nth 3 ppss)
(nth 4 ppss))
;; Find the end of the pragma.
(let ((end (scan-lists begin 1 0)))
;; Match data contains only the opening {-#, update it to cover the
;; whole pragma.
(set-match-data (list begin end))
;; Move to the end so we don't start the next scan from inside the
;; pragma we just found.
(goto-char end)
(throw 'haskell-font-lock-find-pragma t)))))
;; Found no pragma.
nil))

;; The font lock regular expressions.
(defun haskell-font-lock-keywords-create (literate)
"Create fontification definitions for Haskell scripts.
Expand Down Expand Up @@ -400,9 +380,7 @@ Returns keywords suitable for `font-lock-keywords'."
;; Very expensive.
(,sym 0 (if (eq (char-after (match-beginning 0)) ?:)
haskell-constructor-face
haskell-operator-face))

(haskell-font-lock-find-pragma 0 haskell-pragma-face t)))
haskell-operator-face))))
(unless (boundp 'font-lock-syntactic-keywords)
(cl-case literate
(bird
Expand Down Expand Up @@ -508,6 +486,15 @@ that should be commented under LaTeX-style literate scripts."
(and (eq haskell-literate 'bird)
(memq (char-before (nth 8 state)) '(nil ?\n))))
haskell-literate-comment-face)
;; Detect pragmas. A pragma is enclosed in special comment
;; delimeters {-# .. #-}.
((save-excursion
(goto-char (nth 8 state))
(and (looking-at "{-#")
(forward-comment 1)
(goto-char (- (point) 3))
(looking-at "#-}")))
haskell-pragma-face)
;; Haddock comment start with either "-- [|^*$]" or "{- ?[|^*$]"
;; (note space optional for nested comments and mandatory for
;; double dash comments).
Expand Down