--[[-------------------------------------------------- RestoreRecent.lua Authors: mozers™ Version: 1.0 ------------------------------------------------------ Description: Restore position, bookmarks, folds at opening recent file Восстанавливает позицию курсора, букмарки и фолдинг при повторном открытии файла (если ранее он открывался в течении предыдущей сессии). Почему этого функционала нет в ядре SciTE? - совершенно непонятно ------------------------------------------------------ Connection: In file SciTEStartup.lua add a line: dofile (props["SciteDefaultHome"].."\\tools\\RestoreRecent.lua") --]]-------------------------------------------------- local buffers={} local function ReadSession() local session_file = io.open(props['SciteUserHome']..'\\SciTE.session') if session_file then local pattern = "buffer%.(%d+)%.(%a+)=(.+)" for line in session_file:lines() do if #line > 10 then local n, p, v = string.match (line, pattern) if n ~= nil then n = tonumber(n) if buffers[n] == nil then buffers[n] = {} end buffers[n][p] = v end end end session_file:close() end end ReadSession() local function CheckSession() for i = 1, #buffers do if buffers[i]['path'] == props['FilePath'] then return buffers[i] end end end local function Restore(file) local FileParams = CheckSession() if FileParams ~= nil then print(file.." - YES") -- Restore position if tonumber(props['save.position']) == 1 then local pos = FileParams['position'] if pos ~= nil then editor:GotoPos(pos) end end -- Restore bookmarks if tonumber(props['session.bookmarks']) == 1 then local bookmarks = FileParams['bookmarks'] if bookmarks ~= nil then for line_num in string.gmatch(bookmarks, "%d+") do editor:MarkerAdd(tonumber(line_num)-1, 1) end end end -- Restore folds if tonumber(props['session.folds']) == 1 then local folds = FileParams['folds'] if folds ~= nil then for line_num in string.gmatch(folds, "%d+") do editor:ToggleFold(tonumber(line_num)-1) -- При открытии файла эта команда не срабатывает !!! (Баг SciTE ???) end end end else print(file.." - NO") end end -- Add user event handler OnOpen local old_OnOpen = OnOpen function OnOpen(file) local result if old_OnOpen then result = old_OnOpen(file) end if tonumber(props['save.session']) == 1 then Restore(file) end return result end |