diff options
| author | 2021-07-16 16:58:52 -0400 | |
|---|---|---|
| committer | 2021-07-16 16:58:52 -0400 | |
| commit | 24cba05bfd60e183f804a81cf0d34795adfe2ed0 (patch) | |
| tree | 42fbc93f1ae7028d8498d322fcd962378c7277ca /dot_config/micro/plug/textcount | |
| parent | environment: add /etc/termfino to explicit terminfo dirs (diff) | |
micro: textcount: also handle selections
we add a space in between the selections to work with the word filter
technically, not very nice, but hey
maybe pattern could run on every selection separately later
and then add up the results
that could be good
Diffstat (limited to 'dot_config/micro/plug/textcount')
| -rw-r--r-- | dot_config/micro/plug/textcount/textcount.lua | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/dot_config/micro/plug/textcount/textcount.lua b/dot_config/micro/plug/textcount/textcount.lua index cd12e58..383892a 100644 --- a/dot_config/micro/plug/textcount/textcount.lua +++ b/dot_config/micro/plug/textcount/textcount.lua @@ -17,9 +17,21 @@ function init() config.MakeCommand('wc', wc, config.NoComplete) end +local function selections(b) + local str = '' + for _, c in b:GetCursors()() do + if c:HasSelection() then + str = str .. ' ' .. util.String(c:GetSelection()) + end + end + return str +end + -- utils local function pattern(b, pat) - local str = util.String(b:Bytes()) + -- if there is a selection, we use it, else we use b:Bytes() + local str = selections(b) + if str == '' then str = util.String(b:Bytes()) end local _, n = str:gsub(pat, '') return n end |
