]> git.mdlowis.com Git - projs/tide.git/commitdiff
added a force flag to edit command to force launch tide without checking registrar
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 31 Dec 2018 21:30:24 +0000 (16:30 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 31 Dec 2018 21:30:24 +0000 (16:30 -0500)
TODO.md
src/edit.c
src/registrar.c

diff --git a/TODO.md b/TODO.md
index cee6d02962eb81c850135d0ebd4496c08b8e1ac6..43cc9b0870cfbcf759f1a7441f5a6898ae385559 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -15,7 +15,7 @@
 * tide: should re-register with the registrar when a new registrar is launched
 * tide: Line - Get the current line number(s) containing the selection
 * tide: gap buffer does not handle UTF-8 currently
-* edit: should have a force option to launch tide without registrar notification
+* edit: hangs after launching an empty tide instance then trying to open already open file
 
 ## BACKLOG
 
index 0d8a04e5f483931e5548a92ee33c347f65e9c97b..4c925986bdc9a238bf871c0bc826bf3d49279a33 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "config.h"
 
+char* ARGV0;
 Atom XA_REGISTRAR, XA_OPEN, XA_DONE;
 
 int spawn(char* cmd) {
@@ -30,7 +31,7 @@ void prop_set(XConf* x, Window win, char* prop, char* value) {
         (const unsigned char *)value, strlen(value)+1);
 }
 
-void edit_file(XConf* x, Window registrar, char* path, char* addr) {
+void edit_file(XConf* x, Window registrar, char* path, char* addr, int force) {
     char* rpath = realpath(path, NULL);
     prop_set(x, x->self, "FILE", (rpath ? rpath : path));
     prop_set(x, x->self, "ADDR", addr);
@@ -38,41 +39,47 @@ void edit_file(XConf* x, Window registrar, char* path, char* addr) {
     XChangeProperty(
         x->display, registrar, XA_OPEN, XA_WINDOW, 32, PropModeAppend,
         (const unsigned char *)&(x->self), 1);
-    /* wait for the "done" message */
-    for (XEvent e;;) {
-        XNextEvent(x->display, &e);
-        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));
+    EditCmd[2] = addr, EditCmd[3] = path;
+    if (force) {
+        if (!fork())
+            exit(execvp(EditCmd[0], EditCmd));
+    } else {
+        /* wait for the "done" message */
+        for (XEvent e;;) {
+            XNextEvent(x->display, &e);
+            if (e.type == ClientMessage) {
+                if (e.xclient.message_type == XA_DONE) {
+                    break;
+                } else if (e.xclient.message_type == XA_OPEN) {
+                    if (!fork())
+                        exit(execvp(EditCmd[0], EditCmd));
+                    break;
                 }
-                break;
             }
         }
     }
 }
 
 int main(int argc, char** argv) {
-    XConf x = {0};
-    x11_init(&x);
-    x11_mkwin(&x, 1, 1, 0);
-    XA_REGISTRAR = XInternAtom(x.display, "TIDE_REGISTRAR", PropertyChangeMask);
-    XA_OPEN = XInternAtom(x.display, "OPEN", 0);
-    XA_DONE = XInternAtom(x.display, "DONE", 0);
-    Window registrar = start_registrar(&x);
-    if (argc == 1) {
+    int force = 0;
+    OPTBEGIN { case 'f': force = 1; break; } OPTEND;
+    if (argc == 0) {
         spawn("tide");
     } else {
+        XConf x = {0};
+        x11_init(&x);
+        x11_mkwin(&x, 1, 1, 0);
+        XA_REGISTRAR = XInternAtom(x.display, "TIDE_REGISTRAR", PropertyChangeMask);
+        XA_OPEN = XInternAtom(x.display, "OPEN", 0);
+        XA_DONE = XInternAtom(x.display, "DONE", 0);
+        Window registrar = start_registrar(&x);
         /* Loop over files and send an OPEN message for each one. */
-        for (int i = 1; i < argc; i++) {
+        for (int i = 0; i < argc; i++) {
             char* addr = strrchr(argv[i], ':');
             if (addr) *addr = '\0', addr++;
-            edit_file(&x, registrar, argv[i], (addr ? addr : "0"));
+            edit_file(&x, registrar, argv[i], (addr ? addr : "0"), force);
         }
+        XSync(x.display, False);
     }
-    XSync(x.display, False);
     return 0;
 }
index fc0c4edf402f7723e340d44955652823b92f8a6d..9b69ee7dc6664f4a24eb0ffceb8b7df3d17afc17 100644 (file)
@@ -109,8 +109,7 @@ void propnotify(XConf* x, XEvent* e) {
     }
 }
 
-int daemonize(void)
-{
+int daemonize(void) {
     int status;
     /* fork into the background first */
     if ((status = fork()) < 0)