branch: elpa/nix-mode
commit 66cc5478de3555a185eb60ba2c500ecef7fa46bd
Merge: 68793d91c5 3e6fdd8311
Author: Matthew Justin Bauer <[email protected]>
Commit: GitHub <[email protected]>

    Merge branch 'master' into separate-files
---
 nix-mode.el | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 8f5a53db29..b8d2469ee6 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -25,10 +25,28 @@
     `(set (make-local-variable ',var) ,val)))
 
 (require 'nix-format)
-(require 'nix-repl)
 
 ;;; Syntax coloring
 
+(defun nix-syntax-match-antiquote (limit)
+  "Find antiquote within a Nix expression up to LIMIT."
+  (let ((pos (next-single-char-property-change (point) 'nix-syntax-antiquote
+                                               nil limit)))
+    (when (and pos (> pos (point)) (< pos (point-max)))
+      (goto-char pos)
+      (let ((char (char-after pos)))
+        (pcase char
+          (`?{
+           (forward-char 1)
+           (set-match-data (list (1- pos) (point)))
+           t)
+          (`?}
+           (forward-char 1)
+           (set-match-data (list pos (point)))
+           t))
+        )
+      )))
+
 (defconst nix-keywords
   '("if" "then"
     "else" "with"
@@ -68,9 +86,13 @@
     (,nix-re-url . font-lock-constant-face)
     (,nix-re-file-path . font-lock-constant-face)
     (,nix-re-variable-assign 1 font-lock-variable-name-face)
-    (,nix-re-bracket-path . font-lock-constant-face))
+    (,nix-re-bracket-path . font-lock-constant-face)
+    (nix-syntax-match-antiquote 0 font-lock-preprocessor-face t)
+    )
   "Font lock keywords for nix.")
 
+(makunbound 'nix-mode-syntax-table)
+
 (defvar nix-mode-syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?/ ". 14" table)
@@ -114,6 +136,7 @@
          (string-type (nix--get-string-type context)))
     (unless (or (equal string-type ?\")
                 (and (equal string-type nil)
+                     (< 1 start)
                      (string-match-p nix--variable-char
                                      (buffer-substring (1- start) start))))
       (when (equal string-type nil)
@@ -395,9 +418,9 @@
 (nix-create-keymap)
 (nix-create-menu)
 
-(when (featurep 'flycheck) (require 'nix-flycheck))
+(when (featurep 'flycheck) (require 'nix-flycheck nil 'noerror))
 
-(when (require 'company nil 'noerror) (require 'nix-company))
+(when (require 'company nil 'noerror) (require 'nix-company nil 'noerror))
 
 ;;;###autoload
 (define-derived-mode nix-mode prog-mode "Nix"

Reply via email to