Add wordcount part
This commit is contained in:
@@ -15,7 +15,8 @@ M.options = {
|
||||
{class = 'mode', item = require('hardline.parts.mode').get_item},
|
||||
{class = 'high', item = require('hardline.parts.git').get_item},
|
||||
{class = 'med', item = require('hardline.parts.filename').get_item},
|
||||
{class = 'med', item ='%='},
|
||||
{class = 'med', item = '%='},
|
||||
{class = 'med', item = require('hardline.parts.wordcount').get_item},
|
||||
{class = 'error', item = require('hardline.parts.lsp').get_error},
|
||||
{class = 'warning', item = require('hardline.parts.lsp').get_warning},
|
||||
{class = 'warning', item = require('hardline.parts.whitespace').get_item},
|
||||
|
||||
@@ -17,7 +17,8 @@ local function get_branch()
|
||||
end
|
||||
|
||||
local function get_item()
|
||||
return table.concat({' ', get_hunks(), get_branch(), ' '})
|
||||
local item = table.concat({' ', get_hunks(), get_branch(), ' '})
|
||||
return item == ' ' and '' or item
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local cmd, fn, vim = vim.cmd, vim.fn, vim
|
||||
local bo = vim.bo
|
||||
local b, bo = vim.b, vim.bo
|
||||
local enabled = false
|
||||
local cache = ''
|
||||
local options = {
|
||||
c_langs = {'arduino', 'c', 'cpp', 'cuda', 'go', 'javascript', 'ld', 'php'},
|
||||
max_lines = 5000,
|
||||
@@ -49,13 +50,14 @@ local function get_item()
|
||||
if not enabled then
|
||||
cmd 'augroup hardline_whitespace'
|
||||
cmd 'autocmd!'
|
||||
cmd 'autocmd CursorHold, BufWritePost * unlet! b:hardline_whitespace'
|
||||
cmd 'autocmd CursorHold,BufWritePost * unlet! b:hardline_whitespace'
|
||||
cmd 'augroup end'
|
||||
enabled = true
|
||||
end
|
||||
if bo.readonly or not bo.modifiable then return '' end
|
||||
if fn.line('$') > options.max_lines then return '' end
|
||||
if fn.exists('b:hardline_whitespace') ~= 0 then return '' end
|
||||
if fn.exists('b:hardline_whitespace') ~= 0 then return cache end
|
||||
b.hardline_whitespace = 1
|
||||
local item = table.concat({
|
||||
' ',
|
||||
check_trailing(),
|
||||
@@ -64,7 +66,8 @@ local function get_item()
|
||||
check_conflict(),
|
||||
' ',
|
||||
})
|
||||
return item == ' ' and '' or item
|
||||
cache = item == ' ' and '' or item
|
||||
return cache
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,52 @@
|
||||
local M = {}
|
||||
local cmd, fn, vim = vim.cmd, vim.fn, vim
|
||||
local b, bo = vim.b, vim.bo
|
||||
local enabled = false
|
||||
local cache = ''
|
||||
local options = {
|
||||
filetypes = {
|
||||
'asciidoc',
|
||||
'help',
|
||||
'mail',
|
||||
'markdown',
|
||||
'nroff',
|
||||
'org',
|
||||
'rst',
|
||||
'plaintex',
|
||||
'tex',
|
||||
'text',
|
||||
},
|
||||
max_lines = 5000,
|
||||
}
|
||||
|
||||
function M.get_item()
|
||||
return table.concat({
|
||||
})
|
||||
local function in_visual()
|
||||
return vim.tbl_contains({'v', 'V', '', 's', 'S', ''}, fn.mode())
|
||||
end
|
||||
|
||||
return M
|
||||
local function get_wordcount()
|
||||
local query = in_visual() and 'visual_words' or 'words'
|
||||
local wordcount = fn.wordcount()[query]
|
||||
return string.format('%d words', wordcount)
|
||||
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'
|
||||
enabled = true
|
||||
end
|
||||
if not vim.tbl_contains(options.filetypes, bo.filetype) then return '' end
|
||||
if fn.line('$') > options.max_lines then return '' end
|
||||
if fn.exists('b:hardline_wordcount') ~= 0 and not in_visual() then
|
||||
return cache
|
||||
end
|
||||
b.hardline_wordcount = 1
|
||||
local item = table.concat({' ', get_wordcount(), ' '})
|
||||
cache = item == ' ' and '' or item
|
||||
return cache
|
||||
end
|
||||
|
||||
return {
|
||||
get_item = get_item,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user