blob: 1211ae9c4ea4954f1dd493284a87c28e9db1cbfe [file] [log] [blame]
Aliaksei Budavei6bff6a22024-08-19 21:33:26 +02001vim9script
2
3# (Script-local.)
4#
5# Render a loaded screendump file or the difference of a loaded screendump
6# file and its namesake file from the "dumps" directory.
7def Render()
8 const failed_fname: string = bufname()
9 try
10 setlocal suffixesadd=.dump
11 const dumps_fname: string = findfile(
12 fnamemodify(failed_fname, ':p:t'),
13 fnamemodify(failed_fname, ':p:h:h') .. '/dumps')
14 if filereadable(dumps_fname)
15 term_dumpdiff(failed_fname, dumps_fname)
16 else
17 term_dumpload(failed_fname)
18 endif
19 finally
20 exec 'bwipeout ' .. failed_fname
21 endtry
22enddef
23
24# Search for the "failed" directory in the passed _subtreedirname_ directories
25# (usually "\<src\>" or "\<syntax\>") and, if found, select its passed _count_
zeertzjq8feed3a2024-09-29 10:37:47 +020026# occurrence, add all its "*.dump" files to the argument list and list them;
Aliaksei Budavei6bff6a22024-08-19 21:33:26 +020027# also define a BufRead autocommand that would invoke "Render()" for every
28# "*.dump" file.
29def g:Init(subtreedirname: string, count: number)
30 # Support sourcing this script from any directory in the direct path that
31 # leads to the project's root directory.
32 const failed_path: string = finddir('failed', getcwd() .. '/**', -1)
33 ->filter(((cwdpath: string, parentdirname: string) =>
34 (_: number, dirpath: string) =>
35 cwdpath =~ parentdirname || dirpath =~ parentdirname)(
36 getcwd(),
37 subtreedirname))
38 ->get(count, '') .. '/'
39 var error: string = null_string
40
41 if failed_path == '/'
42 error = 'No such directory: "failed"'
43 else
44 const failed_fnames: string = failed_path .. readdir(failed_path,
45 (fname: string) => fname =~ '^.\+\.dump$')
46 ->join(' ' .. failed_path)
47
48 if failed_fnames =~ 'failed/$'
49 error = 'No such file: "*.dump"'
50 else
51 exec ':0argedit ' .. failed_fnames
52 buffers
53 endif
54 endif
55
56 autocmd_add([{
57 replace: true,
58 group: 'viewdumps',
59 event: 'BufRead',
60 pattern: '*.dump',
61 cmd: 'Render()',
62 }])
63
64 # Unconditionally help, in case a list of filenames is passed to the
65 # command, the first terminal window with its BufRead event.
66 silent doautocmd viewdumps BufRead
67
68 if error != null_string
69 # Instead of sleeping, fill half a window with blanks and prompt
70 # hit-enter.
71 echom error .. repeat("\x20",
72 (winwidth(0) * (winheight(0) / 2) - strlen(error)))
73 endif
74enddef
75
zeertzjq3e5bbb82024-10-22 23:11:27 +020076# vim:fdm=syntax:sw=2:ts=8:noet:nosta: