]> rtime.felk.cvut.cz Git - sojka/company-mode.git/blob - company-pysmell.el
Merge changes from the GNU ELPA repository
[sojka/company-mode.git] / company-pysmell.el
1 ;;; company-pysmell.el --- A company-mode completion back-end for pysmell.el
2
3 ;; Copyright (C) 2009-2011  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 (eval-when-compile (require 'cl))
29 (require 'pysmell)
30
31 (defvar company-pysmell--available-p 'unknown)
32 (make-variable-buffer-local 'company-pysmell--available-p)
33
34 (defun company-pysmell--available-p ()
35   (if (eq company-pysmell--available-p 'unknown)
36       (setq company-pysmell--available-p
37             (company-locate-dominating-file buffer-file-name "PYSMELLTAGS"))
38     company-pysmell--available-p))
39
40 (defun company-pysmell--grab-symbol ()
41   (let ((symbol (company-grab-symbol)))
42     (when symbol
43       (cons symbol
44             (save-excursion
45               (let ((pos (point)))
46                 (goto-char (- (point) (length symbol)))
47                 (while (eq (char-before) ?.)
48                   (goto-char (1- (point)))
49                   (skip-syntax-backward "w_"))
50                 (- pos (point))))))))
51
52 ;;;###autoload
53 (defun company-pysmell (command &optional arg &rest ignored)
54   "A `company-mode' completion back-end for pysmell.
55 This requires pysmell.el and pymacs.el."
56   (interactive (list 'interactive))
57   (case command
58     (interactive (company-begin-backend 'company-pysmell))
59     (prefix (and (derived-mode-p 'python-mode)
60                  buffer-file-name
61                  (not (company-in-string-or-comment))
62                  (company-pysmell--available-p)
63                  (company-pysmell--grab-symbol)))
64     (candidates (delete "" (pysmell-get-all-completions)))))
65
66 (provide 'company-pysmell)
67 ;;; company-pysmell.el ends here