--▽▽UTF-8▽▽ --switch_buffers.lua --drops down a list of buffers, in recently-used order scite_Command { 'jscript list|jscript_list|Alt+j|Context', } ------------------------------------------------------------------- --local act_valid = false local function jscript_setting() -- //////////////////////////////////////////////////////////////////// local VT_EMPTY = 0 local VT_NULL = 1 local VT_I2 = 2 local VT_I4 = 3 local VT_R4 = 4 local VT_R8 = 5 local VT_CY = 6 local VT_DATE = 7 local VT_BSTR = 8 local VT_DISPATCH = 9 local VT_ERROR = 10 local VT_BOOL = 11 local VT_VARIANT = 12 local VT_UNKNOWN = 13 local VT_DECIMAL = 14 local VT_I1 = 16 local VT_UI1 = 17 local VT_UI2 = 18 local VT_UI4 = 19 local VT_I8 = 20 local VT_UI8 = 21 local VT_INT = 22 local VT_UINT = 23 local VT_VOID = 24 local VT_HRESULT = 25 local VT_PTR = 26 local VT_SAFEARRAY = 27 local VT_CARRAY = 28 local VT_USERDEFINED = 29 local VT_LPSTR = 30 local VT_LPWSTR = 31 local VT_RECORD = 36 local VT_INT_PTR = 37 local VT_UINT_PTR = 38 local VT_FILETIME = 64 local VT_BLOB = 65 local VT_STREAM = 66 local VT_STORAGE = 67 local VT_STREAMED_OBJECT = 68 local VT_STORED_OBJECT = 69 local VT_BLOB_OBJECT = 70 local VT_CF = 71 local VT_CLSID = 72 local VT_VERSIONED_STREAM = 73 local VT_BSTR_BLOB = 0xfff local VT_VECTOR = 0x1000 local VT_ARRAY = 0x2000 local VT_BYREF = 0x4000 local VT_RESERVED = 0x8000 local VT_ILLEGAL = 0xffff local VT_ILLEGALMASKED = 0xfff local VT_TYPEMASK = 0xfff -- //////////////////////////////////////////////////////////////////// local function Editor_SelectAll() editor:SelectAll() end local function Editor_Replace(seach,replace,flg) spawner.Replace(spawner.ans_to_utf8(seach),spawner.ans_to_utf8(replace),flg) return end local function Editor_GetTbl(no,str) if type(no) == 'string' then no = spawner.ans_to_utf8(no) end local ret=spawner.mygetT(no,spawner.ans_to_utf8(str)) return spawner.utf8_to_ans(ret) end local function Editor_IsTextSelected() local mode=0 if editor.SelectionIsRectangle == 1 then mode=2 elseif editor.SelectionStart ~= editor.SelectionEnd then mode=1 end return mode end local function Editor_GetFilename() return props['FilePath'] end local function Editor_GetSelectLineFrom() local linePos = editor:LineFromPosition(editor.SelectionStart) + 1 return linePos; end local function Editor_GetSelectLineTo() local linePos = editor:LineFromPosition(editor.SelectionEnd) + 1 return linePos; end local function Editor_FileOpen(file) scite.Open(spawner.ans_to_utf8(file)) end local function Editor_ExpandParameter(s1) local str=''; if s1 == '$C' then if editor.SelectionStart == editor.SelectionEnd then local s=editor:WordStartPosition(editor.CurrentPos,true) local e=editor:WordEndPosition(editor.CurrentPos,true) str=editor:textrange(s, e) else str=editor:GetSelText() end end return str end local function Editor_GetLineCount() return editor.LineCount end local function Editor_GetLineStr(num) local line='' if num > 0 and num<=editor.LineCount then line=editor:GetLine(num-1) elseif num == 0 then local linePos = editor:LineFromPosition(editor.CurrentPos) line=editor:GetLine(linePos) end if not line or line=='' then return '' end return spawner.utf8_to_ans(line) end local function Editor_InsText(txt) editor:ReplaceSel(spawner.ans_to_utf8(txt)) end local function Editor_AddTail(txt) editor:AppendText(spawner.ans_to_utf8(txt)) end local function Editor_GetSelectedString() return spawner.utf8_to_ans(editor:GetSelText()) end local function Editor_ReDraw(mode) end local function os_msleep(ms) spawner.msleep(ms) end local function Output_print(txt) print(spawner.ans_to_utf8(txt)) end local function WScript_Echo(content) local str='' if type(content) == 'table' then for i, v in pairs(content)do str = str .. v .. "," end elseif type(content) == 'string' then str=content end print(str) end local function WScript_Quit() end -- /// test function local function lua_GetMacroInfor() return "function from lua" end local function lua_GetMacroVersion() return "1.00" end local function lua_GetTest() return {666, 111.222, spawner.utf8_to_ans("测试") } end local function lua_getdir() return '/aaaaaa/bbbbbb/ccccccc' end local function Debug_StyleAt(p) local style = editor.StyleAt[p] return style end local function Debug_CharAt(p) return char_at(p) end local function Debug_textrange(s,e) return spawner.utf8_to_ans(editor:textrange(s, e)) end local function Debug_TextLength() return editor.TextLength end local function Debug_string_find(str, pst, pos) local bp, ep = string.find(str, pst, pos) return {bp, ep} end local function Debug_utf8toAns(str) return spawner.utf8_to_ans(str) end local function Debug_LexerLanguage() return editor.LexerLanguage end local CWSHIfObj = { { obj = "Editor", member = { { Editor_Replace , "Replace" , { VT_BSTR , VT_BSTR , VT_I4 , VT_EMPTY } , VT_EMPTY } , { Editor_GetTbl , "GetTbl" , { VT_I4 , VT_BSTR , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Editor_SelectAll , "SelectAll" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_EMPTY } , { Editor_IsTextSelected , "IsTextSelected" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_I4 } , { Editor_GetFilename , "GetFilename" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Editor_GetSelectLineFrom , "GetSelectLineFrom" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_I4 } , { Editor_GetSelectLineTo , "GetSelectLineTo" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_I4 } , { Editor_FileOpen , "FileOpen" , { VT_BSTR , VT_I4 , VT_I4 , VT_BSTR } , VT_EMPTY } , { Editor_ExpandParameter , "ExpandParameter" , { VT_BSTR , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Editor_GetLineCount , "GetLineCount" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_I4 } , { Editor_GetLineStr , "GetLineStr" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Editor_InsText , "InsText" , { VT_BSTR , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_EMPTY } , { Editor_AddTail , "AddTail" , { VT_BSTR , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_EMPTY } , { Editor_GetSelectedString , "GetSelectedString" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Editor_ReDraw , "ReDraw" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_EMPTY } } }, { obj = "Debug", member = { { Debug_utf8toAns , "utf8toAns" , { VT_BSTR , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Debug_string_find , "string_find" , { VT_BSTR , VT_BSTR , VT_I4 , VT_EMPTY } , VT_ARRAY | VT_VARIANT } , { Debug_StyleAt , "StyleAt" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_I4 } , { Debug_CharAt , "CharAt" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Debug_textrange , "textrange" , { VT_I4 , VT_I4 , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Debug_LexerLanguage , "LexerLanguage" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_BSTR } , { Debug_TextLength , "TextLength" , { VT_EMPTY , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_I4 } } }, { obj = "os", member = { { os_msleep , "msleep" , { VT_I4 , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_EMPTY } } }, { obj = "Output", member = { { Output_print , "print" , { VT_BSTR , VT_EMPTY , VT_EMPTY , VT_EMPTY } , VT_EMPTY } } }, { obj = "WScript", member = { { WScript_Echo, "Echo", { VT_BSTR, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_EMPTY}, { WScript_Echo, "echo", { VT_BSTR, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_EMPTY}, { WScript_Quit, "Quit", { VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_EMPTY} } }, { obj = "Mcro1", member = { { lua_GetMacroInfor, "GetMacroInfor", { VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_BSTR}, { lua_GetMacroVersion, "GetMacroVersion", { VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_BSTR} } }, { obj = "Mcro2", member = { { lua_GetTest, "GetTest", { VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_ARRAY | VT_VARIANT }, { lua_getdir, "getdir", { VT_EMPTY, VT_EMPTY, VT_EMPTY, VT_EMPTY }, VT_BSTR} } } } spawner.setFuncOfJscript(CWSHIfObj) end scite_OnInit(function(order1, order2) if order1 == 0 and order2 == 0 then jscript_setting() end return false end) scite_OnFinalise(function(level1, level2) if level1 == 1 then spawner.clearJscript(0) end return false end) local function set_utf8code(t) local proxy = {} -- proxy table for 't' local mt = { __index = function(_, k) --print("*access to element " .. tostring(k)) -- return ( t[k] and ( (k-1) .. ':' .. t[k] ) or nil ) -- access the original table return ( t[k] and ( (k-1) .. ':' .. spawner.ans_to_utf8(t[k]) ) or nil ) -- access the original table end, __len = function()return #t end, } setmetatable(proxy, mt) return proxy end function jscript_list() local now_path= props['FileDir'] .. '\\' local jscript_path = ( os.getenv"SAKURA_SCRIPT" ) .. '\\' -- jscript_path = props['SciteDefaultHome'] .. '\\script\\jscript\\' local js_list_now = scite_Files(now_path .. '*.js') local vbs_list_now = scite_Files(now_path .. '*.vbs') local js_list = scite_Files(jscript_path .. '*.js') local vbs_list = scite_Files(jscript_path .. '*.vbs') local all_list={} local all_utf8list=set_utf8code(all_list) for _,v in ipairs(js_list_now) do -- print(v) table.insert(all_list, v) end for _,v in ipairs(vbs_list_now) do -- print(v) table.insert(all_list, v) end for _,v in ipairs(js_list) do -- print(v) table.insert(all_list, v) end for _,v in ipairs(vbs_list) do -- print(v) table.insert(all_list, v) end local idx =1 scite_UserListShow(all_utf8list, idx, function(s) -- print( 'spawner.runJscript(s):' .. s ) local _, p = s:match('^(%d+):(.*)$') spawner.runJscript(spawner.utf8_to_ans(p)) -- spawner.runJscript(s) -- print( 'to ' .. s .. '@:' .. editor.FirstVisibleLine ) return true end) end