[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 4fd637c 428/486: rust-insert-dbg: handle the cas
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 4fd637c 428/486: rust-insert-dbg: handle the case of string literals. (#342) |
Date: |
Sat, 7 Aug 2021 09:26:07 -0400 (EDT) |
branch: elpa/rust-mode
commit 4fd637c06b27c74df2e8080e832b8bd80a55be81
Author: Nathan Moreau <nathan.moreau@m4x.org>
Commit: GitHub <noreply@github.com>
rust-insert-dbg: handle the case of string literals. (#342)
---
rust-mode-tests.el | 11 +++++----
rust-mode.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index b234771..e2e1218 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -245,10 +245,6 @@ fn bar() { }"
/// even more.
fn bar() { }" 14 85))
-(defun test-dbg-wrap (initial expected position &optional end)
- (with-temp-buffer
- (insert initial)))
-
(defun test-auto-fill (initial position inserted expected)
(rust-test-manip-code
initial
@@ -3186,6 +3182,13 @@ impl Two<'a> {
(ert-deftest rust-test-dbg-uwnrap-on-dbg-start ()
(rust-test-dbg-unwrap 13))
+(ert-deftest rust-test-dbg-unwrap-inside-string-literal ()
+ (rust-test-manip-code
+ "let x = \"foo, bar\"";"
+ 15
+ #'rust-dbg-wrap-or-unwrap
+ "let x = dbg!(\"foo, bar\")"))
+
(when (executable-find rust-cargo-bin)
(ert-deftest rust-test-project-located ()
(lexical-let* ((test-dir (expand-file-name "test-project/"
default-directory))
diff --git a/rust-mode.el b/rust-mode.el
index b839558..e98e488 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1811,12 +1811,78 @@ visit the new file."
(insert-parentheses)
(goto-char old-point)))
(t
+ (when (rust-in-str)
+ (rust--up-list -1 t t))
(insert "(")
(forward-sexp)
(insert ")")
(backward-sexp)))
(insert "dbg!"))
+(defun rust--up-list (&optional arg escape-strings no-syntax-crossing)
+ "Compatibility for emacs 24."
+ (or arg (setq arg 1))
+ (let ((inc (if (> arg 0) 1 -1))
+ (pos nil))
+ (while (/= arg 0)
+ (condition-case err
+ (save-restriction
+ ;; If we've been asked not to cross string boundaries
+ ;; and we're inside a string, narrow to that string so
+ ;; that scan-lists doesn't find a match in a different
+ ;; string.
+ (when no-syntax-crossing
+ (let* ((syntax (syntax-ppss))
+ (string-comment-start (nth 8 syntax)))
+ (when string-comment-start
+ (save-excursion
+ (goto-char string-comment-start)
+ (narrow-to-region
+ (point)
+ (if (nth 3 syntax) ; in string
+ (condition-case nil
+ (progn (forward-sexp) (point))
+ (scan-error (point-max)))
+ (forward-comment 1)
+ (point)))))))
+ (if (null forward-sexp-function)
+ (goto-char (or (scan-lists (point) inc 1)
+ (buffer-end arg)))
+ (condition-case err
+ (while (progn (setq pos (point))
+ (forward-sexp inc)
+ (/= (point) pos)))
+ (scan-error (goto-char (nth (if (> arg 0) 3 2) err))))
+ (if (= (point) pos)
+ (signal 'scan-error
+ (list "Unbalanced parentheses" (point) (point))))))
+ (scan-error
+ (let ((syntax nil))
+ (or
+ ;; If we bumped up against the end of a list, see whether
+ ;; we're inside a string: if so, just go to the beginning
+ ;; or end of that string.
+ (and escape-strings
+ (or syntax (setf syntax (syntax-ppss)))
+ (nth 3 syntax)
+ (goto-char (nth 8 syntax))
+ (progn (when (> inc 0)
+ (forward-sexp))
+ t))
+ ;; If we narrowed to a comment above and failed to escape
+ ;; it, the error might be our fault, not an indication
+ ;; that we're out of syntax. Try again from beginning or
+ ;; end of the comment.
+ (and no-syntax-crossing
+ (or syntax (setf syntax (syntax-ppss)))
+ (nth 4 syntax)
+ (goto-char (nth 8 syntax))
+ (or (< inc 0)
+ (forward-comment 1))
+ (setf arg (+ arg inc)))
+ (signal (car err) (cdr err))))))
+ (setq arg (- arg inc)))))
+
;;;###autoload
(defun rust-dbg-wrap-or-unwrap ()
"Either remove or add the dbg! macro."
- [nongnu] elpa/rust-mode a36bc70 426/486: Merge pull request #340 from brotzeit/readme, (continued)
- [nongnu] elpa/rust-mode a36bc70 426/486: Merge pull request #340 from brotzeit/readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6a57253 427/486: rust-dbg-wrap-or-unwrap: bind to C-c C-d rather than C-c d., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e8345f6 440/486: Add triagebot configuration (#364), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a364b24 445/486: Make *rustfmt* buffer readonly., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 15a077a 458/486: rustc-colon-compilation-regexps: improve highlighting., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 00177f5 461/486: compile-mode integration: add link to code references. (#391), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5585cf9 477/486: rust-mode: Cosmetics, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3fa8f0b 479/486: Add non-empty commentary section, slightly reword summary, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7ff04a8 337/486: Merge pull request #234 from jjwest/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 70ff9a0 421/486: electric-pair-mode: prevent self-insert of `>' when already inserted. (#337), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4fd637c 428/486: rust-insert-dbg: handle the case of string literals. (#342),
ELPA Syncer <=
- [nongnu] elpa/rust-mode 844bb51 429/486: add support for "async fn", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 63ec74c 434/486: Enforce use of spaces for indentation and cleanup whitespace (#353), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a36c96a 435/486: integrate rustfmt error messages, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8665005 436/486: Introduce constant for *rustfmt*., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 08d7141 449/486: README: support for emacs 24 has been dropped., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1603a25 455/486: Change 'rust-build' to 'rust-compile' in README.md, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6e4835c 456/486: Update README.md, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5dc219f 465/486: rearrange III: Mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode beda16d 466/486: rearrange IV: Misc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f9e3618 468/486: Divide library into sections, ELPA Syncer, 2021/08/07