From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes Date: Thu, 12 Dec 2024 18:31:04 +0200 Organization: LINKOV.NET Message-ID: <87wmg53rdj.fsf@mail.linkov.net> References: <87plox4mtp.fsf@masteringemacs.org> <87frpm20t7.fsf@masteringemacs.org> <8634lmbs8t.fsf@gnu.org> <87bk0a1u0o.fsf@masteringemacs.org> <86tte2a5o3.fsf@gnu.org> <877cay1lqt.fsf@masteringemacs.org> <86frpma06f.fsf@gnu.org> <86ikueiekp.fsf@mail.linkov.net> <86ed4zg1cc.fsf@mail.linkov.net> <87zflac68t.fsf@mail.linkov.net> <87jzcdlxdp.fsf@mail.linkov.net> <87o71jocgs.fsf@mail.linkov.net> <5192B278-66C0-48AE-B881-E57CCBB6B501@gmail.com> <87frmtbc9z.fsf@mail.linkov.net> <86bjxh1h86.fsf@gnu.org> <87y10l8h6k.fsf@mail.linkov.net> <87ldwl8g60.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22713"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: theo@thornhill.no, casouri@gmail.com, mickey@masteringemacs.org, monnier@iro.umontreal.ca, 73404@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 12 17:45:42 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tLmJn-0005dO-Hr for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 Dec 2024 17:45:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLmJP-0000sk-1e; Thu, 12 Dec 2024 11:45:15 -0500 Original-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 ) id 1tLmJK-0000rO-Oz for bug-gnu-emacs@gnu.org; Thu, 12 Dec 2024 11:45:11 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLmJD-0005DD-6d for bug-gnu-emacs@gnu.org; Thu, 12 Dec 2024 11:45:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=DJ8aUWbxf10l6/2EhjCmEtt1W9LEW6jk0bPQZGGDCkU=; b=j/kvTKr49NR71QEOYUpeIf/eSxl4+b3GZ6g4AnvOmCYuidEhTb89GLjQxktB09aE2A5HQtHAmC+ms7bJba8vrkBD+VDjZpwiUvMjYJVjEo0lpnlVsfpGzQ0ETmzFxWRgQGM+o+jCztTL4dLNScpsxDYVIoXzX9LecCO+JOCipiXmOb/J8wKlxS0v2c4fn85m4VUacGvkE5Kr4v21Zu3GM7JbYpoMHUhlAuIwQhxd0ttyXAxwmnIfmYD+Pgjq4cG+bDSYOSEsUqNZ1NcGRLRJZ5PKIL0fciZtX1kWg9klfuePXrWcCMoZczCSnJfKdhRXXcqTRE1IhY2yemz41sgMqg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLmJC-0003f8-Of for bug-gnu-emacs@gnu.org; Thu, 12 Dec 2024 11:45:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Dec 2024 16:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73404 X-GNU-PR-Package: emacs Original-Received: via spool by 73404-submit@debbugs.gnu.org id=B73404.173402190014049 (code B ref 73404); Thu, 12 Dec 2024 16:45:02 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 12 Dec 2024 16:45:00 +0000 Original-Received: from localhost ([127.0.0.1]:40062 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLmJ9-0003eT-Ob for submit@debbugs.gnu.org; Thu, 12 Dec 2024 11:45:00 -0500 Original-Received: from relay1-d.mail.gandi.net ([217.70.183.193]:48249) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLmJ8-0003e7-70 for 73404@debbugs.gnu.org; Thu, 12 Dec 2024 11:44:59 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 80C0C240006; Thu, 12 Dec 2024 16:44:50 +0000 (UTC) In-Reply-To: <87ldwl8g60.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 12 Dec 2024 10:14:59 +0200") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296922 Archived-At: > A better idea: instead of 'sexp' in treesit-thing-settings > define separately 'list' and 'atom', e.g. replace > > (setq-local treesit-thing-settings > `((javascript > (sexp ,(js--regexp-opt-symbol js--treesit-sexp-nodes))))) > > with > > (setq-local treesit-thing-settings > `((javascript > (list ,(js--regexp-opt-symbol js--treesit-list-nodes)) > (atom ,(js--regexp-opt-symbol js--treesit-atom-nodes))))) Still the problem is that using the atoms from the tree doesn't provide backward-compatibility with non-ts modes and how C-M-f moves on non-list atoms there. One way would be to extract anonymous text leaf nodes such as "export" and "const" from (export_statement "export" declaration: (lexical_declaration kind: "const" But still need to check symbol/word syntax to omit such nodes as "+" from (binary_expression left: (identifier) operator: "+" Therefore to provide backward-compatibility with non-ts modes in regard to C-M-f navigation, navigation on atoms should follow the Sword/Ssymbol rules of 'scan_lists' with non-nil 'sexpflag'. So an atom should be a syntactical entity, not structural. This means that treesit-forward-sexp should use the 'list' thing with syntactical atoms. For example, for 'C-M-f' on var p = { case: 'zzzz', -!-default: 'donkey', tee: 'ornery' }; in js-ts-mode it would be unexpected to move to var p = { case: 'zzzz', default: 'donkey'-!-, tee: 'ornery' }; because js-mode moves to var p = { case: 'zzzz', default-!-: 'donkey', tee: 'ornery' }; But anyway 'list' should be customizable as 'sexp' already is. OTOH, transpose-sexps should use treesit 'sexp' with more fine-grained lists that are not suitable for forward-sexp. (And we have no transpose-lists.) For example, it's expected for transpose-sexps to transpose a pair of key:value defined by 'sexp': var p = { default: 'donkey', -!-case: 'zzzz', tee: 'ornery' }; that will be a big improvement when comparing to js-mode. This also will close bug#60655. And if someone want to transpose adjacent atoms (symbols or words), there is transpose-words. In summary: The current implementation in treesit-forward-sexp is more like forward-list. So let's rename it to treesit-forward-list, then create a new implementation of treesit-forward-sexp that uses the 'list' thing together with syntactical atoms. Another variant is to leave treesit-forward-sexp as is, and create a new function treesit-forward-sexp-with-list that uses the 'list' thing. And anyway let's keep the current implementation of treesit-transpose-sexps that uses the 'sexp' thing.