0

For markdown-modes I activate

(imenu-add-menubar-index)
(setq-local imenu-auto-rescan t)

This gives me a nice index to navigate by headlines. Sub-headings are nested. And this is my issue.

If I have a markdown file like

# Heading 1
# Heading 2
## Heading 2.1
# Heading 3

In the index entries get sorted as

Heading 2 >
Heading 1
Heading 3

with > indicating, that there are sub-entries.

The Documentation reads:

You can customize the way the menus are sorted by setting the variable imenu-sort-function. By default, names are ordered as they occur in the buffer;

Alas, that doesn't seem true, see the result. For a file of type markdown, sorting entries other than order of appearance in a buffer is counter-intuitive.

Do I have a chance to influence the sort-order?

1
  • If you can repro the problem starting with emacs -Q (no init file), then consider filing a bug report (e.g., saying that the doc is wrong): M-x report-emacs-bug. Commented Feb 24 at 22:23

1 Answer 1

0

Dunno whether Imenu+ will help you, but it might. It has no specific behavior for Markdown buffers, but assuming that the usual, general Imenu behavior is sufficient it should help.

Unlike vanilla Imenu, by default Imenu+ sorts by name, not by buffer order. You can change that by customizing the value of option imenu-sort-function to nil.

You can anyway change the sort order anytime interactively using command imenup-toggle-sort or choosing Toggle Sorting from the menu.

The library is here: https://www.emacswiki.org/emacs/download/imenu%2b.el. Just put it in your load-path and put (require 'imenu+) in your init file.

(And whether you use vanilla imenu.el or library imenu+.el, you can set option imenu-sort-function to a sort function that you define.)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.