branch: elpa/nix-mode
commit 5a291127640c967364aeda8c798e17d48c7559f2
Author: Matthew Bauer <[email protected]>
Commit: Matthew Bauer <[email protected]>
Add function for escaped antiquote.
This function detects when it's right to ignore or use the ''${ as an
antiquote.
---
nix-mode.el | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/nix-mode.el b/nix-mode.el
index 58148de03f..d995504b4b 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -135,6 +135,26 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(put-text-property start (1+ start)
'nix-syntax-antiquote t)))))
+(defun nix-syntax-propertize-escaped-antiquote ()
+ "Set syntax properties for escaped antiquote."
+ (let* ((start (match-beginning 0))
+ (context (save-excursion (save-match-data (syntax-ppss start))))
+ (string-type (nth 3 context)))
+
+ ;; treat like multiline when not already in string
+ ;; else ignore
+ (when (not string-type)
+ (put-text-property start (1+ start)
+ 'syntax-table (string-to-syntax "|"))
+
+ (when (string= (buffer-substring (+ 2 start) (+ 4 start)) "${")
+ (put-text-property (+ 2 start) (+ 3 start)
+ 'syntax-table (string-to-syntax "|"))
+ (put-text-property (+ 2 start) (+ 4 start)
+ 'nix-syntax-antiquote t))
+ )
+ ))
+
(defun nix-syntax-propertize (start end)
"Special syntax properties for Nix from START to END."
;; search for multi-line string delimiters
@@ -143,7 +163,7 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(funcall
(syntax-propertize-rules
("''['\\$\]" ;; ignore ''* characters
- (0 (ignore (lambda () nil))))
+ (0 (ignore (nix-syntax-propertize-escaped-antiquote))))
("''"
(0 (ignore (nix-syntax-propertize-multiline-string))))
("\\${"