diff options
| author | fmdkdd <fmdkdd@gmail.com> | 2016-05-14 13:15:32 +0200 |
|---|---|---|
| committer | fmdkdd <fmdkdd@gmail.com> | 2016-05-14 13:33:08 +0200 |
| commit | e3c545ec266721075e6d6e136759d95f4bb798da (patch) | |
| tree | 94d4b99387c688ff69609235af2b8a5934357ee1 /rust-mode.el | |
| parent | 4fce17848d7df44ea5a722577dbf69cccf39878b (diff) | |
| download | rust-mode-e3c545ec266721075e6d6e136759d95f4bb798da.tar.gz | |
imenu: don't add item defs in single-line comments
Fixes #94.
This commit changes the regexp used to build
`rust-imenu-generic-expression` to strictly match item definitions
on lines that are not single-line comments.
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rust-mode.el b/rust-mode.el index b0f8379..2e783a0 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -31,6 +31,7 @@ (defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*") (defconst rust-re-lc-ident "[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*") (defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*") +(defconst rust-re-vis "pub") (defconst rust-re-non-standard-string (rx @@ -543,8 +544,13 @@ buffer." (defconst rust-re-pre-expression-operators "[-=!%&*/:<>[{(|.^;}]") (defun rust-re-word (inner) (concat "\\<" inner "\\>")) (defun rust-re-grab (inner) (concat "\\(" inner "\\)")) +(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)")) (defun rust-re-item-def (itype) (concat (rust-re-word itype) "[[:space:]]+" (rust-re-grab rust-re-ident))) +(defun rust-re-item-def-imenu (itype) + (concat "^[[:space:]]*" + (rust-re-shy (concat (rust-re-word rust-re-vis) "[[:space:]]+")) "?" + (rust-re-item-def itype))) (defconst rust-re-special-types (regexp-opt rust-special-types 'symbols)) @@ -1189,9 +1195,9 @@ the desired identifiers), but does not match type annotations \"foo::<\"." ;;; Imenu support (defvar rust-imenu-generic-expression (append (mapcar #'(lambda (x) - (list nil (rust-re-item-def x) 1)) + (list nil (rust-re-item-def-imenu x) 1)) '("enum" "struct" "type" "mod" "fn" "trait")) - `(("Impl" ,(rust-re-item-def "impl") 1))) + `(("Impl" ,(rust-re-item-def-imenu "impl") 1))) "Value for `imenu-generic-expression' in Rust mode. Create a flat index of the item definitions in a Rust file. |
