]> git.mdlowis.com Git - projs/tide.git/commitdiff
tweaked tctl and tide to support specifying line address as part of path
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 13 Aug 2017 00:49:16 +0000 (20:49 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 13 Aug 2017 00:49:16 +0000 (20:49 -0400)
lib/win.c
tctl.c

index 9951b49a791a2d85b6b32399aca362509eee89ea..2e25d3c8f245ce08883012d6b107bd111cf92013 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -74,6 +74,7 @@ static void set_path_prop(char* path) {
 void win_load(char* path) {
     View* view = win_view(EDIT);
     view_init(view, path, view->buffer.errfn);
+    path = view->buffer.path;
     if (path) set_path_prop(path);
 }
 
diff --git a/tctl.c b/tctl.c
index fa84f810a6ab5ee91a25b9283d7f83f03c91d968..f24e5e93fead63c513048605418fde754c2d4d8f 100644 (file)
--- a/tctl.c
+++ b/tctl.c
@@ -23,7 +23,8 @@ static void* prop_get(Window win, char* propname, Atom type, unsigned long* nite
 static void prop_set(Window win, char* propname, Atom type, int format, void* items, unsigned long nitems);
 static void edit(char* path);
 static Window win_byfile(char* path);
-static void focus_window(Window w);
+static void focus_window(Window w, char* addr);
+static void get_abspath(char* path, char** abspath, char** addr);
 
 /* Main Routine
  ******************************************************************************/
@@ -37,14 +38,17 @@ int main(int argc, char** argv) {
 
     for (int i = 1; i < argc; i++) {
         bool last = (i == argc-1);
-        char* path = realpath(argv[i], NULL);
-        if (!path) path = argv[i];
+        char *orig = argv[i], *path = NULL, *addr = NULL;
+        get_abspath(orig, &path, &addr);
+
         Window win = win_byfile(path);
         if (!win)
-            edit(path);
+            edit(argv[i]);
         else if (last)
-            focus_window(win);
+            focus_window(win, addr);
+        free(path);
     }
+
        XFlush(X.display);
     return 0;
 }
@@ -111,7 +115,7 @@ static Window win_byfile(char* path) {
     return (Window)0;
 }
 
-static void focus_window(Window w) {
+static void focus_window(Window w, char* addr) {
        XEvent ev = {0};
        ev.xclient.type = ClientMessage;
     ev.xclient.send_event = True;
@@ -123,3 +127,13 @@ static void focus_window(Window w) {
     XMapRaised(X.display, w);
     XFlush(X.display);
 }
+
+void get_abspath(char* path, char** abspath, char** addr) {
+       path = stringdup(path);
+       char* faddr = strrchr(path, ':');
+       if (faddr) *(faddr++) = '\0';
+    char* rpath = realpath(path, NULL);
+    if (!rpath) rpath = path;
+       *abspath = rpath, *addr = faddr;
+}
+