Skip to content

Commit

Permalink
Fix handling of keywords in identifiers
Browse files Browse the repository at this point in the history
This case shouldn’t be highlighted. For instance:

  python-with-my-packages

Need to look ahead and behind keywords to make sure they are not used
in attribute names.
  • Loading branch information
matthewbauer committed Jun 26, 2019
1 parent 2f4bd0f commit aa1fa07
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions nix-mode.el
Expand Up @@ -128,10 +128,19 @@ very large Nix files (all-packages.nix)."

(defconst nix-re-comments "#\\|/*\\|*/")

(defun nix-re-keywords (keywords)
"Produce a regexp matching some keywords of Nix.
KEYWORDS a list of strings to match as Nix keywords."
(concat
"\\(?:[[:space:]]\\|^\\)"
(regexp-opt keywords t)
"\\(?:[[:space:]]\\|$\\)"
))

(defconst nix-font-lock-keywords
`((,(regexp-opt nix-keywords 'symbols) 0 'nix-keyword-face)
(,(regexp-opt nix-warning-keywords 'symbols) 0 'nix-keyword-warning-face)
(,(regexp-opt nix-builtins 'symbols) 0 'nix-builtin-face)
`((,(nix-re-keywords nix-keywords) 1 'nix-keyword-face)
(,(nix-re-keywords nix-warning-keywords) 1 'nix-keyword-warning-face)
(,(nix-re-keywords nix-builtins) 1 'nix-builtin-face)
(,nix-re-url 0 'nix-constant-face)
(,nix-re-file-path 0 'nix-constant-face)
(,nix-re-variable-assign 1 'nix-attribute-face)
Expand Down

0 comments on commit aa1fa07

Please sign in to comment.