forked from DGivney/geany-lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-duplicate-lines.lua
44 lines (39 loc) · 1008 Bytes
/
delete-duplicate-lines.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env lua
-- Delete duplicate lines from current file.
--
-- v0.1
-- (c) 2013 by Carl Antuar.
-- Distribution is permitted under the terms of the GPLv3
-- or any later version.
-- Define functions --
debugEnabled = false
function debugMessage(message)
if debugEnabled then geany.message("DEBUG", message) end
end
function chompLine(lineIndex)
return string.gsub(geany.lines(lineIndex), "\n", "")
end
---- Start execution ----
if geany.height() == nil then
debugMessage("No file was open.")
return
end
local previousLine = chompLine(1)
local oldCaret = geany.caret()
geany.caret(1)
local lineIndex = 2
geany.batch(true)
while lineIndex <= geany.height() do
local line = chompLine(lineIndex)
debugMessage("Line "..lineIndex.." is ["..line.."]")
if line == previousLine then
debugMessage("Deleting line "..lineIndex)
geany.keycmd("EDITOR_DELETELINE")
else
previousLine = line
geany.navigate("line", 1)
lineIndex = lineIndex + 1
end
end
geany.caret(oldCaret)
geany.batch(false)