[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 66438d4 108/486: Merge pull request #2 from Mica
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 66438d4 108/486: Merge pull request #2 from MicahChalmer/fix-quotes-with-syntax-properties |
Date: |
Sat, 7 Aug 2021 09:24:59 -0400 (EDT) |
branch: elpa/rust-mode
commit 66438d4e7c25587bf396fb0ee7063a1869ad04a3
Merge: 149cfdd e6e16cc
Author: Felix S Klock II <pnkfelix@pnkfx.org>
Commit: Felix S Klock II <pnkfelix@pnkfx.org>
Merge pull request #2 from MicahChalmer/fix-quotes-with-syntax-properties
Fix quotes with syntax properties
---
rust-mode-tests.el | 26 +++++++++++++++++++++++
rust-mode.el | 61 +++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 73 insertions(+), 14 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 54b4524..2b18728 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -526,6 +526,18 @@ fn foo() {
"
))
+;; Closing braces in single char literals and strings should not confuse the
indentation
+(ert-deftest indent-closing-braces-in-char-literals ()
+ (test-indent
+ "
+fn foo() {
+ { bar('}'); }
+ { bar(']'); }
+ { bar(')'); }
+}
+"
+ ))
+
(setq rust-test-motion-string
"
fn fn1(arg: int) -> bool {
@@ -893,3 +905,17 @@ list of substrings of `STR' each followed by its face."
"/* #[foo] */"
'("/* " font-lock-comment-delimiter-face
"#[foo] */" font-lock-comment-face)))
+
+(ert-deftest font-lock-double-quote-character-literal ()
+ (rust-test-font-lock
+ "'\"'; let"
+ '("'\"'" font-lock-string-face
+ "let" font-lock-keyword-face)))
+
+(ert-deftest font-lock-single-quote-character-literal ()
+ (rust-test-font-lock
+ "fn main() { let ch = '\\''; }"
+ '("fn" font-lock-keyword-face
+ "main" font-lock-function-name-face
+ "let" font-lock-keyword-face
+ "'\\''" font-lock-string-face)))
diff --git a/rust-mode.el b/rust-mode.el
index dae685f..70b49fe 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -44,6 +44,13 @@
table))
+(defvar rust-mode-character-literal-syntax-table
+ (let ((table (make-syntax-table rust-mode-syntax-table)))
+ (modify-syntax-entry ?' "\"" table)
+ (modify-syntax-entry ?\" "_" table)
+
+ table))
+
(defgroup rust-mode nil
"Support for Rust code."
:link '(url-link "http://www.rust-lang.org/")
@@ -259,14 +266,6 @@
;; Lifetimes like `'foo`
(,(concat "'" (rust-re-grab rust-re-ident) "[^']") 1
font-lock-variable-name-face)
- ;; Character constants, since they're not treated as strings
- ;; in order to have sufficient leeway to parse 'lifetime above.
- (,(rust-re-grab "'[^']'") 1 font-lock-string-face)
- (,(rust-re-grab "'\\\\[nrt]'") 1 font-lock-string-face)
- (,(rust-re-grab "'\\\\x[[:xdigit:]]\\{2\\}'") 1 font-lock-string-face)
- (,(rust-re-grab "'\\\\u[[:xdigit:]]\\{4\\}'") 1 font-lock-string-face)
- (,(rust-re-grab "'\\\\U[[:xdigit:]]\\{8\\}'") 1 font-lock-string-face)
-
;; CamelCase Means Type Or Constructor
(,(rust-re-grabword rust-re-CamelCase) 1 font-lock-type-face)
)
@@ -439,12 +438,19 @@ Assume that this is called after beginning-of-defun. So
point is
at the beginning of the defun body.
This is written mainly to be used as `end-of-defun-function' for Rust."
- (interactive "p")
+ (interactive)
;; Find the opening brace
- (re-search-forward "[{]" nil t)
- (goto-char (match-beginning 0))
- ;; Go to the closing brace
- (forward-sexp))
+ (if (re-search-forward "[{]" nil t)
+ (progn
+ (goto-char (match-beginning 0))
+ ;; Go to the closing brace
+ (condition-case err
+ (forward-sexp)
+ (scan-error
+ ;; The parentheses are unbalanced; instead of being unable to
fontify, just jump to the end of the buffer
+ (goto-char (point-max)))))
+ ;; There is no opening brace, so consider the whole buffer to be one
"defun"
+ (goto-char (point-max))))
;; For compatibility with Emacs < 24, derive conditionally
(defalias 'rust-parent-mode
@@ -481,7 +487,34 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(setq-local comment-line-break-function 'rust-comment-indent-new-line)
(setq-local imenu-generic-expression rust-imenu-generic-expression)
(setq-local beginning-of-defun-function 'rust-beginning-of-defun)
- (setq-local end-of-defun-function 'rust-end-of-defun))
+ (setq-local end-of-defun-function 'rust-end-of-defun)
+ (setq-local parse-sexp-lookup-properties t)
+ (add-hook 'syntax-propertize-extend-region-functions
'rust-syntax-propertize-extend-region)
+ (setq-local syntax-propertize-function 'rust-syntax-propertize))
+
+(defun rust-syntax-propertize-extend-region (start end)
+ (save-excursion
+ (goto-char start)
+ (beginning-of-defun)
+ (cons
+ (point)
+ (progn
+ (goto-char end)
+ (end-of-defun)
+ (point)))))
+
+(defun rust-syntax-propertize (start end)
+ ;; Find character literals and make the syntax table recognize the single
quote as the string delimiter
+ (dolist (char-lit-re
+ '("'[^']'"
+ "'\\\\['nrt]'"
+ "'\\\\x[[:xdigit:]]\\{2\\}'"
+ "'\\\\u[[:xdigit:]]\\{4\\}'"
+ "'\\\\U[[:xdigit:]]\\{8\\}'"))
+ (save-excursion
+ (goto-char start)
+ (while (re-search-forward char-lit-re end t)
+ (put-text-property (match-beginning 0) (match-end 0) 'syntax-table
rust-mode-character-literal-syntax-table)))))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
- [nongnu] elpa/rust-mode 336c052 087/486: emacs: Remove outdated references to ~ in tests, (continued)
- [nongnu] elpa/rust-mode 336c052 087/486: emacs: Remove outdated references to ~ in tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8622310 091/486: Add 'move' keyword to emacs, kate, and vim editor modes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4ccac8e 095/486: Update editor syntax files for isize/usize., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2a81393 094/486: added optional method chain indentations for emacs major mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 079f0c2 093/486: Update emacs and vi modes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0b9a7e0 092/486: rust-mode.el: Tweak syntax table, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 67f4832 099/486: Fix tests broken by trailing whitespace removal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f292554 097/486: Changed rust-mode code for tabs -> spaces, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4659aee 098/486: rollup merge of #19913: KOMON/rust-mode-emacs-indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e6e16cc 102/486: Add test for closing braces in character literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 66438d4 108/486: Merge pull request #2 from MicahChalmer/fix-quotes-with-syntax-properties,
ELPA Syncer <=
- [nongnu] elpa/rust-mode f0d4c25 109/486: Fix aligning of method chains (more-or-less) and add various unit tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fd92bfd 111/486: Merge pull request #17 from ramnes/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 149cfdd 106/486: Merge pull request #20 from pnkfelix/fix-broken-tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 81d0680 118/486: Fix ERT section of README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2038365 120/486: Fix bug in rust-indent-method-chains, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fea20e7 131/486: Include the last character in indentation tests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2e7c6dc 128/486: Add test for raw string with inner quote and hash, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eaa332e 143/486: Add rust-playpen-buffer and rust-playpen-region for sharing code., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 054a11c 157/486: Update rust-mode URL in header, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5d0fce5 149/486: Fix word and symbol syntax distinction, ELPA Syncer, 2021/08/07