From unknown Sun Jun 15 08:59:55 2025 X-Loop: help-debbugs@gnu.org Subject: bug#66763: end-of-defun discrepancy depending mode Resent-From: Simon Tournier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Oct 2023 16:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66763 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 66763@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.169833625315728 (code B ref -1); Thu, 26 Oct 2023 16:05:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 Oct 2023 16:04:13 +0000 Received: from localhost ([127.0.0.1]:34373 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qw2qD-00045Y-6Y for submit@debbugs.gnu.org; Thu, 26 Oct 2023 12:04:13 -0400 Received: from lists.gnu.org ([2001:470:142::17]:35810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qw2q7-00044r-HH for submit@debbugs.gnu.org; Thu, 26 Oct 2023 12:04:11 -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 1qw2pW-0003EI-Oi for bug-gnu-emacs@gnu.org; Thu, 26 Oct 2023 12:03:30 -0400 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qw2pV-0006gD-3A for bug-gnu-emacs@gnu.org; Thu, 26 Oct 2023 12:03:30 -0400 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c51774da07so3465741fa.1 for ; Thu, 26 Oct 2023 09:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698336207; x=1698941007; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=/r+Zz0P74W5WT8oMhNQLnsUHN8Kiv4a4BBH2yM1Dso8=; b=IGQKWwd1uocenQlUCsFdKkQpc707rwGbUps06AL9qc+9QLqOpizGsGTAQOxJUoaGbQ vnPrdihUCBd7HYDGu01AamHLbYqpkt0JnC6Z6GeddHpu9Esh5LqIRx25Z/M4rNtK1t+f /IN/viSis9pmtn50w8RC5iKIfyJ41BgcU0KGu3+GVQeJf65KG+szI54TszkQR3bUTlW1 pFP1xXO9I6qlIbX2szba3DSBjve6lX9mBsErNrPChxiAvh1VBF2Xuas26NMk2evuq4oS UcwrWR9YisLVwSnKvvyRGug2N/1ma097lKHfF8mKxydFPwOS/HvUjKtgaWjOFFXh1VRA uOng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698336207; x=1698941007; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/r+Zz0P74W5WT8oMhNQLnsUHN8Kiv4a4BBH2yM1Dso8=; b=tQI+iATd05cmcXSaX3gNagGP1lsDMWCTI3Ea/jJgDpjJM4HNV1FClFpXoW2w8NJ7Gm HxeMzVk/Z+ZWdcCkOfds7ULp4A1AV0qiUKu5RdPeL/fCBDo1iOtuooK23knj1f5UGFqJ ZPGyp660KB33IrCNWkiT0Pmmmq5BM7fzSvRCCbEALCJvzqR6xnqUZg2wdBGi4iKV6il2 Ks0RRH0F/GhMk1vgyHT+FyGkRqu8UvAkJosdkwt3sl9Rn3dgQnbNI1Lxg+BKIrsuY8BR 8OERu2RVoVVKJhAn0JsZhfjHIhJ5J0xZrhPjB7psTtTuWQKrxJG9ErqB6zsjYypnHpnT Bfug== X-Gm-Message-State: AOJu0YwtkVLhoY5ENQy3s32D0XxAdgvpEcoo23T7W5+k9DqhDcGzO7fD 7ErCj9fo4Mysl2/gdi/M1amkWNM2mpM= X-Google-Smtp-Source: AGHT+IEaR0qp0Caqmt3hZBJTekJfoQ8QYQErZlHlPuWvcrUN8HRpQg72nhmi+gvbk/oRtmorW0TkJg== X-Received: by 2002:a2e:b5b6:0:b0:2c5:2d06:cade with SMTP id f22-20020a2eb5b6000000b002c52d06cademr28705ljn.2.1698336206625; Thu, 26 Oct 2023 09:03:26 -0700 (PDT) Received: from pfiuh07 ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id a1-20020a05600c348100b00402ff8d6086sm2893637wmq.18.2023.10.26.09.03.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 09:03:25 -0700 (PDT) From: Simon Tournier Date: Thu, 26 Oct 2023 17:48:26 +0200 Message-ID: <875y2tgzat.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::22b; envelope-from=zimon.toutoune@gmail.com; helo=mail-lj1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) 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: -0.0 (/) Hi, The manual says: The commands to move to the beginning and end of the current defun are =E2=80=98C-M-a=E2=80=99 (=E2=80=98beginning-of-defun=E2=80=99) and = =E2=80=98C-M-e=E2=80=99 (=E2=80=98end-of-defun=E2=80=99). If you repeat one of these commands, or use a positive numeric argument, each repetition moves to the next defun in the direction of motion. =E2=80=98C-M-a=E2=80=99 with a negative argument =E2=88=92N moves fo= rward N times to the next beginning of a defun. This is not exactly the same place that =E2=80= =98C-M-e=E2=80=99 with argument N would move to; the end of this defun is not usually exactly the same place as the beginning of the following defun. and this behaviour is different for nested definitions depending on the mode. For instance, python-mode: 1 def level(): 2 def sublevel(): 3 def subsublevel(): 4 return subsublevel 5 return sublevel 6 return level If the point is located at line 4, then I press =E2=80=99C-M-a=E2=80=99 and= it moves to the beginning of line 3. Then repeat =E2=80=99C-M-a=E2=80=99 moves to the = beginning of line 2, then repeat =E2=80=99C-M-a=E2=80=99 moves to the beginning of line = 1. If the point is located at line 4, then I press =E2=80=99C-u 3 C-M-a=E2=80= =99 and it moves to the beginning of line 1. So far, so good! That=E2=80=99s the first paragraph from the manual. :-) Now, let do the same with scheme-mode: 1 (define (level) 2 (define (sublevel) 3 (define (subsublevel) 4 'subsublevel) 5 'sublevel) 6 'level) If the point is located at line 4, then I press =E2=80=99C-M-a=E2=80=99 and= it moves to the beginning of line 1. Why? Is it expected? Here is the first part of the bug. Now, consider the second paragraph from the manual. Because of these discrepancy and considering 4489450f37deafb013b1f0fc00c89f0973fda14a (In end-of-defun, terminate early if no further defun exists): --8<---------------cut here---------------start------------->8--- + ;; At this point, point either didn't move (because we started + ;; in between two defun's), or is at the end of a defun + ;; (because we started in the middle of a defun). (unless (zerop arg) - (beginning-of-defun-raw (- arg)) - (funcall end-of-defun-function))) + (when (setq success (beginning-of-defun-raw (- arg))) + (funcall end-of-defun-function)))) --8<---------------cut here---------------end--------------->8--- The behaviour can be subtly tweaked when composing =E2=80=99C-u=E2=80=99 an= d =E2=80=99C-M-e=E2=80=99 for some modes. Cheers, simon