Add extra items into existing imenu items
Extra imenu items can be easily added into existing imenu items generated by major/minor modes (lsp-mode, js2-mode, etc).
Install and Setup
You could place imenu-extra.el
under 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,
(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))))
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 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 GNU General Public License for more details.