Open lo48576 opened 5 years ago
I think syntax and defaults should be separate.
Being HTML-like syntax does not impliy HTML-like schema, so the base type to be extends
-ed should add no additional settings.
This pull request does nothing for such HTML defaults.
Currently xml
type in emmet-vim inherits HTML default, which expands param<C-y>,
to <param name="" value=""></param>
for example.
Hence user_emmet_settings.xml.extends = ""
is required to cancel the inheritance to prevent importing HTML defaults into XML.
emmet#lang#type()
uses html
if base type is not found and it's because extends = ""
works expectedly, but this is implicit rule (sorry if I overlooked docs) and might not be desirable.
If empty_elements / block_elements / inline_elements are specified as empty string, those are not merged. If the type does not have those keys, those will be merged. How about this idea?
let empty_elements = emmet#getResourceIfExists(type, 'empty_elements', settings.html.empty_elements)
Sounds good, it enables users to explicitly discard default. :smile:
emmet#getResourceIfExists
might be below.
function! emmet#getResourceIfExists(type, name, default) abort
if !has_key(s:emmet_settings, a:type) || !has_key(s:emmet_settings[a:type], a:name)
return a:default
endif
return emmet#getResource(type, name, default)
endfunction
It would work for string and integer type values (empty_elements
, block_elements
, and inline_elements
(and maybe empty_element_suffix
)).
But for default_attributes
(it has dictionary type), it still merge extends
-ed default config, and users can't discard default (without using extends: ""
).
It is caused by emmet#mergeConfig()
called for list and dictionary.
I want the way to prevent dicts and lists from being merged with values of extends
-ed types.
https://github.com/mattn/emmet-vim/blob/7a4bf3463ef1e2c08393218fc67a8729c00948a5/autoload/emmet.vim#L336-L352
(↑ I want to configurably disable this part for dictinaries and lists, e.g. default_attributes
, expandos
, aliases
.)
In HTML-like type,
settings.html.*
is used as default setting ifsettings.(type).*
is not set. But in HTML type and types extending HTML,settings.html
is merged intosettings.(type)
and no need to usesettings.html
as explicit default.Before this change,
param<C-y>,
expands to<param name="" value=""></param>
becausexml
type extendshtml
by default, andhtml
has default attributes forparam
element.With this change and
g:user_emmet_settings.xml.extends = ""
, users can disable HTML defaults in XML files. So thenparam<C-y>,
expands to<param></param>
.