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)
(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">
After following the solution in the "duplicated question" link, everything seemed to work perfectly, but then after a few hours it started to behave strange, randomdly, sometimes it works sometimes it doesn't. I made a video showing the problem, it works, then I restart Emacs and stops working again.
>UPDATE<
ok, I found out something, it's not that it works randomly, it's just that it simply doesn't works. In that video the auto complete works with the yasnippet keys because they're opened in other buffers, and it's using that. If I close those buffers, they simply stop working. So, the problem is that with this init.el AC it simply doesn't works with yasnippet