-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib-test-markup.c
89 lines (77 loc) · 1.91 KB
/
lib-test-markup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright Neil Brown ©2023 <[email protected]>
* May be distributed under terms of GPLv2 - see file:COPYING
*
* This is a replacement for lib-markup which uses each line
* of the document as verbatim markup. This is for testing only.
*/
#define PANE_DATA_VOID
#include "core.h"
#include "misc.h"
DEF_CMD(test_render_prev)
{
struct mark *m = ci->mark;
if (!m)
return Enoarg;
if (ci->num)
if (doc_prev(ci->focus, m) == WEOF)
return Efail;
call("doc:EOL", ci->focus, -1, m);
return 1;
}
DEF_CMD(test_render_line)
{
struct mark *m = ci->mark;
struct mark *st;
char *s;
int ret;
int pm_offset = -1;
if (!m)
return Enoarg;
st = mark_dup(m);
call("doc:EOL", ci->focus, 1, m, NULL, 1);
s = call_ret(str, "doc:get-str", ci->focus, 0, st, NULL, 0, m);
if (ci->num >= 0) {
struct mark *m2 = mark_dup(st);
call("doc:char", ci->focus, ci->num, m2, NULL, 0, m);
mark_to_mark(m, m2);
mark_free(m2);
if (s && ci->num < (int)utf8_strlen(s))
s[ci->num] = 0;
}
if (ci->mark2) {
char *s2 = call_ret(str, "doc:get-str", ci->focus,
0, st, NULL,
0, ci->mark2);
pm_offset = s2 ? strlen(s2) : 0;
free(s2);
}
ret = comm_call(ci->comm2, "cb", ci->focus, pm_offset, NULL, s);
free(s);
return ret ?: 1;
}
static struct map *tmu_map safe;
DEF_LOOKUP_CMD(test_markup_handle, tmu_map);
DEF_CMD(test_attach)
{
struct pane *ret;
ret = pane_register(ci->focus, 0, &test_markup_handle.c);
if (!ret)
return Efail;
return comm_call(ci->comm2, "cb", ret);
}
DEF_CMD(test_enable)
{
call("attach-test-markup", ci->focus);
return 1;
}
void edlib_init(struct pane *ed safe)
{
tmu_map = key_alloc();
key_add(tmu_map, "doc:render-line", &test_render_line);
key_add(tmu_map, "doc:render-line-prev", &test_render_prev);
call_comm("global-set-command", ed, &test_attach,
0, NULL, "attach-test-markup");
call_comm("global-set-command" ,ed, &test_enable,
0, NULL, "interactive-cmd-test-markup");
}