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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lo48576
Copy link

@lo48576 lo48576 commented Oct 5, 2018

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

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 lo48576 force-pushed the feature/prevent-forcing-html-default branch from 3185aad to 51d68cd Compare October 5, 2018 11:11
@lo48576
Copy link
Author

lo48576 commented Oct 5, 2018

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
Copy link
Owner

mattn commented Oct 5, 2018

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
Copy link
Author

lo48576 commented Oct 5, 2018

Sounds good, it enables users to explicitly discard default. 😄

@mattn
Copy link
Owner

mattn commented Oct 6, 2018

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
Copy link
Author

lo48576 commented Oct 6, 2018

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.

if has_key(s:emmet_settings[type], 'extends')
let extends = s:emmet_settings[type].extends
if type(extends) ==# 1
let tmp = split(extends, '\s*,\s*')
unlet! extends
let extends = tmp
endif
for ext in extends
if has_key(s:emmet_settings, ext) && has_key(s:emmet_settings[ext], a:name)
if type(ret) ==# 3 || type(ret) ==# 4
call emmet#mergeConfig(ret, s:emmet_settings[ext][a:name])
else
let ret = s:emmet_settings[ext][a:name]
endif
endif
endfor
endif

(↑ I want to configurably disable this part for dictinaries and lists, e.g. default_attributes, expandos, aliases.)

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

Successfully merging this pull request may close these issues.

2 participants