[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 5ed4675 171/486: Merge pull request #73 from Mic
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 5ed4675 171/486: Merge pull request #73 from MicahChalmer/raw-string-multiline-edit-fix |
Date: |
Sat, 7 Aug 2021 09:25:12 -0400 (EDT) |
branch: elpa/rust-mode
commit 5ed467549abe81415241b0ea45e2ae87584b588c
Merge: 86db9bd 9d773b4
Author: Felix S Klock II <pnkfelix@pnkfx.org>
Commit: Felix S Klock II <pnkfelix@pnkfx.org>
Merge pull request #73 from MicahChalmer/raw-string-multiline-edit-fix
Fix multi-line raw strings when editing
---
rust-mode-tests.el | 18 ++++++++++++++++++
rust-mode.el | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index bb40781..b40aed0 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1067,6 +1067,24 @@ this_is_not_a_string();)"
"r\" this is a comment\n" font-lock-comment-face
"\"this is a string\"" font-lock-string-face)))
+(ert-deftest font-lock-raw-string-constant ()
+ ;; There was an issue in which a multi-line raw string would be fontified
+ ;; correctly if inserted, but then incorrectly if one of the lines was then
+ ;; edited. This test replicates how font-lock responds when text in the
+ ;; buffer is modified in order to reproduce it.
+ (with-temp-buffer
+ (rust-mode)
+ (font-lock-fontify-buffer)
+ (insert "const BOO:&str = r#\"\nBOO\"#;")
+ (beginning-of-buffer)
+ (insert " ")
+ (font-lock-after-change-function 1 2 0)
+
+ (should (equal 'font-lock-string-face (get-text-property 19 'face))) ;;
Opening "r" of raw string
+ (should (equal 'font-lock-string-face (get-text-property 27 'face))) ;;
Closing "#" of raw string
+ (should (equal nil (get-text-property 28 'face))) ;; Semicolon--should not
be part of the string
+ ))
+
(ert-deftest indent-method-chains-no-align ()
(let ((rust-indent-method-chain nil)) (test-indent
"
diff --git a/rust-mode.el b/rust-mode.el
index 58df76d..c45d5c1 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -374,6 +374,43 @@
("fn" . font-lock-function-name-face)
("static" . font-lock-constant-face)))))
+(defun rust-extend-region-raw-string ()
+ "Extend the region given by `font-lock-beg' and `font-lock-end'
+ to include the beginning of a string if it includes part of it.
+ Adjusts to include the r[#] of a raw string as well."
+
+ (let* ((orig-beg font-lock-beg)
+ (orig-end font-lock-end)
+ (beg-ppss (syntax-ppss font-lock-beg))
+ (beg-in-str (nth 3 beg-ppss))
+ (end-ppss (syntax-ppss font-lock-end))
+ (end-in-str (nth 3 end-ppss)))
+
+ (when (and beg-in-str (> font-lock-beg (nth 8 beg-ppss)))
+ (setq font-lock-beg str-beg)
+ (while (equal ?# (char-before font-lock-beg))
+ (setq font-lock-beg (1- font-lock-beg)))
+ (when (equal ?r (char-before font-lock-beg))
+ (setq font-lock-beg (1- font-lock-beg))))
+
+ (when end-in-str
+ (save-excursion
+ (goto-char (nth 8 end-ppss))
+ (ignore-errors (forward-sexp))
+ (setq font-lock-end (max font-lock-end (point)))))
+
+ ;; If we have the beginning of a raw string in the region, make sure we
have the end of
+ ;; it.
+ (when (or beg-in-str end-in-str)
+ (save-excursion
+ (goto-char font-lock-beg)
+ (while (and (< (point) font-lock-end) (ignore-errors
(rust-look-for-raw-string (buffer-end 1)))))
+ (setq font-lock-end (max font-lock-end (point)))))
+
+ (or (/= font-lock-beg orig-beg)
+ (/= font-lock-end orig-end))
+ ))
+
(defun rust-look-for-raw-string (bound)
;; Find a raw string, but only if it's not in the middle of another string or
;; a comment
@@ -702,6 +739,7 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(setq-local indent-line-function 'rust-mode-indent-line)
;; Fonts
+ (add-to-list 'font-lock-extend-region-functions
'rust-extend-region-raw-string)
(setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil
nil (font-lock-syntactic-keywords . rust-mode-font-lock-syntactic-keywords)))
;; Misc
- [nongnu] elpa/rust-mode d6b1739 136/486: Fix spurious errors in emacs 23, (continued)
- [nongnu] elpa/rust-mode d6b1739 136/486: Fix spurious errors in emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3995d33 152/486: Add regression test for PR #52., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f2d709e 141/486: Make fill-region work correctly, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8a8bd58 159/486: Merge pull request #58 from lunaryorn/patch-1, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2f0c84f 150/486: rust-align-to-method-chain: Jump over symbols, not words, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2e800ee 151/486: workaround emacs 23 issues., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2be934c 147/486: Merge pull request #55 from kriben/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4e938b1 164/486: Merge pull request #63 from krig/panic-compilation-warning, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f17e11a 162/486: Match panics during build as compilation warnings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b4ff35c 168/486: remove rust-mode-character-literal-syntax-table, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5ed4675 171/486: Merge pull request #73 from MicahChalmer/raw-string-multiline-edit-fix,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 9d773b4 170/486: Fix multi-line raw strings when editing, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6bc1540 186/486: Support nested block comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7baae9c 180/486: Merge pull request #78 from tromey/fix-issue-33, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c0e3878 183/486: Merge pull request #81 from MicahChalmer/fix-issue-80, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 75da3b0 189/486: Merge pull request #89 from MicahChalmer/fix-slow-angle-bracket-matching, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a2e9f56 199/486: Merge pull request #84 from birkenfeld/compilation-note, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 92584c3 209/486: Fix the special case for the first line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b76e803 208/486: Correctly indent where clauses, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 304ae4b 219/486: Change font-lock face for module names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ae49380 221/486: Merge pull request #121 from fbergroth/integrate-rustfmt, ELPA Syncer, 2021/08/07