]> code.delx.au - gnu-emacs-elpa/blob - company-tempo.el
Bumped version to 0.4.3.
[gnu-emacs-elpa] / company-tempo.el
1 ;;; company-tempo.el --- a company-mode completion back-end for tempo
2 ;;
3 ;; Copyright (C) 2009 Nikolaj Schumacher
4 ;;
5 ;; This file is part of company 0.4.3.
6 ;;
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.
11 ;;
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.
16 ;;
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/>.
19
20 (require 'company)
21 (eval-when-compile (require 'cl))
22 (require 'tempo)
23
24 (defsubst company-tempo-lookup (match)
25 (cdr (assoc match (tempo-build-collection))))
26
27 (defun company-tempo-insert (match)
28 "Replace MATCH with the expanded tempo template."
29 (search-backward match)
30 (goto-char (match-beginning 0))
31 (replace-match "")
32 (call-interactively (company-tempo-lookup match)))
33
34 (defsubst company-tempo-meta (match)
35 (let ((templ (company-tempo-lookup match))
36 doc)
37 (and templ
38 (setq doc (documentation templ t))
39 (car (split-string doc "\n" t)))))
40
41 ;;;###autoload
42 (defun company-tempo (command &optional arg &rest ignored)
43 "A `company-mode' completion back-end for tempo."
44 (interactive (list 'interactive))
45 (case command
46 ('interactive (company-begin-backend 'company-tempo
47 'company-tempo-insert))
48 ('prefix (or (car (tempo-find-match-string tempo-match-finder)) ""))
49 ('candidates (all-completions arg (tempo-build-collection)))
50 ('meta (company-tempo-meta arg))
51 ('require-match t)
52 ('sorted t)))
53
54 (provide 'company-tempo)
55 ;;; company-tempo.el ends here