From: Michael D. Lowis Date: Mon, 26 Mar 2018 01:02:44 +0000 (-0400) Subject: consolidated shortucts and removed dead code X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a6a55d5845d020ae67301b7803526b633cc6b4b7;p=projs%2Ftide.git consolidated shortucts and removed dead code --- diff --git a/inc/edit.h b/inc/edit.h index 15c0a4f..fadd6d0 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -121,20 +121,6 @@ void utf8save(Buf* buf, FILE* file); void binload(Buf* buf, FMap file); void binsave(Buf* buf, FILE* file); -/* Syntax Highlighting - *****************************************************************************/ -typedef struct SyntaxSpan { - size_t beg; - size_t end; - size_t color; - struct SyntaxSpan* prev; - struct SyntaxSpan* next; -} SyntaxSpan; - -void colors_init(char* path); -SyntaxSpan* colors_scan(SyntaxSpan* spans, Buf* buf, size_t beg, size_t end); -SyntaxSpan* colors_rewind(SyntaxSpan* spans, size_t first); - /* Screen management functions *****************************************************************************/ typedef struct { @@ -156,7 +142,6 @@ typedef struct { size_t nrows; /* number of rows in the view */ size_t ncols; /* number of columns in the view */ Row** rows; /* array of row data structures */ - SyntaxSpan* spans; /* list of colored regions */ int clrnor, clrsel; /* text color pairs for normal and selected text */ bool sync_needed; /* whether the view needs to be synced with cursor */ bool sync_center; /* cursor should be centered on screen if possible */ diff --git a/inc/shortcuts.h b/inc/shortcuts.h deleted file mode 100644 index 39767c2..0000000 --- a/inc/shortcuts.h +++ /dev/null @@ -1,182 +0,0 @@ -static void select_line(void) { - View* view = win_view(FOCUSED); - view_eol(view, false); - view_selctx(view); -} - -static void select_all(void) { - View* view = win_view(FOCUSED); - view_jumpto(view, false, buf_end(&(view->buffer))); - view->selection.beg = 0; -} - -static void join_lines(void) { - View* view = win_view(FOCUSED); - view_eol(view, false); - view_delete(view, RIGHT, false); - Rune r = view_getrune(view); - for (; r == '\t' || r == ' '; r = view_getrune(view)) - view_byrune(view, RIGHT, true); - if (r != '\n' && r != RUNE_CRLF) - view_insert(view, false, ' '); -} - -static void delete(void) { - bool byword = x11_keymodsset(ModCtrl); - view_delete(win_view(FOCUSED), RIGHT, byword); -} - -static void onpaste(char* text) { - view_putstr(win_view(FOCUSED), text); -} - -static void cut(void) { - View* view = win_view(FOCUSED); - /* select the current line if no selection */ - if (!view_selsize(view)) - select_line(); - /* now perform the cut */ - char* str = view_getstr(view, NULL); - x11_sel_set(CLIPBOARD, str); - if (str && *str) { - delete(); - if (view->selection.end == buf_end(&(view->buffer))) - view_delete(view, LEFT, false); - } -} - -static void paste(void) { - assert(x11_sel_get(CLIPBOARD, onpaste)); -} - -static void copy(void) { - /* select the current line if no selection */ - if (!view_selsize(win_view(FOCUSED))) - select_line(); - char* str = view_getstr(win_view(FOCUSED), NULL); - x11_sel_set(CLIPBOARD, str); -} - -static void del_to_bol(void) { - view_bol(win_view(FOCUSED), true); - if (view_selsize(win_view(FOCUSED)) > 0) - delete(); -} - -static void del_to_eol(void) { - view_eol(win_view(FOCUSED), true); - if (view_selsize(win_view(FOCUSED)) > 0) - delete(); -} - -static void del_to_bow(void) { - view_byword(win_view(FOCUSED), LEFT, true); - if (view_selsize(win_view(FOCUSED)) > 0) - delete(); -} - -static void backspace(void) { - bool byword = x11_keymodsset(ModCtrl); - view_delete(win_view(FOCUSED), LEFT, byword); -} - -static void cursor_bol(void) { - view_bol(win_view(FOCUSED), false); -} - -static void cursor_eol(void) { - view_eol(win_view(FOCUSED), false); -} - -static void move_line_up(void) { - if (!view_selsize(win_view(FOCUSED))) - select_line(); - cut(); - view_byline(win_view(FOCUSED), UP, false); - paste(); -} - -static void move_line_dn(void) { - if (!view_selsize(win_view(FOCUSED))) - select_line(); - cut(); - cursor_eol(); - view_byrune(win_view(FOCUSED), RIGHT, false); - paste(); -} - -static void cursor_home(void) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_bof(win_view(FOCUSED), extsel); - else - view_bol(win_view(FOCUSED), extsel); -} - -static void cursor_end(void) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_eof(win_view(FOCUSED), extsel); - else - view_eol(win_view(FOCUSED), extsel); -} - -static void cursor_up(void) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - move_line_up(); - else - view_byline(win_view(FOCUSED), UP, extsel); -} - -static void cursor_dn(void) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - move_line_dn(); - else - view_byline(win_view(FOCUSED), DOWN, extsel); -} - -static void cursor_left(void) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_byword(win_view(FOCUSED), LEFT, extsel); - else - view_byrune(win_view(FOCUSED), LEFT, extsel); -} - -static void cursor_right(void) { - bool extsel = x11_keymodsset(ModShift); - if (x11_keymodsset(ModCtrl)) - view_byword(win_view(FOCUSED), RIGHT, extsel); - else - view_byrune(win_view(FOCUSED), RIGHT, extsel); -} - -static void cursor_warp(void) { - view_csrsummon(win_view(FOCUSED)); -} - -static void page_up(void) { - view_scrollpage(win_view(FOCUSED), UP); -} - -static void page_dn(void) { - view_scrollpage(win_view(FOCUSED), DOWN); -} - -static void select_prev(void) { - view_selprev(win_view(FOCUSED)); -} - -static void change_focus(void) { - win_setregion(win_getregion() == TAGS ? EDIT : TAGS); -} - -static void undo(void) { - view_undo(win_view(FOCUSED)); -} - -static void redo(void) { - view_redo(win_view(FOCUSED)); -} diff --git a/lib/win.c b/lib/win.c deleted file mode 100644 index 8b13789..0000000 --- a/lib/win.c +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tide.c b/tide.c index b8028ee..47d6bf6 100644 --- a/tide.c +++ b/tide.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -37,6 +36,193 @@ char* FetchCmd[] = { "tfetch", NULL, NULL }; #define CMD_GOTO_TAG "!picktag fetch tags" #define CMD_FETCH "tfetch" +/* + ******************************************************************************/ +static void select_line(void) { + View* view = win_view(FOCUSED); + view_eol(view, false); + view_selctx(view); +} + +static void select_all(void) { + View* view = win_view(FOCUSED); + view_jumpto(view, false, buf_end(&(view->buffer))); + view->selection.beg = 0; +} + +static void join_lines(void) { + View* view = win_view(FOCUSED); + view_eol(view, false); + view_delete(view, RIGHT, false); + Rune r = view_getrune(view); + for (; r == '\t' || r == ' '; r = view_getrune(view)) + view_byrune(view, RIGHT, true); + if (r != '\n' && r != RUNE_CRLF) + view_insert(view, false, ' '); +} + +static void delete(void) { + bool byword = x11_keymodsset(ModCtrl); + view_delete(win_view(FOCUSED), RIGHT, byword); +} + +static void onpaste(char* text) { + view_putstr(win_view(FOCUSED), text); +} + +static void cut(void) { + View* view = win_view(FOCUSED); + /* select the current line if no selection */ + if (!view_selsize(view)) + select_line(); + /* now perform the cut */ + char* str = view_getstr(view, NULL); + x11_sel_set(CLIPBOARD, str); + if (str && *str) { + delete(); + if (view->selection.end == buf_end(&(view->buffer))) + view_delete(view, LEFT, false); + } +} + +static void paste(void) { + assert(x11_sel_get(CLIPBOARD, onpaste)); +} + +static void copy(void) { + /* select the current line if no selection */ + if (!view_selsize(win_view(FOCUSED))) + select_line(); + 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(); +} + +static void del_to_bol(void) { + del_to(view_bol); +} + +static void del_to_eol(void) { + del_to(view_eol); +} + +static void del_to_bow(void) { + view_byword(win_view(FOCUSED), LEFT, true); + if (view_selsize(win_view(FOCUSED)) > 0) + delete(); +} + +static void backspace(void) { + bool byword = x11_keymodsset(ModCtrl); + view_delete(win_view(FOCUSED), LEFT, byword); +} + +static void cursor_bol(void) { + view_bol(win_view(FOCUSED), false); +} + +static void cursor_eol(void) { + view_eol(win_view(FOCUSED), false); +} + +static void move_line_up(void) { + if (!view_selsize(win_view(FOCUSED))) + select_line(); + cut(); + view_byline(win_view(FOCUSED), UP, false); + paste(); +} + +static void move_line_dn(void) { + if (!view_selsize(win_view(FOCUSED))) + select_line(); + cut(); + cursor_eol(); + view_byrune(win_view(FOCUSED), RIGHT, false); + paste(); +} + +static void cursor_home(void) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + view_bof(win_view(FOCUSED), extsel); + else + view_bol(win_view(FOCUSED), extsel); +} + +static void cursor_end(void) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + view_eof(win_view(FOCUSED), extsel); + else + view_eol(win_view(FOCUSED), extsel); +} + +static void cursor_up(void) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + move_line_up(); + else + view_byline(win_view(FOCUSED), UP, extsel); +} + +static void cursor_dn(void) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + move_line_dn(); + else + view_byline(win_view(FOCUSED), DOWN, extsel); +} + +static void cursor_left(void) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + view_byword(win_view(FOCUSED), LEFT, extsel); + else + view_byrune(win_view(FOCUSED), LEFT, extsel); +} + +static void cursor_right(void) { + bool extsel = x11_keymodsset(ModShift); + if (x11_keymodsset(ModCtrl)) + view_byword(win_view(FOCUSED), RIGHT, extsel); + else + view_byrune(win_view(FOCUSED), RIGHT, extsel); +} + +static void cursor_warp(void) { + view_csrsummon(win_view(FOCUSED)); +} + +static void page_up(void) { + view_scrollpage(win_view(FOCUSED), UP); +} + +static void page_dn(void) { + view_scrollpage(win_view(FOCUSED), DOWN); +} + +static void select_prev(void) { + view_selprev(win_view(FOCUSED)); +} + +static void change_focus(void) { + win_setregion(win_getregion() == TAGS ? EDIT : TAGS); +} + +static void undo(void) { + view_undo(win_view(FOCUSED)); +} + +static void redo(void) { + view_redo(win_view(FOCUSED)); +} + /* Tag/Cmd Execution ******************************************************************************/ static Tag* tag_lookup(char* cmd) {