]> code.delx.au - gnu-emacs-elpa/blob - packages/company/company-ropemacs.el
Merge commit 'db005182ad0fd05c07e8e5c085abe6c750e6c578' from ivy
[gnu-emacs-elpa] / packages / company / company-ropemacs.el
1 ;;; company-ropemacs.el --- company-mode completion back-end for ropemacs
2
3 ;; Copyright (C) 2009-2011, 2013-2014 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. Requires `ropemacs-mode' to be on."
60 (interactive (list 'interactive))
61 (cl-case command
62 (interactive (company-begin-backend 'company-ropemacs))
63 (prefix (and (bound-and-true-p ropemacs-mode)
64 (not (company-in-string-or-comment))
65 (company-ropemacs--grab-symbol)))
66 (candidates (mapcar (lambda (element) (concat arg element))
67 (rope-completions)))
68 (doc-buffer (company-ropemacs-doc-buffer arg))
69 (location (company-ropemacs-location arg))))
70
71 (provide 'company-ropemacs)
72 ;;; company-ropemacs.el ends here