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