[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company 393084d 1/3: Support yasnippet's condition dire
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company 393084d 1/3: Support yasnippet's condition directive |
Date: |
Sun, 26 Sep 2021 17:57:07 -0400 (EDT) |
branch: externals/company
commit 393084d278257ac610fbfc330d726cca8405e85a
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
Support yasnippet's condition directive
Resolves #1179
---
NEWS.md | 2 ++
company-yasnippet.el | 20 +++++++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index d6e294ef..61701e5 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
## Next
+* `company-yasnippet` respects the `condition` directive in snippets
+ ([#1179](https://github.com/company-mode/company-mode/issues/1179)).
* New user option `company-icon-margin`.
* `company-show-numbers` has been renamed to `company-show-quick-access`
([#1115](https://github.com/company-mode/company-mode/pull/1115)).
diff --git a/company-yasnippet.el b/company-yasnippet.el
index 29067dc..e5df065 100644
--- a/company-yasnippet.el
+++ b/company-yasnippet.el
@@ -35,6 +35,9 @@
(declare-function yas--template-expand-env "yasnippet")
(declare-function yas--warning "yasnippet")
(declare-function yas-minor-mode "yasnippet")
+(declare-function yas--require-template-specific-condition-p "yasnippet")
+(declare-function yas--template-can-expand-p "yasnippet")
+(declare-function yas--template-condition "yasnippet")
(defvar company-yasnippet-annotation-fn
(lambda (name)
@@ -86,6 +89,7 @@ It has to accept one argument: the snippet's name.")
(cl-mapcan
(lambda (table)
(let ((keyhash (yas--table-hash table))
+ (requirement (yas--require-template-specific-condition-p))
res)
(when keyhash
(maphash
@@ -94,13 +98,15 @@ It has to accept one argument: the snippet's name.")
(string-prefix-p key-prefix key))
(maphash
(lambda (name template)
- (push
- (propertize key
- 'yas-annotation name
- 'yas-template template
- 'yas-prefix-offset (- (length key-prefix)
- (length prefix)))
- res))
+ (when (yas--template-can-expand-p
+ (yas--template-condition template) requirement)
+ (push
+ (propertize key
+ 'yas-annotation name
+ 'yas-template template
+ 'yas-prefix-offset (- (length key-prefix)
+ (length prefix)))
+ res)))
value)))
keyhash))
res))