Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs with Python Code Completion > Code Completion Suggestions Not Popping Up

After installing:

[rope]
[ropemode]
[pymacs]
[ropemacs]
[autocomplete 1.3.1]

And configuring .emacs:

(add-to-list 'load-path "~/.emacs.d/autocomplete1.3.1")
(add-to-list 'load-path "~/share/emacs/lisp/")

(setq py-install-directory "~/share/emacs/lisp/")
(require 'python-mode)

(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-exec "pymacs" nil t)
(autoload 'pymacs-load "pymacs" nil t)
(autoload 'pymacs-autoload "pymacs")

(require 'pymacs)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)

(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/autocomplete1.3.1/ac-dict")
(ac-config-default)

(require 'auto-complete)
(global-auto-complete-mode t)

I typed a period after sys., and hoped for code completion similar to Komodo Edit.

Unfortunately, the best I could achieve, was pressing M-/ to bring up a split screen code completion buffer.

How does one achieve code completion in GNU Emacs, which is similar to Komodo-Edit?

Here's a pymacs bug bug that caught me out:

like image 905
Dave Kirkby Avatar asked Feb 27 '26 21:02

Dave Kirkby


1 Answers

Here is the definition of ac-config-default as it is the only thing you do to configure AC:

(defun ac-config-default ()
  (setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
  (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
  (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
  (add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
  (add-hook 'css-mode-hook 'ac-css-mode-setup)
  (add-hook 'auto-complete-mode-hook 'ac-common-setup)
  (global-auto-complete-mode t))

There is no Python config, so you can't expect AC to work for Python.

To set it up:

(add-hook 'python-mode-hook 'ac-ropemacs-setup)

Shameless plug: Here are alternate ropemacs sources for AC - as the included source does not show documentation: https://github.com/cofi/dotfiles/blob/master/emacs.d/config/cofi-python.el#L75

Here again to configure:

(add-hook 'python-mode-hook (lambda ()
                              (setq ac-source (append ac-source '(ac-source-nropemacs
                                                                  ac-source-nropemacs-dot)))))
like image 76
Michael Markert Avatar answered Mar 02 '26 09:03

Michael Markert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!