[Python-mode] [PATCH] Improved pycomplete
Andreas Röhler
andreas.roehler at online.de
Sun Jul 1 21:06:49 CEST 2012
Am 01.07.2012 16:19, schrieb Urs Fleisch:
> Hi,
>
>> If you might open a ticket at
>>
>> https://bugs.launchpad.net/python-mode
>>
>> for it, the patch attached, that would help still, as it's easier to refer.
>
> OK, I have opened a bug: https://bugs.launchpad.net/python-mode/+bug/1019791.
>
> I have another little patch, 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
>
Hi,
thanks a lot, that's quite interesting.
If your time permit, please make a now branch related to company.
Best,
Andreas
As we have several options to realise auto-completion,
> === 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)
>
>
More information about the Python-mode
mailing list