Subject: bug#28051: 25.2; Multiline Statement Indentation Error in Inferior Python Mode

From: [email-masked]
Date: Fri, 11 Aug 2017 13:24:34 -0400

Having simple init.el file like this

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
  (add-to-list 'package-archives (cons "melpa" url) t))
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

(use-package company
  :ensure t
  :init
  (setq company-idle-delay 0.1
	company-tooltip-limit 20
	company-show-numbers t
	company-selection-wrap-around t
	company-minimum-prefix-length 2
	company-tooltip-align-annotations t
	company-echo-delay 0)
  :config
  ;; default `company-backends'
  (setq company-backends '(company-capf
			   (company-dabbrev-code
			    company-gtags
			    company-etags
			    company-keywords)
			   company-files
			   company-dabbrev))

  (defun ffe-add-company-backends (&rest backends)
    "Adds BACKENDS to the beginning of the buffer-local version of `company-backends' list"
    (set (make-local-variable 'company-backends)
	 (append backends company-backends)))

  (global-company-mode 1))

(use-package python
  :defer t
  :commands python-mode
  :config
  (add-hook 'python-mode-hook #'eldoc-mode))

(use-package anaconda-mode
  :ensure t
  :init (progn
          (add-hook 'python-mode-hook #'anaconda-mode)
          (add-hook 'python-mode-hook #'anaconda-eldoc-mode)))

(use-package company-anaconda
  :defer t
  :ensure t
  :init (with-eval-after-load 'company
          (add-hook 'python-mode-hook (lambda () (ffe-add-company-backends 'company-anaconda)))))

leads to IndentationError once I try to enter multi-line statements in
the Inferior python mode. 

Steps:

1. Start Emacs
2. M-x run-python
3. try to enter something simple like

   for x in range(10):<RET>
   <TAB>print x<RET>

4. The following error occurs:

File "<stdin>", line 1
    print x
    ^
IndentationError: unexpected indent

If `company-mode' is disabled in the Inferior Python Mode via M-x company-mode
then entering multi-line statements work as expected. Using C-M-i or
`complete-symbol' works. 

Also at the start of the Inferior Pyhon Mode following Warnings have
been shown

Warning (python): Python shell prompts cannot be detected.
If your emacs session hangs when starting python shells
recover with ‘keyboard-quit’ and then try fixing the
interactive flag for your interpreter by adjusting the
‘python-shell-interpreter-interactive-arg’ or add regexps
matching shell prompts in the directory-local friendly vars:
  + ‘python-shell-prompt-regexp’
  + ‘python-shell-prompt-block-regexp’
  + ‘python-shell-prompt-output-regexp’
Or alternatively in:
  + ‘python-shell-prompt-input-regexps’
  + ‘python-shell-prompt-output-regexps’
Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native-enable’ was t and "python" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally. 

Howver at the start it said:

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python.el: native completion setup loaded

Corresponding issue for the `company-mode' on github.com 
https://github.com/company-mode/company-mode/issues/603

In GNU Emacs 25.2.1 (x86_64-w64-mingw32)
 of 2017-04-24 built on LAPHROAIG
Windowing system distributor 'Microsoft Corp.', version 10.0.14393
Configured using:
 'configure --without-dbus --without-compress-install 'CFLAGS=-O2
 -static -g3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252

Major mode: Inferior Python

Minor modes in effect:
  shell-dirtrack-mode: t
  global-company-mode: t
  override-global-mode: t
  compilation-shell-minor-mode: t
  tooltip-mode: t
  global-eldoc-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
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Saving file c:/Users/esharapov/.emacs.d/init.el...
Wrote c:/Users/esharapov/.emacs.d/init.el [2 times]
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
Can’t guess python-indent-offset, using defaults: 4
Shell native completion is disabled, using fallback
Company mode disabled in current buffer
Mark set
Making completion list...
Type "q" in help window to restore previous buffer.

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug sendmail eieio-opt speedbar sb-image
ezimage dframe tramp-cache company-anaconda pp cus-edit cus-start
cus-load wid-edit anaconda-mode derived pythonic f python tramp-sh tramp
tramp-compat tramp-loaddefs trampver ucs-normalize shell pcomplete
advice json map dash s company-files company-keywords company-etags
company-gtags company-dabbrev-code company-capf tempo warnings ispell
etags xref project find-func company-dabbrev company-template company
edmacro kmacro tar-mode use-package diminish bind-key easy-mmode cl
compile comint ansi-color ring autoload lisp-mnt mm-archive message
dired format-spec rfc822 mml mml-sec mailabbrev gmm-utils mailheader
mm-decode mm-bodies mm-encode mail-utils network-stream nsm starttls
url-http tls gnutls mail-parse rfc2231 rfc2047 rfc2045 ietf-drums url-gw
url-cache url-auth url url-proxy url-privacy url-expand url-methods
url-history url-cookie url-domsuf url-util mailcap url-handlers
url-parse auth-source cl-seq eieio eieio-core cl-macs gnus-util mm-util
help-fns mail-prsvr password-cache url-vars epg finder-inf package
epg-config seq byte-opt gv bytecomp byte-compile cl-extra help-mode
easymenu cconv cl-loaddefs pcase cl-lib time-date mule-util tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
dos-w32 ls-lisp disp-table w32-win w32-vars term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame
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 charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote w32notify w32 multi-tty
make-network-process emacs)

Memory information:
((conses 16 353292 42268)
 (symbols 56 34067 0)
 (miscs 48 165 297)
 (strings 32 68207 11339)
 (string-bytes 1 1877375)
 (vectors 16 55331)
 (vector-slots 8 1659539 79071)
 (floats 8 320 326)
 (intervals 56 1115 2875)
 (buffers 976 70))