Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to configure where Alternate file looks? #146

Closed
rsanheim opened this issue Mar 12, 2012 · 5 comments
Closed

Any way to configure where Alternate file looks? #146

rsanheim opened this issue Mar 12, 2012 · 5 comments

Comments

@rsanheim
Copy link

I have projects where I have a fast_spec/ directory in addition to spec/ -- is there a way to have Alternate file look in fast_spec first for alternate files? I didn't see anywhere to easily configure how it searches through unit, spec, etc, but my vimscript knowledge is poor.

@tpope
Copy link
Owner

tpope commented Mar 12, 2012

I wouldn't call it easy, but you can set b:rails_alternate from a rails.vim autocommand (:help rails-autocommands) to an arbitrary file and :A will respect it. Completely untested:

autocmd User Rails/app/**/*.rb let b:rails_alternate = 'fast_spec/' . rails#buffer().name()[4:-4] . '_spec.rb'

That's an all-or-nothing example; if you want it to fall back to the default, you'll want a filereadable() check in there. I'll leave that as an exercise to the reader.

@tpope tpope closed this as completed Mar 12, 2012
@henrik
Copy link
Contributor

henrik commented Jan 12, 2013

Nice. Just did this:

" lib/foo.rb -> unit/lib/foo_spec.rb
autocmd User Rails/lib/* let b:rails_alternate = 'unit/' . rails#buffer().name()[0:-4] . '_spec.rb'
" unit/lib/foo_spec.rb -> lib/foo.rb
autocmd User Rails/unit/lib/* let b:rails_alternate = rails#buffer().name()[5:-9] . '.rb'

@henrik
Copy link
Contributor

henrik commented Jan 12, 2013

Here is an example of filereadable fallbacks:

" :A on engines/foo/bar.rb -> {spec,unit}/engines/foo/bar_spec.rb
autocmd User Rails/engines/* let common = rails#buffer().name()[0:-4].'_spec.rb' | let spec = 'spec/'.common | let unit = 'unit/'.common | let b:rails_alternate = filereadable(spec) ? spec : unit

@tpope
Copy link
Owner

tpope commented Feb 14, 2013

The recently added "classifications" feature provides a more declarative way to do this at the same time as creating a navigation command.

@henrik
Copy link
Contributor

henrik commented Feb 14, 2013

Oh yes, someone pointed me to that. Haven't tried yet but probably will. Thanks!

Lavinia pushed a commit to Lavinia/dotfiles that referenced this issue Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants