Skip to content

Commit

Permalink
Don't highlight top-level-only keywords at different levels
Browse files Browse the repository at this point in the history
The keywords being modified here only represented keywords when they
are at the beginning of a line with optional indentation.

At different levels these would represent valid record fields or other
identifiers.

This was tested by adding the following code to a PureScript file:

    type Foo = { type :: Int
               , module :: Int
               , import :: Int
               , data :: Int
               , class :: Int
               , newtype :: Int
               }

…and checking that compilation succeeds.
  • Loading branch information
Hi-Angel committed Oct 15, 2024
1 parent d187b3d commit ba3e997
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions purescript-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,22 @@ Returns keywords suitable for `font-lock-keywords'."
;; "@" "~" "=>") t)
"\\(->\\|\\.\\.\\|::\\|∷\\|<-\\|=>\\|[=@\\|~]\\)"
"\\S_"))
;; These are only keywords when appear at top-level, optionally with
;; indentation. They are not reserved and in other levels would represent
;; record fields or other identifiers.
(toplevel-keywords
(rx line-start (zero-or-more whitespace)
(group (or "type" "module" "import" "data" "class" "newtype"
"instance")
word-end)))
;; Reserved identifiers
(reservedid
;; `as', `hiding', and `qualified' are part of the import
;; spec syntax, but they are not reserved.
;; `_' can go in here since it has temporary word syntax.
(regexp-opt
'("ado" "case" "class" "data" "default" "deriving"
"do" "else" "if" "import" "in" "infix" "infixl"
"infixr" "instance" "let" "module" "newtype" "of"
"then" "type" "where" "_") 'words))
'("ado" "case" "default" "deriving" "do" "else" "if" "in" "infix"
"infixl" "infixr" "let" "of" "then" "where" "_") 'words))

;; Top-level declarations
(topdecl-var
Expand Down Expand Up @@ -210,6 +216,7 @@ Returns keywords suitable for `font-lock-keywords'."
("^>>>>>>> .*$" 0 'font-lock-warning-face t)
("^#.*$" 0 'font-lock-preprocessor-face t)

(,toplevel-keywords 1 (symbol-value 'purescript-keyword-face))
(,reservedid 1 (symbol-value 'purescript-keyword-face))
(,reservedsym 1 (symbol-value 'purescript-operator-face))
;; Special case for `as', `hiding', `safe' and `qualified', which are
Expand Down

0 comments on commit ba3e997

Please sign in to comment.