zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: example completion for a2ps
Date: Fri, 26 Feb 1999 16:38:19 +0100 (MET)	[thread overview]
Message-ID: <199902261538.QAA32458@beta.informatik.hu-berlin.de> (raw)


Below is a bit of cleanup in `_path_files', making the `-F' option
work again.
Then there are some enhancements in `_comp_parts' (damn, why didn't I
name this `_parts', no other function starts with `_comp'). And
finally there is a (probably silly) example function using
`_comp_parts' -- a completion function for `a2ps' (GNU version 4.10.1).

With that you can do `a2ps --c=y<TAB>' to get `a2ps --compact=yes' and 
things like that.

The function could still do with a bit of work, though.

Bye
 Sven

diff -u Functions/Completion/_a2ps Functions/Completion/_a2ps
--- Functions/Completion/_a2ps	Fri Feb 26 16:28:54 1999
+++ Functions/Completion/_a2ps	Fri Feb 26 16:20:05 1999
@@ -0,0 +1,22 @@
+#defcomp a2ps
+
+if [[ -prefix -- ]]; then
+  _comp_parts '(--borders --compact --truncate-lines --interpret
+                --print-anyway --delegate)' '=' '(yes no)'
+  _comp_parts '(--major)' '=' '(rows columns)'
+  _comp_parts '(--end-of-line)' '=' '(r n nr rn any)'
+
+  complist -S= -k '(--medium --columns --rows --line-numbers
+                    --font-size --lines-per-page --chars-per-line
+ 		    --tabsize --non-printable-format --encoding
+		    --title --stdin --prologue --highlight-level
+		    --strip-level --output --version-control --suffix
+		    --printer --copies --sides --page-prefeed
+		    --no-page-prefeed)'
+  complist -qS= -k '(--margin --header --underlay --left-title
+                     --right-title --left-footer --footer --right-footer
+		     --pages --pretty-print)'
+  complist -k '(--landscape --portrait --catman --no-header)'
+else
+  _files -F fignore -g "*~*.ps"
+fi
diff -u of/Completion/_comp_parts Functions/Completion/_comp_parts
--- of/Completion/_comp_parts	Fri Feb 26 12:50:25 1999
+++ Functions/Completion/_comp_parts	Fri Feb 26 16:22:28 1999
@@ -13,17 +13,32 @@
 # `friends'. If the string on the line contains a `@', the substring
 # after it will be completed from the array `hosts'. Of course more
 # arrays may be given, each preceded by another separator string.
+#
+# This function understands the `-J group', `-V group', and
+# `-X explanation' options.
+#
 # This function does part of the matching itself and calls the functions
 # `_match_test' and `_match_pattern' for this.
 
 local str arr sep test testarr tmparr prefix suffixes matchers autosuffix
-local matchflags
+local matchflags opt group expl
 
-# I have a global matching specification with multiple sets and want
-# all this tried only once, you may want to change this line.
+# Test if we should use this function for the global matcher in use.
 
 _match_test _comp_parts || return
 
+# Get the options.
+
+group=()
+expl=()
+while getopts "J:V:X:" opt; do
+  case "$opt" in
+  [JV]) group=("-$opt" "$OPTARG");;
+  X)    expl=(-X "$OPTARG");;
+  esac
+done
+shift OPTIND-1
+
 # Get the string from the line.
 
 str="$PREFIX$SUFFIX"
@@ -72,11 +87,14 @@
 if [[ $# -le 1 || "$str" != *${2}* ]]; then
   # No more separators, build the matches.
   matchflags=""
+  test="$str"
   _match_pattern _comp_parts test matchflags
   test="${matchflags}${test}"
   testarr=( "${(@M)${(@P)arr}:#${~test}*}" )
 fi
 
+[[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return
+
 # Now we build the suffixes to give to the completion code.
 shift
 matchers=()
@@ -125,5 +143,5 @@
 
 # Add the matches for each of the suffixes.
 for i in "$suffixes[@]"; do
-  compadd "$matchers[@]" "$autosuffix[@]" -p "$prefix" -s "$i" - "$testarr[@]"
+  compadd "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" -p "$prefix" -s "$i" - "$testarr[@]"
 done
diff -u of/Completion/_path_files Functions/Completion/_path_files
--- of/Completion/_path_files	Fri Feb 26 16:31:37 1999
+++ Functions/Completion/_path_files	Fri Feb 26 16:31:45 1999
@@ -58,7 +58,7 @@
          else
            ignore=( ${(P)${tmp1}} )
          fi
-	 (( $#ignore )) && ignore=(-F "$ignore[@]")
+	 (( $#ignore )) && ignore=(-F "( $ignore )")
          ;;
   [JV])  group=("-$opt" "$OPTARG")
          ;;

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


                 reply	other threads:[~1999-02-26 15:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=199902261538.QAA32458@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@sunsite.auc.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).