From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii 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: Sun, 05 Jan 2025 21:54:12 +0200 Message-ID: <86cyh16nq3.fsf@gnu.org> References: <87plox4mtp.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> <87wmfwqg7e.fsf@mail.linkov.net> <8734i5fyv1.fsf@mail.linkov.net> <875xmumpzv.fsf@mail.linkov.net> <86ikqubdsd.fsf@gnu.org> <87wmf9912l.fsf@mail.linkov.net> <867c798lco.fsf@gnu.org> <871pxhp24e.fsf@mail.linkov.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9791"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mickey@masteringemacs.org, casouri@gmail.com, theo@thornhill.no, 73404@debbugs.gnu.org, monnier@iro.umontreal.ca To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 05 20:55:24 2025 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 1tUWiZ-0002Mj-8b for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Jan 2025 20:55:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUWiO-0007Eh-IB; Sun, 05 Jan 2025 14:55:13 -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 1tUWiN-0007ED-53 for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 14:55: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 1tUWiE-0003OH-1I for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 14:55:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=w3tu1DOTtjYdJJYoLZ+aIob9EdaBoAHQPkXwheIDhRI=; b=cjQjv+zCzuf+JA8RMiB6ukYdJbGDWASOLuS3SQFB2J6EVij3YGvi3dBqyqf+cYvGaO4FaEDb5GsPlETyDK2bI/G+qosUZF1/4VhjoeJT03hIZtaXgwt1LF1Dqqz1lUocd2qA8xXSSwdFlt60Mv1Rl8zaIEmqBoYHcz4I76R8cEbgzMcgvBwL3v6ZSBUeqBFRLaxB9vVbSEE5DWs4FffPDRxRLEvKXhBGhNL8m+M7ovnzsvXq1KglCJz72U/BJxvt1J2vSo/GWDLwD7QGGV4L8Oxdb6sCn2yO58b/Z//J20T0fAOFhNvLpKF/rJHG891aBEVVDJSzu9EMZIOsjGQ3OA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tUWiD-0006Mj-SD for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 14:55:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Jan 2025 19:55:01 +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.173610686624406 (code B ref 73404); Sun, 05 Jan 2025 19:55:01 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 5 Jan 2025 19:54:26 +0000 Original-Received: from localhost ([127.0.0.1]:35351 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tUWhd-0006LZ-Od for submit@debbugs.gnu.org; Sun, 05 Jan 2025 14:54:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48450) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tUWhb-0006LH-Hk for 73404@debbugs.gnu.org; Sun, 05 Jan 2025 14:54:24 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tUWhU-0003Gt-AO; Sun, 05 Jan 2025 14:54:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=w3tu1DOTtjYdJJYoLZ+aIob9EdaBoAHQPkXwheIDhRI=; b=jEtRR2rRmSLC 1qX0gehvSQ2sd7R+OwgkkfX4TCyDFYRrnSrsIsGAYwEIqs44imC4RaFnk0RfibWb48xebdY1E/Zvj rHFOgy0y3tHnFdVJ0PZpDcKVNktE1m6r2NzGUu+1h2IZM7ZVxem2vFk2QBz5ACq1i2wysokA6vqXL vs2Pk+U7Zdote1xVt1cLILnEJGdliUK4rz6u5e5lGjZDi3CQULKqvPPsJsIymYTfNYDF9xlCgbGWl BwNhctUK0N+Ex1J7cYS+i3o8VIp3gF1qbpLBFsRrr2ulCkiecefC+UvrGjHRks6AkYWM1YbNLDZrP tcWeZujfvmpQcMZUsBwAWg==; In-Reply-To: <871pxhp24e.fsf@mail.linkov.net> (message from Juri Linkov on Sun, 05 Jan 2025 20:05:53 +0200) 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:298602 Archived-At: > From: Juri Linkov > Cc: casouri@gmail.com, theo@thornhill.no, mickey@masteringemacs.org, > 73404@debbugs.gnu.org, monnier@iro.umontreal.ca > Date: Sun, 05 Jan 2025 20:05:53 +0200 > > >> The command is 'forward-list'. With 'list' it will do in ts-modes > >> the same that 'forward-list' already does in non-ts modes. > > > > Thanks. > > > > I tried this now in c-ts-mode, and it seems to behave strangely in > > some cases. > > > > First, AFAICT it supports "lists" enclosed in "(..)", "{..}" and > > "<..>", but not "[..]". Is that expected? Why don't we support > > "[..]"? > > This looks like a bug. It would be nice if you posted an example. That's easy: C-f C-f src/dispnew.c RET M-x -c-ts-mode RET C-s [ RET This brings you to this function: static void check_rows (struct frame *f) { for (int y = 0; y < f->desired_matrix->nrows; ++y) if (MATRIX_ROW_ENABLED_P (f->desired_matrix, y)) { struct glyph_row *row = MATRIX_ROW (f->desired_matrix, y); for (int x = 0; x < row->used[TEXT_AREA]; ++x) eassert (row->glyphs[TEXT_AREA][x].frame != 0); } } Move point to any of the [ brackets there and type C-M-n -- you will be moved to the last ) of the function. Another example on line 152 in dispnew.c: struct redisplay_history { char trace[512 + 100]; }; Move point to the [ before 512: C-M-n will signal an error. Any bracket in the file will trigger either the first or the second behavior. > > Next, it many times signals an error "No next group", which is less > > useful than it could be. For example: > > > > w32_get_internal_run_time (void) > > { > > if (get_process_times_fn) > > { > > FILETIME create, exit, kernel, user; > > HANDLE proc = GetCurrentProcess (); > > if ((*get_process_times_fn) (proc, &create, &exit, &kernel, &user)) > > { > > return ltime (total.QuadPart); > > } ^ > > } > > > > return Fcurrent_time (); > > } > > > > If you put point on the semi-colon marked by "^", C-M-n signals an > > error. Can't we instead move to the next "list" after > > "Fcurrent_time"? > > 'C-M-n' doesn't move to the next statement in c-mode, > since we need to support backward-compatibility. The key > that moves to the next statement ignoring nested lists > in C modes is 'M-e'. Well, then maybe we could have the more useful behavior as an opt-in option? > > Also, it sometimes "misses" what looks like a "list". For example: > > > > s_pfn_Open_Process_Token = (OpenProcessToken_Proc) > > get_proc_addr (hm_advapi32, "OpenProcessToken"); > > > > If you put point at the beginning of the line, C-M-n moves to the end > > of the 2nd parenthesized group, not to the end of the first group. > > Welcome to the twisty maze of tree-sitter grammars. C-M-n is unable > to move to the first group because it's inside the node in the AST: > > (cast_expression "(" > type: (type_descriptor type: (type_identifier)) > ")" > value: > (call_expression function: (identifier) > arguments: > (argument_list "(" (identifier) , > (string_literal " (string_content) ") > ")"))) > > Both the first and the 2nd parenthesized groups are inside the > "cast_expression" node. Sorry, I don't follow: the parentheses of the argument list are also inside a node, and yet we do recognize them. What's the difference? > > As for terminology: the Emacs user manual calls these "groupings > > delimited by parentheses (or whatever else serves as delimiters in the > > language you are working with)", or in short "parenthetical group". > > Why cannot we keep this terminology? It sounds like it describes its > > subject as accurate as we can come up with. > > So you prefer "group" over "list"? As a shorthand; the better term is "parenthesized group". > Then 'forward-list' should move over "group"? I'm not sure we should rename the commands, given the legacy. But the doc string should use "group" or "parenthesized group", IMO.