#include <stdlib.h>
#include <string.h>
+#define PANE_DATA_TYPE struct es_info
+#define PANE_DATA_TYPE_2 struct highlight_info
#include "core.h"
#include "rexel.h"
short replaced;
};
+struct highlight_info {
+ int view, replace_view;
+ char *patn;
+ int ci;
+ struct mark *start, *end, *match, *rpos, *oldpoint;
+ struct pane *popup, *replace_popup;
+};
+#include "core-pane.h"
+
static struct map *es_map, *er_map;
DEF_LOOKUP_CMD(search_handle, es_map);
DEF_LOOKUP_CMD(replace_handle, er_map);
DEF_CMD(replace_request_next)
{
- struct pane *sp = ci->home->data;
+ struct pane *sp = ci->home->_data;
char *new;
new = call_ret(str, "doc:get-str", ci->focus);
DEF_CMD(replace_request)
{
- struct pane *sp = ci->home->data;
+ struct pane *sp = ci->home->_data;
char *new;
new = call_ret(str, "doc:get-str", ci->focus);
DEF_CMD(replace_all)
{
- struct pane *sp = ci->home->data;
+ struct pane *sp = ci->home->_data;
char *new;
int replaced = 0;
DEF_CMD(replace_to_search)
{
- struct pane *sp = ci->home->data;
+ struct pane *sp = ci->home->_data;
pane_focus(sp);
return 1;
DEF_CMD(replace_forward)
{
- struct pane *sp = ci->home->data;
+ struct pane *sp = ci->home->_data;
call(ci->key, sp);
DEF_CMD(replace_escape)
{
- struct pane *sp = ci->home->data;
+ struct pane *sp = ci->home->_data;
return call("search:done", sp);
}
DEF_CMD(replace_prev)
{
- struct pane *home = ci->home->data;
+ struct pane *home = ci->home->_data;
struct es_info *esi = home->data;
if (esi->target)
DEF_CMD(replace_next)
{
- struct pane *home = ci->home->data;
+ struct pane *home = ci->home->_data;
struct es_info *esi = home->data;
if (esi->target)
key_add(es_map, "K:C-C", &search_add);
key_add(es_map, "K:C-R", &search_forward);
key_add(es_map, "Close", &search_close);
- key_add(es_map, "Free", &edlib_do_free);
key_add(es_map, "K:Enter", &search_done);
key_add(es_map, "search:done", &search_done);
key_add(es_map, "doc:replaced", &search_again);
DEF_CMD(emacs_search)
{
- struct pane *p;
+ struct pane *p, *target;
struct es_info *esi;
struct mark *m;
if (!es_map)
emacs_search_init_map();
- p = call_ret(pane, "popup:get-target", ci->focus);
- if (!p)
+ target = call_ret(pane, "popup:get-target", ci->focus);
+ if (!target)
return Efail;
- esi = calloc(1, sizeof(*esi));
- esi->target = p;
- m = mark_at_point(p, NULL, MARK_POINT);
- if (!m) {
- free(esi);
+
+ m = mark_at_point(target, NULL, MARK_POINT);
+ if (!m)
return Efail;
- }
+
+ p = pane_register(ci->focus, 0, &search_handle.c);
+ if (!p)
+ return Efail;
+ esi = p->data;
+ esi->target = target;
esi->end = m;
esi->start = mark_dup(m);
esi->replaced = 0;
esi->backwards = ci->num & 1;
- p = pane_register(ci->focus, 0, &search_handle.c, esi);
- if (!p)
- return Efail;
-
call("doc:request:doc:replaced", p);
attr_set_str(&p->attrs, "status-line", " Search: case insensitive ");
comm_call(ci->comm2, "callback:attach", p);
return 1;
}
-struct highlight_info {
- int view, replace_view;
- char *patn;
- int ci;
- struct mark *start, *end, *match, *rpos, *oldpoint;
- struct pane *popup, *replace_popup;
-};
-
static void do_searches(struct pane *p safe,
struct pane *owner safe, int view, char *patn,
int ci,
struct mark *m, struct mark *end)
{
int ret;
- struct highlight_info *hi = owner->data;
+ struct highlight_info *hi = owner->data2;
struct mark *start;
if (!m)
* will highlight other near-by matches.
*/
struct mark *m, *start;
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
if (hi->view < 0)
return Efail;
* be added.
*/
struct mark *m;
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
if (hi->replace_view < 0 || !hi->replace_popup)
return Efail;
DEF_CMD(emacs_hl_attrs)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
if (!ci->str)
return Efallthrough;
DEF_CMD(highlight_draw)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
struct pane *pp = hi->popup;
struct pane *pp2 = hi->replace_popup;
struct xy xy;
DEF_CMD(emacs_search_reposition_delayed)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
struct mark *start = hi->start;
struct mark *end = hi->end;
struct mark *vstart, *vend;
* delayed update won't happen until a suitable time after the last
* reposition.
*/
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
struct mark *start = ci->mark;
struct mark *end = ci->mark2;
struct mark *m;
DEF_CMD(emacs_highlight_close)
{
/* ci->focus is being closed */
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
free(hi->patn);
mark_free(hi->start);
static void free_marks(struct pane *home safe)
{
- struct highlight_info *hi = home->data;
+ struct highlight_info *hi = home->data2;
struct mark *m;
while ((m = vmark_first(home, hi->view, home)) != NULL)
DEF_CMD(emacs_search_done)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
if (ci->str && ci->str[0])
call("history:save", ci->focus, 0, NULL, ci->str);
DEF_CMD(emacs_highlight_abort)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
struct pane *p;
p = hi->replace_popup;
DEF_CMD(emacs_highlight_clip)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
marks_clip(ci->home, ci->mark, ci->mark2,
hi->view, ci->home, !!ci->num);
DEF_CMD(emacs_highlight_set_popup)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
if (ci->num)
hi->replace_popup = ci->focus;
DEF_CMD(emacs_highlight_close_notify)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
if (ci->focus == hi->replace_popup)
hi->replace_popup = NULL;
DEF_CMD(emacs_step_replace)
{
- struct highlight_info *hi = ci->home->data;
+ struct highlight_info *hi = ci->home->data2;
struct mark *m;
if (!hi->replace_view || !hi->match)
key_add(m, "map-attr", &emacs_hl_attrs);
key_add(m, "Draw:text", &highlight_draw);
key_add(m, "Close", &emacs_highlight_close);
- key_add(m, "Free", &edlib_do_free);
key_add(m, "Abort", &emacs_highlight_abort);
key_add(m, "Notify:clip", &emacs_highlight_clip);
key_add(m, "highlight:set-popup", &emacs_highlight_set_popup);
if (!hl_map)
emacs_highlight_init_map();
- alloc(hi, pane);
- p = pane_register(ci->focus, 0, &highlight_handle.c, hi);
+ p = pane_register_2(ci->focus, 0, &highlight_handle.c);
if (!p)
return Efail;
+ hi = p->data2;
hi->view = home_call(ci->focus, "doc:add-view", p) - 1;
hi->replace_view = home_call(ci->focus, "doc:add-view", p) - 1;