Skip to content

Instantly share code, notes, and snippets.

@johnmastro
Created July 29, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmastro/53535e8cbddf7c669788bc2a9105f70e to your computer and use it in GitHub Desktop.
Save johnmastro/53535e8cbddf7c669788bc2a9105f70e to your computer and use it in GitHub Desktop.
Example in a discussion on help-gnu-emacs
;;; perl6-imenu.el --- Imenu support Perl 6 -*- lexical-binding: t; -*-
;;; fragment
;; Imenu functions and variables are defined here.
;; a new definition of the Variables entry regex:
(defconst perl6-vars
(concat
"^\\s-*" ; leading ws allowed
"\\(?:my\\|our\\)\\s-+" ; scope of var, followed by mandatory ws
"\\(" ; start capture group 1 for the var name
"\\(?:\\$\\|@\\|%\\)" ; sigil for type of var
"\\(?:[_[:alnum:]]+\\)" ; the var name ends with ws
"\\)" ; end of capture group 1
))
;; now subsitute the var above in the var below to replace the explicit regex
(defvar perl6-imenu-generic-expression
`(
;; the names are in reverse desired order since they are evaluated here last first
;;("Variables" "^\\s-*\\(?:my\\|our\\)\\s-+\\(\\(?:\\$\\|@\\|%\\)\\(?:[_[:alnum:]]+\\)\\)" 1)
("Variables" ,perl6-vars 1)
("Subs/Methods" "^\\s-*\\(?:my\\s-+\\|our\\s-+\\)?\\(?:multi\\s-+sub\\|multi\\s-+method\\|sub\\|method\\|multi\\)\\s-+\\(.+)\\)" 1)
))
;; Add imenu support for perl6-mode. Note that imenu-generic-expression
;; is buffer-local, so we don't need a local-variable for it.
(setq imenu-generic-expression perl6-imenu-generic-expression
imenu-case-fold-search nil)
;; Imenu support
(setq imenu-auto-rescan t)
(add-hook 'perl6-mode-hook 'imenu-add-menubar-index)
(add-hook 'perl6-mode-hook
(lambda ()
(setq imenu-generic-expression perl6-imenu-generic-expression)))
;;===========================
(provide 'perl6-imenu)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment