bool buffer_insert0(Buffer *buf, size_t pos, const char *data) { if (pos == 0) return buffer_prepend0(buf, data); if (pos == buf->len) return buffer_append0(buf, data); return buffer_insert(buf, pos, data, strlen(data)); }
void vis_keys_feed(Vis *vis, const char *input) { if (!input) return; if (vis->recording) macro_append(vis->recording, input); if (vis->macro_operator) macro_append(vis->macro_operator, input); if (!buffer_append0(vis->keys, input)) buffer_truncate(vis->keys); /* if we are being called from within a keyhandler then appending * the new keys to the end of the input queue is enough. they will * be interpreted once the key handler returns and control reaches * back to the vis_keys_process function. */ if (!vis->keyhandler) vis_keys_process(vis); }
const char *vis_keys_push(Vis *vis, const char *input) { if (!input) return NULL; if (vis->recording) macro_append(vis->recording, input); if (vis->macro_operator) macro_append(vis->macro_operator, input); if (!buffer_append0(&vis->input_queue, input)) { buffer_truncate(&vis->input_queue); return NULL; } return vis_keys_raw(vis, &vis->input_queue, input); }
static bool cmd_substitute(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) { Buffer buf; buffer_init(&buf); bool ret = false; if (buffer_put0(&buf, "s") && buffer_append0(&buf, argv[1])) ret = cmd_filter(vis, win, cmd, (const char*[]){ argv[0], "sed", buf.data, NULL }, cur, range);