Skip to content

treemacs-tag-follow-mode is broken when imenu-create-index-function returns positions rather than markers #1178

@bcc32

Description

@bcc32

(I think this is similar to #132 which was closed for inactivity.)

For major modes with imenu backends that return positions rather than markers, treemacs-tag-follow-mode breaks and messages the following error repeatedly:

  [Treemacs] Encountered error while following tag at point: (wrong-type-argument markerp 138) [2 times]

This is because treemacs--compare-tag-paths assumes the positions in imenu--index-alist are specifically markers rather than just positions (ints). I think this function should not make this assumption. The docstring of imenu--index-alist does not require markers, and indeed eglot-imenu is an example of a prominent imenu backend function that produces positions, not markers.

BTW, < can be used on markers and will automatically do the equiavlent of calling marker-position if necessary. This function can be written simply as:

(define-inline treemacs--compare-tag-paths (p1 p2)
  "Compare two tag paths P1 & P2 by the position of the tags they lead to.
Used to sort tag paths according to the order their tags appear in.

P1: Tag-Path
P2: Tag-Path"
  (declare (pure t) (side-effect-free t))
  (inline-letevals (p1 p2)
    (inline-quote
     (< (-> ,p1 (cdar))
        (-> ,p2 (cdar))))))

(I'm not familiar with the inline library so I just did what seemed intuitively right. It works on my machine, but feel free to implement a different bugfix if you prefer.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions