forked from DGivney/geany-lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinue-line-comment.lua
39 lines (31 loc) · 1.13 KB
/
continue-line-comment.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
#! /usr/bin/env lua
-- Insert a new line with the same commenting as the previous line.
--
-- (c) 2015 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 getCommentText(lineIndex)
local lineText = geany.lines(lineIndex)
debugMessage("Line is "..lineText)
local commentStart = lineText:find("%S")
if not commentStart then return nil end
if lineText:sub(commentStart, commentStart):find("[a-zA-Z0-9]") then
debugMessage("Alphanumeric character found; not a comment")
return nil
end
local commentEnd = lineText:find("%s", commentStart)
if not commentEnd then commentEnd = lineText:len() end
local commentText = lineText:sub(1, commentEnd)
debugMessage("Comment text is ["..commentText.."]")
return commentText
end
---- Start execution ----
local lineIndex = geany.rowcol(geany.caret())
local commentText = getCommentText(lineIndex)
if commentText then
geany.selection("\n"..commentText)
end