|
31 | 31 | (defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
|
32 | 32 | (defconst rust-re-lc-ident "[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
|
33 | 33 | (defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
|
| 34 | +(defconst rust-re-vis "pub") |
34 | 35 |
|
35 | 36 | (defconst rust-re-non-standard-string
|
36 | 37 | (rx
|
@@ -543,8 +544,13 @@ buffer."
|
543 | 544 | (defconst rust-re-pre-expression-operators "[-=!%&*/:<>[{(|.^;}]")
|
544 | 545 | (defun rust-re-word (inner) (concat "\\<" inner "\\>"))
|
545 | 546 | (defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
|
| 547 | +(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)")) |
546 | 548 | (defun rust-re-item-def (itype)
|
547 | 549 | (concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident)))
|
| 550 | +(defun rust-re-item-def-imenu (itype) |
| 551 | + (concat "^[[:space:]]*" |
| 552 | + (rust-re-shy (concat (rust-re-word rust-re-vis) "[[:space:]]+")) "?" |
| 553 | + (rust-re-item-def itype))) |
548 | 554 |
|
549 | 555 | (defconst rust-re-special-types (regexp-opt rust-special-types 'symbols))
|
550 | 556 |
|
@@ -1189,16 +1195,15 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
|
1189 | 1195 | ;;; Imenu support
|
1190 | 1196 | (defvar rust-imenu-generic-expression
|
1191 | 1197 | (append (mapcar #'(lambda (x)
|
1192 |
| - (list nil (rust-re-item-def x) 1)) |
1193 |
| - '("enum" "struct" "type" "mod" "fn" "trait")) |
1194 |
| - `(("Impl" ,(rust-re-item-def "impl") 1))) |
| 1198 | + (list (capitalize x) (rust-re-item-def-imenu x) 1)) |
| 1199 | + '("enum" "struct" "type" "mod" "fn" "trait" "impl")) |
| 1200 | + `(("Macro" ,(rust-re-item-def-imenu "macro_rules!") 1))) |
1195 | 1201 | "Value for `imenu-generic-expression' in Rust mode.
|
1196 | 1202 |
|
1197 |
| -Create a flat index of the item definitions in a Rust file. |
| 1203 | +Create a hierarchical index of the item definitions in a Rust file. |
1198 | 1204 |
|
1199 |
| -Imenu will show all the enums, structs, etc. at the same level. |
1200 |
| -Implementations will be shown under the `Impl` subheading. Use |
1201 |
| -idomenu (imenu with `ido-mode') for best mileage.") |
| 1205 | +Imenu will show all the enums, structs, etc. in their own subheading. |
| 1206 | +Use idomenu (imenu with `ido-mode') for best mileage.") |
1202 | 1207 |
|
1203 | 1208 | ;;; Defun Motions
|
1204 | 1209 |
|
@@ -1334,6 +1339,7 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
|
1334 | 1339 | (setq-local comment-multi-line t)
|
1335 | 1340 | (setq-local comment-line-break-function 'rust-comment-indent-new-line)
|
1336 | 1341 | (setq-local imenu-generic-expression rust-imenu-generic-expression)
|
| 1342 | + (setq-local imenu-syntax-alist '((?! . "w"))) ; For macro_rules! |
1337 | 1343 | (setq-local beginning-of-defun-function 'rust-beginning-of-defun)
|
1338 | 1344 | (setq-local end-of-defun-function 'rust-end-of-defun)
|
1339 | 1345 | (setq-local parse-sexp-lookup-properties t)
|
|
0 commit comments