1 ;;; company-ropemacs.el --- a company-mode completion back-end for pysmell.el
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 ;; Author: Nikolaj Schumacher
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 (eval-when-compile (require 'cl))
27 (unless (fboundp 'rope-completions)
28 (pymacs-load "ropemacs" "rope-"))
30 (unless (fboundp 'rope-completions)
31 (error "rope-completions not found, try development version of ropemacs"))
33 (defun company-ropemacs--grab-symbol ()
34 (let ((symbol (company-grab-symbol)))
39 (goto-char (- (point) (length symbol)))
40 (while (eq (char-before) ?.)
41 (goto-char (1- (point)))
42 (skip-syntax-backward "w_"))
45 (defun company-ropemacs-doc-buffer (candidate)
46 "Return buffer with docstring of CANDIDATE if it is available."
47 (let ((doc (company-with-candidate-inserted candidate (rope-get-doc))))
49 (with-current-buffer (company-doc-buffer)
53 (defun company-ropemacs-location (candidate)
54 "Return location of CANDIDATE in cons form (FILE . LINE) if it is available."
55 (let ((location (company-with-candidate-inserted candidate
56 (rope-definition-location))))
58 (cons (elt location 0) (elt location 1)))))
60 (defun company-ropemacs (command &optional arg &rest ignored)
61 "A `company-mode' completion back-end for ropemacs."
62 (interactive (list 'interactive))
64 ('interactive (company-begin-backend 'company-ropemacs))
65 ('prefix (and (derived-mode-p 'python-mode)
66 (not (company-in-string-or-comment))
67 (company-ropemacs--grab-symbol)))
68 ('candidates (mapcar (lambda (element) (concat arg element))
70 ('doc-buffer (company-ropemacs-doc-buffer arg))
71 ('location (company-ropemacs-location arg))))
73 (provide 'company-ropemacs)
74 ;;; company-ropemacs.el ends here