|
35 | 35 | "Set variable VAR to value VAL in current buffer."
|
36 | 36 | (list 'set (list 'make-local-variable (list 'quote var)) val))))
|
37 | 37 |
|
| 38 | +(defun rust-re-word (inner) (concat "\\<" inner "\\>")) |
| 39 | +(defun rust-re-grab (inner) (concat "\\(" inner "\\)")) |
| 40 | +(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)")) |
| 41 | + |
38 | 42 | (defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
|
39 | 43 | (defconst rust-re-lc-ident "[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
|
40 | 44 | (defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
|
41 |
| -(defconst rust-re-vis "pub") |
42 | 45 | (defconst rust-re-unsafe "unsafe")
|
43 | 46 | (defconst rust-re-extern "extern")
|
| 47 | +(defconst rust-re-async-or-const "async\\|const") |
44 | 48 | (defconst rust-re-generic
|
45 | 49 | (concat "<[[:space:]]*'" rust-re-ident "[[:space:]]*>"))
|
46 | 50 | (defconst rust-re-union
|
|
50 | 54 | (group symbol-start "union" symbol-end)
|
51 | 55 | (+ space) (regexp ,rust-re-ident))))
|
52 | 56 |
|
| 57 | +(defvar rust-re-vis |
| 58 | + ;; pub | pub ( crate ) | pub ( self ) | pub ( super ) | pub ( in SimplePath ) |
| 59 | + (concat |
| 60 | + "pub" |
| 61 | + (rust-re-shy |
| 62 | + (concat |
| 63 | + "[[:space:]]*([[:space:]]*" |
| 64 | + (rust-re-shy |
| 65 | + (concat "crate" "\\|" |
| 66 | + "\\(?:s\\(?:elf\\|uper\\)\\)" "\\|" |
| 67 | + ;; in SimplePath |
| 68 | + (rust-re-shy |
| 69 | + (concat |
| 70 | + "in[[:space:]]+" |
| 71 | + rust-re-ident |
| 72 | + (rust-re-shy (concat "::" rust-re-ident)) "*")))) |
| 73 | + "[[:space:]]*)")) |
| 74 | + "?")) |
| 75 | + |
53 | 76 | ;;; Start of a Rust item
|
54 | 77 | (defvar rust-top-item-beg-re
|
55 |
| - (concat "\\s-*\\(?:priv\\|pub\\)?\\s-*" |
| 78 | + (concat "\\s-*" |
| 79 | + ;; TODO some of this does only make sense for `fn' (unsafe, extern...) |
| 80 | + ;; and not other items |
| 81 | + (rust-re-shy (concat (rust-re-shy rust-re-vis) "[[:space:]]+")) "?" |
| 82 | + |
| 83 | + (rust-re-shy (concat (rust-re-shy rust-re-async-or-const) "[[:space:]]+")) "?" |
| 84 | + (rust-re-shy (concat (rust-re-shy rust-re-unsafe) "[[:space:]]+")) "?" |
56 | 85 | (regexp-opt
|
57 | 86 | '("enum" "struct" "union" "type" "mod" "use" "fn" "static" "impl"
|
58 | 87 | "extern" "trait"))
|
@@ -578,17 +607,18 @@ buffer."
|
578 | 607 | symbol-end))
|
579 | 608 |
|
580 | 609 | (defconst rust-re-pre-expression-operators "[-=!%&*/:<>[{(|.^;}]")
|
581 |
| -(defun rust-re-word (inner) (concat "\\<" inner "\\>")) |
582 |
| -(defun rust-re-grab (inner) (concat "\\(" inner "\\)")) |
583 |
| -(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)")) |
584 | 610 | (defun rust-re-item-def (itype)
|
585 | 611 | (concat (rust-re-word itype)
|
586 |
| - (rust-re-shy rust-re-generic) "?" |
587 |
| - "[[:space:]]+" (rust-re-grab rust-re-ident))) |
| 612 | + (rust-re-shy rust-re-generic) "?" |
| 613 | + "[[:space:]]+" (rust-re-grab rust-re-ident))) |
| 614 | + |
| 615 | +;; TODO some of this does only make sense for `fn' (unsafe, extern...) |
| 616 | +;; and not other items |
588 | 617 | (defun rust-re-item-def-imenu (itype)
|
589 | 618 | (concat "^[[:space:]]*"
|
590 |
| - (rust-re-shy (concat (rust-re-word rust-re-vis) "[[:space:]]+")) "?" |
| 619 | + (rust-re-shy (concat rust-re-vis "[[:space:]]+")) "?" |
591 | 620 | (rust-re-shy (concat (rust-re-word "default") "[[:space:]]+")) "?"
|
| 621 | + (rust-re-shy (concat (rust-re-shy rust-re-async-or-const) "[[:space:]]+")) "?" |
592 | 622 | (rust-re-shy (concat (rust-re-word rust-re-unsafe) "[[:space:]]+")) "?"
|
593 | 623 | (rust-re-shy (concat (rust-re-word rust-re-extern) "[[:space:]]+"
|
594 | 624 | (rust-re-shy "\"[^\"]+\"[[:space:]]+") "?")) "?"
|
@@ -1292,7 +1322,7 @@ whichever comes first."
|
1292 | 1322 | (defvar rust-imenu-generic-expression
|
1293 | 1323 | (append (mapcar #'(lambda (x)
|
1294 | 1324 | (list (capitalize x) (rust-re-item-def-imenu x) 1))
|
1295 |
| - '("async fn" "enum" "struct" "union" "type" "mod" "fn" "trait" "impl")) |
| 1325 | + '("enum" "struct" "union" "type" "mod" "fn" "trait" "impl")) |
1296 | 1326 | `(("Macro" ,(rust-re-item-def-imenu "macro_rules!") 1)))
|
1297 | 1327 | "Value for `imenu-generic-expression' in Rust mode.
|
1298 | 1328 |
|
|
0 commit comments