From: Michael D. Lowis Date: Wed, 19 Jul 2017 16:28:13 +0000 (-0400) Subject: Added first pass at magic right-click X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=6bd4ef4d3cec88004e1610e5f3a2421d69d03d6e;p=projs%2Ftide.git Added first pass at magic right-click --- diff --git a/Makefile b/Makefile index 6793735..26abdbf 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ install: all mkdir -p $(PREFIX)/bin cp -f tide $(PREFIX)/bin cp -f tide-hl.rb $(PREFIX)/bin + cp -f tide-fetch.rb $(PREFIX)/bin cp -f pick $(PREFIX)/bin cp -f xcpd $(PREFIX)/bin cp -f pickfile $(PREFIX)/bin @@ -49,6 +50,7 @@ install: all uninstall: rm -f $(PREFIX)/bin/tide rm -f $(PREFIX)/bin/tide-hl.rb + rm -f $(PREFIX)/bin/tide-fetch.rb rm -f $(PREFIX)/bin/pick rm -f $(PREFIX)/bin/xcpd rm -f $(PREFIX)/bin/pickfile diff --git a/inc/edit.h b/inc/edit.h index e7dabff..2497411 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -188,7 +188,7 @@ Row* view_getrow(View* view, size_t row); void view_byrune(View* view, int move, bool extsel); void view_byword(View* view, int move, bool extsel); void view_byline(View* view, int move, bool extsel); -char* view_fetch(View* view, size_t row, size_t col); +char* view_fetch(View* view, size_t row, size_t col, bool (*isword)(Rune)); bool view_findstr(View* view, int dir, char* str); void view_insert(View* view, bool indent, Rune rune); void view_delete(View* view, int dir, bool byword); @@ -225,7 +225,7 @@ Rune view_getrune(View* view); *****************************************************************************/ bool exec_reap(void); void exec_job(char** cmd, char* data, size_t ndata, View* dest); -void exec_cmd(char** cmd, char* text, char** out, char** err); +int exec_cmd(char** cmd, char* text, char** out, char** err); int exec_spawn(char** cmd, int* in, int* out); /* Pseudo-Terminal Handling diff --git a/lib/exec.c b/lib/exec.c index 8cd698d..30476e4 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -90,16 +90,16 @@ void exec_job(char** cmd, char* data, size_t ndata, View* dest) { } } -void exec_cmd(char** cmd, char* text, char** out, char** err) { +int exec_cmd(char** cmd, char* text, char** out, char** err) { Proc proc; if (execute(cmd, &proc) < 0) { perror("failed to execute"); - return; + return -1; } /* send the input to stdin of the command */ if (text && write(proc.in, text, strlen(text)) < 0) { perror("failed to write"); - return; + return -1; } close(proc.in); /* read the stderr of the command */ @@ -109,7 +109,9 @@ void exec_cmd(char** cmd, char* text, char** out, char** err) { if (out) *out = fdgets(proc.out); close(proc.out); /* wait for the process to finish */ - waitpid(proc.pid, NULL, 0); + int status; + waitpid(proc.pid, &status, 0); + return status; } int exec_spawn(char** cmd, int* in, int* out) { @@ -167,7 +169,6 @@ static void recv_data(int fd, void* data) { Rcvr* rcvr = data; Job* job = rcvr->job; View* view = rcvr->view; - Buf* buf = &(rcvr->view->buffer); Sel sel = view->selection; if (fd >= 0) { diff --git a/lib/utf8.c b/lib/utf8.c index 184340e..379d396 100644 --- a/lib/utf8.c +++ b/lib/utf8.c @@ -114,7 +114,7 @@ bool rissigil(Rune r) { } bool risfile(Rune r) { - return (risword(r) || r == '/' || r == '.'); + return (risword(r) || r == '/' || r == '.' || r == ':'); } bool riscmd(Rune r) { diff --git a/lib/view.c b/lib/view.c index eee19b7..c0124fc 100644 --- a/lib/view.c +++ b/lib/view.c @@ -178,7 +178,7 @@ size_t view_selsize(View* view) { return num_selected(view->selection); } -char* view_fetch(View* view, size_t row, size_t col) { +char* view_fetch(View* view, size_t row, size_t col, bool (*isword)(Rune)) { char* str = NULL; size_t off = getoffset(view, row, col); if (off != SIZE_MAX) { @@ -186,7 +186,7 @@ char* view_fetch(View* view, size_t row, size_t col) { if (in_selection(view->selection, off)) { sel = view->selection; } else { - buf_getword(&(view->buffer), riscmd, &sel); + buf_getword(&(view->buffer), isword, &sel); sel.end++; } str = view_getstr(view, &sel); diff --git a/tide-hl.rb b/tide-hl.rb index 3d7a53b..fa887a8 100755 --- a/tide-hl.rb +++ b/tide-hl.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby if not ARGV[0] then - $stderr.puts "Usage: tide-hl [FILE]" + $stderr.puts "Usage: tide-hl.rb [FILE]" exit 1 end @@ -136,7 +136,7 @@ end language "Ruby" do keywords = Set.new %w[ - if not then else elsif end def do exit nil + if not then else elsif end def do exit nil begin rescue raise pass class goto break return continue case default switch while for ] diff --git a/tide.c b/tide.c index a9e34cc..b4951fa 100644 --- a/tide.c +++ b/tide.c @@ -35,6 +35,9 @@ 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[] = { "tide-fetch.rb", NULL, NULL }; + /* Tag/Cmd Execution ******************************************************************************/ static Tag* tag_lookup(char* cmd) { @@ -197,7 +200,7 @@ void onmousemiddle(WinRegion id, bool pressed, size_t row, size_t col) { if (win_btnpressed(MouseLeft)) { cut(); } else { - char* str = view_fetch(win_view(id), row, col); + char* str = view_fetch(win_view(id), row, col, riscmd); if (str) exec(str); free(str); } @@ -208,12 +211,18 @@ void onmouseright(WinRegion id, bool pressed, size_t row, size_t col) { if (win_btnpressed(MouseLeft)) { paste(); } else { - SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1); - free(SearchTerm); - SearchTerm = view_fetch(win_view(id), row, col); - if (view_findstr(win_view(EDIT), SearchDir, SearchTerm)) { - win_setregion(EDIT); - win_warpptr(EDIT); + char* text = view_fetch(win_view(id), row, col, risfile); + FetchCmd[1] = text; + if (exec_cmd(FetchCmd, NULL, NULL, NULL) != 0) { + SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1); + free(SearchTerm); + SearchTerm = view_fetch(win_view(id), row, col, risfile); + if (view_findstr(win_view(EDIT), SearchDir, SearchTerm)) { + win_setregion(EDIT); + win_warpptr(EDIT); + } + } else { + free(text); } } }