1 ;;; company-pysmell.el --- A company-mode completion back-end for pysmell.el
3 ;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
5 ;; Author: Nikolaj Schumacher
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
28 (eval-when-compile (require 'cl))
31 (defvar company-pysmell--available-p 'unknown)
32 (make-variable-buffer-local 'company-pysmell--available-p)
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))
40 (defun company-pysmell--grab-symbol ()
41 (let ((symbol (company-grab-symbol)))
46 (goto-char (- (point) (length symbol)))
47 (while (eq (char-before) ?.)
48 (goto-char (1- (point)))
49 (skip-syntax-backward "w_"))
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))
58 (interactive (company-begin-backend 'company-pysmell))
59 (prefix (and (derived-mode-p 'python-mode)
61 (not (company-in-string-or-comment))
62 (company-pysmell--available-p)
63 (company-pysmell--grab-symbol)))
64 (candidates (delete "" (pysmell-get-all-completions)))))
66 (provide 'company-pysmell)
67 ;;; company-pysmell.el ends here