emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]