]> git.mdlowis.com Git - projs/tide.git/commitdiff
Execute almost all commands in the backgground now and route ctags and file opening...
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 28 Jul 2017 13:00:43 +0000 (09:00 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 28 Jul 2017 13:00:43 +0000 (09:00 -0400)
pickfile
picktag
tide.c

index 82202a4220263431853ed5636bb633ae899cefe1..495d49a8e953d8949cb7720a368b3c9f328dd8b2 100755 (executable)
--- a/pickfile
+++ b/pickfile
@@ -5,4 +5,4 @@ if [ "$#" -ne 1 ]; then
 fi
 
 export PICKTITLE="Pick File ($PWD)"
-find $1 -not -path '*/\.*' -type f | sed "s|^\./||" | pick
+find $1 -not -path '*/\.*' -type f | sed "s|^\./||" | pick | xargs -r tide
diff --git a/picktag b/picktag
index 034332268c6aa8c6e6e065ed568c8b2f7c612225..68a0b977d66162e0e96d4118c3d51e3d7ffcb8b0 100755 (executable)
--- a/picktag
+++ b/picktag
@@ -21,7 +21,7 @@ printtags(){
 }
 
 print(){
-    printtags | pick "$TAG"
+    printf "%s" "$(printtags | pick "$TAG")"
 }
 
 fetch(){
@@ -38,7 +38,7 @@ fetch(){
         gsub(/\*/, "\\*", matchstr)
         print "grep -Hn", matchstr, $2, "| cut -d: -f1,2"
     }
-    ' "$TAGFILE" | /bin/sh | pick
+    ' "$TAGFILE" | /bin/sh | pick | xargs -r tide
 }
 
 export PICKTITLE="Pick CTag ($PWD)"
@@ -47,5 +47,3 @@ case "$ACTION" in
     "fetch") fetch ;;
     *) usage ;;
 esac
-
-
diff --git a/tide.c b/tide.c
index 6d0ea9ede7fff21b589991589ddf955231561990..3eaf8044c3e743513fdc00d0baf1732407e0bdc2 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -26,18 +26,20 @@ char* ShellCmd[] = { NULL, "-c", NULL, NULL };
 /* Sed command used to execute commands marked with ':' sigil */
 char* SedCmd[] = { "sed", "-e", NULL, NULL };
 
-/* Fuzzy Picker for files in the current directory and subdirectories */
-char* PickFileCmd[] = { "pickfile", ".", NULL };
-
 /* Fuzzy picker for tags in a ctags database. */
 char* PickTagCmd[] = { "picktag", NULL, "tags", NULL, NULL };
 
-/* Open a new instance of the editor */
-char* OpenCmd[] = { "tide", NULL, NULL };
-
 /* Try to fetch the text with tide-fetch */
 char* FetchCmd[] = { "tfetch", NULL, NULL };
 
+#define CMD_TIDE     "!tide"
+#define CMD_PICKFILE "!pickfile ."
+#define CMD_TO_DOS   "|unix2dos"
+#define CMD_TO_UNIX  "|dos2unix"
+#define CMD_COMPLETE "<picktag print tags"
+#define CMD_GOTO_TAG "!picktag fetch tags"
+#define CMD_FETCH    "tfetch"
+
 /* Tag/Cmd Execution
  ******************************************************************************/
 static Tag* tag_lookup(char* cmd) {
@@ -87,6 +89,13 @@ static void cmd_exec(char* cmd) {
         exec_job(execcmd, input, len, (op != '<' ? curr : edit));
 }
 
+static void cmd_execwitharg(char* cmd, char* arg) {
+    cmd = (arg ? strmcat(cmd, " '", arg, "'", 0) : strmcat(cmd));
+    cmd_exec(cmd);
+    free(cmd);
+}
+
+
 static void exec(char* cmd) {
     /* skip leading space */
     for (; *cmd && isspace(*cmd); cmd++);
@@ -97,10 +106,7 @@ static void exec(char* cmd) {
         while (*cmd && !isspace(*cmd++));
         tag_exec(tag, (*cmd ? stringdup(cmd) : NULL));
     } else if (pty_active()) {
-        char* arg = view_getstr(win_view(TAGS), NULL);
-        if (!arg) arg = view_getstr(win_view(EDIT), NULL);
-        pty_send(cmd, arg);
-        free(arg);
+        pty_send(cmd, NULL);
     } else {
         cmd_exec(cmd);
     }
@@ -278,41 +284,11 @@ static void find(char* arg) {
 }
 
 static void open_file(void) {
-    char* file = NULL;
-    exec_cmd(PickFileCmd, NULL, &file, NULL);
-    if (file) {
-        file = chomp(file);
-        if ((!win_buf(EDIT)->path || x11_keymodsset(ModShift)) &&
-            !win_buf(EDIT)->modified) {
-            view_init(win_view(EDIT), file, ondiagmsg);
-        } else {
-            OpenCmd[1] = file;
-            exec_job(OpenCmd,0,0,0);
-        }
-    }
-    free(file);
+    cmd_exec(CMD_PICKFILE);
 }
 
 static void pick_symbol(char* symbol) {
-    PickTagCmd[1] = "fetch";
-    PickTagCmd[3] = symbol;
-    char* pick = NULL;
-    exec_cmd(PickTagCmd, NULL, &pick, NULL);
-    if (pick) {
-        Buf* buf = win_buf(EDIT);
-        if (buf->path && 0 == strncmp(buf->path, pick, strlen(buf->path))) {
-            view_setln(win_view(EDIT), strtoul(strrchr(pick, ':')+1, NULL, 0));
-            win_setregion(EDIT);
-        } else {
-            if (!buf->path && !buf->modified) {
-                view_init(win_view(EDIT), pick, ondiagmsg);
-            } else {
-                OpenCmd[1] = chomp(pick);
-                exec_job(OpenCmd,0,0,0);
-
-            }
-        }
-    }
+    cmd_execwitharg(CMD_GOTO_TAG, symbol);
 }
 
 static void pick_ctag(void) {
@@ -323,13 +299,7 @@ static void complete(void) {
     View* view = win_view(FOCUSED);
     buf_getword(&(view->buffer), risword, &(view->selection));
     view->selection.end = buf_byrune(&(view->buffer), view->selection.end, RIGHT);
-    PickTagCmd[1] = "print";
-    PickTagCmd[3] = view_getstr(view, NULL);
-    char* pick = NULL;
-    exec_cmd(PickTagCmd, NULL, &pick, NULL);
-    if (pick)
-        view_putstr(view, chomp(pick));
-    free(PickTagCmd[3]);
+    cmd_execwitharg(CMD_COMPLETE, view_getstr(view, NULL));
 }
 
 static void jump_to(char* arg) {
@@ -378,11 +348,11 @@ static void eol_mode(void) {
     int crlf = win_buf(EDIT)->crlf;
     win_buf(EDIT)->crlf = !crlf;
     win_buf(TAGS)->crlf = !crlf;
-    exec(crlf ? "|dos2unix" : "|unix2dos");
+    cmd_exec(crlf ? CMD_TO_UNIX : CMD_TO_DOS);
 }
 
 static void new_win(void) {
-    cmd_exec("!tide");
+    cmd_exec(CMD_TIDE);
 }
 
 static void newline(void) {
@@ -639,8 +609,7 @@ int main(int argc, char** argv) {
     /* open all but the last file in new instances */
     for (argc--, argv++; argc > 1; argc--, argv++) {
         if (!strcmp(*argv, "--")) break;
-        OpenCmd[1] = *argv;
-        exec_job(OpenCmd,0,0,0);
+        cmd_execwitharg(CMD_TIDE, *argv);
     }
 
     /* if we still have args left we're going to open it in this instance */