azabiong / vim-highlighter

Highlight words and expressions
MIT License
237 stars 11 forks source link

2 Errors once loading hl file #28

Closed windrg closed 7 months ago

windrg commented 9 months ago

Hi, I've met these 2 errors once trying to load an existing hl file.

Error detected while processing BufWinEnter Autocommands for "*.abc"..function AbcSetKeymap[7]..highlighter#Command[42]..<SNR>225_LoadHighlight[12]..<SNR>225_SetHighlight[4]..<SNR>225_ClearPosHighlight:
line    2:
E968: Need at least one of 'id' or 'type'
Error detected while processing BufWinEnter Autocommands for "*.abc"..function AbcSetKeymap[7]..highlighter#Command[42]..<SNR>225_LoadHighlight[12]..<SNR>225_SetHighlight[11]..<SNR>225_UpdateSync:
line   10:
E684: List index out of range: 0

What I just set is like below in my vimrc

" =================== vim-highlighter
let HiSyncMode = 1
let HiBackup = 0

Could you please let me know how I can solve these 2 errors? My vim is vim 9 and I'm using this on Ubuntu 20.04.

windrg commented 9 months ago

Regarding the 2nd error, I made it get thru by adding a condtion like this

function s:UpdateSync(op, group, pattern)
  if !s:GetSyncMode() || a:pattern[:1] == '\%'
    return
  endif
  let l:match = s:Sync.page[t:HiSync]
  let s:Sync[a:op] = [a:group, a:pattern]
  if a:op == 'add'
    call add(l:match, s:Sync[a:op])
  elseif a:op == 'del'
    if a:group == '*'
      if len(l:match) > 0               <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        call remove(l:match, 0, -1)
      endif
    else
        for i in range(len(l:match))
          if l:match[i][1] ==# a:pattern
            call remove(l:match, i) | break
          endif
        endfor
    endif
  endif
  let w:HiSync = 1
  call s:SetHiSyncWin(1)
endfunction
azabiong commented 9 months ago

Hi @windrg, Thank you for updating this issue, and also the solution for the 2nd error. It looks good! πŸ‘ I will apply it right away. For the 1st error, I'm trying to reproduce this error, but it's not easy. If you have an easily reproducible procedure, please let me know. Thank you!

windrg commented 9 months ago

it’s very easy to reproduce. please follow the below steps.

  1. open a a.abc
  2. highlight few words
  3. Hi save ./a
  4. close file
  5. open a.abc again
  6. Hi load ./a
azabiong commented 9 months ago

Thank you! I was able to reproduce the problem in the order you provided using an older version of Vim. Using the new Vim version 9.1.100 there is no problem. Would you like to try it? Thanks.

windrg commented 9 months ago

I got that it had gone away after updating vim to this one.

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749

Thanks but it also would be appreciated if you would add some exception handling against the 1st error.

azabiong commented 9 months ago

Great! Thank you for confirming that it works. Alright, that's good idea. Now I'll go back to the old version and look at the problem in more detail. Thanks!

azabiong commented 9 months ago

The update is now complete! Now I checked it works in Vim version 8.2.213. I hope you like it πŸ˜„ Please try the latest update, and thank you for your great help in finding and resolving the issue!