emmet-vim
emmet-vim copied to clipboard
Support set expand abbr type?
Hello, when I use emmet in *.vue
files, for example:
<template>
<h1>Hello World</h1>
</template>
<script>
export default {
//
}
</script>
<style lang="scss">
h1 {
//
}
</style>
There are three different syntax in a file, but emmet can't handle this situation properly.
If we can have another function like:
emmet#setExpandAbbrType('css')
Then we can do something like this:
autocmd CursorMoved,CursorMovedI * call dynamicSetEmmetExpandAbbrType()
Thanks in advance.
I met the same problem today, and I find a temporary solution:
- Open
~/.vim/bundle/emmet-vim/autoload/emmet.vim
(linux) - find
function! emmet#getFileType(...)
- add this code before
return type
function! emmet#getFileType(...) abort
...
...
if type ==# 'vue'
let pos = emmet#util#getcurpos()
let type = synIDattr(synID(pos[1], pos[2], 1), 'name')
if type =~# '^css\w'
let type = 'css'
endif
if type =~# '^html\w'
let type = 'html'
endif
if type =~# '^javaScript'
let type = 'javascript'
endif
if len(type) ==# 0 && type =~# '^xml'
let type = 'xml'
endif
endif
return type
endfunction
- search for
let s:emmet_settings = {
- add this attr in
s:emmet_settings
:
let s:emmet_settings = {
\ 'vue': {
\ 'extends': 'html',
\ },
...
}
I've tried to get around this in https://github.com/mattn/emmet-vim/pull/433 by switching the order in which things are analyzed (i.e. prioritizing the syntax at the cursor first, then falling back to the current type identifying method if it doesn't work). As a result, it works as it should for each block in the Vue files I have tested.
I'm not sure if it's a good solution. There seems to be an error in the Travis build that I haven't understood exactly what it is and I was waiting for @mattn's take on that.
:eyes: