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 ?
----
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') :
Index: lib/libshell/common/sh/init.c
===================================================================
--- lib/libshell/common/sh/init.c (revision 222)
+++ lib/libshell/common/sh/init.c (working copy)
@@ -937,6 +937,10 @@
#if SHOPT_TIMEOUT
sh.st.tmout = SHOPT_TIMEOUT;
#endif /* SHOPT_TIMEOUT */
+/* set (platform-specific default modes) */
+#ifdef SHOPT_DEFAULTEDITMODE
+ sh_onoption(SHOPT_DEFAULTEDITMODE);
+#endif
/* initialize jobs table */
job_clear();
if(argc>0)
Index: lib/libshell/Makefile.com
===================================================================
--- lib/libshell/Makefile.com (revision 222)
+++ 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 at
research.att.com>][-copyright?Copyright (c) 1982-2006 AT&T Knowledge
Ventures][-license?http://www.opensource.org/licenses/cpl1.0.txt][--catalog?libshell]"'