Skip to content

Commit e3c545e

Browse files
committed
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.
1 parent 4fce178 commit e3c545e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rust-mode.el

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
(defconst rust-re-ident "[[:word:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
3232
(defconst rust-re-lc-ident "[[:lower:][:multibyte:]_][[:word:][:multibyte:]_[:digit:]]*")
3333
(defconst rust-re-uc-ident "[[:upper:]][[:word:][:multibyte:]_[:digit:]]*")
34+
(defconst rust-re-vis "pub")
3435

3536
(defconst rust-re-non-standard-string
3637
(rx
@@ -543,8 +544,13 @@ buffer."
543544
(defconst rust-re-pre-expression-operators "[-=!%&*/:<>[{(|.^;}]")
544545
(defun rust-re-word (inner) (concat "\\<" inner "\\>"))
545546
(defun rust-re-grab (inner) (concat "\\(" inner "\\)"))
547+
(defun rust-re-shy (inner) (concat "\\(?:" inner "\\)"))
546548
(defun rust-re-item-def (itype)
547549
(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)))
548554

549555
(defconst rust-re-special-types (regexp-opt rust-special-types 'symbols))
550556

@@ -1189,9 +1195,9 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
11891195
;;; Imenu support
11901196
(defvar rust-imenu-generic-expression
11911197
(append (mapcar #'(lambda (x)
1192-
(list nil (rust-re-item-def x) 1))
1198+
(list nil (rust-re-item-def-imenu x) 1))
11931199
'("enum" "struct" "type" "mod" "fn" "trait"))
1194-
`(("Impl" ,(rust-re-item-def "impl") 1)))
1200+
`(("Impl" ,(rust-re-item-def-imenu "impl") 1)))
11951201
"Value for `imenu-generic-expression' in Rust mode.
11961202
11971203
Create a flat index of the item definitions in a Rust file.

0 commit comments

Comments
 (0)