]> git.mdlowis.com Git - projs/tide.git/commitdiff
added shortcut to fuzzy find a ctag symbol
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 3 Dec 2016 15:08:52 +0000 (10:08 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 3 Dec 2016 15:08:52 +0000 (10:08 -0500)
xedit.c
xtagpick

diff --git a/xedit.c b/xedit.c
index df10da7c2ac29056efc931ad279b1b298c537b42..81abc1cc8381b6366f831787190909ef8cccc238 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -49,6 +49,7 @@ static void search(void);
 static void execute(void);
 static void find(char* arg);
 static void open_file(void);
+static void pick_ctag(void);
 static void goto_ctag(void);
 
 // Tag/Cmd Execution
@@ -146,7 +147,7 @@ static KeyBinding Bindings[] = {
     { ModCtrl, 'f',        search       },
     { ModCtrl, 'd',        execute      },
     { ModCtrl, 'o',        open_file    },
-    //{ ModCtrl, 'p',        pick_ctag    },
+    { ModCtrl, 'p',        pick_ctag    },
     { ModCtrl, 'g',        goto_ctag    },
 };
 
@@ -513,28 +514,34 @@ static void open_file(void) {
     free(file);
 }
 
-static void goto_ctag(void) {
-    char* str = view_getctx(currview());
-    if (str) {
-        size_t line = strtoul(str, NULL, 0);
-        if (line) {
-            view_setln(getview(EDIT), line);
+static void pick_symbol(char* symbol) {
+    PickTagCmd[2] = symbol;
+    char* pick = cmdread(PickTagCmd, NULL);
+    if (pick) {
+        Buf* buf = getbuf(EDIT);
+        if (buf->path && 0 == strncmp(buf->path, pick, strlen(buf->path))) {
+            view_setln(getview(EDIT), strtoul(strrchr(pick, ':')+1, NULL, 0));
             Focused = EDIT;
         } else {
-            PickTagCmd[2] = str;
-            char* pick = cmdread(PickTagCmd, NULL);
-            if (pick) {
-                Buf* buf = getbuf(EDIT);
-                if (0 == strncmp(buf->path, pick, strlen(buf->path))) {
-                    view_setln(getview(EDIT), strtoul(strrchr(pick, ':')+1, NULL, 0));
-                    Focused = EDIT;
-                } else {
-                    OpenCmd[1] = pick;
-                    cmdrun(OpenCmd, NULL);
-                }
+            if (!buf->path && !buf->modified) {
+                view_init(getview(EDIT), pick);
+            } else {
+                OpenCmd[1] = chomp(pick);
+                cmdrun(OpenCmd, NULL);
             }
         }
     }
+}
+
+static void pick_ctag(void) {
+    pick_symbol(NULL);
+}
+
+static void goto_ctag(void) {
+    char* str = view_getctx(currview());
+    if (str) {
+        pick_symbol(str);
+    }
     free(str);
 }
 
index 15c4d06c4fdb50d5a972bc022b99decc3149653b..712bff818a22f17b28aa9003f47efe3b1b4df96b 100755 (executable)
--- a/xtagpick
+++ b/xtagpick
@@ -2,9 +2,18 @@
 TAGFILE="$1"
 TAG="$2"
 
-if [ "" == "$TAG" ] || [ "" == "$TAGFILE" ]; then
-    echo "Usage: $0 TAGFILE TAG"
+usage(){
+    echo "Usage: $0 TAGFILE [TAG]"
     exit 1
+}
+
+if [ "" == "$TAGFILE" ]; then
+    usage
+fi
+
+if [ "" == "$TAG" ]; then
+    TAG=$(cat tags | grep -v '^!' | cut -f1 | uniq | xpick)
+    [ "" == "$TAG" ] && exit
 fi
 
 awk -v TAG="$TAG" '