diff options
| author | Jacob McDonnell <jacob@simplelittledream.com> | 2022-10-26 11:10:13 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@simplelittledream.com> | 2022-10-26 11:10:13 -0400 |
| commit | 6b6e91707ecf621a0bedad154351db8f1ccc2123 (patch) | |
| tree | e0bed306b683c344e3f429817b1ef04daba1c2f6 /.config/micro/plug/wc/wc.lua | |
| parent | 161a1bfb0b3e75e9f5241cd7dd8aafec455a67d5 (diff) | |
Working on merging to one branch
Diffstat (limited to '.config/micro/plug/wc/wc.lua')
| -rw-r--r-- | .config/micro/plug/wc/wc.lua | 37 |
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 |
