imenu-extra icon indicating copy to clipboard operation
imenu-extra copied to clipboard

Add extra items into lsp-mode/js2-mode imenu items

  • Add extra items into existing imenu items Extra imenu items can be easily added into existing imenu items generated by major/minor modes ([[https://github.com/emacs-lsp/lsp-mode/][lsp-mode]], [[https://github.com/mooz/js2-mode][js2-mode]], etc).

[[file:demo.png]]

  • Install and Setup You could place =imenu-extra.el= under [[https://www.emacswiki.org/emacs/LoadPath][Load Path]], then add =(require 'imenu-extra)= to your configuration.

But I recommend to use [[http://melpa.org/]] to install the package.

Setup is simple,

At the end of minor/major mode hook, call =imenu-extra-auto-setup= which has one parameter "patterns".

Patterns should be an =alist= of the same form as =imenu-generic-expression=.

For example, insert below code at the end of =js2-mode-hook= to extract unit test case as imenu items from javascript code, #+begin_src elisp (add-hook 'js2-mode-hook (lambda () ;; original js2-mode setup ...

        ;; at the end of mode hook
        (require 'imenu-extra)
        (imenu-extra-auto-setup '(("tdd.it" "^[ \t]*it('\\([^']+\\)" 1)
                                  ("tdd.desc" "^[ \t]*describe('\\([^']+\\)" 1))))

#+end_src

  • Usage Use imenu as usual.
  • Tips
  • Set =imenu-extra-process-item-function= to process extra imenu items
  • Contact me Report bugs at [[https://github.com/redguardtoo/imenu-extra]].
  • License This program is free software: you can redistribute it and/or modify it under the terms of the [[file:LICENSE][GNU General Public License]] as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [[file:LICENSE][GNU General Public License]] for more details.