From: NeilBrown Date: Wed, 2 Dec 2015 02:23:58 +0000 (+1100) Subject: Save search string for later re-use. X-Git-Tag: lca2016~140 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=33bed0bfc73ade3e49532434011918a17809bae4;p=edlib.git Save search string for later re-use. Signed-off-by: NeilBrown --- diff --git a/core-editor.c b/core-editor.c index 6e41595e..cb880391 100644 --- a/core-editor.c +++ b/core-editor.c @@ -19,12 +19,20 @@ DEF_CMD(null_display_handle) return 0; } +DEF_CMD(global_set_attr) +{ + attr_set_str(&ci->home->attrs, ci->str, ci->str2, -1); + return 1; +} + struct pane *editor_new(void) { struct editor *ed = calloc(sizeof(*ed), 1); - if (!ed_map) + if (!ed_map) { ed_map = key_alloc(); + key_add(ed_map, "global-set-attr", &global_set_attr); + } pane_init(&ed->root, NULL, NULL); ed->root.handle = &ed_handle.c; diff --git a/emacs-search.c b/emacs-search.c index afd08a1e..063ecb14 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -54,9 +54,20 @@ DEF_CMD(search_forward) /* already pushed and didn't find anything new */ return 1; } + str = doc_getstr(ci->focus, NULL); + if (!*str) { + /* re-use old string; Is there any point to this indirection? */ + char *ss; + ss = pane_attr_get(ci->focus, "done-key"); + if (ss) + ss = pane_attr_get(ci->focus, ss); + if (ss) { + doc_replace(esi->search, NULL, ss, &first); + return 1; + } + } s = malloc(sizeof(*s)); s->m = esi->start; - str = doc_getstr(ci->focus, NULL); s->len = strlen(str); free(str); s->next = esi->s; diff --git a/mode-emacs.c b/mode-emacs.c index 99d27c40..9c092f3c 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -541,6 +541,12 @@ DEF_CMD(emacs_search) m = call_mark("doc:dup-point", ci->home, 0, NULL, MARK_UNGROUPED); + ci2.key = "global-set-attr"; + ci2.str = "Search String"; + ci2.str2 = ci->str; + ci2.focus = ci->home; + key_handle_focus(&ci2); + memset(&ci2, 0, sizeof(ci2)); ci2.focus = ci->home; ci2.mark = m;