completions: make: respect line continuations in recipes

Without this, a recipe containing a trailing backslash followed by a line not
beginning with tab (like any non-continued recipe lines would) would result in
the continuation showing up in completions.

Whenever a line ends in a backslash, consider the next line invalid as a target.

Regex explanation:

^([^#]*[^#\\])? -- optional prefix not containing comment character and not
                   ending in backslash
(\\\\)*\\$      -- 2n+1 backslashes at end of line (handles escaped backslashes)
This commit is contained in:
Xiretza 2023-08-23 21:42:54 +00:00 committed by Fabian Boehm
parent 676c3c9bc2
commit fff320b56b

View file

@ -12,9 +12,13 @@ function __fish_print_make_targets --argument-names directory file
if make --version 2>/dev/null | string match -q 'GNU*'
# https://stackoverflow.com/a/26339924
make $makeflags -pRrq : 2>/dev/null |
awk -F: '/^# Files/,/^# Finished Make data base/ {
awk -F: -v 'bs_regex=\\\\\\\\' '/^# Files/,/^# Finished Make data base/ {
if ($1 == "# Not a target") skip = 1;
if ($1 !~ "^[#.\t]") { if (!skip) print $1; skip=0 }
if ($1 !~ "^[#.\t]" && !is_continuation ) {
if (!skip) print $1;
skip = 0
}
is_continuation = $0 ~ "^([^#]*[^#" bs_regex "])?(" bs_regex bs_regex ")*" bs_regex "$";
}' 2>/dev/null
else
# BSD make