GNU logs - #77256, boring messages


Message sent to casouri@HIDDEN, v.pupillo@HIDDEN, bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: casouri@HIDDEN, v.pupillo@HIDDEN, bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 25 Mar 2025 18:44:02 +0000
Resent-Message-ID: <handler.77256.B.174292822513368 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: 77256 <at> debbugs.gnu.org
Cc: Yuan Fu <casouri@HIDDEN>,  Vincenzo Pupillo <v.pupillo@HIDDEN>
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
X-Debbugs-Original-Xcc: Yuan Fu <casouri@HIDDEN>,  Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by submit <at> debbugs.gnu.org id=B.174292822513368
          (code B ref -1); Tue, 25 Mar 2025 18:44:02 +0000
Received: (at submit) by debbugs.gnu.org; 25 Mar 2025 18:43:45 +0000
Received: from localhost ([127.0.0.1]:39995 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tx9FY-0003TX-Pq
	for submit <at> debbugs.gnu.org; Tue, 25 Mar 2025 14:43:45 -0400
Received: from lists.gnu.org ([2001:470:142::17]:56234)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tx9FV-0003TA-Qd
 for submit <at> debbugs.gnu.org; Tue, 25 Mar 2025 14:43:42 -0400
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 1tx9FO-0001qO-O2
 for bug-gnu-emacs@HIDDEN; Tue, 25 Mar 2025 14:43:34 -0400
Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1tx9FL-0001ja-F1
 for bug-gnu-emacs@HIDDEN; Tue, 25 Mar 2025 14:43:34 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id B5304441C0
 for <bug-gnu-emacs@HIDDEN>; Tue, 25 Mar 2025 18:43:23 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
Date: Tue, 25 Mar 2025 20:42:02 +0200
Message-ID: <87a5990x6t.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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieefgedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufhofffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeejgffgtddthfelteejkeejueegvdekgfdufffgtdehvddtkeetveehgfffjeeuteenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepuddprhgtphhtthhopegsuhhgqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhg
X-GND-Sasl: juri@HIDDEN
Received-SPF: pass client-ip=2001:4b98:dc4:8::222;
 envelope-from=juri@HIDDEN; helo=relay2-d.mail.gandi.net
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001,
 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-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 (/)

Do we still need such complicated functions as
mhtml-ts-mode--language-at-point, js--treesit-language-at-point, etc.
that duplicate the rules from 'treesit-range-rules'
when now the default language-at-point function could be implemented
just as

  (treesit-parser-language
   (or (seq-some (lambda (o) (overlay-get o 'treesit-parser))
                 (overlays-at (point) t))
       treesit-primary-parser))




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Juri Linkov <juri@HIDDEN>
Subject: bug#77256: Acknowledgement (Treesit language-at-point)
Message-ID: <handler.77256.B.174292822513368.ack <at> debbugs.gnu.org>
References: <87a5990x6t.fsf@HIDDEN>
X-Gnu-PR-Message: ack 77256
X-Gnu-PR-Package: emacs
Reply-To: 77256 <at> debbugs.gnu.org
Date: Tue, 25 Mar 2025 18:44:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

As you requested using X-Debbugs-CC, your message was also forwarded to
  Yuan Fu <casouri@HIDDEN>,  Vincenzo Pupillo <v.pupillo@HIDDEN>
(after having been given a bug report number, if it did not have one).

Your message has been sent to the package maintainer(s):
 bug-gnu-emacs@HIDDEN

If you wish to submit further information on this problem, please
send it to 77256 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
77256: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D77256
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Yuan Fu <casouri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 29 Mar 2025 08:27:01 +0000
Resent-Message-ID: <handler.77256.B77256.17432367653993 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Juri Linkov <juri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.17432367653993
          (code B ref 77256); Sat, 29 Mar 2025 08:27:01 +0000
Received: (at 77256) by debbugs.gnu.org; 29 Mar 2025 08:26:05 +0000
Received: from localhost ([127.0.0.1]:56688 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyRW0-00012K-NW
	for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 04:26:05 -0400
Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:55451)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1tyRVz-00011h-48
 for 77256 <at> debbugs.gnu.org; Sat, 29 Mar 2025 04:26:03 -0400
Received: by mail-pj1-x102f.google.com with SMTP id
 98e67ed59e1d1-301e05b90caso5189232a91.2
 for <77256 <at> debbugs.gnu.org>; Sat, 29 Mar 2025 01:26:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743236757; x=1743841557; 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=dc3H3BQYLJt/SYMfyz0rpgpmWhLw32naL4Dc0knb6GM=;
 b=NAmFz6T0klCWANlfDKk4j4Vl6SflSrhgMZwj0QwFh4zGX7s0CQ3pt6+Jw5BPOgDtGz
 wLK9Dwg6MYwv3k53u8Cq9PDxVisrcNq937EP97aYa5xC7V0yeBKor2U+rbrWh59Fsh/u
 eUXaXzY9uiK/6NE0KSq7gBqFkt2NCsy0xweA4UGUqCCUZVimFLbaUceMBL5EbNePbWhy
 UgaRKAbd5erG4T4pBtxNIMgL4PGDAd/gUzTrJQ08BPMCxET3pVFS0+0F/rC3QzXQN2ie
 lUdHcSEdPPGsSF9CYAA9goADtspuk9OrlTKvSL/BrgWBLxjQWDIbJbhwuyabPcxwSPl+
 wRfA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743236757; x=1743841557;
 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=dc3H3BQYLJt/SYMfyz0rpgpmWhLw32naL4Dc0knb6GM=;
 b=t/eTIxlMcalRtP5nxdF/ISeDArwtihp+IfrbdIP3Oph5eg9Ja2nGHIU+nVLMSJqcal
 NYfi+CrjlYITlXnSBJPdwTElKDMJpumsl7MlVGHWocL1IsHQZK6xmvdzqd5HfhqRkoPp
 CqQZFgax2CtzHq7PGPhc2a3G3TQYh1yAtUmKIzQDyIiQasjdodfYY5EFARrhRN8hVgE9
 TPrtx6O4ZKHHhuHn8H0MLh1o9nHa2BFmxY25l4GaUFGJ1JFp5z3VAEkOICtTgL62UFON
 ZQzf80LXMlrNpwwh09goYHuoO8rZMTBgrIuuL6YaxsOYErwzhgnf0VuBZg1vhWDCUZEd
 p0Dg==
X-Gm-Message-State: AOJu0YyY9aOpqyM4W2XO+n3OCdcSovr+XaGVtI2s5MQkdYA79M9tQlN4
 68HttSLUNK8y0ZM7amxTSn2SEzkWoKU9hb6iXZaCR/uHc4vZOQl9
X-Gm-Gg: ASbGncsCwkCc86GkC6xhbCuziVJfQD9fbg7jSDHAUKhQLcTHT8eyjp8B3npsOX8x4m5
 OqrND1dcW8uQLONjQTNC/vroqAMmwxrrRk+3cMc+0Ne7FjnIMjFBkdHu6CMQtRSh+g4xFUaKTFn
 08LCh+nz2/J4/IKfGc7Rw0z5Q6UzVqvNuH7CjCZF2RrovMQ69FswomEWT620EuCcRFzFEd1JKi0
 3JRKUVSxeuAWTDQwYsCEYUoo40wrty+ho6juMY2eBWAgKWjAOAHc/092ZbpB+QXewTNoXxRrFpa
 RIoChxqFU2dcg8av0N8Kx6toOmjsbUkeD0lxoTa//W5ZBeoAaX/W6SQjcmN+BUkHVfBr
X-Google-Smtp-Source: AGHT+IFmF9lr2L/GrfaXGtoSRzIiLg5uHOR7SRBgpl9KQzhKiLEiPLv8cmiav9W79u0RiN7ppyLTKw==
X-Received: by 2002:a17:90b:53c3:b0:305:2d9b:f8d1 with SMTP id
 98e67ed59e1d1-30532164b3cmr3780219a91.24.1743236756733; 
 Sat, 29 Mar 2025 01:25:56 -0700 (PDT)
Received: from smtpclient.apple ([2601:646:8f81:6120:b008:a4e4:1666:e0f6])
 by smtp.gmail.com with ESMTPSA id
 98e67ed59e1d1-30516d623a5sm3188537a91.25.2025.03.29.01.25.55
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Sat, 29 Mar 2025 01:25:56 -0700 (PDT)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\))
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <87a5990x6t.fsf@HIDDEN>
Date: Sat, 29 Mar 2025 01:25:44 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
References: <87a5990x6t.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3826.400.131.1.6)
X-Spam-Score: 0.0 (/)
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: -1.0 (-)



> On Mar 25, 2025, at 11:42=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
> Do we still need such complicated functions as
> mhtml-ts-mode--language-at-point, js--treesit-language-at-point, etc.
> that duplicate the rules from 'treesit-range-rules'
> when now the default language-at-point function could be implemented
> just as
>=20
>  (treesit-parser-language
>   (or (seq-some (lambda (o) (overlay-get o 'treesit-parser))
>                 (overlays-at (point) t))
>       treesit-primary-parser))

Yeah, we can provide a default language-at-point function now that =
determines the =E2=80=9Cmost relevant parser=E2=80=9D by embed level. =
But we should keep treesit-language-at-point-function because a) it=E2=80=99=
s already in a release version and b) we want major modes to be able to =
customize what parser to pick at any given point.

Yuan=




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 31 Mar 2025 17:05:01 +0000
Resent-Message-ID: <handler.77256.B77256.1743440684451 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.1743440684451
          (code B ref 77256); Mon, 31 Mar 2025 17:05:01 +0000
Received: (at 77256) by debbugs.gnu.org; 31 Mar 2025 17:04:44 +0000
Received: from localhost ([127.0.0.1]:42664 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzIZ1-00007C-DN
	for submit <at> debbugs.gnu.org; Mon, 31 Mar 2025 13:04:44 -0400
Received: from relay5-d.mail.gandi.net ([217.70.183.197]:51633)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tzIYy-00006B-MC
 for 77256 <at> debbugs.gnu.org; Mon, 31 Mar 2025 13:04:41 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 578514433C;
 Mon, 31 Mar 2025 17:04:31 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
Date: Mon, 31 Mar 2025 19:53:14 +0300
Message-ID: <87plhxw7fh.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: multipart/mixed; boundary="=-=-="
X-GND-State: clean
X-GND-Score: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukedtgeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesmhdtreertderjeenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpedtiedthfehhfetteefgfefgffftedttdefjeefveekfefgteettddutefgleethfenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopehvrdhpuhhpihhllhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeejvdehieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhm
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
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: -1.7 (-)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

>> Do we still need such complicated functions as
>> mhtml-ts-mode--language-at-point, js--treesit-language-at-point, etc.
>> that duplicate the rules from 'treesit-range-rules'
>> when now the default language-at-point function could be implemented
>> just as
>> 
>>  (treesit-parser-language
>>   (or (seq-some (lambda (o) (overlay-get o 'treesit-parser))
>>                 (overlays-at (point) t))
>>       treesit-primary-parser))
>
> Yeah, we can provide a default language-at-point function now that
> determines the “most relevant parser” by embed level. But we should keep
> treesit-language-at-point-function because a) it’s already in a release
> version and b) we want major modes to be able to customize what parser to
> pick at any given point.

Ok, so here is a complete patch:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-parsers-at.patch

diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el
index 22c0455a4ee..fdb286fc8c4 100644
--- a/lisp/textmodes/mhtml-ts-mode.el
+++ b/lisp/textmodes/mhtml-ts-mode.el
@@ -221,21 +222,6 @@ mhtml-ts-mode-menu
   "Menu bar for `mhtml-ts-mode'."
   css-mode--menu)
 
-;; To enable some basic treesiter functionality, you should define
-;; a function that recognizes which grammar is used at-point.
-;; This function should be assigned to `treesit-language-at-point-function'
-(defun mhtml-ts-mode--language-at-point (point)
-  "Return the language at POINT assuming the point is within a HTML buffer."
-  (let* ((node (treesit-node-at point 'html))
-         (parent (treesit-node-parent node))
-         (node-query (format "(%s (%s))"
-                             (treesit-node-type parent)
-                             (treesit-node-type node))))
-    (cond
-     ((equal "(script_element (raw_text))" node-query) (js--treesit-language-at-point point))
-     ((equal "(style_element (raw_text))" node-query) 'css)
-     (t 'html))))
-
 ;; Custom font-lock function that's used to apply color to css color
 ;; The signature of the function should be conforming to signature
 ;; QUERY-SPEC required by `treesit-font-lock-rules'.
@@ -448,7 +434,7 @@ mhtml-ts-mode-flymake-mhtml
 
 ;;;###autoload
 (define-derived-mode mhtml-ts-mode html-ts-mode
-  '("HTML+" (:eval (let ((lang (mhtml-ts-mode--language-at-point (point))))
+  '("HTML+" (:eval (let ((lang (treesit-language-at (point))))
                      (cond ((eq lang 'html) "")
                            ((eq lang 'javascript) "JS")
                            ((eq lang 'css) "CSS")))))
@@ -527,10 +520,6 @@ mhtml-ts-mode
       (setq-local c-ts-common--comment-regexp
                   js--treesit-jsdoc-comment-regexp))
 
-
-    ;; Many treesit functions need to know the language at-point.
-    ;; So you should define such a function.
-    (setq-local treesit-language-at-point-function #'mhtml-ts-mode--language-at-point)
     (setq-local prettify-symbols-alist mhtml-ts-mode--prettify-symbols-alist)
 
     ;; Indent.
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 54c29326df2..75c04912216 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -185,15 +185,15 @@ treesit-language-at
 This function assumes that parser ranges are up-to-date.  It
 returns the return value of `treesit-language-at-point-function'
 if it's non-nil, otherwise it returns the language of the first
-parser in `treesit-parser-list', or nil if there is no parser.
+parser from `treesit-parsers-at', or the primary parser.
 
-In a multi-language buffer, make sure
-`treesit-language-at-point-function' is implemented!  Otherwise
-`treesit-language-at' wouldn't return the correct result."
+In a multi-language buffer, optionally you can implement
+`treesit-language-at-point-function' to return more correct result."
   (if treesit-language-at-point-function
       (funcall treesit-language-at-point-function position)
-    (when-let* ((parser (car (treesit-parser-list))))
-      (treesit-parser-language parser))))
+    (treesit-parser-language
+     (or (car (treesit-parsers-at position))
+         treesit-primary-parser))))
 
 ;;; Node API supplement
 
@@ -247,8 +247,9 @@ treesit-node-at
                 (parser-or-lang
                  (let* ((local-parser (car (treesit-local-parsers-at
                                             pos parser-or-lang)))
-                        (global-parser (car (treesit-parser-list
-                                             nil parser-or-lang)))
+                        (global-parser (or (car (treesit-parsers-at
+                                                 pos parser-or-lang))
+                                           treesit-primary-parser))
                         (parser (or local-parser global-parser)))
                    (when parser
                      (treesit-parser-root-node parser))))
@@ -267,13 +268,10 @@ treesit-node-at
                         (local-parser
                          ;; Find the local parser with highest
                          ;; embed-level at point.
-                         (car (seq-sort-by #'treesit-parser-embed-level
-                                           (lambda (a b)
-                                             (> (or a 0) (or b 0)))
-                                           (treesit-local-parsers-at
-                                            pos lang))))
-                        (global-parser (car (treesit-parser-list
-                                             nil lang)))
+                         (car (treesit-local-parsers-at pos lang)))
+                        (global-parser (or (car (treesit-parsers-at
+                                                 pos lang))
+                                           treesit-primary-parser))
                         (parser (or local-parser global-parser)))
                    (when parser
                      (treesit-parser-root-node parser))))))
@@ -851,6 +849,38 @@ treesit--clip-ranges
            if (<= start (car range) (cdr range) end)
            collect range))
 
+(defun treesit-parsers-at (&optional pos language with-host local-only)
+  "Return all the non-primary parsers at POS.
+
+POS defaults to point.
+If LANGUAGE is non-nil, only return parsers for LANGUAGE.
+
+If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
+instead.  HOST-PARSER is the host parser which created the PARSER.
+
+If LOCAL-ONLY is non-nil, return only local parsers.
+Local parsers are those which only parse a limited region marked
+by an overlay with non-nil `treesit-parser' property."
+  (let ((res nil))
+    ;; Refer to (ref:local-parser-overlay) for more explanation of local
+    ;; parser overlays.
+    (dolist (ov (overlays-at (or pos (point))))
+      (when-let* ((parser (overlay-get ov 'treesit-parser))
+                  (host-parser (or (null with-host)
+                                   (overlay-get ov 'treesit-host-parser)))
+                  (_ (or (null local-only)
+                         (overlay-get ov 'treesit-parser-local-p)))
+                  (_ (or (null language)
+                         (eq (treesit-parser-language parser)
+                             language))))
+        (push (if with-host (cons parser host-parser) parser) res)))
+    (seq-sort-by (lambda (p)
+                   (treesit-parser-embed-level
+                    (or (car-safe p) p)))
+                 (lambda (a b)
+                   (> (or a 0) (or b 0)))
+                 res)))
+
 (defun treesit-local-parsers-at (&optional pos language with-host)
   "Return all the local parsers at POS.
 
@@ -862,19 +892,7 @@ treesit-local-parsers-at
 If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
 instead.  HOST-PARSER is the host parser which created the local
 PARSER."
-  (let ((res nil))
-    ;; Refer to (ref:local-parser-overlay) for more explanation of local
-    ;; parser overlays.
-    (dolist (ov (overlays-at (or pos (point))))
-      (let ((parser (overlay-get ov 'treesit-parser))
-            (host-parser (overlay-get ov 'treesit-host-parser))
-            (local-p (overlay-get ov 'treesit-parser-local-p)))
-        (when (and parser host-parser local-p
-                   (or (null language)
-                       (eq (treesit-parser-language parser)
-                           language)))
-          (push (if with-host (cons parser host-parser) parser) res))))
-    (nreverse res)))
+  (treesit-parsers-at pos language with-host t))
 
 (defun treesit-local-parsers-on (&optional beg end language with-host)
   "Return the list of local parsers that cover the region between BEG and END.
@@ -3135,9 +3159,7 @@ treesit-up-list
           (setq parent (treesit-parent-until parent pred)))
 
         (unless parent
-          (let ((parsers (seq-keep (lambda (o)
-                                     (overlay-get o 'treesit-host-parser))
-                                   (overlays-at (point) t))))
+          (let ((parsers (mapcar #'cdr (treesit-parsers-at (point) nil t))))
             (while (and (not parent) parsers)
               (setq parent (treesit-parent-until
                             (treesit-node-at (point) (car parsers)) pred)
@@ -3887,9 +3929,9 @@ treesit-simple-imenu
       (lambda (entry)
         (let* ((lang (car entry))
                (settings (cdr entry))
-               (global-parser (car (treesit-parser-list nil lang)))
-               (local-parsers
-                (treesit-parser-list nil lang 'embedded)))
+               (global-parser (or (car (treesit-parsers-at nil lang))
+                                  treesit-primary-parser))
+               (local-parsers (treesit-local-parsers-at nil lang)))
           (cons (treesit-language-display-name lang)
                 ;; No one says you can't have both global and local
                 ;; parsers for the same language.  E.g., Rust uses
@@ -4029,9 +4074,7 @@ treesit-outline-level
       (setq level (1+ level)))
 
     ;; Continue counting the host nodes.
-    (dolist (parser (seq-keep (lambda (o)
-                                (overlay-get o 'treesit-host-parser))
-                              (overlays-at (point) t)))
+    (dolist (parser (mapcar #'cdr (treesit-parsers-at (point) nil t)))
       (let* ((node (treesit-node-at (point) parser))
              (lang (treesit-parser-language parser))
              (pred (alist-get lang treesit-aggregated-outline-predicate)))

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Yuan Fu <casouri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 01 Apr 2025 00:28:03 +0000
Resent-Message-ID: <handler.77256.B77256.174346726425305 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Juri Linkov <juri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.174346726425305
          (code B ref 77256); Tue, 01 Apr 2025 00:28:03 +0000
Received: (at 77256) by debbugs.gnu.org; 1 Apr 2025 00:27:44 +0000
Received: from localhost ([127.0.0.1]:43570 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzPTi-0006Zq-Cc
	for submit <at> debbugs.gnu.org; Mon, 31 Mar 2025 20:27:44 -0400
Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:54364)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1tzPTf-0006Yc-2L
 for 77256 <at> debbugs.gnu.org; Mon, 31 Mar 2025 20:27:40 -0400
Received: by mail-pl1-x62e.google.com with SMTP id
 d9443c01a7336-2295d78b45cso3729955ad.0
 for <77256 <at> debbugs.gnu.org>; Mon, 31 Mar 2025 17:27:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743467253; x=1744072053; 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=brq+Pb+/MwrPSdOVi0p6fHfy6DtUWfBsxybcULKimYc=;
 b=JFHPyUfUYRCjAAgwCozUtsP6nnjO+oDhqqYRhNA4ck0dGiiqYW9ZXWIa4jCtGkZ//B
 EPdJ2Lkt4ohXp2lAa14+5x+bnfDItjcRQQeHcIEYNudgaSi/lIAe3TNHX4QlL4p4YWcK
 3FxCLlgfIIwl/iCii/DmuCYxbJvhF1bSDBimAdM6pszN2lfHDacDEdos99Xv45ourCzS
 P5D6tR11IQ6KhS5ka49rBsUSUQZLpcBFM44B53k6pUxzj0EIsM9Oh8iSbtVbzPovHQpb
 ZflhBtYAagHH+KpBiJG2IzwOmlAJlMsCzyGv+Mj+gooKd56XImFVBOr5RbC4PXzrgCuX
 nucg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743467253; x=1744072053;
 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=brq+Pb+/MwrPSdOVi0p6fHfy6DtUWfBsxybcULKimYc=;
 b=dQvM7PuHm/XqAT+DvDsHcW9nA//mX2bW6SloLXlz5VUyW9PxlfzQ6m1ueSbeiZPxdJ
 UHITsvivRa+EJn1wX4QrvPWYsc9RcTLEXABDqOeBCaQPIOV7Q7ZohMZe12k8wNKQQTz3
 W46i1XOI0kY0ogFpunnbq6g4exxTnosnRtY/+lFW7cMsMZyhZxvZRYCL263sYI/rp0lZ
 yjwxax3YPNltRrwANQmdS+3pRE3NUW+waU6QEpL7MhFTS7HA/fJaoIOSXuqDObp5qPhb
 hqrO4rmYg16i9XRxvECIWUX9NQ5FAQ1P48agpAvKMc2HX1IUGSGA+88P/4K5XkV/P08E
 nbKQ==
X-Gm-Message-State: AOJu0YyDZGuNO6sek92m0PuwAW5WotnNdTcnaWYfJsebRMI6VxysK9lT
 p2aSM9kMqwUr4wBiBcUjpBpAX4po7jgqDo7ER/HNFTFjSg1Fcjqq
X-Gm-Gg: ASbGncsmzGny8KSo/cjKd40sd2RUkPvWqGh3qsq98ZjnFd65JoBYSpXqhy+vVF7tkHZ
 FmY0w0h4O7e8g36H/dDnspJH/IDlT8QHUvOzksktiCiVA0YT0CWeuYhx2Fg49uS1233kW+sT58e
 nDEDBL4FLYuhFnaW+w7DxXkb0LqsQwEtrd6nTHcLjuq+27MZ9MgPXggcz0AiD64Qm331ZKzHOdL
 84LeVV+7ftpRoUjgMlbLdWk+Q9BxklH4pzwDNzGC+u/bUza3e1Fi8RCEi1KAR114njfO2FdEfdT
 hhdoejH+xqWFfSkRMnjufUZUht1norprpEGj7zNRSL1g1WYob9/MOseMm9WUGbS3E/i6WzwLvnc
 tKQ==
X-Google-Smtp-Source: AGHT+IED0JzlkIMztFDzYN1VM/p0erbcF/mqsB6sk/rRxaUIvTt3EG3lelvNherw/fmLWpj+qf8oiA==
X-Received: by 2002:a05:6a21:9214:b0:1f5:7873:304b with SMTP id
 adf61e73a8af0-2009f75b1f2mr18224964637.26.1743467252543; 
 Mon, 31 Mar 2025 17:27:32 -0700 (PDT)
Received: from smtpclient.apple ([2601:646:8f81:6120:7c76:5133:615:6915])
 by smtp.gmail.com with ESMTPSA id
 41be03b00d2f7-af93ba0df86sm6951517a12.71.2025.03.31.17.27.31
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Mon, 31 Mar 2025 17:27:31 -0700 (PDT)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\))
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <87plhxw7fh.fsf@HIDDEN>
Date: Mon, 31 Mar 2025 17:27:20 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3826.400.131.1.6)
X-Spam-Score: 0.0 (/)
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: -1.0 (-)



> On Mar 31, 2025, at 9:53=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
>>> Do we still need such complicated functions as
>>> mhtml-ts-mode--language-at-point, js--treesit-language-at-point, =
etc.
>>> that duplicate the rules from 'treesit-range-rules'
>>> when now the default language-at-point function could be implemented
>>> just as
>>>=20
>>> (treesit-parser-language
>>>  (or (seq-some (lambda (o) (overlay-get o 'treesit-parser))
>>>                (overlays-at (point) t))
>>>      treesit-primary-parser))
>>=20
>> Yeah, we can provide a default language-at-point function now that
>> determines the =E2=80=9Cmost relevant parser=E2=80=9D by embed level. =
But we should keep
>> treesit-language-at-point-function because a) it=E2=80=99s already in =
a release
>> version and b) we want major modes to be able to customize what =
parser to
>> pick at any given point.
>=20
> Ok, so here is a complete patch:

Thanks for working on this!

>=20
> diff --git a/lisp/textmodes/mhtml-ts-mode.el =
b/lisp/textmodes/mhtml-ts-mode.el
> index 22c0455a4ee..fdb286fc8c4 100644
> --- a/lisp/textmodes/mhtml-ts-mode.el
> +++ b/lisp/textmodes/mhtml-ts-mode.el
> @@ -221,21 +222,6 @@ mhtml-ts-mode-menu
>   "Menu bar for `mhtml-ts-mode'."
>   css-mode--menu)
>=20
> -;; To enable some basic treesiter functionality, you should define
> -;; a function that recognizes which grammar is used at-point.
> -;; This function should be assigned to =
`treesit-language-at-point-function'
> -(defun mhtml-ts-mode--language-at-point (point)
> -  "Return the language at POINT assuming the point is within a HTML =
buffer."
> -  (let* ((node (treesit-node-at point 'html))
> -         (parent (treesit-node-parent node))
> -         (node-query (format "(%s (%s))"
> -                             (treesit-node-type parent)
> -                             (treesit-node-type node))))
> -    (cond
> -     ((equal "(script_element (raw_text))" node-query) =
(js--treesit-language-at-point point))
> -     ((equal "(style_element (raw_text))" node-query) 'css)
> -     (t 'html))))
> -
> ;; Custom font-lock function that's used to apply color to css color
> ;; The signature of the function should be conforming to signature
> ;; QUERY-SPEC required by `treesit-font-lock-rules'.
> @@ -448,7 +434,7 @@ mhtml-ts-mode-flymake-mhtml
>=20
> ;;;###autoload
> (define-derived-mode mhtml-ts-mode html-ts-mode
> -  '("HTML+" (:eval (let ((lang (mhtml-ts-mode--language-at-point =
(point))))
> +  '("HTML+" (:eval (let ((lang (treesit-language-at (point))))
>                      (cond ((eq lang 'html) "")
>                            ((eq lang 'javascript) "JS")
>                            ((eq lang 'css) "CSS")))))
> @@ -527,10 +520,6 @@ mhtml-ts-mode
>       (setq-local c-ts-common--comment-regexp
>                   js--treesit-jsdoc-comment-regexp))
>=20
> -
> -    ;; Many treesit functions need to know the language at-point.
> -    ;; So you should define such a function.
> -    (setq-local treesit-language-at-point-function =
#'mhtml-ts-mode--language-at-point)
>     (setq-local prettify-symbols-alist =
mhtml-ts-mode--prettify-symbols-alist)
>=20
>     ;; Indent.
> diff --git a/lisp/treesit.el b/lisp/treesit.el
> index 54c29326df2..75c04912216 100644
> --- a/lisp/treesit.el
> +++ b/lisp/treesit.el
> @@ -185,15 +185,15 @@ treesit-language-at
> This function assumes that parser ranges are up-to-date.  It
> returns the return value of `treesit-language-at-point-function'
> if it's non-nil, otherwise it returns the language of the first
> -parser in `treesit-parser-list', or nil if there is no parser.
> +parser from `treesit-parsers-at', or the primary parser.

If we handle the fallback case in treesit-language-at directly, rather =
than defining a separate default function, IMO we should describe the =
fallback behavior as the default. So something like =E2=80=9CReturn the =
language at POS. When there are multiple parsers that covers POS, =
determine the most relevant parser (hence language) by their embed =
level. If treesit-language-at-point-function is non-nil, return the =
return value of that function instead.=E2=80=9D (Not saying we should =
use this exact docstring but to illustrate the point.)

>=20
> -In a multi-language buffer, make sure
> -`treesit-language-at-point-function' is implemented!  Otherwise
> -`treesit-language-at' wouldn't return the correct result."
> +In a multi-language buffer, optionally you can implement
> +`treesit-language-at-point-function' to return more correct result."
>   (if treesit-language-at-point-function
>       (funcall treesit-language-at-point-function position)
> -    (when-let* ((parser (car (treesit-parser-list))))
> -      (treesit-parser-language parser))))
> +    (treesit-parser-language
> +     (or (car (treesit-parsers-at position))
> +         treesit-primary-parser))))
>=20
> ;;; Node API supplement
>=20
> @@ -247,8 +247,9 @@ treesit-node-at
>                 (parser-or-lang
>                  (let* ((local-parser (car (treesit-local-parsers-at
>                                             pos parser-or-lang)))
> -                        (global-parser (car (treesit-parser-list
> -                                             nil parser-or-lang)))
> +                        (global-parser (or (car (treesit-parsers-at
> +                                                 pos parser-or-lang))
> +                                           treesit-primary-parser))
>                         (parser (or local-parser global-parser)))
>                    (when parser
>                      (treesit-parser-root-node parser))))
> @@ -267,13 +268,10 @@ treesit-node-at
>                         (local-parser
>                          ;; Find the local parser with highest
>                          ;; embed-level at point.
> -                         (car (seq-sort-by =
#'treesit-parser-embed-level
> -                                           (lambda (a b)
> -                                             (> (or a 0) (or b 0)))
> -                                           (treesit-local-parsers-at
> -                                            pos lang))))
> -                        (global-parser (car (treesit-parser-list
> -                                             nil lang)))
> +                         (car (treesit-local-parsers-at pos lang)))
> +                        (global-parser (or (car (treesit-parsers-at
> +                                                 pos lang))
> +                                           treesit-primary-parser))
>                         (parser (or local-parser global-parser)))
>                    (when parser
>                      (treesit-parser-root-node parser))))))
> @@ -851,6 +849,38 @@ treesit--clip-ranges
>            if (<=3D start (car range) (cdr range) end)
>            collect range))
>=20
> +(defun treesit-parsers-at (&optional pos language with-host =
local-only)
> +  "Return all the non-primary parsers at POS.

I get why you used treesit-parsers-at rather than a more technically =
correct name like treesit-non-primary-parsers-at, or =
treesit-embeded-parsers-at. But this is confusing for not much benefit =
IMO. I suggest either use treesit-parsers-at, and add an optional =
argument exclude-primary; or use a more correct name and don=E2=80=99t =
include the primary parser. Also, instead of using LOCAL-ONLY, we might =
be more future-prove to use a ONLY parameter, and let user pass =E2=80=98l=
ocal to mean local-only. This way we can add the option of returning =
only non-local non-primary parsers in the future, should the need arises =
(it already kinda does in treesit-node-at and treesit-simple-imenu, =
technically global-parser should be picked from non-local parsers).

> +
> +POS defaults to point.
> +If LANGUAGE is non-nil, only return parsers for LANGUAGE.
> +
> +If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
> +instead.  HOST-PARSER is the host parser which created the PARSER.
> +
> +If LOCAL-ONLY is non-nil, return only local parsers.
> +Local parsers are those which only parse a limited region marked
> +by an overlay with non-nil `treesit-parser' property."
> +  (let ((res nil))
> +    ;; Refer to (ref:local-parser-overlay) for more explanation of =
local
> +    ;; parser overlays.
> +    (dolist (ov (overlays-at (or pos (point))))
> +      (when-let* ((parser (overlay-get ov 'treesit-parser))
> +                  (host-parser (or (null with-host)
> +                                   (overlay-get ov =
'treesit-host-parser)))
> +                  (_ (or (null local-only)
> +                         (overlay-get ov 'treesit-parser-local-p)))
> +                  (_ (or (null language)
> +                         (eq (treesit-parser-language parser)
> +                             language))))
> +        (push (if with-host (cons parser host-parser) parser) res)))
> +    (seq-sort-by (lambda (p)
> +                   (treesit-parser-embed-level
> +                    (or (car-safe p) p)))
> +                 (lambda (a b)
> +                   (> (or a 0) (or b 0)))
> +                 res)))
> +
> (defun treesit-local-parsers-at (&optional pos language with-host)
>   "Return all the local parsers at POS.
>=20
> @@ -862,19 +892,7 @@ treesit-local-parsers-at
> If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
> instead.  HOST-PARSER is the host parser which created the local
> PARSER."
> -  (let ((res nil))
> -    ;; Refer to (ref:local-parser-overlay) for more explanation of =
local
> -    ;; parser overlays.
> -    (dolist (ov (overlays-at (or pos (point))))
> -      (let ((parser (overlay-get ov 'treesit-parser))
> -            (host-parser (overlay-get ov 'treesit-host-parser))
> -            (local-p (overlay-get ov 'treesit-parser-local-p)))
> -        (when (and parser host-parser local-p
> -                   (or (null language)
> -                       (eq (treesit-parser-language parser)
> -                           language)))
> -          (push (if with-host (cons parser host-parser) parser) =
res))))
> -    (nreverse res)))
> +  (treesit-parsers-at pos language with-host t))
>=20
> (defun treesit-local-parsers-on (&optional beg end language with-host)
>   "Return the list of local parsers that cover the region between BEG =
and END.
> @@ -3135,9 +3159,7 @@ treesit-up-list
>           (setq parent (treesit-parent-until parent pred)))
>=20
>         (unless parent
> -          (let ((parsers (seq-keep (lambda (o)
> -                                     (overlay-get o =
'treesit-host-parser))
> -                                   (overlays-at (point) t))))
> +          (let ((parsers (mapcar #'cdr (treesit-parsers-at (point) =
nil t))))
>             (while (and (not parent) parsers)
>               (setq parent (treesit-parent-until
>                             (treesit-node-at (point) (car parsers)) =
pred)
> @@ -3887,9 +3929,9 @@ treesit-simple-imenu
>       (lambda (entry)
>         (let* ((lang (car entry))
>                (settings (cdr entry))
> -               (global-parser (car (treesit-parser-list nil lang)))
> -               (local-parsers
> -                (treesit-parser-list nil lang 'embedded)))
> +               (global-parser (or (car (treesit-parsers-at nil lang))
> +                                  treesit-primary-parser))
> +               (local-parsers (treesit-local-parsers-at nil lang)))
>           (cons (treesit-language-display-name lang)
>                 ;; No one says you can't have both global and local
>                 ;; parsers for the same language.  E.g., Rust uses
> @@ -4029,9 +4074,7 @@ treesit-outline-level
>       (setq level (1+ level)))
>=20
>     ;; Continue counting the host nodes.
> -    (dolist (parser (seq-keep (lambda (o)
> -                                (overlay-get o 'treesit-host-parser))
> -                              (overlays-at (point) t)))
> +    (dolist (parser (mapcar #'cdr (treesit-parsers-at (point) nil =
t)))
>       (let* ((node (treesit-node-at (point) parser))
>              (lang (treesit-parser-language parser))
>              (pred (alist-get lang =
treesit-aggregated-outline-predicate)))

We should also update manual sections that mentions treesit-language-at.

Yuan





Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 01 Apr 2025 16:56:02 +0000
Resent-Message-ID: <handler.77256.B77256.17435265476512 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.17435265476512
          (code B ref 77256); Tue, 01 Apr 2025 16:56:02 +0000
Received: (at 77256) by debbugs.gnu.org; 1 Apr 2025 16:55:47 +0000
Received: from localhost ([127.0.0.1]:50761 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzett-0001gl-Hv
	for submit <at> debbugs.gnu.org; Tue, 01 Apr 2025 12:55:47 -0400
Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]:48033)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tzetq-0001fD-JB
 for 77256 <at> debbugs.gnu.org; Tue, 01 Apr 2025 12:55:43 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id DE25444440;
 Tue,  1 Apr 2025 16:55:29 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
Date: Tue, 01 Apr 2025 19:53:37 +0300
Message-ID: <871pucdti6.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: multipart/mixed; boundary="=-=-="
X-GND-State: clean
X-GND-Score: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeeffedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesmhdtreertderjeenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpedtiedthfehhfetteefgfefgffftedttdefjeefveekfefgteettddutefgleethfenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopehvrdhpuhhpihhllhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeejvdehieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhm
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.0 (/)
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: -1.0 (-)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

>> @@ -185,15 +185,15 @@ treesit-language-at
>> This function assumes that parser ranges are up-to-date.  It
>> returns the return value of `treesit-language-at-point-function'
>> if it's non-nil, otherwise it returns the language of the first
>> -parser in `treesit-parser-list', or nil if there is no parser.
>> +parser from `treesit-parsers-at', or the primary parser.
>
> If we handle the fallback case in treesit-language-at directly, rather than
> defining a separate default function, IMO we should describe the fallback
> behavior as the default. So something like “Return the language at
> POS. When there are multiple parsers that covers POS, determine the most
> relevant parser (hence language) by their embed level. If
> treesit-language-at-point-function is non-nil, return the return value of
> that function instead.” (Not saying we should use this exact docstring but
> to illustrate the point.)

Now fixed in the next patch.

>> +(defun treesit-parsers-at (&optional pos language with-host local-only)
>> +  "Return all the non-primary parsers at POS.
>
> I get why you used treesit-parsers-at rather than a more technically
> correct name like treesit-non-primary-parsers-at, or
> treesit-embeded-parsers-at. But this is confusing for not much benefit
> IMO. I suggest either use treesit-parsers-at, and add an optional argument
> exclude-primary; or use a more correct name and don’t include the primary
> parser. Also, instead of using LOCAL-ONLY, we might be more future-prove to
> use a ONLY parameter, and let user pass ‘local to mean local-only. This way
> we can add the option of returning only non-local non-primary parsers in
> the future, should the need arises (it already kinda does in
> treesit-node-at and treesit-simple-imenu, technically global-parser should
> be picked from non-local parsers).

I can't find a better function signature than to add the argument ONLY
with the following combinations of symbols for its list, wrt existing uses
of treesit-parsers-at:

  nil                treesit-language-at (nil returns all parsers)
  (local)            treesit-local-parsers-at
  (primary global)   treesit-node-at, treesit-simple-imenu
  (global local)     treesit-outline-level, treesit-up-list

> We should also update manual sections that mentions treesit-language-at.

Will do when everything is ok with this patch:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-parsers-at.patch

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 54c29326df2..4ba46e5b7ce 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -182,18 +182,14 @@ treesit-language-at-point-function
 (defun treesit-language-at (position)
   "Return the language at POSITION.
 
-This function assumes that parser ranges are up-to-date.  It
-returns the return value of `treesit-language-at-point-function'
-if it's non-nil, otherwise it returns the language of the first
-parser in `treesit-parser-list', or nil if there is no parser.
-
-In a multi-language buffer, make sure
-`treesit-language-at-point-function' is implemented!  Otherwise
-`treesit-language-at' wouldn't return the correct result."
+When there are multiple parsers that covers POSITION, determine
+the most relevant parser (hence language) by their embed level.
+If `treesit-language-at-point-function' is non-nil, return
+the return value of that function instead."
   (if treesit-language-at-point-function
       (funcall treesit-language-at-point-function position)
-    (when-let* ((parser (car (treesit-parser-list))))
-      (treesit-parser-language parser))))
+    (treesit-parser-language
+     (car (treesit-parsers-at position)))))
 
 ;;; Node API supplement
 
@@ -247,8 +243,9 @@ treesit-node-at
                 (parser-or-lang
                  (let* ((local-parser (car (treesit-local-parsers-at
                                             pos parser-or-lang)))
-                        (global-parser (car (treesit-parser-list
-                                             nil parser-or-lang)))
+                        (global-parser (car (treesit-parsers-at
+                                             pos parser-or-lang nil
+                                             '(primary global))))
                         (parser (or local-parser global-parser)))
                    (when parser
                      (treesit-parser-root-node parser))))
@@ -267,13 +264,10 @@ treesit-node-at
                         (local-parser
                          ;; Find the local parser with highest
                          ;; embed-level at point.
-                         (car (seq-sort-by #'treesit-parser-embed-level
-                                           (lambda (a b)
-                                             (> (or a 0) (or b 0)))
-                                           (treesit-local-parsers-at
-                                            pos lang))))
-                        (global-parser (car (treesit-parser-list
-                                             nil lang)))
+                         (car (treesit-local-parsers-at pos lang)))
+                        (global-parser (car (treesit-parsers-at
+                                             pos lang nil
+                                             '(primary global))))
                         (parser (or local-parser global-parser)))
                    (when parser
                      (treesit-parser-root-node parser))))))
@@ -851,6 +845,56 @@ treesit--clip-ranges
            if (<= start (car range) (cdr range) end)
            collect range))
 
+(defun treesit-parsers-at (&optional pos language with-host only)
+  "Return all parsers at POS.
+
+POS defaults to point.  The returned parsers are sorted by
+the decreasing embed level.
+
+If LANGUAGE is non-nil, only return parsers for LANGUAGE.
+
+If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
+instead.  HOST-PARSER is the host parser which created the PARSER.
+
+If ONLY is nil, return all parsers including the primary parser.
+
+The argument ONLY can be a list of symbols that specify what
+parsers to include in the return value.
+
+If ONLY contains the symbol `local', include local parsers.
+Local parsers are those which only parse a limited region marked
+by an overlay with non-nil `treesit-parser' property.
+
+If ONLY contains the symbol `global', include non-local parsers
+excluding the primary parser.
+
+If ONLY contains the symbol `primary', include the primary parser."
+  (let ((res nil))
+    ;; Refer to (ref:local-parser-overlay) for more explanation of local
+    ;; parser overlays.
+    (dolist (ov (overlays-at (or pos (point))))
+      (when-let* ((parser (overlay-get ov 'treesit-parser))
+                  (host-parser (or (null with-host)
+                                   (overlay-get ov 'treesit-host-parser)))
+                  (_ (or (null language)
+                         (eq (treesit-parser-language parser)
+                             language)))
+                  (_ (or (null only)
+                         (and (memq 'local only) (memq 'global only))
+                         (and (memq 'local only)
+                              (overlay-get ov 'treesit-parser-local-p))
+                         (and (memq 'global only)
+                              (not (overlay-get ov 'treesit-parser-local-p))))))
+        (push (if with-host (cons parser host-parser) parser) res)))
+    (when (or (null only) (memq 'primary only))
+      (setq res (cons treesit-primary-parser res)))
+    (seq-sort-by (lambda (p)
+                   (treesit-parser-embed-level
+                    (or (car-safe p) p)))
+                 (lambda (a b)
+                   (> (or a 0) (or b 0)))
+                 res)))
+
 (defun treesit-local-parsers-at (&optional pos language with-host)
   "Return all the local parsers at POS.
 
@@ -862,19 +906,7 @@ treesit-local-parsers-at
 If WITH-HOST is non-nil, return a list of (PARSER . HOST-PARSER)
 instead.  HOST-PARSER is the host parser which created the local
 PARSER."
-  (let ((res nil))
-    ;; Refer to (ref:local-parser-overlay) for more explanation of local
-    ;; parser overlays.
-    (dolist (ov (overlays-at (or pos (point))))
-      (let ((parser (overlay-get ov 'treesit-parser))
-            (host-parser (overlay-get ov 'treesit-host-parser))
-            (local-p (overlay-get ov 'treesit-parser-local-p)))
-        (when (and parser host-parser local-p
-                   (or (null language)
-                       (eq (treesit-parser-language parser)
-                           language)))
-          (push (if with-host (cons parser host-parser) parser) res))))
-    (nreverse res)))
+  (treesit-parsers-at pos language with-host '(local)))
 
 (defun treesit-local-parsers-on (&optional beg end language with-host)
   "Return the list of local parsers that cover the region between BEG and END.
@@ -3135,9 +3173,7 @@ treesit-up-list
           (setq parent (treesit-parent-until parent pred)))
 
         (unless parent
-          (let ((parsers (seq-keep (lambda (o)
-                                     (overlay-get o 'treesit-host-parser))
-                                   (overlays-at (point) t))))
+          (let ((parsers (mapcar #'cdr (treesit-parsers-at (point) nil t '(global local)))))
             (while (and (not parent) parsers)
               (setq parent (treesit-parent-until
                             (treesit-node-at (point) (car parsers)) pred)
@@ -3887,9 +3943,8 @@ treesit-simple-imenu
       (lambda (entry)
         (let* ((lang (car entry))
                (settings (cdr entry))
-               (global-parser (car (treesit-parser-list nil lang)))
-               (local-parsers
-                (treesit-parser-list nil lang 'embedded)))
+               (global-parser (car (treesit-parsers-at nil lang nil '(primary global))))
+               (local-parsers (treesit-local-parsers-at nil lang)))
           (cons (treesit-language-display-name lang)
                 ;; No one says you can't have both global and local
                 ;; parsers for the same language.  E.g., Rust uses
@@ -4029,9 +4087,7 @@ treesit-outline-level
       (setq level (1+ level)))
 
     ;; Continue counting the host nodes.
-    (dolist (parser (seq-keep (lambda (o)
-                                (overlay-get o 'treesit-host-parser))
-                              (overlays-at (point) t)))
+    (dolist (parser (mapcar #'cdr (treesit-parsers-at (point) nil t '(global local))))
       (let* ((node (treesit-node-at (point) parser))
              (lang (treesit-parser-language parser))
              (pred (alist-get lang treesit-aggregated-outline-predicate)))

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Yuan Fu <casouri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Wed, 02 Apr 2025 00:00:03 +0000
Resent-Message-ID: <handler.77256.B77256.1743551964908 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Juri Linkov <juri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.1743551964908
          (code B ref 77256); Wed, 02 Apr 2025 00:00:03 +0000
Received: (at 77256) by debbugs.gnu.org; 1 Apr 2025 23:59:24 +0000
Received: from localhost ([127.0.0.1]:52521 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzlVs-0000Ea-2R
	for submit <at> debbugs.gnu.org; Tue, 01 Apr 2025 19:59:24 -0400
Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:45264)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1tzlVp-0000Du-J5
 for 77256 <at> debbugs.gnu.org; Tue, 01 Apr 2025 19:59:22 -0400
Received: by mail-pl1-x632.google.com with SMTP id
 d9443c01a7336-22423adf751so114524375ad.2
 for <77256 <at> debbugs.gnu.org>; Tue, 01 Apr 2025 16:59:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743551955; x=1744156755; 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=yvheMTCFO5vEgT3FR4m7QCwshOXpLPqWZn06dBf6VdI=;
 b=NPSOUGRTqCV6SgwJo1XQgzGm4cS4gx4OUgR2LoY/bTXpl4LphJA1YexaEswoe7NokK
 K5KuT4FmGUihbOT8zDyvwGYtdlnMpLe0Jw9ew1dRYy4/ykvfkVSRqXdfjRklcHDaEnVb
 wayYzVwej0NOpWXHVpi34kNOJtMf7mcxL9+wY86+tpb4442Yxd4JyEVfcxCy4G7DjTnN
 R2zRcT4aIYAzYlph2FO9Q3rIFWfrtVsOklqGEczwIBfvgx6PLWK73dv7hCF2s9iWHGgF
 uq9a1Kc0r3/NwLdxGFHTMmlfTObOfejivi97FmqyTlOFR7Z0eph879zq0G9AA6gGIFYp
 KCgw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743551955; x=1744156755;
 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=yvheMTCFO5vEgT3FR4m7QCwshOXpLPqWZn06dBf6VdI=;
 b=utoh2zjPnnzGMJxMHCAsEgo0amhTGwhtuwY2XGfhfWfcYdzBheYUy8muELCjYyaVFF
 LcXArChzF7MEJmohaWlzhuoUZYXrdhP4hspoSolqXn7Q7OSOTUcj+ONQKJvHx8zB/50X
 NdZN1e56IH2boZIk5c+8GCC3Zht/lITs95EO1pid+gURnJOA4P4WD20BLoVV+aM1Fxam
 F4IDxaspoPMwPTOIW62hRCMokIMW6+rsreEVaF23dcDMXfrYH8MVmFkKymAGxIbKupRy
 iEobYiearA6lse7/ugeQKqrGVUlz5okSI4X6au9I13VdKeG1teB9E0eL8TNW1mQNAYWb
 Eupg==
X-Gm-Message-State: AOJu0YxQnXRPGTet50/EmohFUw7lcR0qeYogXV4/GM3zbldRhpEdKxnY
 RDS0aTKAQJpzBKKph2+qDsZEBNxwIj/HzXGZQrqM9USnPOQD/YTgDP+zCw==
X-Gm-Gg: ASbGnctv5+bB0srSoCsfn7BLecd/yl1CEVVheGg7KGh2RQuKD9eb/yabguCvRTGi4M4
 1zjS3twADEmEfGKTiDIkwT9aeFzpKaXwv+PohkzdB6uF+iJ+33loQVLLlflKp+Xma7dVRAOT7KO
 5MdL1Ytq+7o+4D1Ehlznjffk0SHfncdP4o01KUgnKvc2RWKo4gwi5mrF0uuIx5JFbvf3FiDfcFP
 E+0YwK3pNpW0mdIYl3guN0oF94ykzEJt/9znyFleiv9yZ08fPtqfem+k/3wSr7XW1Ok4ukybATk
 2okRhJpZkSY7hXIRPbLbMry/2y4pG5w3f/KuKkChUhY0z1f6/5XRJjdQpIjOLbpqsAs=
X-Google-Smtp-Source: AGHT+IGkttlkMdBw+vxLkrJg5UyaPhRjCmTXeBLBaOpEDTgtr7N4T8xTVWEcW1I0kiBdYvCBXSNMDg==
X-Received: by 2002:a17:903:22c7:b0:224:1c41:a4c0 with SMTP id
 d9443c01a7336-2295be31750mr67648785ad.9.1743551955506; 
 Tue, 01 Apr 2025 16:59:15 -0700 (PDT)
Received: from smtpclient.apple ([2601:646:8f81:6120:7c76:5133:615:6915])
 by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-2291f1cf131sm95763045ad.134.2025.04.01.16.59.14
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Tue, 01 Apr 2025 16:59:14 -0700 (PDT)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\))
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <871pucdti6.fsf@HIDDEN>
Date: Tue, 1 Apr 2025 16:59:03 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3826.400.131.1.6)
X-Spam-Score: 0.0 (/)
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: -1.0 (-)



> On Apr 1, 2025, at 9:53=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
>>> @@ -185,15 +185,15 @@ treesit-language-at
>>> This function assumes that parser ranges are up-to-date.  It
>>> returns the return value of `treesit-language-at-point-function'
>>> if it's non-nil, otherwise it returns the language of the first
>>> -parser in `treesit-parser-list', or nil if there is no parser.
>>> +parser from `treesit-parsers-at', or the primary parser.
>>=20
>> If we handle the fallback case in treesit-language-at directly, =
rather than
>> defining a separate default function, IMO we should describe the =
fallback
>> behavior as the default. So something like =E2=80=9CReturn the =
language at
>> POS. When there are multiple parsers that covers POS, determine the =
most
>> relevant parser (hence language) by their embed level. If
>> treesit-language-at-point-function is non-nil, return the return =
value of
>> that function instead.=E2=80=9D (Not saying we should use this exact =
docstring but
>> to illustrate the point.)
>=20
> Now fixed in the next patch.
>=20
>>> +(defun treesit-parsers-at (&optional pos language with-host =
local-only)
>>> +  "Return all the non-primary parsers at POS.
>>=20
>> I get why you used treesit-parsers-at rather than a more technically
>> correct name like treesit-non-primary-parsers-at, or
>> treesit-embeded-parsers-at. But this is confusing for not much =
benefit
>> IMO. I suggest either use treesit-parsers-at, and add an optional =
argument
>> exclude-primary; or use a more correct name and don=E2=80=99t include =
the primary
>> parser. Also, instead of using LOCAL-ONLY, we might be more =
future-prove to
>> use a ONLY parameter, and let user pass =E2=80=98local to mean =
local-only. This way
>> we can add the option of returning only non-local non-primary parsers =
in
>> the future, should the need arises (it already kinda does in
>> treesit-node-at and treesit-simple-imenu, technically global-parser =
should
>> be picked from non-local parsers).
>=20
> I can't find a better function signature than to add the argument ONLY
> with the following combinations of symbols for its list, wrt existing =
uses
> of treesit-parsers-at:
>=20
>  nil                treesit-language-at (nil returns all parsers)
>  (local)            treesit-local-parsers-at
>  (primary global)   treesit-node-at, treesit-simple-imenu
>  (global local)     treesit-outline-level, treesit-up-list
>=20
>> We should also update manual sections that mentions =
treesit-language-at.
>=20
> Will do when everything is ok with this patch:
>=20

Thanks! LGTM.

Yuan=




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Fri, 04 Apr 2025 16:16:02 +0000
Resent-Message-ID: <handler.77256.B77256.1743783349605 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.1743783349605
          (code B ref 77256); Fri, 04 Apr 2025 16:16:02 +0000
Received: (at 77256) by debbugs.gnu.org; 4 Apr 2025 16:15:49 +0000
Received: from localhost ([127.0.0.1]:39699 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u0jht-00009h-Eu
	for submit <at> debbugs.gnu.org; Fri, 04 Apr 2025 12:15:49 -0400
Received: from relay3-d.mail.gandi.net ([2001:4b98:dc4:8::223]:43409)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1u0jhY-000069-Ag
 for 77256 <at> debbugs.gnu.org; Fri, 04 Apr 2025 12:15:28 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 7FF362047C;
 Fri,  4 Apr 2025 16:15:19 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
Date: Fri, 04 Apr 2025 19:14:11 +0300
Message-ID: <87y0wgx8l8.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: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduledukeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopehvrdhpuhhpihhllhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeejvdehieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhm
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
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: -1.7 (-)

>>> We should also update manual sections that mentions treesit-language-at.
>> 
>> Will do when everything is ok with this patch:
>
> Thanks! LGTM.

Unfortunately, I discovered that it causes treesit-node-outdated errors.

This is because overlays are updated by 'pre-redisplay-functions'
later than outline-minor-mode uses them by 'after-change-functions',
since 'after-change-functions' runs before 'pre-redisplay-functions'.

The reproducible test case: with the latest patch for treesit.el,
and another patch that removes 'mhtml-ts-mode--language-at-point'
from mhtml-ts-mode.el, open a simple html file like this:

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
</body>
</html>

then type:

1. M-x load-library RET treesit-x RET
2. M-x liquid-generic-ts-mode RET
3. M-x outline-minor-mode RET
4. move point before </html>
5. type SPC

then with non-nil debug-on-error:

Debugger entered--Lisp error: (treesit-node-outdated #<treesit-node-outdated>)
  treesit-node-enclosed-p(#<treesit-node-outdated> #<treesit-node element in 17-82>)
  treesit-navigate-thing(73 1 beg html-ts-mode--outline-predicate)
  treesit-outline-search(#<marker at 82 in test.html>)
  outline-map-region(#<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_46> 74 82)
  outline--fix-up-all-buttons(74 82)
  outline--fix-buttons-after-change(74 75 0)
  self-insert-command(1 32)
  funcall-interactively(self-insert-command 1 32)
  command-execute(self-insert-command)




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 05 Apr 2025 18:39:02 +0000
Resent-Message-ID: <handler.77256.B77256.174387828729216 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.174387828729216
          (code B ref 77256); Sat, 05 Apr 2025 18:39:02 +0000
Received: (at 77256) by debbugs.gnu.org; 5 Apr 2025 18:38:07 +0000
Received: from localhost ([127.0.0.1]:44752 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u18P9-0007bA-8L
	for submit <at> debbugs.gnu.org; Sat, 05 Apr 2025 14:38:07 -0400
Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]:43473)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1u18P6-0007aY-JE
 for 77256 <at> debbugs.gnu.org; Sat, 05 Apr 2025 14:38:05 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 16850431EB;
 Sat,  5 Apr 2025 18:37:54 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <87y0wgx8l8.fsf@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
 <87y0wgx8l8.fsf@HIDDEN>
Date: Sat, 05 Apr 2025 21:35:54 +0300
Message-ID: <87r026pib9.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: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleehuddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopehvrdhpuhhpihhllhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeejvdehieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhm
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.0 (/)
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: -1.0 (-)

> Unfortunately, I discovered that it causes treesit-node-outdated errors.
>
> This is because overlays are updated by 'pre-redisplay-functions'
> later than outline-minor-mode uses them by 'after-change-functions',
> since 'after-change-functions' runs before 'pre-redisplay-functions'.

This fixes the problem:

   (defun outline--fix-buttons-after-change (beg end _len)
  +  (when (fboundp 'treesit-update-ranges)
  +    (treesit-update-ranges beg end))
     ;; Handle whole lines
     (save-excursion (goto-char beg) (setq beg (pos-bol)))
     (save-excursion (goto-char end) (setq end (pos-eol)))

But can we do better?  I see that 'treesit-major-mode-setup'
adds the notifier

      (treesit-parser-add-notifier
       treesit-primary-parser #'treesit--font-lock-mark-ranges-to-fontify)

to 'after_change_functions'.  But why the treesit
'after_change_functions' notifier is called after the
'after-change-functions' hook?  Can we change their order?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Yuan Fu <casouri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 06 Apr 2025 04:52:02 +0000
Resent-Message-ID: <handler.77256.B77256.17439151124834 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Juri Linkov <juri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.17439151124834
          (code B ref 77256); Sun, 06 Apr 2025 04:52:02 +0000
Received: (at 77256) by debbugs.gnu.org; 6 Apr 2025 04:51:52 +0000
Received: from localhost ([127.0.0.1]:45676 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u1Hz5-0001Ft-LJ
	for submit <at> debbugs.gnu.org; Sun, 06 Apr 2025 00:51:52 -0400
Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:61461)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1u1Hz2-0001Fd-Fe
 for 77256 <at> debbugs.gnu.org; Sun, 06 Apr 2025 00:51:49 -0400
Received: by mail-pf1-x432.google.com with SMTP id
 d2e1a72fcca58-736c3e7b390so2912251b3a.2
 for <77256 <at> debbugs.gnu.org>; Sat, 05 Apr 2025 21:51:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1743915102; x=1744519902; 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=Dxl4VVMMO1fXosinFNz2AOGMfMKY2m0te62ST5yVoek=;
 b=l0L+hhMV+P7kGDPdkjJRCrfPJJlILMoWzko+rBD64X0sQHKo2q/KL5O5vUlNVo2zD5
 xWvCykd9/n+HyDmq2YpRLcThnz6NMEu/vecd1vh75r9beqn2lQ/ns1PEfkAYqCvazbVa
 PydA0AX4iUriWsWmZAkDitQKs4kkiCDIiPTIhFz0r31tzHFwyFyEfpgpuq9wGK+zkWqk
 Ppkyc2qglXvsk+KGYFcXX8gD0xudFtRRnYFqHwn+tj68qHnM8PLIDgrEUTyjvCOldgoe
 yx8OLLek/HZN1TI9Nbf3cLWV1p+4DpO8dkdesMydNgNxNFuUKEgjfOuJ82lF0ZaPQGk/
 dReg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1743915102; x=1744519902;
 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=Dxl4VVMMO1fXosinFNz2AOGMfMKY2m0te62ST5yVoek=;
 b=rwfQG3AyeIJReX2i/z12yaFDjnULUArPMjFlxwsTk5jG32mzUO4/QUb8jzRt5SM5pd
 MVKDvh4FP4AX8h9a6FPHUJ5EqJq4w33Ef3/AGFlwk8iAQW82Te3H8WfLosKZA7jZF0ag
 kppjO/BkmCDn5MIfauUkzxZxSTDN+ziH50oM6fhZJ3Q1ZB2nJElAvotIqKieNJSTFJF9
 Pm5IYkPeF4qox1pkYYK0f1xzkUeC9lbH82ZWArh1xDFslwxJ8PteBacV0Y6pOWqIN9FV
 GuO1+pudjMk23t0lYLsS3ae+booM6qEbSJT/syHew22xUGwSc0wi03acCYEAr/LI/zSs
 2ZQw==
X-Gm-Message-State: AOJu0Ywpl6D5M3HgvhNEVCNFToSQ9X8CLuMpmFq6K2dyym06aQDNXwof
 ykhomCAa4r+6XWfQQ1coEQ7zUZlo/lf3j+nF9Kt67/HpAaELW3gg
X-Gm-Gg: ASbGncvg//pjscxRebyYjjnwchJTw4vhv3k+Wd2GUa2cgdT1vGN6HINt25qP2jpAvQY
 yf8Qj+AsubK+yNLn69PcL+vCsQOnwx5emGnIq5itpyypNQB9+7+gGvImmbNVVKNQYXhMlqKo2mN
 51Ymtefj/eGlCsdATLgrsOUIsMbfnc0zrvhUuXzVjOaNCvctwuhag6GZxAalfavshhj5lE1Rln3
 fnN8V3PUYU+6+dbnKeOfMKeWFsfaT5lU9pl9pmxilChEctuyQhEsfK3eoRtjMnBAGK//0Jcu0zH
 GQr1/W/N1waodsBewZQ/8NWfzcUrJ5Fm7T2KAbFeKqbH608GaPw1bp2e29mlGEON5Mc=
X-Google-Smtp-Source: AGHT+IHhqRVs0oWbN/0I4OBqbDVdWOlN52YB+tbhcYGztE/iYHXoh0rtAEiJwdcJ5TBu5ErEUkzubA==
X-Received: by 2002:a05:6a21:6d93:b0:1f5:7ba7:69d7 with SMTP id
 adf61e73a8af0-20107ea2353mr11502087637.3.1743915102224; 
 Sat, 05 Apr 2025 21:51:42 -0700 (PDT)
Received: from smtpclient.apple ([2601:646:8f81:6120:c894:9229:b93:122a])
 by smtp.gmail.com with ESMTPSA id
 d2e1a72fcca58-739d97ee7a0sm6040159b3a.41.2025.04.05.21.51.40
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Sat, 05 Apr 2025 21:51:41 -0700 (PDT)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\))
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <87r026pib9.fsf@HIDDEN>
Date: Sat, 5 Apr 2025 21:51:29 -0700
Content-Transfer-Encoding: quoted-printable
Message-Id: <76B8FD44-EFDD-4A75-AAF6-3EA9A91A60A4@HIDDEN>
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
 <87y0wgx8l8.fsf@HIDDEN> <87r026pib9.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3826.400.131.1.6)
X-Spam-Score: 0.0 (/)
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: -1.0 (-)



> On Apr 5, 2025, at 11:35=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
>> Unfortunately, I discovered that it causes treesit-node-outdated =
errors.
>>=20
>> This is because overlays are updated by 'pre-redisplay-functions'
>> later than outline-minor-mode uses them by 'after-change-functions',
>> since 'after-change-functions' runs before 'pre-redisplay-functions'.
>=20
> This fixes the problem:
>=20
>   (defun outline--fix-buttons-after-change (beg end _len)
>  +  (when (fboundp 'treesit-update-ranges)
>  +    (treesit-update-ranges beg end))
>     ;; Handle whole lines
>     (save-excursion (goto-char beg) (setq beg (pos-bol)))
>     (save-excursion (goto-char end) (setq end (pos-eol)))

Using treesit-update-ranges is the right approach. But is there no =
better place to put it? I assume there should be a function that =
involves tree-sitter, in front of which you can put this call.

> But can we do better?  I see that 'treesit-major-mode-setup'
> adds the notifier
>=20
>      (treesit-parser-add-notifier
>       treesit-primary-parser =
#'treesit--font-lock-mark-ranges-to-fontify)
>=20
> to 'after_change_functions'.  But why the treesit
> 'after_change_functions' notifier is called after the
> 'after-change-functions' hook?  Can we change their order?

Because we parse lazily. And I should=E2=80=99ve called them after-parse =
functions in the docstring (good thing I named them notifiers, not =
after-change-functions)=E2=80=94they get called after the parser =
re-parses, but the parser doesn=E2=80=99t have to re-parse immediately =
after a buffer change. It only re-parses when some Lisp asks for a node =
from the parse tree.

In practice, that usually happens in pre-redisplay-function where we set =
ranges for embedded parsers, which causes the primary parser to re-parse =
and return a root node for querying. As a (intended) side-effect, the =
notifiers get called and mark relevant regions to be re-fontified.

Yuan





Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 06 Apr 2025 06:57:01 +0000
Resent-Message-ID: <handler.77256.B77256.174392257229021 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.174392257229021
          (code B ref 77256); Sun, 06 Apr 2025 06:57:01 +0000
Received: (at 77256) by debbugs.gnu.org; 6 Apr 2025 06:56:12 +0000
Received: from localhost ([127.0.0.1]:45813 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u1JvP-0007Y1-IR
	for submit <at> debbugs.gnu.org; Sun, 06 Apr 2025 02:56:11 -0400
Received: from relay8-d.mail.gandi.net ([217.70.183.201]:37501)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1u1JvJ-0007XI-K8
 for 77256 <at> debbugs.gnu.org; Sun, 06 Apr 2025 02:56:09 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id DE17144430;
 Sun,  6 Apr 2025 06:55:57 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <76B8FD44-EFDD-4A75-AAF6-3EA9A91A60A4@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
 <87y0wgx8l8.fsf@HIDDEN> <87r026pib9.fsf@HIDDEN>
 <76B8FD44-EFDD-4A75-AAF6-3EA9A91A60A4@HIDDEN>
Date: Sun, 06 Apr 2025 09:51:27 +0300
Message-ID: <87semlpzah.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; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-State: clean
X-GND-Score: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduleeiiedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgfgsehtkeertddtreejnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuggftrfgrthhtvghrnhepieffteejgeehffejuedtiefhudekgeejteekiefgveeuheetvdefgeekkeevkedunecukfhppeeluddruddvledruddthedruddujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeluddruddvledruddthedruddujedphhgvlhhopehmrghilhdrghgrnhguihdrnhgvthdpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnsggprhgtphhtthhopeefpdhrtghpthhtohepvhdrphhuphhilhhlohesghhmrghilhdrtghomhdprhgtphhtthhopeejjedvheeiseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomh
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
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: -1.7 (-)

>>> Unfortunately, I discovered that it causes treesit-node-outdated errors.
>>> 
>>> This is because overlays are updated by 'pre-redisplay-functions'
>>> later than outline-minor-mode uses them by 'after-change-functions',
>>> since 'after-change-functions' runs before 'pre-redisplay-functions'.
>> 
>> This fixes the problem:
>> 
>>   (defun outline--fix-buttons-after-change (beg end _len)
>>  +  (when (fboundp 'treesit-update-ranges)
>>  +    (treesit-update-ranges beg end))
>>     ;; Handle whole lines
>>     (save-excursion (goto-char beg) (setq beg (pos-bol)))
>>     (save-excursion (goto-char end) (setq end (pos-eol)))
>
> Using treesit-update-ranges is the right approach.  But is there no
> better place to put it?  I assume there should be a function that
> involves tree-sitter, in front of which you can put this call.

'treesit-outline-search' has no information about the positions of
the beginning and end of the range of changed text.  Only
'after-change-functions' has access to this information.

So what we could do is this, and I've tested that this approach works:

#+begin_src diff
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 07861603244..c77b28c4647 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -4044,6 +4112,10 @@ treesit-outline-level
 
     level))
 
+(defun treesit--after-change (beg end _len)
+  "Force updating the ranges after each text change."
+  (treesit-update-ranges beg end))
+
 ;;; Hideshow mode
 
 (defun treesit-hs-block-end ()
@@ -4338,7 +4410,16 @@ treesit-major-mode-setup
       (setq treesit-outline-predicate
             #'treesit-outline-predicate--from-imenu))
     (setq-local outline-search-function #'treesit-outline-search
-                outline-level #'treesit-outline-level))
+                outline-level #'treesit-outline-level)
+    (add-hook 'outline-minor-mode-hook
+              (lambda ()
+                (if (bound-and-true-p outline-minor-mode)
+                    (add-hook 'after-change-functions
+                              #'treesit--after-change
+                              0 t)
+                  (remove-hook 'after-change-functions
+                               #'treesit--after-change t)))
+              nil t))
 
   ;; Remove existing local parsers.
   (dolist (ov (overlays-in (point-min) (point-max)))
#+end_src

>> But can we do better?  I see that 'treesit-major-mode-setup'
>> adds the notifier
>> 
>>      (treesit-parser-add-notifier
>>       treesit-primary-parser #'treesit--font-lock-mark-ranges-to-fontify)
>> 
>> to 'after_change_functions'.  But why the treesit
>> 'after_change_functions' notifier is called after the
>> 'after-change-functions' hook?  Can we change their order?
>
> Because we parse lazily. And I should’ve called them after-parse functions
> in the docstring (good thing I named them notifiers, not
> after-change-functions)—they get called after the parser re-parses, but the
> parser doesn’t have to re-parse immediately after a buffer change. It only
> re-parses when some Lisp asks for a node from the parse tree.
>
> In practice, that usually happens in pre-redisplay-function where we set
> ranges for embedded parsers, which causes the primary parser to re-parse
> and return a root node for querying. As a (intended) side-effect, the
> notifiers get called and mark relevant regions to be re-fontified.

Would it be possible on the first attempt of Lisp code to access a node
to detect such a situation that there are some outdated nodes and
to update their ranges automatically?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 08 Apr 2025 17:46:01 +0000
Resent-Message-ID: <handler.77256.B77256.174413436026021 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.174413436026021
          (code B ref 77256); Tue, 08 Apr 2025 17:46:01 +0000
Received: (at 77256) by debbugs.gnu.org; 8 Apr 2025 17:46:00 +0000
Received: from localhost ([127.0.0.1]:35330 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u2D1L-0006lc-Hq
	for submit <at> debbugs.gnu.org; Tue, 08 Apr 2025 13:45:59 -0400
Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]:42645)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>)
 id 1u2D1I-0006kP-NX; Tue, 08 Apr 2025 13:45:57 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id F169644553;
 Tue,  8 Apr 2025 17:45:35 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
Date: Tue, 08 Apr 2025 20:40:44 +0300
Message-ID: <877c3upn4z.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: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdefjedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepgedprhgtphhtthhopegtohhnthhrohhlseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepvhdrphhuphhilhhlohesghhmrghilhdrtghomhdprhgtphhtthhopeejjedvheeiseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomh
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.0 (/)
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: -1.0 (-)

close 77256 31.0.50
thanks

>>> We should also update manual sections that mentions treesit-language-at.
>> 
>> Will do when everything is ok with this patch:
>
> Thanks! LGTM.

Now pushed together with updates in the manual.
Please check the commit 5e0daa1ef77.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#77256: Treesit language-at-point
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 08 Apr 2025 17:48:02 +0000
Resent-Message-ID: <handler.77256.B77256.174413442226429 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 77256
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: 
To: Yuan Fu <casouri@HIDDEN>
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
Received: via spool by 77256-submit <at> debbugs.gnu.org id=B77256.174413442226429
          (code B ref 77256); Tue, 08 Apr 2025 17:48:02 +0000
Received: (at 77256) by debbugs.gnu.org; 8 Apr 2025 17:47:02 +0000
Received: from localhost ([127.0.0.1]:35337 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u2D2L-0006s6-U9
	for submit <at> debbugs.gnu.org; Tue, 08 Apr 2025 13:47:02 -0400
Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]:45807)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1u2D1T-0006lB-2h
 for 77256 <at> debbugs.gnu.org; Tue, 08 Apr 2025 13:46:07 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id 3E2EE44363;
 Tue,  8 Apr 2025 17:45:51 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <87semlpzah.fsf@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
 <87y0wgx8l8.fsf@HIDDEN> <87r026pib9.fsf@HIDDEN>
 <76B8FD44-EFDD-4A75-AAF6-3EA9A91A60A4@HIDDEN>
 <87semlpzah.fsf@HIDDEN>
Date: Tue, 08 Apr 2025 20:44:05 +0300
Message-ID: <871pu2pmze.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: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdefjedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepfedprhgtphhtthhopehvrdhpuhhpihhllhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohepjeejvdehieesuggvsggsuhhgshdrghhnuhdrohhrghdprhgtphhtthhopegtrghsohhurhhisehgmhgrihhlrdgtohhm
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.0 (/)
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: -1.0 (-)

>> Using treesit-update-ranges is the right approach.  But is there no
>> better place to put it?  I assume there should be a function that
>> involves tree-sitter, in front of which you can put this call.
>
> 'treesit-outline-search' has no information about the positions of
> the beginning and end of the range of changed text.  Only
> 'after-change-functions' has access to this information.
>
> So what we could do is this, and I've tested that this approach works:

This is pushed as well.




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


Received: (at control) by debbugs.gnu.org; 8 Apr 2025 17:47:02 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 08 13:47:01 2025
Received: from localhost ([127.0.0.1]:35335 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u2D2L-0006rs-Jb
	for submit <at> debbugs.gnu.org; Tue, 08 Apr 2025 13:47:01 -0400
Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]:42645)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>)
 id 1u2D1I-0006kP-NX; Tue, 08 Apr 2025 13:45:57 -0400
Received: by mail.gandi.net (Postfix) with ESMTPSA id F169644553;
 Tue,  8 Apr 2025 17:45:35 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#77256: Treesit language-at-point
In-Reply-To: <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
Organization: LINKOV.NET
References: <87a5990x6t.fsf@HIDDEN>
 <9271D97C-0820-4C70-9A58-88988F2E6BF9@HIDDEN>
 <87plhxw7fh.fsf@HIDDEN>
 <73DD04E6-D914-4A14-8DA9-876519BBEF4D@HIDDEN>
 <871pucdti6.fsf@HIDDEN>
 <8B15AB89-2A73-4260-AFD5-400B11342625@HIDDEN>
Date: Tue, 08 Apr 2025 20:40:44 +0300
Message-ID: <877c3upn4z.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: -100
X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdefjedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufgjohhffffkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucggtffrrghtthgvrhhnpeffgeetfeevlefhleejfeeuheeiudeitdffhfdutdekfeffgffhveehteegueekheenucfkphepledurdduvdelrddutdehrdduudejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepledurdduvdelrddutdehrdduudejpdhhvghlohepmhgrihhlrdhgrghnughirdhnvghtpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhgspghrtghpthhtohepgedprhgtphhtthhopegtohhnthhrohhlseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtohepvhdrphhuphhilhhlohesghhmrghilhdrtghomhdprhgtphhtthhopeejjedvheeiseguvggssghughhsrdhgnhhurdhorhhgpdhrtghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomh
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: control
Cc: 77256 <at> debbugs.gnu.org, Vincenzo Pupillo <v.pupillo@HIDDEN>
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: -1.0 (-)

close 77256 31.0.50
thanks

>>> We should also update manual sections that mentions treesit-language-at.
>> 
>> Will do when everything is ok with this patch:
>
> Thanks! LGTM.

Now pushed together with updates in the manual.
Please check the commit 5e0daa1ef77.





Last modified: Tue, 8 Apr 2025 18:00:02 UTC

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