In the spacemace python layer, the following function overrides my customizations for the variable company-minimum-prefix-length python layer

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

I've tried setting this variable to 2 with a mode hook as well as by using M-x customize

This hook in my init file has zero effect (maybe I'm doing something wrong):

  (add-hook 'inferior-python-mode-hook
            (lambda ()
              (setq-local company-minimum-prefix-length 2)))

M-x customize-variable also has zero effect in the python buffer although it works in other buffers. After save and apply in the customize-variable buffer M-x describe-variable yields this:

Its value is 0
Original value was 3
Local in buffer *Python*; global value is 2

The minimum prefix length for idle completion.

  Automatically becomes buffer-local when set.
  You can customize this variable.


The only way I can change the variable is by using M-x set-variable after the buffer loads. This change is overridden if I restart the buffer with M-x python-shell-restart. Is there any way I can write a hook that will set the variable after all other mode hooks?


1 Answer 1


Adding a hook on company-mode instead of inferior-python-mode worked presumably due to the order in which the modes run.

  (add-hook 'company-mode-hook
            (lambda ()
                  (equal major-mode 'inferior-python-mode)
                  (setq-local company-minimum-prefix-length 2))))

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.