]> git.neil.brown.name Git - edlib.git/commitdiff
emacs-search: get notification when panes close.
authorNeilBrown <neil@brown.name>
Thu, 1 Jun 2023 04:53:11 +0000 (14:53 +1000)
committerNeilBrown <neil@brown.name>
Thu, 8 Jun 2023 10:38:57 +0000 (20:38 +1000)
If we hold a reference to a pane, we must get Notify:Close notifications
from it, and clear the pointer if that happens.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
emacs-search.c

index dbbe243fd1813f6637a0bd0c9604853e0d26e074..f615d12faf8c905de48f040985118cb0a71e86d9 100644 (file)
@@ -12,7 +12,7 @@ the file.
 
 ### Small
 
-- [ ] ->replace_pane, ->replace_popup can be deleted (Abort) but we
+- [X] ->replace_pane, ->replace_popup can be deleted (Abort) but we
       don't catch it...
 - [ ] notmuch reply should interpolate the first *visible* text part
 - [ ] ncurses - don't block in nc_external_viewer - at least abort after
@@ -218,7 +218,7 @@ Module features
 
 - [ ] Num-C-l doesn't work if it would require part of a wrapped line
       off top of screen
-- [ ] ->replace_pane, ->replace_popup can be deleted (Abort) but we
+- [X] ->replace_pane, ->replace_popup can be deleted (Abort) but we
       don't catch it...
 - [ ] :C-q to recognise names of Unicode chars: e.g. WASTEBASKET
        Possibly matches a list which continued :C-q cycles through
index 855fd7ffe91f341e776e2b472eab266dc797e025..743c1beb12cec495bc18eb3b6f0094d07ffd2db1 100644 (file)
@@ -453,8 +453,10 @@ DEF_CMD(search_replace)
        p = call_ret(pane, "attach-history", p, 0, NULL, "*Replace History*",
                     0, NULL, "popup:close");
        esi->replace_pane = p;
-       if (p)
+       if (p) {
+               pane_add_notify(ci->home, p, "Notify:Close");
                home_call(esi->target, "highlight:set-popup", p, 1);
+       }
        if (strcmp(ci->key, "K:A-%") == 0)
                pane_focus(ci->focus);
        else
@@ -462,6 +464,15 @@ DEF_CMD(search_replace)
        return 1;
 }
 
+DEF_CMD(search_notify_close)
+{
+       struct es_info *esi = ci->home->data;
+
+       if (ci->focus == esi->replace_pane)
+               esi->replace_pane = NULL;
+       return 1;
+}
+
 DEF_CMD(do_replace)
 {
        struct es_info *esi = ci->home->data;
@@ -633,6 +644,7 @@ static void emacs_search_init_map(void)
        key_add(es_map, "K:ESC", &search_escape);
 
        key_add(es_map, "search:replace", &do_replace);
+       key_add(es_map, "Notify:Close", &search_notify_close);
 
        /* keys for the 'replace' pane */
        er_map = key_alloc();
@@ -755,7 +767,7 @@ DEF_CMD(emacs_search_highlight)
        struct mark *m, *start;
        struct highlight_info *hi = ci->home->data;
 
-       if (hi->view < 0 || !hi->popup)
+       if (hi->view < 0)
                return Efail;
 
        while ((start = vmark_first(ci->focus, hi->view, ci->home)) != NULL)
@@ -1094,6 +1106,18 @@ DEF_CMD(emacs_highlight_set_popup)
                hi->replace_popup = ci->focus;
        else
                hi->popup = ci->focus;
+       pane_add_notify(ci->home, ci->focus, "Notify:Close");
+       return 1;
+}
+
+DEF_CMD(emacs_highlight_close_notify)
+{
+       struct highlight_info *hi = ci->home->data;
+
+       if (ci->focus == hi->replace_popup)
+               hi->replace_popup = NULL;
+       if (ci->focus == hi->popup)
+               hi->popup = NULL;
        return 1;
 }
 
@@ -1162,6 +1186,7 @@ static void emacs_highlight_init_map(void)
        key_add(m, "Notify:clip", &emacs_highlight_clip);
        key_add(m, "highlight:set-popup", &emacs_highlight_set_popup);
        key_add(m, "attach-emacs-search-highlight", &emacs_highlight_reattach);
+       key_add(m, "Notify:Close", &emacs_highlight_close_notify);
        hl_map = m;
 }