From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun Date: Fri, 9 Dec 2022 00:03:57 +0200 Message-ID: <4215c43c-ee75-ddbe-85da-7fed0129a30b@yandex.ru> References: <5B538888-E454-4F75-B3B8-AB20E10B3E89@gmail.com> <83o7sniokt.fsf@gnu.org> <4D5A1640-4F0F-4C21-8ED6-770B88A870EA@thornhill.no> <83r0xhdluq.fsf@gnu.org> <3e25eadb-3f2b-f92d-8b18-bf1daca91b64@yandex.ru> <83wn78cqz4.fsf@gnu.org> <4d605e69-7df9-6480-c1c5-dcb22abd3bde@yandex.ru> <83y1ri2wnj.fsf@gnu.org> <875yemz55b.fsf@thornhill.no> <83r0xa2tc4.fsf@gnu.org> <87zgbyxohf.fsf@thornhill.no> <83o7se2n89.fsf@gnu.org> <87tu269mox.fsf@thornhill.no> <34c2b5b5-3312-066e-50f4-2aa776d0273f@yandex.ru> <87k032c577.fsf@thornhill.no> <617cb890-b622-4f76-c446-f4c95c377cc5@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20192"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Cc: larsi@gnus.org, 59662@debbugs.gnu.org, casouri@gmail.com, monnier@iro.umontreal.ca To: Theodor Thornhill , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 08 23:05:23 2022 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 1p3P19-00052J-N8 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 08 Dec 2022 23:05:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3P0q-0004kw-Q0; Thu, 08 Dec 2022 17:05:04 -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 1p3P0o-0004j9-O9 for bug-gnu-emacs@gnu.org; Thu, 08 Dec 2022 17:05:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p3P0o-0004tk-Fb for bug-gnu-emacs@gnu.org; Thu, 08 Dec 2022 17:05:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p3P0n-0006Xh-UW for bug-gnu-emacs@gnu.org; Thu, 08 Dec 2022 17:05:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 Dec 2022 22:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59662 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 59662-submit@debbugs.gnu.org id=B59662.167053704825138 (code B ref 59662); Thu, 08 Dec 2022 22:05:01 +0000 Original-Received: (at 59662) by debbugs.gnu.org; 8 Dec 2022 22:04:08 +0000 Original-Received: from localhost ([127.0.0.1]:59406 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p3Ozw-0006XO-FN for submit@debbugs.gnu.org; Thu, 08 Dec 2022 17:04:08 -0500 Original-Received: from mail-wr1-f48.google.com ([209.85.221.48]:34544) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p3Ozu-0006X1-HK for 59662@debbugs.gnu.org; Thu, 08 Dec 2022 17:04:07 -0500 Original-Received: by mail-wr1-f48.google.com with SMTP id o5so3357929wrm.1 for <59662@debbugs.gnu.org>; Thu, 08 Dec 2022 14:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=CUiVxH19yfsj9am+mUj/QeWLlEMNM+BEzA7vqaMELfA=; b=oBd1Yc5gCsT9U9dNgYot0t3RFa6ESWkQLAV+YNK7xYJ7HlEKPBI/f7WK9/VsFxsNm8 Ghb+gnxAjWEqxrOPtZqnN5tXyJviWVQEDOs6nSXjvv3VcJqplKTirNIOQyOBQ1xjMxm0 egfwyaQ6i0jFvyJyKA/qsayIyBCaKS6BCe7zKWs6qPW64/hjmuWcvpF+N0eZjEnrVYF6 xQAuTYch4HtcDw+gSD+AUTXrPPLctmtFpv+voMUGLrBxVm8bbBbK0pZ+YUlVICG+2G3Q YCLYBpxFd0JFCnOikr1rX9AC5jgvtjZ1sv38+3plVUifNZFC/PtFiTTZ9A2JRmvt0q0G ljSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CUiVxH19yfsj9am+mUj/QeWLlEMNM+BEzA7vqaMELfA=; b=qPzgdxM/SfO8HJW3LgsUU9DkV8q67BRWc4qwwepZ3FP5coTI7lxVmuQQbkpNjNm5vg I3vD8SSchY0IrunJSeLOxSV2xf9nisTNSIp4x9jBir4awO+VoDApoq85uT9/JJzYuV0j Pu9xs4JHdCnoaCacwIF9DB2eFJc3vIMtZJQKnW1UBQ/vovh0X/D+06ZeX0VaxcyamcUz r+o/jo8A55+D6SFHR9VowchABwyeltvsK2/HBlwh0kic4D1wBn7XBjRqYSle1OAnFCq3 P0Ewxe+fh667esr88UpxqtHJHirrskrTRkXj1yEuDqTvCAtzLu/ScSXLlybce8SQegB2 9pnA== X-Gm-Message-State: ANoB5pmkyS+kXYndlZs0k7VVZ4nsirNQH8D89WD6L1Rq4/UPRw6KJM9E 1PKe+PjiBzejG7BdBOIHdLA= X-Google-Smtp-Source: AA0mqf4FCfnIx66SOTC9vpxIVU1bftUdvdH8aJZUzc2F3O+by0xtI0DZeOLIRGGUz2ZpmgBUwLITgA== X-Received: by 2002:adf:ebc8:0:b0:236:5e35:7b1a with SMTP id v8-20020adfebc8000000b002365e357b1amr2404801wrn.60.1670537040447; Thu, 08 Dec 2022 14:04:00 -0800 (PST) Original-Received: from [192.168.0.2] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id z4-20020a5d4d04000000b0022ae0965a8asm22734452wrt.24.2022.12.08.14.03.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Dec 2022 14:03:59 -0800 (PST) Content-Language: en-US In-Reply-To: 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:250338 Archived-At: On 08/12/2022 18:33, Theodor Thornhill wrote: > > > On 8 December 2022 17:06:26 CET, Dmitry Gutov wrote: >> On 08/12/2022 16:58, Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: >>> Dmitry Gutov writes: >>> >>>> On 08/12/2022 13:09, Theodor Thornhill wrote: >>>>> What about this? I changed it to make a point that we should fill if >>>>> inside of a string or comment, and indent if inside a code block. We >>>>> one such variable for each type, or in both as suggested below. >>>> Could you rephrase maybe? I'm not seeing the difference. >>> In the first example I made the variable specific to comments. But >>> filling should work on everything that's considered text, IIUC. So if >>> the variable refers to both the regex needs to accommodate strings and >>> comments. That will in turn make it less useful if we want to find >>> comments specifically, or strings specifically. so we could have both >>> 'treesit-comment-regexp' and 'treesit-string-regexp' and match on '(or >>> treesit-comment-regexp treesit-string-regexp)' in this particular case. >>> >>> Not really sure if that made more sense. >> >> Ah. So that was about the name of the variable. Looks good. >> > > Yeah, and thus what nodes it should capture > > >> Note that if the improvement which I described ever comes to life (hopefully), then the variable will probably need to be renamed/moved/multiplied again. > > Why is that? Suppose we have a thingy called tree-sitter-parse-state, or tsps in short. As a general purpose thigy, it would have the means to check whether the state corresponds to a string, or to a comment, at least. Maybe it would be able to signal different kinds of strings and comments as well, but let's put that aside for now. For clients to get that info, it can have a general function that would return the current node (or maybe a derivative of it) -- call it tree-sitter-parse-state, and helpers like tsps-string-p and tsps-comment-p, as well as, possibly, tsps-comment-or-string-start. Maybe other helpers similar to the fields in the ppss defstruct. And it seems to me that to implement tsps-string-p and tsps-comment-p you will need two different constants like that. Then, in turn, prog-fill-or-reindent-defun could be implemented in terms of tsps-string-p and tsps-comment-p. It could also call tsps-comment-or-string[-start], if such helper will be defined, which will internally be implemented either in terms of tsps-*-p functions, or use the two corresponding new constants anyway.