--▽▽UTF-8▽▽ --[[ copyleft by jinzhongjie(xjinzhongjie@hotmail.com).anyone who want change the code please tell writer. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. ]] --[[ This will make a menu item in your "Tools" menu, that can be used with Control+9 shortcut ]] scite_Command { 'Make CT item |makeCtItem|Ctrl+7', } local Branchlist = { 'if', 'while', 'for', 'switch' } local clsName local fucName function makeCtItem() local clsFucSelect = ParseFile('cls') output:BeginUndoAction() print("--------(CT item)----------------------------") if editor.SelectionStart < editor.SelectionEnd then print_ctitem(clsFucSelect, editor.SelectionStart, editor.SelectionEnd, "") else for k, name in pairs(clsFucSelect)do print_ctitem(clsFucSelect, name[3], name[4], "") end end output:EndUndoAction() end -- case1 not comment,not space -- case2 function search_key(pos_start, key, style) local pos = pos_start local len = string.len(key) while true do local ch = char_at(pos) if ch then if not style then if not string.find(' \t\r\n', ch)then local stl = editor.StyleAt[pos] if stl ~= SCE_C_COMMENT and style ~= SCE_C_COMMENTLINE and style ~= SCE_C_COMMENTDOC then local sel = editor:textrange(pos, pos+len) if sel ~= key then pos = nil end break end end else local stl = editor.StyleAt[pos] if stl == style then local sel = editor:textrange(pos, pos+len) if sel == key then break end end end else pos = nil break end pos = pos+1 end return pos end -- {} () function search_pairEnd(pos_start, key_start, key_end) local pos = pos_start local count = 1 while count>0 do local style = editor.StyleAt[pos] if style == SCE_C_OPERATOR then local ch = char_at(pos) if not ch then pos = nil break end if ch == key_start then count = count+1 elseif ch == key_end then count = count-1 end end pos = pos+1 end return pos end function print_ctitem(clsFuc, pos_start, pos_end, parent_case) local print_flag = nil local case_else_if_flag = nil local s, e e = pos_start while e do s, e = editor:findtext('\\w+\\s*(', SCFIND_MATCHCASE+SCFIND_REGEXP, e) if s then if s > pos_end then break end local style = editor.StyleAt[s] if style == SCE_C_WORD then local sel = editor:textrange(s, e) local statement = string.match(sel, "([%w_]+)%s*%(") local flag_match = nil for k, pat in pairs(Branchlist)do if statement == pat then flag_match = true end end if flag_match then e = search_pairEnd(e, '(', ')') for k, name in pairs(clsFuc)do if s < name[4] and s > name[3] then if clsName~= name[1] or fucName~= name[2] then clsName = name[1] fucName = name[2] print("------------------------------------") if clsName == 0 then print(fucName .."()".."==") else print(clsName.."::"..fucName .."()".."==") end end break end end local ct_case = editor:textrange(s, e) ct_case = string.gsub(ct_case, '%s*\n%s*', ' ') if case_else_if_flag then ct_case = 'else '..ct_case end ct_case = parent_case..ct_case if statement == 'switch' then local pos_s, pos_e pos_e = e while pos_e do local case_start_pos = pos_e pos_s, pos_e = editor:findtext('\\S.*:', SCFIND_MATCHCASE+SCFIND_REGEXP+SCFIND_POSIX, pos_e) if pos_s then local case_sel = editor:textrange(pos_s, pos_e) local ch = char_at(pos_s) if ch == 'c' then local value = string.match(case_sel, "case%s*(%S+)%s*:") print_flag = print_ctitem(clsFuc, case_start_pos, pos_e, ct_case..":".. value..";") if not print_flag then print(ct_case..":".. value) print_flag = true; end elseif ch == 'd' then print_flag = print_ctitem(clsFuc, case_start_pos, pos_e, ct_case..":".. 'default'..";") if not print_flag then print(ct_case..":".. 'default') print_flag = true; end break else break end end end e = pos_e else --[[ local lineNum=editor:LineFromPosition(s) local pos_s=editor:PositionFromLine(lineNum) local pos_e=editor.LineEndPosition[lineNum] local line = editor:textrange(pos_s,pos_e) ]]-- ct_case = ct_case:gsub("^%s*(.-)%s*$", "%1") --line=ct_case:gsub("^%s*(.-)%s*{$", "%1") local ct_case_true = ct_case..":".. "true" local ct_case_false = ct_case..":".. "false" local first_case_end local first_case_start = search_key(e, '{') if first_case_start then first_case_end = search_pairEnd(first_case_start+1, '{', '}') print_flag = print_ctitem(clsFuc, first_case_start, first_case_end, ct_case_true..";") if not print_flag then print(ct_case_true) print_flag = true; end else first_case_end = search_key(e, ';', SCE_C_OPERATOR) print(ct_case_true) print_flag = true; end if statement == 'if' then local secend_case_end local secend_case_start = search_key(first_case_end, 'else') if secend_case_start then e = secend_case_start secend_case_start = search_key(e+4, 'if') if secend_case_start then case_else_if_flag = true else if case_else_if_flag then ct_case_false = parent_case..'all else if:false' end secend_case_start = search_key(e+4, '{') if secend_case_start then e = secend_case_start secend_case_end = search_pairEnd(e+1, '{', '}') print_flag = print_ctitem(clsFuc, secend_case_start, secend_case_end, ct_case_false..";") if not print_flag then print(ct_case_false) print_flag = true; end e = secend_case_end else e = search_key(e+4, ';', SCE_C_OPERATOR) print(ct_case_false) print_flag = true; end case_else_if_flag = nil end else if case_else_if_flag then ct_case_false = parent_case..'all else if:false' end e = first_case_end print(ct_case_false) print_flag = true; case_else_if_flag = nil end else e = first_case_end print(ct_case_false) print_flag = true; end end end end end end return print_flag end