From fcf0cc8e54ff7eb3778270bb356414558bcf51c9 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 28 Jul 2017 09:00:43 -0400 Subject: [PATCH] Execute almost all commands in the backgground now and route ctags and file opening commands trhough the tfetch command. --- pickfile | 2 +- picktag | 6 ++--- tide.c | 75 +++++++++++++++++--------------------------------------- 3 files changed, 25 insertions(+), 58 deletions(-) diff --git a/pickfile b/pickfile index 82202a4..495d49a 100755 --- 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 0343322..68a0b97 100755 --- 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 6d0ea9e..3eaf804 100644 --- 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 "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 */ -- 2.49.0