branch: elpa/haskell-tng-mode commit b7cb5b91a57aa6c9d4215a7379edadb06c2df638 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
starting to create imenu --- README.md | 4 +++- haskell-tng-imenu.el | 22 ++++++++++++++++++++++ haskell-tng-mode.el | 9 +++++++-- test/haskell-tng-imenu-test.el | 29 +++++++++++++++++++++++++++++ test/src/layout.hs.imenu | 1 + 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1fa039..6de2218 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ Giving the following commands - `C-- C-c c` clean project - `C-c e` jump to error +Built-in navigation commands such as `forward-symbol`, `forward-sexp` and `imenu` work as expected (although [`popup-imenu`](https://github.com/ancane/popup-imenu) is recommended). + ## Contrib Integrations are provided for common libraries (installed separately), enable them from `use-package` with @@ -103,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 + - [ ] `imenu` population (IN PROGRESS) - Editing: - [x] indentation - [x] `prettify-symbols` to emulate `UnicodeSyntax` diff --git a/haskell-tng-imenu.el b/haskell-tng-imenu.el new file mode 100644 index 0000000..4ab1a56 --- /dev/null +++ b/haskell-tng-imenu.el @@ -0,0 +1,22 @@ +;;; haskell-tng-imenu.el --- imenu support -*- lexical-binding: t -*- + +;; Copyright (C) 2019 Tseen She +;; License: GPL 3 or any later version + +;;; Commentary: +;; +;; Creates a summary of the current file for navigation purposes. +;; +;;; Code: + +(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)) + ) + +(provide 'haskell-tng-imenu) +;;; haskell-tng-imenu.el ends here diff --git a/haskell-tng-mode.el b/haskell-tng-mode.el index eb3ec62..2c33e6c 100644 --- a/haskell-tng-mode.el +++ b/haskell-tng-mode.el @@ -15,12 +15,14 @@ ;;; Code: (require 'dabbrev) +(require 'imenu) (require 'rx) -(require 'haskell-tng-syntax) +(require 'haskell-tng-compile) (require 'haskell-tng-font-lock) +(require 'haskell-tng-imenu) (require 'haskell-tng-smie) -(require 'haskell-tng-compile) +(require 'haskell-tng-syntax) (defgroup haskell-tng () "Haskell support: The Next Generation." @@ -72,6 +74,9 @@ Load `prettify-symbols-mode' in `haskell-tng-mode-hook'." font-lock-multiline t font-lock-extend-region-functions haskell-tng--font-lock-extend-region-functions + imenu-auto-rescan t + imenu-create-index-function #'haskell-tng--imenu-create + prettify-symbols-alist haskell-tng-prettify-symbols) ;; whitespace is meaningful, disable electric indentation. Note that diff --git a/test/haskell-tng-imenu-test.el b/test/haskell-tng-imenu-test.el new file mode 100644 index 0000000..7a54cd0 --- /dev/null +++ b/test/haskell-tng-imenu-test.el @@ -0,0 +1,29 @@ +;;; haskell-tng-imenu-test.el --- Tests for imenu generation -*- lexical-binding: t -*- + +;; Copyright (C) 2019 Tseen She +;; License: GPL 3 or any later version + +(require 'ert) + +(require 'haskell-tng-mode) + +(require 'haskell-tng-testutils + "test/haskell-tng-testutils.el") + +(ert-deftest haskell-tng-lexer-file-tests:layout () + (should (have-expected-imenu (testdata "src/layout.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")) + +(provide 'haskell-tng-imenu-test) +;;; haskell-tng-imenu-test.el ends here diff --git a/test/src/layout.hs.imenu b/test/src/layout.hs.imenu new file mode 100644 index 0000000..b6b2fda --- /dev/null +++ b/test/src/layout.hs.imenu @@ -0,0 +1 @@ +(("*Rescan*" . -99))