]> code.delx.au - gnu-emacs-elpa/blob - packages/company-0.5/company-pysmell.el
(debbugs-emacs): New function and modes for listing the Emacs bugs, reading them...
[gnu-emacs-elpa] / packages / company-0.5 / company-pysmell.el
1 ;;; company-pysmell.el --- a company-mode completion back-end for pysmell.el
2
3 ;; Copyright (C) 2009, 2010 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 ;;; Code:
23
24 (eval-when-compile (require 'cl))
25 (require 'pysmell)
26
27 (defvar company-pysmell--available-p 'unknown)
28 (make-variable-buffer-local 'company-pysmell--available-p)
29
30 (defun company-pysmell--available-p ()
31 (if (eq company-pysmell--available-p 'unknown)
32 (setq company-pysmell--available-p
33 (company-locate-dominating-file buffer-file-name "PYSMELLTAGS"))
34 company-pysmell--available-p))
35
36 (defun company-pysmell--grab-symbol ()
37 (let ((symbol (company-grab-symbol)))
38 (when symbol
39 (cons symbol
40 (save-excursion
41 (let ((pos (point)))
42 (goto-char (- (point) (length symbol)))
43 (while (eq (char-before) ?.)
44 (goto-char (1- (point)))
45 (skip-syntax-backward "w_"))
46 (- pos (point))))))))
47
48 ;;;###autoload
49 (defun company-pysmell (command &optional arg &rest ignored)
50 "A `company-mode' completion back-end for pysmell.
51 This requires pysmell.el and pymacs.el."
52 (interactive (list 'interactive))
53 (case command
54 ('interactive (company-begin-backend 'company-pysmell))
55 ('prefix (and (derived-mode-p 'python-mode)
56 buffer-file-name
57 (not (company-in-string-or-comment))
58 (company-pysmell--available-p)
59 (company-pysmell--grab-symbol)))
60 ('candidates (delete "" (pysmell-get-all-completions)))))
61
62 (provide 'company-pysmell)
63 ;;; company-pysmell.el ends here