[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode c2deea8 037/104: Merge pull request #14 from mgxm
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode c2deea8 037/104: Merge pull request #14 from mgxm/imenu |
Date: |
Sun, 29 Aug 2021 11:36:58 -0400 (EDT) |
branch: elpa/zig-mode
commit c2deea85dd65c3e73c2771c56a998cbdeb9ff717
Merge: 1f4ebf1 4542a5d
Author: Matthew D. Steele <mdsteele@alum.mit.edu>
Commit: GitHub <noreply@github.com>
Merge pull request #14 from mgxm/imenu
add imenu support
---
tests.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
zig-mode.el | 15 ++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/tests.el b/tests.el
index 304103e..83171f2 100644
--- a/tests.el
+++ b/tests.el
@@ -2,6 +2,7 @@
(require 'ert)
(require 'zig-mode)
+(require 'imenu)
;;===========================================================================;;
;; Font lock tests
@@ -288,3 +289,69 @@ if (false) { // This comment shouldn't mess anything up.
}"))
;;===========================================================================;;
+;; Imenu tests
+
+;; taken from rust-mode
+(defun test-imenu (code expected-items)
+ (with-temp-buffer
+ (zig-mode)
+ (insert code)
+ (let ((actual-items
+ ;; Replace ("item" . #<marker at ? in ?.el) with "item"
+ (mapcar (lambda (class)
+ (cons (car class)
+ (mapcar #'car (cdr class))))
+ (imenu--generic-function
zig-imenu-generic-expression))))
+ (should (equal expected-items actual-items)))))
+
+
+(ert-deftest test-imenu-struct ()
+ (test-imenu
+ "
+pub const Foo = struct {};
+pub const Bar = extern struct {};
+const FooBar = struct {};
+"
+ '(("Struct"
+ "Foo"
+ "Bar"
+ "FooBar"))))
+
+(ert-deftest test-imenu-enum ()
+ (test-imenu
+ "
+pub const Foo = enum {};
+const FooBarError = enum {};
+"
+ '(("Enum"
+ "Foo"
+ "FooBarError"))))
+
+(ert-deftest test-imenu-enum ()
+ (test-imenu
+ "
+pub const Foo = enum {};
+const FooBarError = enum {};
+"
+ '(("Enum"
+ "Foo"
+ "FooBarError"))))
+
+(ert-deftest test-imenu-all ()
+ (test-imenu
+ "
+const Foo = struct {
+ pub fn init() void {}
+};
+
+const FooError = enum {};
+
+pub fn main() void {
+}
+"
+ '(("Fn" "init" "main")
+ ("Struct" "Foo")
+ ("Enum" "FooError"))))
+
+
+;;===========================================================================;;
diff --git a/zig-mode.el b/zig-mode.el
index 4e4c99a..172899f 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -283,6 +283,20 @@
'font-lock-doc-face
'font-lock-comment-face))))
+;;; Imenu support
+(defun zig-re-structure-def-imenu (stype)
+ "Construct a regular expression for strucutres definitions of type STYPE."
+ (concat (zig-re-word "const") "[[:space:]]+"
+ (zig-re-grab zig-re-identifier)
+ ".*"
+ (zig-re-word stype)))
+
+(defvar zig-imenu-generic-expression
+ (append (mapcar #'(lambda (x)
+ (list (capitalize x)
(zig-re-structure-def-imenu x) 1))
+ '("enum" "struct" "union"))
+ `(("Fn" ,(zig-re-definition "fn") 1))))
+
;;;###autoload
(define-derived-mode zig-mode prog-mode "Zig"
"A major mode for the Zig programming language."
@@ -295,6 +309,7 @@
(setq-local indent-line-function 'zig-mode-indent-line)
(setq-local indent-tabs-mode nil) ; Zig forbids tab characters.
(setq-local syntax-propertize-function 'zig-syntax-propertize)
+ (setq-local imenu-generic-expression zig-imenu-generic-expression)
(setq font-lock-defaults '(zig-font-lock-keywords
nil nil nil nil
(font-lock-syntactic-face-function
- [nongnu] elpa/zig-mode 1e75c04 100/104: Remove irrelevant comment, (continued)
- [nongnu] elpa/zig-mode 1e75c04 100/104: Remove irrelevant comment, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0babe7e 103/104: Merge pull request #59 from eric-p-hutchins/params-with-optionals-pointers-and-arrays-oh-my, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2d0eb23 097/104: Merge pull request #55 from arqv/optim-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 232bfff 010/104: Merge pull request #2 from syohex/fix-package, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fead48b 002/104: Initial revision., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c961a6d 005/104: noreturn., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 5b3b772 011/104: Removed hook., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode fb8d52f 017/104: License., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 4f281e4 020/104: Changed repository location, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c5315ff 026/104: Apply font-lock-doc-face to doc comments (for issue #5), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode c2deea8 037/104: Merge pull request #14 from mgxm/imenu,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 52e3e20 004/104: README., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode bc1bed3 009/104: Fix package, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 1d26390 015/104: Merge pull request #3 from purcell/patch-1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0ed57d8 014/104: Minor fixes, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e659a58 024/104: Set comment-start and comment-end (for issue #5) (#7), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b773127 027/104: Initial implementation of indent-line-function, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9c200f4 032/104: Add -y flag to apt-get command in AppVeyor install script, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode e0bccb1 047/104: add zig-format-buffer command, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 2acd88f 049/104: add zig-mode-map with default keybinding, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 0a150f2 054/104: Merge pull request #19 from mgxm/fix_multiline_string, ELPA Syncer, 2021/08/29