]> rtime.felk.cvut.cz Git - sojka/company-mode.git/blob - company-ropemacs.el
company-css-property-values: delete duplicates
[sojka/company-mode.git] / company-ropemacs.el
1 ;;; company-ropemacs.el --- company-mode completion back-end for ropemacs
2
3 ;; Copyright (C) 2009-2011, 2013  Free Software Foundation, Inc.
4
5 ;; Author: Nikolaj Schumacher
6
7 ;; This file is part of GNU Emacs.
8
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.
13
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.
18
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/>.
21
22
23 ;;; Commentary:
24 ;;
25
26 ;;; Code:
27
28 (require 'cl-lib)
29
30 (defun company-ropemacs--grab-symbol ()
31   (let ((symbol (company-grab-symbol)))
32     (when symbol
33       (cons symbol
34             (save-excursion
35               (let ((pos (point)))
36                 (goto-char (- (point) (length symbol)))
37                 (while (eq (char-before) ?.)
38                   (goto-char (1- (point)))
39                   (skip-syntax-backward "w_"))
40                 (- pos (point))))))))
41
42 (defun company-ropemacs-doc-buffer (candidate)
43   "Return buffer with docstring of CANDIDATE if it is available."
44   (let ((doc (company-with-candidate-inserted candidate (rope-get-doc))))
45     (when doc
46       (company-doc-buffer doc))))
47
48 (defun company-ropemacs-location (candidate)
49   "Return location of CANDIDATE in cons form (FILE . LINE) if it is available."
50   (let ((location (company-with-candidate-inserted candidate
51                     (rope-definition-location))))
52     (when location
53       (cons (elt location 0) (elt location 1)))))
54
55 (defun company-ropemacs (command &optional arg &rest ignored)
56   "`company-mode' completion back-end for ropemacs.
57
58 Depends on third-party code: Pymacs (both Python and Emacs packages),
59 rope, ropemacs and ropemode."
60   (interactive (list 'interactive))
61   (cl-case command
62     (init (when (and (derived-mode-p 'python-mode)
63                      (not (fboundp 'rope-completions)))
64             (require 'pymacs)
65             (pymacs-load "ropemacs" "rope-")))
66     (interactive (company-begin-backend 'company-ropemacs))
67     (prefix (and (derived-mode-p 'python-mode)
68                  (not (company-in-string-or-comment))
69                  (company-ropemacs--grab-symbol)))
70     (candidates (mapcar (lambda (element) (concat arg element))
71                         (rope-completions)))
72     (doc-buffer (company-ropemacs-doc-buffer arg))
73     (location (company-ropemacs-location arg))))
74
75 (provide 'company-ropemacs)
76 ;;; company-ropemacs.el ends here