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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: wishlist; Reported by: Juri Linkov <juri@HIDDEN>; dated Thu, 20 Feb 2025 18:03:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 76443 <at> debbugs.gnu.org:


Received: (at 76443) by debbugs.gnu.org; 21 Feb 2025 05:54:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 21 00:54:23 2025
Received: from localhost ([127.0.0.1]:50113 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tlLzS-0003Mg-Ur
	for submit <at> debbugs.gnu.org; Fri, 21 Feb 2025 00:54:23 -0500
Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:55433)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1tlLzQ-0003LU-AE
 for 76443 <at> debbugs.gnu.org; Fri, 21 Feb 2025 00:54:20 -0500
Received: by mail-pj1-x1035.google.com with SMTP id
 98e67ed59e1d1-2fc0bd358ccso3552415a91.2
 for <76443 <at> debbugs.gnu.org>; Thu, 20 Feb 2025 21:54:20 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1740117254; x=1740722054; darn=debbugs.gnu.org;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:from:to:cc:subject:date
 :message-id:reply-to;
 bh=/KKrtpWXzlLUichDTmPeojGTOpEFFRSnJtttNc7NACg=;
 b=WzQupn2ssXSH0Ue6hUZAaNewpiXJa8XlmAAWlMjA/bea+8kknZiFTvClGCyDpXWieW
 eKf+tIhSqRtq3xRqSgeP+fEiNBPpU12qqJAjeSsYLl6sLzPXoFOK/Vu9YJCcEIP4hyQJ
 IWYLFw6yu/yII6sqc3YtY/iB2FhNnW6deWbvs0OA0RFpOJhckbbWvcvD5vuePLv9QgLf
 ix+ayVwN2EhTjgdbNPvTnWB38LZraFQLFbCs/6lnGfSYk2MPxdviDJvhAmslKHi/xmCk
 VeLGOdaiAjSN8/0AAnWXIDctMcQ0qVSm4fpF0hNbqSg6TiJxshON6pbGnx/oKplGaEly
 DDzw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1740117254; x=1740722054;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=/KKrtpWXzlLUichDTmPeojGTOpEFFRSnJtttNc7NACg=;
 b=R8oKZZoiUxMgOuNGQvvLBzmFFXqBsO9NhIQtcg/aHp25g4RyHHMQW1K/z7vKOYZ3d+
 q76rtZZssZiw3IZ8U2FQ6CJfHsuE3xaHLJ9BnfDIf9YaxuaE2csdLiEAQUUQf6e3S/Im
 QJruJQOgPKiiFDtdFkZAnnAy3H6890Xqll0PCA3qGJh24nES01FTu5mrcSpOimRS6zTm
 oPTIKByW7hzE2VTAGGhr0MjNW3LrVRcuLXkiJZzRyJDtYQ3lde0hgK2Dr5mOFKKgO4Rp
 IoE8DjPeG5989jLOKl66iJ4DbqKZaINLi3b1fsIidjk7x1HOYEv8Dk1WGJNRBXUB0G2s
 RdNQ==
X-Gm-Message-State: AOJu0Yzi4lx/8HuhDeAjDoyhqp/DC8hROIAyxj3QfVxEnCxhC5BgRlYr
 ATw9OLaWHv1A/2b6kmxQlXcdxml14ffttkbDFN6wbGzQyXjiAhsg
X-Gm-Gg: ASbGnctFDLgtM6ZoGBs54Vj6Ous9dXtDSFTBnGiEiZ+U+MSCsheGbIbZNp4BUDrzksu
 hA8KRP2nRPZJ7NMquJPAG1x18EkS3PGNQBhayzCvh6McZ8CnsPNFmV+hi/s7lcjNJFPnyEvQLLU
 krNWRqekK/eYXPgouDyfePmffG9Xyh2lJM7y1t8gJZVV6N9M9WZEsITZUNeQgUyp68h8dU5q+16
 ZqIZ2WeNuoAkm6jPqkELVICiTJZnbsZSTKw7K8PL3Cozvd0HxU/bsBfGIWt+J4SbB9zwlIA1ngb
 Uuz5qwziY5zTJu+RdMc95+te1DztiPFky2AFlgZDh5ZJ7MmmLA==
X-Google-Smtp-Source: AGHT+IGhCQhjWs/U3Onz7HUxpaAFHjEl7LUIfgsMVOtDfAhFu7hcyzO2SroIA64OBDAUcEzGTsH0Ag==
X-Received: by 2002:a17:90b:2d4e:b0:2ee:db1a:2e3c with SMTP id
 98e67ed59e1d1-2fce779bc35mr3023231a91.1.1740117253916; 
 Thu, 20 Feb 2025 21:54:13 -0800 (PST)
Received: from smtpclient.apple ([2601:646:8f81:6120:9c39:a9fb:7754:17f8])
 by smtp.gmail.com with ESMTPSA id
 98e67ed59e1d1-2fceb049964sm434489a91.13.2025.02.20.21.54.12
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 20 Feb 2025 21:54:13 -0800 (PST)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\))
Subject: Re: bug#76443: Imenu in markdown-ts-mode
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <87seo8wl85.fsf@HIDDEN>
Date: Thu, 20 Feb 2025 21:54:01 -0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <B6A67F74-5D29-434C-B830-D506FA9A98B5@HIDDEN>
References: <87seo8wl85.fsf@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
X-Mailer: Apple Mail (2.3776.700.51)
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: 76443
Cc: Rahul Martim Juliato <rahul.juliato@HIDDEN>, 76443 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.3 (/)



> On Feb 20, 2025, at 9:59=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
> markdown-ts-mode uses the function as the second element of
> treesit-simple-imenu-settings:
>=20
>  (setq-local treesit-simple-imenu-settings
>              `(("Headings" markdown-ts-imenu-node-p nil =
markdown-ts-imenu-name-function)))
>=20
> This breaks treesit-outline-predicate--from-imenu since it expects =
only a string.
>=20
> 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:
>=20
>  REGEXP should be a regexp matching the type of nodes that
>  belong to CATEGORY.
>=20
> So there is two possible variants:
>=20
> 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.
>=20
> 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=E2=80=
=99s keep it simple and use regex. markdown-ts-imenu-node-p just =
compares the node type to a string, it doesn=E2=80=99t even need a =
regex.

Yuan=




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#76443; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 20 Feb 2025 18:02:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 20 13:02:03 2025
Received: from localhost ([127.0.0.1]:40257 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tlAs6-0000Ay-4z
	for submit <at> debbugs.gnu.org; Thu, 20 Feb 2025 13:02:02 -0500
Received: from lists.gnu.org ([2001:470:142::17]:45902)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tlAs4-00008X-4L
 for submit <at> debbugs.gnu.org; Thu, 20 Feb 2025 13:02:00 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1tlArS-0002pF-A8
 for bug-gnu-emacs@HIDDEN; Thu, 20 Feb 2025 13:01:26 -0500
Received: from relay7-d.mail.gandi.net ([217.70.183.200])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1tlArJ-0000Zn-49
 for bug-gnu-emacs@HIDDEN; Thu, 20 Feb 2025 13:01:19 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id F2879441DB
 for <bug-gnu-emacs@HIDDEN>; Thu, 20 Feb 2025 18:00:47 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: Imenu in markdown-ts-mode
Organization: LINKOV.NET
X-Debbugs-Cc: Rahul Martim Juliato <rahul.juliato@HIDDEN>,  Yuan Fu
 <casouri@HIDDEN>
Date: Thu, 20 Feb 2025 19:59:38 +0200
Message-ID: <87seo8wl85.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-State: clean
X-GND-Score: 0
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeijeejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucenucfjughrpefhvffuohffkfgfgggtsehttdertddtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepjefggfdttdfhleetjeekjeeugedvkefgudffgfdthedvtdekteevhefgffejueetnecukfhppeeluddruddvledrleeirdeiieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledrleeirdeiiedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopedupdhrtghpthhtohepsghughdqghhnuhdqvghmrggtshesghhnuhdrohhrgh
X-GND-Sasl: juri@HIDDEN
Received-SPF: pass client-ip=217.70.183.200; envelope-from=juri@HIDDEN;
 helo=relay7-d.mail.gandi.net
X-Spam_score_int: -25
X-Spam_score: -2.6
X-Spam_bar: --
X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7,
 RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.3 (/)

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




Acknowledgement sent to Juri Linkov <juri@HIDDEN>:
New bug report received and forwarded. Copy sent to rahul.juliato@HIDDEN, casouri@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to rahul.juliato@HIDDEN, casouri@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#76443; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 23 Feb 2025 00:00:02 UTC

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