1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-11 13:01:28 +02:00

27429: _make: restore variable value completion

make indentation more standard
This commit is contained in:
Peter Stephenson 2009-11-24 10:14:33 +00:00
parent b97284cde2
commit 85842387f8
2 changed files with 174 additions and 171 deletions

View file

@ -1,5 +1,8 @@
2009-11-24 Peter Stephenson <pws@csr.com> 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: * Michael Hwang <michael.a.hwang@gmail.com>: 27428:
Completion/Unix/Command/_make: complete rewrite with Completion/Unix/Command/_make: complete rewrite with
variable completion. variable completion.
@ -12387,5 +12390,5 @@
***************************************************** *****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL * This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.4821 $ * $Revision: 1.4822 $
***************************************************** *****************************************************

View file

@ -7,210 +7,210 @@ local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match
local -A TARGETS VARIABLES local -A TARGETS VARIABLES
expandVars() { expandVars() {
local open close var val front ret tmp=$1 local open close var val front ret tmp=$1
front=${tmp%%\$*} front=${tmp%%\$*}
case $tmp in case $tmp in
(\(*) # Variable of the form $(foobar) (\(*) # Variable of the form $(foobar)
open='(' open='('
close=')' close=')'
;; ;;
({*) # ${foobar} ({*) # ${foobar}
open='{' open='{'
close='}' close='}'
;; ;;
([[:alpha:]]*) # $foobar. This is exactly $(f)oobar. ([[:alpha:]]*) # $foobar. This is exactly $(f)oobar.
open='' open=''
close='' close=''
var=${(s::)var[1]} var=${(s::)var[1]}
;; ;;
(\$*) # Escaped $. (\$*) # Escaped $.
print -- "${front}\$$(expandVars ${tmp#\$})" print -- "${front}\$$(expandVars ${tmp#\$})"
return return
;; ;;
(*) # Nothing left to substitute. (*) # Nothing left to substitute.
print -- $tmp print -- $tmp
return return
;; ;;
esac esac
if [[ -n $open ]] if [[ -n $open ]]
then then
var=${tmp#$open} var=${tmp#$open}
var=${var%%$close*} var=${var%%$close*}
fi fi
case $var in case $var in
([[:alnum:]_]#) ([[:alnum:]_]#)
val=${VARIABLES[$var]} val=${VARIABLES[$var]}
ret=${ret//\$$open$var$close/$val} ret=${ret//\$$open$var$close/$val}
;; ;;
(*) # Improper variable name. No replacement. I'm not sure if this is desired behavior. (*)
front+="\$$open$var$close" # Improper variable name. No replacement.
ret=${ret/\$$open$var$close/} # I'm not sure if this is desired behavior.
;; front+="\$$open$var$close"
esac ret=${ret/\$$open$var$close/}
;;
esac
print -- "${front}$(expandVars ${ret})" print -- "${front}$(expandVars ${ret})"
} }
parseMakefile () { 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 while read input
do do
case "$input " in case "$input " in
# VARIABLE = value # VARIABLE = value
([[:alnum:]][[:alnum:]_]#[ $TAB]#=*) ([[:alnum:]][[:alnum:]_]#[ $TAB]#=*)
var=${input%%[ $TAB]#=*} var=${input%%[ $TAB]#=*}
val=${input#*=} val=${input#*=}
val=${val##[ $TAB]#} val=${val##[ $TAB]#}
VARIABLES[$var]=$val VARIABLES[$var]=$val
;; ;;
# VARIABLE := value # VARIABLE := value
# Evaluated immediately # Evaluated immediately
([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*) ([[:alnum:]][[:alnum:]_]#[ $TAB]#:=*)
var=${input%%[ $TAB]#:=*} var=${input%%[ $TAB]#:=*}
val=${input#*=} val=${input#*=}
val=${val##[ $TAB]#} val=${val##[ $TAB]#}
val=$(expandVars $val) val=$(expandVars $val)
VARIABLES[$var]=$val VARIABLES[$var]=$val
;; ;;
# TARGET: dependencies # TARGET: dependencies
# TARGET1 TARGET2 TARGET3: dependencies # TARGET1 TARGET2 TARGET3: dependencies
([[:alnum:]][^$TAB:=]#:[^=]*) ([[:alnum:]][^$TAB:=]#:[^=]*)
input=$(expandVars $input) input=$(expandVars $input)
target=${input%%:*} target=${input%%:*}
dep=${input#*:} dep=${input#*:}
dep=${(z)dep} dep=${(z)dep}
dep="$dep" dep="$dep"
for tmp in ${(z)target} for tmp in ${(z)target}
do do
TARGETS[$tmp]=$dep TARGETS[$tmp]=$dep
done done
;; ;;
# Include another makefile # Include another makefile
(${~incl} *) (${~incl} *)
local f=${input##${~incl} ##} local f=${input##${~incl} ##}
if [[ $incl == '.include' ]] if [[ $incl == '.include' ]]
then then
f=${f#[\"<]} f=${f#[\"<]}
f=${f%[\">]} f=${f%[\">]}
fi fi
f=$(expandVars $f) f=$(expandVars $f)
case $f in case $f in
(/*) ;; (/*) ;;
(*) f=$dir/$f ;; (*) f=$dir/$f ;;
esac esac
if [[ -r $f ]] if [[ -r $f ]]
then then
parseMakefile ${f%%/[^/]##} < $f parseMakefile ${f%%/[^/]##} < $f
fi fi
;; ;;
esac esac
done done
} }
findBasedir () { findBasedir () {
local file index basedir local file index basedir
basedir=$PWD basedir=$PWD
for (( index=0; index < $#@; index++ )) for (( index=0; index < $#@; index++ ))
do do
if [[ $@[index] == -C ]] if [[ $@[index] == -C ]]
then then
file=${~@[index+1]}; file=${~@[index+1]};
if [[ -z $file ]] if [[ -z $file ]]
then then
# make returns with an error if an empty arg is given # make returns with an error if an empty arg is given
# even if the concatenated path is a valid directory # even if the concatenated path is a valid directory
return return
elif [[ $file == /* ]] elif [[ $file == /* ]]
then then
# Absolute path, replace base directory # Absolute path, replace base directory
basedir=$file basedir=$file
else else
# Relative, concatenate path # Relative, concatenate path
basedir=$basedir/$file basedir=$basedir/$file
fi fi
fi fi
done done
print -- $basedir print -- $basedir
} }
_pick_variant -r is_gnu gnu=GNU unix -v -f _pick_variant -r is_gnu gnu=GNU unix -v -f
if [[ $is_gnu == gnu ]] if [[ $is_gnu == gnu ]]
then then
incl="(-|)include" incl="(-|)include"
else else
incl=.include incl=.include
fi fi
if [[ "$prev" == -[CI] ]] if [[ "$prev" == -[CI] ]]
then then
_files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/ _files -W ${(q)$(findBasedir ${words[1,CURRENT-1]})} -/
elif [[ "$prev" == -[foW] ]] elif [[ "$prev" == -[foW] ]]
then then
_files -W ${(q)$(findBasedir $words)} _files -W ${(q)$(findBasedir $words)}
else else
file="$words[(I)-f]" file="$words[(I)-f]"
if (( file )) if (( file ))
then then
file=${~words[file+1]} file=${~words[file+1]}
[[ $file == [^/]* ]] && file=${(q)$(findBasedir $words)}/$file [[ $file == [^/]* ]] && file=${(q)$(findBasedir $words)}/$file
[[ -r $file ]] || file= [[ -r $file ]] || file=
else else
local basedir local basedir
basedir=${(q)$(findBasedir $words)} basedir=${(q)$(findBasedir $words)}
if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]] if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]]
then then
file=$basedir/GNUmakefile file=$basedir/GNUmakefile
elif [[ -r $basedir/makefile ]] elif [[ -r $basedir/makefile ]]
then then
file=$basedir/makefile file=$basedir/makefile
elif [[ -r $basedir/Makefile ]] elif [[ -r $basedir/Makefile ]]
then then
file=$basedir/Makefile file=$basedir/Makefile
else else
file='' file=''
fi fi
fi fi
if [[ -n "$file" ]] if [[ -n "$file" ]]
then then
if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command
then then
parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null) parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null)
else else
parseMakefile $PWD < $file parseMakefile $PWD < $file
fi fi
fi fi
if [[ $PREFIX == (#b)([^=]##)'='* ]] && [[ -n ${${(k)VARIABLES}[(r)${match[1]}]} ]] if [[ $PREFIX == (#b)([^=]##)'='* ]] && [[ -n ${${(k)VARIABLES}[(r)${match[1]}]} ]]
then then
_message 'override make variable' # Complete make variable as if shell variable
else compstate[parameter]="${PREFIX%%\=*}"
_tags targets variables compset -P 1 '*='
while _tags _value "$@"
do else
_requested targets expl 'make targets' \ _tags targets variables
compadd -- ${(k)TARGETS} while _tags
_requested variables expl 'make variables' \ do
compadd -S '=' -- ${(k)VARIABLES} _requested targets expl 'make targets' \
done compadd -- ${(k)TARGETS}
fi _requested variables expl 'make variables' \
compadd -S '=' -- ${(k)VARIABLES}
# These are left over from the old completion. I'm not sure what they do. done
#compstate[parameter]="${PREFIX%%\=*}" fi
#compset -P 1 '*='
#_value "$@"
fi fi