Srish Agrawal wrote:
Hello EveryBody

I needed a small LUA script to be used with SciTE. It was supposed to remove all
multilple lines except the first one from a text document without changing the
original document in any other way. Unable to find a similer script posted
anywhere on the NET, I wrote it myself.
Of cource, I borrowed some coding ideas/tricks and functions from codes written
by Neil Hodgson and Philippe Lhoste.

It works as expected but is rather big.  May anybody give me some idea as to how
can I cange the logic and save a few lines of code.

This is what I have :

-- this function removes multiple lines
-- only the first occurance is kept
-- original order of lines are meintained
-- NOTE
-- editor line number starts from ZERO
-- table element number strats from ONE
[snipped]

Using scripting language methods...

function RemoveDupLines()
  local lookup, result = {}, {}
  for i = 0, editor.LineCount - 1 do
    local ln = editor:GetLine(i) or ""
    local eol = string.find(ln, "[\r\n]+$")
    local line = ln
    if eol then ln = string.sub(ln, 1, eol-1) end
    if ln ~= "" and not lookup[ln] then
      lookup[ln] = true
      table.insert(result, line)
    end
  end--for
  editor:SetText(table.concat(result))
end

Enjoy :-)

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest

Reply via email to