Changeset 6579 for lang/vim/ku/trunk

Show
Ignore:
Timestamp:
02/12/08 01:44:48 (6 years ago)
Author:
kana
Message:

lang/vim/ku:
* Sync with my local repository (from 2008-02-11T14:51:28+0900 to

2008-02-12T01:43:48+09:00).

Location:
lang/vim/ku/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/vim/ku/trunk/autoload/ku.vim

    r6400 r6579  
    44" License: MIT license (see <http://www.opensource.org/licenses/mit-license>) 
    55" $Id$  "{{{1 
    6 " FIXME: auto-complete 1 component for each typing '/' (like bluewind). 
    76" FIXME: s:do(): Force action on unmatched pattern. 
    87" FIXME: more smart sorting: 
     
    2423let s:TYPE_DICTONARY = type({}) 
    2524 
     25" Key sequence to start (omni) completion 
     26" without auto-selecting the first match. 
     27let s:KEYS_TO_START_COMPLETION = "\<C-x>\<C-o>\<C-p>" 
     28 
     29" The prompt for user input. 
     30" This is necessary to publish CursorMovedI event for each typing. 
     31" Note that the length should be 1 to avoid some problems. 
     32let s:PROMPT = '>' 
     33 
     34 
     35" Flag to avoid infinite loop by auto-directory-insertion. 
     36let s:auto_directory_insertion_done_p = s:FALSE 
    2637 
    2738" Flag which indicates whether the ku window is opened with bang (:Ku!). 
     
    3243let s:INVALID_BUFNR = -3339 
    3344  " to be reloadable (for debugging) 
    34 if exists('s:bufnr') && s:bufnr != s:INVALID_BUFNR 
     45if exists('s:bufnr') && s:bufnr != s:INVALID_BUFNR && bufexists(s:bufnr) 
    3546  execute s:bufnr 'bwipeout' 
    3647endif 
    3748let s:bufnr = s:INVALID_BUFNR 
    3849 
     50" Fallback actions for all types. 
     51if !exists('s:fallback_actions') 
     52  let s:fallback_actions = {} 
     53endif 
     54 
     55" The last column of the cursor. 
     56let s:INVALID_COL = -3338 
     57let s:last_col = s:INVALID_COL 
     58 
     59" Items gathered by the last completion. 
     60let s:last_items = [] 
     61 
    3962" Preferred type of items. 
    4063let s:INVALID_TYPE = '*all*' 
    4164let s:preferred_type = s:INVALID_TYPE 
    42  
    43 " Key sequence to start (omni) completion 
    44 " without auto-selecting the first match. 
    45 let s:KEYS_TO_START_COMPLETION = "\<C-x>\<C-o>\<C-p>" 
    46  
    47 " The last column of the cursor. 
    48 let s:INVALID_COL = -3338 
    49 let s:last_col = s:INVALID_COL 
    50  
    51 " Items gathered by the last completion. 
    52 let s:last_items = [] 
    5365 
    5466" All available types. 
     
    5769endif 
    5870 
    59 " The prompt for user input. 
    60 " This is necessary to publish CursorMovedI event for each typing. 
    61 " Note that the length should be 1 to avoid some problems. 
    62 let s:PROMPT = '>' 
    63  
    6471" Misc. values to restore the original state. 
    6572let s:completeopt = '' 
    6673let s:ignorecase = '' 
    6774let s:winrestcmd = '' 
    68  
    69 " Flag to avoid infinite loop by auto-directory-insertion. 
    70 let s:auto_directory_insertion_done_p = s:FALSE 
    7175 
    7276 
     
    108112  set ignorecase 
    109113  let s:winrestcmd = winrestcmd() 
     114 
     115  " Do some initialization for each type -- before opening the ku buffer. 
     116  for type_name in keys(s:types) 
     117    call s:types[type_name].initialize('before-open') 
     118  endfor 
    110119 
    111120  " Open a new window and switch to the ku buffer. 
     
    119128  2 wincmd _ 
    120129 
    121   " Do some initialization for each type. 
     130  " Do some initialization for each type -- after opening the ku buffer. 
    122131  for type_name in keys(s:types) 
    123     call s:types[type_name].initialize() 
     132    call s:types[type_name].initialize('after-open') 
    124133  endfor 
    125134 
     
    174183function! ku#custom_key(type_name, key, new_action_name)  "{{{2 
    175184  if !s:valid_type_name_p(a:type_name) 
    176    \ || !has_key(s:types[a:type_name].actions, a:new_action_name) 
     185   \ || !s:type_has_action_p(s:types[a:type_name], a:new_action_name) 
    177186    return '' 
    178187  endif 
     
    187196 
    188197function! ku#custom_action(type_name, action_name, new_action_function)  "{{{2 
    189   if !s:valid_type_name_p(a:type_name) || !s:callable_p(a:new_action_function) 
     198  if !s:callable_p(a:new_action_function) 
    190199    return s:FALSE 
    191200  endif 
    192201 
    193   let s:types[a:type_name].actions[a:action_name] = a:new_action_function 
     202  if a:type_name ==# '*fallback*' 
     203    let s:fallback_actions[a:action_name] = a:new_action_function 
     204  elseif s:valid_type_name_p(a:type_name) 
     205    let s:types[a:type_name].actions[a:action_name] = a:new_action_function 
     206  else 
     207    return s:TRUE 
     208  endif 
    194209  return s:TRUE 
    195210endfunction 
     
    301316      \ = (a:choose_p 
    302317      \    ? s:choose_action_for_item(item) 
    303       \    : item._ku_type.actions[item._ku_type.keys['*default*']]) 
     318      \    : s:type_action(item._ku_type, item._ku_type.keys['*default*'])) 
    304319    call s:apply(ActionFunction, [item]) 
    305320  endif 
     
    624639 
    625640  if has_key(a:item._ku_type.keys, c) 
    626     let name = a:item._ku_type.keys[c] 
    627     if has_key(a:item._ku_type.actions, name) 
    628       return a:item._ku_type.actions[name] 
     641    let Action = s:type_action(a:item._ku_type, a:item._ku_type.keys[c]) 
     642    if s:callable_p(Action) 
     643      return Action 
    629644    endif 
    630645  endif 
     
    728743  endfor 
    729744  for n in values(a:args.keys) 
    730     if !has_key(a:args.actions, n) 
     745    if !s:type_has_action_p(a:args, n) 
    731746      return s:FALSE 
    732747    endif 
     
    737752 
    738753  return s:TRUE 
     754endfunction 
     755 
     756 
     757 
     758 
     759function! s:type_has_action_p(type, action_name)  "{{{2 
     760  return s:callable_p(s:type_action(a:type, a:action_name)) 
     761endfunction 
     762 
     763 
     764 
     765 
     766function! s:type_action(type, action_name)  "{{{2 
     767  let Action = get(a:type.actions, a:action_name, 0) 
     768  if s:callable_p(Action) 
     769    return Action 
     770  endif 
     771  return get(s:fallback_actions, a:action_name, 0) 
    739772endfunction 
    740773 
     
    799832  call feedkeys("\<C-b>", 'n') 
    800833endfunction 
     834call ku#custom_action('*fallback*', 'ex', function('s:_type_any_action_ex')) 
    801835 
    802836 
     
    812846  endif 
    813847endfunction 
     848call ku#custom_action('*fallback*', 'cd', s:pa('s:_type_any_action_xcd', 'cd')) 
     849call ku#custom_action('*fallback*', 'cd-local', 
     850   \                  s:pa('s:_type_any_action_xcd', 'lcd')) 
    814851 
    815852 
     
    910947   \     'split-far-right': 
    911948   \       s:pa('s:_type_buffer_action_xsplit', 'vertical botright'), 
    912    \     'ex': 
    913    \       function('s:_type_any_action_ex'), 
    914    \     'cd': 
    915    \       s:pa('s:_type_any_action_xcd', 'cd'), 
    916    \     'cd-local': 
    917    \       s:pa('s:_type_any_action_xcd', 'lcd'), 
    918949   \     'unload': 
    919950   \       s:pa('s:_type_buffer_action_xdelete', 'bunload'), 
     
    929960 
    930961" file  "{{{2 
    931 " FIXME: smart caching. 
    932 function! s:_type_file_initialize() 
    933   let s:_type_file_cache = {} 
    934   let s:_type_file_frags_count = -1 
    935 endfunction 
     962" Note: Timestamps of directories will be updated when files/directories are 
     963" created or removed. 
     964  " key = full path of the directory 
     965  " value = [time stamp of the directory, list of items in the directory] 
     966  " FIXME: how about when the cache becames too large? 
     967let s:_type_file_cache = {} 
    936968 
    937969function! s:_type_file_gather(pattern) 
     
    942974    let base_directory = a:pattern[:last_slash] 
    943975    let last_component = a:pattern[last_slash+1:] 
    944     let cache_key = base_directory 
     976    let cache_key = fnamemodify(base_directory, ':p') 
    945977  else 
    946978    let base_directory = '' 
    947979    let last_component = a:pattern 
    948     let cache_key = ' '  " can't use empty string as a key of dictionaries. 
     980    let cache_key = fnamemodify('.', ':p') 
    949981  endif 
    950982 
    951983  if !has_key(s:_type_file_cache, cache_key) 
     984   \ || getftime(cache_key) != s:_type_file_cache[cache_key][0] 
    952985    let items = [] 
    953986    for f in ['*', '.[^.]*'] 
     
    956989      endfor 
    957990    endfor 
    958     let s:_type_file_cache[cache_key] = items 
    959   endif 
    960   return s:_type_file_cache[cache_key] 
     991    let s:_type_file_cache[cache_key] = [getftime(cache_key), items] 
     992  endif 
     993  return s:_type_file_cache[cache_key][1] 
    961994endfunction 
    962995 
     
    9731006call ku#register_type({ 
    9741007   \   'name': 'file', 
    975    \   'initialize': function('s:_type_file_initialize'), 
    9761008   \   'gather': function('s:_type_file_gather'), 
    9771009   \   'keys': { 
     
    10251057   \     'split-far-right': 
    10261058   \       s:pa('s:_type_file_action_xsplit', 'vertical botright'), 
    1027    \     'ex': 
    1028    \       function('s:_type_any_action_ex'), 
    1029    \     'cd': 
    1030    \       s:pa('s:_type_any_action_xcd', 'cd'), 
    1031    \     'cd-local': 
    1032    \       s:pa('s:_type_any_action_xcd', 'lcd'), 
    10331059   \   }, 
    10341060   \ }) 
     
    10411067 
    10421068 
    1043 " __END__  "{{{1 
     1069" Fin.  "{{{1 
     1070 
     1071silent doautocmd User KuLoaded 
     1072 
     1073 
     1074 
     1075 
     1076 
     1077 
     1078 
     1079 
     1080" __END__ 
    10441081" vim: foldmethod=marker 
  • lang/vim/ku/trunk/doc/ku.txt

    r6400 r6579  
    6464 
    6565ku#default_key_mappings()                          *ku#default_key_mappings()* 
    66                         Define the following key mappings for the ku window 
    67                         to the current buffer. 
     66                        Define the following key mappings which are local to 
     67                        the current buffer.  If one of the following {lhs}s is 
     68                        already mapped to something, it will be overridden. 
     69                        Be careful about when to call this function. 
    6870 
    6971                        Modes   {lhs}           {rhs} ~ 
     
    9698                        for items of the type {type-name}. 
    9799 
     100                        {type-name} may be '*fallback*', if so, the given 
     101                        action is defined as a fallback action for all types. 
     102                        This means that the fallback action {action-name} will 
     103                        be used if the action {action-name} is not defined for 
     104                        a type, 
     105 
    98106ku#custom_key({type-name}, {key}, {new-action-name})    *ku#custom_key()* 
    99107                        Define {key} to do the action {new-action-name} for 
     
    160168 
    161169Initialization                                          *ku-initialization* 
     170                                                        *KuLoaded* 
     171        Most part of Ku isn't loaded until one of its functions or commands is 
     172        actually used.  After all part of Ku is loaded, "User KuLoaded" event 
     173        will be published.  Use this event to delay applying user's settings 
     174        until all part of Ku is loaded. 
    162175                                                        *KuBufferInitialize* 
    163176        Ku has its own buffer to do its work.  Whenever the buffer is created, 
     
    168181< 
    169182        If there is no autocommand for |KuBufferInitialize|, Ku will call 
    170         |ku#default_key_mappings()|. 
     183        |ku#default_key_mappings()| to define some useful key mappings. 
     184        Otherwise, no key mapping will be defined.  So you have to call it 
     185        explicitly if you use |KuBufferInitialize|. 
    171186 
    172187Write New Type                                          *ku-write-new-type* 
     
    184199 
    185200        'initialize'    funcref         (optional) 
    186                 The function which will be called with no argument whenever 
    187                 the ku window is opened.  The main purpose of this function is 
    188                 to do some initialization for 'gather'. 
     201                The function which will be called whenever the ku window is 
     202                opened.  It's called with 1 argument which indicates the 
     203                timing of calling.  The possible values are: 
     204 
     205                'before-open'   before opening the |ku-buffer| 
     206                'after-open'    after opening the |ku-buffer| 
     207 
     208                The main purpose of this function is to do some initialization 
     209                for 'gather'. 
    189210 
    190211        'keys'          dictionary