diff --git a/contrib/10.readline/src/readline.c b/contrib/10.readline/src/readline.c index e5a33258..9d9650ac 100644 --- a/contrib/10.readline/src/readline.c +++ b/contrib/10.readline/src/readline.c @@ -232,6 +232,21 @@ pic_rl_truncate_file(pic_state *pic) return pic_undef_value(); } +static pic_value +pic_rl_history_expand(pic_state *pic) +{ + char *input, *result; + int status; + + pic_get_args(pic, "z", &input); + + status = history_expand(input, &result); + if(status == -1 || status == 2) + pic_errorf(pic, "%s\n", result); + + return pic_obj_value(pic_str_new_cstr(pic, result)); +} + void pic_init_readline(pic_state *pic){ using_history(); @@ -258,5 +273,6 @@ pic_init_readline(pic_state *pic){ pic_defun(pic, "read-history", pic_rl_read_history); pic_defun(pic, "write-history", pic_rl_write_history); pic_defun(pic, "truncate-file", pic_rl_truncate_file); + pic_defun(pic, "history-expand", pic_rl_history_expand); } } diff --git a/contrib/10.readline/t/test.scm b/contrib/10.readline/t/test.scm index 37c8d9bb..227a85b0 100644 --- a/contrib/10.readline/t/test.scm +++ b/contrib/10.readline/t/test.scm @@ -324,5 +324,16 @@ pos 1 (truncate-file testfile 5) ;(read-history testfile) (test 5 (history-length)) +(clear-history) +(add-history "foo") +(add-history "bar") +(add-history "baz") +(test "baz" (history-expand "!b")) +(test "baz" (history-expand "!!")) +(test "bar" (history-expand "!?r?")) +(add-history "com arg") +(test "arg" (history-expand "!!:$")) +(test "arg" (history-expand "!$")) +(test "command arg" (history-expand "!!:s/com/command/")) (test-end)