Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: completion



In article <199908201259.OAA00799@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
  Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx> writes:

> Not that easy and some people probably don't like the way option names 
> are completed with this patch, but still...

I tried to use this for "patch" and few problems are found and
fixed. And I thought some about _arguments.

1. The help message may not suited for _long_options.

For example, help message of "patch" contains: 
  -p NUM  --strip=NUM  Strip NUM leading components from file names.

The options are not separeted by ",".

I avoid this problem by modifying the help message.
# http://www.ldl.jaist.ac.jp/~akr/junk/patch-2.5.3-cvsaware-19990820.patch

But, in general, help messages may not able to modify.  Therefore I
think it is useful that _arguments can handle options started with
"--".

# Also, if _arguments supports options started with "--" directly,
# opt-spec to specify both "--xxx=yyy" and "--xxx yyy" at once may
# useful.

2. I would like to refer the parsed arguments in completers.

I think this is useful in many cases.
For example, if the completer for port of telnet can refer host
argument, it can complete ports precisely: "nntp" for news servers,
"smtp" for mail servers, etc.  If the completer for emacs can check
whether the argument of -f is batch-byte-compile, we can complete only
*.el.

3. "xterm -e" style.

Some options take arguments up to end of command line.

If _arguments supports this style of options, it is also useful for
_cvs, I suppose. Because first non-option argument for cvs command
behaves like that.

For example, I would like to describe _cvs as:

_cvs () {
  _arguments -s \
    '-d:cvsroot:...' \
    ... \
    '**:subcommand:_cvs_subcommand'
}

_cvs_subcommand () {
  if [[ CURRENT = 1 ]]; then
    compadd -- add commit diff ...
  else
    case $words[1] in
      add) _arguments -s '-k+:keyword expansion:...' ...;;
      ...
    esac
  fi
}

Index: Completion/Base/_arguments
===================================================================
RCS file: /projects/zsh/zsh/Completion/Base/_arguments,v
retrieving revision 1.1.1.4
diff -u -F^( -r1.1.1.4 _arguments
--- _arguments	1999/08/20 13:29:01	1.1.1.4
+++ _arguments	1999/08/20 22:25:02
@@ -158,12 +158,12 @@
       else
         uns=''
         if [[ -n "$single" && "$ws[1]" = [-+]* ]]; then
-          if [[ $#opts -ne 0 &&
+          if [[ ${#${(kj::)opts[(R)?*]#?}} -ne 0 &&
                 "$ws[1]" = ${ws[1][1]}*[${(kj::)opts[(R)?*]#?}] ]]; then
 	    def="$opts[${ws[1][1]}${ws[1][-1]}]"
 	    uns="${ws[1][2,-1]}"
 	    opt=''
-	  elif [[ $#mopts -ne 0 &&
+	  elif [[ ${#${(kj::)mopts[(R)?*]#?}} -ne 0 &&
                   "$ws[1]" = ${ws[1][1]}*[${(kj::)mopts[(R)?*]#?}] ]]; then
 	    def="$mopts[${ws[1][1]}${ws[1][-1]}]"
 	    uns="${ws[1][2,-1]}"
@@ -457,7 +457,7 @@
       [[ $#long -ne 0 &&
          ( "$compconfig[option_prefix]" != *(long|all)* ||
            "$PREFIX" = --* ) ]] && \
-          _long_options && ret=0
+	  _long_options "$long[@]" && ret=0
     fi
   fi
 
Index: Completion/Base/_long_options
===================================================================
RCS file: /projects/zsh/zsh/Completion/Base/_long_options,v
retrieving revision 1.1.1.7
diff -u -F^( -r1.1.1.7 _long_options
--- _long_options	1999/08/19 14:41:32	1.1.1.7
+++ _long_options	1999/08/20 22:25:02
@@ -135,7 +135,7 @@
 
   set -- "$@" '*=FILE*:file:_files' '*=(DIR|PATH)*:directory:_files -/' '*:unknown:'
 
-  while [[ $# -gt 1 ]]; do
+  while [[ $# -gt 0 ]]; do
 
     # First, we get the pattern and the action to use and take them
     # from the positional parameters.
@@ -265,6 +265,8 @@
 	  action=($=action)
 	  ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]}
         fi
+      else
+        _message "$descr"
       fi
 
       # We found the option string, return.
Index: Completion/User/_patch
===================================================================
RCS file: _patch
diff -N _patch
--- /dev/null	Fri Apr 17 15:56:34 1998
+++ _patch	Fri Aug 20 22:25:03 1999
@@ -0,0 +1,32 @@
+#compdef patch
+
+_arguments -s \
+  '-p+:number:(0)' \
+  '-F+:lines:' \
+  '-l' '-c' '-e' '-n' '-u' '-N' '-R' \
+  '-i+:patch file:_files' \
+  '-o+:output file:_files' \
+  '-r+:reject file:_files' \
+  '-D+:name:' \
+  '-E' '-Z' '-T' \
+  '-b' \
+  '-V+:version control style:(simple numbered existing)' \
+  '-B+:backup path prefix:' \
+  '-Y+:basename basename prefix:_files' \
+  '-z+:backup file suffix:(.bak)' \
+  '-g+:NUM:' \
+  '-t' '-f' '-s' \
+  '-d+:chdir to:_files -/' \
+  '-v' \
+  ':original file:_files' \
+  ':patch file:_files' \
+  -- \
+  '*=NUM*:number:(0)' \
+  '*=LINES*:lines:' \
+  '*=PATCHFILE*:patch file:_files' \
+  '*=FILE*:file:_files' \
+  '*=NAME*:name:' \
+  '*=WORD*:quoting style:(literal shell shell-always c escape)' \
+  '*=STYLE*:version control style:(simple numbered existing)' \
+  '*=SUFFIX*:backup file suffix:(.bak)' \
+  '*=DIR*:chdir to:_files -/'
-- 
Tanaka Akira



Messages sorted by: Reverse Date, Date, Thread, Author