]> git.mdlowis.com Git - projs/tide.git/commitdiff
ignore warnings about initializers and move logic for opening files from registrar...
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 11 Dec 2018 04:08:42 +0000 (23:08 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 11 Dec 2018 04:08:42 +0000 (23:08 -0500)
TODO.md
config.h
config.mk
src/edit.c
src/pick.c
src/registrar.c

diff --git a/TODO.md b/TODO.md
index e26d92b3cd4fd1e64f3737b8d7260fca0cd8e55e..ea22584cff6c873e40e6306f1330541df27b1cf5 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -2,11 +2,11 @@
 
 ## STAGING
 
+* registrar doesnt match open windows when new file created and is then opened for edit or line number
+* fetch should stuff match strings in environment variables instead of evaling
 * registrar should remove invalid windows from registry when detected
 * tide should re-register with the registrar when a new registrar is launched
 * edit command should have a force option to launch tide without registrar notification
-* edit command should launch tide instead of registrar
-* fetch should stuff match strings in environment variables instead of evaling
 * Line - Get the current line number(s) containing the selection
 * gap buffer does not handle UTF-8 currently
 
@@ -14,7 +14,6 @@
 
 * refactor selection handling to avoid swapping manually (use buf_selbeg and buf_selend)
 * encode EOL setting in log entries?
-* centering logic in view.c seems slightly broken
 
 ## BACKLOG
 
index 3e71db8ee0b4b513e479eb1b81f3e55f1b46fff4..65c73f28b3ccf227e83cf295b6251c8e08f84bfe 100644 (file)
--- a/config.h
+++ b/config.h
@@ -90,11 +90,10 @@ Rule* BuiltinRules[] = {
     (Rule[]){ /* Match URLS and open them with the browser */
         { ISSET, "BROWSER", NULL },
         { MATCHES, "data", "^(https?|ftp)://.*" },
-        { LAUNCH, "$BROWSER $0", NULL },
+        { LAUNCH, "$BROWSER \"$0\"", NULL },
         { COMPLETE, NULL, NULL }
     },
     (Rule[]){ /* Open files with addresses in the editor */
-        { ISSET, "EDITOR", NULL },
         { MATCHES, "data", "^([^:]+):([0-9]+)" },
         { ISFILE, "$1", NULL },
         { LAUNCH, "edit \"$0\"", NULL },
@@ -103,23 +102,21 @@ Rule* BuiltinRules[] = {
     (Rule[]){ /* If it's an existing text file, open it with editor */
         { ISSET, "EDITOR", NULL },
         { ISFILE, "$data", NULL },
-        { EXEC, "file --mime '$file' | grep -q 'text/'", NULL },
-        { LAUNCH, "$EDITOR '$file'", NULL },
+        { EXEC, "file --mime \"$file\" | grep -q 'text/'", NULL },
+        { LAUNCH, "edit \"$file\"", NULL },
         { COMPLETE, NULL, NULL }
     },
     (Rule[]){ /* Look it up in ctags database */
-        { ISSET, "EDITOR", NULL },
         { ISFILE, "tags", NULL },
         { EXEC, "grep -q '^$data\\s\\+' tags", NULL },
         { LAUNCH, "picktag fetch tags '$data' | xargs -r edit", NULL },
         { COMPLETE, NULL, NULL }
     },
     (Rule[]){ /* Look up .c or .h files in Code/ */
-        { ISSET, "EDITOR", NULL },
         { MATCHES, "data", "\\.[ch]$" },
         { ISDIR, "Code", NULL },
         { EXEC, "[[ $(find Code -type f -name '*$data') ]]", NULL },
-        { LAUNCH, "find Code -type f -name '*$data' | xargs -r $EDITOR", NULL },
+        { LAUNCH, "find Code -type f -name '*$data' | xargs -r edit", NULL },
         { COMPLETE, NULL, NULL }
     },
     (Rule[]){ /* If it's an existing directory, open it with system default */
index 6c8014528980a61f3b05cbda44effd6441eb2bf9..f203e4f00c9302fb810c7efc0f6eb77b2171c0c4 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -22,6 +22,7 @@ CFLAGS  = -g -MMD $(INCS)
 CFLAGS += --std=c99 -pedantic
 CFLAGS += -Wall -Wextra
 CFLAGS += -Werror
+CFLAGS += -Wno-missing-field-initializers
 
 # Linker Setup
 LD = $(CC)
index 3ea9c0bf778302286ec3c7ac5a839278575ed3d5..0d8a04e5f483931e5548a92ee33c347f65e9c97b 100644 (file)
@@ -3,6 +3,8 @@
 #include <unistd.h>
 #include <stdc.h>
 
+#include "config.h"
+
 Atom XA_REGISTRAR, XA_OPEN, XA_DONE;
 
 int spawn(char* cmd) {
@@ -29,11 +31,7 @@ void prop_set(XConf* x, Window win, char* prop, char* value) {
 }
 
 void edit_file(XConf* x, Window registrar, char* path, char* addr) {
-    static char wdirbuf[32768] = {0};
-    char* wdir = getcwd(wdirbuf, sizeof(wdirbuf));
-    if (!wdir) return;
     char* rpath = realpath(path, NULL);
-    prop_set(x, x->self, "WDIR", wdir);
     prop_set(x, x->self, "FILE", (rpath ? rpath : path));
     prop_set(x, x->self, "ADDR", addr);
     free(rpath);
@@ -43,8 +41,17 @@ void edit_file(XConf* x, Window registrar, char* path, char* addr) {
     /* wait for the "done" message */
     for (XEvent e;;) {
         XNextEvent(x->display, &e);
-        if (e.type == ClientMessage && e.xclient.message_type == XA_DONE)
-            break;
+        if (e.type == ClientMessage) {
+            if (e.xclient.message_type == XA_DONE) {
+                break;
+            } else if (e.xclient.message_type == XA_OPEN) {
+                if (!fork()) {
+                    EditCmd[2] = addr, EditCmd[3] = path;
+                    exit(execvp(EditCmd[0], EditCmd));
+                }
+                break;
+            }
+        }
     }
 }
 
index b0edf245859be3df5533a346584d8f0bc99d45dd..b932e43cfa21f1373044a4048fc88eef856bc265 100644 (file)
@@ -172,4 +172,4 @@ int main(void) {
     if (vec_size(&Choices) && ChoiceIdx != SIZE_MAX)
         printf("%s\n", choice->string);
     return 0;
-}
\ No newline at end of file
+}
index 8b744b9f1a4ccc7135673ada00ba453b6e87b279..d0d6be562f14d0a030651685fe4d3ce4359bac3b 100644 (file)
@@ -8,16 +8,16 @@ typedef struct TWindow {
     char* path;
 } TWindow;
 
-Atom XA_REGISTRAR, XA_ADD, XA_DEL, XA_OPEN, XA_DONE, XA_WDIR, XA_FILE, XA_ADDR;
+Atom XA_REGISTRAR, XA_ADD, XA_DEL, XA_OPEN, XA_DONE;
 TWindow* Windows = NULL;
 
-char* readprop(XConf* x, Window win, Atom prop, size_t* length) {
-    Atom type;
+char* readprop(XConf* x, Window win, char* prop, size_t* length) {
+    Atom type, xa_prop = XInternAtom(x->display, prop, False);
     int format;
     unsigned long datalen, nleft;
     unsigned char* data = NULL;
     XGetWindowProperty(
-        x->display, win, prop, 0, -1, True, XA_STRING,
+        x->display, win, xa_prop, 0, -1, True, XA_STRING,
         &type, &format, &datalen, &nleft, &data);
     if (length) *length = datalen;
     return (char*)data;
@@ -27,7 +27,7 @@ void win_add(XConf* x, Window id) {
     TWindow* win = calloc(1, sizeof(TWindow));
     win->win = id;
     win->next = Windows;
-    win->path = readprop(x, id, XA_FILE, 0);
+    win->path = readprop(x, id, "FILE", 0);
     Windows = win;
 }
 
@@ -60,7 +60,7 @@ void win_send(XConf* x, Window from, Window to, int mask, char* atom, size_t val
     XFlush(x->display);
 }
 
-void win_open(XConf* x, char* wdir, char* path, char* addr) {
+void win_open(XConf* x, Window winid, char* path, char* addr) {
     if (!path) return;
     /* search for an existing window */
     for (TWindow* win = Windows; win; win = win->next) {
@@ -68,16 +68,13 @@ void win_open(XConf* x, char* wdir, char* path, char* addr) {
             win_send(x, win->win, x->root, SubstructureRedirectMask|SubstructureNotifyMask,  "_NET_ACTIVE_WINDOW", 0);
             XMapRaised(x->display, win->win);
             win_send(x, x->self, win->win, 0,  "GOTO", strtoul(addr, NULL, 0));
+            win_send(x, x->self, winid, 0,  "DONE", 0);
             return;
         }
     }
 
-    /* if we don't find it, spawn a new one */
-    if (!fork()) {
-        if (wdir) chdir(wdir);
-            EditCmd[2] = addr, EditCmd[3] = path;
-            exit(execvp(EditCmd[0], EditCmd));
-        }
+    /* if we don't find it, tell sender to spawn a new one */
+    win_send(x, x->self, winid, 0,  "OPEN", 0);
 }
 
 void selclear(XConf* x, XEvent* e) {
@@ -104,12 +101,9 @@ void propnotify(XConf* x, XEvent* e) {
         x->display, x->self, XA_OPEN, 0, -1, True, XA_WINDOW,
         &type, &format, &datalen, &nleft, &data);
     for (Window* win = (Window*)data; datalen && win && *win; win++, datalen--) {
-        char* wdir = readprop(x, *win, XA_WDIR, NULL);
-        char* file = readprop(x, *win, XA_FILE, NULL);
-        char* addr = readprop(x, *win, XA_ADDR, NULL);
-        win_open(x, wdir, file, (addr ? addr : "0"));
-        win_send(x, x->self, *win, 0,  "DONE", 0);
-        if(wdir) XFree(wdir);
+        char* file = readprop(x, *win, "FILE", NULL);
+        char* addr = readprop(x, *win, "ADDR", NULL);
+        win_open(x, *win, file, (addr ? addr : "0"));
         if(file) XFree(file);
         if(addr) XFree(addr);
     }
@@ -124,9 +118,6 @@ int main(void) {
     XA_DEL = XInternAtom(x.display, "DEL", 0);
     XA_OPEN = XInternAtom(x.display, "OPEN", 0);
     XA_DONE = XInternAtom(x.display, "DONE", 0);
-    XA_WDIR = XInternAtom(x.display, "WDIR", 0);
-    XA_FILE = XInternAtom(x.display, "FILE", 0);
-    XA_ADDR = XInternAtom(x.display, "ADDR", 0);
     x.eventfns[SelectionClear] = selclear;
     x.eventfns[ClientMessage] = clientmsg;
     x.eventfns[PropertyNotify] = propnotify;