From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#65870: 30.0.50; Error in python-mode when try to delete a character in badly-indented code Date: Sun, 17 Sep 2023 00:06:58 +0900 Message-ID: References: <3a4467d3-f190-4115-b73a-9ae18b31a527@gmail.com> <83led6igai.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sun_Sep_17_00:06:57_2023-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5588"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: Daniel Lopez , 65870@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 16 17:08:17 2023 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 1qhWu8-0001JB-Rv for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Sep 2023 17:08:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhWtu-00048Z-PG; Sat, 16 Sep 2023 11:08:02 -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 1qhWtn-00044s-Gv for bug-gnu-emacs@gnu.org; Sat, 16 Sep 2023 11:08:00 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhWtn-0002yA-8L for bug-gnu-emacs@gnu.org; Sat, 16 Sep 2023 11:07:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qhWtu-0000gH-97 for bug-gnu-emacs@gnu.org; Sat, 16 Sep 2023 11:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Sep 2023 15:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65870 X-GNU-PR-Package: emacs Original-Received: via spool by 65870-submit@debbugs.gnu.org id=B65870.16948768402410 (code B ref 65870); Sat, 16 Sep 2023 15:08:02 +0000 Original-Received: (at 65870) by debbugs.gnu.org; 16 Sep 2023 15:07:20 +0000 Original-Received: from localhost ([127.0.0.1]:48268 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qhWtD-0000cm-Nc for submit@debbugs.gnu.org; Sat, 16 Sep 2023 11:07:20 -0400 Original-Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:57596) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qhWtB-0000c7-3B for 65870@debbugs.gnu.org; Sat, 16 Sep 2023 11:07:18 -0400 Original-Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68fb2e9ebcdso2500793b3a.2 for <65870@debbugs.gnu.org>; Sat, 16 Sep 2023 08:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694876824; x=1695481624; darn=debbugs.gnu.org; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=ETaO6hpcXFCrQDM3NasLz6yvQ+2G9nioPAwVPX0ELJQ=; b=atavX7EgBlll1iahJFOi0Y/ofPwKYkM9srsxlsYvgQVTEhZT4eWv8oITiFXXcKYpz9 8sajKC+1GmCnl74NWfyglzRPq/gCM+G2cefQofRRXfLYHKKfzZFavyYrAoLQWRFpJZ0k 2FKkAGjZVM8lcLelNS2SbAPctXL+uRYLq+sFkxFsJTWtjg2rWGGUkQDr5WT83c7Ln5IY PS0DX9khXr+xf4BMY1hakt54ApSMTbRtDidFVCPwS7L9lwSojwx3hRxW0SXP3vbZtuZ1 LLGVptQgW6w6JKc2jAUNfdmVuTKDYlGHYtugtIs1ovpqty9zq+nvaOulArolD5tsir92 y6oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694876824; x=1695481624; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ETaO6hpcXFCrQDM3NasLz6yvQ+2G9nioPAwVPX0ELJQ=; b=EuX5pqMmgN7acA3v36lzs2DBPuIma4QcxgvU98KcSKqjZOaBTULubOi4WFsqSLUBdZ fjH4N89aPL6LKz09pt55BdZ4XV8nvfYk/mxe3Hfb+IRuOXeUvaKsK81pPeuOV7pIS48W fwZY0okCVjMwBBZdH3qM0w7atNS4SEqEo8B3Q4uwK8JGwHfgTPukILvOvLpu9m71Wv2Z fHgvkqNHsKt+LCfAxQ1C2A0fV9Iv1NeoQ9H4kexVYHVO4PJN9wk6uNsjW+2+hDcr9sNR o2fKt9cRI5tmMqIpwbVm4j/JmYMCEDmZShF6nVzyZt59QJXp68IpLSGYOXS/Bl9/Xyq9 fOxw== X-Gm-Message-State: AOJu0Yxg/0fJMZZy1AJkCafn/gGQKUD1R9fD9Fp6FcTTUwQivfcGqFU4 MhX8KqZqs+Idyf7GL5jEGuA= X-Google-Smtp-Source: AGHT+IGzqUn2d4D1UvKGbX2wlzZDbRMt/xdiqeUHmKzlfLhaoAeHspNgsKvUHIE8GYbPp/2Lf3jfnw== X-Received: by 2002:a05:6a00:1882:b0:68b:f3a4:ff6b with SMTP id x2-20020a056a00188200b0068bf3a4ff6bmr5157560pfh.9.1694876824039; Sat, 16 Sep 2023 08:07:04 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id t25-20020a62ea19000000b0068c6889e146sm4764376pfh.98.2023.09.16.08.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 08:07:03 -0700 (PDT) In-Reply-To: <83led6igai.fsf@gnu.org> 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:270626 Archived-At: --Multipart_Sun_Sep_17_00:06:57_2023-1 Content-Type: text/plain; charset=US-ASCII Eli Zaretskii wrote: > > Date: Mon, 11 Sep 2023 17:36:59 +0100 > > From: Daniel Lopez > > > > To reproduce from emacs -Q: > > C-x b hello.py RET > > M-x python-mode > > On the first line, type the word "return", then press the Return key. > > On the second line, type one or more spaces. > > Press Backspace. This triggers the error message: > > python-indent-line: Wrong type argument: wholenump, -4 > > and, the last-typed space is not deleted. > > > > Backtrace of the error: > > Debugger entered--Lisp error: (wrong-type-argument wholenump -4) > > indent-line-to(-4) > > python-indent-line(t) > > python-indent-dedent-line() > > python-indent-dedent-line-backspace(1) > > funcall-interactively(python-indent-dedent-line-backspace 1) > > command-execute(python-indent-dedent-line-backspace) > > > > This can also happen with Python keywords/statements that tend to end a > > scope, eg. "break" or "raise", as well as "return". > > > > I guess the smart dedenting sees the "return" (or similar statement) at > > top-level scope and then tries to move the cursor to a parent scope / > > negative column that doesn't exist. Perhaps one of those indent > > functions could clamp itself somehow to not do that but I'm not sure > > where the best place for that would be. > > Thanks. > > kobarity, any suggestions or comments? Thank you for the report. The attached is the proposed fix. --Multipart_Sun_Sep_17_00:06:57_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-Python-mode-error-caused-by-incorrect-indentatio.patch" Content-Disposition: attachment; filename="0001-Fix-Python-mode-error-caused-by-incorrect-indentatio.patch" Content-Transfer-Encoding: 7bit >From 32f0dbe5f942ffa60f0945d2ffb771db82db5832 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 16 Sep 2023 23:14:45 +0900 Subject: [PATCH] Fix Python mode error caused by incorrect indentation * lisp/progmodes/python.el (python-indent--calculate-indentation): Guard against negative indentation. (Bug #65870) * test/lisp/progmodes/python-tests.el (python-indent-badly-indented-block-end): New test. --- lisp/progmodes/python.el | 2 +- test/lisp/progmodes/python-tests.el | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 4b940b3f13b..d7e49e225d8 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1660,7 +1660,7 @@ python-indent--calculate-indentation (`(:after-block-end . ,start) ;; Subtract one indentation level. (goto-char start) - (- (current-indentation) python-indent-offset)) + (max 0 (- (current-indentation) python-indent-offset))) (`(:at-dedenter-block-start . ,_) ;; List all possible indentation levels from opening blocks. (let ((opening-block-start-points diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index a44a11896f0..f3456030975 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -2081,6 +2081,15 @@ python-indent-after-bare-match (python-tests-look-at "else:") (should (= (python-indent-calculate-indentation) 4)))) +(ert-deftest python-indent-badly-indented-block-end () + "Test BUG 65870 regression." + (python-tests-with-temp-buffer + " +return +" + (goto-char (point-max)) + (should (= (python-indent-calculate-indentation) 0)))) + ;;; Filling -- 2.34.1 --Multipart_Sun_Sep_17_00:06:57_2023-1--