From: Michael D. Lowis Date: Tue, 30 May 2017 15:07:29 +0000 (-0400) Subject: fixed a bug in edit_relative function, added a cursor summoning shortcut fixed linkin... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3ac18658aac1031c8dd9c2224c1fe052ee21e457;p=projs%2Ftide.git fixed a bug in edit_relative function, added a cursor summoning shortcut fixed linking on linux for term.c --- diff --git a/TODO.md b/TODO.md index 416a49d..45560d3 100644 --- a/TODO.md +++ b/TODO.md @@ -5,7 +5,7 @@ Up Next: * move by words is inconsistent. Example: var infoId = 'readerinfo'+reader.id; * Add a way to CD using a builtin (buffers will track original dir) -* selection of 1 and arrow keys moves wrong direction +* selection of size 1 and arrow keys moves wrong direction * cd to root in xcpd * Ctrl+; Shortcut to warp cursor to middle of current screen. * shortcut to jump to previous edit @@ -33,6 +33,7 @@ Maybe think about addressing these later: * Shift+Insert should insert primary selection * Find shortcut should select previous word if current char is newline * diagnostic messages can stack up if deselected and not resolved +* mouse click and hold on scroll bar should continually scroll # Auxillary Programs diff --git a/config.mk b/config.mk index 583123a..f2e2dce 100644 --- a/config.mk +++ b/config.mk @@ -18,7 +18,7 @@ CFLAGS = --std=c99 -MMD $(INCS) # Linker Setup LD = $(CC) -LDFLAGS = $(LIBS) -lX11 -lXft -lfontconfig +LDFLAGS = $(LIBS) -lX11 -lXft -lfontconfig -lutil # Archive Setup AR = ar diff --git a/inc/edit.h b/inc/edit.h index af2e8ba..d5497d3 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -176,6 +176,7 @@ char* view_getcmd(View* view); char* view_getctx(View* view); void view_selctx(View* view); void view_scroll(View* view, int move); +void view_csrsummon(View* view); void view_scrollpage(View* view, int move); void view_setln(View* view, size_t line); void view_indent(View* view, int dir); diff --git a/inc/shortcuts.h b/inc/shortcuts.h index a3a6258..9835c61 100644 --- a/inc/shortcuts.h +++ b/inc/shortcuts.h @@ -148,6 +148,10 @@ static void cursor_right(void) { 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); } diff --git a/lib/utils.c b/lib/utils.c index ceebd3e..f94eb87 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -137,8 +137,8 @@ char* strconcat(char* dest, ...) { va_list args; char* curr = dest; va_start(args, dest); - for (char* s; (s = va_arg(args, char*));) - while (*s) *(curr++) = *(s++); + for (char* s = NULL; (s = va_arg(args, char*));) + while (s && *s) *(curr++) = *(s++); va_end(args); *curr = '\0'; return dest; diff --git a/lib/view.c b/lib/view.c index 66d20b8..6d330ac 100644 --- a/lib/view.c +++ b/lib/view.c @@ -567,37 +567,25 @@ void view_scroll(View* view, int move) { } } -void view_scrollpage(View* view, int move) { +void view_csrsummon(View* view) { size_t col = SIZE_MAX, row = SIZE_MAX; find_cursor(view, &col, &row); - move = (move < 0 ? -1 : 1) * view->nrows; - view_scroll(view, move); - size_t off = view->rows[view->nrows/2]->off; - -// size_t scrbeg = view->rows[0]->off; -// size_t scrend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen - 1; -// if (scrbeg == 0) -// off = 0; -// else if (scrend >= buf_end(&(view->buffer))) -// off = view->rows[view->nrows-1]->off; - -// size_t off = (move == UP ? view->rows[0]->off : view->rows[view->nrows/2]->off); -// if (row != SIZE_MAX && col != SIZE_MAX) { -// off = view->rows[row]->off + col; -// if (col >= view->rows[row]->rlen) -// off = view->rows[row]->off + view->rows[row]->rlen - 1; -// } - + size_t off = view->rows[view->nrows/2]->off; if (row != SIZE_MAX && col != SIZE_MAX) if (col >= view->rows[view->nrows/2]->rlen) off = view->rows[view->nrows/2]->off + view->rows[view->nrows/2]->rlen - 1; else off += col; - view_jumpto(view, false, off); view->sync_needed = false; } +void view_scrollpage(View* view, int move) { + move = (move < 0 ? -1 : 1) * view->nrows; + view_scroll(view, move); + view_csrsummon(view); +} + void view_indent(View* view, int dir) { Buf* buf = &(view->buffer); unsigned indoff = (buf->expand_tabs ? TabWidth : 1); diff --git a/term.c b/term.c index 14b8c3e..b6b523a 100644 --- a/term.c +++ b/term.c @@ -40,8 +40,12 @@ void onerror(char* msg) { #ifndef TEST #include -#include #include +#ifdef __MACH__ +#include +#else +#include +#endif void spawn_shell(int master, int slave) { static char* shell[] = { "/bin/sh", "-l", NULL }; diff --git a/tide.c b/tide.c index ad45db0..4441a24 100644 --- a/tide.c +++ b/tide.c @@ -417,12 +417,13 @@ static Tag Builtins[] = { static KeyBinding Bindings[] = { /* Cursor Movements */ - { ModAny, KEY_HOME, cursor_home }, - { ModAny, KEY_END, cursor_end }, - { ModAny, KEY_UP, cursor_up }, - { ModAny, KEY_DOWN, cursor_dn }, - { ModAny, KEY_LEFT, cursor_left }, - { ModAny, KEY_RIGHT, cursor_right }, + { ModAny, KEY_HOME, cursor_home }, + { ModAny, KEY_END, cursor_end }, + { ModAny, KEY_UP, cursor_up }, + { ModAny, KEY_DOWN, cursor_dn }, + { ModAny, KEY_LEFT, cursor_left }, + { ModAny, KEY_RIGHT, cursor_right }, + { ModCtrl, ';', cursor_warp }, /* Standard Unix Shortcuts */ { ModCtrl, 'u', del_to_bol }, @@ -534,9 +535,10 @@ void edit_relative(char* path) { /* search for a ctags index file indicating the project root */ if (try_chdir(path)) { - currdir = getcurrdir(); - currpath = calloc(strlen(currdir) + strlen("/tags") + 1, 1); - relpath = calloc(strlen(currdir) + strlen("/tags") + 1, 1); + currdir = getcurrdir(); + size_t sz = strlen(currdir) + strlen(path) + strlen("/tags") + 1; + currpath = calloc(sz, 1); + relpath = calloc(sz, 1); while (true) { /* figure out the current path to check */ strconcat(currpath, currdir, "/tags", 0); @@ -559,7 +561,7 @@ void edit_relative(char* path) { if (currdir && *currdir) { char* fname = strrchr(path, '/')+1; if (*relpath) - strconcat(currpath, relpath+1, "/", fname, 0); + strconcat(currpath, (*relpath == '/' ? relpath+1 : relpath), "/", fname, 0); else strconcat(currpath, fname, 0); chdir(currdir);