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/>.
25 ;; Someone who can actually install Pysmell should tell us if this still works.
29 (eval-when-compile (require 'cl))
32 (defvar company-pysmell--available-p 'unknown)
33 (make-variable-buffer-local 'company-pysmell--available-p)
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))
41 (defun company-pysmell--grab-symbol ()
42 (let ((symbol (company-grab-symbol)))
47 (goto-char (- (point) (length symbol)))
48 (while (eq (char-before) ?.)
49 (goto-char (1- (point)))
50 (skip-syntax-backward "w_"))
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))
59 (interactive (company-begin-backend 'company-pysmell))
60 (prefix (and (derived-mode-p 'python-mode)
62 (not (company-in-string-or-comment))
63 (company-pysmell--available-p)
64 (company-pysmell--grab-symbol)))
65 (candidates (delete "" (pysmell-get-all-completions)))))
67 (provide 'company-pysmell)
68 ;;; company-pysmell.el ends here