Skip to content

Instantly share code, notes, and snippets.

@atelic
Last active October 23, 2015 17:16
Show Gist options
  • Save atelic/4d7988f35c00826a82e5 to your computer and use it in GitHub Desktop.
Save atelic/4d7988f35c00826a82e5 to your computer and use it in GitHub Desktop.
Get mocha test keywords to show in Emacs imenu
(defun js2-imenu-make-index ()
(save-excursion
(imenu--generic-function '(("describe" "\\s-*describe\\s-*([\"']\\(.+\\)[\"']\\s-*,.*" 1)
("it" "\\s-*it\\s-*([\"']\\(.+\\)[\"']\\s-*,.*" 1)
("before" "\\s-*before\\s-*([\"']\\(.+\\)[\"']\\s-*,.*" 1)
("after" "\\s-*after\\s-*([\"']\\(.+\\)[\"']\\s-*,.*" 1)
;;add more keyword for mocha here
("Function" "function[ \t]+\\([a-zA-Z0-9_$.]+\\)[ \t]*(" 1)
("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*=[ \t]*function[ \t]*(" 1)))))
(add-hook 'js2-mode-hook
(lambda ()
(setq imenu-create-index-function 'js2-imenu-make-index)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment