mattn / emmet-vim

emmet for vim: http://emmet.io/
http://mattn.github.io/emmet-vim
MIT License
6.41k stars 411 forks source link

Use empty string and `0` for HTML-like type, not HTML default #434

Open lo48576 opened 5 years ago

lo48576 commented 5 years ago

In HTML-like type, settings.html.* is used as default setting if settings.(type).* is not set. But in HTML type and types extending HTML, settings.html is merged into settings.(type) and no need to use settings.html as explicit default.

Before this change, param<C-y>, expands to <param name="" value=""></param> because xml type extends html by default, and html has default attributes for param element.

With this change and g:user_emmet_settings.xml.extends = "", users can disable HTML defaults in XML files. So then param<C-y>, expands to <param></param>.

lo48576 commented 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.

mattn commented 5 years ago

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)
lo48576 commented 5 years ago

Sounds good, it enables users to explicitly discard default. :smile:

mattn commented 5 years ago

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
lo48576 commented 5 years ago

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.)