const Offset = 3333
var Show = false
var Words: list<string>
-var Cycle = 1
+var Idx = 1
def Init()
if len(Words) > 0 | return | endif
silent! matchdelete(Offset + i + 1)
enddef
-def Add(i: number)
- matchadd("MarkWord" .. (i + 1), Words[i], -10, Offset + i + 1)
+def Add(i: number, word: string)
+ Words[i] = word
+ matchadd("MarkWord" .. (i + 1), word, -10, Offset + i + 1)
enddef
-export def Update()
+export def Refresh()
Init()
var word: string
for i in range(len(Words))
exec "syntax clear MarkWord" .. (i + 1)
if Words[i] == "" | continue | endif
silent! matchdelete(Offset + i + 1)
- if Show | Add(i) | endif
+ if Show | Add(i, Words[i]) | endif
endfor
enddef
export def Toggle()
Show = !Show
- Update()
+ Refresh()
enddef
-def Do(word: string): bool
+def Do(word: string)
Init()
- if !Show
- for i in range(len(Words))
- if Words[i] == "" | continue | endif
- Del(i)
- endfor
- Show = true
- endif
for i in range(len(Words))
- if word == Words[i]
- Del(i)
- return true
+ if !Show | Del(i)
+ elseif Words[i] == word | Del(i) | return
endif
endfor
+ if !Show | Show = true | endif
for i in range(len(Words))
if Words[i] != "" | continue | endif
- Del(i)
- Words[i] = word
- Add(i)
- Cycle = ((i + 1) == len(Words)) ? 1 : i + 1
- return true
+ Add(i, word)
+ Idx = ((i + 1) == len(Words)) ? 1 : (i + 1)
+ return
endfor
- Del(Cycle)
- Words[Cycle] = word
- Add(Cycle)
- Cycle = ((Cycle + 1) == len(Words)) ? 1 : Cycle + 1
- return true
+ Del(Idx)
+ Add(Idx, word)
+ Idx = ((Idx + 1) == len(Words)) ? 1 : (Idx + 1)
enddef
export def Word()
if exists("*mark#Word") | finish | endif
-nmap <unique> <silent> <leader>m <Plug>MarkWord
-nnoremap <silent> <Plug>MarkWord :call mark#Word()<CR>
-command! MarkToggle call mark#Toggle()
-autocmd! BufWinEnter,WinEnter * call mark#Update()
+nmap <silent> <leader>m :call mark#Word()<CR>
+autocmd! BufWinEnter,WinEnter * call mark#Refresh()