digraphs: prepare target characters as strings
[sheet.git] / tools / mkdigraphs-vim
1 #!/bin/sh
2
3 VERSION=1.01
4
5 vim -e -c'echo version' -cdigraphs -cq | perl -CSD -nE '
6         if ($. == 1) { # head
7                 say "# digraphs list from vim version ", s/\s*\z//r;
8                 say "+{";
9         } else { # body
10                 while (/\G(\S\S) (.[^ ]*) +([0-9]+)\s+/g) {
11                         my ($mnem, $chr, $cp) = ($1, $2, $3);
12                         $mnem =~ s/(?=[\\}])/\\/g;  # escape string delimiter
13                         $chrstr = sprintf q("\x{%x}"), $cp;
14                         say "q{$mnem} => $chrstr,";
15                 }
16         } END { # foot
17                 say "}";
18                 exit warn "only $. lines of :digraphs output\n" if $. < 6;
19         }
20 '