Aliaksei Budavei | d33afe1 | 2024-08-12 18:37:15 +0200 | [diff] [blame] | 1 | vim9script |
| 2 | |
| 3 | # Support sourcing this script from this directory or any other directory in |
| 4 | # the direct path that leads to the project's root directory. |
| 5 | const failed_path: string = finddir('failed', getcwd() .. '/**', -1) |
| 6 | ->filter(((cwdpath: string) => (_: number, dirpath: string) => |
| 7 | cwdpath =~ '\<syntax\>' || dirpath =~ '\<syntax\>')(getcwd())) |
| 8 | ->get(-1, '') .. '/' |
| 9 | var error: string = null_string |
| 10 | |
| 11 | if failed_path == '/' |
| 12 | error = 'No such directory: "failed"' |
| 13 | else |
| 14 | const failed_fnames: string = failed_path .. readdir(failed_path, |
| 15 | (fname: string) => fname =~ '^.\+\.dump$') |
| 16 | ->join(' ' .. failed_path) |
| 17 | |
| 18 | if failed_fnames =~ 'failed/$' |
| 19 | error = 'No such file: "*.dump"' |
| 20 | else |
| 21 | exec ':0argedit ' .. failed_fnames |
| 22 | buffers |
| 23 | endif |
| 24 | endif |
| 25 | |
| 26 | def Render() |
| 27 | const failed_fname: string = bufname() |
| 28 | try |
| 29 | setlocal suffixesadd=.dump |
| 30 | const dumps_fname: string = findfile( |
| 31 | fnamemodify(failed_fname, ':p:t'), |
| 32 | fnamemodify(failed_fname, ':p:h:h') .. '/dumps') |
| 33 | if filereadable(dumps_fname) |
| 34 | term_dumpdiff(failed_fname, dumps_fname) |
| 35 | else |
| 36 | term_dumpload(failed_fname) |
| 37 | endif |
| 38 | finally |
| 39 | exec 'bwipeout ' .. failed_fname |
| 40 | endtry |
| 41 | enddef |
| 42 | |
| 43 | # THE FOLLOWING SETTINGS PERTAIN TO "input/" FILES THAT ARE LIKELY TO BE |
| 44 | # LOADED SIDE BY SIDE WHENEVER BATCHES OF NEW SCREENDUMPS ARE GENERATED. |
| 45 | |
| 46 | # Match "LC_ALL=C" of Makefile. |
| 47 | language C |
| 48 | |
| 49 | # Match the settings from term_util.vim#RunVimInTerminal(). |
| 50 | set t_Co=256 background=light |
| 51 | hi Normal ctermfg=NONE ctermbg=NONE |
| 52 | |
| 53 | # Match the settings from runtest.vim#Xtestscript#SetUpVim(). |
| 54 | set display=lastline ruler scrolloff=5 t_ZH= t_ZR= |
| 55 | |
| 56 | # Anticipate non-Latin-1 characters in "input/" files. |
| 57 | set encoding=utf-8 termencoding=utf-8 |
| 58 | |
| 59 | autocmd_add([{ |
| 60 | replace: true, |
| 61 | group: 'viewdumps', |
| 62 | event: 'BufRead', |
| 63 | pattern: '*.dump', |
| 64 | cmd: 'Render()', |
| 65 | }]) |
| 66 | |
| 67 | # Unconditionally help, in case a list of filenames is passed to the command, |
| 68 | # the first terminal window with its BufRead event. |
| 69 | silent doautocmd viewdumps BufRead |
| 70 | |
| 71 | if error != null_string |
| 72 | # Instead of sleeping, fill half a window with blanks and prompt hit-enter. |
| 73 | echom error .. repeat("\x20", (winwidth(0) * (winheight(0) / 2) - strlen(error))) |
| 74 | error = null_string |
| 75 | endif |
| 76 | |
| 77 | # vim:fdm=syntax:sw=2:ts=8:noet:nolist:nosta: |