]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added first pass at magic right-click
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 19 Jul 2017 16:28:13 +0000 (12:28 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 19 Jul 2017 16:28:13 +0000 (12:28 -0400)
Makefile
inc/edit.h
lib/exec.c
lib/utf8.c
lib/view.c
tide-hl.rb
tide.c

index 6793735a638dff321c8cb9bd2acb58b143b74b23..26abdbfc8efbd1325bb5445eea71d65b17904277 100644 (file)
--- 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
index e7dabff55f690c50a7b34f6bc4a247a0c001f605..2497411da30a7981cc80511ad91203eabfef0d7d 100644 (file)
@@ -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
index 8cd698d78116ab291c8b602150914ccfbcc80772..30476e4984c1f19b598d5d829dc04ec2602bf399 100644 (file)
@@ -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) {
index 184340ec53f73b5dc565fd1340e92ab880be52ba..379d396d00001b3909c3566cc9bf41c350edc49c 100644 (file)
@@ -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) {
index eee19b71bb2d34dcf323bd0b20f9d80492624a64..c0124fc32b7034c13f3e2040dc76504a9b52e8c0 100644 (file)
@@ -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);
index 3d7a53b236cd5c36ae9fcd80965480d8afc28b43..fa887a89370e7b593adbffbcd6d0de3129cf6b4b 100755 (executable)
@@ -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 a9e34cc8cb129a1ae3b91b4d6efff05117584395..b4951fa8d7fa0073e310e9b4126376117d1e7a25 100644 (file)
--- 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);
         }
     }
 }