Skip to content

Instantly share code, notes, and snippets.

@rrreese
Created October 3, 2013 18:19
Show Gist options
  • Save rrreese/6814480 to your computer and use it in GitHub Desktop.
Save rrreese/6814480 to your computer and use it in GitHub Desktop.
Scite Word Count
--Calculate whitespace control
for m in editor:match("\n") do --count newline
whiteSpace = whiteSpace + 1;
end
for m in editor:match("\r") do --count carriage return
whiteSpace = whiteSpace + 1;
end
for m in editor:match("\t") do --count tabs
whiteSpace = whiteSpace + 1;
end
--calculate number of words
local itt = 0;
while itt < editor.LineCount do --iterate through each line
line = editor:GetLine(itt);
if line then
for word in string.gfind(line, "%w+") do
wordCount = wordCount + 1
end
end
itt = itt + 1;
end
--Calculate non-empty lines
local itt = 0;
while itt < editor.LineCount do --iterate through each line
local hasChar, hasNum = 0;
line = editor:GetLine(itt);
if line then
hasAlphaNum = string.find(line,'%w');
end
if (hasAlphaNum ~= nill)
nonEmptyLine = nonEmptyLine + 1;
end
itt = itt + 1;
end
print("----------------------------");
print("Char Count: \t",editor.Length);
print("Word Count: ",wordCount);
print("Line Count: \t",editor.LineCount);
print("Non empty lines: ", nonEmptyLine);
print("Empty lines: \t", editor.LineCount - nonEmptyLine);
print("White Space: \t", whiteSpace);
print("Non white space chars: ",(editor.Length)-whiteSpace);
print("Current Pos: ",editor.CurrentPos);
print("Current Line: ",
editor:LineFromPosition(editor.CurrentPos) +1);
local newline = 0; --number of newlines
local nonEmptyLine = 0; --number of non blank lines
local wordCount = 0; --total number of words
local whiteSpace = 0; --number of whitespace chars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment