0

When I enter an IPython repl via python-start-or-switch-repl, I get annoying auto completion behavior where the completions popup opens with zero characters entered. If I type one character and erase it the popup opens and stays open starting with '%%!', '%%HTML', etc. If I type a function call like print('hello') and hit enter, Autocompletion inserts '%%!' at the end of my input and I end up entering print('hello')%%!. Auto completion works fine in all other buffers.

Here are the results from M-x describe-mode:

Minor modes enabled in this buffer: Anzu Company Compilation-Shell Evil-Local
Evil-Surround Font-Lock Show-Smartparens Smartparens Spacemacs-Leader-Override
Term-Cursor Undo-Tree Yas

The major mode is Inferior Python mode defined in python.el:

Major mode for Python inferior process.
Runs a Python interpreter as a subprocess of Emacs, with Python
I/O through an Emacs buffer.  Variables ‘python-shell-interpreter’
and ‘python-shell-interpreter-args’ control which Python
interpreter is run.  Variables
‘python-shell-prompt-regexp’,
‘python-shell-prompt-output-regexp’,
‘python-shell-prompt-block-regexp’,
‘python-shell-font-lock-enable’,
‘python-shell-completion-setup-code’,
‘python-shell-completion-string-code’,
‘python-eldoc-setup-code’,
‘python-ffap-setup-code’ can
customize this mode for different Python interpreters.

This mode resets ‘comint-output-filter-functions’ locally, so you
may want to re-add custom functions to it using the
‘inferior-python-mode-hook’.

EDIT: Here are some company-mode details:

Company 0.9.13

company-backends: (php-extras-company company-bbdb company-semantic company-cmake company-capf company-clang company-files
                    (company-dabbrev-code company-gtags company-etags company-keywords)
                    company-oddmuse company-dabbrev)

Used backend: company-capf
Value of c-a-p-f: (lsp-completion-at-point python-completion-at-point t)
Major mode: python-mode
Prefix: ""

EDIT: @dalanicolai requested this info:

python-shell-interpreter-args is a variable defined in ‘python.el’.

Its value is "-i --simple-prompt"
Original value was "-i"
Local in buffer *Python*; global value is "-i"

here is the popup

3
  • What is the value of python-shell-interpreter-args? Aug 24, 2023 at 7:40
  • @dalanicolai I edited my post to include that info
    – degen872
    Aug 25, 2023 at 2:47
  • Although it is probably not related to this issue, I think you should not include the -i flag when using ipython (I am not sure if it would do any harm, though). Aug 25, 2023 at 14:58

2 Answers 2

2

You’re using company-mode for completion, so you should consult the company-mode documentation (this manual is also available inside the Emacs Info viewer, type C-h i to start it).

In particular, language–specific suggestions come from a language–specific backend. You can check which backends are in use by checking the value of the company-backends variable, as well as the `completion-at-point-functions variable (both of which you should include in your question).

Once you figure out where Company is getting the suggestions, you will have figured out how to configure it properly.

3
  • 1
    Like company-mode bug reporting instructions also recommend, the output of M-x company-diag might shed some light as well.
    – Dmitry
    Aug 27, 2023 at 23:44
  • @Dmitry That was a helpful tip that lead to the culprit. A spacemacs python layer is specifically setting company-minimum-prefix-length to 0
    – degen872
    Aug 29, 2023 at 8:55
  • @degen872 That makes a lot of sense (and I was also thinking in that direction), but for most completion backends you'd be fine with that setting. There might be something fix-able in this one. I couldn't reproduce your problem in my Emacs, though, so maybe it's already fixed in a recent release (e.g. 29.1).
    – Dmitry
    Aug 31, 2023 at 1:29
0

The spacemacs python layer is setting company-minimum-prefix-length to 0:

spacemacs python layer:


(defun python/post-init-company ()
  ;; backend specific
  (add-hook 'python-mode-local-vars-hook #'spacemacs//python-setup-company)
  (spacemacs|add-company-backends
    :backends (company-files company-capf)
    :modes inferior-python-mode
    :variables
    company-minimum-prefix-length 0
    company-idle-delay 0.5)
  (when (configuration-layer/package-used-p 'pip-requirements)
    (spacemacs|add-company-backends
      :backends company-capf
      :modes pip-requirements-mode)))

This layer overrides my use of setq-local in a python-inferior-mode-hook in my init file as well as anything done with M-x customize-variable. The only fix as of now is using M-x set-variable every time I open a python-inferior-mode buffer. Using M-x python-shell-restart resets the variable to 0 and I have to set it again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.