mattn / emmet-vim

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

Support set expand abbr type? #430

Open storyn26383 opened 6 years ago

storyn26383 commented 6 years ago

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.

ArisAgeha commented 6 years ago

I met the same problem today, and I find a temporary solution:

  1. Open ~/.vim/bundle/emmet-vim/autoload/emmet.vim(linux)
  2. find function! emmet#getFileType(...)
  3. 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
  4. search for let s:emmet_settings = {
  5. add this attr in s:emmet_settings:
    
    let s:emmet_settings = {
    \    'vue': {
    \        'extends': 'html',
    \    },

... }

resolritter commented 6 years ago

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.

Eduruiz commented 4 years ago

:eyes: