[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 9bfc6bf 215/385: really basic imenu
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 9bfc6bf 215/385: really basic imenu |
Date: |
Tue, 5 Oct 2021 23:59:34 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 9bfc6bf94a02c52c6f7bf16c31bd61e8b3264ddc
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
really basic imenu
---
README.md | 2 +-
haskell-tng-contrib.el | 2 +-
haskell-tng-imenu.el | 38 ++++++++++++++++++++++++++++++++++++--
test/haskell-tng-imenu-test.el | 11 ++++++-----
test/src/indentation.hs.imenu | 22 ++++++++++++++++++++++
test/src/layout.hs.imenu | 6 +++++-
6 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
index 6de2218..58e2516 100644
--- a/README.md
+++ b/README.md
@@ -105,7 +105,7 @@ This is the status of core features:
- [x] performance-minded `syntax-table`
- [x] `font-lock` to visually distinguish types and values
- [x] `sexp` navigation
- - [ ] `imenu` population (IN PROGRESS)
+ - [x] `imenu` population
- Editing:
- [x] indentation
- [x] `prettify-symbols` to emulate `UnicodeSyntax`
diff --git a/haskell-tng-contrib.el b/haskell-tng-contrib.el
index 4f06107..1c9499f 100644
--- a/haskell-tng-contrib.el
+++ b/haskell-tng-contrib.el
@@ -47,7 +47,7 @@
(interactive)
(save-excursion
(goto-char (point-min))
- (re-search-forward (rx bol "module" word-end) nil nil)
+ (re-search-forward (rx bol "module" word-end))
(forward-comment (point-max))
(re-search-forward (rx point (group (+ (not space))) space))
(kill-new (match-string 1))))
diff --git a/haskell-tng-imenu.el b/haskell-tng-imenu.el
index 4ab1a56..59a932d 100644
--- a/haskell-tng-imenu.el
+++ b/haskell-tng-imenu.el
@@ -9,13 +9,47 @@
;;
;;; Code:
+(require 'imenu)
+
+(require 'haskell-tng-rx)
+
(defun haskell-tng--imenu-create ()
"Creates a `imenu--index-alist' for the current buffer."
;; Simple elements in the alist look like (INDEX-NAME . POSITION).
;; A nested sub-alist element looks like (INDEX-NAME . SUB-ALIST).
- ;; FIXME implement imenu
- '(("*Rescan*" . -99))
+ (let (entries)
+ (save-excursion
+ (goto-char (point-min))
+
+ (re-search-forward (rx bol "module" word-end))
+ (push `("module" . ,(match-beginning 0)) entries)
+
+ (when (re-search-forward (rx bol "import" word-end) nil t)
+ (push `("imports" . ,(match-beginning 0)) entries))
+ ;; ignore all other imports
+ (while (re-search-forward (rx bol "import" word-end) nil t))
+
+ (while
+ ;; TODO type / data / class / instance
+ ;; TODO nested defns (use lexer not rx)
+ ;; TODO inline symid defns `a <*> b ='
+ ;; TODO consym defns `a :<|> b :<|> c ='
+ (re-search-forward
+ (rx-to-string
+ `(: bol
+ (group
+ (| ,haskell-tng--rx-varid
+ (: "(" ,haskell-tng--rx-symid ")")))))
+ nil t)
+ (let ((name (match-string 0))
+ (pos (match-beginning 0)))
+ (when (not (string-match haskell-tng--rx-c-reserved name))
+ (push `(,name . ,pos) entries)))))
+
+ (seq-uniq
+ (reverse entries)
+ (lambda (a1 a2) (equal (car a1) (car a2)))))
)
(provide 'haskell-tng-imenu)
diff --git a/test/haskell-tng-imenu-test.el b/test/haskell-tng-imenu-test.el
index 7a54cd0..624c0ab 100644
--- a/test/haskell-tng-imenu-test.el
+++ b/test/haskell-tng-imenu-test.el
@@ -13,16 +13,17 @@
(ert-deftest haskell-tng-lexer-file-tests:layout ()
(should (have-expected-imenu (testdata "src/layout.hs"))))
+(ert-deftest haskell-tng-lexer-file-tests:indentation ()
+ (should (have-expected-imenu (testdata "src/indentation.hs"))))
+
(defun have-expected-imenu (file)
(haskell-tng--testutils-assert-file-contents
file
#'haskell-tng-mode
(lambda ()
- (imenu "*Rescan*")
- (let ((entries imenu--index-alist))
- (with-temp-buffer
- (pp entries (current-buffer))
- (buffer-string))))
+ (imenu "module")
+ (with-output-to-string
+ (pp imenu--index-alist)))
"imenu"))
(provide 'haskell-tng-imenu-test)
diff --git a/test/src/indentation.hs.imenu b/test/src/indentation.hs.imenu
new file mode 100644
index 0000000..1dd5a55
--- /dev/null
+++ b/test/src/indentation.hs.imenu
@@ -0,0 +1,22 @@
+(("module" . 486)
+ ("imports" . 512)
+ ("basic_do" . 609)
+ ("nested_do" . 903)
+ ("nested_where" . 1028)
+ ("let_in" . 1262)
+ ("implicit_let" . 1334)
+ ("case_of" . 1402)
+ ("lambda_case" . 1481)
+ ("dollars" . 1540)
+ ("not_dollars" . 1613)
+ ("lists1" . 2020)
+ ("lists2" . 2118)
+ ("lists3" . 2144)
+ ("tuples1" . 2179)
+ ("tuples2" . 2283)
+ ("tuples3" . 2310)
+ ("typesig" . 2347)
+ ("types1" . 2371)
+ ("types2" . 2416)
+ ("types2b" . 2474)
+ ("types3" . 2535))
diff --git a/test/src/layout.hs.imenu b/test/src/layout.hs.imenu
index b6b2fda..850c08d 100644
--- a/test/src/layout.hs.imenu
+++ b/test/src/layout.hs.imenu
@@ -1 +1,5 @@
-(("*Rescan*" . -99))
+(("module" . 43)
+ ("push" . 151)
+ ("size" . 207)
+ ("pop" . 371)
+ ("top" . 490))
- [nongnu] elpa/haskell-tng-mode e1c0f0a 179/385: allow indentation option to be tested, (continued)
- [nongnu] elpa/haskell-tng-mode e1c0f0a 179/385: allow indentation option to be tested, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1cceb64 182/385: cleaner tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b1122e4 188/385: allow users to use unsupported build tools, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode bd4ff6f 192/385: standardise on naming convention:, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3b5ac7f 190/385: package-lint, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a227f7e 200/385: blank lines end a run of type definitions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e4ead98 201/385: thots on prettify-symbol, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 387aa18 203/385: more efficient layout algorithm, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode bfc3841 193/385: remove bind-key dependency, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6acba95 206/385: better insertion indentation on toplevels, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9bfc6bf 215/385: really basic imenu,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode f648cf9 212/385: fallback to current directory (e.g. for cabal scripts), ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5bdf688 211/385: better in-line indentation of parens, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1cdf901 120/385: better escape syntax detection, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c40c6e6 125/385: fix explicit export fontification bug, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 82312a2 126/385: working compilation matchers, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 794c80b 131/385: better indentation alts, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d43fd73 141/385: more efficient indentation 'insert test, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a830fcb 135/385: reindention test, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode aa2a0ad 146/385: prefer --enable-tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a754020 144/385: indent alts will suggest based on previous <- lines, ELPA Syncer, 2021/10/06