1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-30 19:20:53 +02:00

19295: $CONTEXT zle parameter

This commit is contained in:
Peter Stephenson 2003-12-15 22:45:27 +00:00
parent ff1feb920f
commit 6eb5f99f1e
7 changed files with 76 additions and 10 deletions

View file

@ -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 displayed on screen (i.e. without any changes to the preceding
parameters done after the last redisplay); read-only. 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) vindex(CURSOR)
item(tt(CURSOR) (integer))( item(tt(CURSOR) (integer))(
The offset of the cursor, within the edit buffer. This is in the range The offset of the cursor, within the edit buffer. This is in the range

View file

@ -58,6 +58,11 @@ mod_export int hascompmod;
/**/ /**/
int zlereadflags; int zlereadflags;
/* ZLCON_* flags passed to zleread() */
/**/
int zlecontext;
/* != 0 if we're done editing */ /* != 0 if we're done editing */
/**/ /**/
@ -735,7 +740,7 @@ zlecore(void)
/**/ /**/
unsigned char * unsigned char *
zleread(char *lp, char *rp, int flags) zleread(char *lp, char *rp, int flags, int context)
{ {
unsigned char *s; unsigned char *s;
int old_errno = errno; int old_errno = errno;
@ -787,6 +792,7 @@ zleread(char *lp, char *rp, int flags)
free_prepostdisplay(); free_prepostdisplay();
zlereadflags = flags; zlereadflags = flags;
zlecontext = context;
histline = curhist; histline = curhist;
undoing = 1; undoing = 1;
line = (unsigned char *)zalloc((linesz = 256) + 2); line = (unsigned char *)zalloc((linesz = 256) + 2);
@ -838,7 +844,7 @@ zleread(char *lp, char *rp, int flags)
trashzle(); trashzle();
free(lpromptbuf); free(lpromptbuf);
free(rpromptbuf); free(rpromptbuf);
zleactive = zlereadflags = lastlistlen = 0; zleactive = zlereadflags = lastlistlen = zlecontext = 0;
alarm(0); alarm(0);
freeundo(); freeundo();
@ -1154,7 +1160,8 @@ bin_vared(char *name, char **args, Options ops, int func)
if (OPT_ISSET(ops,'h')) if (OPT_ISSET(ops,'h'))
hbegin(2); hbegin(2);
isfirstln = OPT_ISSET(ops,'e'); 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')) if (OPT_ISSET(ops,'h'))
hend(NULL); hend(NULL);
isfirstln = ifl; isfirstln = ifl;

View file

@ -91,6 +91,8 @@ static struct zleparam {
zleunsetfn, NULL }, zleunsetfn, NULL },
{ "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch), { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch),
zleunsetfn, NULL }, zleunsetfn, NULL },
{ "CONTEXT", PM_SCALAR | PM_READONLY, NULL, FN(get_context),
zleunsetfn, NULL },
{ NULL, 0, NULL, NULL, NULL, NULL } { NULL, 0, NULL, NULL, NULL, NULL }
}; };
@ -548,3 +550,27 @@ get_lsearch(Param pm)
else else
return ""; 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;
}
}

View file

@ -1146,17 +1146,17 @@ mod_export ZleVoidIntFn zlesetkeymapptr = noop_function_int;
/**/ /**/
unsigned char * unsigned char *
autoload_zleread(char *lp, char *rp, int ha) autoload_zleread(char *lp, char *rp, int ha, int con)
{ {
zlereadptr = fallback_zleread; zlereadptr = fallback_zleread;
if (load_module("zsh/zle")) if (load_module("zsh/zle"))
load_module("zsh/compctl"); load_module("zsh/compctl");
return zleread(lp, rp, ha); return zleread(lp, rp, ha, con);
} }
/**/ /**/
mod_export unsigned char * mod_export unsigned char *
fallback_zleread(char *lp, char *rp, int ha) fallback_zleread(char *lp, char *rp, int ha, int con)
{ {
char *pptbuf; char *pptbuf;
int pptlen; int pptlen;

View file

@ -223,6 +223,7 @@ static int
inputline(void) inputline(void)
{ {
char *ingetcline, *ingetcpmptl = NULL, *ingetcpmptr = NULL; char *ingetcline, *ingetcpmptl = NULL, *ingetcpmptr = NULL;
int context = ZLCON_LINE_START;
/* If reading code interactively, work out the prompts. */ /* If reading code interactively, work out the prompts. */
if (interact && isset(SHINSTDIN)) { if (interact && isset(SHINSTDIN)) {
@ -230,6 +231,7 @@ inputline(void)
ingetcpmptl = prompt2; ingetcpmptl = prompt2;
if (rprompt2) if (rprompt2)
ingetcpmptr = rprompt2; ingetcpmptr = rprompt2;
context = ZLCON_LINE_CONT;
} }
else { else {
ingetcpmptl = prompt; ingetcpmptl = prompt;
@ -272,7 +274,8 @@ inputline(void)
int flags = ZLRF_HISTORY|ZLRF_NOSETTY; int flags = ZLRF_HISTORY|ZLRF_NOSETTY;
if (isset(IGNOREEOF)) if (isset(IGNOREEOF))
flags |= ZLRF_IGNOREEOF; flags |= ZLRF_IGNOREEOF;
ingetcline = (char *)zleread(ingetcpmptl, ingetcpmptr, flags); ingetcline = (char *)zleread(ingetcpmptl, ingetcpmptr, flags,
context);
histdone |= HISTFLAG_SETTY; histdone |= HISTFLAG_SETTY;
} }
if (!ingetcline) { if (!ingetcline) {

View file

@ -245,7 +245,7 @@ execselect(Estate state, int do_exec)
int oef = errflag; int oef = errflag;
isfirstln = 1; isfirstln = 1;
str = (char *)zleread(prompt3, NULL, 0); str = (char *)zleread(prompt3, NULL, 0, ZLCON_SELECT);
if (errflag) if (errflag)
str = NULL; str = NULL;
errflag = oef; errflag = oef;

View file

@ -28,7 +28,7 @@
*/ */
#define trashzle() trashzleptr() #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 spaceinline(X) spaceinlineptr(X)
#define zrefresh() refreshptr() #define zrefresh() refreshptr()
@ -1761,6 +1761,17 @@ struct heap {
#define ZLRF_NOSETTY 0x02 /* Don't set tty before return */ #define ZLRF_NOSETTY 0x02 /* Don't set tty before return */
#define ZLRF_IGNOREEOF 0x04 /* Ignore an EOF from the keyboard */ #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 */ /* Entry points */
/****************/ /****************/
@ -1773,7 +1784,7 @@ typedef int (*CompctlReadFn) _((char *, char **, Options, char *));
typedef void (*ZleVoidFn) _((void)); typedef void (*ZleVoidFn) _((void));
typedef void (*ZleVoidIntFn) _((int)); typedef void (*ZleVoidIntFn) _((int));
typedef unsigned char * (*ZleReadFn) _((char *, char *, int)); typedef unsigned char * (*ZleReadFn) _((char *, char *, int, int));
/***************************************/ /***************************************/
/* Hooks in core. */ /* Hooks in core. */