- Timestamp:
- 02/12/08 01:44:48 (10 months ago)
- Location:
- lang/vim/ku/trunk
- Files:
-
- 2 modified
-
autoload/ku.vim (modified) (21 diffs)
-
doc/ku.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/vim/ku/trunk/autoload/ku.vim
r6400 r6579 4 4 " License: MIT license (see <http://www.opensource.org/licenses/mit-license>) 5 5 " $Id$ "{{{1 6 " FIXME: auto-complete 1 component for each typing '/' (like bluewind).7 6 " FIXME: s:do(): Force action on unmatched pattern. 8 7 " FIXME: more smart sorting: … … 24 23 let s:TYPE_DICTONARY = type({}) 25 24 25 " Key sequence to start (omni) completion 26 " without auto-selecting the first match. 27 let 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. 32 let s:PROMPT = '>' 33 34 35 " Flag to avoid infinite loop by auto-directory-insertion. 36 let s:auto_directory_insertion_done_p = s:FALSE 26 37 27 38 " Flag which indicates whether the ku window is opened with bang (:Ku!). … … 32 43 let s:INVALID_BUFNR = -3339 33 44 " to be reloadable (for debugging) 34 if exists('s:bufnr') && s:bufnr != s:INVALID_BUFNR 45 if exists('s:bufnr') && s:bufnr != s:INVALID_BUFNR && bufexists(s:bufnr) 35 46 execute s:bufnr 'bwipeout' 36 47 endif 37 48 let s:bufnr = s:INVALID_BUFNR 38 49 50 " Fallback actions for all types. 51 if !exists('s:fallback_actions') 52 let s:fallback_actions = {} 53 endif 54 55 " The last column of the cursor. 56 let s:INVALID_COL = -3338 57 let s:last_col = s:INVALID_COL 58 59 " Items gathered by the last completion. 60 let s:last_items = [] 61 39 62 " Preferred type of items. 40 63 let s:INVALID_TYPE = '*all*' 41 64 let s:preferred_type = s:INVALID_TYPE 42 43 " Key sequence to start (omni) completion44 " 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 = -333849 let s:last_col = s:INVALID_COL50 51 " Items gathered by the last completion.52 let s:last_items = []53 65 54 66 " All available types. … … 57 69 endif 58 70 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 64 71 " Misc. values to restore the original state. 65 72 let s:completeopt = '' 66 73 let s:ignorecase = '' 67 74 let s:winrestcmd = '' 68 69 " Flag to avoid infinite loop by auto-directory-insertion.70 let s:auto_directory_insertion_done_p = s:FALSE71 75 72 76 … … 108 112 set ignorecase 109 113 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 110 119 111 120 " Open a new window and switch to the ku buffer. … … 119 128 2 wincmd _ 120 129 121 " Do some initialization for each type .130 " Do some initialization for each type -- after opening the ku buffer. 122 131 for type_name in keys(s:types) 123 call s:types[type_name].initialize( )132 call s:types[type_name].initialize('after-open') 124 133 endfor 125 134 … … 174 183 function! ku#custom_key(type_name, key, new_action_name) "{{{2 175 184 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) 177 186 return '' 178 187 endif … … 187 196 188 197 function! 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) 190 199 return s:FALSE 191 200 endif 192 201 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 194 209 return s:TRUE 195 210 endfunction … … 301 316 \ = (a:choose_p 302 317 \ ? 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*'])) 304 319 call s:apply(ActionFunction, [item]) 305 320 endif … … 624 639 625 640 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 629 644 endif 630 645 endif … … 728 743 endfor 729 744 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) 731 746 return s:FALSE 732 747 endif … … 737 752 738 753 return s:TRUE 754 endfunction 755 756 757 758 759 function! s:type_has_action_p(type, action_name) "{{{2 760 return s:callable_p(s:type_action(a:type, a:action_name)) 761 endfunction 762 763 764 765 766 function! 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) 739 772 endfunction 740 773 … … 799 832 call feedkeys("\<C-b>", 'n') 800 833 endfunction 834 call ku#custom_action('*fallback*', 'ex', function('s:_type_any_action_ex')) 801 835 802 836 … … 812 846 endif 813 847 endfunction 848 call ku#custom_action('*fallback*', 'cd', s:pa('s:_type_any_action_xcd', 'cd')) 849 call ku#custom_action('*fallback*', 'cd-local', 850 \ s:pa('s:_type_any_action_xcd', 'lcd')) 814 851 815 852 … … 910 947 \ 'split-far-right': 911 948 \ 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'),918 949 \ 'unload': 919 950 \ s:pa('s:_type_buffer_action_xdelete', 'bunload'), … … 929 960 930 961 " 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? 967 let s:_type_file_cache = {} 936 968 937 969 function! s:_type_file_gather(pattern) … … 942 974 let base_directory = a:pattern[:last_slash] 943 975 let last_component = a:pattern[last_slash+1:] 944 let cache_key = base_directory976 let cache_key = fnamemodify(base_directory, ':p') 945 977 else 946 978 let base_directory = '' 947 979 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') 949 981 endif 950 982 951 983 if !has_key(s:_type_file_cache, cache_key) 984 \ || getftime(cache_key) != s:_type_file_cache[cache_key][0] 952 985 let items = [] 953 986 for f in ['*', '.[^.]*'] … … 956 989 endfor 957 990 endfor 958 let s:_type_file_cache[cache_key] = items959 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] 961 994 endfunction 962 995 … … 973 1006 call ku#register_type({ 974 1007 \ 'name': 'file', 975 \ 'initialize': function('s:_type_file_initialize'),976 1008 \ 'gather': function('s:_type_file_gather'), 977 1009 \ 'keys': { … … 1025 1057 \ 'split-far-right': 1026 1058 \ 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'),1033 1059 \ }, 1034 1060 \ }) … … 1041 1067 1042 1068 1043 " __END__ "{{{1 1069 " Fin. "{{{1 1070 1071 silent doautocmd User KuLoaded 1072 1073 1074 1075 1076 1077 1078 1079 1080 " __END__ 1044 1081 " vim: foldmethod=marker -
lang/vim/ku/trunk/doc/ku.txt
r6400 r6579 64 64 65 65 ku#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. 68 70 69 71 Modes {lhs} {rhs} ~ … … 96 98 for items of the type {type-name}. 97 99 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 98 106 ku#custom_key({type-name}, {key}, {new-action-name}) *ku#custom_key()* 99 107 Define {key} to do the action {new-action-name} for … … 160 168 161 169 Initialization *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. 162 175 *KuBufferInitialize* 163 176 Ku has its own buffer to do its work. Whenever the buffer is created, … … 168 181 < 169 182 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|. 171 186 172 187 Write New Type *ku-write-new-type* … … 184 199 185 200 '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'. 189 210 190 211 'keys' dictionary
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)