I have another little patch,
Hi Urs,
thinking meanwhile it might be worth a separate file, as it relies at company.
You will be aware of M-x auto-insert.
Thanks a lot,
Andreas
not related to a bug, rather an improvement.
It provides functions py-complete-define-ac-source(),
py-complete-define-company-completion() to integrate pycomplete into
auto-complete or company, so that the completions are displayed in a nice popup.
Regards,
Urs
=== modified file 'completion/pycomplete.el'
--- completion/pycomplete.el 2012-07-01 13:05:48 +0000
+++ completion/pycomplete.el 2012-07-01 13:21:44 +0000
@@ -78,4 +78,50 @@
(display-completion-list completions))
(message "Making completion list...%s" "done")))))
+(defun py-complete-completions ()
+ "get possible completions for current statement"
+ (pycomplete-get-all-completions
+ (py-symbol-near-point)
+ (py-find-global-imports)))
+
+(defun py-complete-define-ac-source ()
+ "Define ac-source-pycomplete to be used with auto-complete.
+
+The ac-source can be enabled solely using
+(setq ac-sources '(ac-source-pycomplete))
+or before the other sources using
+(add-to-list 'ac-sources 'ac-source-pycomplete)."
+ (require 'auto-complete)
+ (ac-define-source pycomplete
+ '((candidates . py-complete-completions))))
+
+(defun py-complete-define-company-completion ()
+ "Define company-pycomplete function to be used with company.
+
+The function can be enabled using
+(setq company-backends '((company-pycomplete)))."
+ (require 'company)
+ (defun company-pycomplete--grab-symbol ()
+ (let ((symbol (company-grab-symbol)))
+ (when symbol
+ (cons symbol
+ (save-excursion
+ (let ((pos (point)))
+ (goto-char (- (point) (length symbol)))
+ (while (eq (char-before) ?.)
+ (goto-char (1- (point)))
+ (skip-syntax-backward "w_"))
+ (- pos (point))))))))
+ (defun company-pycomplete (command &optional arg &rest ignored)
+ "A `company-mode' completion back-end for pycomplete."
+ (interactive (list 'interactive))
+ (case command
+ ('interactive (company-begin-backend 'company-pycomplete))
+ ('prefix (and (derived-mode-p 'python-mode)
+ buffer-file-name
+ (not (company-in-string-or-comment))
+ (company-pycomplete--grab-symbol)))
+ ('candidates (py-complete-completions))))
+ )
+
(provide 'pycomplete)
_______________________________________________
Python-mode mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-mode