Skip to content

Instantly share code, notes, and snippets.

@russell
Created July 17, 2012 01:35
Show Gist options
  • Save russell/3126357 to your computer and use it in GitHub Desktop.
Save russell/3126357 to your computer and use it in GitHub Desktop.
auto-complete for python-mode using python-shell-completion
(defun ac-python-candidates ()
(let* (py-split-windows-on-execute-p
py-switch-buffers-on-execute-p
(shell (py-choose-shell))
(proc (or (get-buffer-process shell)
(get-buffer-process (py-shell nil nil shell 'noswitch nil)))))
(if (processp proc)
(with-syntax-table python-dotty-syntax-table
(let* ((imports (py-find-imports))
(beg (save-excursion (skip-chars-backward "a-zA-Z0-9_.") (point)))
(end (point))
(word (buffer-substring-no-properties beg end))
(code (if imports
(concat imports python-shell-module-completion-string-code)
python-shell-module-completion-string-code)))
(python-shell-completion--get-completions word proc code))))))
(ac-define-source python
'((candidates . ac-python-candidates)
(symbol . "f")
(cache)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment