]> rtime.felk.cvut.cz Git - sojka/company-mode.git/blob - company-pysmell.el
Introduce company-clang-insert-arguments
[sojka/company-mode.git] / company-pysmell.el
1 ;;; company-pysmell.el --- 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 ;; The main problem with using this backend is installing Pysmell.
26 ;; I couldn't manage to do that. --Dmitry
27
28 ;;; Code:
29
30 (require 'pysmell)
31 (require 'cl-lib)
32
33 (defvar company-pysmell--available-p 'unknown)
34 (make-variable-buffer-local 'company-pysmell--available-p)
35
36 (defun company-pysmell--available-p ()
37   (if (eq company-pysmell--available-p 'unknown)
38       (setq company-pysmell--available-p
39             (locate-dominating-file buffer-file-name "PYSMELLTAGS"))
40     company-pysmell--available-p))
41
42 (defun company-pysmell--grab-symbol ()
43   (let ((symbol (company-grab-symbol)))
44     (when symbol
45       (cons symbol
46             (save-excursion
47               (let ((pos (point)))
48                 (goto-char (- (point) (length symbol)))
49                 (while (eq (char-before) ?.)
50                   (goto-char (1- (point)))
51                   (skip-syntax-backward "w_"))
52                 (- pos (point))))))))
53
54 ;;;###autoload
55 (defun company-pysmell (command &optional arg &rest ignored)
56   "`company-mode' completion back-end for pysmell.
57 This requires pysmell.el and pymacs.el."
58   (interactive (list 'interactive))
59   (cl-case command
60     (interactive (company-begin-backend 'company-pysmell))
61     (prefix (and (derived-mode-p 'python-mode)
62                  buffer-file-name
63                  (not (company-in-string-or-comment))
64                  (company-pysmell--available-p)
65                  (company-pysmell--grab-symbol)))
66     (candidates (delete "" (pysmell-get-all-completions)))))
67
68 (provide 'company-pysmell)
69 ;;; company-pysmell.el ends here