From: Michael D. Lowis Date: Tue, 6 Dec 2016 16:48:43 +0000 (-0500) Subject: Added shortcuts for indent/deindent X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ab3ca1d1e1e30533ab517dc3203b04d71374eac4;p=projs%2Ftide.git Added shortcuts for indent/deindent --- diff --git a/TODO.md b/TODO.md index 771e971..a0f8077 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,10 @@ # Implementation Tweaks and Bug Fixes +* Home key should toggle between beginning of line and beginning of non-ws data * Expand tabs setting should be disabled if opened file contains tabs * Add tag for ctags lookup and line number jump * add a shortcut to autocomplete ctag +* Add a tools dir to namespace utility scripts only useful inside the editor * off by one error on scrolling up with wrapped lines * block selection should handle brace-balancing * Use select to check for error strings in exec.c @@ -10,6 +12,8 @@ * track down double click bug for selecting whole line * Implement minimal regex search (per Kernighan article) * Implement fuzzy file/buffer/tag picker +* check for file changes when window regains focus +* check for file changes on save # Auxillary Programs diff --git a/inc/edit.h b/inc/edit.h index 2058cb4..e3da9fa 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -161,6 +161,7 @@ char* view_getctx(View* view); void view_scroll(View* view, int move); void view_scrollpage(View* view, int move); void view_setln(View* view, size_t line); +void view_indent(View* view, int dir); /* Command Executions *****************************************************************************/ diff --git a/libedit/view.c b/libedit/view.c index 980e833..a55a314 100644 --- a/libedit/view.c +++ b/libedit/view.c @@ -555,3 +555,32 @@ void view_setln(View* view, size_t line) { view->sync_needed = true; view->sync_center = true; } + +void view_indent(View* view, int dir) { + Buf* buf = &(view->buffer); + unsigned indoff = (buf->expand_tabs ? TabWidth : 1); + view->selection.beg = buf_bol(buf, view->selection.beg); + view->selection.end = buf_eol(buf, view->selection.end); + unsigned off = buf_bol(buf, view->selection.end); + while (off >= view->selection.beg) { + if (dir == RIGHT) { + buf_ins(buf, true, off, '\t'); + view->selection.end += indoff; + } else if (dir == LEFT) { + unsigned i = 4; + for (; i > 0; i--) { + if (' ' == buf_get(buf, off)) { + buf_del(buf, off); + view->selection.end--; + } else { + break; + } + } + if (i && '\t' == buf_get(buf, off)) { + buf_del(buf, off); + view->selection.end--; + } + } + off = buf_byline(buf, off, UP); + } +} \ No newline at end of file diff --git a/xedit.c b/xedit.c index 5869813..dd7d347 100644 --- a/xedit.c +++ b/xedit.c @@ -53,6 +53,8 @@ static void pick_ctag(void); static void goto_ctag(void); static void tabs(void); static void indent(void); +static void del_indent(void); +static void add_indent(void); // Tag/Cmd Execution static Tag* tag_lookup(char* cmd); @@ -73,6 +75,8 @@ static Buf* getbuf(enum RegionId id); static View* currview(void); static Buf* currbuf(void); static enum RegionId getregion(size_t x, size_t y); +static Sel* getsel(enum RegionId id); +static Sel* currsel(void); /* Global Data *****************************************************************************/ @@ -130,6 +134,10 @@ static KeyBinding Bindings[] = { { ModCtrl, 'x', cut }, { ModCtrl, 'c', copy }, { ModCtrl, 'v', paste }, + + /* Block Indent */ + { ModCtrl, '[', del_indent }, + { ModCtrl, ']', add_indent }, /* Common Special Keys */ { ModNone, KEY_PGUP, page_up }, @@ -570,6 +578,14 @@ static void indent(void) { getbuf(TAGS)->copy_indent = enabled; } +static void del_indent(void) { + view_indent(currview(), LEFT); +} + +static void add_indent(void) { + view_indent(currview(), RIGHT); +} + /* Tag/Cmd Execution *****************************************************************************/ static Tag* tag_lookup(char* cmd) { @@ -706,3 +722,11 @@ static enum RegionId getregion(size_t x, size_t y) { } return NREGIONS; } + +static Sel* getsel(enum RegionId id) { + return &(getview(id)->selection); +} + +static Sel* currsel(void) { + return getsel(Focused); +}