From: Michael D. Lowis Date: Fri, 28 Sep 2018 02:34:19 +0000 (-0400) Subject: hooked in tfetch logic for magic right click handling X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=efc45d088afa6e8176d936ceba36153938d68257;p=projs%2Ftide.git hooked in tfetch logic for magic right click handling --- diff --git a/TODO.md b/TODO.md index 3e3c28b..c2b03d8 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,10 @@ ## STAGING -* no magic right click +* selecting lines no longer works if cursor is on first char +* implement new version of tfetch +* implement tide registrar +* implement tctl command * implement mouse warping on search, jump to line, and focus change * gap buffer does not handle UTF-8 currently * mouse selection handling when mouse moves outside region diff --git a/inc/edit.h b/inc/edit.h index bffdbe0..bb1e8b8 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -172,6 +172,7 @@ bool job_poll(int ms); void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data); void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data); void job_start(char** cmd, char* data, size_t ndata, View* dest); +int job_run(char** cmd); /* Configuration Data *****************************************************************************/ @@ -186,7 +187,7 @@ enum { /* Color Names */ ClrCount }; -extern char *TagString, *Fonts[2]; +extern char *TagString, *Fonts[2], *FetchCmd[]; extern int Palette[ClrCount]; extern int WinWidth, WinHeight, ScrollWidth, Timeout, TabWidth, ScrollBy, ClickTime, CopyIndent, TrimOnSave, ExpandTabs, DosLineFeed; diff --git a/lib/config.c b/lib/config.c index 145bf83..db50379 100644 --- a/lib/config.c +++ b/lib/config.c @@ -4,7 +4,10 @@ #include #include +char* FetchCmd[] = { "tfetch", NULL, NULL }; + char* TagString = "Del Put Undo Redo | Font Tabs Eol | Find "; + char* Fonts[2] = { "Verdana:size=11", #ifdef __MACH__ diff --git a/lib/job.c b/lib/job.c index aac1b34..c54f6cc 100644 --- a/lib/job.c +++ b/lib/job.c @@ -80,7 +80,7 @@ static void job_process(int fd, int events) { job_finish(job); } -static int job_exec(char** cmd) { +static int job_exec(char** cmd, int* p_pid) { int pid, fds[2]; /* create the sockets */ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) @@ -100,6 +100,7 @@ static int job_exec(char** cmd) { } else { close(fds[1]); } + if (p_pid) *p_pid = pid; return fds[0]; } @@ -134,7 +135,7 @@ void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) { } void job_start(char** cmd, char* data, size_t ndata, View* dest) { - int fd = job_exec(cmd); + int fd = job_exec(cmd, 0); if (fd >= 0 && (data || dest)) { struct PipeData* pipedata = NULL; if (data) { @@ -148,3 +149,12 @@ void job_start(char** cmd, char* data, size_t ndata, View* dest) { close(fd); } } + +int job_run(char** cmd) { + int pid = -1, status = 0; + job_exec(cmd, &pid); + do { + waitpid(pid, &status, WUNTRACED|WCONTINUED); + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); + return WEXITSTATUS(status); +} diff --git a/lib/x11.c b/lib/x11.c index fac3632..6afd01a 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -237,10 +237,15 @@ static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) { if (PRESSED(MouseLeft)) { paste(NULL); } else { - SearchDir *= (win_keymodsset(ModShift) ? -1 : +1); - free(SearchTerm); - SearchTerm = view_fetch(win_view(id), row, col, risfile); - view_findstr(win_view(id), SearchDir, SearchTerm); + FetchCmd[1] = view_fetch(win_view(id), row, col, risfile); + if (job_run(FetchCmd) != 0) { + SearchDir *= (win_keymodsset(ModShift) ? -1 : +1); + free(SearchTerm); + SearchTerm = view_fetch(win_view(id), row, col, risfile); + view_findstr(win_view(EDIT), SearchDir, SearchTerm); + } else { + free(FetchCmd[1]); + } } } diff --git a/tide.c b/tide.c index 5b4277b..c6d7c3b 100644 --- a/tide.c +++ b/tide.c @@ -20,9 +20,6 @@ char* ShellCmd[] = { NULL, "-c", NULL, NULL }; /* Sed command used to execute commands marked with ':' sigil */ char* SedCmd[] = { "sed", "-e", 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_COMPLETE "