From: NeilBrown Date: Tue, 8 Dec 2015 01:28:14 +0000 (+1100) Subject: Change text-search to return result directly. X-Git-Tag: lca2016~110 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=ac05667c4affc3edac4a1fac523b47fd5d7e6b95;p=edlib.git Change text-search to return result directly. -2 is cannot find -1 is incomplete regex 0 is no such commnd N is match of length N-1 found. Signed-off-by: NeilBrown --- diff --git a/emacs-search.c b/emacs-search.c index fab222a1..b0c54055 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -201,9 +201,12 @@ REDEF_CMD(search_again) ret = key_lookup(pane2ed(esi->target)->commands, &ci2); if (ret == 0) pfx = "Search (unavailable): "; - else if (ret < 0) { + else if (ret == -2) { + esi->matched = 0; + pfx = "Failed Search: "; + } else if (ret < 0) { pfx = "Search (incomplete): "; - } else if (ci2.extra > 0) { + } else { memset(&ci2, 0, sizeof(ci2)); point_to_mark(esi->end, m); /* TEMP HACK - please fix */ @@ -213,9 +216,6 @@ REDEF_CMD(search_again) pfx = "Search: "; if (esi->wrapped) pfx = "Wrapped Search: "; - } else { - esi->matched = 0; - pfx = "Failed Search: "; } /* HACK */ for (p = esi->search; p; p = p->parent) { diff --git a/lib-search.c b/lib-search.c index 64148a23..55747ba1 100644 --- a/lib-search.c +++ b/lib-search.c @@ -50,10 +50,11 @@ DEF_CMD(text_search) mark_to_mark(m, endmark); mark_free(endmark); } - ci->extra = since_start; rxl_free_state(st); free(rxl); - return 1; + if (since_start < 0) + return -2; + return since_start + 1; } void edlib_init(struct editor *ed) diff --git a/mode-emacs.c b/mode-emacs.c index 0c051cfe..6f3c27ea 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -521,6 +521,7 @@ DEF_CMD(emacs_search) { struct cmd_info ci2 = {0}; struct mark *m; + int ret; if (strcmp(ci->key, "Search String") != 0) { struct pane *p = pane_attach(ci->focus, "popup", NULL, "TR2"); @@ -554,9 +555,8 @@ DEF_CMD(emacs_search) ci2.mark = m; ci2.str = ci->str; ci2.key = "text-search"; - if (!key_lookup(pane2ed(ci->focus)->commands, &ci2)) - ci2.extra = -1; - if (ci2.extra > 0) + ret = key_lookup(pane2ed(ci->focus)->commands, &ci2); + if (ret > 1) call3("Move-to", ci->focus, 0, m); mark_free(m);