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

To reply to this bug, email your comments to 76443 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to rahul.juliato <at> gmail.com, casouri <at> gmail.com, bug-gnu-emacs <at> gnu.org:
bug#76443; Package emacs. (Thu, 20 Feb 2025 18:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to rahul.juliato <at> gmail.com, casouri <at> gmail.com, bug-gnu-emacs <at> gnu.org. (Thu, 20 Feb 2025 18:03:02 GMT) Full text and rfc822 format available.

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))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76443; Package emacs. (Fri, 21 Feb 2025 05:55:02 GMT) Full text and rfc822 format available.

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

From: Yuan Fu <casouri <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Rahul Martim Juliato <rahul.juliato <at> gmail.com>, 76443 <at> debbugs.gnu.org
Subject: Re: bug#76443: Imenu in markdown-ts-mode
Date: Thu, 20 Feb 2025 21:54:01 -0800

> On Feb 20, 2025, at 9:59 AM, Juri Linkov <juri <at> linkov.net> wrote:
> 
> 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))

Thanks Juri. FWIW, if we can accomplish it with regex only, then let’s keep it simple and use regex. markdown-ts-imenu-node-p just compares the node type to a string, it doesn’t even need a regex.

Yuan



Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 22 Feb 2025 23:59:03 GMT) Full text and rfc822 format available.

This bug report was last modified 112 days ago.

Previous Next


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