Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
813 views
in Technique[技术] by (71.8m points)

emacs - How to get completion for yasnippets using auto-complete

I am using autocomplete-1.4.0 and yasnippet-0.8.1 with the following order and configuration in my .emacs file.

    ; === auto-complete ===
    (require 'auto-complete)
    (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict") 
    (require 'auto-complete-config)
    (ac-config-default)

    ;; === yasnippet ===
    (require 'yasnippet)
    (yas-global-mode t)
    (setq yas-snippet-dirs
    '("~/.emacs.d/snippets/my-snippets"
      "~/.emacs.d/snippets/yasnippet-snippets"
      ))

However, I get no prompts from autocomplete for any of the existing snippets or for any of the new snippets that I create. Can someone help if I am doing something wrong here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should add the yasnippet ac-source. I have this in my init files:

(defun add-yasnippet-ac-sources ()
  (add-to-list 'ac-sources 'ac-source-yasnippet))

Then for every mode where I want the yasnippet source enabled, I add add-yasnippet-ac-sources to that mode hook:

(add-hook 'ruby-mode-hook 'add-yasnippet-ac-sources)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...