aboutsummaryrefslogtreecommitdiff
path: root/config/ecexrc.c
blob: 75f2470119e18d0990264e1e66d6d70b7c0921b0 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "ecex.h"
#include "buffers.h"

#define ECEX_NO_STANDALONE_CONFIG
#include "render_demo.c"
#include "tetris.c"
#include "markdown_plugin.c"
#include "which_key_plugin.c"
#include "c_mode_plugin.c"
#include "ecex_api_completion_plugin.c"
#include "c_tools_plugin.c"
#undef ECEX_NO_STANDALONE_CONFIG

#define RGB(r, g, b) ECEX_RGB8(r, g, b)

/* Gruvbox dark palette */
#define GB_DARK0_HARD  RGB(0x1d, 0x20, 0x21)
#define GB_DARK0       RGB(0x28, 0x28, 0x28)
#define GB_DARK1       RGB(0x3c, 0x38, 0x36)
#define GB_DARK2       RGB(0x50, 0x49, 0x45)

#define GB_LIGHT0      RGB(0xfb, 0xf1, 0xc7)
#define GB_LIGHT1      RGB(0xeb, 0xdb, 0xb2)
#define GB_LIGHT2      RGB(0xd5, 0xc4, 0xa1)

#define GB_RED         RGB(0xfb, 0x49, 0x34)
#define GB_GREEN       RGB(0xb8, 0xbb, 0x26)
#define GB_YELLOW      RGB(0xfa, 0xbd, 0x2f)
#define GB_BLUE        RGB(0x83, 0xa5, 0x98)
#define GB_PURPLE      RGB(0xd3, 0x86, 0x9b)
#define GB_AQUA        RGB(0x8e, 0xc0, 0x7c)
#define GB_ORANGE      RGB(0xfe, 0x80, 0x19)

static int hello_command(ecex_t *ed) {
    buffer_t *buf = ecex_current_buffer(ed);
    buffer_insert(buf, "Hello from Gruvbox ecex config!\n");
    return 0;
}

static int make_notes_command(ecex_t *ed) {
    buffer_t *notes = ecex_find_buffer(ed, "*notes*");

    if (!notes) {
        notes = ecex_create_buffer(ed, "*notes*", NULL, 0);
    }

    if (notes) {
        buffer_insert(notes, "Created or reused *notes* from command.\n");
        ecex_switch_buffer(ed, "*notes*");
    }

    return 0;
}


static int demo_line_action(ecex_t *ed,
                            buffer_t *buffer,
                            size_t line,
                            const char *payload,
                            void *userdata) {
    (void)buffer;
    (void)line;
    (void)userdata;

    buffer_t *notes = ecex_find_buffer(ed, "*notes*");
    if (!notes) {
        notes = ecex_create_buffer(ed, "*notes*", NULL, 0);
    }

    if (!notes) return -1;

    ecex_switch_buffer(ed, "*notes*");
    buffer_insert(notes, payload ? payload : "selected an interactive line\n");
    return 0;
}

static int demo_interactive_command(ecex_t *ed) {
    buffer_t *menu = ecex_create_interactive_buffer(ed, "*demo-menu*");
    if (!menu) return -1;

    buffer_clear(menu);
    buffer_set_interactive(menu, 1);

    buffer_append(menu, "Demo interactive buffer\n");
    buffer_append(menu, "Move to a line and press ENTER.\n\n");

    ecex_interactive_append_line(ed,
                                 menu,
                                 "Insert hello into *notes*",
                                 demo_line_action,
                                 "hello from an interactive config buffer!\n",
                                 NULL);

    ecex_interactive_append_line(ed,
                                 menu,
                                 "Insert gruvbox note into *notes*",
                                 demo_line_action,
                                 "gruvbox menu action selected\n",
                                 NULL);

    ecex_switch_buffer(ed, "*demo-menu*");
    return 0;
}

static const ecex_config_command_t config_commands[] = {
    {"hello", hello_command},
    {"make-notes", make_notes_command},
    {"demo-interactive", demo_interactive_command},
};

static const ecex_config_keybind_t config_binds[] = {
    {"C-h", "hello"},
    {"C-m", "make-notes"},
    {"F2", "list-commands"},
    {"F3", "list-buffers"},
    {"F4", "demo-interactive"},
    {"C-q", "quit"},
    {"C-x h", "beginning-of-buffer"},
};

ECEX_CONFIG_BEGIN
    ecex_set_font_size(ed, 20.0f);

    ecex_set_bg_color(ed, GB_DARK0_HARD);
    ecex_set_fg_color(ed, GB_LIGHT1);

    ecex_set_status_bg_color(ed, GB_DARK0);
    ecex_set_status_fg_color(ed, GB_YELLOW);
    ecex_set_status_border_color(ed, GB_DARK1);

    ecex_set_minibuffer_bg_color(ed, GB_DARK1);
    ecex_set_minibuffer_fg_color(ed, GB_LIGHT0);

    ecex_set_completion_enabled(ed, 1);
    ecex_set_completion_fg_color(ed, GB_DARK2);

    ecex_set_interactive_highlight_bg_color(ed, GB_DARK1);
    ecex_set_interactive_highlight_fg_color(ed, GB_YELLOW);

    ecex_set_cursor_color(ed, GB_AQUA);
    ecex_set_region_bg_color(ed, GB_DARK2);

    ECEX_CONFIG_COMMANDS(config_commands);
    ECEX_CONFIG_BINDS(config_binds);
    ECEX_CONFIG_INCLUDE(ecex_render_demo_plugin);
    ECEX_CONFIG_INCLUDE(ecex_tetris_plugin);
    ECEX_CONFIG_INCLUDE(ecex_markdown_plugin);
    ECEX_CONFIG_INCLUDE(ecex_which_key_plugin);
    ECEX_CONFIG_INCLUDE(ecex_c_mode_plugin);
    ECEX_CONFIG_INCLUDE(ecex_api_completion_plugin);
    if (ecex_plugin_require_dependency(ed, "c-tools", "clang") == 0 &&
        ecex_plugin_require_dependency(ed, "c-tools", "clangd") == 0) {
        ECEX_CONFIG_INCLUDE(ecex_c_tools_plugin);
    }

    buffer_t *scratch = ecex_current_buffer(ed);

    buffer_insert(scratch, "ecex config loaded !\n");
    buffer_insert(scratch, "Try M-x, C-x C-f, C-x C-s, C-x d file browser, F2 commands, F3 buffers, F4 demo menu, C-x b.\n");
    buffer_insert(scratch, "which-key is enabled: press C-x or M-g and the minibuffer will show continuations.\n");
    buffer_insert(scratch, "TAB indents; in C buffers it smart-indents. C-TAB completes and cycles candidates.\n");
    buffer_insert(scratch, "C completion asks clangd; c-mode highlights C syntax.\n");
    buffer_insert(scratch, "When c-tools is loaded, C-x c l checks, C-x c k lints, C-x c e lints with ./include.\n");
    buffer_insert(scratch, "Run M-x render-demo for a custom renderer demo, or M-x tetris for Tetris.\n");
    buffer_insert(scratch, "Example line to edit then C-x C-e: ecex_set_font_size(ed, 28.0f);\n");
    buffer_insert(scratch, "Example relative change: ecex_adjust_font_size(ed, 2.0f);\n\n");

ECEX_CONFIG_END