zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: pws-25: _read_comp, again
Date: Wed, 07 Jul 1999 12:03:11 +0200	[thread overview]
Message-ID: <9907071003.AA22985@ibmth.df.unipi.it> (raw)

This modifies _read_comp to use Sven's zle -R rewrite to provide a
completion listing for the completion functions that can be completed to
run to get a completion.  (Alles klar?)  With autolist set and
alwayslastprompt set, it will list the possible functions after the first
character is typed.

There were some small problems: beeping added a newline, it was still
possible to get a completion on global matchers after the first if you
aborted, and I had to trap SIGINT to return from the function because for
some reason `read -k' wasn't returning the right status, just a 0 (which
you can't tell from C-SPC):  strange, since it seems to work perfectly well
in ordinary widgets.  I've left the commented-out debugging code in
deliberately.  Sigh.

--- Completion/Commands/_read_comp.c6	Mon Jul  5 16:21:32 1999
+++ Completion/Commands/_read_comp	Wed Jul  7 11:50:26 1999
@@ -23,7 +23,10 @@
 #  _read_comp         Last completion string read from user
 
 emulate -L zsh
-setopt extendedglob nobadpattern
+setopt extendedglob nobadpattern # xtrace promptsubst
+# local PS4='%N:%i:$((#key))> '
+
+trap 'zle -cR ""; return 1' INT
 
 # Took me ages to work this out.  If we're not on the first global
 # matcher specification, we mustn't do any I/O.
@@ -41,7 +44,9 @@
   return
 fi
 
-local key search str str2 newch funcs funcs2 exact msg
+_read_comp=
+
+local key search str str2 newch funcs funcs2 exact msg list
 integer pos
 
 msg="Completion: "
@@ -49,37 +54,48 @@
 zle -R $msg
 
 if ! read -k key; then
-  zle -R ''
+  zle -cR ''
   return 1
 fi
 
 while [[ '#key' -ne 10 && '#key' -ne 13 ]]; do
-  if [[ '#key' -eq 3 || '#key' -eq 7 ]]; then
-    zle -R ''
+  if [[ '#key' -eq 0 && '#key' -eq 3 || '#key' -eq 7 ]]; then
+    zle -cR ''
     return 1
   fi
   if [[ ( '#key' -eq 8 || '#key' -eq 127 ) && -n $str ]]; then
     # delete character
     str="$str[1,-2]"
     exact=
+    list=()
   elif [[ '#key' -eq 21 ]]; then
     # ^U: delete line
     str=
     exact=
+    list=()
+  elif [[ '#key' -eq 4 && $str = _[^\ ]# && $str != *' '* ]]; then
+    # ^D: list completions
+    list=(${$(whence -m "$str*" 2>/dev/null)%: function})
   elif [[ ( -n $exact && $key != ' ' ) || '#key & 127' -lt 32 ]]; then
     # If we've got an exact function, only allow a space after it.
     # Don't try to insert non-printing characters.
     if [[ -n $ZBEEP ]]; then
       print -nb $ZBEEP
     elif [[ -o beep ]]; then
-      print "\a"
+      print -n "\a"
     fi
+    list=()
   else
     str="$str$key"
     if [[ $str = _[^\ ]# ]]; then
       # Rudimentary completion for function names.
       # Allow arguments, i.e. don't do this after we've got a space.
       funcs=(${$(whence -m "$str*" 2>/dev/null)%: function})
+      if [[ -o autolist && $#str -gt 1 ]]; then
+	list=($funcs)
+      else
+	list=()
+      fi
       if (( $#funcs == 1 )); then
 	# Exact match; prompt the user for a newline to confirm
 	str=$funcs[1]
@@ -89,9 +105,10 @@
 	if [[ -n $ZBEEP ]]; then
 	  print -nb $ZBEEP
 	elif [[ -o beep ]]; then
-	  print "\a"
+	  print -n "\a"
 	fi
 	str="$str[1,-2]"
+	list=()
       else
 	# Add characters to the string until a name doesn't
 	# match any more, then backtrack one character to get
@@ -112,9 +129,13 @@
       exact=
     fi
   fi
-  zle -R "$msg$str$exact"
+  if (( $#list )); then
+    zle -R "$msg$str$exact" $list
+  else
+    zle -cR "$msg$str$exact"
+  fi
   if ! read -k key; then
-    zle -R ''
+    zle -cR ''
     return 1
   fi
 done
@@ -130,7 +151,7 @@
   _read_comp=$str
 fi
 
-zle -R ''
+zle -cR ''
 
 if [[ $str = _* ]]; then
   eval $str

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


             reply	other threads:[~1999-07-07 10:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-07 10:03 Peter Stephenson [this message]
1999-07-08 11:48 Sven Wischnowsky
1999-07-08 11:59 ` Peter Stephenson
1999-07-08 12:43 Sven Wischnowsky

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=9907071003.AA22985@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --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).