Commits

Takeshi NISHIDA  committed 8f1f30f

Added g:acp_behaviorKeywordIgnores option

  • Participants
  • Parent commits a80b4bf

Comments (0)

Files changed (4)

File autoload/acp.vim

 endfunction
 
 "
-function acp#requireForSnipmate(context)
+function acp#meetsForSnipmate(context)
   if g:acp_behaviorSnipmateLength < 0
     return 0
   endif
 endfunction
 
 "
-function acp#requireForKeyword(context)
-  return g:acp_behaviorKeywordLength >= 0 &&
-        \ a:context =~ '\k\{' . g:acp_behaviorKeywordLength . ',}$'
+function acp#meetsForKeyword(context)
+  if g:acp_behaviorKeywordLength < 0
+    return 0
+  endif
+  let matches = matchlist(a:context, '\(\k\{' . g:acp_behaviorKeywordLength . ',}\)$')
+  if empty(matches)
+    return 0
+  endif
+  for ignore in g:acp_behaviorKeywordIgnores
+    if stridx(ignore, matches[1]) == 0
+      return 0
+    endif
+  endfor
+  return 1
 endfunction
 
 "
-function acp#requireForFile(context)
+function acp#meetsForFile(context)
   if g:acp_behaviorFileLength < 0
     return 0
   endif
 endfunction
 
 "
-function acp#requireForRubyOmni(context)
+function acp#meetsForRubyOmni(context)
   if !has('ruby')
     return 0
   endif
 endfunction
 
 "
-function acp#requireForPythonOmni(context)
+function acp#meetsForPythonOmni(context)
   return has('python') &&
         \ a:context =~ '\k\.\k\{' . g:acp_behaviorPythonOmniLength . ',}$'
 endfunction
 
 "
-function acp#requireForXmlOmni(context)
+function acp#meetsForXmlOmni(context)
   return a:context =~ '\(<\|<\/\|<[^>]\+ \|<[^>]\+=\"\)\k\{' .
         \             g:acp_behaviorXmlOmniLength . ',}$'
 endfunction
 
 "
-function acp#requireForCssOmni(context)
+function acp#meetsForHtmlOmni(context)
+  return a:context =~ '\(<\|<\/\|<[^>]\+ \|<[^>]\+=\"\)\k\{' .
+        \             g:acp_behaviorHtmlOmniLength . ',}$'
+endfunction
+
+"
+function acp#meetsForCssOmni(context)
   if g:acp_behaviorCssOmniPropertyLength >= 0 &&
         \ a:context =~ '\(^\s\|[;{]\)\s*\k\{' .
         \              g:acp_behaviorCssOmniPropertyLength . ',}$'
 function acp#onBs()
   " using "matchstr" and not "strpart" in order to handle multi-byte
   " characters
-  if s:matchesBehavior(matchstr(s:getCurrentText(), '.*\ze.'),
-        \              s:behavsCurrent[0])
+  if call(s:behavsCurrent[0].meets, [matchstr(s:getCurrentText(), '.*\ze.')])
     return "\<BS>"
   endif
   return "\<C-e>\<BS>"
 endfunction
 
 "
-function s:matchesBehavior(text, behav)
-  return call(a:behav.require, [a:text])
-endfunction
-
-"
 function s:isCursorMovedSinceLastCall()
   if exists('s:posLast')
     let posPrev = s:posLast
   else
     unlet! s:lastUncompletableWord
     let text = s:getCurrentText()
-    call filter(s:behavsCurrent, 's:matchesBehavior(text, v:val)')
+    call filter(s:behavsCurrent, 'call(v:val.meets, [text])')
   endif
   if empty(s:behavsCurrent)
     call s:finishPopup(1)
                                         *g:acp_behaviorUserDefinedFunction*  >
   let g:acp_behaviorUserDefinedFunction = ''
 <
-        ユーザー定義補完の関数。空ならこの補完は行いません。
+        ユーザー定義補完の|g:acp_behavior-completefunc|。空ならこの補完は行わ
+        れません。。
 
-        See also:|complete-functions|
-
-                                         *g:acp_behaviorUserDefinedRequire*  >
-  let g:acp_behaviorUserDefinedRequire = ''
+                                         *g:acp_behaviorUserDefinedMeets*  >
+  let g:acp_behaviorUserDefinedMeets = ''
 <
-        TODO
+        ユーザー定義補完の|g:acp_behavior-meets|。空ならこの補完は行われません
+        。
 
                                              *g:acp_behaviorSnipmateLength*  >
   let g:acp_behaviorSnipmateLength = -1
   let g:acp_behaviorKeywordLength = 2
 <
         キーワード補完の自動ポップアップを行うのに必要なカーソルの直前のキーワ
-        ード文字数。負数ならこの補完は行いません。
+        ード文字数。負数ならこの補完は行われません。
+
+                                             *g:acp_behaviorKeywordIgnores*  >
+  let g:acp_behaviorKeywordIgnores = []
+<
+        文字列のリスト。カーソル直前の単語がこれらの内いずれかの先頭部分にマッ
+        チする場合、この補完は行われません。
+
+        例えば、 "get" で始まる補完キーワードが多過ぎて、"g", "ge", "get" を入
+        力したときの自動ポップアップがレスポンスの低下を引き起こしている場合、
+        このオプションに ["get"] を設定することでそれを回避することができます。
 
                                                  *g:acp_behaviorFileLength*  >
   let g:acp_behaviorFileLength = 0
 <
         ファイル名補完の自動ポップアップを行うのに必要なカーソルの直前のキーワ
-        ード文字数。負数ならこの補完は行ません。
+        ード文字数。負数ならこの補完は行われません。
 
                                        *g:acp_behaviorRubyOmniMethodLength*  >
   let g:acp_behaviorRubyOmniMethodLength = 0
 <
         メソッド補完のための、Ruby オムニ補完の自動ポップアップを行うのに必要
-        なカーソルの直前のキーワード文字数。負数ならこの補完は行ません。
+        なカーソルの直前のキーワード文字数。負数ならこの補完は行われません。
 
                                        *g:acp_behaviorRubyOmniSymbolLength*  >
   let g:acp_behaviorRubyOmniSymbolLength = 1
 <
         シンボル補完のための、Ruby オムニ補完の自動ポップアップを行うのに必要
-        なカーソルの直前のキーワード文字数。負数ならこの補完は行ません。
+        なカーソルの直前のキーワード文字数。負数ならこの補完は行われません。
 
                                            *g:acp_behaviorPythonOmniLength*  >
   let g:acp_behaviorPythonOmniLength = 0
 <
         Python オムニ補完の自動ポップアップを行うのに必要なカーソルの直前のキ
-        ーワード文字数。負数ならこの補完は行ません。
+        ーワード文字数。負数ならこの補完は行われません。
 
                                               *g:acp_behaviorXmlOmniLength*  >
   let g:acp_behaviorXmlOmniLength = 0
 <
         XML オムニ補完の自動ポップアップを行うのに必要なカーソルの直前のキーワ
-        ード文字数。負数ならこの補完は行ません。
+        ード文字数。負数ならこの補完は行われません。
 
                                              *g:acp_behaviorHtmlOmniLength*  >
   let g:acp_behaviorHtmlOmniLength = 0
 <
         HTML オムニ補完の自動ポップアップを行うのに必要なカーソルの直前のキー
-        ワード文字数。負数ならこの補完は行ません。
+        ワード文字数。負数ならこの補完は行われません。
 
                                       *g:acp_behaviorCssOmniPropertyLength*  >
   let g:acp_behaviorCssOmniPropertyLength = 1
 <
         プロパティ補完のための、CSS オムニ補完の自動ポップアップを行うのに必要
-        なカーソルの直前のキーワード文字数。負数ならこの補完は行ません。
+        なカーソルの直前のキーワード文字数。負数ならこの補完は行われません。
 
                                          *g:acp_behaviorCssOmniValueLength*  >
   let g:acp_behaviorCssOmniValueLength = 0
 <
         値補完のための、CSS オムニ補完の自動ポップアップを行うのに必要なカーソ
-        ルの直前のキーワード文字数。負数ならこの補完は行ません。
+        ルの直前のキーワード文字数。負数ならこの補完は行われません。
 
                                                            *g:acp_behavior*  >
   let g:acp_behavior = {}
         を表します。値はリスト型です。補完候補が得られるまでリストの先頭アイテ
         ムから順に評価します。各要素は|Dictionary|で詳細は次の通り:
 
-        "command":
+        "command":                                    *g:acp_behavior-command*
           補完メニューをポップアップするためのコマンド。
 
-        "completefunc":
+        "completefunc":                          *g:acp_behavior-completefunc*
           'completefunc' に設定する関数。 "command" が "<C-x><C-u>" のときだけ
           意味があります。
 
-        "require":
-          TODO
+        "meets":                                        *g:acp_behavior-meets*
+          この補完を行うかどうかを判断する関数の名前。この関数はカーソル直前の
+          テキストを引数に取り、補完を行うなら非 0 の値を返します。
 
-        "repeat":
+        "onPopupClose":                          *g:acp_behavior-onPopupClose*
+          この補完のポップアップメニューが閉じられたときに呼ばれる関数の名前。
+          この関数が 0 を返した場合、続いて行われる予定の補完は抑制されます。
+
+        "repeat":                                      *g:acp_behavior-repeat*
           真なら最後の補完が自動的に繰り返されます。
 
 
 Which completion method is used depends on the text before the cursor. The
 default behavior is as follows:
 
-        kind      filetype    text before a cursor ~
+        kind      filetype    text before the cursor ~
         Keyword   *           two keyword characters
         Filename  *           a filename character + a path separator 
                               + 0 or more filename character
                                         *g:acp_behaviorUserDefinedFunction*  >
   let g:acp_behaviorUserDefinedFunction = ''
 <
-        Function for user-defined completion. If empty, this completion will
-        be never attempted.
+        |g:acp_behavior-completefunc| for user-defined completion. If empty,
+        this completion will be never attempted.
 
-        See also:|complete-functions|
-
-                                         *g:acp_behaviorUserDefinedRequire*  >
-  let g:acp_behaviorUserDefinedRequire = ''
+                                           *g:acp_behaviorUserDefinedMeets*  >
+  let g:acp_behaviorUserDefinedMeets = ''
 <
-        TODO
+        |g:acp_behavior-meets| for user-defined completion. If empty, this
+        completion will be never attempted.
 
                                              *g:acp_behaviorSnipmateLength*  >
   let g:acp_behaviorSnipmateLength = -1
 <
-        Pattern before a cursor, which are needed to attempt snipMate-trigger
-        completion.
+        Pattern before the cursor, which are needed to attempt
+        snipMate-trigger completion.
 
                                              *g:acp_behaviorKeywordCommand*  >
   let g:acp_behaviorKeywordCommand = "\<C-n>"
                                               *g:acp_behaviorKeywordLength*  >
   let g:acp_behaviorKeywordLength = 2
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt keyword completion. If negative value, this completion will be
         never attempted.
 
+                                             *g:acp_behaviorKeywordIgnores*  >
+  let g:acp_behaviorKeywordIgnores = []
+<
+        List of string. If a word before the cursor matches to the front part
+        of one of them, keyword completion won't be attempted.
+
+        E.g., when there are too many keywords beginning with "get" for the
+        completion and auto-popup by entering "g", "ge", or "get" causes
+        response degradation, set ["get"] to this option and avoid it.
+
                                                  *g:acp_behaviorFileLength*  >
   let g:acp_behaviorFileLength = 0
 <
-        Length of filename characters before a cursor, which are needed to
+        Length of filename characters before the cursor, which are needed to
         attempt filename completion. If negative value, this completion will
         be never attempted.
 
                                        *g:acp_behaviorRubyOmniMethodLength*  >
   let g:acp_behaviorRubyOmniMethodLength = 0
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt ruby omni-completion for methods. If negative value, this
         completion will be never attempted.
 
                                        *g:acp_behaviorRubyOmniSymbolLength*  >
   let g:acp_behaviorRubyOmniSymbolLength = 1
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt ruby omni-completion for symbols. If negative value, this
         completion will be never attempted.
 
                                            *g:acp_behaviorPythonOmniLength*  >
   let g:acp_behaviorPythonOmniLength = 0
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt python omni-completion. If negative value, this completion
         will be never attempted.
 
                                               *g:acp_behaviorXmlOmniLength*  >
   let g:acp_behaviorXmlOmniLength = 0
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt XML omni-completion. If negative value, this completion will
         be never attempted.
 
                                              *g:acp_behaviorHtmlOmniLength*  >
   let g:acp_behaviorHtmlOmniLength = 0
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt HTML omni-completion. If negative value, this completion will
         be never attempted.
 
                                       *g:acp_behaviorCssOmniPropertyLength*  >
   let g:acp_behaviorCssOmniPropertyLength = 1
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt CSS omni-completion for properties. If negative value, this
         completion will be never attempted.
 
                                          *g:acp_behaviorCssOmniValueLength*  >
   let g:acp_behaviorCssOmniValueLength = 0
 <
-        Length of keyword characters before a cursor, which are needed to
+        Length of keyword characters before the cursor, which are needed to
         attempt CSS omni-completion for values. If negative value, this
         completion will be never attempted.
 
         sequence until completion item is found. Each element is a
         |Dictionary| which has following items:
 
-        "command":
+        "command":                                    *g:acp_behavior-command*
           Command to be fed to open popup menu for completions.
 
-        "completefunc":
+        "completefunc":                          *g:acp_behavior-completefunc*
           'completefunc' will be set to this user-provided function during the
           completion. Only makes sense when "command" is "<C-x><C-u>".
 
-        "require":
-          TODO
+        "meets":                                        *g:acp_behavior-meets*
+          Name of the function which dicides whether or not to attempt this
+          completion. It will be attempted if this function returns non-zero.
+          This function takes a text before the cursor.
 
-        "repeat":
+        "onPopupClose":                          *g:acp_behavior-onPopupClose*
+          Name of the function which is called when popup menu for this
+          completion is closed. Following completions will be suppressed if
+          this function returns zero.
+
+        "repeat":                                      *g:acp_behavior-repeat*
           If non-zero, the last completion is automatically repeated.
 
 
 ==============================================================================
 CHANGELOG                                                      *acp-changelog*
 
-2.11.2
-  - Fixed a bug that keyword completion was never attempted when
-    no candidate for snipMate's trigger completion was found.
+2.12
+  - Added g:acp_behaviorKeywordIgnores option.
+  - Added g:acp_behaviorUserDefinedMeets option and removed
+    g:acp_behaviorUserDefinedPattern.
+  - Changed the structure of g:acp_behavior option.
+  - Changed to reflect a change of behavior options (named g:acp_behavior*)
+    any time it is done.
+  - Fixed a bug that completions after snipMate's trigger completion were
+    never attempted when no candidate for snipMate's trigger completion was
+    found.
 
 2.11.1
   - Fixed a bug that a snipMate's trigger could not be expanded when it was

File plugin/acp.vim

         \ }
   "---------------------------------------------------------------------------
   if !empty(g:acp_behaviorUserDefinedFunction) &&
-        \ !empty(g:acp_behaviorUserDefinedRequire)
+        \ !empty(g:acp_behaviorUserDefinedMeets)
     for key in keys(behavs)
       call add(behavs[key], {
             \   'command'      : "\<C-x>\<C-u>",
             \   'completefunc' : g:acp_behaviorUserDefinedFunction,
-            \   'require'      : g:acp_behaviorUserDefinedRequire,
+            \   'meets'        : g:acp_behaviorUserDefinedMeets,
             \   'repeat'       : 0,
             \ })
     endfor
     call add(behavs[key], {
           \   'command'      : "\<C-x>\<C-u>",
           \   'completefunc' : 'acp#completeSnipmate',
-          \   'require'      : "acp#requireForSnipmate",
+          \   'meets'        : 'acp#meetsForSnipmate',
+          \   'onPopupClose' : 'acp#onPopupCloseSnipmate',
           \   'repeat'       : 0,
-          \   'onPopupClose' : 'acp#onPopupCloseSnipmate'
           \ })
   endfor
   "---------------------------------------------------------------------------
   for key in keys(behavs)
     call add(behavs[key], {
           \   'command' : g:acp_behaviorKeywordCommand,
-          \   'require' : "acp#requireForKeyword",
+          \   'meets'   : 'acp#meetsForKeyword',
           \   'repeat'  : 0,
           \ })
   endfor
   for key in keys(behavs)
     call add(behavs[key], {
           \   'command' : "\<C-x>\<C-f>",
-          \   'require' : "acp#requireForFile",
+          \   'meets'   : 'acp#meetsForFile',
           \   'repeat'  : 1,
           \ })
   endfor
   "---------------------------------------------------------------------------
   call add(behavs.ruby, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForRubyOmni",
+        \   'meets'   : 'acp#meetsForRubyOmni',
         \   'repeat'  : 0,
         \ })
   "---------------------------------------------------------------------------
   call add(behavs.ruby, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForRubyOmni",
+        \   'meets'   : 'acp#meetsForRubyOmni',
         \   'repeat'  : 0,
         \ })
   "---------------------------------------------------------------------------
   call add(behavs.python, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForPythonOmni",
+        \   'meets'   : 'acp#meetsForPythonOmni',
         \   'repeat'  : 0,
         \ })
   "---------------------------------------------------------------------------
   call add(behavs.xml, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForXmlOmni",
+        \   'meets'   : 'acp#meetsForXmlOmni',
         \   'repeat'  : 1,
         \ })
   "---------------------------------------------------------------------------
   call add(behavs.html, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForXmlOmni",
+        \   'meets'   : 'acp#meetsForHtmlOmni',
         \   'repeat'  : 1,
         \ })
   "---------------------------------------------------------------------------
   call add(behavs.xhtml, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForXmlOmni",
+        \   'meets'   : 'acp#meetsForHtmlOmni',
         \   'repeat'  : 1,
         \ })
   "---------------------------------------------------------------------------
   call add(behavs.css, {
         \   'command' : "\<C-x>\<C-o>",
-        \   'require' : "acp#requireForCssOmni",
+        \   'meets'   : 'acp#meetsForCssOmni',
         \   'repeat'  : 0,
         \ })
   "---------------------------------------------------------------------------
 call s:defineOption('g:acp_completeOption', '.,w,b,k')
 call s:defineOption('g:acp_completeoptPreview', 0)
 call s:defineOption('g:acp_behaviorUserDefinedFunction', '')
-call s:defineOption('g:acp_behaviorUserDefinedRequire', '')
+call s:defineOption('g:acp_behaviorUserDefinedMeets', '')
 call s:defineOption('g:acp_behaviorSnipmateLength', -1)
 call s:defineOption('g:acp_behaviorKeywordCommand', "\<C-n>")
 call s:defineOption('g:acp_behaviorKeywordLength', 2)
+call s:defineOption('g:acp_behaviorKeywordIgnores', [])
 call s:defineOption('g:acp_behaviorFileLength', 0)
 call s:defineOption('g:acp_behaviorRubyOmniMethodLength', 0)
 call s:defineOption('g:acp_behaviorRubyOmniSymbolLength', 1)