Skip to content

Commit e53dc8a

Browse files
committed
Don't call syntax-ppss twice for raw strings.
1 parent df31a6e commit e53dc8a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

rust-mode.el

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,32 +1105,32 @@ should be considered a paired angle bracket."
11051105
(group "'")))
11061106
"A regular expression matching a character literal."))
11071107

1108-
(defun rust--syntax-propertize-raw-string (end)
1108+
(defun rust--syntax-propertize-raw-string (str-start end)
11091109
"A helper for rust-syntax-propertize.
11101110
1111-
If point is already in a raw string, this will apply the
1112-
appropriate string syntax to the character up to the end of the
1113-
raw string, or to END, whichever comes first."
1114-
(let ((str-start (nth 8 (syntax-ppss))))
1115-
(when str-start
1116-
(when (save-excursion
1117-
(goto-char str-start)
1118-
(looking-at "r\\(#*\\)\\(\"\\)"))
1119-
;; In a raw string, so try to find the end.
1120-
(let ((hashes (match-string 1)))
1121-
;; Match \ characters at the end of the string to suppress
1122-
;; their normal character-quote syntax.
1123-
(when (re-search-forward (concat "\\(\\\\*\\)\\(\"" hashes "\\)") end t)
1124-
(put-text-property (match-beginning 1) (match-end 1)
1125-
'syntax-table (string-to-syntax "_"))
1126-
(put-text-property (1- (match-end 2)) (match-end 2)
1127-
'syntax-table (string-to-syntax "|"))
1128-
(goto-char (match-end 0))))))))
1111+
This will apply the appropriate string syntax to the character
1112+
from the STR-START up to the end of the raw string, or to END,
1113+
whichever comes first."
1114+
(when (save-excursion
1115+
(goto-char str-start)
1116+
(looking-at "r\\(#*\\)\\(\"\\)"))
1117+
;; In a raw string, so try to find the end.
1118+
(let ((hashes (match-string 1)))
1119+
;; Match \ characters at the end of the string to suppress
1120+
;; their normal character-quote syntax.
1121+
(when (re-search-forward (concat "\\(\\\\*\\)\\(\"" hashes "\\)") end t)
1122+
(put-text-property (match-beginning 1) (match-end 1)
1123+
'syntax-table (string-to-syntax "_"))
1124+
(put-text-property (1- (match-end 2)) (match-end 2)
1125+
'syntax-table (string-to-syntax "|"))
1126+
(goto-char (match-end 0))))))
11291127

11301128
(defun rust-syntax-propertize (start end)
11311129
"A `syntax-propertize-function' to apply properties from START to END."
11321130
(goto-char start)
1133-
(rust--syntax-propertize-raw-string end)
1131+
(let ((str-start (rust-in-str-or-cmnt)))
1132+
(when str-start
1133+
(rust--syntax-propertize-raw-string str-start end)))
11341134
(funcall
11351135
(syntax-propertize-rules
11361136
;; Character literals.
@@ -1142,7 +1142,7 @@ raw string, or to END, whichever comes first."
11421142
(unless (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
11431143
(put-text-property (match-beginning 1) (match-end 1)
11441144
'syntax-table (string-to-syntax "|"))
1145-
(rust--syntax-propertize-raw-string end)))))
1145+
(rust--syntax-propertize-raw-string (match-beginning 0) end)))))
11461146
("[<>]"
11471147
(0 (ignore
11481148
(when (save-match-data

0 commit comments

Comments
 (0)