branch: elpa/nix-mode
commit c577957d668ea9513cc1cafc911ef6789d9fcb14
Merge: bf027132d0 8118a807a7
Author: Matthew Bauer <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #85 from NixOS/fix-84
Fix handling of keywords in identifiers
---
.gitignore | 4 +++-
Makefile | 7 ++++---
nix-mode.el | 15 ++++++++++++---
tests/nix-font-lock-tests.el | 10 ++++++++--
4 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/.gitignore b/.gitignore
index bfc379fa2f..04e5e875c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,6 @@ result
*.info
*.tex
*.pdf
-auto/
\ No newline at end of file
+auto/
+
+AUTHORS.md
diff --git a/Makefile b/Makefile
index c111c1f3ce..3f3b0c24f1 100644
--- a/Makefile
+++ b/Makefile
@@ -6,15 +6,16 @@ ELS = nix.el nix-company.el nix-drv-mode.el nix-format.el \
nix-shell.el nix-store.el
ELCS = $(ELS:.el=.elc)
+TESTS = tests/nix-mode-tests.el tests/nix-font-lock-tests.el
+
DESTDIR =
PREFIX = /usr
all: $(ELCS) nix-mode.info nix-mode.html AUTHORS.md
-check:
+check: $(TESTS) $(ELCS)
emacs -batch -L . \
- -l tests/nix-mode-tests.el \
- -l tests/nix-font-lock-tests.el \
+ $(foreach test,$(TESTS),-l $(test)) \
-f ert-run-tests-batch-and-exit
install: $(ELCS) nix-mode.info nix-mode.html AUTHORS.md
diff --git a/nix-mode.el b/nix-mode.el
index 6e354cc19e..e1dba6c1c9 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)
diff --git a/tests/nix-font-lock-tests.el b/tests/nix-font-lock-tests.el
index 1ec0008b6a..5abdb5744f 100644
--- a/tests/nix-font-lock-tests.el
+++ b/tests/nix-font-lock-tests.el
@@ -40,7 +40,7 @@ after a test as this aids interactive debugging."
(defun check-properties (lines-or-contents props &optional mode)
"Check if syntax properties and font-lock properties as set properly.
LINES is a list of strings that will be inserted to a new
-buffer. Then PROPS is a list of tripples of (string syntax
+buffer. Then PROPS is a list of triples of (string syntax
face). String is searched for in the buffer and then is checked
if all of its characters have syntax and face. See
`check-syntax-and-face-match-range`."
@@ -64,7 +64,6 @@ if all of its characters have syntax and face. See
(search-forward string))
(check-syntax-and-face-match-range
(match-beginning 0) (match-end 0) syntax face)))))
-
(ert-deftest nix-equals-1 ()
(check-properties
'("pattern = 3")
@@ -75,6 +74,13 @@ if all of its characters have syntax and face. See
'("pattern == 3")
'(("pattern" t nil))))
+(ert-deftest nix-issue-84 ()
+ (check-properties
+ '("{ with-a ? {let-in=1; } , ... }:with with-a; { foo = \"bar\"; }")
+ '(("let-in" t nix-attribute-face)
+ ("with" t nix-keyword-face)
+ ("foo" t nix-attribute-face))))
+
;; Local Variables:
;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
;; End: