Skip to content

Commit 7ddbd20

Browse files
committed
[TODO] changes that I would like you to backport
(progn (copy-file "~/.emacs.d/lib/rustic/rustic.el" "~/.emacs.d/lib/rust-mode/rust-mode.el" t) (with-current-buffer (find-file-noselect "~/.emacs.d/lib/rust-mode/rust-mode.el") (save-excursion (goto-char (point-min)) ;; (re-search-forward "^;;; Code:$" nil t) ;; (kill-region (point-min) (match-beginning 0)) (save-excursion (replace-regexp ":group 'rustic" ":group 'rust-mode")) (save-excursion (replace-regexp "rustic-mode" "rust-mode")) (save-excursion (replace-regexp "rustic" "rust")) (save-excursion (replace-regexp "\"1.2\"" "\"0.6.0\"")) )))
1 parent 0ff4cce commit 7ddbd20

File tree

1 file changed

+30
-58
lines changed

1 file changed

+30
-58
lines changed

rust-mode.el

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,12 @@ or if NODEFAULT is non-nil, then fall back to returning nil."
134134

135135
;;; Syntax
136136

137-
(defun rust-re-word (inner) (concat "\\<" inner "\\>"))
138-
(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
139-
(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)"))
140-
141137
(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
142138
(defconst rust-re-lc-ident "[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
143139
(defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
144-
(defvar rust-re-vis
145-
;; pub | pub ( crate ) | pub ( self ) | pub ( super ) | pub ( in SimplePath )
146-
(concat
147-
"pub"
148-
(rust-re-shy
149-
(concat
150-
"[[:space:]]*([[:space:]]*"
151-
(rust-re-shy
152-
(concat "crate" "\\|"
153-
"\\(?:s\\(?:elf\\|uper\\)\\)" "\\|"
154-
;; in SimplePath
155-
(rust-re-shy
156-
(concat
157-
"in[[:space:]]+"
158-
rust-re-ident
159-
(rust-re-shy (concat "::" rust-re-ident)) "*"))))
160-
"[[:space:]]*)"))
161-
"?"))
140+
(defconst rust-re-vis "pub")
162141
(defconst rust-re-unsafe "unsafe")
163142
(defconst rust-re-extern "extern")
164-
(defconst rust-re-async-or-const "async\\|const")
165143
(defconst rust-re-generic
166144
(concat "<[[:space:]]*'" rust-re-ident "[[:space:]]*>"))
167145
(defconst rust-re-union
@@ -171,27 +149,27 @@ or if NODEFAULT is non-nil, then fall back to returning nil."
171149
(group symbol-start "union" symbol-end)
172150
(+ space) (regexp ,rust-re-ident))))
173151

152+
(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)"))
153+
(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
174154
(defun rust-re-item-def (itype)
175155
(concat (rust-re-word itype)
176156
(rust-re-shy rust-re-generic) "?"
177157
"[[:space:]]+" (rust-re-grab rust-re-ident)))
158+
(defun rust-re-word (inner) (concat "\\<" inner "\\>"))
178159

179-
;; TODO some of this does only make sense for `fn' (unsafe, extern...)
180-
;; and not other items
181160
(defun rust-re-item-def-imenu (itype)
182161
(concat "^[[:space:]]*"
183-
(rust-re-shy (concat rust-re-vis "[[:space:]]+")) "?"
162+
(rust-re-shy (concat (rust-re-word rust-re-vis) "[[:space:]]+")) "?"
184163
(rust-re-shy (concat (rust-re-word "default") "[[:space:]]+")) "?"
185-
(rust-re-shy (concat (rust-re-shy rust-re-async-or-const) "[[:space:]]+")) "?"
186164
(rust-re-shy (concat (rust-re-word rust-re-unsafe) "[[:space:]]+")) "?"
187165
(rust-re-shy (concat (rust-re-word rust-re-extern) "[[:space:]]+"
188-
(rust-re-shy "\"[^\"]+\"[[:space:]]+") "?")) "?"
189-
(rust-re-item-def itype)))
166+
(rust-re-shy "\"[^\"]+\"[[:space:]]+") "?")) "?"
167+
(rust-re-item-def itype)))
190168

191169
(defvar rust-imenu-generic-expression
192170
(append (mapcar #'(lambda (x)
193171
(list (capitalize x) (rust-re-item-def-imenu x) 1))
194-
'("enum" "struct" "union" "type" "mod" "fn" "trait" "impl"))
172+
'("async fn" "enum" "struct" "union" "type" "mod" "fn" "trait" "impl"))
195173
`(("Macro" ,(rust-re-item-def-imenu "macro_rules!") 1)))
196174
"Value for `imenu-generic-expression' in Rust mode.
197175
@@ -315,15 +293,10 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
315293
(setq auto-mode-alist (remove mode auto-mode-alist))))
316294

317295
(defvar rust-top-item-beg-re
318-
(concat "\\s-*"
319-
;; TODO some of this does only make sense for `fn' (unsafe, extern...)
320-
;; and not other items
321-
(rust-re-shy (concat (rust-re-shy rust-re-vis) "[[:space:]]+")) "?"
322-
(rust-re-shy (concat (rust-re-shy rust-re-async-or-const) "[[:space:]]+")) "?"
323-
(rust-re-shy (concat (rust-re-shy rust-re-unsafe) "[[:space:]]+")) "?"
296+
(concat "\\s-*\\(?:priv\\|pub\\)?\\s-*"
324297
(regexp-opt
325298
'("enum" "struct" "union" "type" "mod" "use" "fn" "static" "impl"
326-
"extern" "trait"))
299+
"extern" "trait" "async"))
327300
"\\_>")
328301
"Start of a Rust item.")
329302

@@ -337,7 +310,7 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
337310
"box" "break"
338311
"const" "continue" "crate"
339312
"do" "dyn"
340-
"else" "enum" "extern"
313+
"else" "enum" "extern" "existential"
341314
"false" "fn" "for"
342315
"if" "impl" "in"
343316
"let" "loop"
@@ -375,7 +348,7 @@ This is used by `rust-font-lock-keywords'.
375348
\(`write!' is handled separately).")
376349

377350
(defvar rust-formatting-macro-opening-re
378-
"[[:space:]\n]*[({[][[:space:]\n]*"
351+
"[[:space:]]*[({[][[:space:]]*"
379352
"Regular expression to match the opening delimiter of a Rust formatting macro.")
380353

381354
(defvar rust-start-of-string-re
@@ -421,19 +394,17 @@ Does not match type annotations of the form \"foo::<\"."
421394
1 font-lock-preprocessor-face keep)
422395

423396
;; Builtin formatting macros
424-
(,(concat (rust-re-grab
425-
(concat (rust-re-word (regexp-opt rust-builtin-formatting-macros))
426-
"!"))
397+
(,(concat (rust-re-grab (concat (regexp-opt rust-builtin-formatting-macros) "!"))
427398
rust-formatting-macro-opening-re
428-
"\\(?:" rust-start-of-string-re "\\)?")
399+
rust-start-of-string-re)
429400
(1 'rust-builtin-formatting-macro)
430401
(rust-string-interpolation-matcher
431402
(rust-end-of-string)
432403
nil
433404
(0 'rust-string-interpolation t nil)))
434405

435406
;; write! macro
436-
(,(concat (rust-re-grab (concat (rust-re-word "write\\(ln\\)?") "!"))
407+
(,(concat (rust-re-grab "write\\(ln\\)?!")
437408
rust-formatting-macro-opening-re
438409
"[[:space:]]*[^\"]+,[[:space:]]*"
439410
rust-start-of-string-re)
@@ -448,14 +419,13 @@ Does not match type annotations of the form \"foo::<\"."
448419
1 font-lock-preprocessor-face)
449420

450421
;; Field names like `foo:`, highlight excluding the :
451-
(,(concat (rust-re-grab rust-re-ident) "[[:space:]]*:[^:]")
452-
1 font-lock-variable-name-face)
422+
(,(concat (rust-re-grab rust-re-ident) ":[^:]") 1 font-lock-variable-name-face)
453423

454424
;; CamelCase Means Type Or Constructor
455425
(,rust-re-type-or-constructor 1 font-lock-type-face)
456426

457427
;; Type-inferred binding
458-
(,(concat "\\_<\\(?:let\\s-+ref\\|let\\|ref\\|for\\)\\s-+\\(?:mut\\s-+\\)?"
428+
(,(concat "\\_<\\(?:let\\s-+ref\\|let\\|ref\\)\\s-+\\(?:mut\\s-+\\)?"
459429
(rust-re-grab rust-re-ident)
460430
"\\_>")
461431
1 font-lock-variable-name-face)
@@ -1033,21 +1003,23 @@ should be considered a paired angle bracket."
10331003
;; as angle brackets it won't mess up any paren balancing.
10341004
((rust-in-macro) t)
10351005

1036-
((= (following-char) ?<)
1006+
((looking-at "<")
10371007
(rust-is-lt-char-operator))
10381008

1039-
;; Since rust-ordinary-lt-gt-p is called only when either < or > are at the point,
1040-
;; we know that the following char must be > in the clauses below.
1009+
((looking-at ">")
1010+
(cond
1011+
;; Don't treat the > in -> or => as an angle bracket
1012+
((member (char-before (point)) '(?- ?=)) t)
10411013

1042-
;; If we are at top level and not in any list, it can't be a closing
1043-
;; angle bracket
1044-
((>= 0 (rust-paren-level)) t)
1014+
;; If we are at top level and not in any list, it can't be a closing
1015+
;; angle bracket
1016+
((>= 0 (rust-paren-level)) t)
10451017

1046-
;; Otherwise, treat the > as a closing angle bracket if it would
1047-
;; match an opening one
1048-
((save-excursion
1049-
(backward-up-list)
1050-
(/= (following-char) ?<)))))
1018+
;; Otherwise, treat the > as a closing angle bracket if it would
1019+
;; match an opening one
1020+
((save-excursion
1021+
(backward-up-list)
1022+
(not (looking-at "<"))))))))
10511023

10521024
(defun rust-syntactic-face-function (state)
10531025
"Return face that distinguishes doc and normal comments in given syntax STATE."

0 commit comments

Comments
 (0)