[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode 2879253 029/104: Don't let backslashes escape new
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode 2879253 029/104: Don't let backslashes escape newlines in multiline strings |
Date: |
Sun, 29 Aug 2021 11:36:57 -0400 (EDT) |
branch: elpa/zig-mode
commit 2879253d906d6b888a3e76e77fc344f6b1d5b2fb
Author: Matthew D. Steele <mdsteele@alum.mit.edu>
Commit: Matthew D. Steele <mdsteele@alum.mit.edu>
Don't let backslashes escape newlines in multiline strings
---
tests.el | 10 ++++++++++
zig-mode.el | 46 +++++++++++++++++++++++++++++++++++-----------
2 files changed, 45 insertions(+), 11 deletions(-)
diff --git a/tests.el b/tests.el
index 2f81db3..f5f7fb2 100644
--- a/tests.el
+++ b/tests.el
@@ -31,6 +31,16 @@
("escaped" font-lock-variable-name-face)
("'\\''" font-lock-string-face))))
+(ert-deftest test-font-lock-backslash-in-multiline-str-literal ()
+ (zig-test-font-lock
+ "
+const string =
+ \\\\ This newline is NOT escaped \\
+;"
+ '(("const" font-lock-keyword-face)
+ ("string" font-lock-variable-name-face)
+ ("\\\\ This newline is NOT escaped \\\n" zig-multiline-string-face))))
+
(ert-deftest test-font-lock-backslash-in-str-literal ()
(zig-test-font-lock
"\"This quote \\\" is escaped\""
diff --git a/zig-mode.el b/zig-mode.el
index 36bd031..2a3a737 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -192,26 +192,50 @@
(indent-line-to indent-col)
(save-excursion (indent-line-to indent-col)))))
-(defun zig-syntax-propertize-newline-if-in-multiline-str (end)
- (when (and (zig-currently-in-str)
- (save-excursion
- (goto-char (zig-start-of-current-str-or-comment))
- (looking-at "\\\\\\\\"))
- (re-search-forward "\n" end t))
- (put-text-property (match-beginning 0) (match-end 0)
- 'syntax-table (string-to-syntax "|"))
- (goto-char (match-end 0))))
+(defun zig-syntax-propertize-to-newline-if-in-multiline-str (end)
+ ;; First, we need to check if we're in a multiline string literal; if we're
+ ;; not, do nothing.
+ (when (zig-currently-in-str)
+ (let ((start (zig-start-of-current-str-or-comment)))
+ (when (save-excursion
+ (goto-char start)
+ (looking-at "\\\\\\\\"))
+ ;; At this point, we've determined that we're within a multiline string
+ ;; literal. Let `stop' be the position of the closing newline, or
+ ;; `end', whichever comes first.
+ (let ((stop (if (save-excursion
+ (goto-char start)
+ (re-search-forward "\n" end t))
+ (prog1 (match-end 0)
+ ;; We found the closing newline, so mark it as the
+ ;; end of this string literal.
+ (put-text-property (match-beginning 0)
+ (match-end 0)
+ 'syntax-table
+ (string-to-syntax "|")))
+ end)))
+ ;; Zig multiline string literals don't support escapes, so mark all
+ ;; backslashes (up to `stop') as punctation instead of escapes.
+ (save-excursion
+ (goto-char (+ 2 start))
+ (while (re-search-forward "\\\\" stop t)
+ (put-text-property (match-beginning 0) (match-end 0)
+ 'syntax-table (string-to-syntax "."))
+ (goto-char (match-end 0))))
+ ;; Move to the end of the string (or `end'), so that
+ ;; zig-syntax-propertize can pick up from there.
+ (goto-char stop))))))
(defun zig-syntax-propertize (start end)
(goto-char start)
- (zig-syntax-propertize-newline-if-in-multiline-str end)
+ (zig-syntax-propertize-to-newline-if-in-multiline-str end)
(funcall
(syntax-propertize-rules
;; Multiline strings
("\\(\\\\\\)\\\\"
(1 (prog1 "|"
(goto-char (match-end 0))
- (zig-syntax-propertize-newline-if-in-multiline-str end)))))
+ (zig-syntax-propertize-to-newline-if-in-multiline-str end)))))
(point) end))
(defun zig-mode-syntactic-face-function (state)
- [nongnu] elpa/zig-mode 68f3fc5 087/104: Update the required emacs version from 24 to 24.3, (continued)
- [nongnu] elpa/zig-mode 68f3fc5 087/104: Update the required emacs version from 24 to 24.3, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode d263591 090/104: Account for opening brace after newline, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 07efab0 095/104: Merge pull request #48 from noisegul/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b6abeb4 093/104: Add a defvar to define if user wants to return to buffer after fmt., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode df572da 099/104: Add opaque keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode acf3ee8 104/104: Add GitHub Actions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2842797 007/104: Fix builtins. Reorder tables., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e69ebc0 012/104: and, or, @panic., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9a252eb 016/104: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ad9f398 028/104: Add some font-lock tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2879253 029/104: Don't let backslashes escape newlines in multiline strings,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 4542a5d 036/104: add imenu support, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 604484c 039/104: M-x untabify, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 67ad48b 045/104: fix multiline string properties rules regex, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ab46e22 048/104: add some zig cli build commands, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode acebfb1 057/104: Add anyframe; remove promise, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fc7fde3 056/104: Merge pull request #23 from joachimschmidt557/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ad844c3 062/104: noasync -> nosuspend, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2c45c45 059/104: Merge pull request #24 from joachimschmidt557/add-anyframe, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 22187f4 076/104: Merge pull request #32 from joachimschmidt557/remove-this, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 8721255 079/104: Merge pull request #34 from jdpage/shell-quoting, ELPA Syncer, 2021/08/29