]> git.mdlowis.com Git - projs/tide.git/commitdiff
added shortcut to complete tag using fuzzy picker
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 5 Mar 2017 00:45:45 +0000 (19:45 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 5 Mar 2017 00:45:45 +0000 (19:45 -0500)
TODO.md
lib/view.c
xedit.c
xpick.c
xtagpick

diff --git a/TODO.md b/TODO.md
index add30c8a0ca8baa2ef407dabbf795d056ff2bba0..d8e80fec013d638d05d9ff993eef8a99a82afe45 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -2,19 +2,18 @@
 
 Up Next:
 
-* Make Fn keys execute nth command in the tags buffer
 * check for file changes on save
 * check for file changes when window regains focus
 * Right click in tags region should search edit region
-* Add keyboard shortcut to highlight the thing under the cursor
 * 100% coverage with unit and unit-integration tests
 
 Tomorrow-ish:
 
+* Make Fn keys execute nth command in the tags buffer
 * selecting text should set PRIMARY x11 selection
 * Add a SaveAs tag that takes an argument for the filename to save as
 * Add a GoTo tag for ctags lookup and line number jump (or right click magic?) 
-* Add a ctrl+space shortcut to autocomplete ctag
+* Add keyboard shortcut to highlight the thing under the cursor
 * off by one error on scrolling up with wrapped lines
 * tab inserts dont coalesce like one would expect
 
index 76bee774795b9fd6b5ccece9d8946101c912469a..3c62e97bd9bb5ae4bda40cfc7bd69477d7fc8b08 100644 (file)
@@ -316,7 +316,8 @@ static void selcontext(View* view, Sel* sel) {
 
 void view_selword(View* view, size_t row, size_t col) {
     buf_loglock(&(view->buffer));
-    view_setcursor(view, row, col);
+    if (row != SIZE_MAX && col != SIZE_MAX)
+        view_setcursor(view, row, col);
     Sel sel = view->selection;
     buf_getword(&(view->buffer), risbigword, &(sel));
     sel.end++;
diff --git a/xedit.c b/xedit.c
index ea3899d1b0db24da0c150a348cf1aee58093c94f..c0cb86d5f63bc0ded179853b29c0266e92649d3a 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -17,7 +17,7 @@ typedef struct {
 static char* ShellCmd[] = { NULL, "-c", NULL, NULL };
 static char* SedCmd[] = { "sed", "-e", NULL, NULL };
 static char* PickFileCmd[] = { "xfilepick", ".", NULL };
-static char* PickTagCmd[] = { "xtagpick", "tags", NULL, NULL };
+static char* PickTagCmd[] = { "xtagpick", NULL, "tags", NULL, NULL };
 static char* OpenCmd[] = { "xedit", NULL, NULL };
 static Tag Builtins[];
 static int SearchDir = DOWN;
@@ -333,7 +333,8 @@ static void open_file(void) {
 }
 
 static void pick_symbol(char* symbol) {
-    PickTagCmd[2] = symbol;
+    PickTagCmd[1] = "fetch";
+    PickTagCmd[3] = symbol;
     char* pick = cmdread(PickTagCmd, NULL);
     if (pick) {
         Buf* buf = win_buf(EDIT);
@@ -355,6 +356,17 @@ static void pick_ctag(void) {
     pick_symbol(NULL);
 }
 
+static void complete(void) {
+    View* view = win_view(FOCUSED);
+    view_selword(view, SIZE_MAX, SIZE_MAX);
+    PickTagCmd[1] = "print";
+    PickTagCmd[3] = view_getstr(view, NULL);
+    char* pick = cmdread(PickTagCmd, NULL);
+    if (pick)
+        view_putstr(view, chomp(pick));
+    free(PickTagCmd[3]);
+}
+
 static void goto_ctag(void) {
     char* str = view_getctx(win_view(FOCUSED));
     if (str) {
@@ -482,6 +494,7 @@ static KeyBinding Bindings[] = {
     { ModCtrl,                 'n',        new_win      },
     { ModCtrl,                 '\n',       newline      },
     { ModCtrl|ModShift,        '\n',       newline      },
+    { ModCtrl,                 ' ',        complete     },
     { 0, 0, 0 }
 };
 
diff --git a/xpick.c b/xpick.c
index 181130dd300d5aa0639080df36d08218af4fed6b..8141d5b1729e2a3710e5a08fc51435d0c1d55ea7 100644 (file)
--- a/xpick.c
+++ b/xpick.c
@@ -197,9 +197,14 @@ static void keyboard_input(int mods, uint32_t key) {
 #ifndef TEST
 int main(int argc, char** argv) {
     load_choices();
+    buf_init(&Query);
+    if (argc >= 2) {
+        char* str = argv[1];
+        while (*str)
+            buf_insert(&Query, false, Pos++, *(str++));
+        score();
+    }
     if (vec_size(&Choices) > 1) {
-        /* initialize the filter edit buffer */
-        buf_init(&Query);
         /* initialize the display engine */
         x11_init(&Config);
         x11_dialog("pick", Width, Height);
index dbe515fab434e2111a1a306c65a45a01a466ed8d..eb59ed110f9dafd6ed178905eaf22cd0f89564dc 100755 (executable)
--- a/xtagpick
+++ b/xtagpick
@@ -1,28 +1,50 @@
 #!/bin/sh
-TAGFILE="$1"
-TAG="$2"
+ACTION="$1"
+TAGFILE="$2"
+TAG="$3"
 
 usage(){
-    echo "Usage: $0 TAGFILE [TAG]"
+    echo "Usage: $0 ACTION TAGFILE [TAG]"
+    echo ""
+    echo "Actions:"
+    echo "    fetch - Print the filename and line number of the selcted tag"
+    echo "    print - Print the selected tag"
     exit 1
 }
 
-if [ "" == "$TAGFILE" ]; then
+if [ "" == "$TAGFILE" ] || [ "" == "$ACTION" ]; then
     usage
 fi
 
-if [ "" == "$TAG" ]; then
-    TAG=$(cat tags | grep -v '^!' | cut -f1 | uniq | xpick)
-    [ "" == "$TAG" ] && exit
-fi
+printtags(){
+    cat "$TAGFILE" | grep -v '^!' | cut -f1 | uniq
+}
+
+print(){
+    printtags | xpick "$TAG"
+}
 
-awk -v TAG="$TAG" '
-BEGIN { FS = "[\t]+" }
-($1 == TAG) {
-    matchstr = $3
-    sub(/^\//, "\"", matchstr)
-    sub(/\$?\/;"$/, "\"", matchstr)
-    gsub(/\*/, "\\*", matchstr)
-    print "grep -Hn", matchstr, $2, "| cut -d: -f1,2"
+fetch(){
+    if [ "" == "$TAG" ]; then
+        TAG=$(printtags | xpick)
+        [ "" == "$TAG" ] && exit
+    fi
+    awk -v TAG="$TAG" '
+    BEGIN { FS = "[\t]+" }
+    ($1 == TAG) {
+        matchstr = $3
+        sub(/^\//, "\"", matchstr)
+        sub(/\$?\/;"$/, "\"", matchstr)
+        gsub(/\*/, "\\*", matchstr)
+        print "grep -Hn", matchstr, $2, "| cut -d: -f1,2"
+    }
+    ' "$TAGFILE" | /bin/sh | xpick
 }
-' "$TAGFILE" | /bin/sh | xpick
+
+case "$ACTION" in
+    "print") print ;;
+    "fetch") fetch ;;
+    *) usage ;;
+esac
+
+