Skip to content

Commit f224431

Browse files
committed
Exclude eruby.yaml from plugin initialization
1 parent 0b8e45e commit f224431

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ If you set it to an empty list, `[]`, the plugin will not be automatically insta
102102

103103
### `g:tagalong_additional_filetypes`
104104

105+
Example usage:
106+
105107
``` vim
106108
let g:tagalong_additional_filetypes = ['custom', 'another']
107109
```
@@ -112,6 +114,22 @@ The plugin should work with any HTML-like tags, so if a compatible filetype is m
112114

113115
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.
114116

117+
### `g:tagalong_excluded_filetype_combinations`
118+
119+
Example usage:
120+
121+
``` vim
122+
let g:tagalong_excluded_filetype_combinations = ['custom.html']
123+
```
124+
125+
Default value: `['eruby.yaml']`
126+
127+
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.
128+
129+
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.
130+
131+
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.
132+
115133
### `g:tagalong_mappings`
116134

117135
Example usage:

doc/tagalong.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,27 @@ opening a github issue to suggest one that you feel is missing. As long as
145145
it's not something too custom, I would likely be okay with adding it to the
146146
built-in list.
147147

148+
*g:tagalong_excluded_filetype_combinations*
149+
>
150+
let g:tagalong_excluded_filetype_combinations = ['custom.html']
151+
<
152+
Default value: ['eruby.yaml']
153+
154+
This setting allows the exclusion of particular filetype dot-combinations from
155+
initialization. The "filetypes" setting includes single filetypes, so any
156+
combination of them including, for instance, "html" would activate the plugin.
157+
So you could set custom filetypes like "html.rails" or something and it would
158+
still work.
159+
160+
That said, there are combinations that are not HTML-like. The current default
161+
value of the setting, "eruby.yaml" is a good example -- it's being set by
162+
vim-rails, but there's no HTML to edit in there.
163+
164+
It's recommended to leave this setting untouched, but you could use it as an
165+
escape hatch. If you have any problems with a particular filetype that are solved
166+
by an entry in this setting, consider opening an issue to make a change to the
167+
defaults.
168+
148169
*g:tagalong_mappings*
149170
>
150171
let g:tagalong_mappings = [{'c': '_c'}, 'i', 'a']

plugin/tagalong.vim

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ if !exists('g:tagalong_additional_filetypes')
1414
let g:tagalong_additional_filetypes = []
1515
endif
1616

17+
if !exists('g:tagalong_excluded_filetype_combinations')
18+
let g:tagalong_excluded_filetype_combinations = ['eruby.yaml']
19+
endif
20+
1721
if !exists('g:tagalong_mappings')
1822
let g:tagalong_mappings = ['c', 'C', 'v', 'i', 'a']
1923
endif
@@ -41,9 +45,25 @@ nnoremap <silent> <Plug>TagalongReapply :call tagalong#Reapply()<cr>
4145
" Needed in order to handle dot-filetypes like "javascript.jsx" or
4246
" "custom.html".
4347
function s:InitIfSupportedFiletype(filetype_string)
44-
for filetype in split(a:filetype_string, '\.')
45-
if index(g:tagalong_filetypes, filetype) >= 0 ||
46-
\ index(g:tagalong_additional_filetypes, filetype) >= 0
48+
let filetypes = split(a:filetype_string, '\.')
49+
call sort(filetypes)
50+
51+
" first, check for exclusion:
52+
for filetype_string in g:tagalong_excluded_filetype_combinations
53+
let excluded_filetypes = split(filetype_string, '\.')
54+
call sort(excluded_filetypes)
55+
56+
if filetypes == excluded_filetypes
57+
return
58+
endif
59+
endfor
60+
61+
" if it's not explicitly excluded, check if it's supported:
62+
let included_filetypes = copy(g:tagalong_filetypes)
63+
call extend(included_filetypes, g:tagalong_additional_filetypes)
64+
65+
for filetype in filetypes
66+
if index(included_filetypes, filetype) >= 0
4767
call tagalong#Init()
4868
return
4969
endif

spec/plugin/filetype_support_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,24 @@
136136
HTML
137137
end
138138
end
139+
140+
describe "excluding filetypes" do
141+
let(:filename) { 'test.html' }
142+
143+
specify "allows excluding filetypes with a setting" do
144+
vim.command('let g:tagalong_excluded_filetype_combinations = ["html"]')
145+
146+
set_file_contents <<~HTML
147+
<div>Text</div>
148+
HTML
149+
150+
vim.search('div')
151+
edit('cwspan')
152+
153+
# Doesn't work anymore
154+
assert_file_contents <<~HTML
155+
<span>Text</div>
156+
HTML
157+
end
158+
end
139159
end

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
RSpec.configure do |config|
1919
config.include Support::Vim
2020

21+
config.before :each do
22+
# Reset to default plugin settings
23+
vim.command('let g:tagalong_excluded_filetype_combinations = ["eruby.yaml"]')
24+
end
25+
2126
config.expect_with :rspec do |expectations|
2227
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
2328
end

0 commit comments

Comments
 (0)