]> code.delx.au - gnu-emacs-elpa/blob - company-ropemacs.el
Added company-ropemacs.
[gnu-emacs-elpa] / company-ropemacs.el
1 ;;; company-pysmell.el --- a company-mode completion back-end for pysmell.el
2 ;;
3 ;; Copyright (C) 2009 Nikolaj Schumacher
4 ;;
5 ;; This file is part of company 0.4.2.
6 ;;
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License
9 ;; as published by the Free Software Foundation; either version 2
10 ;; of the License, or (at your option) any later version.
11 ;;
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 (eval-when-compile (require 'cl))
21 (require 'pymacs)
22
23 (unless (fboundp 'rope-completions)
24 (pymacs-load "ropemacs" "rope-"))
25
26 (unless (fboundp 'rope-completions)
27 (error "rope-completions not found, try development version of ropemacs"))
28
29 (defun company-ropemacs--grab-symbol ()
30 (let ((symbol (company-grab-symbol)))
31 (when symbol
32 (cons symbol
33 (save-excursion
34 (let ((pos (point)))
35 (goto-char (- (point) (length symbol)))
36 (while (eq (char-before) ?.)
37 (goto-char (1- (point)))
38 (skip-syntax-backward "w_"))
39 (- pos (point))))))))
40
41 (defun company-ropemacs (command &optional arg &rest ignored)
42 "A `company-mode' completion back-end for ropemacs."
43 (interactive (list 'interactive))
44 (case command
45 ('interactive (company-begin-backend 'company-ropemacs))
46 ('prefix (and (derived-mode-p 'python-mode)
47 (not (company-in-string-or-comment))
48 (company-pysmell--grab-symbol)))
49 ('candidates (mapcar (lambda (element) (concat arg element))
50 (rope-completions)))))
51
52 (provide 'company-ropemacs)
53 ;;; company-ropemacs.el ends here