Subject: bug#59421: 28.2; python-mode breaks literal tabs when entering a command in the buffer

From: Alexandre Hannud Abdo <[email-masked]>
Date: Sun, 20 Nov 2022 22:49:36 +0100

Ni! Hello,

I notice that python-mode is interpreting literal tabs when receiving a command from the buffer, which notably becomes an issue when pasting data, e.g. from "tab separated" table into a string. It also affects pasting code containing tabs, but strangely doesn't affect indentation tabs, so only the string case seems of concern.

After starting emacs and 'M-x run-python':

```
Python 3.9.9 (main, Jan  1 1970, 00:00:01)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: text = "F    oo"

0__dummy_completion__  1__dummy_completion__

In [5]: text
Out[5]: 'Foo'

In [6]:
```

At "In [1]", the spaces after "F" should be replaced by a literal TAB (pasted or C-q TAB).
At "In [5]", the TAB is absent in the variable "text".
This works fine in a regular ipython REPL.

This is bugging me as I haven't found any way to use text with TABs in emacs python-mode.
It seems to have been treated as a completion trigger, given the dummy completion messages.

More generally:

This works in a regular ipython REPL, but doesn't within emacs:

```
In [7]: def    foo(): pass
def

0__dummy_completion__  1__dummy_completion__
   Input In [15]
     deffoo(): pass
               ^
SyntaxError: invalid syntax

In [8]:
```

At "In [7]" the spaces after "def" should be replaced by a literal TAB.
This also works fine in a regular ipython REPL.

Surprisingly, the code below (replacing space indentations by literal TABs) works, though the dummy completion messages are still there.

```
In [9]: for _ in []:
     ...:     for _ in []:

0__dummy_completion__  1__dummy_completion__
     ...:         pass

0__dummy_completion__  1__dummy_completion__

0__dummy_completion__  1__dummy_completion__
     ...:

In [10]:
```

Let me know if I can help. Best,

ale
--

In GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Guix System

Configured using:
  'configure
  CONFIG_SHELL=/gnu/store/4y5m9lb8k3qkb1y9m02sw9w9a6hacd16-bash-minimal-5.1.8/bin/bash
  SHELL=/gnu/store/4y5m9lb8k3qkb1y9m02sw9w9a6hacd16-bash-minimal-5.1.8/bin/bash
  --prefix=/gnu/store/gxjwd3q2iy3hgzwnc37mcnvfiv2s1pxz-emacs-28.2
  --enable-fast-install --with-modules --with-cairo
  --with-native-compilation --disable-build-details'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES
NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
   value of $EMACSLOADPATH: /home/eris/.guix-profile/share/emacs/site-lisp:/home/eris/.guix-profile/share/emacs/site-lisp:/gnu/store/gxjwd3q2iy3hgzwnc37mcnvfiv2s1pxz-emacs-28.2/share/emacs/28.2/lisp
   value of $EMACSNATIVELOADPATH: /home/eris/.guix-profile/lib/emacs/native-site-lisp:/home/eris/.guix-profile/lib/emacs/native-site-lisp
   value of $LANG: en_US.utf8
   locale-coding-system: utf-8-unix

Major mode: Inferior Python

Minor modes in effect:
   compilation-shell-minor-mode: t
   shell-dirtrack-mode: t
   yas-global-mode: t
   yas-minor-mode: t
   global-undo-tree-mode: t
   undo-tree-mode: t
   save-place-mode: t
   savehist-mode: t
   recentf-mode: t
   global-linum-mode: t
   linum-mode: t
   windmove-mode: t
   tooltip-mode: t
   global-eldoc-mode: t
   show-paren-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   column-number-mode: t
   line-number-mode: t
   transient-mark-mode: t

Load-path shadows:
/gnu/store/gcvj3grb55ic034b9a56p6m182b2qfdr-emacs-nadvice-0.3/share/emacs/site-lisp/nadvice-0.3/nadvice hides /gnu/store/gxjwd3q2iy3hgzwnc37mcnvfiv2s1pxz-emacs-28.2/share/emacs/28.2/lisp/emacs-lisp/nadvice

Features:
(shadow sort mail-extr emacsbug message rmc puny rfc822 mml mml-sec epa
derived epg rfc6068 epg-config gnus-util rmail rmail-loaddefs mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils vc-mtn
vc-hg vc-git diff-mode easy-mmode vc-bzr vc-src vc-sccs vc-svn vc-cvs
vc-rcs vc vc-dispatcher ibuffer-vc ibuf-ext ibuffer ibuffer-loaddefs
compile text-property-search python tramp-sh tramp tramp-loaddefs
trampver tramp-integration files-x tramp-compat shell pcomplete
parse-time iso8601 time-date ls-lisp format-spec auth-source eieio
eieio-core cl-macs eieio-loaddefs password-cache json subr-x map comint
ring ansi-color dired-aux dired dired-loaddefs paredit skeleton
yasnippet-snippets cl-extra cl-seq yasnippet help-mode undo-tree diff
queue saveplace savehist recentf tree-widget wid-edit linum windmove
edmacro kmacro cl-loaddefs cl-lib paredit-autoloads
yasnippet-snippets-autoloads queue-autoloads undo-tree-autoloads
ibuffer-vc-autoloads yaml-mode-autoloads markdown-mode-autoloads
compat-autoloads async-autoloads with-editor-autoloads magit-autoloads
reformatter-autoloads python-black-autoloads magit-popup-autoloads
geiser-guile-autoloads geiser-autoloads edit-indirect-autoloads
dash-autoloads bui-autoloads guix-autoloads rx s-autoloads
pyvenv-autoloads yasnippet-autoloads highlight-indentation-autoloads
find-file-in-project-autoloads company-autoloads elpy-autoloads
guix-emacs seq byte-opt gv bytecomp byte-compile cconv iso-transl
tooltip 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 cl-generic
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 simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 168337 4461)
  (symbols 48 14202 0)
  (strings 32 47024 3692)
  (string-bytes 1 1717737)
  (vectors 16 25865)
  (vector-slots 8 517852 13516)
  (floats 8 50 71)
  (intervals 56 588 0)
  (buffers 992 15))