zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: pws-25: _read_comp, again
@ 1999-07-08 11:48 Sven Wischnowsky
  1999-07-08 11:59 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 1999-07-08 11:48 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> 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.

For me it correctly returns `1' as the return status. The problem is
that the signal handler for SIGINT sets `breaks=loops' and since the
second read is in a loop the then-clause will never be executed
(because of the test of the while-loop in `execlist()').

Hm. What are we to do here -- should we reset some of the things
changed by the signal handler in bin_read()? Do we always want that?

Bye
 Sven


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


^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: PATCH: pws-25: _read_comp, again
@ 1999-07-08 12:43 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 1999-07-08 12:43 UTC (permalink / raw)
  To: zsh-workers


Or was there another reason I've missed?

Bye
 Sven

diff -u oc/Commands/_read_comp Completion/Commands/_read_comp
--- oc/Commands/_read_comp	Thu Jul  8 14:42:16 1999
+++ Completion/Commands/_read_comp	Thu Jul  8 14:42:03 1999
@@ -26,8 +26,6 @@
 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.
 if [[ compstate[matcher] -gt 1 && -z $_read_comp ]]; then

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


^ permalink raw reply	[flat|nested] 4+ messages in thread
* PATCH: pws-25: _read_comp, again
@ 1999-07-07 10:03 Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 1999-07-07 10:03 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-07-08 12:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-08 11:48 PATCH: pws-25: _read_comp, again Sven Wischnowsky
1999-07-08 11:59 ` Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
1999-07-08 12:43 Sven Wischnowsky
1999-07-07 10:03 Peter Stephenson

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).