about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Doc/Zsh/zle.yo19
-rw-r--r--Src/Zle/zle_main.c13
-rw-r--r--Src/Zle/zle_params.c26
-rw-r--r--Src/init.c6
-rw-r--r--Src/input.c5
-rw-r--r--Src/loop.c2
-rw-r--r--Src/zsh.h15
7 files changed, 76 insertions, 10 deletions
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 409a04026..0ebbb2739 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -593,6 +593,25 @@ The number of screen lines needed for the edit buffer currently
 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
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index c3317175c..25d2539dc 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -58,6 +58,11 @@ mod_export int hascompmod;
 /**/
 int zlereadflags;
 
+/* ZLCON_* flags passed to zleread() */
+
+/**/
+int zlecontext;
+
 /* != 0 if we're done editing */
 
 /**/
@@ -735,7 +740,7 @@ zlecore(void)
 
 /**/
 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 @@ zleread(char *lp, char *rp, int flags)
     free_prepostdisplay();
 
     zlereadflags = flags;
+    zlecontext = context;
     histline = curhist;
     undoing = 1;
     line = (unsigned char *)zalloc((linesz = 256) + 2);
@@ -838,7 +844,7 @@ zleread(char *lp, char *rp, int flags)
     trashzle();
     free(lpromptbuf);
     free(rpromptbuf);
-    zleactive = zlereadflags = lastlistlen = 0;
+    zleactive = zlereadflags = lastlistlen = zlecontext = 0;
     alarm(0);
 
     freeundo();
@@ -1154,7 +1160,8 @@ bin_vared(char *name, char **args, Options ops, int func)
     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;
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index a9fd93450..0d7b20119 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -91,6 +91,8 @@ static struct zleparam {
 	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 }
 };
 
@@ -548,3 +550,27 @@ get_lsearch(Param pm)
     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;
+    }
+}
diff --git a/Src/init.c b/Src/init.c
index b4b7e6f97..15e7f9c60 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1146,17 +1146,17 @@ mod_export ZleVoidIntFn zlesetkeymapptr = noop_function_int;
 
 /**/
 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;
diff --git a/Src/input.c b/Src/input.c
index 3867474b8..c07583781 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -223,6 +223,7 @@ static int
 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 @@ inputline(void)
 	    ingetcpmptl = prompt2;
 	    if (rprompt2)
 		ingetcpmptr = rprompt2;
+	    context = ZLCON_LINE_CONT;
 	}
 	else {
 	    ingetcpmptl = prompt;
@@ -272,7 +274,8 @@ inputline(void)
 	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) {
diff --git a/Src/loop.c b/Src/loop.c
index 4da5a50f0..5b09a76df 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -245,7 +245,7 @@ execselect(Estate state, int do_exec)
 		    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;
diff --git a/Src/zsh.h b/Src/zsh.h
index f60fa5f45..cf470f001 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -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 @@ struct heap {
 #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 int (*CompctlReadFn) _((char *, char **, Options, char *));
 
 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.                      */