]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to expand path on save to absolute path
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 11 Sep 2018 19:58:57 +0000 (15:58 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 11 Sep 2018 19:58:57 +0000 (15:58 -0400)
lib/x11.c
tide.c

index 9aecb7fd77b54d11bc8bacb38bbb62b34137d665..95d66dc5e45782828a20e688732ed628a211ea4d 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -562,6 +562,7 @@ void win_title(char* path) {
 }
 
 void win_prop_set(char* xname, char* ename, char* value) {
+    if (!value) return;
     Atom propname = XInternAtom(X.display, xname, 0);
     XChangeProperty(X.display, X.self, propname, XA_STRING, 8, PropModeReplace,
         (const unsigned char *)value, strlen(value));
diff --git a/tide.c b/tide.c
index 9ab21e36ccf06dc72c9811a95903c556bd0a7d1b..03e4a1a985eff8584b04c0aa53dde9d5955ffe7f 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -262,15 +262,19 @@ static void put(char* arg) {
     if (!arg) arg = view->buffer.path;
     if (!arg) return;
     char* path = realpath(arg, NULL);
+    if (!path) path = strdup(arg);
     free(view->buffer.path);
     view->buffer.path = path;
     buf_save(&(view->buffer));
-    win_title(path);
-    win_prop_set("TIDE_FILE", "file", path);
-}
-
-static void save(char* arg) {
-    put(NULL);
+    if (view->buffer.status == NORMAL) {
+        char* path = realpath(view->buffer.path, NULL);
+        if (path) {
+            free(view->buffer.path);
+            view->buffer.path = path;
+        }
+    }
+    win_title(view->buffer.path);
+    win_prop_set("TIDE_FILE", "file", view->buffer.path);
 }
 
 static void get(char* arg) {
@@ -415,7 +419,7 @@ static KeyBinding Bindings[] = {
     { ModCtrl, 'e', cursor_eol  },
 
     /* Standard Text Editing Shortcuts */
-    { ModCtrl, 's', save        },
+    { ModCtrl, 's', put         },
     { ModCtrl, 'z', undo        },
     { ModCtrl, 'y', redo        },
     { ModCtrl, 'x', cut         },
@@ -486,6 +490,7 @@ int main(int argc, char** argv) {
     /* if we still have args left we're going to open it in this instance */
     if (*argv) {
         char* path = realpath(*argv, NULL);
+        if (!path) path = strdup(*argv); // if  file doesnt exist, use the original name
         view_init(win_view(EDIT), path);
         win_title(path);
         win_prop_set("TIDE_FILE", "file", path);