1 ;;; company-pysmell.el --- a company-mode completion back-end for pysmell.el
3 ;; Copyright (C) 2009 Nikolaj Schumacher
5 ;; This file is part of company 0.5.
7 ;; This program is free software; you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License
9 ;; as published by the Free Software Foundation; either version 2
10 ;; of the License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 (eval-when-compile (require 'cl))
23 (defvar company-pysmell--available-p 'unknown)
24 (make-variable-buffer-local 'company-pysmell--available-p)
26 (defun company-pysmell--available-p ()
27 (if (eq company-pysmell--available-p 'unknown)
28 (setq company-pysmell--available-p
29 (company-locate-dominating-file buffer-file-name "PYSMELLTAGS"))
30 company-pysmell--available-p))
32 (defun company-pysmell--grab-symbol ()
33 (let ((symbol (company-grab-symbol)))
38 (goto-char (- (point) (length symbol)))
39 (while (eq (char-before) ?.)
40 (goto-char (1- (point)))
41 (skip-syntax-backward "w_"))
45 (defun company-pysmell (command &optional arg &rest ignored)
46 "A `company-mode' completion back-end for pysmell.
47 This requires pysmell.el and pymacs.el."
48 (interactive (list 'interactive))
50 ('interactive (company-begin-backend 'company-pysmell))
51 ('prefix (and (derived-mode-p 'python-mode)
53 (not (company-in-string-or-comment))
54 (company-pysmell--available-p)
55 (company-pysmell--grab-symbol)))
56 ('candidates (delete "" (pysmell-get-all-completions)))))
58 (provide 'company-pysmell)
59 ;;; company-pysmell.el ends here