* completions for make targets?
@ 1999-06-21 4:46 Raju K. V.
1999-06-21 7:06 ` Thomas Köhler
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Raju K. V. @ 1999-06-21 4:46 UTC (permalink / raw)
To: zsh-users
Hi all,
I am a zsh newbie still struggling to understand the power of compctl. I
have one requirement. How can I use compctl to complate make targets? I
can illustrate my requirements:
suppose I have 'Makefile' in my current directory with targets
xx:
yy:
zz:
clean:
clobber:
now I want to program compctl in such a way that $make <TAB> will list all
the targets for make.
Any help will be welcome.
Thanks and regards,
Raju
p.s.: Since I am not subscribed to the list, please CC me in your replies.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completions for make targets?
1999-06-21 4:46 completions for make targets? Raju K. V.
@ 1999-06-21 7:06 ` Thomas Köhler
1999-06-21 9:17 ` Falk Hueffner
1999-06-21 12:05 ` Stefan Monnier
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Köhler @ 1999-06-21 7:06 UTC (permalink / raw)
To: Raju K. V.; +Cc: zsh-users
Raju K. V. <rajukv@wipinfo.soft.net> wrote:
>
> Hi all,
>
> I am a zsh newbie still struggling to understand the power of compctl. I
> have one requirement. How can I use compctl to complate make targets? I
> can illustrate my requirements:
> suppose I have 'Makefile' in my current directory with targets
> xx:
> yy:
> zz:
> clean:
> clobber:
> now I want to program compctl in such a way that $make <TAB> will list all
> the targets for make.
>
> Any help will be welcome.
Well, there is a tool to convert tcsh complete commands to zsh compctl
statements. Using that, I got this solution (sorry for the *long* line):
compctl -s '`cat -s GNUmakefile Makefile makefile |& sed -n -e "/No such file/d" -e "/^[^ #].*:/s/:.*//p"`' -x 'c[-1,-f]' -f - 'n[-1,=]' -f -- make
> Thanks and regards,
> Raju
HTH,
Thomas
> p.s.: Since I am not subscribed to the list, please CC me in your replies.
No problem. :-)
--
Thomas Köhler Email: jean-luc@picard.franken.de
<>< WWW: http://home.pages.de/~jeanluc/
IRC: jeanluc
LCARS --- Linux for Computers on All Real Starships
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completions for make targets?
1999-06-21 4:46 completions for make targets? Raju K. V.
1999-06-21 7:06 ` Thomas Köhler
@ 1999-06-21 9:17 ` Falk Hueffner
1999-06-21 12:05 ` Stefan Monnier
2 siblings, 0 replies; 4+ messages in thread
From: Falk Hueffner @ 1999-06-21 9:17 UTC (permalink / raw)
To: Raju K. V.; +Cc: zsh-users
"Raju K. V." <rajukv@wipinfo.soft.net> writes:
> I am a zsh newbie still struggling to understand the power of
> compctl. I have one requirement. How can I use compctl to complate
> make targets?
Try this (I think it comes from the snandard compctl example file):
compctl -s "\$(awk '/^[a-zA-Z0-9][^ ]+:/ {print \$1}' FS=: [mM]akefile)" -x \
'c[-1,-f]' -f -- make gmake pmake
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completions for make targets?
1999-06-21 4:46 completions for make targets? Raju K. V.
1999-06-21 7:06 ` Thomas Köhler
1999-06-21 9:17 ` Falk Hueffner
@ 1999-06-21 12:05 ` Stefan Monnier
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 1999-06-21 12:05 UTC (permalink / raw)
To: zsh-users
>>>>> "Raju" == Raju K V <rajukv@wipinfo.soft.net> writes:
> How can I use compctl to complate make targets?
Admittedly, my solution doesn't exploit compctl too much (maybe
because I had it for tcsh before and just adapted it), but it's
probably a bit fancier (in some respects) than many others:
comp_make () {
local cmd args i where
read -Ac cmd; read -cn where
i=1
while [[ "$i" -lt "$#cmd" ]]; do
if [[ "$cmd[$i]" = "-f" ]]; then
reply=("${(@f)$(~/libexec/complete/make.perl "$cmd[$[$i + 1]]" 2>/dev/null)}")
comp_fixreply
return 0;
else
((i += 1))
fi
done
reply=("${(@f)$(~/libexec/complete/make.perl 2>/dev/null)}")
comp_fixreply
}
compctl -x 'c[-1,-f]' -f -- + -Q -S '' -K comp_make + gmake make
now, you'll notice that this depends on a perl file that does the actual
target extraction. The perl file is appended.
Stefan
#!/usr/bin/env perl
# read all the var definitions into the "vars" hash-table
# and the target lines into the "targetlines" array
sub ReadFile {
local($file) = @_;
local($prevs) = ("");
open(MAKEFILE, "<$file") || return;
for (<MAKEFILE>) {
chomp();
$_ = $prevs . $_; $prevs = "";
if (s/\\$//o ) {
$prevs = $_;
} elsif (/^[- \t]*include[ \t]+([^ \t]+)/) {
push(@includes, $1);
} elsif (/^[ \t]*([-a-zA-Z0-9_.]+)[ \t]*=(.*)$/o) {
$vars{$1} = $2;
} elsif (/^((([-a-zA-Z0-9_ ][-a-zA-Z0-9_. ]*)|(\$\((([^()]+)|(\$\([^()]+\)))\)))+)[\t ]*:/o) {
push(@targetlines, $1);
}
}
close(MAKEFILE);
if ($file = pop(@includes)) {
ReadFile($file);
}
}
# debugging: dump out the vars, their values and the targetlines
#print "**bindings**\n";
#@vars = keys(%vars);
#for (@vars) {
# print "<$_> is <$vars{$_}>\n";
#}
#print "**targets**\n";
#for (@targetlines) {
# print "$_\n";
#}
sub ExpandTargets {
local(@targets);
# look for potential targets (lines with a ":")
for $targets (@targetlines) {
# for each set of targets, look for variables to substitue
while (($var) = $targets =~ /\$\( *([^()\$]*)\)/o ) {
# print "var =$var: <$targets> => <";
# first case: a simple macro
if ($tmpvar = $vars{$var}) {
$var =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var
$targets =~ s/\$\( *$var\)/$tmpvar/g ;
#second case: a macro with simple substitution
} elsif (($var0, $s1, $s2) = $var =~ / *(.*):(.*)=(.*)/o) {
if ($tmpvar = $vars{$var0}) {
$s1 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote s1
$tmpvar =~ s/$s1/$s2/g ;
$s2 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote s2
$var0 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var0
$targets =~ s/\$\( *$var0:$s1=$s2\)/$tmpvar/g ;
} else {
$var0 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var0
$targets =~ s/\$\( *$var0:$s1=$s2\)//g ;
}
} else {
$var =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var
$targets =~ s/\$\( *$var\)//g ;
}
# print "$targets>\n";
}
$targets =~ s/:.*$//; # removes anything after a :
# split the "targets line" into an array of targets
@targets = ($targets =~ /([^ ]+)/og );
#put each target into a hash-table (to remove duplicates)
for $target (@targets) {
$targets{$target} = true;
}
}
}
if ($#ARGV < 0) {
if (-r "GNUmakefile") { $file = "GNUmakefile"; }
elsif (-r "Makefile") { $file = "Makefile"; }
elsif (-r "makefile") { $file = "makefile"; }
else { $file = "/dev/null"; }
} else {
$file = $ARGV[0];
}
ReadFile($file);
ExpandTargets();
# dump out the table of targets
for $target (keys(%targets)) { print "$target \n"; }
for $var (keys(%vars)) { print "$var=\n"; }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1999-06-21 12:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-21 4:46 completions for make targets? Raju K. V.
1999-06-21 7:06 ` Thomas Köhler
1999-06-21 9:17 ` Falk Hueffner
1999-06-21 12:05 ` Stefan Monnier
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).