summaryrefslogtreecommitdiff
path: root/.config/micro/plug/wc/wc.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/micro/plug/wc/wc.lua')
-rw-r--r--.config/micro/plug/wc/wc.lua37
1 files changed, 0 insertions, 37 deletions
diff --git a/.config/micro/plug/wc/wc.lua b/.config/micro/plug/wc/wc.lua
deleted file mode 100644
index 0e13677..0000000
--- a/.config/micro/plug/wc/wc.lua
+++ /dev/null
@@ -1,37 +0,0 @@
-VERSION = "1.2.1"
-
-local micro = import("micro")
-local config = import("micro/config")
-local util = import("micro/util")
-local utf8 = import("unicode/utf8")
-
-function init()
- config.MakeCommand("wc", wordCount, config.NoComplete)
- config.AddRuntimeFile("wc", config.RTHelp, "help/wc.md")
- config.TryBindKey("F5", "lua:wc.wordCount", false)
-end
-
-function wordCount(bp)
- -- Buffer of selection/whole document
- local buffer
- --Get active cursor (to get selection)
- local cursor = bp.Buf:GetActiveCursor()
- --If cursor exists and there is selection, convert selection byte[] to string
- if cursor and cursor:HasSelection() then
- buffer = util.String(cursor:GetSelection())
- else
- --no selection, convert whole buffer byte[] to string
- buffer = util.String(bp.Buf:Bytes())
- end
- --length of the buffer/selection (string), utf8 friendly
- charCount = utf8.RuneCountInString(buffer)
- --Get word/line count using gsub's number of substitutions
- -- number of substitutions, pattern: %S+ (more than one non-whitespace characters)
- local _ , wordCount = buffer:gsub("%S+","")
- -- number of substitutions, pattern: \n (number of newline characters)
- local _, lineCount = buffer:gsub("\n", "")
- --add one to line count (since we're counting separators not lines above)
- lineCount = lineCount + 1
- --display the message
- micro.InfoBar():Message("Lines:" .. lineCount .. " Words:"..wordCount.." Characters:"..charCount)
-end