读书人

yasnippet 0.7.0跟auto-complete-mode

发布时间: 2012-06-21 13:42:41 作者: rapoo

yasnippet 0.7.0和auto-complete-mode一起使用

I will only talk about how to set up yasnippet 0.7.0 or higher version.

Table of Contents1 If you follow `normal install` way, setup is simple2 If you use elpa package system, setup is even simpler3 The real world setup is NOT simple3.1 Two snippets may share the same key, so I need activate `yas/dropdown-prompt'3.2 `yas/dropdown-prompt' is not perfect3.3 Yasnippets conflicts with other plugins4 My final yasnippet setup

See its official documentation.

Install the yasnippet into somewhere and add following code into your .emacs:

After installation, you only need two lines in .emacs.

I will explain the reasons at first and give my complete yasnippet configuration code at the end of the this post.

One issue is I need a user-friendly dropdown window popped up when the key I input has several candidates. For example, when I type "inc" in C code. There are two candicates `#include "…"' and `#include <…>' available. A handy dropdown popup will help me to choose one of them as efficient as possible.

The good news is such fancy popup is a standard component of yasnippet. It's called `yas/dropdown-prompt'. Yasnippet's default algorithm will activate it at highest prority.

The bad news is for some wierd reason yasnippet won't load that dropdown-list by default. So you need manually load that component by one line of elisp code `(require 'dropdown-list)'.

I cannot scroll down the dropdown window when there are more candidates it can display. That's especially annoying when calling `yas/insert-snippet'. In this case, we need use `yas/completing-prompt' instead. I will show the fix at the end of this article.

I use Auto Complete Mode (version 20120327 in elpa). There are two issuses when using it with yasnippets.

First, it use TAB key to do the auto-complete thing while yasnippet also uses TAB key. So I need re-configure hotkeys of yasnippets.

Second, yansippet changed its API `yas/get-snippet-tables' since version 0.7.0. This make the auto-complete cannot use yasnippet at all. This issue isreported and fixed by tkf. Actually all you need do is simple:

(require 'yasnippet)(yas/initialize);; default TAB key is occupied by auto-complete(global-set-key (kbd "C-c ; u") 'yas/expand);; default hotkey `C-c & C-s` is still valid(global-set-key (kbd "C-c ; s") 'yas/insert-snippet);; give yas/dropdown-prompt in yas/prompt-functions a chance(require 'dropdown-list);; use yas/completing-prompt when ONLY when `M-x yas/insert-snippet';; thanks to capitaomorte for providing the trick.(defadvice yas/insert-snippet (around use-completing-prompt activate)     "Use `yas/completing-prompt' for `yas/prompt-functions' but only here..."       (let ((yas/prompt-functions '(yas/completing-prompt)))             ad-do-it))

读书人网 >其他相关

热点推荐