Add set_cache function

This commit is contained in:
Olivier Roques
2020-12-26 10:12:25 +01:00
parent 55cabe29f8
commit 63594c914c
3 changed files with 10 additions and 8 deletions

View File

@@ -35,4 +35,11 @@ function M.get_state(class)
return M.is_active() and 'active' or 'inactive'
end
function M.set_cache(augroup)
cmd(string.format('augroup %s', augroup))
cmd('autocmd!')
cmd(string.format('autocmd CursorHold,BufWritePost * unlet! b:%s', augroup))
cmd('augroup END')
end
return M

View File

@@ -1,5 +1,6 @@
local cmd, fn, vim = vim.cmd, vim.fn, vim
local b, bo = vim.b, vim.bo
local common = require('hardline.common')
local enabled = false
local cache = ''
@@ -49,10 +50,7 @@ end
local function get_item()
if not enabled then
cmd 'augroup hardline_whitespace'
cmd 'autocmd!'
cmd 'autocmd CursorHold,BufWritePost * unlet! b:hardline_whitespace'
cmd 'augroup END'
common.set_cache('hardline_whitespace')
enabled = true
end
if bo.readonly or not bo.modifiable then return '' end

View File

@@ -33,10 +33,7 @@ end
local function get_item()
if not enabled then
cmd 'augroup hardline_wordcount'
cmd 'autocmd!'
cmd 'autocmd CursorHold,BufWritePost * unlet! b:hardline_wordcount'
cmd 'augroup END'
common.set_cache('hardline_wordcount')
enabled = true
end
if not vim.tbl_contains(options.filetypes, bo.filetype) then return '' end