1
3
2012
18

neocomplcache: 请尊重大小写!

本文来自依云's Blog,转载请注明。

今天给 Vim 加了个 CursorHold 事件。加完提交到 git 仓库中,发现写 Cur 时,neocomplcache 给出的补全是 Cursorhold,而不是代码中写的 CursorHold,得手动改过来,很郁闷。这已经不是我第一次遇到了,决定需求解决方案。

neocomplcache 关于大小写的设置变量有两个,g:neocomplcache_enable_ignore_caseg:neocomplcache_enable_smart_case。这两个我都没有设置啊。以为是 bug,上网搜索无果,遂看源码,最终发现这真是款自作聪明的插件——在输入文本而不是代码时,它将总是忽略大小写!

补丁如下:

commit aaed422a2dff182954813c16db242545389a0018
Author: 依云 <lilydjwg@gmail.com>
Date:   2012-01-03 23:01:43 +0800

    neocomplcache: never use 'is_text_mode'
    
    This always causes inconvenience for me.

diff --git a/autoload/neocomplcache.vim b/autoload/neocomplcache.vim
index 26a2d09..ac1e0f0 100644
--- a/autoload/neocomplcache.vim
+++ b/autoload/neocomplcache.vim
@@ -995,9 +995,6 @@ endfunction"}}}
 function! neocomplcache#is_eskk_enabled()"{{{
   return exists('*eskk#is_enabled') && eskk#is_enabled()
 endfunction"}}}
-function! neocomplcache#is_text_mode()"{{{
-  return s:is_text_mode || s:within_comment
-endfunction"}}}
 function! neocomplcache#is_win()"{{{
   return has('win32') || has('win64')
 endfunction"}}}
@@ -1135,9 +1132,7 @@ function! neocomplcache#get_complete_result(cur_text, ...)"{{{
       " Save options.
       let l:ignorecase_save = &ignorecase
 
-      if neocomplcache#is_text_mode()
-        let &ignorecase = 1
-      elseif g:neocomplcache_enable_smart_case && l:cur_keyword_str =~ '\u'
+      if g:neocomplcache_enable_smart_case && l:cur_keyword_str =~ '\u'
         let &ignorecase = 0
       else
         let &ignorecase = g:neocomplcache_enable_ignore_case
@@ -1289,26 +1284,6 @@ function! neocomplcache#integrate_completion(complete_result, is_sort)"{{{
     endfor
   endif"}}}
 
-  " Convert words.
-  if neocomplcache#is_text_mode()"{{{
-    if l:cur_keyword_str =~ '^\l\+$'
-      for l:keyword in l:complete_words
-        let l:keyword.word = tolower(l:keyword.word)
-        let l:keyword.abbr = tolower(l:keyword.abbr)
-      endfor
-    elseif l:cur_keyword_str =~ '^\u\+$'
-      for l:keyword in l:complete_words
-        let l:keyword.word = toupper(l:keyword.word)
-        let l:keyword.abbr = toupper(l:keyword.abbr)
-      endfor
-    elseif l:cur_keyword_str =~ '^\u\l\+$'
-      for l:keyword in l:complete_words
-        let l:keyword.word = toupper(l:keyword.word[0]).tolower(l:keyword.word[1:])
-        let l:keyword.abbr = toupper(l:keyword.abbr[0]).tolower(l:keyword.abbr[1:])
-      endfor
-    endif
-  endif"}}}
-
   if g:neocomplcache_max_keyword_width >= 0"{{{
     " Abbr check.
     let l:abbr_pattern = printf('%%.%ds..%%s', g:neocomplcache_max_keyword_width-15)
@@ -1671,9 +1646,7 @@ function! neocomplcache#complete_common_string()"{{{
   " Get cursor word.
   let [l:cur_keyword_pos, l:cur_keyword_str] = neocomplcache#match_word(s:get_cur_text())
 
-  if neocomplcache#is_text_mode()
-    let &ignorecase = 1
-  elseif g:neocomplcache_enable_smart_case && l:cur_keyword_str =~ '\u'
+  if g:neocomplcache_enable_smart_case && l:cur_keyword_str =~ '\u'
     let &ignorecase = 0
   else
     let &ignorecase = g:neocomplcache_enable_ignore_case
@@ -1771,9 +1744,7 @@ function! s:make_quick_match_list(list, cur_keyword_str)"{{{
   " Save options.
   let l:ignorecase_save = &ignorecase
 
-  if neocomplcache#is_text_mode()
-    let &ignorecase = 1
-  elseif g:neocomplcache_enable_smart_case && a:cur_keyword_str =~ '\u'
+  if g:neocomplcache_enable_smart_case && a:cur_keyword_str =~ '\u'
     let &ignorecase = 0
   else
     let &ignorecase = g:neocomplcache_enable_ignore_case
diff --git a/autoload/neocomplcache/sources/dictionary_complete.vim b/autoload/neocomplcache/sources/dictionary_complete.vim
index 97e7b12..dda34be 100644
--- a/autoload/neocomplcache/sources/dictionary_complete.vim
+++ b/autoload/neocomplcache/sources/dictionary_complete.vim
@@ -79,11 +79,7 @@ endfunction"}}}
 function! s:source.get_keyword_list(cur_keyword_str)"{{{
   let l:list = []
 
-  let l:filetype = neocomplcache#is_text_mode() ? 'text' : neocomplcache#get_context_filetype()
-  if neocomplcache#is_text_mode() && !has_key(s:dictionary_list, 'text')
-    " Caching.
-    call s:caching()
-  endif
+  let l:filetype = neocomplcache#get_context_filetype()
 
   for l:ft in neocomplcache#get_source_filetypes(l:filetype)
     call neocomplcache#cache#check_cache('dictionary_cache', l:ft, s:async_dictionary_list,
@@ -102,7 +98,7 @@ function! s:caching()"{{{
     return
   endif
 
-  let l:key = neocomplcache#is_text_mode() ? 'text' : neocomplcache#get_context_filetype()
+  let l:key = neocomplcache#get_context_filetype()
   for l:filetype in neocomplcache#get_source_filetypes(l:key)
     if !has_key(s:dictionary_list, l:filetype)
           \ && !has_key(s:async_dictionary_list, l:filetype)

2012年3月30日更新:针对 neocomplcache 6.2 的补丁在此

2013年6月2日更新:针对 neocomplcache 8.0 的补丁在这里或者这里。对应的 git 提交为 17dd164。

Category: Vim | Tags: vim | Read Count: 11458
harry 说:
Jan 04, 2012 12:15:43 AM

我也有遇到这个问题,主要就是在写git提交日志的时候。

Avatar_small
Rykka 说:
Jan 04, 2012 01:40:25 AM

怪不得我说我设置了
g:neocomplcache_enable_smart_case
g:neocomplcache_enable_ignore_case
g:neocomplcache_enable_camel_case_completion
怎么总是大小写表现不一致。
还以为里面还有另外的选项我没设置。

你提交给作者了么?

Avatar_small
依云 说:
Jan 04, 2012 01:05:07 PM

没有。我估计他不会喜欢,不然也不会加这些了。

9hills 说:
Jan 04, 2012 05:01:43 PM

最好来个pull request

Avatar_small
Rykka 说:
Jan 04, 2012 05:45:43 PM

我以前给他提的有个建议后来也被他取消掉了。

但是这个作者更新很频繁的,这样版本不同patch的时候就会出错啊。

4 out of 5 hunks FAILED -- saving rejects to file autoload/neocomplcache.vim.rej

难道只能手动改了么。。。

Avatar_small
Rykka 说:
Jan 04, 2012 05:54:33 PM

嗯,我猜如果他来的话可能是添加一个g:neocomplcache_enable_text_mode_ignore_case之类的选项吧。

Avatar_small
依云 说:
Jan 04, 2012 06:06:15 PM

嗯。。。。我用的 vim.org 上的。你用的 git 版?

xsnail 说:
Jan 06, 2012 05:25:42 PM

你那个在gvim用firefox打开链接我不知道什么意思,也不知道怎么用,求指导

Avatar_small
依云 说:
Jan 06, 2012 06:10:16 PM

你说的是我 vimrc 的那个?在链接上按 tf 就调用火狐(Windows 上是默认浏览器)打开链接。

xsnail 说:
Jan 06, 2012 06:13:58 PM

<h3 class="title"><a href="http://www.baidu.com">标题</h3>
比如这个吧我按了tf也不管用哦。想好好学一下vim环境是windows的还请博主赐教

Avatar_small
依云 说:
Jan 06, 2012 07:07:27 PM

可能是命令行不正确吧,不太会用 windows。不行你试试把命令改成你的浏览器的路径(注意引号)。
你关于 vim 有什么问题可以到 test@vim-cn.com 这个 gtalk 群来问,最近因为没什么人问问题所以话题比较水。。。。如果 gtalk 登录困难的话可以试试别的 XMPP 服务器,比如 https://www.jappix.com/ 或者 https://lisux.tk/ (自签名证书)。这两个 Web 版的 XMPP 客户端也可以用来注册/登录别的域名下的 XMPP 服务,比如 gtalk。

Avatar_small
依云 说:
Jan 06, 2012 10:51:19 PM

一点小问题就算了吧,维护起来太麻烦了。

tianxialangui 说:
Jun 05, 2012 03:09:51 AM

hello,我想请教一下neocomplcatche是怎么实现的。我想自己写一个vim的补全插件,之前补全用之用简单的<C-N>和自己写的一个小功能补全。现在实现类似与neocomplcateche可以在输入任意字符可以弹出下拉补全列表。我目前使用的是
inoremap a a<C-X><C-U><C-P>
inoremap b b<C-X><C-U><C-P>
..
inoremap z z<C-X><C-U><C-P>
这种方式,不过感觉不是很好,请问一下neocompcatche是怎么实现的??

Avatar_small
依云 说:
Jun 05, 2012 10:03:15 AM

neocomplcache 使用的是 CursorHoldI 和 CursorMovedI 事件。

tianxialangui 说:
Jun 05, 2012 10:29:18 AM

这么一说我看明白neocomplcache的源代码了,使用CursorHoldl和CursorHoldI事件,然后使用feedkeys插入字符。难怪之前我找inoremap和map找不到指定的按键信息。作者真聪明。谢谢呀。

fanhe 说:
May 28, 2013 12:02:53 PM

我也很不明白,这个插件的作者的需求为什么就这么反人类呢,我需要匹配的时候ic,不是在插入文本的时候ic啊
懒得改了,暂时不用这插件


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

| Theme: Aeros 2.0 by TheBuckmaker.com