From 212ef73f1ce8cb30ccba1a98085b3c315770a453 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 11 Sep 2018 15:58:57 -0400 Subject: [PATCH] added logic to expand path on save to absolute path --- lib/x11.c | 1 + tide.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/x11.c b/lib/x11.c index 9aecb7f..95d66dc 100644 --- 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 9ab21e3..03e4a1a 100644 --- 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); -- 2.49.0