hinter: use same hint for all occurrences of match
This patch changes the hinter to use the same hint for all occurrences of a match, thereby reducing the need to use multi-character hints and also eliminating redundant hints to simplify the user's hint decision.
This commit is contained in:
parent
ca1db9af26
commit
b10ea7791c
|
@ -1,7 +1,5 @@
|
|||
BEGIN {
|
||||
n_matches = 0;
|
||||
line_pos = 0;
|
||||
col_pos = 0;
|
||||
COMPACT_HINTS = ENVIRON["COMPACT_HINTS"];
|
||||
|
||||
HINTS[0] = "p"
|
||||
|
@ -121,50 +119,37 @@ BEGIN {
|
|||
}
|
||||
|
||||
{
|
||||
line = $0;
|
||||
pos = 0;
|
||||
col_pos = 0;
|
||||
col_pos_correction = 0;
|
||||
|
||||
output_line = line;
|
||||
output_line = $0;
|
||||
|
||||
# insert hints into `output_line` and accumulate hints in `hint_lookup`
|
||||
line = output_line;
|
||||
pos = col_pos_correction = 0;
|
||||
while (match(line, finger_patterns)) {
|
||||
n_matches += 1;
|
||||
|
||||
hint = HINTS[n_matches - 1]
|
||||
pos += RSTART;
|
||||
|
||||
col_pos = pos;
|
||||
|
||||
col_pos = pos + col_pos_correction
|
||||
pre_match = substr(output_line, 0, col_pos - 1);
|
||||
post_match = substr(output_line, col_pos + RLENGTH, length(line) - 1);
|
||||
line_match = substr(line, RSTART, RLENGTH);
|
||||
full_line_match = line_match
|
||||
|
||||
hint = hint_by_match[line_match]
|
||||
if (!hint) {
|
||||
hint = HINTS[n_matches++]
|
||||
hint_by_match[line_match] = hint
|
||||
}
|
||||
hint_lookup = hint_lookup hint ":" line_match "\n"
|
||||
|
||||
if (COMPACT_HINTS) {
|
||||
hint_len = length(hint)
|
||||
line_match = substr(line_match, hint_len + 1, length(line_match) - hint_len);
|
||||
}
|
||||
|
||||
col_pos = col_pos + col_pos_correction
|
||||
|
||||
line_pos = NR;
|
||||
|
||||
pre_match = substr(output_line, 0, col_pos - 1);
|
||||
|
||||
if (COMPACT_HINTS) {
|
||||
hint_match = sprintf(compound_format, hint, line_match);
|
||||
} else {
|
||||
hint_match = sprintf(compound_format, line_match, hint);
|
||||
}
|
||||
|
||||
post_match = substr(output_line, col_pos + RLENGTH, length(line) - 1);
|
||||
|
||||
output_line = pre_match hint_match post_match;
|
||||
|
||||
line = post_match;
|
||||
|
||||
col_pos_correction += length(sprintf(highlight_format, line_match)) + length(sprintf(hint_format, hint)) - 1;
|
||||
|
||||
hint_lookup = hint_lookup hint ":" full_line_match "\n"
|
||||
line = post_match;
|
||||
}
|
||||
|
||||
printf "\n%s", output_line
|
||||
|
|
Loading…
Reference in New Issue