]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor refactoring
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 9 Apr 2018 01:29:11 +0000 (21:29 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 9 Apr 2018 01:29:11 +0000 (21:29 -0400)
inc/win.h
lib/x11.c
tide.c

index 51caae1951fbe0a73a457f78891e86bcf706666f..7651154523d3c433a904335d3c00a638c539aee9 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -32,7 +32,7 @@ View* win_view(WinRegion id);
 Buf* win_buf(WinRegion id);
 bool win_btnpressed(int btn);
 WinRegion win_getregion(void);
-bool win_setregion(WinRegion id);
+void win_setregion(WinRegion id);
 void win_setscroll(double offset, double visible);
 
 /* move these to x11.c when possible */
index fecfaf96670052e64c603e0e388ecf5f1f2f98e2..0a7354c5056317c23711016541de5709c848d5f9 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -166,11 +166,8 @@ WinRegion win_getregion(void) {
     return Focused;
 }
 
-bool win_setregion(WinRegion id) {
-    bool changed = true;
-    if (Focused != id && (id == TAGS || id == EDIT))
-        changed = true, Focused = id;
-    return changed;
+void win_setregion(WinRegion id) {
+    Focused = id;
 }
 
 View* win_view(WinRegion id) {
diff --git a/tide.c b/tide.c
index 9c4e75004c38d7d531a8fa97290ce038eda0ea67..3c1340efc1f6286aa6f6c78470863e0ee3ed7c38 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -29,10 +29,78 @@ char* FetchCmd[] = { "tfetch", NULL, NULL };
 #define CMD_TO_UNIX  "|dos2unix"
 #define CMD_COMPLETE "<picktag print tags"
 #define CMD_GOTO_TAG "!picktag fetch tags"
-#define CMD_FETCH    "tfetch"
 
-/******************************************************************************/
+/* Tag/Cmd Execution
+ ******************************************************************************/
+static Tag* tag_lookup(char* cmd) {
+    size_t len = 0;
+    Tag* tags = Builtins;
+    for (char* tag = cmd; *tag && !isspace(*tag); tag++, len++);
+    while (tags->tag) {
+        if (!strncmp(tags->tag, cmd, len))
+            return tags;
+        tags++;
+    }
+    return NULL;
+}
+
+static void tag_exec(Tag* tag, char* arg) {
+    /* if we didnt get an arg, find one in the selection */
+    if (!arg) arg = view_getstr(win_view(TAGS));
+    if (!arg) arg = view_getstr(win_view(EDIT));
+    /* execute the tag handler */
+    tag->action(arg);
+    free(arg);
+}
+
+static void cmd_exec(char* cmd) {
+    /* parse the command sigils */
+    char op = '\0', **execcmd = NULL;
+    if (*cmd == ':' || *cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>')
+        op = *cmd, cmd++;
+    execcmd = (op == ':' ? SedCmd : ShellCmd);
+    execcmd[2] = cmd;
 
+    /* get the selection that the command will operate on */
+    if (op && op != '<' && op != '!' && !view_selsize(win_view(EDIT)))
+        view_selectall(win_view(EDIT));
+    char* input = view_getstr(win_view(EDIT));
+    size_t len  = (input ? strlen(input) : 0);
+    View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED);
+
+    /* execute the job */
+    if (op == '!')
+        free(input), job_start(execcmd, NULL, 0, NULL);
+    else if (op == '>')
+        job_start(execcmd, input, len, tags);
+    else if (op == '|' || op == ':')
+        job_start(execcmd, input, len, edit);
+    else
+        job_start(execcmd, input, len, (op != '<' ? curr : edit));
+}
+
+static void cmd_execwitharg(char* cmd, char* arg) {
+    cmd = (arg ? strmcat(cmd, " '", arg, "'", 0) : strmcat(cmd));
+    cmd_exec(cmd);
+    free(cmd);
+}
+
+void exec(char* cmd) {
+    /* skip leading space */
+    for (; *cmd && isspace(*cmd); cmd++);
+    if (!*cmd) return;
+    /* see if it matches a builtin tag */
+    Tag* tag = tag_lookup(cmd);
+    if (tag) {
+        while (*cmd && !isspace(*cmd++));
+        tag_exec(tag, (*cmd ? stringdup(cmd) : NULL));
+    } else {
+        cmd_exec(cmd);
+    }
+}
+
+/* Keyboard and Tag Handlers
+ ******************************************************************************/
 static void select_line(char* arg) {
     View* view = win_view(FOCUSED);
     view_eol(view, false);
@@ -114,8 +182,6 @@ static void cursor_eol(char* arg) {
     view_eol(win_view(FOCUSED), false);
 }
 
-/******************************************************************************/
-
 static void cursor_mvlr(int dir) {
     bool extsel = x11_keymodsset(ModShift);
     if (x11_keymodsset(ModCtrl))
@@ -140,8 +206,6 @@ static void cursor_home_end(
         linefn(win_view(FOCUSED), extsel);
 }
 
-/******************************************************************************/
-
 static void cursor_home(char* arg) {
     cursor_home_end(view_bof, view_bol);
 }
@@ -190,77 +254,6 @@ static void redo(char* arg) {
     view_redo(win_view(FOCUSED));
 }
 
-/* Tag/Cmd Execution
- ******************************************************************************/
-static Tag* tag_lookup(char* cmd) {
-    size_t len = 0;
-    Tag* tags = Builtins;
-    for (char* tag = cmd; *tag && !isspace(*tag); tag++, len++);
-    while (tags->tag) {
-        if (!strncmp(tags->tag, cmd, len))
-            return tags;
-        tags++;
-    }
-    return NULL;
-}
-
-static void tag_exec(Tag* tag, char* arg) {
-    /* if we didnt get an arg, find one in the selection */
-    if (!arg) arg = view_getstr(win_view(TAGS));
-    if (!arg) arg = view_getstr(win_view(EDIT));
-    /* execute the tag handler */
-    tag->action(arg);
-    free(arg);
-}
-
-static void cmd_exec(char* cmd) {
-    /* parse the command sigils */
-    char op = '\0', **execcmd = NULL;
-    if (*cmd == ':' || *cmd == '!' || *cmd == '<' || *cmd == '|' || *cmd == '>')
-        op = *cmd, cmd++;
-    execcmd = (op == ':' ? SedCmd : ShellCmd);
-    execcmd[2] = cmd;
-
-    /* get the selection that the command will operate on */
-    if (op && op != '<' && op != '!' && !view_selsize(win_view(EDIT)))
-        view_selectall(win_view(EDIT));
-    char* input = view_getstr(win_view(EDIT));
-    size_t len  = (input ? strlen(input) : 0);
-    View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED);
-
-    /* execute the job */
-    if (op == '!')
-        free(input), job_start(execcmd, NULL, 0, NULL);
-    else if (op == '>')
-        job_start(execcmd, input, len, tags);
-    else if (op == '|' || op == ':')
-        job_start(execcmd, input, len, edit);
-    else
-        job_start(execcmd, input, len, (op != '<' ? curr : edit));
-}
-
-static void cmd_execwitharg(char* cmd, char* arg) {
-    cmd = (arg ? strmcat(cmd, " '", arg, "'", 0) : strmcat(cmd));
-    cmd_exec(cmd);
-    free(cmd);
-}
-
-void exec(char* cmd) {
-    /* skip leading space */
-    for (; *cmd && isspace(*cmd); cmd++);
-    if (!*cmd) return;
-    /* see if it matches a builtin tag */
-    Tag* tag = tag_lookup(cmd);
-    if (tag) {
-        while (*cmd && !isspace(*cmd++));
-        tag_exec(tag, (*cmd ? stringdup(cmd) : NULL));
-    } else {
-        cmd_exec(cmd);
-    }
-}
-
-/* Action Callbacks
- ******************************************************************************/
 static void quit(char* arg) {
     win_quit();
 }
@@ -280,8 +273,6 @@ static void get(char* arg) {
         view_reload(win_view(EDIT));
 }
 
-/* Keyboard Handling
- ******************************************************************************/
 static void tag_undo(char* arg) {
     view_undo(win_view(EDIT));
 }