]>
Commit | Line | Data |
---|---|---|
53e6db90 DC |
1 | ;;; company-tempo.el --- company-mode completion backend for tempo |
2 | ||
3 | ;; Copyright (C) 2009-2011, 2013-2016 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 <https://www.gnu.org/licenses/>. | |
21 | ||
22 | ||
23 | ;;; Commentary: | |
24 | ;; | |
25 | ||
26 | ;;; Code: | |
27 | ||
28 | (require 'company) | |
29 | (require 'cl-lib) | |
30 | (require 'tempo) | |
31 | ||
32 | (defgroup company-tempo nil | |
33 | "Tempo completion backend." | |
34 | :group 'company) | |
35 | ||
36 | (defcustom company-tempo-expand nil | |
37 | "Whether to expand a tempo tag after completion." | |
38 | :type '(choice (const :tag "Off" nil) | |
39 | (const :tag "On" t))) | |
40 | ||
41 | (defsubst company-tempo-lookup (match) | |
42 | (cdr (assoc match (tempo-build-collection)))) | |
43 | ||
44 | (defun company-tempo-insert (match) | |
45 | "Replace MATCH with the expanded tempo template." | |
46 | (search-backward match) | |
47 | (goto-char (match-beginning 0)) | |
48 | (replace-match "") | |
49 | (call-interactively (company-tempo-lookup match))) | |
50 | ||
51 | (defsubst company-tempo-meta (match) | |
52 | (let ((templ (company-tempo-lookup match)) | |
53 | doc) | |
54 | (and templ | |
55 | (setq doc (documentation templ t)) | |
56 | (car (split-string doc "\n" t))))) | |
57 | ||
58 | ;;;###autoload | |
59 | (defun company-tempo (command &optional arg &rest ignored) | |
60 | "`company-mode' completion backend for tempo." | |
61 | (interactive (list 'interactive)) | |
62 | (cl-case command | |
63 | (interactive (company-begin-backend 'company-tempo)) | |
64 | (prefix (or (car (tempo-find-match-string tempo-match-finder)) "")) | |
65 | (candidates (all-completions arg (tempo-build-collection))) | |
66 | (kind 'snippet) | |
67 | (meta (company-tempo-meta arg)) | |
68 | (post-completion (when company-tempo-expand (company-tempo-insert arg))) | |
69 | (sorted t))) | |
70 | ||
71 | (provide 'company-tempo) | |
72 | ;;; company-tempo.el ends here |