GNU bug report logs - #76443
Imenu in markdown-ts-mode

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Thu, 20 Feb 2025 18:03:01 UTC

Severity: wishlist

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Imenu in markdown-ts-mode
Date: Thu, 20 Feb 2025 19:59:38 +0200
markdown-ts-mode uses the function as the second element of
treesit-simple-imenu-settings:

  (setq-local treesit-simple-imenu-settings
              `(("Headings" markdown-ts-imenu-node-p nil markdown-ts-imenu-name-function)))

This breaks treesit-outline-predicate--from-imenu since it expects only a string.

So I tried to fix this with the patch below.  But then noticed that the
REGEXP element of treesit-simple-imenu-settings is documented only as
a string:

  REGEXP should be a regexp matching the type of nodes that
  belong to CATEGORY.

So there is two possible variants:

1. Support a function by applying this patch and changing the
documentation of treesit-simple-imenu-settings;
2. Maybe markdown-ts-mode doesn't need to use a function
and it should be sufficient to use just "section" as string.
Then markdown-ts-imenu-name-function can extract "atx_heading" from it.

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 30efd4d4599..6eaa7a761e3 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -3611,7 +3611,10 @@ treesit-outline-predicate--from-imenu
   ;; you can directly set a proper value to `treesit-outline-predicate'.
   (seq-some
    (lambda (setting)
-     (and (string-match-p (nth 1 setting) (treesit-node-type node))
+     (and (or (and (stringp (nth 1 setting))
+                   (string-match-p (nth 1 setting) (treesit-node-type node)))
+              (and (functionp (nth 1 setting))
+                   (funcall (nth 1 setting) node)))
           (or (null (nth 2 setting))
               (funcall (nth 2 setting) node))))
    treesit-simple-imenu-settings))




This bug report was last modified 113 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.