--▽▽UTF-8▽▽ --switch_buffers.lua --drops down a list of buffers, in recently-used order scite_Command { 'Buffer list|do_buffer_list|Ctrl+K|Context', } ------------------------------------------------------------------- --local act_valid = false local my_path = lua_LoadPath() local buffers = {} scite_OnInit(function(order1, order2) props['SciteBufferSwitch'] = '1' if order1 == 0 and order2 == 0 then local f = io.open(my_path.."/SciteBufferSwitch.cnf", "r") if not f then return false end local size = 0 for line in f:lines()do local field, Value = line:match('^([^=]+)=(.*)$') if field then if field == 'size' then size = tonumber(Value) else local ind = tonumber(field) table.insert(buffers, Value) end end end f:close() end return false end) scite_OnFinalise(function(level1, level2) props['SciteBufferSwitch'] = '0' if level1 == 1 then local f = io.open(my_path.."/SciteBufferSwitch.cnf", "w") if not f then return false end f:write('size='..#buffers..'\n') for i, file in ipairs(buffers)do f:write(i..'='..file..'\n') end f:close() end return false end) local function buffer_switch(f) --- swop the new current buffer with the last one! if scite_GetPropBool('SciteBufferSwitch', false) and f~="" then local idx for i, file in ipairs(buffers)do if file == f then idx = i; break end end if idx then table.remove(buffers, idx) table.insert(buffers, 1, f) else --append(buffers,f) table.insert(buffers, 1, f) end end end scite_OnOpen(buffer_switch) scite_OnSwitchFile(buffer_switch) function do_buffer_list() local idx =1 local FileName = props['FileName'] --show from 2 start if FileName~="" then idx=2 end scite_UserListShow(buffers, idx, function(s) scite.Open(s) return true end) end function allow_buffer_list(value) if value then props['SciteBufferSwitch'] = '1' else props['SciteBufferSwitch'] = '0' end end