branch: elpa/lua-mode
commit 6436a45df5987b55a1208bc74a71830bd545fc88
Author: immerrr <[email protected]>
Commit: immerrr <[email protected]>
Index "require" as imenu items
---
lua-mode.el | 3 ++-
test/test-generic.el | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/lua-mode.el b/lua-mode.el
index 640e490..33f68c2 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -662,7 +662,8 @@ Groups 6-9 can be used in any of argument regexps."
"Default expressions to highlight in Lua mode.")
(defvar lua-imenu-generic-expression
- `((nil ,(lua-rx (or bol ";") ws (opt (seq (symbol "local") ws))
lua-funcheader) 1))
+ `(("Requires" ,(lua-rx (or bol ";") ws (opt (seq (symbol "local") ws))
(group-n 1 lua-name) ws "=" ws (symbol "require")) 1)
+ (nil ,(lua-rx (or bol ";") ws (opt (seq (symbol "local") ws))
lua-funcheader) 1))
"Imenu generic expression for lua-mode. See `imenu-generic-expression'.")
(defvar lua-sexp-alist '(("then" . "end")
diff --git a/test/test-generic.el b/test/test-generic.el
index d7b6880..d0356b7 100644
--- a/test/test-generic.el
+++ b/test/test-generic.el
@@ -3,6 +3,8 @@
default-directory))
"utils.el") nil 'nomessage 'nosuffix)
+(require 'imenu)
+
(describe "lua-forward-sexp"
(it "properly scans through curly braces"
(with-lua-buffer
@@ -77,3 +79,31 @@
(it "is derived from prog-mode"
(with-lua-buffer
(expect (derived-mode-p 'prog-mode)))))
+
+(describe "imenu integration"
+ (it "indexes functions"
+ (with-lua-buffer
+ (insert "\
+function foo()
+ function bar() end
+ local function baz() end
+ qux = function() end
+ local quux = function() end
+end
+")
+ (expect (mapcar 'car (funcall imenu-create-index-function))
+ :to-equal '("foo" "bar" "baz" "qux" "quux"))))
+
+ (it "indexes require statements"
+ (with-lua-buffer
+ (insert "\
+foo = require (\"foo\")
+local bar = require (\"bar\")
+")
+ (expect (mapcar (lambda (item) (cons (car item)
+ (if (listp (cdr item))
+ (mapcar 'car (cdr item))
+ -1)))
+ (funcall imenu-create-index-function))
+ :to-equal '(("Requires" . ("foo" "bar")))))))
+