Skip to content

Commit

Permalink
Exclude eruby.yaml from plugin initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Aug 16, 2020
1 parent 0b8e45e commit f224431
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ If you set it to an empty list, `[]`, the plugin will not be automatically insta

### `g:tagalong_additional_filetypes`

Example usage:

``` vim
let g:tagalong_additional_filetypes = ['custom', 'another']
```
Expand All @@ -112,6 +114,22 @@ The plugin should work with any HTML-like tags, so if a compatible filetype is m

Ideally, the above setting would just hold all sensible filetypes, so consider opening a github issue to suggest one that you feel is missing. As long as it's not something too custom, I would likely be okay with adding it to the built-in list.

### `g:tagalong_excluded_filetype_combinations`

Example usage:

``` vim
let g:tagalong_excluded_filetype_combinations = ['custom.html']
```

Default value: `['eruby.yaml']`

This setting allows the exclusion of particular filetype dot-combinations from initialization. The "filetypes" setting includes single filetypes, so any combination of them including, for instance, "html" would activate the plugin. So you could set custom filetypes like "html.rails" or something and it would still work.

That said, there are combinations that are not HTML-like. The current default value of the setting, "eruby.yaml" is a good example -- it's being set by vim-rails, but there's no HTML to edit in there.

It's recommended to leave this setting untouched, but you could use it as an escape hatch. If you have any problems with a particular filetype that are solved by an entry in this setting, consider opening an issue to make a change to the defaults.

### `g:tagalong_mappings`

Example usage:
Expand Down
21 changes: 21 additions & 0 deletions doc/tagalong.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ opening a github issue to suggest one that you feel is missing. As long as
it's not something too custom, I would likely be okay with adding it to the
built-in list.

*g:tagalong_excluded_filetype_combinations*
>
let g:tagalong_excluded_filetype_combinations = ['custom.html']
<
Default value: ['eruby.yaml']

This setting allows the exclusion of particular filetype dot-combinations from
initialization. The "filetypes" setting includes single filetypes, so any
combination of them including, for instance, "html" would activate the plugin.
So you could set custom filetypes like "html.rails" or something and it would
still work.

That said, there are combinations that are not HTML-like. The current default
value of the setting, "eruby.yaml" is a good example -- it's being set by
vim-rails, but there's no HTML to edit in there.

It's recommended to leave this setting untouched, but you could use it as an
escape hatch. If you have any problems with a particular filetype that are solved
by an entry in this setting, consider opening an issue to make a change to the
defaults.

*g:tagalong_mappings*
>
let g:tagalong_mappings = [{'c': '_c'}, 'i', 'a']
Expand Down
26 changes: 23 additions & 3 deletions plugin/tagalong.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ if !exists('g:tagalong_additional_filetypes')
let g:tagalong_additional_filetypes = []
endif

if !exists('g:tagalong_excluded_filetype_combinations')
let g:tagalong_excluded_filetype_combinations = ['eruby.yaml']
endif

if !exists('g:tagalong_mappings')
let g:tagalong_mappings = ['c', 'C', 'v', 'i', 'a']
endif
Expand Down Expand Up @@ -41,9 +45,25 @@ nnoremap <silent> <Plug>TagalongReapply :call tagalong#Reapply()<cr>
" Needed in order to handle dot-filetypes like "javascript.jsx" or
" "custom.html".
function s:InitIfSupportedFiletype(filetype_string)
for filetype in split(a:filetype_string, '\.')
if index(g:tagalong_filetypes, filetype) >= 0 ||
\ index(g:tagalong_additional_filetypes, filetype) >= 0
let filetypes = split(a:filetype_string, '\.')
call sort(filetypes)

" first, check for exclusion:
for filetype_string in g:tagalong_excluded_filetype_combinations
let excluded_filetypes = split(filetype_string, '\.')
call sort(excluded_filetypes)

if filetypes == excluded_filetypes
return
endif
endfor

" if it's not explicitly excluded, check if it's supported:
let included_filetypes = copy(g:tagalong_filetypes)
call extend(included_filetypes, g:tagalong_additional_filetypes)

for filetype in filetypes
if index(included_filetypes, filetype) >= 0
call tagalong#Init()
return
endif
Expand Down
20 changes: 20 additions & 0 deletions spec/plugin/filetype_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,24 @@
HTML
end
end

describe "excluding filetypes" do
let(:filename) { 'test.html' }

specify "allows excluding filetypes with a setting" do
vim.command('let g:tagalong_excluded_filetype_combinations = ["html"]')

set_file_contents <<~HTML
<div>Text</div>
HTML

vim.search('div')
edit('cwspan')

# Doesn't work anymore
assert_file_contents <<~HTML
<span>Text</div>
HTML
end
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
RSpec.configure do |config|
config.include Support::Vim

config.before :each do
# Reset to default plugin settings
vim.command('let g:tagalong_excluded_filetype_combinations = ["eruby.yaml"]')
end

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
Expand Down

0 comments on commit f224431

Please sign in to comment.