2

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 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">

is it possible to make Emacs auto complete work if I just write lorem and press to show in a dropdown the two choices ( lorem_dummy and lorem_image )? Because right now it doesn't come up the yasnippets, but the regular autocomplete does work ( variables and the rest of the stuff ).

-- update --

Ok, this is strange, 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.

video

Fabman
  • 333
  • 5
  • 20
  • ok, it is a duplicate. I'm sorry but I'm afraid I couldn't find that question when I searched on stackoverflow. Please close or remove this as the one you posted solves my problem. – Fabman May 26 '15 at 12:54

1 Answers1

1

Add ac-source-yasnippet to your ac-sources, e.g.

(eval-after-load "auto-complete"
  '(add-to-list 'ac-sources 'ac-source-yasnippet))
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • I added that after the `` definitions and I got an error: `Symbol's value as variable is void: ac-sources` – Fabman May 26 '15 at 12:40
  • 1
    @Fabman, this only works after `auto-complete` is loaded. I've updated my answer accordingly. – ChrisGPT was on strike May 26 '15 at 12:44
  • I'm sorry my bad, I added that before activating `'ac-sources` and that's why I got that error. Anyway, after adding that still won't auto-complete the snippets. – Fabman May 26 '15 at 12:45
  • @Fabman, if you inspect `ac-sources` (e.g. using `C-h v ac-sources RET` or similar), does the value include `ac-source-yasnippet`? – ChrisGPT was on strike May 26 '15 at 12:46
  • I'm afraid not, it says `Its value is (ac-source-words-in-same-mode-buffers)` – Fabman May 26 '15 at 12:49
  • @Fabman, are you setting `ac-sources` elsewhere in your config? Are you actually loading `auto-complete` somewhere? – ChrisGPT was on strike May 26 '15 at 12:50
  • 1
    Sorry Chris, No, I wasn't, I just checked the 'possible duplicate' that you added and that did solved my problem. I guess I didn't searched for the proper words, english is not my first language. – Fabman May 26 '15 at 12:56
  • I don't know if I should add a new question in stackoverflow or if I can continue to ask in this one, after a few hours working right now the autocomplete of yasnippets is not working again, and then it works sometimes, it randomly works, and if I check the ac-sources the yasnippet source hasn't been added to the web-mode, it's very strange. `(defun add-yasnippet-ac-sources () (add-to-list 'ac-sources 'ac-source-yasnippet)) (add-hook 'web-mode-hook 'add-yasnippet-ac-sources)` – Fabman May 31 '15 at 10:47
  • I made a video, in that video I use a couple of custom snippets, and they work perfectly, and then restart Emacs, try those again and autocomplete won't work with them ( even if they're loaded, because they work if I type them manually ). [--> video <---](http://www.youtube.com/watch?v=F-ewuKhMqW4&hd=1) – Fabman May 31 '15 at 10:56
  • 1
    @Fabman, please ask a new question. – ChrisGPT was on strike May 31 '15 at 12:21
  • ok, thanks, is just that I wasn't quite sure if it was going to be marked as duplicate, because is basically the same question... After the explanation in the new question can I link to this one? – Fabman May 31 '15 at 12:23