From 2b5eb202f74f45754591a24063873b5ed48de7d3 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 28 Oct 2012 19:15:58 +0900 Subject: [PATCH] - Improved filter behavior. --- .../sources/snippets_complete.vim | 41 +++++++++++-------- doc/neosnippet.txt | 1 + 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/autoload/neocomplcache/sources/snippets_complete.vim b/autoload/neocomplcache/sources/snippets_complete.vim index 69dc5eb..0799695 100644 --- a/autoload/neocomplcache/sources/snippets_complete.vim +++ b/autoload/neocomplcache/sources/snippets_complete.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: snippets_complete.vim " AUTHOR: Shougo Matsushita -" Last Modified: 21 Oct 2012. +" Last Modified: 28 Oct 2012. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -53,23 +53,7 @@ function! s:source.get_keyword_pos(cur_text)"{{{ endfunction"}}} function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)"{{{ - return s:keyword_filter(neocomplcache#dup_filter( - \ values(neosnippet#get_snippets())), a:cur_keyword_str) -endfunction"}}} - -function! s:keyword_filter(list, cur_keyword_str)"{{{ - " Keyword filter. - - " Uniq by real_name. - let dict = {} - for snippet in neocomplcache#keyword_filter(a:list, a:cur_keyword_str) - if !has_key(dict, snippet.real_name) || - \ len(dict[snippet.real_name].word) > len(snippet.word) - let dict[snippet.real_name] = snippet - endif - endfor - - let list = values(dict) + let list = s:keyword_filter(neosnippet#get_snippets(), a:cur_keyword_str) " Substitute abbr. let abbr_pattern = printf('%%.%ds..%%s', @@ -92,6 +76,27 @@ function! s:keyword_filter(list, cur_keyword_str)"{{{ return list endfunction"}}} +function! s:keyword_filter(snippets, cur_keyword_str)"{{{ + " Uniq by real_name. + let dict = {} + let list = neocomplcache#keyword_filter( + \ values(a:snippets), a:cur_keyword_str) + + " Add cur_keyword_str snippet. + if has_key(a:snippets, a:cur_keyword_str) + call add(list, a:snippets[a:cur_keyword_str]) + endif + + for snippet in neocomplcache#dup_filter(list) + if !has_key(dict, snippet.real_name) || + \ len(dict[snippet.real_name].word) > len(snippet.word) + let dict[snippet.real_name] = snippet + endif + endfor + + return values(dict) +endfunction"}}} + function! neocomplcache#sources#snippets_complete#define()"{{{ return s:source diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index d0d9ced..8887bee 100644 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -457,6 +457,7 @@ CHANGELOG *neosnippet-changelog* 2012-10-28 - Improved snipMate compatibility. - Improved expand behavior. +- Improved filter behavior. 2012-10-27 - Fixed for :SnippetEdit.