[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 17/31: Add company-yasnippet
From: |
Dmitry Gutov |
Subject: |
[elpa] 17/31: Add company-yasnippet |
Date: |
Tue, 18 Mar 2014 05:19:37 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 7f3f2239d85b7f994163401f24889d26141c8c1b
Author: Dmitry Gutov <address@hidden>
Date: Tue Mar 11 14:59:14 2014 +0200
Add company-yasnippet
Closes #73
---
NEWS.md | 1 +
company-yasnippet.el | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index da764ab..7403af4 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
## Next
+* New bundled back-end `company-yasnippet`.
* Completion candidates returned from grouped back-ends are tagged to remember
which back-end each came from.
* New user option `company-tooltip-align-annotations`, off by default.
diff --git a/company-yasnippet.el b/company-yasnippet.el
new file mode 100644
index 0000000..ad7c8dc
--- /dev/null
+++ b/company-yasnippet.el
@@ -0,0 +1,88 @@
+;;; company-clang.el --- company-mode completion back-end for Clang
+
+;; Copyright (C) 2014 Free Software Foundation, Inc.
+
+;; Author: Dmitry Gutov
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+
+;;; Commentary:
+;;
+
+;;; Code:
+
+(require 'yasnippet)
+
+(defun company-yasnippet--candidates (prefix)
+ (mapcan
+ (lambda (table)
+ (let ((keyhash (yas--table-hash table))
+ res)
+ (when keyhash
+ (maphash
+ (lambda (key value)
+ (when (and (stringp key)
+ (string-prefix-p prefix key))
+ (maphash
+ (lambda (name template)
+ (push
+ (propertize key
+ 'yas-annotation name
+ 'yas-template template)
+ res))
+ value)))
+ keyhash))
+ res))
+ (yas--get-snippet-tables)))
+
+(defun company-yasnippet (command &optional arg &rest ignore)
+ "`company-mode' back-end for `yasnippet'.
+
+This back-end is supposed to be used in a particular way:
+
+* In a buffer-local value of `company-backends'.
+* Grouped with a backend or several that provide actual text completions.
+
+Neither condition is mandatory, but as long as there are snippets defined
+for the current major mode, this back-end will always shadow back-ends that
+come after it. So any other back-ends intended to be used in the current
+buffer should be grouped with it. Example config:
+
+ (add-hook 'js-mode-hook
+ (lambda ()
+ (set (make-local-variable 'company-backends)
+ '((company-dabbrev-code company-yasnippet))))
+"
+ (interactive (list 'interactive))
+ (case command
+ (interactive (company-begin-backend 'company-yasnippet))
+ (prefix
+ ;; Should probably use `yas--current-key', but that's bound to be slower.
+ ;; How many trigger keys start with non-symbol characters anyway?
+ (and yas-minor-mode
+ (company-grab-symbol)))
+ (annotation (concat " -> " (get-text-property 0 'yas-annotation arg)))
+ (candidates (company-yasnippet--candidates arg))
+ (post-completion
+ (let ((template (get-text-property 0 'yas-template arg)))
+ (yas-expand-snippet (yas--template-content template)
+ (- (point) (length arg))
+ (point)
+ (yas--template-expand-env template))))))
+
+(provide 'company-yasnippet)
+;;; company-yasnippet.el ends here
- [elpa] 14/31: Fix indentation, (continued)
- [elpa] 14/31: Fix indentation, Dmitry Gutov, 2014/03/18
- [elpa] 11/31: Remove superfluous statement, Dmitry Gutov, 2014/03/18
- [elpa] 10/31: company-auto-begin: wrap `company-begin' in `condition-case-no-debug', Dmitry Gutov, 2014/03/18
- [elpa] 12/31: Fix `args-out-of-bounds' error on formatting annotations when annotation start position is greater than the width of window., Dmitry Gutov, 2014/03/18
- [elpa] 05/31: Add user option company-tooltip-align-annotations, Dmitry Gutov, 2014/03/18
- [elpa] 15/31: Clear company-backend in company-auto-begin, Dmitry Gutov, 2014/03/18
- [elpa] 19/31: Highlight last annotation character, too, Dmitry Gutov, 2014/03/18
- [elpa] 13/31: Merge pull request #70 from sadboy/master, Dmitry Gutov, 2014/03/18
- [elpa] 18/31: company--multi-backend-adapter: noop when arg is empty, Dmitry Gutov, 2014/03/18
- [elpa] 16/31: Tag candidates from grouped backends, Dmitry Gutov, 2014/03/18
- [elpa] 17/31: Add company-yasnippet,
Dmitry Gutov <=
- [elpa] 22/31: company-sort-by-occurrence: do stable sorting, Dmitry Gutov, 2014/03/18
- [elpa] 20/31: Fix company-yasnippet summary, Dmitry Gutov, 2014/03/18
- [elpa] 23/31: Define company-version, Dmitry Gutov, 2014/03/18
- [elpa] 24/31: company-yasnippet: autoload, to make it easy to use separately, Dmitry Gutov, 2014/03/18
- [elpa] 27/31: company-semantic--current-tags: make buffer-local, Dmitry Gutov, 2014/03/18
- [elpa] 25/31: company-keywords-alist: add missing question mark, Dmitry Gutov, 2014/03/18
- [elpa] 29/31: Remove leftover debug statement, Dmitry Gutov, 2014/03/18
- [elpa] 28/31: company-semantic: don't try to fetch doc for tag without buffer, Dmitry Gutov, 2014/03/18
- [elpa] 08/31: Wrap `company-call-backend' in `condition-case', Dmitry Gutov, 2014/03/18
- [elpa] 26/31: Support the keyword :with, Dmitry Gutov, 2014/03/18