1 ;;; company-tempo.el --- company-mode completion backend for tempo
3 ;; Copyright (C) 2009-2011, 2013-2016 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 <https://www.gnu.org/licenses/>.
32 (defgroup company-tempo nil
33 "Tempo completion backend."
36 (defcustom company-tempo-expand nil
37 "Whether to expand a tempo tag after completion."
38 :type '(choice (const :tag "Off" nil)
41 (defsubst company-tempo-lookup (match)
42 (cdr (assoc match (tempo-build-collection))))
44 (defun company-tempo-insert (match)
45 "Replace MATCH with the expanded tempo template."
46 (search-backward match)
47 (goto-char (match-beginning 0))
49 (call-interactively (company-tempo-lookup match)))
51 (defsubst company-tempo-meta (match)
52 (let ((templ (company-tempo-lookup match))
55 (setq doc (documentation templ t))
56 (car (split-string doc "\n" t)))))
59 (defun company-tempo (command &optional arg &rest ignored)
60 "`company-mode' completion backend for tempo."
61 (interactive (list 'interactive))
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)))
67 (meta (company-tempo-meta arg))
68 (post-completion (when company-tempo-expand (company-tempo-insert arg)))
71 (provide 'company-tempo)
72 ;;; company-tempo.el ends here