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



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.