Skip to content

Commit

Permalink
Remove SHOPT_EDPREDICT (re: 9530f09)
Browse files Browse the repository at this point in the history
Due to its brokenness, lack of awareness and interest among users,
and no one stepping up to fix it, this is now removed from the dev
branch to avoid bit rot, as announced in #233 on 17th February.

Resolves: #233
  • Loading branch information
McDutchie committed Aug 26, 2022
1 parent 278c48c commit 5366967
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 422 deletions.
8 changes: 0 additions & 8 deletions src/cmd/ksh93/README
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ The options have the following defaults and meanings:

ECHOPRINT off Make echo equivalent to print.

EDPREDICT off Enables history pattern search menu. As you begin a line
with a #, the following characters are treated as a shell
pattern and cause matching lines from the history file to
be displayed as a numbered list as you type. You can
scroll up and down this list or you can use <ESC>nTAB to
make this the current line (n defaults to 1 if omitted).
Experimental. Bugs: https://github.com/ksh93/ksh/issues/233

ESH on Compile with emacs command line editing. The original
emacs line editor code was provided by Mike Veach at IH.

Expand Down
1 change: 0 additions & 1 deletion src/cmd/ksh93/SHOPT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ SHOPT CRNL= # accept MS Windows newlines (<cr><nl>) for <nl>
SHOPT DEVFD= # use /dev/fd instead of FIFOs for process substitutions
SHOPT DYNAMIC=0 # dynamic loading for builtins
SHOPT ECHOPRINT= # make echo equivalent to print
SHOPT EDPREDICT=0 # History pattern search menu (type #<pattern>, then ESC <number> TAB). Experimental.
SHOPT ESH=1 # emacs/gmacs edit mode
SHOPT FILESCAN=1 # fast file scan: while <file; do [use $REPLY or positional parameters]; done
SHOPT FIXEDARRAY=1 # fixed dimension indexed array
Expand Down
222 changes: 0 additions & 222 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,6 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
ep->e_fd = fd;
ep->e_multiline = sh_editor_active() && sh_isoption(SH_MULTILINE);
sh.winch = 0;
#if SHOPT_EDPREDICT
ep->hlist = 0;
ep->nhlist = 0;
ep->hoff = 0;
#endif /* SHOPT_EDPREDICT */
ep->e_stkoff = staktell();
ep->e_stkptr = stakfreeze(0);
if(!(last = sh.prompt))
Expand Down Expand Up @@ -1624,223 +1619,6 @@ static int keytrap(Edit_t *ep,char *inbuff,register int insize, int bufsize, int
return(insize);
}

#if SHOPT_EDPREDICT
static int ed_sortdata(const char *s1, const char *s2)
{
Histmatch_t *m1 = (Histmatch_t*)s1;
Histmatch_t *m2 = (Histmatch_t*)s2;
return(strcmp(m1->data,m2->data));
}

static int ed_sortindex(const char *s1, const char *s2)
{
Histmatch_t *m1 = (Histmatch_t*)s1;
Histmatch_t *m2 = (Histmatch_t*)s2;
return(m2->index-m1->index);
}

static int ed_histlencopy(const char *cp, char *dp)
{
int c,n=1,col=1;
const char *oldcp=cp;
for(n=0;c = mbchar(cp);oldcp=cp,col++)
{
if(c=='\n' && *cp)
{
n += 2;
if(dp)
{
*dp++ = '^';
*dp++ = 'J';
col +=2;
}
}
else if(c=='\t')
{
n++;
if(dp)
*dp++ = ' ';
}
else
{
n += cp-oldcp;
if(dp)
{
while(oldcp < cp)
*dp++ = *oldcp++;
}
}
}
return(n);
}

int ed_histgen(Edit_t *ep,const char *pattern)
{
Histmatch_t *mp,*mplast=0;
History_t *hp;
off_t offset;
int ac=0,l,n,index1,index2;
size_t m;
char *cp, **argv=0, **av, **ar;
static int maxmatch;
if(!(hp=sh.hist_ptr) && (!nv_getval(HISTFILE) || !sh_histinit()))
return(0);
if(ep->e_cur <=2)
maxmatch = 0;
else if(maxmatch && ep->e_cur > maxmatch)
{
ep->hlist = 0;
ep->hfirst = 0;
return(0);
}
hp = sh.hist_ptr;
if(*pattern=='#' && *++pattern=='#')
return(0);
cp = stakalloc(m=strlen(pattern)+6);
sfsprintf(cp,m,"@(%s)*%c",pattern,0);
if(ep->hlist)
{
m = strlen(ep->hpat)-4;
if(strncmp(pattern,ep->hpat+2,m)==0)
{
n = strcmp(cp,ep->hpat)==0;
for(argv=av=(char**)ep->hlist,mp=ep->hfirst; mp;mp= mp->next)
{
if(n || strmatch(mp->data,cp))
*av++ = (char*)mp;
}
*av = 0;
ep->hmax = av-argv;
if(ep->hmax==0)
maxmatch = ep->e_cur;
return(ep->hmax=av-argv);
}
stakset(ep->e_stkptr,ep->e_stkoff);
}
if((m=strlen(cp)) >= sizeof(ep->hpat))
m = sizeof(ep->hpat)-1;
memcpy(ep->hpat,cp,m);
ep->hpat[m] = 0;
pattern = cp;
index1 = (int)hp->histind;
for(index2=index1-hp->histsize; index1>index2; index1--)
{
offset = hist_tell(hp,index1);
sfseek(hp->histfp,offset,SEEK_SET);
if(!(cp = sfgetr(hp->histfp,0,0)))
continue;
if(*cp=='#')
continue;
if(strmatch(cp,pattern))
{
l = ed_histlencopy(cp,(char*)0);
mp = (Histmatch_t*)stakalloc(sizeof(Histmatch_t)+l);
mp->next = mplast;
mplast = mp;
mp->len = l;
ed_histlencopy(cp,mp->data);
mp->count = 1;
mp->data[l] = 0;
mp->index = index1;
ac++;
}
}
if(ac>0)
{
l = ac;
argv = av = (char**)stakalloc((ac+1)*sizeof(char*));
for(; l>=0 && (*av= (char*)mp); mp=mp->next,av++)
l--;
*av = 0;
strsort(argv,ac,ed_sortdata);
mplast = (Histmatch_t*)argv[0];
for(ar= av= &argv[1]; mp=(Histmatch_t*)*av; av++)
{
if(strcmp(mp->data,mplast->data)==0)
{
mplast->count++;
if(mp->index> mplast->index)
mplast->index = mp->index;
continue;
}
*ar++ = (char*)(mplast=mp);
}
*ar = 0;
mplast->next = 0;
ac = ar-argv;
strsort(argv,ac,ed_sortindex);
mplast = (Histmatch_t*)argv[0];
for(av= &argv[1]; mp=(Histmatch_t*)*av; av++, mplast=mp)
mplast->next = mp;
mplast->next = 0;
}
if (argv)
{
ep->hlist = (Histmatch_t**)argv;
ep->hfirst = ep->hlist?ep->hlist[0]:0;
}
else
ep->hfirst = 0;
return(ep->hmax=ac);
}

#if SHOPT_ESH || SHOPT_VSH
void ed_histlist(Edit_t *ep,int n)
{
Histmatch_t *mp,**mpp = ep->hlist+ep->hoff;
int i,last=0,save[2];
if(n)
{
/* don't bother updating the screen if there is typeahead */
if(!ep->e_lookahead && sfpkrd(ep->e_fd,save,1,'\r',200L,-1)>0)
ed_ungetchar(ep,save[0]);
if(ep->e_lookahead)
return;
ed_putchar(ep,'\n');
ed_putchar(ep,'\r');
}
else
{
stakset(ep->e_stkptr,ep->e_stkoff);
ep->hlist = 0;
ep->nhlist = 0;
}
ed_putstring(ep,ERASE_EOS);
if(n)
{
for(i=1; (mp= *mpp) && i <= 16 ; i++,mpp++)
{
last = 0;
if(mp->len >= ep->e_winsz-4)
{
last = ep->e_winsz-4;
save[0] = mp->data[last-1];
save[1] = mp->data[last];
mp->data[last-1] = '\n';
mp->data[last] = 0;
}
ed_putchar(ep,i<10?' ':'1');
ed_putchar(ep,i<10?'0'+i:'0'+i-10);
ed_putchar(ep,')');
ed_putchar(ep,' ');
ed_putstring(ep,mp->data);
if(last)
{
mp->data[last-1] = save[0];
mp->data[last] = save[1];
}
ep->nhlist = i;
}
last = i-1;
while(i-->0)
ed_putstring(ep,CURSOR_UP);
}
ed_flush(ep);
}
#endif /* SHOPT_ESH || SHOPT_VSH */

#endif /* SHOPT_EDPREDICT */

void *ed_open(void)
{
Edit_t *ed = sh_newof(0,Edit_t,1,0);
Expand Down
85 changes: 0 additions & 85 deletions src/cmd/ksh93/edit/emacs.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,6 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
search(ep,out,count);
goto drawline;
case cntl('P') :
#if SHOPT_EDPREDICT
if(ep->ed->hlist)
{
if(ep->ed->hoff == 0)
{
beep();
continue;
}
ep->ed->hoff--;
goto hupdate;
}
#endif /* SHOPT_EDPREDICT */
if (count <= hloff)
hloff -= count;
else
Expand Down Expand Up @@ -665,21 +653,6 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
c = '\n';
goto process;
case cntl('N') :
#if SHOPT_EDPREDICT
if(ep->ed->hlist)
{
if(ep->ed->hoff >= ep->ed->hmax)
{
beep();
continue;
}
ep->ed->hoff++;
hupdate:
ed_histlist(ep->ed,*ep->ed->hlist!=0);
draw(ep,REFRESH);
continue;
}
#endif /* SHOPT_EDPREDICT */
#ifdef ESH_NFIRST
hline = location.hist_command; /* start at saved position */
hloff = location.hist_line;
Expand Down Expand Up @@ -970,34 +943,8 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
return(-1);
}

#if SHOPT_EDPREDICT
case '\n': case '\t':
if(!ep->ed->hlist)
{
beep();
break;
}
if(ch=='\n')
ed_ungetchar(ep->ed,'\n');
#endif /* SHOPT_EDPREDICT */
/* FALLTHROUGH */
/* file name expansion */
case ESC :
#if SHOPT_EDPREDICT
if(ep->ed->hlist)
{
value += ep->ed->hoff;
if(value > ep->ed->nhlist)
beep();
else
{
value = histlines - ep->ed->hlist[value-1]->index;
ed_histlist(ep->ed,0);
ed_ungetchar(ep->ed,cntl('P'));
return(value);
}
}
#endif /* SHOPT_EDPREDICT */
i = '\\'; /* filename completion */
/* FALLTHROUGH */
case '*': /* filename expansion */
Expand Down Expand Up @@ -1097,11 +1044,7 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
{
case 'A':
/* VT220 up arrow */
#if SHOPT_EDPREDICT
if(!ep->ed->hlist && cur>0 && eol==cur && (cur<(SEARCHSIZE-2) || ep->prevdirection == -2))
#else
if(cur>0 && eol==cur && (cur<(SEARCHSIZE-2) || ep->prevdirection == -2))
#endif /* SHOPT_EDPREDICT */
{
/* perform a reverse search based on the current command line */
if(ep->lastdraw==APPEND)
Expand Down Expand Up @@ -1541,34 +1484,6 @@ static void draw(register Emacs_t *ep,Draw_t option)
i = *(logcursor-1); /* last character inserted */
else
i = 0;
#if SHOPT_EDPREDICT
if(option==FINAL)
{
if(ep->ed->hlist)
ed_histlist(ep->ed,0);
}
else if((option==UPDATE||option==APPEND) && drawbuff[0]=='#' && cur>1 && cur==eol && drawbuff[cur-1]!='*')
{
int n;
drawbuff[cur+1]=0;
# if SHOPT_MULTIBYTE
ed_external(drawbuff,(char*)drawbuff);
# endif /* SHOPT_MULTIBYTE */
n = ed_histgen(ep->ed,(char*)drawbuff);
# if SHOPT_MULTIBYTE
ed_internal((char*)drawbuff,drawbuff);
# endif /* SHOPT_MULTIBYTE */
if(ep->ed->hlist)
{
ed_histlist(ep->ed,n);
putstring(ep,Prompt);
ed_setcursor(ep->ed,ep->screen,0,ep->cursor-ep->screen, 0);
}
else
ed_ringbell();

}
#endif /* SHOPT_EDPREDICT */

if ((option == APPEND)&&(ep->scvalid)&&(*logcursor == '\0')&&
print(i)&&((ep->cursor-ep->screen)<(w_size-1)))
Expand Down
Loading

0 comments on commit 5366967

Please sign in to comment.