mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-03 10:21:46 +02:00
27429: _make: restore variable value completion
make indentation more standard
This commit is contained in:
parent
b97284cde2
commit
85842387f8
2 changed files with 174 additions and 171 deletions
|
@ -1,5 +1,8 @@
|
|||
2009-11-24 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 27429: Completion/Unix/Command/_make: restore variable value
|
||||
completion. Also make indentation more standard (not posted).
|
||||
|
||||
* Michael Hwang <michael.a.hwang@gmail.com>: 27428:
|
||||
Completion/Unix/Command/_make: complete rewrite with
|
||||
variable completion.
|
||||
|
@ -12387,5 +12390,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.4821 $
|
||||
* $Revision: 1.4822 $
|
||||
*****************************************************
|
||||
|
|
|
@ -7,210 +7,210 @@ local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
|
|||
local -A TARGETS VARIABLES
|
||||
|
||||
expandVars() {
|
||||
local open close var val front ret tmp=$1
|
||||
local open close var val front ret tmp=$1
|
||||
|
||||
front=${tmp%%\$*}
|
||||
case $tmp in
|
||||
(\(*) # Variable of the form $(foobar)
|
||||
open='('
|
||||
close=')'
|
||||
;;
|
||||
front=${tmp%%\$*}
|
||||
case $tmp in
|
||||
(\(*) # Variable of the form $(foobar)
|
||||
open='('
|
||||
close=')'
|
||||
;;
|
||||
|
||||
({*) # ${foobar}
|
||||
open='{'
|
||||
close='}'
|
||||
;;
|
||||
({*) # ${foobar}
|
||||
open='{'
|
||||
close='}'
|
||||
;;
|
||||
|
||||
([[:alpha:]]*) # $foobar. This is exactly $(f)oobar.
|
||||
open=''
|
||||
close=''
|
||||
var=${(s::)var[1]}
|
||||
;;
|
||||
([[:alpha:]]*) # $foobar. This is exactly $(f)oobar.
|
||||
open=''
|
||||
close=''
|
||||
var=${(s::)var[1]}
|
||||
;;
|
||||
|
||||
(\$*) # Escaped $.
|
||||
print -- "${front}\$$(expandVars ${tmp#\$})"
|
||||
return
|
||||
;;
|
||||
(\$*) # Escaped $.
|
||||
print -- "${front}\$$(expandVars ${tmp#\$})"
|
||||
return
|
||||
;;
|
||||
|
||||
(*) # Nothing left to substitute.
|
||||
print -- $tmp
|
||||
return
|
||||
;;
|
||||
esac
|
||||
(*) # Nothing left to substitute.
|
||||
print -- $tmp
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ -n $open ]]
|
||||
then
|
||||
var=${tmp#$open}
|
||||
var=${var%%$close*}
|
||||
fi
|
||||
if [[ -n $open ]]
|
||||
then
|
||||
var=${tmp#$open}
|
||||
var=${var%%$close*}
|
||||
fi
|
||||
|
||||
case $var in
|
||||
([[:alnum:]_]#)
|
||||
val=${VARIABLES[$var]}
|
||||
ret=${ret//\$$open$var$close/$val}
|
||||
;;
|
||||
case $var in
|
||||
([[:alnum:]_]#)
|
||||
val=${VARIABLES[$var]}
|
||||
ret=${ret//\$$open$var$close/$val}
|
||||
;;
|
||||
|
||||
(*) # Improper variable name. No replacement. I'm not sure if this is desired behavior.
|
||||
front+="\$$open$var$close"
|
||||
ret=${ret/\$$open$var$close/}
|
||||
;;
|
||||
esac
|
||||
(*)
|
||||
# Improper variable name. No replacement.
|
||||
# I'm not sure if this is desired behavior.
|
||||
front+="\$$open$var$close"
|
||||
ret=${ret/\$$open$var$close/}
|
||||
;;
|
||||
esac
|
||||
|
||||
print -- "${front}$(expandVars ${ret})"
|
||||
print -- "${front}$(expandVars ${ret})"
|
||||
}
|
||||
|
||||
parseMakefile () {
|
||||
local input var val target dep TAB=$'\t' dir=$1 tmp
|
||||
local input var val target dep TAB=$'\t' dir=$1 tmp
|
||||
|
||||
while read input
|
||||
do
|
||||
case "$input " in
|
||||
# VARIABLE = value
|
||||
([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
|
||||
var=${input%%[ $TAB]#=*}
|
||||
val=${input#*=}
|
||||
val=${val##[ $TAB]#}
|
||||
VARIABLES[$var]=$val
|
||||
;;
|
||||
while read input
|
||||
do
|
||||
case "$input " in
|
||||
# VARIABLE = value
|
||||
([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
|
||||
var=${input%%[ $TAB]#=*}
|
||||
val=${input#*=}
|
||||
val=${val##[ $TAB]#}
|
||||
VARIABLES[$var]=$val
|
||||
;;
|
||||
|
||||
# VARIABLE := value
|
||||
# Evaluated immediately
|
||||
([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
|
||||
var=${input%%[ $TAB]#:=*}
|
||||
val=${input#*=}
|
||||
val=${val##[ $TAB]#}
|
||||
val=$(expandVars $val)
|
||||
VARIABLES[$var]=$val
|
||||
;;
|
||||
# VARIABLE := value
|
||||
# Evaluated immediately
|
||||
([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
|
||||
var=${input%%[ $TAB]#:=*}
|
||||
val=${input#*=}
|
||||
val=${val##[ $TAB]#}
|
||||
val=$(expandVars $val)
|
||||
VARIABLES[$var]=$val
|
||||
;;
|
||||
|
||||
# TARGET: dependencies
|
||||
# TARGET1 TARGET2 TARGET3: dependencies
|
||||
([[:alnum:]][^$TAB:=]#:[^=]*)
|
||||
input=$(expandVars $input)
|
||||
target=${input%%:*}
|
||||
dep=${input#*:}
|
||||
dep=${(z)dep}
|
||||
dep="$dep"
|
||||
for tmp in ${(z)target}
|
||||
do
|
||||
TARGETS[$tmp]=$dep
|
||||
done
|
||||
;;
|
||||
# TARGET: dependencies
|
||||
# TARGET1 TARGET2 TARGET3: dependencies
|
||||
([[:alnum:]][^$TAB:=]#:[^=]*)
|
||||
input=$(expandVars $input)
|
||||
target=${input%%:*}
|
||||
dep=${input#*:}
|
||||
dep=${(z)dep}
|
||||
dep="$dep"
|
||||
for tmp in ${(z)target}
|
||||
do
|
||||
TARGETS[$tmp]=$dep
|
||||
done
|
||||
;;
|
||||
|
||||
# Include another makefile
|
||||
(${~incl} *)
|
||||
local f=${input##${~incl} ##}
|
||||
if [[ $incl == '.include' ]]
|
||||
then
|
||||
f=${f#[\"<]}
|
||||
f=${f%[\">]}
|
||||
fi
|
||||
f=$(expandVars $f)
|
||||
case $f in
|
||||
(/*) ;;
|
||||
(*) f=$dir/$f ;;
|
||||
esac
|
||||
# Include another makefile
|
||||
(${~incl} *)
|
||||
local f=${input##${~incl} ##}
|
||||
if [[ $incl == '.include' ]]
|
||||
then
|
||||
f=${f#[\"<]}
|
||||
f=${f%[\">]}
|
||||
fi
|
||||
f=$(expandVars $f)
|
||||
case $f in
|
||||
(/*) ;;
|
||||
(*) f=$dir/$f ;;
|
||||
esac
|
||||
|
||||
if [[ -r $f ]]
|
||||
then
|
||||
parseMakefile ${f%%/[^/]##} < $f
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [[ -r $f ]]
|
||||
then
|
||||
parseMakefile ${f%%/[^/]##} < $f
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
findBasedir () {
|
||||
local file index basedir
|
||||
basedir=$PWD
|
||||
for (( index=0; index < $#@; index++ ))
|
||||
do
|
||||
if [[ $@[index] == -C ]]
|
||||
then
|
||||
file=${~@[index+1]};
|
||||
if [[ -z $file ]]
|
||||
then
|
||||
# make returns with an error if an empty arg is given
|
||||
# even if the concatenated path is a valid directory
|
||||
return
|
||||
elif [[ $file == /* ]]
|
||||
then
|
||||
# Absolute path, replace base directory
|
||||
basedir=$file
|
||||
else
|
||||
# Relative, concatenate path
|
||||
basedir=$basedir/$file
|
||||
fi
|
||||
fi
|
||||
done
|
||||
print -- $basedir
|
||||
local file index basedir
|
||||
basedir=$PWD
|
||||
for (( index=0; index < $#@; index++ ))
|
||||
do
|
||||
if [[ $@[index] == -C ]]
|
||||
then
|
||||
file=${~@[index+1]};
|
||||
if [[ -z $file ]]
|
||||
then
|
||||
# make returns with an error if an empty arg is given
|
||||
# even if the concatenated path is a valid directory
|
||||
return
|
||||
elif [[ $file == /* ]]
|
||||
then
|
||||
# Absolute path, replace base directory
|
||||
basedir=$file
|
||||
else
|
||||
# Relative, concatenate path
|
||||
basedir=$basedir/$file
|
||||
fi
|
||||
fi
|
||||
done
|
||||
print -- $basedir
|
||||
}
|
||||
|
||||
_pick_variant -r is_gnu gnu=GNU unix -v -f
|
||||
|
||||
if [[ $is_gnu == gnu ]]
|
||||
then
|
||||
incl="(-|)include"
|
||||
incl="(-|)include"
|
||||
else
|
||||
incl=.include
|
||||
incl=.include
|
||||
fi
|
||||
|
||||
if [[ "$prev" == -[CI] ]]
|
||||
then
|
||||
_files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/
|
||||
_files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/
|
||||
elif [[ "$prev" == -[foW] ]]
|
||||
then
|
||||
_files -W ${(q)$(findBasedir $words)}
|
||||
_files -W ${(q)$(findBasedir $words)}
|
||||
else
|
||||
file="$words[(I)-f]"
|
||||
if (( file ))
|
||||
then
|
||||
file=${~words[file+1]}
|
||||
[[ $file == [^/]* ]] && file=${(q)$(findBasedir $words)}/$file
|
||||
[[ -r $file ]] || file=
|
||||
else
|
||||
local basedir
|
||||
basedir=${(q)$(findBasedir $words)}
|
||||
if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]]
|
||||
then
|
||||
file=$basedir/GNUmakefile
|
||||
elif [[ -r $basedir/makefile ]]
|
||||
then
|
||||
file=$basedir/makefile
|
||||
elif [[ -r $basedir/Makefile ]]
|
||||
then
|
||||
file=$basedir/Makefile
|
||||
else
|
||||
file=''
|
||||
fi
|
||||
fi
|
||||
file="$words[(I)-f]"
|
||||
if (( file ))
|
||||
then
|
||||
file=${~words[file+1]}
|
||||
[[ $file == [^/]* ]] && file=${(q)$(findBasedir $words)}/$file
|
||||
[[ -r $file ]] || file=
|
||||
else
|
||||
local basedir
|
||||
basedir=${(q)$(findBasedir $words)}
|
||||
if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]]
|
||||
then
|
||||
file=$basedir/GNUmakefile
|
||||
elif [[ -r $basedir/makefile ]]
|
||||
then
|
||||
file=$basedir/makefile
|
||||
elif [[ -r $basedir/Makefile ]]
|
||||
then
|
||||
file=$basedir/Makefile
|
||||
else
|
||||
file=''
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$file" ]]
|
||||
then
|
||||
if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command
|
||||
then
|
||||
parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
|
||||
else
|
||||
parseMakefile $PWD < $file
|
||||
fi
|
||||
fi
|
||||
if [[ -n "$file" ]]
|
||||
then
|
||||
if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command
|
||||
then
|
||||
parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
|
||||
else
|
||||
parseMakefile $PWD < $file
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $PREFIX == (#b)([^=]##)'='* ]] && [[ -n ${${(k)VARIABLES}[(r)${match[1]}]} ]]
|
||||
then
|
||||
_message 'override make variable'
|
||||
else
|
||||
_tags targets variables
|
||||
while _tags
|
||||
do
|
||||
_requested targets expl 'make targets' \
|
||||
compadd -- ${(k)TARGETS}
|
||||
_requested variables expl 'make variables' \
|
||||
compadd -S '=' -- ${(k)VARIABLES}
|
||||
done
|
||||
fi
|
||||
|
||||
# These are left over from the old completion. I'm not sure what they do.
|
||||
#compstate[parameter]="${PREFIX%%\=*}"
|
||||
#compset -P 1 '*='
|
||||
#_value "$@"
|
||||
if [[ $PREFIX == (#b)([^=]##)'='* ]] && [[ -n ${${(k)VARIABLES}[(r)${match[1]}]} ]]
|
||||
then
|
||||
# Complete make variable as if shell variable
|
||||
compstate[parameter]="${PREFIX%%\=*}"
|
||||
compset -P 1 '*='
|
||||
_value "$@"
|
||||
else
|
||||
_tags targets variables
|
||||
while _tags
|
||||
do
|
||||
_requested targets expl 'make targets' \
|
||||
compadd -- ${(k)TARGETS}
|
||||
_requested variables expl 'make variables' \
|
||||
compadd -S '=' -- ${(k)VARIABLES}
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue