Skip to content

Pr font lock 1 #451

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 3 commits into from
Jan 24, 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
38 changes: 13 additions & 25 deletions haskell-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ Inherit from `default' to avoid fontification of them."
(defvar haskell-default-face 'haskell-default-face)
(defvar haskell-literate-comment-face 'haskell-literate-comment-face)

(defconst haskell-emacs21-features (string-match "[[:alpha:]]" "x")
"Non-nil if we have regexp char classes.
Assume this means we have other useful features from Emacs 21.")

(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 @@ -379,15 +375,7 @@ Returns keywords suitable for `font-lock-keywords'."
("^=======" 0 'font-lock-warning-face t)
("^>>>>>>> .*$" 0 'font-lock-warning-face t)
("^#.*$" 0 'font-lock-preprocessor-face t)
,@(unless haskell-emacs21-features ;Supports nested comments?
;; Expensive.
`((,string-and-char 1 font-lock-string-face)))

;; This was originally at the very end (and needs to be after
;; all the comment/string/doc highlighting) but it seemed to
;; trigger a bug in Emacs-21.3 which caused the compositions to
;; be "randomly" dropped. Moving it earlier seemed to reduce
;; the occurrence of the bug.

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

(,reservedid 1 haskell-keyword-face)
Expand Down Expand Up @@ -453,37 +441,37 @@ Returns keywords suitable for `font-lock-keywords'."
("^>" 0 haskell-default-face t))))
((latex tex)
(setq keywords
`((haskell-fl-latex-comments 0 'font-lock-comment-face t)
`((haskell-font-lock-latex-comments 0 'font-lock-comment-face t)
,@keywords)))))
keywords))

;; The next three aren't used in Emacs 21.

(defvar haskell-fl-latex-cache-pos nil
"Position of cache point used by `haskell-fl-latex-cache-in-comment'.
(defvar haskell-font-lock-latex-cache-pos nil
"Position of cache point used by `haskell-font-lock-latex-cache-in-comment'.
Should be at the start of a line.")
(make-variable-buffer-local 'haskell-font-lock-latex-cache-pos)

(defvar haskell-fl-latex-cache-in-comment nil
"If `haskell-fl-latex-cache-pos' is outside a
(defvar haskell-font-lock-latex-cache-in-comment nil
"If `haskell-font-lock-latex-cache-pos' is outside a
\\begin{code}..\\end{code} block (and therefore inside a comment),
this variable is set to t, otherwise nil.")
(make-variable-buffer-local 'haskell-font-lock-latex-cache-in-comment)

(defun haskell-fl-latex-comments (end)
(defun haskell-font-lock-latex-comments (end)
"Sets `match-data' according to the region of the buffer before end
that should be commented under LaTeX-style literate scripts."
(let ((start (point)))
(if (= start end)
;; We're at the end. No more to fontify.
nil
(if (not (eq start haskell-fl-latex-cache-pos))
(if (not (eq start haskell-font-lock-latex-cache-pos))
;; If the start position is not cached, calculate the state
;; of the start.
(progn
(setq haskell-fl-latex-cache-pos start)
(setq haskell-font-lock-latex-cache-pos start)
;; If the previous \begin{code} or \end{code} is a
;; \begin{code}, then start is not in a comment, otherwise
;; it is in a comment.
(setq haskell-fl-latex-cache-in-comment
(setq haskell-font-lock-latex-cache-in-comment
(if (and
(re-search-backward
"^\\(\\(\\\\begin{code}\\)\\|\\(\\\\end{code}\\)\\)$"
Expand All @@ -492,7 +480,7 @@ that should be commented under LaTeX-style literate scripts."
nil t))
;; Restore position.
(goto-char start)))
(if haskell-fl-latex-cache-in-comment
(if haskell-font-lock-latex-cache-in-comment
(progn
;; If start is inside a comment, search for next \begin{code}.
(re-search-forward "^\\\\begin{code}$" end 'move)
Expand Down