Advertisement
Guest User

Untitled

a guest
Apr 25th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. ---@diagnostic disable: unused-local
  2. local file=assert(io.open('/home/user/.local/state/nvim/undo/%home%user%.config%nvim%init.lua'))
  3. local function get(n)
  4. return file:read(n)
  5. end
  6. local function nget(n)
  7. --NOTE: this will always return a signed integer,
  8. -- while the actual implementation may return an unsigned integer
  9. local ret=0
  10. for i in get(n):gmatch'.' do
  11. ret=ret*256+string.byte(i)
  12. end
  13. return ret
  14. end
  15. --Header
  16. assert(get(9)=='Vim\x9fUnDo\xe5')
  17. local version=nget(2)
  18. assert(version==3)
  19. local hash=get(32)
  20. local line_count=nget(4)
  21. -- "U" command data
  22. local str_len=nget(4)
  23. local line_ptr=get(str_len)
  24. local U_lnum=nget(4)
  25. local U_colnr=nget(4)
  26. -- Header
  27. local old_header_seq=nget(4)
  28. local new_header_seq=nget(4)
  29. local cur_header_seq=nget(4)
  30. local num_head=nget(4)
  31. local seq_last=nget(4)
  32. local seq_cur=get(4)
  33. local seq_time=nget(8)
  34. local last_save_nr=0
  35. while true do
  36. local len=nget(1)
  37. if len==0 then break end
  38. local what=nget(1)
  39. if what==1 then
  40. assert(len==4)
  41. last_save_nr=nget(4)
  42. else
  43. -- Field not supported, read and discard
  44. for _=1,len do get(1) end
  45. end
  46. end
  47. local function unserialize()
  48. local function pos_read(t)
  49. t.pos_lnum=nget(4)
  50. t.pos_col=nget(4)
  51. t.pos_coladd=nget(4)
  52. end
  53. local uhp={}
  54. uhp.next_seq=nget(4)
  55. uhp.prev_seq=nget(4)
  56. uhp.alt_next_seq=nget(4)
  57. uhp.alt_prev_seq=nget(4)
  58. uhp.seq=nget(4)
  59. pos_read(uhp)
  60. uhp.cursor_vcol=nget(4)
  61. uhp.flags=nget(2)
  62. uhp.marks=vim.defaulttable(function () return {} end)
  63. local time=os.time()
  64. for i=1,26 do
  65. pos_read(uhp.marks[i])
  66. uhp.marks[i].timestamp=time
  67. uhp.marks[i].fnum=0
  68. end
  69. uhp.vi_start={}
  70. pos_read(uhp.vi_start)
  71. uhp.vi_end={}
  72. pos_read(uhp.vi_end)
  73. uhp.vi_mode=nget(4)
  74. uhp.vi_curswant=nget(4)
  75. uhp.time=nget(8)
  76. while true do
  77. local len=nget(1)
  78. if len==0 then break end
  79. local what=nget(1)
  80. if what==1 then
  81. assert(len==4)
  82. uhp.save_nr=nget(4)
  83. else
  84. -- Field not supported, read and discard
  85. for _=1,len do get(1) end
  86. end
  87. end
  88. local last_uep
  89. local m
  90. while true do
  91. m=get(2)
  92. if m~='\xf5\x18' then break end
  93. local uep={}
  94. uep.top=nget(4)
  95. uep.bot=nget(4)
  96. uep.lcount=nget(4)
  97. uep.size=nget(4)
  98. uep.array={}
  99. for i=1,uep.size do
  100. local line_len=nget(4)
  101. local line=get(line_len)
  102. uep.array[i]=line
  103. end
  104. if not last_uep then
  105. uhp.entry=uep
  106. else
  107. last_uep.next=uep
  108. end
  109. last_uep=uep
  110. end
  111. assert(m=='\x35\x81')
  112. while true do
  113. m=get(2)
  114. if m~='\xf5\x18' then break end
  115. local ext={}
  116. local type=nget(4)
  117. ext.type=type
  118. if type==0 then
  119. ext.raw_data=get(48)
  120. elseif type==1 then
  121. ext.raw_data=get(48)
  122. else error'' end
  123. end
  124. assert(m=='\x35\x81')
  125. return uhp
  126. end
  127. local uhps={}
  128. local m
  129. while true do
  130. m=get(2)
  131. if m~='\x5f\xd0' then break end
  132. table.insert(uhps,unserialize())
  133. end
  134. assert(#uhps==num_head)
  135. assert(m=='\xe7\xaa')
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement