]> code.delx.au - gnu-emacs-elpa/blob - company-pysmell.el
company-keywords: fix interactive invocation
[gnu-emacs-elpa] / 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 ;; Someone who can actually install Pysmell should tell us if this still works.
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30 (require 'pysmell)
31
32 (defvar company-pysmell--available-p 'unknown)
33 (make-variable-buffer-local 'company-pysmell--available-p)
34
35 (defun company-pysmell--available-p ()
36 (if (eq company-pysmell--available-p 'unknown)
37 (setq company-pysmell--available-p
38 (company-locate-dominating-file buffer-file-name "PYSMELLTAGS"))
39 company-pysmell--available-p))
40
41 (defun company-pysmell--grab-symbol ()
42 (let ((symbol (company-grab-symbol)))
43 (when symbol
44 (cons symbol
45 (save-excursion
46 (let ((pos (point)))
47 (goto-char (- (point) (length symbol)))
48 (while (eq (char-before) ?.)
49 (goto-char (1- (point)))
50 (skip-syntax-backward "w_"))
51 (- pos (point))))))))
52
53 ;;;###autoload
54 (defun company-pysmell (command &optional arg &rest ignored)
55 "A `company-mode' completion back-end for pysmell.
56 This requires pysmell.el and pymacs.el."
57 (interactive (list 'interactive))
58 (case command
59 (interactive (company-begin-backend 'company-pysmell))
60 (prefix (and (derived-mode-p 'python-mode)
61 buffer-file-name
62 (not (company-in-string-or-comment))
63 (company-pysmell--available-p)
64 (company-pysmell--grab-symbol)))
65 (candidates (delete "" (pysmell-get-all-completions)))))
66
67 (provide 'company-pysmell)
68 ;;; company-pysmell.el ends here