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

List:       ast-users
Subject:    [ast-users] TAB-TAB completion patch #004 (which makes "gmacs" the
From:       roland.mainz () nrubsig ! org (Roland Mainz)
Date:       2006-05-11 20:31:38
Message-ID: 4463D75A.876DA4D6 () nrubsig ! org
[Download RAW message or body]


Hi!

----

Attached is the 4th iteration of the ksh93 TAB-TAB completion patch
("ksh93_tab_tab_gmacs_completion_default_editor_mode_try4.diff.txt").

* Changes since previous version
(http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2006-May/000285.html):
 1. Synced build flags in usr/src/cmd/ksh/Makefile.com with
usr/src/lib/libshell/Makefile.com
2. Changed "gmacs" editing mode that ctrl-l now clears the screen like
bash3/readline do
3. Setting the default editing mode (to "gmacs") is now only done if no
other editing mode was set yet per David Korn's suggestion (e.g. "gmacs"
is only made the default editing mode if no command line option or
related environment variable (like EDITOR=vi) is set).

[2] requires some discussion whether this is a good idea (and the
implementation is quite bad - I didn'd found any other ways except
linking against libcurses/libxcurses or calling |system("clear")| ... if
we want to keep it then a better implementation may be required (but how
?)))

----

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: cmd/ksh/Makefile.com
===================================================================
--- cmd/ksh/Makefile.com	(revision 225)
+++ 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: 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 */
@@ -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: 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,14 @@
 #if SHOPT_TIMEOUT
 	sh.st.tmout = SHOPT_TIMEOUT;
 #endif /* SHOPT_TIMEOUT */
+/* set platform-specific default modes (if no editing mode was set yet) */
+#ifdef SHOPT_DEFAULTEDITMODE
+	if((sh_isoption(SH_VI) || sh_isoption(SH_VIRAW) ||
+	    sh_isoption(SH_EMACS) || sh_isoption(SH_GMACS)) == 0)
+	{
+		sh_onoption(SHOPT_DEFAULTEDITMODE);
+	}
+#endif /* SHOPT_DEFAULTEDITMODE */
 	/* 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@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