mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-11-19 05:24:23 +01:00
19295: $CONTEXT zle parameter
This commit is contained in:
parent
ff1feb920f
commit
6eb5f99f1e
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
15
Src/zsh.h
15
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. */
|
||||
|
Loading…
Reference in New Issue
Block a user