Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---@diagnostic disable: unused-local
- local file=assert(io.open('/home/user/.local/state/nvim/undo/%home%user%.config%nvim%init.lua'))
- local function get(n)
- return file:read(n)
- end
- local function nget(n)
- --NOTE: this will always return a signed integer,
- -- while the actual implementation may return an unsigned integer
- local ret=0
- for i in get(n):gmatch'.' do
- ret=ret*256+string.byte(i)
- end
- return ret
- end
- --Header
- assert(get(9)=='Vim\x9fUnDo\xe5')
- local version=nget(2)
- assert(version==3)
- local hash=get(32)
- local line_count=nget(4)
- -- "U" command data
- local str_len=nget(4)
- local line_ptr=get(str_len)
- local U_lnum=nget(4)
- local U_colnr=nget(4)
- -- Header
- local old_header_seq=nget(4)
- local new_header_seq=nget(4)
- local cur_header_seq=nget(4)
- local num_head=nget(4)
- local seq_last=nget(4)
- local seq_cur=get(4)
- local seq_time=nget(8)
- local last_save_nr=0
- while true do
- local len=nget(1)
- if len==0 then break end
- local what=nget(1)
- if what==1 then
- assert(len==4)
- last_save_nr=nget(4)
- else
- -- Field not supported, read and discard
- for _=1,len do get(1) end
- end
- end
- local function unserialize()
- local function pos_read(t)
- t.pos_lnum=nget(4)
- t.pos_col=nget(4)
- t.pos_coladd=nget(4)
- end
- local uhp={}
- uhp.next_seq=nget(4)
- uhp.prev_seq=nget(4)
- uhp.alt_next_seq=nget(4)
- uhp.alt_prev_seq=nget(4)
- uhp.seq=nget(4)
- pos_read(uhp)
- uhp.cursor_vcol=nget(4)
- uhp.flags=nget(2)
- uhp.marks=vim.defaulttable(function () return {} end)
- local time=os.time()
- for i=1,26 do
- pos_read(uhp.marks[i])
- uhp.marks[i].timestamp=time
- uhp.marks[i].fnum=0
- end
- uhp.vi_start={}
- pos_read(uhp.vi_start)
- uhp.vi_end={}
- pos_read(uhp.vi_end)
- uhp.vi_mode=nget(4)
- uhp.vi_curswant=nget(4)
- uhp.time=nget(8)
- while true do
- local len=nget(1)
- if len==0 then break end
- local what=nget(1)
- if what==1 then
- assert(len==4)
- uhp.save_nr=nget(4)
- else
- -- Field not supported, read and discard
- for _=1,len do get(1) end
- end
- end
- local last_uep
- local m
- while true do
- m=get(2)
- if m~='\xf5\x18' then break end
- local uep={}
- uep.top=nget(4)
- uep.bot=nget(4)
- uep.lcount=nget(4)
- uep.size=nget(4)
- uep.array={}
- for i=1,uep.size do
- local line_len=nget(4)
- local line=get(line_len)
- uep.array[i]=line
- end
- if not last_uep then
- uhp.entry=uep
- else
- last_uep.next=uep
- end
- last_uep=uep
- end
- assert(m=='\x35\x81')
- while true do
- m=get(2)
- if m~='\xf5\x18' then break end
- local ext={}
- local type=nget(4)
- ext.type=type
- if type==0 then
- ext.raw_data=get(48)
- elseif type==1 then
- ext.raw_data=get(48)
- else error'' end
- end
- assert(m=='\x35\x81')
- return uhp
- end
- local uhps={}
- local m
- while true do
- m=get(2)
- if m~='\x5f\xd0' then break end
- table.insert(uhps,unserialize())
- end
- assert(#uhps==num_head)
- assert(m=='\xe7\xaa')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement