typedef struct {
char* tag;
- union {
- void (*noarg)(void);
- void (*arg)(char* arg);
- } action;
+ void (*action)(char*);
} Tag;
static Tag Builtins[];
/*
******************************************************************************/
-static void select_line(void) {
+static void select_line(char* arg) {
View* view = win_view(FOCUSED);
view_eol(view, false);
view_selctx(view);
}
-static void select_all(void) {
+static void select_all(char* arg) {
View* view = win_view(FOCUSED);
view_jumpto(view, false, buf_end(&(view->buffer)));
view->selection.beg = 0;
}
-static void join_lines(void) {
+static void join_lines(char* arg) {
View* view = win_view(FOCUSED);
view_eol(view, false);
view_delete(view, RIGHT, false);
view_insert(view, false, ' ');
}
-static void delete(void) {
+static void delete(char* arg) {
bool byword = x11_keymodsset(ModCtrl);
view_delete(win_view(FOCUSED), RIGHT, byword);
}
view_putstr(win_view(FOCUSED), text);
}
-static void cut(void) {
+static void cut(char* arg) {
View* view = win_view(FOCUSED);
/* select the current line if no selection */
if (!view_selsize(view))
- select_line();
+ select_line(arg);
/* now perform the cut */
char* str = view_getstr(view, NULL);
x11_sel_set(CLIPBOARD, str);
if (str && *str) {
- delete();
+ delete(arg);
if (view->selection.end == buf_end(&(view->buffer)))
view_delete(view, LEFT, false);
}
}
-static void paste(void) {
+static void paste(char* arg) {
assert(x11_sel_get(CLIPBOARD, onpaste));
}
-static void copy(void) {
+static void copy(char* arg) {
/* select the current line if no selection */
if (!view_selsize(win_view(FOCUSED)))
- select_line();
+ select_line(arg);
char* str = view_getstr(win_view(FOCUSED), NULL);
x11_sel_set(CLIPBOARD, str);
}
static void del_to(void (*tofn)(View*, bool)) {
tofn(win_view(FOCUSED), true);
if (view_selsize(win_view(FOCUSED)) > 0)
- delete();
+ delete(NULL);
}
-static void del_to_bol(void) {
+static void del_to_bol(char* arg) {
del_to(view_bol);
}
-static void del_to_eol(void) {
+static void del_to_eol(char* arg) {
del_to(view_eol);
}
-static void del_to_bow(void) {
+static void del_to_bow(char* arg) {
view_byword(win_view(FOCUSED), LEFT, true);
if (view_selsize(win_view(FOCUSED)) > 0)
- delete();
+ delete(arg);
}
-static void backspace(void) {
+static void backspace(char* arg) {
view_delete(win_view(FOCUSED), LEFT, x11_keymodsset(ModCtrl));
}
-static void cursor_bol(void) {
+static void cursor_bol(char* arg) {
view_bol(win_view(FOCUSED), false);
}
-static void cursor_eol(void) {
+static void cursor_eol(char* arg) {
view_eol(win_view(FOCUSED), false);
}
-static void move_line_up(void) {
+static void move_line_up(char* arg) {
if (!view_selsize(win_view(FOCUSED)))
- select_line();
- cut();
+ select_line(arg);
+ cut(arg);
view_byline(win_view(FOCUSED), UP, false);
- paste();
+ paste(arg);
}
-static void move_line_dn(void) {
+static void move_line_dn(char* arg) {
if (!view_selsize(win_view(FOCUSED)))
- select_line();
- cut();
- cursor_eol();
+ select_line(arg);
+ cut(arg);
+ cursor_eol(arg);
view_byrune(win_view(FOCUSED), RIGHT, false);
- paste();
+ paste(arg);
}
-static void cursor_home(void) {
+static void cursor_home(char* arg) {
bool extsel = x11_keymodsset(ModShift);
if (x11_keymodsset(ModCtrl))
view_bof(win_view(FOCUSED), extsel);
view_bol(win_view(FOCUSED), extsel);
}
-static void cursor_end(void) {
+static void cursor_end(char* arg) {
bool extsel = x11_keymodsset(ModShift);
if (x11_keymodsset(ModCtrl))
view_eof(win_view(FOCUSED), extsel);
view_eol(win_view(FOCUSED), extsel);
}
-static void cursor_up(void) {
+static void cursor_up(char* arg) {
bool extsel = x11_keymodsset(ModShift);
if (x11_keymodsset(ModCtrl))
- move_line_up();
+ move_line_up(arg);
else
view_byline(win_view(FOCUSED), UP, extsel);
}
-static void cursor_dn(void) {
+static void cursor_dn(char* arg) {
bool extsel = x11_keymodsset(ModShift);
if (x11_keymodsset(ModCtrl))
- move_line_dn();
+ move_line_dn(arg);
else
view_byline(win_view(FOCUSED), DOWN, extsel);
}
-static void cursor_left(void) {
+static void cursor_left(char* arg) {
bool extsel = x11_keymodsset(ModShift);
if (x11_keymodsset(ModCtrl))
view_byword(win_view(FOCUSED), LEFT, extsel);
view_byrune(win_view(FOCUSED), LEFT, extsel);
}
-static void cursor_right(void) {
+static void cursor_right(char* arg) {
bool extsel = x11_keymodsset(ModShift);
if (x11_keymodsset(ModCtrl))
view_byword(win_view(FOCUSED), RIGHT, extsel);
view_byrune(win_view(FOCUSED), RIGHT, extsel);
}
-static void cursor_warp(void) {
+static void cursor_warp(char* arg) {
view_csrsummon(win_view(FOCUSED));
}
-static void page_up(void) {
+static void page_up(char* arg) {
view_scrollpage(win_view(FOCUSED), UP);
}
-static void page_dn(void) {
+static void page_dn(char* arg) {
view_scrollpage(win_view(FOCUSED), DOWN);
}
-static void select_prev(void) {
+static void select_prev(char* arg) {
view_selprev(win_view(FOCUSED));
}
-static void change_focus(void) {
+static void change_focus(char* arg) {
win_setregion(win_getregion() == TAGS ? EDIT : TAGS);
}
-static void undo(void) {
+static void undo(char* arg) {
view_undo(win_view(FOCUSED));
}
-static void redo(void) {
+static void redo(char* arg) {
view_redo(win_view(FOCUSED));
}
if (!arg) arg = view_getstr(win_view(TAGS), NULL);
if (!arg) arg = view_getstr(win_view(EDIT), NULL);
/* execute the tag handler */
- tag->action.arg(arg);
+ tag->action(arg);
free(arg);
}
win_setregion(TAGS);
}
-static void trim_whitespace(void) {
+static void trim_whitespace(char* arg) {
Buf* buf = win_buf(EDIT);
if (TrimOnSave && buf_end(buf) > 0) {
View* view = win_view(EDIT);
}
}
-static void quit(void) {
+static void quit(char* arg) {
static uint64_t before = 0;
uint64_t now = getmillis();
if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)ClickTime) {
}
static void put(char* arg) {
- trim_whitespace();
+ trim_whitespace(arg);
win_save(arg);
}
-static void save(void) {
+static void save(char* arg) {
put(NULL);
}
void onmousemiddle(WinRegion id, bool pressed, size_t row, size_t col) {
if (pressed) return;
if (win_btnpressed(MouseLeft)) {
- cut();
+ cut(NULL);
} else {
char* str = view_fetch(win_view(id), row, col, riscmd);
if (str) exec(str);
void onmouseright(WinRegion id, bool pressed, size_t row, size_t col) {
if (pressed) return;
if (win_btnpressed(MouseLeft)) {
- paste();
+ paste(NULL);
} else {
SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);
free(SearchTerm);
/* Keyboard Handling
******************************************************************************/
-static void tag_undo(void) {
+static void tag_undo(char* arg) {
view_undo(win_view(EDIT));
}
-static void tag_redo(void) {
+static void tag_redo(char* arg) {
view_redo(win_view(EDIT));
}
-static void search(void) {
+static void search(char* arg) {
char* str;
SearchDir *= (x11_keymodsset(ModShift) ? UP : DOWN);
if (x11_keymodsset(ModAlt) && SearchTerm)
SearchTerm = str;
}
-static void execute(void) {
+static void execute(char* arg) {
char* str = view_getcmd(win_view(FOCUSED));
if (str) exec(str);
free(str);
view_findstr(win_view(EDIT), SearchDir, arg);
}
-static void open_file(void) {
+static void open_file(char* arg) {
cmd_exec(CMD_PICKFILE);
}
cmd_execwitharg(CMD_GOTO_TAG, symbol);
}
-static void pick_ctag(void) {
+static void pick_ctag(char* arg) {
pick_symbol(NULL);
}
-static void complete(void) {
+static void complete(char* arg) {
View* view = win_view(FOCUSED);
buf_getword(&(view->buffer), risword, &(view->selection));
view->selection.end = buf_byrune(&(view->buffer), view->selection.end, RIGHT);
}
}
-static void goto_ctag(void) {
+static void goto_ctag(char* arg) {
if (x11_keymodsset(ModShift)) {
view_jumpback(win_view(FOCUSED));
} else {
}
}
-static void tabs(void) {
+static void tabs(char* arg) {
ExpandTabs = !ExpandTabs;
}
-static void indent(void) {
+static void indent(char* arg) {
CopyIndent = !CopyIndent;
}
-static void del_indent(void) {
+static void del_indent(char* arg) {
view_indent(win_view(FOCUSED), LEFT);
}
-static void add_indent(void) {
+static void add_indent(char* arg) {
view_indent(win_view(FOCUSED), RIGHT);
}
-static void eol_mode(void) {
+static void eol_mode(char* arg) {
DosLineFeed = !DosLineFeed;
cmd_exec(DosLineFeed ? CMD_TO_DOS : CMD_TO_UNIX);
}
-static void new_win(void) {
+static void new_win(char* arg) {
cmd_exec(CMD_TIDE);
}
-static void newline(void) {
+static void newline(char* arg) {
View* view = win_view(FOCUSED);
if (x11_keymodsset(ModShift)) {
view_byline(view, UP, false);
view_insert(view, true, '\n');
}
-static void highlight(void) {
+static void highlight(char* arg) {
view_selctx(win_view(FOCUSED));
}
/* Main Routine
******************************************************************************/
static Tag Builtins[] = {
- { .tag = "Cut", .action.noarg = cut },
- { .tag = "Copy", .action.noarg = copy },
- { .tag = "Del", .action.noarg = quit },
- { .tag = "Eol", .action.noarg = eol_mode },
- { .tag = "Find", .action.arg = find },
- { .tag = "GoTo", .action.arg = jump_to },
- { .tag = "Get", .action.arg = get },
- { .tag = "Indent", .action.noarg = indent },
- { .tag = "Paste", .action.noarg = paste },
- { .tag = "Put", .action.arg = put },
- { .tag = "Redo", .action.noarg = tag_redo },
- { .tag = "Tabs", .action.noarg = tabs },
- { .tag = "Undo", .action.noarg = tag_undo },
- { .tag = NULL, .action.noarg = NULL }
+ { .tag = "Cut", .action = cut },
+ { .tag = "Copy", .action = copy },
+ { .tag = "Del", .action = quit },
+ { .tag = "Eol", .action = eol_mode },
+ { .tag = "Find", .action = find },
+ { .tag = "GoTo", .action = jump_to },
+ { .tag = "Get", .action = get },
+ { .tag = "Indent", .action = indent },
+ { .tag = "Paste", .action = paste },
+ { .tag = "Put", .action = put },
+ { .tag = "Redo", .action = tag_redo },
+ { .tag = "Tabs", .action = tabs },
+ { .tag = "Undo", .action = tag_undo },
+ { .tag = NULL, .action = NULL }
};
static KeyBinding Bindings[] = {
(void)changed_externally(win_buf(EDIT));
}
-void onupdate(void) {
-}
-
void onlayout(void) {
/* calculate and update scroll region */
View* view = win_view(EDIT);
}
void onshutdown(void) {
- quit();
+ quit(0);
exit(0);
}