Scite 处理字符串 |
|
function SciteProcessString() local StringStyle = 6 -- constant: language style for strings local function StyleAt(pos) return math.mod(editor.StyleAt[pos], 128) end local i = editor.CurrentPos while i < editor.Length do local sprev, style = StyleAt(i-1), StyleAt(i) if sprev ~= StringStyle and style == StringStyle then local inserted = false ------------------------------------------------------------ -- insert _( if not present ------------------------------------------------------------ editor:GotoPos(i) if i >= 2 and editor:textrange(i-2, i) ~= "_(" then editor:BeginUndoAction() inserted = true editor:AddText("_(") i = i + 2 end while i < editor.Length and StyleAt(i) == StringStyle do i = i + 1 end ------------------------------------------------------------ -- insert ) if _( inserted ------------------------------------------------------------ editor:GotoPos(i) if inserted then editor:AddText(")") editor:EndUndoAction() end break end i = i + 1 end end
function SciteProcessString() local StringStyle = 6 -- constant: language style for strings local function StyleAt(pos) return math.mod(editor.StyleAt[pos], 128) end local function StrStart(pos) local sprev, style = StyleAt(pos-1), StyleAt(pos) if sprev ~= StringStyle and style == StringStyle then return true end end local i = editor.CurrentPos if StrStart(i) then local inserted = false ------------------------------------------------------------ -- insert _( if not present ------------------------------------------------------------ editor:GotoPos(i) if i >= 2 and editor:textrange(i-2, i) ~= "_(" then editor:BeginUndoAction() inserted = true editor:AddText("_(") i = i + 2 end while i < editor.Length and StyleAt(i) == StringStyle do i = i + 1 end ------------------------------------------------------------ -- insert ) if _( inserted ------------------------------------------------------------ editor:GotoPos(i) if inserted then editor:AddText(")") editor:EndUndoAction() end else while i < editor.Length do if StrStart(i) then editor:GotoPos(i) break end i = i + 1 end end end