[ksh93-integration-discuss] Re: [ast-users] RFE: Make TAB completion in ksh93 work like ESC-'=' ...

Roland Mainz roland.mainz at nrubsig.org
Mon May 8 22:27:32 PDT 2006


Roland Mainz wrote:

> Attached is a small patch ("ksh93_tab_completion_choice.diff.txt" ;
> relative to the current Solaris OS/Net tree, but it should apply to
> ksh93r cleanly, too) which may be usefull for integration into ksh93r+.
> 
> The patch changes the behaviour of the TAB completion in emacs mode to
> preview a list of choices (e.g. equilavent to ESC-'=') instead of doing
> the completion itself which may be much more usefull when many file name
> are matching the given pattern (it also contains a comment how to make
> it slightly "better", however I am not sure (yet) how this can be done
> easily).
> 
> Little bit testing with our students showed that they like it more than
> the current TAB completion... :-)
> 
> Basically the patch is equivalent to
> -- snip --
> function emacs_completion
> {
>     if [[ ${.sh.edchar} == "$(printf "\t")" ]] then
>         .sh.edchar="$(printf "\E=")"
>         true
>     fi
> }
> 
> trap emacs_completion KEYBD
> -- snip --

Actually it could be done better... attached is a 2nd patch
("ksh93_tab_tab_gmacs_completion_try2.diff.txt") which also implements
TAB-TAB completion like in bash3.
Single TAB now completes the filename either completely - or if that
isn't possible it's completed to the point where the filenames start to
differ. TAB-TAB then displays a list of choices. Additionally in "gmacs"
mode typing TAB on an empty string will try to do the filename
completion for the whole directory (and TAB-TAB displays all choices
then). "emacs" mode still behaves as usual, incl. the ability to enter
the TAB character.
(note: the previous patch was tested for ~~one week, the current one is
more or less untested) ...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
-------------- next part --------------
Index: lib/libshell/common/edit/emacs.c
===================================================================
--- lib/libshell/common/edit/emacs.c	(revision 222)
+++ lib/libshell/common/edit/emacs.c	(working copy)
@@ -179,6 +179,7 @@
 
 int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
 {
+	static unsigned int tab_count = 0;
 	Edit_t *ed = (Edit_t*)context;
 	register int c;
 	register int i;
@@ -306,6 +307,13 @@
 			count = 1;
 		adjust = -1;
 		i = cur;
+
+		/* Count tabs for TAB completion (single TAB or TAB-TAB) */
+		if(c == '\t')
+			tab_count++;
+		else
+			tab_count = 0;
+
 		switch(c)
 		{
 		case cntl('V'):
@@ -327,11 +335,14 @@
 			continue;
 #endif	/* u370 */
 		case '\t':
-			if(cur>0 && cur>=eol && out[cur-1]!='\t' && out[cur-1]!=' ' && ep->ed->sh->nextprompt)
+			if((cur>0 && cur>=eol && out[cur-1]!='\t' && out[cur-1]!=' ' && ep->ed->sh->nextprompt) ||
+			    sh_isoption(SH_GMACS))
 			{
-				ed_ungetchar(ep->ed,ESC);
-				ed_ungetchar(ep->ed,ESC);
-				continue;
+				if (tab_count == 1)
+					ed_ungetchar(ep->ed,cntl('['));	/* like ESC-ESC */
+				else if (tab_count >= 2)
+					ed_ungetchar(ep->ed,'=');	/* like ESC-'=' */
+				goto esc_;
 			}
 		default:
 			if ((eol+1) >= (scend)) /*  will not fit on line */
@@ -578,6 +589,7 @@
 			draw(ep,REFRESH);
 			continue;
 		case cntl('[') :
+esc_:
 			adjust = escape(ep,out,oadjust);
 			continue;
 		case cntl('R') :


More information about the ksh93-integration-discuss mailing list