emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/nix-mode e22819a73b 12/14: Merge pull request #157 from no


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode e22819a73b 12/14: Merge pull request #157 from nosewings/master
Date: Tue, 19 Jul 2022 01:58:49 -0400 (EDT)

branch: elpa/nix-mode
commit e22819a73bf4e2b71166992a0af2f555036cf634
Merge: 5d5704d846 7fbde25122
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #157 from nosewings/master
    
    Fix syntax highlighting for ''$ in indented strings
---
 nix-mode.el                  | 22 +++++++++++++++++++---
 tests/nix-font-lock-tests.el | 24 ++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 73bd4af794..59ca5a2101 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -244,9 +244,21 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
         (setq start (+ 2 start)))
       (when (equal (mod (- end start) 3) 2)
         (let ((str-peek (buffer-substring end (min (point-max) (+ 2 end)))))
-          (if (member str-peek '("${" "\\n" "\\r" "\\t"))
-              (goto-char (+ 2 end))
-            (nix--mark-string (1- end) ?\')))))))
+          (cond
+           ((member str-peek '("${" "\\n" "\\r" "\\t"))
+            (goto-char (+ 2 end)))
+           ((string-prefix-p "$" str-peek)
+            (goto-char (1+ end)))
+           (t
+            (nix--mark-string (1- end) ?\'))))))))
+
+(defun nix--escaped-dollar-sign-antiquote-sq-style ()
+  "Hande Nix escaped dollar sign antiquote sq style."
+  (let* ((start (match-beginning 0))
+         (ps (nix--get-parse-state start))
+        (string-type (nix--get-string-type ps)))
+    (when (equal string-type ?\")
+      (nix--antiquote-open-at (+ start 2) ?\"))))
 
 (defun nix--escaped-antiquote-dq-style ()
   "Handle Nix escaped antiquote dq style."
@@ -344,6 +356,10 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
      (0 nil))
     ("\\\\\""
      (0 nil))
+    ("\\$\\$"
+     (0 nil))
+    ("\\\\\\$\\${"
+     (0 (ignore (nix--escaped-dollar-sign-antiquote-sq-style))))
     ("\\\\\\${"
      (0 (ignore (nix--escaped-antiquote-dq-style))))
     ("'\\{2,\\}"
diff --git a/tests/nix-font-lock-tests.el b/tests/nix-font-lock-tests.el
index 5abdb5744f..619ee78f56 100644
--- a/tests/nix-font-lock-tests.el
+++ b/tests/nix-font-lock-tests.el
@@ -81,6 +81,30 @@ if all of its characters have syntax and face. See
      ("with" t nix-keyword-face)
      ("foo" t nix-attribute-face))))
 
+(ert-deftest nix-issue-157 ()
+  (check-properties
+   '("\"''$${x}")
+   '(("\"''$${x}" t font-lock-string-face)))
+  (check-properties
+   '("''''$${x}''")
+   '(("''''$" t font-lock-string-face)
+     ("${" t nix-antiquote-face)
+     ("}" t nix-antiquote-face)))
+  (check-properties
+   '("\"$${x}\"")
+   '(("\"$${x}\"" t font-lock-string-face)))
+  (check-properties
+   '("''$${x}''")
+   '(("''$${x}''" t font-lock-string-face)))
+  (check-properties
+   '("\"\\$${x}\"")
+   '(("\"\\$" t font-lock-string-face)
+     ("${" t nix-antiquote-face)
+     ("}" t nix-antiquote-face)))
+  (check-properties
+   '("''\\$${x}''")
+   '(("''\\$${x}''" t font-lock-string-face))))
+
 ;; Local Variables:
 ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
 ;; End:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]