]> code.delx.au - gnu-emacs-elpa/blobdiff - company-yasnippet.el
Merge pull request #106 from proofit404/master
[gnu-emacs-elpa] / company-yasnippet.el
index ce2caac1546aa20abc5527b48e16c6dadeb88a0d..741a160086707a5ed25c4681a63f0c7bd4488c02 100644 (file)
@@ -25,6 +25,7 @@
 
 ;;; Code:
 
+(require 'cl-lib)
 (require 'yasnippet)
 
 (defun company-yasnippet--candidates (prefix)
        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:
+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:
 
-* 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:
+* 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
           (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)))