From 206f432b1b5811c99ecf5f14a914de8da37277c0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 22 Sep 2015 06:08:50 -0700 Subject: linenoise: forward paren jump too. * linenoise/linenoise.c (paren_jump): Scan forward also, if reverse scan turns up nothing, thereby jumping to a closing parenthesis in the forward direction. * txr.1: Documentation updated. --- linenoise/linenoise.c | 4 ++++ txr.1 | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 7dd29aa5..1a16ac7c 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1118,6 +1118,9 @@ static void paren_jump(lino_t *l) { size_t pos = scan_rev(l->data, l->dpos - 1); + if (pos == -1) + pos = scan_fwd(l->data, l->dpos - 1); + if (pos != -1) { size_t dp = l->dpos; l->dpos = pos; @@ -1840,6 +1843,7 @@ static int edit(lino_t *l, const char *prompt) } break; case ')': case ']': case '}': + case '(': case '[': case '{': if (edit_insert(l,c)) { l->error = lino_ioerr; goto out; diff --git a/txr.1 b/txr.1 index 273dd533..18fd43d0 100644 --- a/txr.1 +++ b/txr.1 @@ -34126,12 +34126,20 @@ When any of the three closing characters or .code } is inserted, the listener scans backward for the matching opening -character. If the matching character is found, the cursor jumps to that +character. Likewise, if any of the three opening characters +.codn ( , +.codn [ +or +.code { +is inserted in the middle of text, the listener scans forward for the matching +closing character. + +If the matching character is found, the cursor jumps to that character and then returns to the original position a brief moment later. If a new character is typed during the brief time delay, the delay is immediately canceled, so as not to hinder rapid typing. -Note that the backward matching is unsophisticated; it doesn't observe the +Note that the matching is unsophisticated; it doesn't observe the lexical conventions and syntax of the \*(TL programming language. For instance, a closing parenthesis outside a string literal may match match an opening one inside a string literal. -- cgit v1.2.3