I have configured yasnippet and auto-complete bindings so it won't collide, auto complete uses <tab>
and yasnippet uses <backtab>
:
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets/snippets"
"~/.emacs.d/snippets/yasmate/snippets"
))
(yas-global-mode 1)
;; Remove Yasnippet's default tab key binding
(define-key yas-minor-mode-map (kbd "<tab>") nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
;; Set Yasnippet's key binding to shift+tab
(define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
I also added yasnippet source like this to the ac-sources as recommended in this question.
(defun add-yasnippet-ac-sources ()
(add-to-list 'ac-sources 'ac-source-yasnippet))
(add-hook 'web-mode-hook 'add-yasnippet-ac-sources)
I created two yasnippets one with the key lorem_dummy
and the other with the key lorem_image
, one of the examples:
# -*- mode: snippet; require-final-newline: nil -*-
# name: lorem_image
# key: lorem_image
# binding: direct-keybinding
# --
<img src="http://lorempixel.com/${1:width}/${2:height}/${3:$$(yas-choose-value '("abstract" "city" "animals" "food" "people" "transport" "business" "sports" "technics"))}/${4:text}" alt="$3">
So, the problem is that with this init.el AC it simply doesn't works with yasnippet. The autocomplete won't popup with the snippets. If you want to watch exactly what its going on you can watch this video: