Skip to content

Commit

Permalink
add basic support for per-filetype config
Browse files Browse the repository at this point in the history
  • Loading branch information
kljohann committed Apr 1, 2013
1 parent 1df2811 commit ef64a2d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions autoload/expand_region.vim
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ function! s:get_candidate_dict(text_object)
endfunction


" Return dictionary of text objects that are to be used for the current
" filetype. Filetype-specific dictionaries will be loaded if they exist
" and the global dictionary will be used as a fallback.
function! s:get_configuration()
let configuration = {}
for ft in split(&ft, '\.')
if exists("g:expand_region_text_objects_".ft)
call extend(configuration, g:expand_region_text_objects_{ft})
endif
endfor

if empty(configuration)
call extend(configuration, g:expand_region_text_objects)
endif

return configuration
endfunction

" Return list of candidate dictionary. Each dictionary contains the following:
" text_object: The actual text object string
" start_pos: The result of getpos() on the starting position of the text object
Expand All @@ -131,16 +149,18 @@ function! s:get_candidate_list()
let save_wrapscan = &wrapscan
set nowrapscan

let config = s:get_configuration()

" Generate the candidate list for every defined text object
let candidates = keys(g:expand_region_text_objects)
let candidates = keys(config)
call map(candidates, "s:get_candidate_dict(v:val)")

" For the ones that are recursive, generate them until they no longer match
" any region
let recursive_candidates = []
for i in candidates
" Continue if not recursive
if !g:expand_region_text_objects[i.text_object]
if !config[i.text_object]
continue
endif
" If the first level is already empty, no point in going any further
Expand Down

0 comments on commit ef64a2d

Please sign in to comment.