zsh-workers
 help / color / mirror / code / Atom feed
* Re:  [PATCH] bash-style completion
@ 1999-02-04  8:15 Sven Wischnowsky
  1999-02-04 11:09 ` Dag-Erling Smorgrav
  1999-02-04 11:22 ` PATCH: zsh-3.1.5-pws-6: " Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Sven Wischnowsky @ 1999-02-04  8:15 UTC (permalink / raw)
  To: zsh-workers; +Cc: Dag-Erling Smorgrav


Dag-Erling Smorgrav wrote:

> I installed zsh 3.0.5 today and immediately liked it a lot better than
> bash2, which I'd previously been using. The only zsh feature I dislike
> is the csh-style completion (TAB to complete the unambiguous prefix,
> ^D to list possible completions), so I hacked zsh to provide
> bash-style completion (TAB completes the unambiguous prefix, TAB again
> lists possible completions). Patches against 3.0.5 are attached. Hope
> they can be of use.

I don't have a 3.0.5, so I couldn't try the patch. But as far as I can 
see, this should behave like normal completion with `setopt AUTOLIST'
and `setopt LISTAMBIGUOUS'.

> The patches also fix a minor bug (lastambig was not being reset when
> the completion list is invalidated).

This is already in all current versions of 3.1.5.

(For Dag: the most recent version is available at
`http://www.ifh.de/~pws/computing/zsh-3.1.5-pws-6.tar.gz', but it's
*very* beta.)


Bye
 Sven


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


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

* Re: [PATCH] bash-style completion
  1999-02-04  8:15 [PATCH] bash-style completion Sven Wischnowsky
@ 1999-02-04 11:09 ` Dag-Erling Smorgrav
  1999-02-04 11:22 ` PATCH: zsh-3.1.5-pws-6: " Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Dag-Erling Smorgrav @ 1999-02-04 11:09 UTC (permalink / raw)
  To: Sven Wischnowsky; +Cc: zsh-workers, Dag-Erling Smorgrav

Sven Wischnowsky <wischnow@informatik.hu-berlin.de> writes:
> Dag-Erling Smorgrav wrote:
> >                                [...] I hacked zsh to provide
> > bash-style completion (TAB completes the unambiguous prefix, TAB again
> > lists possible completions). [...]
> I don't have a 3.0.5, so I couldn't try the patch. But as far as I can 
> see, this should behave like normal completion with `setopt AUTOLIST'
> and `setopt LISTAMBIGUOUS'.

Sounds like another case of not enough RTFM ;)

Thanks,

DES
-- 
Dag-Erling Smorgrav - des@flood.ping.uio.no


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

* PATCH: zsh-3.1.5-pws-6: bash-style completion
  1999-02-04  8:15 [PATCH] bash-style completion Sven Wischnowsky
  1999-02-04 11:09 ` Dag-Erling Smorgrav
@ 1999-02-04 11:22 ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 1999-02-04 11:22 UTC (permalink / raw)
  To: zsh-workers, Dag-Erling Smorgrav

Sven Wischnowsky wrote:
> I don't have a 3.0.5, so I couldn't try the patch. But as far as I can 
> see, this should behave like normal completion with `setopt AUTOLIST'
> and `setopt LISTAMBIGUOUS'.

We seem to have this discussion every week.  It's not like bash,
because bash only shows the list on the *second* tab, and zsh can't
currently do that.  Nor do I think it's fair to rely on the new
completion to try to get this behaviour.

It's so often requested by bash converts --- it seems to be the first
thing they noticed --- and it's not so hard to do, along the lines of
the 3.0.5 patch, and it's a good deal shorter than most of the recent
zle changes, so I would suggest simply doing it.  The following is a
suggestion for 3.1.5: it probably won't work in 3.0.5 without quite
major surgery, though it should be relatively straightforward since
the algorithms in question haven't changed as far as I know.

However, it's a bit problematic making it a function, since you might
want that behaviour with complete-word, expand-or-complete or
expand-or-complete-prefix (those are the three I've tracked down,
anyway).  So I've made it an option, called BASH_AUTO_LIST.  It takes
precedence over AUTO_LIST and LIST_AMBIGUOUS:  the reason
for that is that those are now set by default, so this provides the
simplest way for the user to change the default behaviour (without
having to decode lines like
  noautolist            off
to invert the double negative).

Note the behaviour when combined with AUTO_MENU:  one tab, complete
unambiguous part if any; two tabs, show list; three tabs, start
cycling through completions.

I've done basic testing on this, but with all the possible options I
can't claim everything's OK.

I only just discovered quite how LIST_AMBIGUOUS works, so I added to
the manual entry.

I've also been having strange effects when combining all this with:
  compctl -M 'm:{a-z}={A-Z}' 'r:|[.,_-]=* r:|=*'
but I haven't tracked it down (and it's there anyway, I just normally
use menu completion so hadn't noticed).  I think there may be a
problem with `compctl -M' on its own, too, since I got a crash after
that once.

--- Doc/Zsh/options.yo.2tab	Thu Feb  4 11:12:16 1999
+++ Doc/Zsh/options.yo	Thu Feb  4 11:45:49 1999
@@ -150,6 +150,15 @@
 list, if it contains no `tt(|)', `tt(LPAR())' or (if special) `tt(~)'
 characters.  See noderef(Filename Generation).
 )
+pindex(BASH_AUTO_LIST)
+cindex(completion, listing choices, bash style)
+item(tt(BASH_AUTO_LIST))(
+On an ambiguous completion, automatically list choices when the
+completion function is called twice in succession.  This takes
+precedence over tt(AUTO_LIST) and tt(LIST_AMBIGUOUS).  If
+tt(AUTO_MENU) is set, the menu behaviour will then start with the
+third press.
+)
 pindex(BEEP)
 cindex(beep, enabling)
 cindex(enabling the beep)
@@ -488,9 +497,10 @@
 cindex(ambiguous completion)
 cindex(completion, ambiguous)
 item(tt(LIST_AMBIGUOUS))(
-If this option is set, completions are shown only if the completions
-don't have a unambiguous prefix or suffix that could be inserted in
-the command line.
+This option works when tt(AUTO_LIST) is also set.  If there is an
+unambiguous prefix to insert on the command line, that is done without
+a completion list being displayed; in other words, auto-listing
+behaviour only takes place when nothing would be inserted.
 )
 pindex(LIST_BEEP)
 cindex(beep, ambiguous completion)
--- Src/Zle/zle_tricky.c.2tab	Thu Feb  4 11:02:49 1999
+++ Src/Zle/zle_tricky.c	Thu Feb  4 12:07:33 1999
@@ -270,6 +270,19 @@
        COMP_LIST_EXPAND };
 #define COMP_ISEXPAND(X) ((X) >= COMP_EXPAND)
 
+/* Non-zero if the last completion done was ambiguous (used to find   *
+ * out if AUTOMENU should start).  More precisely, it's nonzero after *
+ * successfully doing any completion, unless the completion was       *
+ * unambiguous and did not cause the display of a completion list.    *
+ * From the other point of view, it's nonzero iff AUTOMENU (if set)   *
+ * should kick in on another completion.                              *
+ *                                                                    *
+ * If both AUTOMENU and BASHAUTOLIST are set, then we get a listing   *
+ * on the second tab, a` la bash, and then automenu kicks in when     *
+ * lastambig == 2.                                                    */
+
+static int lastambig;
+
 /**/
 void
 completecall(void)
@@ -287,8 +300,13 @@
     useglob = isset(GLOBCOMPLETE);
     if (c == '\t' && usetab())
 	selfinsert();
-    else
-	docomplete(COMP_COMPLETE);
+    else {
+	if (lastambig == 1 && isset(BASHAUTOLIST) && !usemenu && !menucmp) {
+	    docomplete(COMP_LIST_COMPLETE);
+	    lastambig == 2;
+	} else
+	    docomplete(COMP_COMPLETE);
+    }
 }
 
 /**/
@@ -358,8 +376,13 @@
     useglob = isset(GLOBCOMPLETE);
     if (c == '\t' && usetab())
 	selfinsert();
-    else
-	docomplete(COMP_EXPAND_COMPLETE);
+    else {
+	if (lastambig == 1 && isset(BASHAUTOLIST) && !usemenu && !menucmp) {
+	    docomplete(COMP_LIST_COMPLETE);
+	    lastambig = 2;
+	} else
+	    docomplete(COMP_EXPAND_COMPLETE);
+    }
 }
 
 /**/
@@ -451,15 +474,6 @@
 
 static char *rdstr;
 
-/* Non-zero if the last completion done was ambiguous (used to find   *
- * out if AUTOMENU should start).  More precisely, it's nonzero after *
- * successfully doing any completion, unless the completion was       *
- * unambiguous and did not cause the display of a completion list.    *
- * From the other point of view, it's nonzero iff AUTOMENU (if set)   *
- * should kick in on another completion.                              */
-
-static int lastambig;
-
 /* This holds the name of the current command (used to find the right *
  * compctl).                                                          */
 
@@ -569,7 +583,8 @@
 
     /* Check if we have to start a menu-completion (via automenu). */
 
-    if ((amenu = (isset(AUTOMENU) && lastambig)))
+    if ((amenu = (isset(AUTOMENU) && lastambig &&
+		  (!isset(BASHAUTOLIST) || lastambig == 2))))
 	usemenu = 1;
 
     /* Expand history references before starting completion.  If anything *
@@ -5459,12 +5474,17 @@
 	if (isset(RECEXACT) && !lc && !ainfo->prerest)
 	    am = 1;
 
-	/* If the LIST_AMBIGUOUS option (meaning roughly `show a list only *
+	/*
+	 * If the LIST_AMBIGUOUS option (meaning roughly `show a list only *
 	 * if the completion is completely ambiguous') is set, and some    *
 	 * prefix was inserted, return now, bypassing the list-displaying  *
 	 * code.  On the way, invalidate the list and note that we don't   *
-	 * want to enter an AUTO_MENU imediately.                          */
-	if(isset(LISTAMBIGUOUS) && !am &&
+	 * want to enter an AUTO_MENU imediately.                          *
+	 *                                                                 *
+	 * We don't do this when BASH_AUTO_LIST is set, because that would *
+	 * mean you only got a completion list the third time you hit tab  *
+	 * (or whichever key).                                             */
+	if(isset(LISTAMBIGUOUS) && !isset(BASHAUTOLIST) && !am &&
 	   (ics != cs || (ainfo->suflen && !atend))) {
 	    invalidatelist();
 	    lastambig = 0;
@@ -5475,7 +5495,8 @@
      * if it is needed.                                                     */
     if (isset(LISTBEEP))
 	feep();
-    if (isset(AUTOLIST) && !amenu && !showinglist && smatches >= 2)
+    if (isset(AUTOLIST) && !isset(BASHAUTOLIST) && !amenu && !showinglist &&
+	smatches >= 2)
 	showinglist = -2;
     if (am)
 	lastambig = 1;
--- Src/options.c.2tab	Thu Feb  4 11:06:13 1999
+++ Src/options.c	Thu Feb  4 10:42:30 1999
@@ -90,6 +90,7 @@
 {NULL, "badpattern",	      OPT_EMULATE|OPT_NONBOURNE, BADPATTERN},
 {NULL, "banghist",	      OPT_EMULATE|OPT_NONBOURNE, BANGHIST},
 {NULL, "bareglobqual",        OPT_EMULATE|OPT_ZSH,       BAREGLOBQUAL},
+{NULL, "bashautolist",	      0,                         BASHAUTOLIST},
 {NULL, "beep",		      OPT_ALL,			 BEEP},
 {NULL, "bgnice",	      OPT_EMULATE|OPT_NONBOURNE, BGNICE},
 {NULL, "braceccl",	      0,			 BRACECCL},
--- Src/zsh.h.2tab	Thu Feb  4 11:07:22 1999
+++ Src/zsh.h	Thu Feb  4 10:44:55 1999
@@ -1057,6 +1057,7 @@
     BADPATTERN,
     BANGHIST,
     BAREGLOBQUAL,
+    BASHAUTOLIST,
     BEEP,
     BGNICE,
     BRACECCL,

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

* [PATCH] bash-style completion
@ 1999-02-03 21:20 Dag-Erling Smorgrav
  0 siblings, 0 replies; 4+ messages in thread
From: Dag-Erling Smorgrav @ 1999-02-03 21:20 UTC (permalink / raw)
  To: zsh-workers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2427 bytes --]

Hi,

I installed zsh 3.0.5 today and immediately liked it a lot better than
bash2, which I'd previously been using. The only zsh feature I dislike
is the csh-style completion (TAB to complete the unambiguous prefix,
^D to list possible completions), so I hacked zsh to provide
bash-style completion (TAB completes the unambiguous prefix, TAB again
lists possible completions). Patches against 3.0.5 are attached. Hope
they can be of use.

The patches also fix a minor bug (lastambig was not being reset when
the completion list is invalidated).

To use bash-style completion, just bind your favorite key to
'complete-or-list'. I use 'bindkey \\t complete-or-list'.

OBTW, I put completeorlist() at the end of zle_tricky.c because it
uses lastambig. There's probably a cleaner way, e.g. defining
COMP_COMPLETE_OR_LIST and doing the dirty work (all four lines of it)
within do_complete().

Oh, and I'm not on the list, so please Cc: me any questions or
comments.

DES
-- 
Dag-Erling Smørgrav - des@flood.ping.uio.no

--- zle.h.orig	Tue Jun  3 07:11:24 1997
+++ zle.h	Wed Feb  3 18:48:03 1999
@@ -291,6 +291,7 @@
     z_beginningoflinehist,
     z_capitalizeword,
     z_clearscreen,
+    z_completeorlist,
     z_completeword,
     z_copyprevword,
     z_copyregionaskill,
--- zle_bindings.c.orig	Fri Jun 28 15:43:51 1996
+++ zle_bindings.c	Wed Feb  3 18:46:08 1999
@@ -51,6 +51,7 @@
     {"beginning-of-line-hist", beginningoflinehist, ZLE_MOVEMENT},
     {"capitalize-word", capitalizeword, 0},
     {"clear-screen", clearscreen, ZLE_MENUCMP},
+    {"complete-or-list", completeorlist, ZLE_MENUCMP},
     {"complete-word", completeword, ZLE_MENUCMP},
     {"copy-prev-word", copyprevword, 0},
     {"copy-region-as-kill", copyregionaskill, ZLE_KILL},
--- zle_tricky.c.orig	Wed Feb  3 18:49:08 1999
+++ zle_tricky.c	Wed Feb  3 22:09:29 1999
@@ -2998,7 +2998,7 @@
 	if (ccmain != &cc_dummy)
 	    freecompctl(ccmain);
     }
-    menucmp = showinglist = validlist = 0;
+    menucmp = showinglist = validlist = lastambig = 0;
     menucur = NULL;
 }
 
@@ -3968,4 +3968,20 @@
 	deletechar();		/* delete the added space. */
     }
     remove_at = -1;
+}
+
+/**/
+void
+completeorlist(void)
+{
+    usemenu = isset(MENUCOMPLETE);
+    useglob = isset(GLOBCOMPLETE);
+    if (c == '\t' && usetab())
+	selfinsert();
+    else {
+	if (lastambig)
+	    docomplete(COMP_LIST_COMPLETE);
+	else
+	    docomplete(COMP_COMPLETE);
+    }
 }


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

end of thread, other threads:[~1999-02-04 11:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-04  8:15 [PATCH] bash-style completion Sven Wischnowsky
1999-02-04 11:09 ` Dag-Erling Smorgrav
1999-02-04 11:22 ` PATCH: zsh-3.1.5-pws-6: " Peter Stephenson
  -- strict thread matches above, loose matches on Subject: below --
1999-02-03 21:20 [PATCH] " Dag-Erling Smorgrav

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