Closed kljohann closed 11 years ago
Thanks! Per filetype configuration is definitely a feature that's needed. I prefer the user configuration to be as lean as possible. I think the following makes sense:
I think for 3, we could just add another global method expand_region#custom_text_objects(filetype, dict). This way, the user could easily extend it for ruby for example by calling the following in their vimrc
call expand_region#custom_text_objects('ruby', { ... })
I think in many cases it would be preferable for per-filetype configuration to overwrite global default configuration instead of extending it (same example as above: use ab
instead of ib
for lisp). See the attached pull request for what I had in mind.
It now tries to read the configuration from g:expand_region_text_objects_ruby
etc. and falls back to use g:expand_region_text_objects
as a default if no per-filetype configuration was found.
A possible definition of a custom_text_objects
like you described above could then be:
function! expand_region#custom_text_objects(...)
if a:0 == 1
call extend(g:expand_region_text_objects, a:1)
elseif a:0 == 2
if !exists("g:expand_region_text_objects_".a:1)
let g:expand_region_text_objects_{a:1} = {}
call extend(g:expand_region_text_objects_{a:1}, g:expand_region_text_objects)
endif
call extend(g:expand_region_text_objects_{a:1}, a:2)
endif
endfunction
Thanks for adding this! I like your idea of modifying the custom_text_objects method as well. The combination of the two give users enough flexibility to define per filetype config however they want. Could you make the other change as well and perhaps update the documentation?
I made the change and updated the doc, thanks for the suggestion!
Hey, thanks for porting this over to vim. I have been using expand-region.el with evil and have been waiting for someone to do a vim port. I particularly like how you reused text objects! Sometimes it would be nice to have per-filetype configuration (f.ex. indentation based text objects in python,
ap
instead ofip
in clojure/lisp). I see two approaches: • Allow the configuraion to be shadowed by a buffer-local variable (that may be set in anautocmd FileType …
) • Implement some white-/blacklisting/dictionary magic I think I prefer the first approach. If you tell me your opinion I will work on a patch.