;;; Code:
-(require 'yasnippet)
+(require 'company)
+(require 'cl-lib)
+
+(declare-function yas--table-hash "yasnippet")
+(declare-function yas--get-snippet-tables "yasnippet")
+(declare-function yas-expand-snippet "yasnippet")
+(declare-function yas--template-content "yasnippet")
+(declare-function yas--template-expand-env "yasnippet")
(defun company-yasnippet--candidates (prefix)
- (mapcan
+ (cl-mapcan
(lambda (table)
(let ((keyhash (yas--table-hash table))
res)
res))
(yas--get-snippet-tables)))
+;;;###autoload
(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.
+This back-end should be used with care, because as long as there are
+snippets defined for the current major mode, this back-end will always
+shadow back-ends that come after it. Recommended usages:
-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:
+* In a buffer-local value of `company-backends', grouped with a back-end or
+ several that provide actual text completions.
(add-hook 'js-mode-hook
(lambda ()
(set (make-local-variable 'company-backends)
- '((company-dabbrev-code company-yasnippet))))
+ '((company-dabbrev-code company-yasnippet)))))
+
+* After keyword `:with', grouped with other back-ends.
+
+ (push '(company-semantic :with company-yasnippet) company-backends)
+
+* Not in `company-backends', just bound to a key.
+
+ (global-set-key (kbd \"C-c y\") 'company-yasnippet)
"
(interactive (list 'interactive))
- (case command
+ (cl-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
+ (and (bound-and-true-p yas-minor-mode)
(company-grab-symbol)))
- (annotation (concat " -> " (get-text-property 0 'yas-annotation arg)))
+ (annotation
+ (concat
+ (unless company-tooltip-align-annotations " -> ")
+ (get-text-property 0 'yas-annotation arg)))
(candidates (company-yasnippet--candidates arg))
(post-completion
(let ((template (get-text-property 0 'yas-template arg)))