Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: $CONTEXT
- X-seq: zsh-workers 19295
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: $CONTEXT
- Date: Mon, 15 Dec 2003 22:43:59 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
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@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk
Messages sorted by:
Reverse Date,
Date,
Thread,
Author