Skip to content

Commit 5dfc5be

Browse files
authored
Merge pull request #168 from immerrr/index-requires-as-imenu-items
Index "require" as imenu items
2 parents 658bf8f + 6436a45 commit 5dfc5be

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lua-mode.el

+2-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ Groups 6-9 can be used in any of argument regexps."
662662
"Default expressions to highlight in Lua mode.")
663663

664664
(defvar lua-imenu-generic-expression
665-
`((nil ,(lua-rx (or bol ";") ws (opt (seq (symbol "local") ws)) lua-funcheader) 1))
665+
`(("Requires" ,(lua-rx (or bol ";") ws (opt (seq (symbol "local") ws)) (group-n 1 lua-name) ws "=" ws (symbol "require")) 1)
666+
(nil ,(lua-rx (or bol ";") ws (opt (seq (symbol "local") ws)) lua-funcheader) 1))
666667
"Imenu generic expression for lua-mode. See `imenu-generic-expression'.")
667668

668669
(defvar lua-sexp-alist '(("then" . "end")

test/test-generic.el

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
default-directory))
44
"utils.el") nil 'nomessage 'nosuffix)
55

6+
(require 'imenu)
7+
68
(describe "lua-forward-sexp"
79
(it "properly scans through curly braces"
810
(with-lua-buffer
@@ -77,3 +79,31 @@
7779
(it "is derived from prog-mode"
7880
(with-lua-buffer
7981
(expect (derived-mode-p 'prog-mode)))))
82+
83+
(describe "imenu integration"
84+
(it "indexes functions"
85+
(with-lua-buffer
86+
(insert "\
87+
function foo()
88+
function bar() end
89+
local function baz() end
90+
qux = function() end
91+
local quux = function() end
92+
end
93+
")
94+
(expect (mapcar 'car (funcall imenu-create-index-function))
95+
:to-equal '("foo" "bar" "baz" "qux" "quux"))))
96+
97+
(it "indexes require statements"
98+
(with-lua-buffer
99+
(insert "\
100+
foo = require (\"foo\")
101+
local bar = require (\"bar\")
102+
")
103+
(expect (mapcar (lambda (item) (cons (car item)
104+
(if (listp (cdr item))
105+
(mapcar 'car (cdr item))
106+
-1)))
107+
(funcall imenu-create-index-function))
108+
:to-equal '(("Requires" . ("foo" "bar")))))))
109+

0 commit comments

Comments
 (0)