From 215acda7cd1e6aa2c991616c55fc1b422f8d217b Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sat, 14 Mar 2015 17:43:28 +0100 Subject: [PATCH 1/3] Remove haskell-font-lock-seen-haddock. Haddock comments are more popular these days than they used to be so we can take their presence for granted. --- haskell-font-lock.el | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/haskell-font-lock.el b/haskell-font-lock.el index 8e6f29e0d..b74b4d4a6 100644 --- a/haskell-font-lock.el +++ b/haskell-font-lock.el @@ -504,9 +504,6 @@ that should be commented under LaTeX-style literate scripts." :type 'boolean :group 'haskell) -(defvar haskell-font-lock-seen-haddock nil) -(make-variable-buffer-local 'haskell-font-lock-seen-haddock) - (defun haskell-syntactic-face-function (state) "`font-lock-syntactic-face-function' for Haskell." (cond @@ -539,8 +536,7 @@ that should be commented under LaTeX-style literate scripts." (save-excursion (goto-char (nth 8 state)) (or (looking-at "\\(?:{- ?\\|-- \\)[|^*$]") - (and haskell-font-lock-seen-haddock - (looking-at "--") + (and (looking-at "--") (let ((doc nil) pos) (while (and (not doc) @@ -550,7 +546,6 @@ that should be commented under LaTeX-style literate scripts." (looking-at "--\\([ \\t]*[|^*]\\)?")) (setq doc (match-beginning 1))) doc))))) - (setq haskell-font-lock-seen-haddock t) font-lock-doc-face) (t font-lock-comment-face))) From 195cfbbd2fe692bf5388570bd31dda683bc38eea Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sat, 14 Mar 2015 17:45:50 +0100 Subject: [PATCH 2/3] Set haskell-font-lock-haddock permamently. --- haskell-font-lock.el | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/haskell-font-lock.el b/haskell-font-lock.el index b74b4d4a6..70d14e56c 100644 --- a/haskell-font-lock.el +++ b/haskell-font-lock.el @@ -499,11 +499,6 @@ that should be commented under LaTeX-style literate scripts." ("^\\(\\\\\\)end{code}$" 1 "!")) haskell-basic-syntactic-keywords)) -(defcustom haskell-font-lock-haddock (boundp 'font-lock-doc-face) - "If non-nil try to highlight Haddock comments specially." - :type 'boolean - :group 'haskell) - (defun haskell-syntactic-face-function (state) "`font-lock-syntactic-face-function' for Haskell." (cond @@ -532,20 +527,19 @@ that should be commented under LaTeX-style literate scripts." ;; And then there are also haddock section headers that start with ;; any number of stars: ;; -- * ... - ((and haskell-font-lock-haddock - (save-excursion - (goto-char (nth 8 state)) - (or (looking-at "\\(?:{- ?\\|-- \\)[|^*$]") - (and (looking-at "--") - (let ((doc nil) - pos) - (while (and (not doc) - (setq pos (line-beginning-position)) - (forward-comment -1) - (eq (line-beginning-position 2) pos) - (looking-at "--\\([ \\t]*[|^*]\\)?")) - (setq doc (match-beginning 1))) - doc))))) + ((save-excursion + (goto-char (nth 8 state)) + (or (looking-at "\\(?:{- ?\\|-- \\)[|^*$]") + (and (looking-at "--") + (let ((doc nil) + pos) + (while (and (not doc) + (setq pos (line-beginning-position)) + (forward-comment -1) + (eq (line-beginning-position 2) pos) + (looking-at "--\\([ \\t]*[|^*]\\)?")) + (setq doc (match-beginning 1))) + doc)))) font-lock-doc-face) (t font-lock-comment-face))) From 4f6cd960885d4847a4cbbb5804f3ab3957ab12a4 Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Sat, 14 Mar 2015 18:30:19 +0100 Subject: [PATCH 3/3] Simplify haddock font lock. --- haskell-font-lock.el | 46 +++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/haskell-font-lock.el b/haskell-font-lock.el index 70d14e56c..75be027b5 100644 --- a/haskell-font-lock.el +++ b/haskell-font-lock.el @@ -508,38 +508,28 @@ 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) - ;; Try and recognize Haddock comments. From what I gather from its - ;; documentation, its comments can take the following forms: - ;; a) {-| ... -} - ;; b) {-^ ... -} - ;; c) -- | ... - ;; d) -- ^ ... - ;; e) -- ... - ;; Where `e' is the tricky one: it is only a Haddock comment if it - ;; follows immediately another Haddock comment. Even an empty line - ;; breaks such a sequence of Haddock comments. It is not clear if `e' - ;; can follow any other case, so I interpreted it as following only cases - ;; c,d,e (not a or b). In any case, this `e' is expensive since it - ;; requires extra work for each and every non-Haddock comment, so I only - ;; go through the more expensive check if we've already seen a Haddock - ;; comment in the buffer. + ;; Haddock comment start with either "-- [|^*$]" or "{- ?[|^*$]" + ;; (note space optional for nested comments and mandatory for + ;; double dash comments). ;; - ;; And then there are also haddock section headers that start with - ;; any number of stars: - ;; -- * ... + ;; Haddock comment will also continue on next line, provided: + ;; - current line is a double dash haddock comment + ;; - next line is also double dash comment + ;; - there is only whitespace between + ;; + ;; We recognize double dash haddock comments by property + ;; 'font-lock-doc-face attached to newline. In case of bounded + ;; comments newline is outside of comment. ((save-excursion (goto-char (nth 8 state)) (or (looking-at "\\(?:{- ?\\|-- \\)[|^*$]") - (and (looking-at "--") - (let ((doc nil) - pos) - (while (and (not doc) - (setq pos (line-beginning-position)) - (forward-comment -1) - (eq (line-beginning-position 2) pos) - (looking-at "--\\([ \\t]*[|^*]\\)?")) - (setq doc (match-beginning 1))) - doc)))) + (and (looking-at "--") ; 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 + (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)))