From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7396 invoked by alias); 24 May 2011 01:38:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29365 Received: (qmail 12198 invoked from network); 24 May 2011 01:38:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=CPJSvOkWw0egzosYSwaPgNSHJoRMXi7NlpiQY5/0kk8=; b=Q8vMHAhzCQbUgILUto5LdQ93lO+zMPHT7FHx0YBRdgsmBru34hrFSWR2GBT40QB3l8 itsLP25YU2EhNBVWAlC74gZr+wSXn3P6cezDSHETF5PzSXTQ/OTk6YDnvglsSJqdoXPu 32/OtPx7NtqYvQaQakfRiGFAOGAbks+IIHRFs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=ohYIzmsF1CQczPUfL0/CBG4UR7GQm5nWmAzPVFiasPF5vaz+upLyEZ4Y6O6KYQFB42 xQEtTkI5QwgXTI6txTMKrRcpBZ0d/LpYophChmqFHc/9JP7t43/DhdqxqG3k6osBCNj1 fp9+OhwFoNBPr1SPmQkVHfKx1BvDgPhFOOL14= From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: _make: put body in _make() and don't redefine helpers every time Date: Tue, 24 May 2011 03:38:33 +0200 Message-Id: <1306201113-26434-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 1.7.4-rc1 In-Reply-To: References: Here's the diff without reindent, full patch below. +++ b/Completion/Unix/Command/_make @@ -3,10 +3,6 @@ # TODO: Based on targets given on the command line, show only variables that # are used in those targets and their dependencies. -local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match -local -A TARGETS VARIABLES -local ret=1 - _make-expandVars() { local open close var val front ret tmp=$1 @@ -149,6 +145,11 @@ _make-findBasedir () { print -- $basedir } +_make () { + local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match + local -A TARGETS VARIABLES + local ret=1 + _pick_variant -r is_gnu gnu=GNU unix -v -f if [[ $is_gnu == gnu ]] @@ -223,3 +224,6 @@ else fi return ret +} + +_make "$@" --- Completion/Unix/Command/_make | 136 +++++++++++++++++++++-------------------- 1 files changed, 70 insertions(+), 66 deletions(-) diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make index 322414b..09f44a3 100644 --- a/Completion/Unix/Command/_make +++ b/Completion/Unix/Command/_make @@ -3,10 +3,6 @@ # TODO: Based on targets given on the command line, show only variables that # are used in those targets and their dependencies. -local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match -local -A TARGETS VARIABLES -local ret=1 - _make-expandVars() { local open close var val front ret tmp=$1 @@ -149,77 +145,85 @@ _make-findBasedir () { print -- $basedir } -_pick_variant -r is_gnu gnu=GNU unix -v -f - -if [[ $is_gnu == gnu ]] -then - incl="(-|)include" -else - incl=.include -fi - -if [[ "$prev" == -[CI] ]] -then - _files -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0 -elif [[ "$prev" == -[foW] ]] -then - _files -W ${(q)$(_make-findBasedir $words)} && ret=0 -else - file="$words[(I)-f]" - if (( file )) +_make () { + local prev="$words[CURRENT-1]" file expl tmp is_gnu dir incl match + local -A TARGETS VARIABLES + local ret=1 + + _pick_variant -r is_gnu gnu=GNU unix -v -f + + if [[ $is_gnu == gnu ]] then - file=${~words[file+1]} - [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file - [[ -r $file ]] || file= + incl="(-|)include" else - local basedir - basedir=${(q)$(_make-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 ]] + incl=.include + fi + + if [[ "$prev" == -[CI] ]] + then + _files -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0 + elif [[ "$prev" == -[foW] ]] + then + _files -W ${(q)$(_make-findBasedir $words)} && ret=0 + else + file="$words[(I)-f]" + if (( file )) then - file=$basedir/Makefile + file=${~words[file+1]} + [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file + [[ -r $file ]] || file= else - file='' + local basedir + basedir=${(q)$(_make-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 - fi - if [[ -n "$file" ]] - then - if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command + if [[ -n "$file" ]] + then + if [[ $is_gnu == gnu ]] && zstyle -t ":completion:${curcontext}:targets" call-command + then + _make-parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null) + else + case "$OSTYPE" in + freebsd*) + _make-parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp -f "$file" .PHONY 2> /dev/null) + ;; + *) + _make-parseMakefile $PWD < $file + esac + fi + fi + + if [[ $PREFIX == *'='* ]] then - _make-parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null) + # Complete make variable as if shell variable + compstate[parameter]="${PREFIX%%\=*}" + compset -P 1 '*=' + _value "$@" && ret=0 else - case "$OSTYPE" in - freebsd*) - _make-parseMakefile $PWD < <(_call_program targets "$words[1]" -nsp -f "$file" .PHONY 2> /dev/null) - ;; - *) - _make-parseMakefile $PWD < $file - esac + _tags targets variables + while _tags + do + _requested targets expl 'make targets' \ + compadd -- ${(k)TARGETS} && ret=0 + _requested variables expl 'make variables' \ + compadd -S '=' -- ${(k)VARIABLES} && ret=0 + done fi fi - if [[ $PREFIX == *'='* ]] - then - # Complete make variable as if shell variable - compstate[parameter]="${PREFIX%%\=*}" - compset -P 1 '*=' - _value "$@" && ret=0 - else - _tags targets variables - while _tags - do - _requested targets expl 'make targets' \ - compadd -- ${(k)TARGETS} && ret=0 - _requested variables expl 'make variables' \ - compadd -S '=' -- ${(k)VARIABLES} && ret=0 - done - fi -fi + return ret +} -return ret +_make "$@" -- 1.7.4-rc1