Search code examples
pythonemacsautocompletepymacs

python code completion in Emacs


I tried make PythonIDE using emacs like in this article http://www.enigmacurry.com/2009/01/21/autocompleteel-python-code-completion-in-emacs/ But emacs said me "auto-complete-mode not enabled". It is possible use emacs for python coding?


Solution

  • You want to activate the auto-complete mode in the context where you get that message, either

    • every time you open python files, by adding the following to your .emacs:

      (add-hook 'python-mode-hook
        (lambda ()
               (auto-complete-mode 1)))
      
    • or when you open any file, by adding the following to your .emacs:

      (global-auto-complete-mode t)
      

    The question you're linking to suggests something even more complete (i.e. which subsumes the first of the two additions I suggest):

    (add-hook 'python-mode-hook
          (lambda ()
                 (auto-complete-mode 1)
                 (set (make-local-variable 'ac-sources)
                      (append ac-sources '(ac-source-rope) '(ac-source-yasnippet)))
                 (set (make-local-variable 'ac-find-function) 'ac-python-find)
                 (set (make-local-variable 'ac-candidate-function) 'ac-python-candidate)
                 (set (make-local-variable 'ac-auto-start) nil)))
    

    Those additions will be needed to get full completion using snippets and Rope.