[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ast-users
Subject:    TAB-TAB completion patch #005 / was: Re: TAB-TAB completion patch
From:       roland.mainz () nrubsig ! org (Roland Mainz)
Date:       2006-05-15 16:53:50
Message-ID: 4468DEE9.2E5C2F3B () nrubsig ! org
[Download RAW message or body]

April Chin wrote:
> > Roland Mainz wrote:
> > > 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) ...
> > 
> > Attached is now the 3rd version... the only difference to the previous
> > patch is that I added a way to provide a default editor mode (set to
> > "gmacs" for the initial ksh93-integration (and to aid the migration of
> > bash2/3 users to ksh93)). Basically it is an equivalent to the following
> > ksh93 shell code:
> > -- snip --
> > emacs_completion_tab_count=0
> > 
> > function emacs_completion
> > {
> > if [[ ${.sh.edchar} == "$(printf "\t")" ]] then
> > emacs_completion_tab_count=$((emacs_completion_tab_count + 1))
> > 
> > if [ $emacs_completion_tab_count -eq 1 ] ; then
> > .sh.edchar="$(printf "\E\E")"
> > elif [ $emacs_completion_tab_count -ge 2 ] ; then
> > .sh.edchar="$(printf "\E=")"
> > fi
> > else
> > emacs_completion_tab_count=0
> > fi
> > }
> > 
> > trap emacs_completion KEYBD
> > set -o gmacs
> > -- snip --
> > 
> > David/April: Are there any objections of making the "gmacs" editor mode
> > the "default" for both Solaris (for both "ksh93r+" and
> > ksh93-integration) and Linux ?
> 
> Solaris ksh also does not have a default editor mode if
> VISUAL and EDITOR are not set.  A default seems like a good idea.
> Is there any reason for gmacs over emacs or vi mode?

Well, the idea behind making "gmacs" or "emacs" the default edit mode is
that almost all X11 GUI toolkits, including Qt/KDE/Motif/libXUL/Xaw/GTK+
use some kind of "emacs" editing mode in their text input fields. I
picked "gmacs" as choice since "emacs" should continue to behave like
the current "emacs" mode in ksh93 (e.g. for "power users"), including
the ability to insert TAB characters on demand while "gmacs" should
evolve to be more beginner/non-programmer friendly.
I hate to admit it - but bash3 is good at at least one point: Giving
people an easy-to-use shell interface with powerfull completion
features. I'd love to see that the "gmacs" editing more becomes similar
easy-to-use since it would mean we could simply drop the bash nightmare
(which is both a memory hog and i18n nightmare) for our accounts and
have one shell (=ksh93) which serves all people equally (both
beginners/non-programmers and the "power users").

BTW: Attached is the new patch
("ksh93_solaris_default_editor_mode_gmacs_clear005.diff.txt") for the
making "gmacs" the default editing mode. The patch now only makes
"gmacs" the default edit mode if neither ${EDITOR} nor ${VISUAL} nor
anyother edit mode are set (David/Glenn: the thing with making CTRL-L
calling "/usr/bin/clear" wasn't detected yet... or was it ? :-) ).

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
-------------- next part --------------
Index: src/cmd/ksh/Makefile.com
===================================================================
--- src/cmd/ksh/Makefile.com	(revision 225)
+++ src/cmd/ksh/Makefile.com	(working copy)
@@ -56,6 +56,7 @@
 	-DSHOPT_RAWONLY \
 	-DSHOPT_SUID_EXEC \
 	-DSHOPT_VSH \
+	-DSHOPT_DEFAULTEDITMODE=SH_GMACS \
         -D_BLD_shell \
 	-D_PACKAGE_ast \
 	'-DUSAGE_LICENSE="[-author?David Korn <dgk@research.att.com>][-copyright?Copyright \
(c) 1982-2006 AT&T Knowledge \
Ventures][-license?http://www.opensource.org/licenses/cpl1.0.txt][--catalog?libshell]"'
                
Index: src/lib/libshell/common/edit/emacs.c
===================================================================
--- src/lib/libshell/common/edit/emacs.c	(revision 222)
+++ src/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 */
@@ -574,10 +585,23 @@
 			}
 			continue;
 		case cntl('L'):
-			ed_crlf(ep->ed);
+			if (sh_isoption(SH_GMACS))
+			{
+				/* FixMe: a better way is needed here than
+				 * calling |system()| - unfortunately I do
+				 * not know a "portable" way (except
+				 * linking to curses/ncurses) */
+				/* clear the screen (like bash/readline does) */
+				system("clear");
+			}
+			else
+			{
+				ed_crlf(ep->ed);
+			}
 			draw(ep,REFRESH);
 			continue;
 		case cntl('[') :
+esc_:
 			adjust = escape(ep,out,oadjust);
 			continue;
 		case cntl('R') :
Index: src/lib/libshell/common/sh/init.c
===================================================================
--- src/lib/libshell/common/sh/init.c	(revision 222)
+++ src/lib/libshell/common/sh/init.c	(working copy)
@@ -937,6 +937,17 @@
 #if SHOPT_TIMEOUT
 	sh.st.tmout = SHOPT_TIMEOUT;
 #endif /* SHOPT_TIMEOUT */
+#ifdef SHOPT_DEFAULTEDITMODE
+	/* set platform-specific default modes (if EDITOR/VISUAL env vars
+	 * are not defined and no edit mode was set yet) */
+	if((sh_isoption(SH_VI) || sh_isoption(SH_VIRAW) ||
+	    sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS) ||
+	    nv_getval(nv_scoped(VISINOD)) ||
+	    nv_getval(nv_scoped(EDITNOD)) ) == 0)
+	{
+		sh_onoption(SHOPT_DEFAULTEDITMODE);
+	}
+#endif /* SHOPT_DEFAULTEDITMODE */
 	/* initialize jobs table */
 	job_clear();
 	if(argc>0)
Index: src/lib/libshell/Makefile.com
===================================================================
--- src/lib/libshell/Makefile.com	(revision 222)
+++ src/lib/libshell/Makefile.com	(working copy)
@@ -127,6 +127,7 @@
 	-DSHOPT_RAWONLY \
 	-DSHOPT_SUID_EXEC \
 	-DSHOPT_VSH \
+	-DSHOPT_DEFAULTEDITMODE=SH_GMACS \
         -D_BLD_shell \
 	-D_PACKAGE_ast \
 	'-DUSAGE_LICENSE="[-author?David Korn <dgk@research.att.com>][-copyright?Copyright \
(c) 1982-2006 AT&T Knowledge \
Ventures][-license?http://www.opensource.org/licenses/cpl1.0.txt][--catalog?libshell]"'



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic