From unknown Fri Jun 20 07:13:54 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#62158 <62158@debbugs.gnu.org> To: bug#62158 <62158@debbugs.gnu.org> Subject: Status: treesit-end-of-defun error Reply-To: bug#62158 <62158@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:13:54 +0000 retitle 62158 treesit-end-of-defun error reassign 62158 emacs submitter 62158 Juri Linkov severity 62158 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 13 03:35:32 2023 Received: (at submit) by debbugs.gnu.org; 13 Mar 2023 07:35:33 +0000 Received: from localhost ([127.0.0.1]:33523 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pbciS-0002JV-Ig for submit@debbugs.gnu.org; Mon, 13 Mar 2023 03:35:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:41778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pbciQ-0002JI-Br for submit@debbugs.gnu.org; Mon, 13 Mar 2023 03:35:30 -0400 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 1pbciP-0008Lp-Lf for bug-gnu-emacs@gnu.org; Mon, 13 Mar 2023 03:35:30 -0400 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbciO-0008PZ-03 for bug-gnu-emacs@gnu.org; Mon, 13 Mar 2023 03:35:29 -0400 Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id F31AC20005 for ; Mon, 13 Mar 2023 07:35:21 +0000 (UTC) From: Juri Linkov To: bug-gnu-emacs@gnu.org Subject: treesit-end-of-defun error Organization: LINKOV.NET Date: Mon, 13 Mar 2023 09:28:59 +0200 Message-ID: <868rg13y9w.fsf_-_@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2001:4b98:dc4:8::227; envelope-from=juri@linkov.net; helo=relay7-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) X-Debbugs-Cc: Yuan Fu , Dmitry Gutov Since this is a separate problem, I'm closing bug#62086 and opening a new bug report: >>>> I don't know if the second bug is related to this, but while >>>> in the same file, also type 'C-M-l' ('reposition-window'). >>>> It raises the error: >>>> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil) >>>> treesit-end-of-defun() >>>> end-of-defun(-1) >>>> reposition-window(nil nil) >>>> reposition-window(nil 89) >>>> funcall-interactively(reposition-window nil 89) >>>> command-execute(reposition-window) >> I see it only in some files in test/lisp/progmodes/ruby-mode-resources/ >> e.g. ruby-parenless-call-arguments-indent.rb, ruby-method-call-indent.rb, >> ruby-block-indent.rb. But not in e.g. ruby-after-operator-indent.rb. >> Also everywhere in test/lisp/progmodes/js-resources/js-indent-init-dynamic.js, >> js-indent-init-t.js. But not in e.g. js-chain.js. > > Thanks, I can repro. I might have been trying the wrong binding at the end > last night (C-l instead of C-M-l). > > The fix seems to be easy: > > diff --git a/lisp/treesit.el b/lisp/treesit.el > index c118f5d52a4..b271a1f0c4b 100644 > --- a/lisp/treesit.el > +++ b/lisp/treesit.el > @@ -1882,6 +1882,7 @@ treesit-end-of-defun > `treesit-defun-skipper'." > (interactive "^p\nd") > (let ((orig-point (point))) > + (if (or (null arg) (= arg 0)) (setq arg 1)) > (catch 'done > (dotimes (_ 2) ; Not making progress is better than infloop. > > But I'm not quite sure if that is what we want to do. > > More naturally, I think, would be to remove the argument from > treesit-end-of-defun altogether (and adjust the code accordingly), because > end-of-defun-function is documented to take no arguments. > > The only other place where treesit-end-of-defun seems to be used is the > binding set up by treesit-major-mode-setup. > > Why not keep the default bindings for these? When > beginning-of-defun-function and end-of-defun-function are set > appropriately, they should work fine. Don't they? > > Cc'ing Yuan on that subject. From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 13 18:04:58 2023 Received: (at 62158) by debbugs.gnu.org; 13 Mar 2023 22:04:58 +0000 Received: from localhost ([127.0.0.1]:35757 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pbqHq-0007CK-1P for submit@debbugs.gnu.org; Mon, 13 Mar 2023 18:04:58 -0400 Received: from mail-pl1-f174.google.com ([209.85.214.174]:38610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pbqHo-0007C8-Km for 62158@debbugs.gnu.org; Mon, 13 Mar 2023 18:04:57 -0400 Received: by mail-pl1-f174.google.com with SMTP id ja10so4892794plb.5 for <62158@debbugs.gnu.org>; Mon, 13 Mar 2023 15:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678745091; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=jklrmpaHIu7ryTNuNTajo2ZUpOYjFrb8FwFeHpS7x5w=; b=dzUX8UyIXr4Qmr8BSAHoPtrEsBJoKi6VkTt9ouhckOIXSWPcAw8bxRtsQQSa97oUcb e33JQhotlo322igPc77nMMDwXfg4JYQTf03VnAhFb1I4QV6SIsm1dxhOpK+YRveb+zjI fyY5HyOsU3uG8DidzDQmOzeurNHVYKwuvnmpjvyceEv61jgFgaNqwEAIAJ6HmydsDbHu Uh9YotM65vTGYVJPu4LCSRUp354FnEBWs/5Rih3RkY9JTDZzY2pA2GuIidKtXqS9H8C0 Y7Veno0vXbHhn1d8kEGp84V1gW392hzJa0rizVkKwlUldL5re954NVj/6bQ0AkD+NffY B62Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678745091; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jklrmpaHIu7ryTNuNTajo2ZUpOYjFrb8FwFeHpS7x5w=; b=S4exoAMHH3dpBEHBULcRkF4ykftmpwxY2uqKuCeU5xaT3ux8MFfsDZ37KEBZKS2INB MXMNXY7dJ5lutw8s3UKNMghAaPlAAuAMenYDXEN7TGpgGyQuiZxguLMfzzwYFfw876Y4 Q7c6RIBymuPdQl8kQVMb0wfovYgxtKRRpvkrGrpZTNpvNU3B0k2x8KOvJ2UScX1wKtYR a4xnPiMza5Lwiraqz9pMm/CUdPcRxMeqiQmbxqY2u+5MBSOiLeZ36zHb9ca7YzORDlDj d+NI5A9BoFSqSoKN8wcnVYNlYh+UvnDw7pjByzG6OEjlEI/wWgFlhcd+pjPUnP/z5RB3 zpOg== X-Gm-Message-State: AO0yUKXmvzfxZvpzr5cpeN7LPovU78RMCZ74Vs2EKbhrX/CojHY8ebMb aDzMS4g0xqOqOivRmn30tZ0= X-Google-Smtp-Source: AK7set+XtoBEcxZfGOCL96fXG41LZcbs6Z64SSWrRtD8RlAXIgmti+luA8ewtEHGaIBC3szZ5xjFsQ== X-Received: by 2002:a17:902:c407:b0:19e:21d0:5b90 with SMTP id k7-20020a170902c40700b0019e21d05b90mr21716619plk.4.1678745090775; Mon, 13 Mar 2023 15:04:50 -0700 (PDT) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id h4-20020a170902748400b001a0616d7624sm285722pll.302.2023.03.13.15.04.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2023 15:04:50 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Subject: Re: bug#62158: treesit-end-of-defun error From: Yuan Fu In-Reply-To: <868rg13y9w.fsf_-_@mail.linkov.net> Date: Mon, 13 Mar 2023 15:04:37 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <48E5D6CC-3249-4A5E-82B6-D3B9BF37D40A@gmail.com> References: <868rg13y9w.fsf_-_@mail.linkov.net> To: Juri Linkov X-Mailer: Apple Mail (2.3731.400.51.1.1) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 62158 Cc: 62158@debbugs.gnu.org, dmitry gutov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Mar 13, 2023, at 12:28 AM, Juri Linkov wrote: >=20 > X-Debbugs-Cc: Yuan Fu , Dmitry Gutov = >=20 > Since this is a separate problem, I'm closing bug#62086 > and opening a new bug report: >=20 >>>>> I don't know if the second bug is related to this, but while >>>>> in the same file, also type 'C-M-l' ('reposition-window'). >>>>> It raises the error: >>>>> Debugger entered--Lisp error: (wrong-type-argument = number-or-marker-p nil) >>>>> treesit-end-of-defun() >>>>> end-of-defun(-1) >>>>> reposition-window(nil nil) >>>>> reposition-window(nil 89) >>>>> funcall-interactively(reposition-window nil 89) >>>>> command-execute(reposition-window) >>> I see it only in some files in = test/lisp/progmodes/ruby-mode-resources/ >>> e.g. ruby-parenless-call-arguments-indent.rb, = ruby-method-call-indent.rb, >>> ruby-block-indent.rb. But not in e.g. = ruby-after-operator-indent.rb. >>> Also everywhere in = test/lisp/progmodes/js-resources/js-indent-init-dynamic.js, >>> js-indent-init-t.js. But not in e.g. js-chain.js. >>=20 >> Thanks, I can repro. I might have been trying the wrong binding at = the end >> last night (C-l instead of C-M-l). >>=20 >> The fix seems to be easy: >>=20 >> diff --git a/lisp/treesit.el b/lisp/treesit.el >> index c118f5d52a4..b271a1f0c4b 100644 >> --- a/lisp/treesit.el >> +++ b/lisp/treesit.el >> @@ -1882,6 +1882,7 @@ treesit-end-of-defun >> `treesit-defun-skipper'." >> (interactive "^p\nd") >> (let ((orig-point (point))) >> + (if (or (null arg) (=3D arg 0)) (setq arg 1)) >> (catch 'done >> (dotimes (_ 2) ; Not making progress is better than infloop. >>=20 >> But I'm not quite sure if that is what we want to do. This looks good to me. >>=20 >> More naturally, I think, would be to remove the argument from >> treesit-end-of-defun altogether (and adjust the code accordingly), = because >> end-of-defun-function is documented to take no arguments. >>=20 >> The only other place where treesit-end-of-defun seems to be used is = the >> binding set up by treesit-major-mode-setup. >>=20 >> Why not keep the default bindings for these? When >> beginning-of-defun-function and end-of-defun-function are set >> appropriately, they should work fine. Don't they? We tried that initially, but end-of-defun doesn=E2=80=99t have the = notion of nested defuns, which leads to problems when = end-of-defun-function recognizes nested defuns. In the following code (defun xxx () | (defun yyy () ...) (defun zzz () ...) ) If point is at =E2=80=9C|=E2=80=9D and you call end-of-defun, you=E2=80=99= d expect point to move to the end of yyy, but instead it moves to the = end of xxx. That=E2=80=99s because end-of-defun first runs = (beginning-of-defun -1) followed by (end-of-defun 1) to check if the = starting point is in a defun or between two defuns. This is fine in = non-nested defuns, but in this example, the point first goes to the = beginning of xxx, then goes to the end of xxx. And end-of-defun thinks = that we started in a defun and now is at an end of defun, job=E2=80=99s = done, and finishes. The plan is to improve end-of-defun to support nested defuns in Emacs = 30. For now we rebind end-of-defun to treesit-end-of-defun. Yuan= From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 20 14:22:31 2023 Received: (at 62158) by debbugs.gnu.org; 20 Mar 2023 18:22:32 +0000 Received: from localhost ([127.0.0.1]:56771 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1peK9P-0007XD-LC for submit@debbugs.gnu.org; Mon, 20 Mar 2023 14:22:31 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:59373) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1peK9N-0007Wx-Rc; Mon, 20 Mar 2023 14:22:30 -0400 Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 26422E0008; Mon, 20 Mar 2023 18:22:20 +0000 (UTC) From: Juri Linkov To: Yuan Fu Subject: Re: bug#62158: treesit-end-of-defun error In-Reply-To: <48E5D6CC-3249-4A5E-82B6-D3B9BF37D40A@gmail.com> (Yuan Fu's message of "Mon, 13 Mar 2023 15:04:37 -0700") Organization: LINKOV.NET References: <868rg13y9w.fsf_-_@mail.linkov.net> <48E5D6CC-3249-4A5E-82B6-D3B9BF37D40A@gmail.com> Date: Mon, 20 Mar 2023 20:21:38 +0200 Message-ID: <868rfrthal.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 62158 Cc: 62158@debbugs.gnu.org, Dmitry Gutov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) close 62158 29.0.60 thanks >>> The fix seems to be easy: >>> >>> diff --git a/lisp/treesit.el b/lisp/treesit.el >>> index c118f5d52a4..b271a1f0c4b 100644 >>> --- a/lisp/treesit.el >>> +++ b/lisp/treesit.el >>> @@ -1882,6 +1882,7 @@ treesit-end-of-defun >>> `treesit-defun-skipper'." >>> (interactive "^p\nd") >>> (let ((orig-point (point))) >>> + (if (or (null arg) (= arg 0)) (setq arg 1)) >>> (catch 'done >>> (dotimes (_ 2) ; Not making progress is better than infloop. >>> >>> But I'm not quite sure if that is what we want to do. > > This looks good to me. So Dmitry's fix is pushed to emacs-29. From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 20 14:44:02 2023 Received: (at 62158) by debbugs.gnu.org; 20 Mar 2023 18:44:02 +0000 Received: from localhost ([127.0.0.1]:56802 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1peKUE-00021m-Gz for submit@debbugs.gnu.org; Mon, 20 Mar 2023 14:44:02 -0400 Received: from mail-wr1-f52.google.com ([209.85.221.52]:34724) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1peKUC-00021A-Sw for 62158@debbugs.gnu.org; Mon, 20 Mar 2023 14:44:01 -0400 Received: by mail-wr1-f52.google.com with SMTP id v1so5268109wrv.1 for <62158@debbugs.gnu.org>; Mon, 20 Mar 2023 11:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679337835; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=wkf5LE3UJQYVyY8O1+rCxwIWR6IxXNopWcWMLT7KQGo=; b=dLacG6LgbJZ4ozFKT+ay2nK0XKRGKGsqF7vt/YgMqB5JZtTE2D8Kt92HPbihIKzc/N oG4w735eC4oCwppdbQMHsMEJPQuRTY25M7/VDcPW5Bz+wVZL5czHGt7wPnzqqXG0CMb3 p38Y706PmZdxfzeKA6nvf/emxmcEkOw4zGUr5ilkzAqN122wZRKhzj2BD2NCYnGn3wgp YIxfI8y6PJdNNOp2/7gXC9rDt7Qe3WMZtjmShX35jOQAAMCqso7alyOeC4rflakVqP+r f4Tjtgz8QGA00GqfqHvHR8AeOwdJAPXt09K1QWxX7quRPqbzzcdSLuVS3O9IG4SOaSRB 6/hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679337835; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wkf5LE3UJQYVyY8O1+rCxwIWR6IxXNopWcWMLT7KQGo=; b=d109VmFfxP5ULRkZxxXoHNHBAh9Gek9B3asl9+zQJMCshhxMyGGUn9Oc900f69w1GY jJpOAil4jVaooRBdr5jebYyLcUmSpzqqxXu8YY+n5nYCuHEl1kWY/hlKfgwNcQx0n0NV aA1qubphDdeuPaEtTds1vIdD1yTjzbWZ+tujlYwWS2rmkFtGpdj0YTLzzPakjlnruaIb kc9/SggnZV1YOVBboaU4/egQP8dyqCOejbPpTawRxgelVOyaEYcSrAea6VGVVyLV0NJa HtJfp2VrpUu5IVZdTBWzn/TkTaA6PJ865yKJyzBuU/G3ZzKFpM8l9i0nQtPMsKXaCEZI 89Pg== X-Gm-Message-State: AO0yUKWy9FxGuWpExwOTTmep6zdlf+ijBEipjyjFBquzotSbgG5KkLcl 5U1/axyr1Jn/lGPJjlzi4fQ= X-Google-Smtp-Source: AK7set/bDFDokmRSeN9K/8C6ZrSBwIVAUfbw/O77F3lvxFqSU+I42/RDuWRzNdyDCq007xvXMww2vw== X-Received: by 2002:a5d:5381:0:b0:2cf:ee3b:950 with SMTP id d1-20020a5d5381000000b002cfee3b0950mr253359wrv.54.1679337834673; Mon, 20 Mar 2023 11:43:54 -0700 (PDT) Received: from [192.168.0.2] ([85.132.229.92]) by smtp.googlemail.com with ESMTPSA id bg7-20020a05600c3c8700b003eb2e33f327sm28962392wmb.2.2023.03.20.11.43.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Mar 2023 11:43:54 -0700 (PDT) Message-ID: Date: Mon, 20 Mar 2023 20:43:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: bug#62158: treesit-end-of-defun error To: Yuan Fu , Juri Linkov References: <868rg13y9w.fsf_-_@mail.linkov.net> <48E5D6CC-3249-4A5E-82B6-D3B9BF37D40A@gmail.com> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <48E5D6CC-3249-4A5E-82B6-D3B9BF37D40A@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -0.9 (/) X-Debbugs-Envelope-To: 62158 Cc: 62158@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.9 (-) On 14/03/2023 00:04, Yuan Fu wrote: > We tried that initially, but end-of-defun doesn’t have the notion of nested defuns, which leads to problems when end-of-defun-function recognizes nested defuns. In the following code > > (defun xxx () > | > (defun yyy () ...) > > (defun zzz () ...) > ) > > If point is at “|” and you call end-of-defun, you’d expect point to move to the end of yyy, but instead it moves to the end of xxx. That’s because end-of-defun first runs (beginning-of-defun -1) followed by (end-of-defun 1) to check if the starting point is in a defun or between two defuns. This is fine in non-nested defuns, but in this example, the point first goes to the beginning of xxx, then goes to the end of xxx. And end-of-defun thinks that we started in a defun and now is at an end of defun, job’s done, and finishes. > > The plan is to improve end-of-defun to support nested defuns in Emacs 30. For now we rebind end-of-defun to treesit-end-of-defun. That makes sense, thanks! I guess one of the things to try is to call end-of-defun-function first, followed by beginning-of-defun-function. And see if the resulting position is below the original point. From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 21 17:26:47 2023 Received: (at 62158) by debbugs.gnu.org; 21 Mar 2023 21:26:47 +0000 Received: from localhost ([127.0.0.1]:32781 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pejVG-0002va-RE for submit@debbugs.gnu.org; Tue, 21 Mar 2023 17:26:47 -0400 Received: from mail-pj1-f48.google.com ([209.85.216.48]:36558) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pejVE-0002vH-GS for 62158@debbugs.gnu.org; Tue, 21 Mar 2023 17:26:45 -0400 Received: by mail-pj1-f48.google.com with SMTP id o6-20020a17090a9f8600b0023f32869993so17785417pjp.1 for <62158@debbugs.gnu.org>; Tue, 21 Mar 2023 14:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679433998; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TLa0LDB51soRq3eDo+VNawEAx/DUPnB4TfHuQ+pxZek=; b=g21ZOaJ3aIVhAZI2NFed+HQo/HL4nh0jKEf4J9fiYsuLXhUbtylA8MJAC2SUm3nVrl OALpKWsfmiTQqwJT3Nmbc71PVNISsTorUJRlM+6ih3YvgSCOCSMJHB8URjkISilrtK2k +hikTNc7LSxYDZ5Ib7XHjahjcBR07n0jhZ2DOvbZIzOADEHsopsLZ3gKCHRIoHeeQBmS GK30o+ZM94VHc8S4v8iEQ0+Vjvrp++ivhF6E7ZjYkUr8r3F0Mg4ewpY4FmR8TDkzlUrj wSJKhD5ISY/6khcWa+vijn6MsBpbuODad6a+RJraGvKgMNKq4BBFscyj+C45mb82384v jraw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679433998; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TLa0LDB51soRq3eDo+VNawEAx/DUPnB4TfHuQ+pxZek=; b=42ZdF4Nz3mIGeIoixDr5zGbk99Ty/oxN/1QNqylQg0PHumiuYN1zyXRZwvNxMIwszY IUbOvml1J2NYh9x6Ww7/fEi42brWsmmtQy+nsnTRMnwbeiQd83wOoiYLa37hBDA8QWSt qGmGRmR93w1mttvj5AHurrqE2XXGsPbK+fqyy3XZz2XvTXkzYSSgHNpMLGQPVy86j1z1 siImeQmC2xicoKTJBMgoyv6ccbBBF0TRBpM1YemysmVIWNJbNzYcAsJwrX7WiYHM7SLr 9i2HOICnv9xIADOEb/Ev0YnTbaa5VVMyQRg23BkdGhYlQNKJHPMV5lXIe+znw+qmuC0N g3dQ== X-Gm-Message-State: AO0yUKUqfwJpJ3tzaovj8UltBbJeQZVL1Q1c8xzciAsNOvjfDwNpFBai 5cxnnlRdgOmBGL1fVK6J+qU= X-Google-Smtp-Source: AK7set+w0yphtqPMH11rLxbUCp+ysWWP2ZE+ckAG6kPUM1sXQ1qT+dXUewL6U5xAZS94Xn9cv334qg== X-Received: by 2002:a05:6a20:1e46:b0:da:17b4:461a with SMTP id cy6-20020a056a201e4600b000da17b4461amr2509247pzb.32.1679433998280; Tue, 21 Mar 2023 14:26:38 -0700 (PDT) Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id b2-20020aa78702000000b00592543d7363sm8718421pfo.1.2023.03.21.14.26.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Mar 2023 14:26:37 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Subject: Re: bug#62158: treesit-end-of-defun error From: Yuan Fu In-Reply-To: Date: Tue, 21 Mar 2023 14:26:26 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <8CC10648-87D5-455F-BE3D-43E7A4EC94C5@gmail.com> References: <868rg13y9w.fsf_-_@mail.linkov.net> <48E5D6CC-3249-4A5E-82B6-D3B9BF37D40A@gmail.com> To: Dmitry Gutov X-Mailer: Apple Mail (2.3731.400.51.1.1) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 62158 Cc: 62158@debbugs.gnu.org, Juri Linkov X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > On Mar 20, 2023, at 11:43 AM, Dmitry Gutov wrote: >=20 > On 14/03/2023 00:04, Yuan Fu wrote: >> We tried that initially, but end-of-defun doesn=E2=80=99t have the = notion of nested defuns, which leads to problems when = end-of-defun-function recognizes nested defuns. In the following code >> (defun xxx () >> | >> (defun yyy () ...) >> (defun zzz () ...) >> ) >> If point is at =E2=80=9C|=E2=80=9D and you call end-of-defun, you=E2=80= =99d expect point to move to the end of yyy, but instead it moves to the = end of xxx. That=E2=80=99s because end-of-defun first runs = (beginning-of-defun -1) followed by (end-of-defun 1) to check if the = starting point is in a defun or between two defuns. This is fine in = non-nested defuns, but in this example, the point first goes to the = beginning of xxx, then goes to the end of xxx. And end-of-defun thinks = that we started in a defun and now is at an end of defun, job=E2=80=99s = done, and finishes. >> The plan is to improve end-of-defun to support nested defuns in Emacs = 30. For now we rebind end-of-defun to treesit-end-of-defun. >=20 > That makes sense, thanks! >=20 > I guess one of the things to try is to call end-of-defun-function = first, followed by beginning-of-defun-function. And see if the resulting = position is below the original point. Unfortunately, end-of-defun-function must be called from the beginning = of a defun, according to its docstring. So that won=E2=80=99t do. We got = to upgrade beginning/end-of-defun to support nested defuns. Yuan= From unknown Fri Jun 20 07:13:54 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 19 Apr 2023 11:24:15 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator