zsh-users
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Bill Burton <billb@progress.com>
Cc: Zsh users <zsh-users@sunsite.dk>
Subject: Re: [SUBMIT] _ant completion function
Date: Mon, 19 Aug 2002 15:47:31 +0100	[thread overview]
Message-ID: <E17gnoZ-0004m9-00@bimbo.logica.co.uk> (raw)
In-Reply-To: <3D5DA795.8CE14D47@progress.com>

On 16 Aug, Bill Burton wrote:

> Here's my version of an _ant function for Ant completion support in
> versions 1.3 to 1.5.

Great, thanks. As I suggested in the previous mail, I've gone through
this and merged it with the _ant I posted last week. The _arguments
sections were almost the same and I've used the call-command style to
select between your ant -projecthelp parsing and my sed solution.

> zsh I'd appreciate it.  There's also a minor cosmetic issue in that the
> default target is printed with a leading space.  The problem is I couldn't
> figure out how to do a substitution while condtitionally removing a
> trailing space.  Using ? or * didn't work for me to make a space optional.

Just using ${default_target# } does the job. The other cosmetic issue
was that targets without a description were added with an empty
description instead of with no description. I've attempted to fix this,
hopefully without breaking the rest of it. How do you specify target
descriptions in a build.xml file?

> Suggested improvements
> * A number of the options support completing on a classname.  However,
> this doesn't work unless the class file is in a package under the current
> directory.  It would be desirable to complete on any class in the
> classpath.  Since Ant's classpath isn't exposed, the best guess would be
> to use a classpath of $ANT_HOME/lib/*.jar.

On the 4.1 branch, there is a _java_class function which is meant to do
this but I can't entirely make sense of what it is doing and how to get
it to use $ANT_HOME/lib/*.jar as you suggest. It ought to use
_multi_parts too.

Certainly, this can still be improved. For zsh 4.0, the _java_class
stuff will need the be replaced with the state from Bill's function, the
-e option passed  to _message needs to go and the $ANT_ARGS stuff needs
to go. So don't expect this to work properly on 4.0.

Oliver

Index: _ant
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ant,v
retrieving revision 1.1
diff -u -r1.1 _ant
--- _ant	9 Aug 2002 15:28:24 -0000	1.1
+++ _ant	19 Aug 2002 14:44:00 -0000
@@ -1,8 +1,9 @@
 #compdef ant -value-,ANT_ARGS,-default-
 
 typeset -A opt_args
-local state line curcontext="$curcontext"
+local buildfile tmp state line curcontext="$curcontext"
 local target='*:target:->target'
+#local CLASSPATH="$ANT_HOME/lib/*.jar"
 
 if [[ $service = *ANT_ARGS* ]]; then
   compset -q
@@ -22,17 +23,73 @@
   '-emacs[produce logging information without adornments]' \
   '(-l -logfile)'{-l,-logfile}'[use specified file for
log]:logfile:_files' \
   '-logger[the class which is to perform
logging]:classname:_java_class' \
-  '-listener[add an instance of class as a project
listener]:classname:_java_class' \
-  '(-f -file -buildfile)'{-f,-file,-buildfile}'[use specified build
file]:build file:_files' \
-  '*-D[specify property with value to use]:property' \
+  '*-listener[add an instance of class as a project
listener]:classname:_java_class' \
+  '(-f -file -buildfile -find)'{-f,-file,-buildfile}'[use specified
build file]:build file:_files' \
+  '*-D[specify property with value to use]:property:->property' \
   '-propertyfile[load properties from specfied file]:property
file:_files' \
   '-inputhandler[specify class which will handle input
requests]:class:_java_class' \
-  '-find[search for buildfile]:file:_files' \
+  '(-f -file -buildfile)-find[search for build file towards the root of
filesystem]:build file:(build.xml)' \
   $target && return
 
-if [[ -n $state ]]; then
-  targets=( $(sed -n 's/ *<target name="\([^"]*\)".*/\1/p' < build.xml)
)
-  # ant can be used to get a list of targets for us like this but it is
slow
-  # targets=( ${${(M)${(f)"$(_call_program targets $words[1]
-projecthelp)"}:# *}# } )
-  _wanted targets expl target compadd -a targets
-fi
+case $state in
+  property)
+    if compset -P '*='; then
+      _default
+    else
+      _message -e properties 'property name'
+    fi
+  ;;
+  target)
+    if zstyle -t ":completion:${curcontext}:targets" call-command; then
+      # Run ant -projecthelp also passing any of -find, -buildfile or
-f options.
+      # Parse output into an array of the format "target:description".
+      # For the array to be set with correct argument boundaries, the
entire
+      # set statement needs to be eval'd.  On Cygwin, need to kill \r's
output
+      # from Java or parsing will fail.
+      eval set -A tmp "${$(_call_program targets "$words[1]" $buildxml
-projecthelp |
+	while read target desc
+	do
+          # This loop reads ant -projecthelp output from versions 1.3
to 1.5
+          ln="${target}${desc:+:$desc}"
+          [[ $target = "" ]] && continue  # skip blank lines
+          case $ln in
+              (Buildfile:*)
+                  buildfile=$desc
+              ;;
+              (Default:target:*)
+                  # with version 1.5, target is on the same line
+                  default_target="${${desc/target:/}# }"
+                  # versions 1.3 and 1.4 with default target on a
separate line
+                  if [[ -z $default_target ]]; then
+                      read junk
+                      read default_target junk
+                  fi
+                  # Output target again indicating its the default one.
+                  print -n "'${default_target}:(Default target) ' "
+              ;;
+
(Searching:*|Main:targets:|Subtargets:|BUILD:SUCCESSFUL|Total:time:
+	      *)
+              ;;
+              (*)
+                  # Return target and description
+                  print -n "'$ln' "
+              ;;
+          esac
+	done
+      )//$'\015'}"
+      _describe 'target' tmp
+    else
+      if [[ -n $opt_args[-find] ]]; then
+	buildfile=( (../)#${opt_args[-find]:-build.xml}(N[-1]) )
+      else
+	buildfile=${(v)opt_args[(I)(-f|-file|-buildfile)]:-build.xml}
+      fi
+      if [[ -f $buildfile ]]; then
+	targets=( $(sed -n 's/ *<target name="\([^"]*\)".*/\1/p' <
$buildfile) )
+	_wanted targets expl target compadd -a targets
+      else
+	_message -e targets target
+      fi
+    fi
+  ;;
+esac

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


  parent reply	other threads:[~2002-08-19 14:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-17  1:32 Bill Burton
2002-08-18 10:45 ` Byron Foster
2002-08-18 15:09   ` Bart Schaefer
2002-08-19 14:47 ` Oliver Kiddle [this message]
2002-08-20  0:52   ` Felix Rosencrantz
2002-08-20  1:06   ` Felix Rosencrantz
2002-08-20 10:32     ` Oliver Kiddle
2002-08-20 16:05       ` Bill Burton
2002-08-20 19:41       ` Felix Rosencrantz

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=E17gnoZ-0004m9-00@bimbo.logica.co.uk \
    --to=okiddle@yahoo.co.uk \
    --cc=billb@progress.com \
    --cc=zsh-users@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).