emmet-vim icon indicating copy to clipboard operation
emmet-vim copied to clipboard

Support set expand abbr type?

Open storyn26383 opened this issue 6 years ago • 3 comments

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.

storyn26383 avatar Jul 26 '18 15:07 storyn26383

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
  1. search for let s:emmet_settings = {
  2. add this attr in s:emmet_settings:
let s:emmet_settings = {
\    'vue': {
\        'extends': 'html',
\    },

...
}

ArisAgeha avatar Jul 30 '18 13:07 ArisAgeha

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.

resolritter avatar Aug 28 '18 21:08 resolritter

:eyes:

Eduruiz avatar Mar 25 '20 21:03 Eduruiz