diff options
author | 2016-05-10 11:07:53 +0000 | |
---|---|---|
committer | 2016-05-10 11:07:53 +0000 | |
commit | 47f0686a862e2df42bc81479b406fc58352d68b9 (patch) | |
tree | c6e091dc1185407c31a0bea2d306fe5342c6f616 | |
parent | move some argument checking from vmmaction() to start_vm() (diff) | |
download | wireguard-openbsd-47f0686a862e2df42bc81479b406fc58352d68b9.tar.xz wireguard-openbsd-47f0686a862e2df42bc81479b406fc58352d68b9.zip |
Fix next_history() and previous_history():
* The meaning of "next" and "previous" is exchanged in readline(3) with
respect to editline(3); this part of the patch from Bastian Maerkisch.
* next_history() can move beyond the newest entry; issue pointed out
by Bastian Maerkisch, fix by me.
While here, make the documentation of ed-next-history, ed-prev-history,
H_NEXT, and H_PREV more precise.
OK czarkoff@.
-rw-r--r-- | lib/libedit/editline.3 | 6 | ||||
-rw-r--r-- | lib/libedit/editline.7 | 6 | ||||
-rw-r--r-- | lib/libedit/readline.c | 30 |
3 files changed, 34 insertions, 8 deletions
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3 index 96463db95a6..7bede329b09 100644 --- a/lib/libedit/editline.3 +++ b/lib/libedit/editline.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: editline.3,v 1.42 2016/04/20 01:11:45 schwarze Exp $ +.\" $OpenBSD: editline.3,v 1.43 2016/05/10 11:07:53 schwarze Exp $ .\" $NetBSD: editline.3,v 1.88 2016/02/25 14:59:22 wiz Exp $ .\" .\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: April 20 2016 $ +.Dd $Mdocdate: May 10 2016 $ .Dt EDITLINE 3 .Os .Sh NAME @@ -731,8 +731,10 @@ Return the first element in the history. Return the last element in the history. .It Dv H_PREV Return the previous element in the history. +It is newer than the current one. .It Dv H_NEXT Return the next element in the history. +It is older than the current one. .It Dv H_CURR Return the current element in the history. .It Dv H_SET diff --git a/lib/libedit/editline.7 b/lib/libedit/editline.7 index 0adf1d015ce..af80e03e577 100644 --- a/lib/libedit/editline.7 +++ b/lib/libedit/editline.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: editline.7,v 1.1 2016/04/20 01:11:45 schwarze Exp $ +.\" $OpenBSD: editline.7,v 1.2 2016/05/10 11:07:53 schwarze Exp $ .\" .\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 20 2016 $ +.Dd $Mdocdate: May 10 2016 $ .Dt EDITLINE 7 .Os .Sh NAME @@ -407,6 +407,7 @@ It is an error if the cursor is already at the end of the edit buffer. .It Ic ed-next-history Pq vi command: j, +, Ctrl-N; emacs: Ctrl-N Replace the edit buffer with the next history line. +That line is older than the current line. With an argument, go forward by that number of history lines. It is a non-fatal error to advance by more lines than are available. .It Ic ed-next-line Pq not bound by default @@ -426,6 +427,7 @@ It is an error if the cursor is already at the beginning of the edit buffer. .It Ic ed-prev-history Pq vi command: k, -, Ctrl-P; emacs: Ctrl-P Replace the edit buffer with the previous history line. +That line is newer than the current line. With an argument, go back by that number of lines. It is a non-fatal error to back up by more lines than are available. .It Ic ed-prev-line Pq not bound by default diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c index 3fae304361c..4eeb2208acf 100644 --- a/lib/libedit/readline.c +++ b/lib/libedit/readline.c @@ -1,4 +1,4 @@ -/* $OpenBSD: readline.c,v 1.25 2016/05/10 10:49:37 schwarze Exp $ */ +/* $OpenBSD: readline.c,v 1.26 2016/05/10 11:07:53 schwarze Exp $ */ /* $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $ */ /*- @@ -149,6 +149,14 @@ char *rl_special_prefixes = NULL; */ int rl_completion_append_character = ' '; +/* + * When the history cursor is on the newest element and next_history() + * is called, GNU readline moves the cursor beyond the newest element. + * The editline library does not provide data structures to express + * that state, so we need a local flag. + */ +static int current_history_valid = 1; + /* stuff below is used internally by libedit for readline emulation */ static History *h = NULL; @@ -280,6 +288,8 @@ rl_initialize(void) int editmode = 1; struct termios t; + current_history_valid = 1; + if (e != NULL) el_end(e); if (h != NULL) @@ -1406,6 +1416,7 @@ add_history(const char *line) (void)history(h, &ev, H_ENTER, line); if (history(h, &ev, H_GETSIZE) == 0) history_length = ev.num; + current_history_valid = 1; return !(history_length > 0); /* return 0 if all is okay */ } @@ -1495,6 +1506,7 @@ clear_history(void) (void)history(h, &ev, H_CLEAR); history_length = 0; + current_history_valid = 1; } @@ -1530,7 +1542,7 @@ HIST_ENTRY * current_history(void) { - return _move_history(H_CURR); + return current_history_valid ? _move_history(H_CURR) : NULL; } @@ -1575,6 +1587,7 @@ history_set_pos(int pos) (void)history(h, &ev, H_CURR); curr_num = ev.num; + current_history_valid = 1; /* * use H_DELDATA to set to nth history (without delete) by passing @@ -1590,12 +1603,17 @@ history_set_pos(int pos) /* * returns previous event in history and shifts pointer accordingly + * Note that readline and editline define directions in opposite ways. */ HIST_ENTRY * previous_history(void) { - return _move_history(H_PREV); + if (current_history_valid == 0) { + current_history_valid = 1; + return _move_history(H_CURR); + } + return _move_history(H_NEXT); } @@ -1605,8 +1623,12 @@ previous_history(void) HIST_ENTRY * next_history(void) { + HIST_ENTRY *he; - return _move_history(H_NEXT); + he = _move_history(H_PREV); + if (he == NULL) + current_history_valid = 0; + return he; } |