Add search-history-up and search-history-down keybindings (both unbound
by default) to the Emacs command line editing mode; patch originally by James Butler <sweetnavelorange@gmail.com> but slightly modified 10x
This commit is contained in:
parent
eb3f3d584f
commit
747cc12184
4
check.t
4
check.t
|
@ -1,4 +1,4 @@
|
||||||
# $MirOS: src/bin/mksh/check.t,v 1.272 2009/04/22 16:43:18 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.273 2009/05/16 14:19:20 tg Exp $
|
||||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
# http://www.research.att.com/~gsf/public/ifs.sh
|
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||||
|
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)MIRBSD KSH R37 2009/04/07
|
@(#)MIRBSD KSH R37 2009/05/16
|
||||||
description:
|
description:
|
||||||
Check version of shell.
|
Check version of shell.
|
||||||
stdin:
|
stdin:
|
||||||
|
|
41
edit.c
41
edit.c
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.160 2009/04/07 18:41:33 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.161 2009/05/16 14:19:21 tg Exp $");
|
||||||
|
|
||||||
/* tty driver characters we are interested in */
|
/* tty driver characters we are interested in */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1036,6 +1036,7 @@ static void x_zotc2(int);
|
||||||
static void x_zotc3(char **);
|
static void x_zotc3(char **);
|
||||||
static void x_load_hist(char **);
|
static void x_load_hist(char **);
|
||||||
static int x_search(char *, int, int);
|
static int x_search(char *, int, int);
|
||||||
|
static int x_search_dir(int);
|
||||||
static int x_match(char *, char *);
|
static int x_match(char *, char *);
|
||||||
static void x_redraw(int);
|
static void x_redraw(int);
|
||||||
static void x_push(int);
|
static void x_push(int);
|
||||||
|
@ -1114,6 +1115,8 @@ static void bind_if_not_bound(int, int, int);
|
||||||
#define XFUNC_comment 53
|
#define XFUNC_comment 53
|
||||||
#define XFUNC_version 54
|
#define XFUNC_version 54
|
||||||
#define XFUNC_edit_line 55
|
#define XFUNC_edit_line 55
|
||||||
|
#define XFUNC_search_hist_up 56
|
||||||
|
#define XFUNC_search_hist_down 57
|
||||||
|
|
||||||
/* XFUNC_* must be < 128 */
|
/* XFUNC_* must be < 128 */
|
||||||
|
|
||||||
|
@ -1173,6 +1176,8 @@ static int x_set_arg(int);
|
||||||
static int x_comment(int);
|
static int x_comment(int);
|
||||||
static int x_version(int);
|
static int x_version(int);
|
||||||
static int x_edit_line(int);
|
static int x_edit_line(int);
|
||||||
|
static int x_search_hist_up(int);
|
||||||
|
static int x_search_hist_down(int);
|
||||||
|
|
||||||
static const struct x_ftab x_ftab[] = {
|
static const struct x_ftab x_ftab[] = {
|
||||||
{ x_abort, "abort", 0 },
|
{ x_abort, "abort", 0 },
|
||||||
|
@ -1231,6 +1236,8 @@ static const struct x_ftab x_ftab[] = {
|
||||||
{ x_comment, "comment", 0 },
|
{ x_comment, "comment", 0 },
|
||||||
{ x_version, "version", 0 },
|
{ x_version, "version", 0 },
|
||||||
{ x_edit_line, "edit-line", XF_ARG },
|
{ x_edit_line, "edit-line", XF_ARG },
|
||||||
|
{ x_search_hist_up, "search-history-up", 0 },
|
||||||
|
{ x_search_hist_down, "search-history-down", 0 },
|
||||||
{ 0, NULL, 0 }
|
{ 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2157,6 +2164,38 @@ x_search(char *pat, int sameline, int offset)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* anchored search up from current line */
|
||||||
|
static int
|
||||||
|
x_search_hist_up(int c __unused)
|
||||||
|
{
|
||||||
|
return (x_search_dir(-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* anchored search down from current line */
|
||||||
|
static int
|
||||||
|
x_search_hist_down(int c __unused)
|
||||||
|
{
|
||||||
|
return (x_search_dir(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* anchored search in the indicated direction */
|
||||||
|
static int
|
||||||
|
x_search_dir(int search_dir /* should've been bool */)
|
||||||
|
{
|
||||||
|
char **hp = x_histp + search_dir;
|
||||||
|
size_t curs = xcp - xbuf;
|
||||||
|
|
||||||
|
while (histptr >= hp && hp >= history) {
|
||||||
|
if (strncmp(xbuf, *hp, curs) == 0) {
|
||||||
|
x_load_hist(hp);
|
||||||
|
x_goto(xbuf + curs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
hp += search_dir;
|
||||||
|
}
|
||||||
|
return (KSTD);
|
||||||
|
}
|
||||||
|
|
||||||
/* return position of first match of pattern in string, else -1 */
|
/* return position of first match of pattern in string, else -1 */
|
||||||
static int
|
static int
|
||||||
x_match(char *str, char *pat)
|
x_match(char *str, char *pat)
|
||||||
|
|
25
mksh.1
25
mksh.1
|
@ -1,4 +1,4 @@
|
||||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.159 2009/05/16 14:17:39 tg Exp $
|
.\" $MirOS: src/bin/mksh/mksh.1,v 1.160 2009/05/16 14:19:22 tg Exp $
|
||||||
.\" $OpenBSD: ksh.1,v 1.128 2009/03/06 12:28:36 jmc Exp $
|
.\" $OpenBSD: ksh.1,v 1.128 2009/03/06 12:28:36 jmc Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Try to make GNU groff and AT&T nroff more compatible
|
.\" Try to make GNU groff and AT&T nroff more compatible
|
||||||
|
@ -4723,7 +4723,8 @@ Each input line originally starts just after the last entry
|
||||||
in the history buffer, so
|
in the history buffer, so
|
||||||
.Ic down\-history
|
.Ic down\-history
|
||||||
is not useful until either
|
is not useful until either
|
||||||
.Ic search\-history
|
.Ic search\-history ,
|
||||||
|
.Ic search\-history\-up
|
||||||
or
|
or
|
||||||
.Ic up\-history
|
.Ic up\-history
|
||||||
has been performed.
|
has been performed.
|
||||||
|
@ -4822,9 +4823,10 @@ The current cursor position may be anywhere on the line.
|
||||||
Causes the current input line to be processed by the shell, and the next line
|
Causes the current input line to be processed by the shell, and the next line
|
||||||
from history becomes the current line.
|
from history becomes the current line.
|
||||||
This is only useful after an
|
This is only useful after an
|
||||||
.Ic up\-history
|
.Ic up\-history ,
|
||||||
|
.Ic search\-history
|
||||||
or
|
or
|
||||||
.Ic search\-history .
|
.Ic search\-history\-up .
|
||||||
.It no\-op: QUIT
|
.It no\-op: QUIT
|
||||||
This does nothing.
|
This does nothing.
|
||||||
.It prefix\-1: \*(ha[
|
.It prefix\-1: \*(ha[
|
||||||
|
@ -4883,6 +4885,21 @@ commands continue searching backward to the next previous occurrence of the
|
||||||
pattern.
|
pattern.
|
||||||
The history buffer retains only a finite number of lines; the oldest
|
The history buffer retains only a finite number of lines; the oldest
|
||||||
are discarded as necessary.
|
are discarded as necessary.
|
||||||
|
.It search\-history\-up: (not bound)
|
||||||
|
Search backwards through the history buffer for commands whose beginning match
|
||||||
|
the portion of the input line before the cursor.
|
||||||
|
When used on an empty line, this has the same effect as
|
||||||
|
.Ic up\-history .
|
||||||
|
.It search\-history\-down: (not bound)
|
||||||
|
Search forwards through the history buffer for commands whose beginning match
|
||||||
|
the portion of the input line before the cursor.
|
||||||
|
When used on an empty line, this has the same effect as
|
||||||
|
.Ic down\-history .
|
||||||
|
This is only useful after an
|
||||||
|
.Ic up\-history ,
|
||||||
|
.Ic search\-history
|
||||||
|
or
|
||||||
|
.Ic search\-history\-up .
|
||||||
.It set\-mark\-command: \*(ha[ Ns Aq space
|
.It set\-mark\-command: \*(ha[ Ns Aq space
|
||||||
Set the mark at the cursor position.
|
Set the mark at the cursor position.
|
||||||
.It transpose\-chars: \*(haT
|
.It transpose\-chars: \*(haT
|
||||||
|
|
4
sh.h
4
sh.h
|
@ -102,9 +102,9 @@
|
||||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.293 2009/04/07 19:43:28 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.294 2009/05/16 14:19:23 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R37 2009/04/07"
|
#define MKSH_VERSION "R37 2009/05/16"
|
||||||
|
|
||||||
#ifndef MKSH_INCLUDES_ONLY
|
#ifndef MKSH_INCLUDES_ONLY
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue