Skip to content

Commit

Permalink
Don't use set_prompt(), but set prompt directly in emacs mode I-search.
Browse files Browse the repository at this point in the history
set_prompt() also manipulates cur_prompt, which is not desired here.
This fixes a bug where command substitions in PS1 triggered a PS2
continuation after I-search (even when not desired).

issue reported by and ok marco@
  • Loading branch information
natano committed Aug 4, 2015
1 parent e096700 commit e9e2fbf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 8 additions & 4 deletions bin/ksh/emacs.c
Expand Up @@ -814,15 +814,19 @@ x_search_hist(int c)
int offset = -1; /* offset of match in xbuf, else -1 */
char pat [256+1]; /* pattern buffer */
char *p = pat;
const char *oprompt;
int (*f)(int);

*p = '\0';
set_prompt(ISEARCH, NULL);
oprompt = prompt;
prompt = "I-search: ";
x_redraw(1);
while (1) {
x_flush();
if ((c = x_e_getc()) < 0)
if ((c = x_e_getc()) < 0) {
prompt = oprompt;
return (KSTD);
}
f = kb_find_hist_func(c);
if (c == CTRL('[')) {
/* might be part of an escape sequence */
Expand Down Expand Up @@ -866,9 +870,9 @@ x_search_hist(int c)
break;
}
}
set_prompt(PS1, NULL);
prompt = oprompt;
x_redraw(1);
return KSTD;
return (KSTD);
}

/* search backward from current line */
Expand Down
3 changes: 0 additions & 3 deletions bin/ksh/lex.c
Expand Up @@ -1180,9 +1180,6 @@ set_prompt(int to, Source *s)
case PS2: /* command continuation */
prompt = str_val(global("PS2"));
break;
case ISEARCH: /* incremental search */
prompt = "I-search: ";
break;
}
}

Expand Down
1 change: 0 additions & 1 deletion bin/ksh/table.h
Expand Up @@ -174,7 +174,6 @@ extern const struct builtin shbuiltins [], kshbuiltins [];
/* values for set_prompt() */
#define PS1 0 /* command */
#define PS2 1 /* command continuation */
#define ISEARCH 2 /* incremental search */

EXTERN char *path; /* copy of either PATH or def_path */
EXTERN const char *def_path; /* path to use if PATH not set */
Expand Down

0 comments on commit e9e2fbf

Please sign in to comment.