GNU bug report logs - #65870
30.0.50; Error in python-mode when try to delete a character in badly-indented code

Previous Next

Package: emacs;

Reported by: Daniel Lopez <daniel.lopez999 <at> gmail.com>

Date: Mon, 11 Sep 2023 16:38:01 UTC

Severity: normal

Found in version 30.0.50

To reply to this bug, email your comments to 65870 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Mon, 11 Sep 2023 16:38:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Lopez <daniel.lopez999 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 11 Sep 2023 16:38:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; Error in python-mode when try to delete a character in
 badly-indented code
Date: Mon, 11 Sep 2023 17:36:59 +0100
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.

Daniel



In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.36, cairo version 1.17.8) of 2023-02-21 built on ENO
Repository revision: 098add06eb7d742ff0e6ee0e294931a93a60c71c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-modules --without-libotf --without-m17n-flt --without-gconf
 --with-native-compilation=yes --with-xinput2 --with-x-toolkit=gtk3
 --without-xaw3d --with-sound=no --with-tree-sitter --without-gpm
 --without-compress-install
 '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=2 -Wformat -fstack-clash-protection
 -fcf-protection'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP
X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils help-fns
radix-tree cl-print debug backtrace find-func python project byte-opt
pcase treesit comint ansi-osc ring cl-loaddefs comp comp-cstr warnings
icons subr-x rx cl-seq cl-macs gv cl-extra help-mode bytecomp
byte-compile cl-lib ansi-color cus-start cus-load rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 105838 7866)
 (symbols 48 9884 0)
 (strings 32 26714 1992)
 (string-bytes 1 822994)
 (vectors 16 18667)
 (vector-slots 8 375164 12614)
 (floats 8 37 45)
 (intervals 56 310 0)
 (buffers 984 13))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sat, 16 Sep 2023 10:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Daniel Lopez <daniel.lopez999 <at> gmail.com>, kobarity <kobarity <at> gmail.com>
Cc: 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50;
 Error in python-mode when try to delete a character in badly-indented
 code
Date: Sat, 16 Sep 2023 13:05:57 +0300
> Date: Mon, 11 Sep 2023 17:36:59 +0100
> From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
> 
> 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?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sat, 16 Sep 2023 15:08:02 GMT) Full text and rfc822 format available.

Message #11 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Daniel Lopez <daniel.lopez999 <at> gmail.com>, 65870 <at> debbugs.gnu.org
Subject: Re: 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 part 1 (text/plain, inline)]
Eli Zaretskii wrote:
> > Date: Mon, 11 Sep 2023 17:36:59 +0100
> > From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
> > 
> > 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.
[0001-Fix-Python-mode-error-caused-by-incorrect-indentatio.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sun, 17 Sep 2023 04:07:01 GMT) Full text and rfc822 format available.

Message #14 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
To: kobarity <kobarity <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50; Error in python-mode when try to delete a
 character in badly-indented code
Date: Sun, 17 Sep 2023 05:06:10 +0100
On 16/09/2023 16:06, kobarity wrote:
> 
> Eli Zaretskii wrote:
>>> Date: Mon, 11 Sep 2023 17:36:59 +0100
>>> From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
>>>
>>> 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.

On applying the fix to my own installation, I can confirm that it works 
for me. Thanks. :)




This bug report was last modified 230 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.