]> code.delx.au - gnu-emacs-elpa/blob - packages/company/company-pysmell.el
Update packages/yasnippet by subtree-merging from its github-based upstream
[gnu-emacs-elpa] / packages / company / company-pysmell.el
1 ;;; company-pysmell.el --- company-mode completion back-end for pysmell.el
2
3 ;; Copyright (C) 2009-2011, 2013-2014 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 ;; The main problem with using this backend is installing Pysmell.
26 ;; I couldn't manage to do that. --Dmitry
27
28 ;;; Code:
29
30 (if t (require 'pysmell)) ;Don't load during compilation.
31 (require 'company)
32 (require 'cl-lib)
33
34 (defvar-local company-pysmell--available-p 'unknown)
35
36 (defun company-pysmell--available-p ()
37 (if (eq company-pysmell--available-p 'unknown)
38 (setq company-pysmell--available-p
39 (locate-dominating-file buffer-file-name "PYSMELLTAGS"))
40 company-pysmell--available-p))
41
42 (defun company-pysmell--grab-symbol ()
43 (let ((symbol (company-grab-symbol)))
44 (when symbol
45 (cons symbol
46 (save-excursion
47 (let ((pos (point)))
48 (goto-char (- (point) (length symbol)))
49 (while (eq (char-before) ?.)
50 (goto-char (1- (point)))
51 (skip-syntax-backward "w_"))
52 (- pos (point))))))))
53
54 ;;;###autoload
55 (defun company-pysmell (command &optional arg &rest ignored)
56 "`company-mode' completion back-end for pysmell.
57 This requires pysmell.el and pymacs.el."
58 (interactive (list 'interactive))
59 (cl-case command
60 (interactive (company-begin-backend 'company-pysmell))
61 (prefix (and (derived-mode-p 'python-mode)
62 buffer-file-name
63 (not (company-in-string-or-comment))
64 (company-pysmell--available-p)
65 (company-pysmell--grab-symbol)))
66 (candidates (delete "" (pysmell-get-all-completions)))))
67
68 (provide 'company-pysmell)
69 ;;; company-pysmell.el ends here