zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Hugo Haas <hugo@larve.net>
Cc: zsh-workers@sunsite.dk, 262247@bugs.debian.org
Subject: Re: Bug#262247: zsh: Improved make completion
Date: Sat, 21 Aug 2004 11:09:20 -0700	[thread overview]
Message-ID: <20040821180920.GA24266@blorf.net> (raw)
In-Reply-To: <20040818150736.GI4753@larve.net>

[-- Attachment #1: Type: text/plain, Size: 858 bytes --]

On Wed, Aug 18, 2004 at 11:07:36AM -0400, Hugo Haas wrote:
> Attached is an attempt at doing this. It seems to work, though I only
> enabled it for the gnu case.

I tried your patch, and it ignored targets that had dependencies (since
it only matched a colon at the end of the line).  Here's my attempt at a
zsh-only verson of _make.  It not only follows include files, but it
expands variables too.  I tried to make it handle both gnu and non-gnu
include files, but I assume that the ".include <...>" form needs more
code to handle where the include really resides.

Since the patch was larger than the new _make script, I'm just attaching
the new _make script here.  Give it a try and see how you like it.

Also, feel free to suggest how to improve it (for instance, I'd like to
know if the eval statements can be replaced with something else).

..wayne..

[-- Attachment #2: _make --]
[-- Type: text/plain, Size: 2471 bytes --]

#compdef make gmake pmake dmake

local prev="$words[CURRENT-1]" file expl tmp is_gnu cmdargs dir incl

expandVars() {
    local open close var val tmp=$1 ret=$1
    while :; do
	var=${tmp#*\$}
	if [[ $var != $tmp ]]; then
	    tmp=$var
	    case $var in
	    (\(*)
		open='('
		close=')'
		;;
	    ({*)
		open='{'
		close='}'
		;;
	    ([[:alnum:]]*)
		open=''
		close=''
		var=${(s::)var[1]}
		;;
	    (*)
		continue
		;;
	    esac
	    if [[ $open != '' ]]; then
		var=${var#$open}
		var=${var%%$close*}
	    fi
	    case $var in
	    ([[:alnum:]_]#)
		eval val=\${$var}
		val=$(expandVars $val)
		ret=${ret//\$$open$var$close/$val}
		;;
	    esac
	else
	    print $ret
	    return
	fi
    done
}

parseMakefile() {
    local input var val TAB=$'\t' dir=$1

    while read input; do
	case "$input " in
	([[:alnum:]][^$TAB:= ]#[ $TAB]#=*)
	    var=${input%%[ $TAB]#=*}
	    val=${input#*=}
	    val=${val##[ $TAB]#}
	    eval $var=\$val
	    ;;
	([[:alnum:]][^$TAB:= ]#[ $TAB]#:=*)
	    var=${input%%[ $TAB]#:=*}
	    val=${input#*=}
	    val=${val##[ $TAB]#}
	    val=$(expandVars $val)
	    eval $var=\$val
	    ;;
	([[:alnum:]][^$TAB:=]#:[^=]*)
	    input=${input%%:*}
	    print $(expandVars $input)
	    ;;
	($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
}

_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 -/
elif [[ "$prev" = -[foW] ]]; then
  _files
else
  file="$words[(I)-f]"
  if (( file )); then
    file="$words[file+1]"
  elif [[ -e Makefile ]]; then
    file=Makefile
  elif [[ -e makefile ]]; then
    file=makefile
  elif [[ $is_gnu = gnu && -e GNUmakefile ]]; then
    file=GNUmakefile
  else
    file=''
  fi

  if [[ -n "$file" ]] && _tags targets; then
    if [[ $is_gnu = gnu ]] &&
       zstyle -t ":completion:${curcontext}:targets" call-command; then
       tmp=( $(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null | parseMakefile $PWD) )
    else
       tmp=( $(parseMakefile $PWD < $file) )
    fi
    _wanted targets expl 'make target' compadd -a tmp && return 0
  fi
  compstate[parameter]="${PREFIX%%\=*}"
  compset -P 1 '*='
  _value "$@"
fi

  parent reply	other threads:[~2004-08-21 18:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040730101751.GA11905@larve.net>
2004-07-30 15:30 ` Clint Adams
2004-07-30 16:51   ` Hugo Haas
2004-08-18 15:07     ` Hugo Haas
2004-08-18 17:04       ` Wayne Davison
2004-08-21 18:09       ` Wayne Davison [this message]
2004-08-22  1:47         ` Bart Schaefer
2004-08-26 16:10         ` Hugo Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040821180920.GA24266@blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=262247@bugs.debian.org \
    --cc=hugo@larve.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).