]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added shortcuts for indent/deindent
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 6 Dec 2016 16:48:43 +0000 (11:48 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 6 Dec 2016 16:48:43 +0000 (11:48 -0500)
TODO.md
inc/edit.h
libedit/view.c
xedit.c

diff --git a/TODO.md b/TODO.md
index 771e971c9fafc7e6ef99a15e1d30ebcc5aadf96a..a0f8077f81b0cbffad99616ad0eaa8cfd8aa3f1b 100644 (file)
--- 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
 
index 2058cb4e41aeb30d3024db7b0b0a27b41fb6486c..e3da9fac73606dd96e5c084b6c722a7881d712cd 100644 (file)
@@ -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
  *****************************************************************************/
index 980e833f9853e0cdf0fff4c3b065b163c3373507..a55a3142ddcc4c6becf46b6d4816ff6bc6e55a3e 100644 (file)
@@ -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 5869813deb4dc22c0933e6254074d85fd4fb0890..dd7d3476f4f5bf0fa964009287e0f620edf83f62 100644 (file)
--- 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);
+}