branch: elpa/nix-mode
commit aa1fa07344271b8bca1ec259d041d1a106329417
Author: Matthew Bauer <[email protected]>
Commit: Matthew Bauer <[email protected]>
Fix handling of keywords in identifiers
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.
---
nix-mode.el | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/nix-mode.el b/nix-mode.el
index 4fa219ce14..b1a263465a 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -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)