From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun Date: Wed, 30 Nov 2022 02:33:34 -0800 Message-ID: <14C14797-987C-43D2-9A45-F8DB6AD898DE@gmail.com> References: <874juig9ji.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38553"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59662@debbugs.gnu.org, theo@thornhill.no To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 30 11:35:28 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 1p0KR4-0009if-Gi for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Nov 2022 11:35:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0KQ3-0003ls-2W; Wed, 30 Nov 2022 05:34:24 -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 1p0KPi-0003j0-Gp for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2022 05:34:06 -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 1p0KPi-0003GC-2N for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2022 05:34:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p0KPh-0007AI-MG for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2022 05:34:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <874juig9ji.fsf@thornhill.no> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Nov 2022 10:34: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.166980442527530 (code B ref 59662); Wed, 30 Nov 2022 10:34:01 +0000 Original-Received: (at 59662) by debbugs.gnu.org; 30 Nov 2022 10:33:45 +0000 Original-Received: from localhost ([127.0.0.1]:60127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p0KPR-00079y-1T for submit@debbugs.gnu.org; Wed, 30 Nov 2022 05:33:45 -0500 Original-Received: from mail-pj1-f43.google.com ([209.85.216.43]:38702) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p0KPN-00079q-Us for 59662@debbugs.gnu.org; Wed, 30 Nov 2022 05:33:43 -0500 Original-Received: by mail-pj1-f43.google.com with SMTP id l22-20020a17090a3f1600b00212fbbcfb78so1502401pjc.3 for <59662@debbugs.gnu.org>; Wed, 30 Nov 2022 02:33:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=1Rz0uQAsTLzsUS1EenXt/C+eLodx9v/dNRSXeqQy6Rg=; b=JvzQvEnqzZWGkA7crFyzSdTzFbfMGYoIRyNMEHsRkg7JK3FsNOGvLQtIzPpTNVMGmQ lB7JcYlxC7LbgI2iuFzfn5ypiaiWzsing70kL/J0NAij/M1wlr0msj9rv6Fv8xsp6Vfi t2edixYYxedL05HYwarZneiz+6OGtcGKm+3a0MoHZCA9QjpL1DvEfMHl964RZDq2icTm WSPnZc/RiR7Q1Xl4YdyKIpgm237OdO3mf2dyLKKQU22u6MRJIWkHDL4j42uJTLvHQLpQ 8zTIB32FL6cBIuRS9n3qkqcagezQEs86zpGnT+8AA9tHIKC+hsSbJIrKjGbU+huluhdx CoZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1Rz0uQAsTLzsUS1EenXt/C+eLodx9v/dNRSXeqQy6Rg=; b=4Z7lziHY84LA814QR96YsfugX5Qb/dqaCm3E9H2vl+w7kTVTHATOu8QtPPhFlVgBz8 DLKRb2P0gXhv/UaSy2eIhCwq9HfcAoll7Xm/bkIRUJVWZZgcoUiSk8oemU20zKnRjquv chLpFzyr++/eg35djr53jhfhY8SrCy7JyrAybKQS2UhA+I2ugVLkdo3SkiLetlP5E/25 LGvXZlYjPUe39Ewyar3JbKOkhkfVkiX+cmyOSRpUb8r8lo73LLjD+7LuLb1+SPWaeQh6 HR92fkaz/J+q/PTWrsGVBvTOX0kN+itG/NlNb0JmnWwrMuvu2zR6rg0jNxSoZ0wjFJoz r9mA== X-Gm-Message-State: ANoB5pnAKHD5im0mNmb7LkoTCaPD0LcwaXiJc0jAtQ6AoSSECK7WWqXA dm8n7BhBS7UsJ3zz0vGWsYw= X-Google-Smtp-Source: AA0mqf4hq4vNQViFsS0zfsajRbyjGtgs/C2KUI8olygf8tuIM1p/HDqWTVShb85LyRyKWjebPDtL7w== X-Received: by 2002:a17:90a:fa03:b0:219:813:bcb3 with SMTP id cm3-20020a17090afa0300b002190813bcb3mr28348329pjb.82.1669804416121; Wed, 30 Nov 2022 02:33:36 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id 16-20020a630f50000000b004767bc37e03sm744824pgp.39.2022.11.30.02.33.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Nov 2022 02:33:35 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:249480 Archived-At: Eli Zaretskii writes: > Resending with correct address of Yuan. > >> From: Theodor Thornhill >> Cc: 59662@debbugs.gnu.org, casouri@gmail.org >> Date: Tue, 29 Nov 2022 13:14:21 +0100 >>=20 >> Eli Zaretskii writes: >>=20 >> >> Cc: eliz@gnu.org, casouri@gmail.org >> >> From: Theodor Thornhill >> >> Date: Mon, 28 Nov 2022 20:32:01 +0100 >> >>=20 >> >> I've added a function to treesit.el, for use in >> >> treesit-major-mode-setup. Because the treesit-defun-type-regexp = gives >> >> us "defuns" for free, we can set fill-paragraph-function to this = new >> >> function, thus enabling quick formatting, and some sensible = default for >> >> fill-paragraph. It aims to mirror c-indent-defun. >> >>=20 >> >> I think this is a nice way to get this functionality for free, but = I'm >> >> not 100% whether this is considered ok or not. >> > >> > Sounds good, but why did you think it wouldn't be OK? Anything = here that >> > doesn't meet the eye? >> > >>=20 >> Not really, but see below answer. >>=20 >> >> An alternative could be to add a 'treesit-mode-map' where we can >> >> auto-enable such constructs. >> > >> > I think this is less desirable. >> > >> > Yuan, WDYT? >> > >> >> @@ -1698,7 +1713,10 @@ treesit-major-mode-setup >> >> ;; Navigation. >> >> (when treesit-defun-type-regexp >> >> (setq-local beginning-of-defun-function = #'treesit-beginning-of-defun) >> >> - (setq-local end-of-defun-function #'treesit-end-of-defun))) >> >> + (setq-local end-of-defun-function #'treesit-end-of-defun)) >> >> + ;; Filling >> >> + (when (and treesit-defun-type-regexp = treesit-simple-indent-rules) >> >> + (setq-local fill-paragraph-function = #'treesit--indent-defun))) >> > >> > I'm a bit confused: if the function's name is = treesit--indent-defun, and it >> > uses treesit-indent-region to do its job, why do we assign it to >> > fill-paragraph-function, which is supposed to _fill_, not to = _indent_? >>=20 >> This is why I was thinking it would maybe be better to put it into a >> treesit-mode-map that major-modes can inherit from, thus binding it = to >> things such as C-c C-q. The reason I put it in filling was because = that >> is a common key to press in everything _but_ prog-modes. And = prog-modes >> seem to mostly just turn it off if not inside of comments etc. This >> would behave just like that, except we would reformat/reindent/refill >> code. >>=20 >> In a way filling _is_ formatting/reindenting, at least that's how I = look >> at it. >>=20 >> Theo >>=20 I was caught up in some stuff the past two days, sorry about that :-) I=E2=80=99ll have a look tomorrow! Yuan