Marcel's blog

Nested Imenu for PHP

I wanted an easy way to navigate a PHP file full of object-oriented class definitions in Emacs. My search for such a tool turned up php-mode integration with imenu. Imenu allows modes to generate menus of structural elements in a file, where selecting an element jumps to to its location in the file.

But php-mode separates the list of functions from the list of classes. The list of functions is often way too long, and it's not clearly organized by class.

I wanted imenu to show functions in a class. It already supports hierarchy. So I hacked together an implementation of imenu-create-index-function that did what I wanted. Here it is: php-imenu.el

Screen Shot Menu generated for PEAR code

It's worked great on the PHP I've thrown at it, but patches are welcome to support other coding styles, etc.

  1. Lennart says:

    Hi Marcel,

    I just grabbed a copy of php-imenu.el to distribute with nXhtml. Is that ok for you?

    Any suggestions for how to set it up there? Should I perhaps modify the copy of php-mode.el that I have their? (BTW did you contact the author of php-mode.el?)

  2. Marcel says:


    Yes, I'd love to see php-imenu.el's functionality included with nxhtml-mode. I intend to submit a patch to php-mode, but haven't yet integrated the code in php-imenu.el with php-mode.el. Until it's integrated and released, it might be easiest to just drop php-imenu.el into your nXhtml distro along-side php-mode.el.

Post a comment

Name or OpenID (required)

(lesstile enabled - surround code blocks with ---)