1

I'm trying to add support for imenu in a major mode I currently writing.
Reading documentation I've found that its API looks simple and all I want to do is to write a function and bind it to imenu-create-index-function.

Documentation for imenu--index-alist also declares something called nested sub-alist:

A nested sub-alist element looks like (INDEX-NAME . SUB-ALIST). The function ‘imenu--subalist-p’ tests an element and returns t if it is a sub-alist.

Does it mean that one could make imenu have nested structure like?

- index 1
  - sub-index
    - ...
- index 2

I've tried to return following from funciton bound to imenu-create-index-function:

'(("item 1" . '(("sub-item" . 1))) ("item 2" . 1))

And error says that it violates integer-or-marker-p at '(("sub-item" . 1)).

If nested structures are possible, how to form them?

1 Answer 1

2

It is possible to represent structured menu with imenu.

A valid alist shape could be:

(list
 (list "Title 1"
       (list "Title 11"
             '("Index Name 1" . 1)
             '("Index Name 2" . 1)))
 (list "Title 2"
       '("Index Name 21" . 1)
       '("Index Name 22" . 1)))

The error was caused by quoting of '(("sub-item" . 1)) form.

1
  • But how do you have the items that have both the marker and the nested items? In the example you provided you'd be able to jump to nested children but not "Title 1" itself
    – iLemming
    Nov 26, 2023 at 18:13

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.