gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: company 0.4 -- extensible inline text completion mechanism


From: Ralf Schmitt
Subject: Re: company 0.4 -- extensible inline text completion mechanism
Date: Mon, 20 Apr 2009 09:50:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Nikolaj Schumacher <address@hidden> writes:

>
> All this should make company much more suitable for languages not
> supported by CEDET, e.g. Python.
>

I'm attaching some code which makes company use rope in python mode.
It's based on code found on the emacswiki which did the same for
autocomplete mode. I'm setting company-minimum-prefix-length to 0 in
order to get completions after a dot like in "self.". It depends on rope,
ropemacs and pymacs being installed.

(require  'company)

(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)

(defvar company-python-ropemacs-loaded nil)
(defun company-python-ropemacs-require ()
  (unless company-python-ropemacs-loaded
    ;; Almost people hate rope to use `C-x p'.
    (if (not (boundp 'ropemacs-global-prefix))
        (setq ropemacs-global-prefix nil))
    (pymacs-load "ropemacs" "rope-")
    (setq ropemacs-enable-autoimport t)
    (setq company-python-ropemacs-loaded t)))

;; (company-python-ropemacs-require)

(defun company-python-prefix-list-elements (list prefix)
  (let (value)
    (nreverse
     (dolist (element list value)
       (setq value (cons (format "%s%s" prefix element) value))))))


(defun company-python-prefix()
  (interactive)
  (if (and (derived-mode-p 'python-mode) (fboundp 'rope-completions)) 
      (if (looking-back "\\_<[a-zA-Z_]+\\_>")
          (match-string 0)
        (if (looking-back "\\.")
            ""
          ))
    nil))

(defun company-python-candidates()
  (interactive)
  (when (fboundp 'rope-completions)
    (let (
          (prefix (company-python-prefix))
          (completions (rope-completions))
          )
      (company-python-prefix-list-elements completions prefix)
      )))


(defun company-python-backend (command &optional arg &rest ignored)
  (case command
    ('prefix (company-python-prefix))
    ('candidates (company-python-candidates))
    ))

;; (add-to-list 'company-backends 'company-python-backend) 

(provide 'company-python)








reply via email to

[Prev in Thread] Current Thread [Next in Thread]