With the PHP-mode that's shipped with Emacs, suppose I have the following PHP function:

public function foo() 
    print "bar";

Imenu will list the foo in all methods and public methods.

Other packages like Helm and Ido use the same Imenu, which causes my functions to be double listed. When I call helm-imenu that uses the imenu source, I see my functions double listed.

It gets listed in helm-imenu as All methods / foo and public methods / foo. I see the same in ido-imenu. I would like to reduce that to only the methods get listed once, instead double. And in Emacs nearly everything is scriptable, right?

To make it more clear what I'm meaning, a screenshot:

enter image description here

Sometimes it makes it very confusing for me, when navigating around in the codebase.

So any suggestion how I could handle this?

  • 1
    You should add a link to the php mode you are using, because the solution depends on the way the imenu is created.
    – politza
    Commented Feb 7, 2016 at 20:11
  • Do you mean the php-mode that's get shipped with Emacs?
    – ReneFroger
    Commented Feb 8, 2016 at 15:16
  • 1
    php-mode does not ship with Emacs. Commented Feb 11, 2016 at 21:22

1 Answer 1


Vanilla imenu presents things hierarchically, so you'd first have to choose between Public/Private/All functions, before you actually chose from a list of actual function. However, this is confusing with other imenu frontends that show them all at the same time.

There are distinct entries in the imenu-generic-expression value that php-mode defines for private, protected, public, and all functions. You could remove the "all" entry or remove the private, protected, and public entries to make things appear once.

For example this will remove the "All Methods" category from imenu in php-mode.

(with-eval-after-load "php-mode"
  (add-hook 'php-mode-hook
            (defun my-php-mode-hook ()
              (setq-local imenu-generic-expression
                     (lambda (entry) (equal (car entry) "All Methods"))

You may want to look at the definition of php-imenu-generic-expression to better understand what the hook is doing.

  • You still amaze me with your solutions. I checked the documentation of imenu, but found nothing satisfying that addressed my issue. How did you find such ways to a solution? (As in, how do you knew the php-imenu-generic-expression was the key to this?)
    – ReneFroger
    Commented Feb 12, 2016 at 9:29
  • 1
    imenu-generic-expression always drives imenu entries, so if php-mode supports imenu, it must customize imenu-generic-expression. So I opened php-mode and searched for imenu-generic-expressions to see what it sets the variable as. Commented Feb 12, 2016 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.