From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58873: 29.0.50; Fix indent-line-function in tree-sitter Date: Sat, 29 Oct 2022 21:11:27 +0200 Message-ID: <87eduqsaw0.fsf@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22854"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com To: 58873@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 29 21:12:16 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 1oorFf-0005ig-Vy for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 29 Oct 2022 21:12:15 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oorFV-0000XF-1y; Sat, 29 Oct 2022 15:12:05 -0400 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 1oorFT-0000X4-Do for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 15:12:03 -0400 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 1oorFS-0000Q6-Rx for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 15:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oorFS-0005vo-Bx for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 15:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Oct 2022 19:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58873 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166707069822764 (code B ref -1); Sat, 29 Oct 2022 19:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Oct 2022 19:11:38 +0000 Original-Received: from localhost ([127.0.0.1]:36675 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oorF4-0005v6-5f for submit@debbugs.gnu.org; Sat, 29 Oct 2022 15:11:38 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:42552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oorEz-0005uv-3G for submit@debbugs.gnu.org; Sat, 29 Oct 2022 15:11:36 -0400 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 1oorEy-0000Um-UF for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 15:11:32 -0400 Original-Received: from out2.migadu.com ([188.165.223.204]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oorEx-0000Li-4k for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2022 15:11:32 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. Received-SPF: pass client-ip=188.165.223.204; envelope-from=theo@thornhill.no; helo=out2.migadu.com 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246568 Archived-At: --=-=-= Content-Type: text/plain Hi Yuan! There were some regressions with the new indent-line-function - see attached patch. We need the point, not the indentation, and the save-excursion is actually needed. consider: ``` foo({ thing: 1, tho|ng: 2, // <--- point is | }) ``` if you indent now you want to end up like this: ``` foo({ thing: 1, tho|ng: 2, // <--- point is | }) ``` or if ``` foo({ thing: 1, |thong: 2, // <--- point is | }) ``` You want to end up like this: ``` foo({ thing: 1, |thong: 2, // <--- point is | }) ``` This patch addresses this :-) In addition there was a bug where the parent-bol didn't indent correctly, this should also be fixed now. Thanks again, Yuan! Theo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-indent-line-function.patch Content-Description: Fix indent-line-function in tree-sitter >From b8af08cbe03b66437901af2164e3b31c7df46f04 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Sat, 29 Oct 2022 21:03:23 +0200 Subject: [PATCH] Fix indent-line-function * lisp/treesit.el (treesit-simple-indent-presets): We need the actual position, not the indentation offset from column 0. Revert earlier change. (treesit-indent): Revert earlier change to preserve behavior with similar functions for other modes. Specifically. We want to preserve position in text if we are "in front of" the indentation goal. Otherwise just jump to the correct indentation. --- lisp/treesit.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index dd0aca5049..4032af5f14 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -783,7 +783,8 @@ treesit-simple-indent-presets (lambda (_n parent &rest _) (save-excursion (goto-char (treesit-node-start parent)) - (current-indentation))))) + (back-to-indentation) + (point))))) (prev-sibling . ,(byte-compile (lambda (node &rest _) (treesit-node-start @@ -973,13 +974,19 @@ treesit--indent-1 (defun treesit-indent () "Indent according to the result of `treesit-indent-function'." (treesit-update-ranges) - (pcase-let* ((`(,anchor . ,offset) (treesit--indent-1))) + (pcase-let* ((orig-pos (point)) + (bol (save-excursion + (back-to-indentation) + (point))) + (`(,anchor . ,offset) (treesit--indent-1))) (when (and anchor offset) (let ((col (+ (save-excursion (goto-char anchor) (current-column)) offset))) - (indent-line-to col))))) + (if (< bol orig-pos) + (save-excursion (indent-line-to col)) + (indent-line-to col)))))) (defvar treesit--indent-region-batch-size 400 "How many lines of indent value do we precompute. -- 2.34.1 --=-=-=--