I feel like something is wrong with my Imenu setup, because here is what it shows on a simple Python script:

enter image description here

It seems to show some variable definitions, but doesn't have separate entries for the function definitions (the def ... lines), or the classes. What I want is an Imenu that shows just the function and class definitions, in the order in which they appear. So, I want to see something like:

Function: foo(x)
Class: Bar
Function: Bar / __init__(s)
Function: Bar / buz(x, y)

Is that possible at all? Semantic is not an option because it does not parse functions that are typed using Python's type annotations (e.g. a function like def foo() -> None: ... does not appear in the list).

  • 1
    Can you share your imenu configuration? Are you using a LSP, or maybe elpy? Please share more information. Oct 12, 2020 at 9:26
  • I am using LSP, yes, but I have lsp-ui-imenu-enable nil and no other imenu-related entries in my init.el Oct 12, 2020 at 19:12

2 Answers 2


For any imenu problem, check the buffer's how-to-generate-imenu status (which is usually modified by major-mode, sometimes also some minor modes), mostly variable imenu-create-index-function and imenu-generic-expression:

  • if imenu-create-index-function is imenu-default-create-index-function, which is Emacs default, the imenu is generated by running the regexps in imenu-generic-expression against buffer content, then you only need to tweak the regexps.
  • if imenu-create-index-function is NOT imenu-default-create-index-function, then you need to dive into the actual value of imenu-create-index-function (which is a function, probably written and set by major mode) to see what's actually going wrong.
  • How do I check the how-to-generate-imenu status? Oct 12, 2020 at 19:12
  • <kbd>C-h v</kbd> (describe-variable) to check the values of the 2 variables I mentioned above (also read the documents there, which along with my answer above should give you the idea of how imenu works).
    – JJPandari
    Oct 13, 2020 at 2:55

This is lsp-mode issue, which was reported and closed as wont fix. I have a better idea of how to fix it, so you may open issue lsp-mode bug tracker.


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.