zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: $CONTEXT
@ 2003-12-15 22:43 Peter Stephenson
  2003-12-16  9:56 ` Oliver Kiddle
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2003-12-15 22:43 UTC (permalink / raw)
  To: Zsh hackers list

Here is the zle parameter CONTEXT.  There are four contexts start, cont,
select, vared.  Let me know if you think there should be more.

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.31
diff -u -r1.31 zle.yo
--- Doc/Zsh/zle.yo	12 Dec 2003 22:53:28 -0000	1.31
+++ Doc/Zsh/zle.yo	15 Dec 2003 22:35:32 -0000
@@ -593,6 +593,25 @@
 displayed on screen (i.e. without any changes to the preceding
 parameters done after the last redisplay); read-only.
 )
+vindex(CONTEXT)
+item(tt(CONTEXT) (scalar))(
+The context in which zle was called to read a line; read-only.  One of
+the values:
+startitem()
+item(start)(
+The start of a command line (at prompt tt(PS1)).
+)
+item(cont)(
+A continuation to a command line (at prompt tt(PS2)).
+)
+item(select)(
+In a tt(select) loop.
+)
+item(vared)(
+Editing a variable in tt(vared).
+)
+enditem()
+)
 vindex(CURSOR)
 item(tt(CURSOR) (integer))(
 The offset of the cursor, within the edit buffer.  This is in the range
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.38
diff -u -r1.38 init.c
--- Src/init.c	13 Nov 2003 14:34:38 -0000	1.38
+++ Src/init.c	15 Dec 2003 22:35:41 -0000
@@ -1146,17 +1146,17 @@
 
 /**/
 unsigned char *
-autoload_zleread(char *lp, char *rp, int ha)
+autoload_zleread(char *lp, char *rp, int ha, int con)
 {
     zlereadptr = fallback_zleread;
     if (load_module("zsh/zle"))
 	load_module("zsh/compctl");
-    return zleread(lp, rp, ha);
+    return zleread(lp, rp, ha, con);
 }
 
 /**/
 mod_export unsigned char *
-fallback_zleread(char *lp, char *rp, int ha)
+fallback_zleread(char *lp, char *rp, int ha, int con)
 {
     char *pptbuf;
     int pptlen;
Index: Src/input.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/input.c,v
retrieving revision 1.9
diff -u -r1.9 input.c
--- Src/input.c	29 Oct 2003 19:17:30 -0000	1.9
+++ Src/input.c	15 Dec 2003 22:35:43 -0000
@@ -223,6 +223,7 @@
 inputline(void)
 {
     char *ingetcline, *ingetcpmptl = NULL, *ingetcpmptr = NULL;
+    int context = ZLCON_LINE_START;
 
     /* If reading code interactively, work out the prompts. */
     if (interact && isset(SHINSTDIN)) {
@@ -230,6 +231,7 @@
 	    ingetcpmptl = prompt2;
 	    if (rprompt2)
 		ingetcpmptr = rprompt2;
+	    context = ZLCON_LINE_CONT;
 	}
 	else {
 	    ingetcpmptl = prompt;
@@ -272,7 +274,8 @@
 	int flags = ZLRF_HISTORY|ZLRF_NOSETTY;
 	if (isset(IGNOREEOF))
 	    flags |= ZLRF_IGNOREEOF;
-	ingetcline = (char *)zleread(ingetcpmptl, ingetcpmptr, flags);
+	ingetcline = (char *)zleread(ingetcpmptl, ingetcpmptr, flags,
+				     context);
 	histdone |= HISTFLAG_SETTY;
     }
     if (!ingetcline) {
Index: Src/loop.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/loop.c,v
retrieving revision 1.10
diff -u -r1.10 loop.c
--- Src/loop.c	17 Feb 2003 14:07:10 -0000	1.10
+++ Src/loop.c	15 Dec 2003 22:35:43 -0000
@@ -245,7 +245,7 @@
 		    int oef = errflag;
 
 		    isfirstln = 1;
-		    str = (char *)zleread(prompt3, NULL, 0);
+		    str = (char *)zleread(prompt3, NULL, 0, ZLCON_SELECT);
 		    if (errflag)
 			str = NULL;
 		    errflag = oef;
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.51
diff -u -r1.51 zsh.h
--- Src/zsh.h	13 Nov 2003 14:34:38 -0000	1.51
+++ Src/zsh.h	15 Dec 2003 22:35:50 -0000
@@ -28,7 +28,7 @@
  */
 
 #define trashzle()      trashzleptr()
-#define zleread(X,Y,H)  zlereadptr(X,Y,H)
+#define zleread(X,Y,H,C)  zlereadptr(X,Y,H,C)
 #define spaceinline(X)  spaceinlineptr(X)
 #define zrefresh()      refreshptr()
 
@@ -1761,6 +1761,17 @@
 #define ZLRF_NOSETTY	0x02	/* Don't set tty before return */
 #define ZLRF_IGNOREEOF  0x04	/* Ignore an EOF from the keyboard */
 
+/***************************/
+/* Context of zleread call */
+/***************************/
+
+enum {
+    ZLCON_LINE_START,		/* Command line at PS1 */
+    ZLCON_LINE_CONT,		/* Command line at PS2 */
+    ZLCON_SELECT,		/* Select loop */
+    ZLCON_VARED			/* Vared command */
+};
+
 /****************/
 /* Entry points */
 /****************/
@@ -1773,7 +1784,7 @@
 
 typedef void (*ZleVoidFn) _((void));
 typedef void (*ZleVoidIntFn) _((int));
-typedef unsigned char * (*ZleReadFn) _((char *, char *, int));
+typedef unsigned char * (*ZleReadFn) _((char *, char *, int, int));
 
 /***************************************/
 /* Hooks in core.                      */
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.38
diff -u -r1.38 zle_main.c
--- Src/Zle/zle_main.c	12 Dec 2003 22:53:28 -0000	1.38
+++ Src/Zle/zle_main.c	15 Dec 2003 22:35:59 -0000
@@ -58,6 +58,11 @@
 /**/
 int zlereadflags;
 
+/* ZLCON_* flags passed to zleread() */
+
+/**/
+int zlecontext;
+
 /* != 0 if we're done editing */
 
 /**/
@@ -735,7 +740,7 @@
 
 /**/
 unsigned char *
-zleread(char *lp, char *rp, int flags)
+zleread(char *lp, char *rp, int flags, int context)
 {
     unsigned char *s;
     int old_errno = errno;
@@ -787,6 +792,7 @@
     free_prepostdisplay();
 
     zlereadflags = flags;
+    zlecontext = context;
     histline = curhist;
     undoing = 1;
     line = (unsigned char *)zalloc((linesz = 256) + 2);
@@ -838,7 +844,7 @@
     trashzle();
     free(lpromptbuf);
     free(rpromptbuf);
-    zleactive = zlereadflags = lastlistlen = 0;
+    zleactive = zlereadflags = lastlistlen = zlecontext = 0;
     alarm(0);
 
     freeundo();
@@ -1154,7 +1160,8 @@
     if (OPT_ISSET(ops,'h'))
 	hbegin(2);
     isfirstln = OPT_ISSET(ops,'e');
-    t = (char *) zleread(p1, p2, OPT_ISSET(ops,'h') ? ZLRF_HISTORY : 0);
+    t = (char *) zleread(p1, p2, OPT_ISSET(ops,'h') ? ZLRF_HISTORY : 0,
+			 ZLCON_VARED);
     if (OPT_ISSET(ops,'h'))
 	hend(NULL);
     isfirstln = ifl;
Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.11
diff -u -r1.11 zle_params.c
--- Src/Zle/zle_params.c	29 Oct 2003 19:17:48 -0000	1.11
+++ Src/Zle/zle_params.c	15 Dec 2003 22:36:00 -0000
@@ -91,6 +91,8 @@
 	zleunsetfn, NULL },
     { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch),
         zleunsetfn, NULL },
+    { "CONTEXT", PM_SCALAR | PM_READONLY, NULL, FN(get_context),
+	zleunsetfn, NULL },
     { NULL, 0, NULL, NULL, NULL, NULL }
 };
 
@@ -547,4 +549,28 @@
 	return metafy(previous_search, previous_search_len, META_HEAPDUP);
     else
 	return "";
+}
+
+/**/
+static char *
+get_context(Param pm)
+{
+    switch (zlecontext) {
+    case ZLCON_LINE_CONT:
+	return "cont";
+	break;
+
+    case ZLCON_SELECT:
+	return "select";
+	break;
+
+    case ZLCON_VARED:
+	return "vared";
+	break;
+
+    case ZLCON_LINE_START:
+    default:
+	return "start";
+	break;
+    }
 }

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


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

* Re: PATCH: $CONTEXT
  2003-12-15 22:43 PATCH: $CONTEXT Peter Stephenson
@ 2003-12-16  9:56 ` Oliver Kiddle
  2003-12-16 10:30   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2003-12-16  9:56 UTC (permalink / raw)
  To: Zsh hackers list

Peter wrote:
> Here is the zle parameter CONTEXT.  There are four contexts start, cont,
> select, vared.  Let me know if you think there should be more.

Would `primary' and `secondary' perhaps be better values for `start'
and `cont'?  That would tie up more closely with the documentation for
PS1 and PS2.

As for other values, reading from the minibuffer probably ought to be
relevant but I suspect it isn't.  Replacing accept-line caused me
problems from it.  Menu selection and scrolling came to mind but they
take place from a primary or secondary prompt. If we're going to have a
number of different minor things, a zlestate associative array like
compstate might be better.

Would it perhaps be worth making a convention of sticking this $CONTEXT
in a second component of the zstyle context (after :zle:) when looking
up styles from zle widgets?

Oliver


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

* Re: PATCH: $CONTEXT
  2003-12-16  9:56 ` Oliver Kiddle
@ 2003-12-16 10:30   ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2003-12-16 10:30 UTC (permalink / raw)
  To: Zsh hackers list

Oliver Kiddle wrote:
> Peter wrote:
> > Here is the zle parameter CONTEXT.  There are four contexts start, cont,
> > select, vared.  Let me know if you think there should be more.
> 
> Would `primary' and `secondary' perhaps be better values for `start'
> and `cont'?  That would tie up more closely with the documentation for
> PS1 and PS2.

Maybe, but it's a bit ugly, and a bit less obvious what it's for.

> As for other values, reading from the minibuffer probably ought to be
> relevant but I suspect it isn't.  Replacing accept-line caused me
> problems from it.  Menu selection and scrolling came to mind but they
> take place from a primary or secondary prompt. If we're going to have a
> number of different minor things, a zlestate associative array like
> compstate might be better.

Yes, these are slightly different and not actually orthogonal to the
primary context.

> Would it perhaps be worth making a convention of sticking this $CONTEXT
> in a second component of the zstyle context (after :zle:) when looking
> up styles from zle widgets?

On reflection, this makes some sense... you might different word
behaviour in a vared than at the command line, for example.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: PATCH: $CONTEXT
@ 2003-12-17 20:09 Felix Rosencrantz
  0 siblings, 0 replies; 4+ messages in thread
From: Felix Rosencrantz @ 2003-12-17 20:09 UTC (permalink / raw)
  To: zsh-workers

Peter wrote:
> Here is the zle parameter CONTEXT. There are four contexts start, cont,
> select, vared. Let me know if you think there should be more.

It might also be useful to include interactive search as a context, and
any other sub-prompt prompt modes.
 
-FR
ps as long as you are looking at zle parameters, it would be handy
if HISTNO was writable.... (there was a thread that lost Barts focus
ending around zsh-users:6618)



__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/


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

end of thread, other threads:[~2003-12-17 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-15 22:43 PATCH: $CONTEXT Peter Stephenson
2003-12-16  9:56 ` Oliver Kiddle
2003-12-16 10:30   ` Peter Stephenson
2003-12-17 20:09 Felix Rosencrantz

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