]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added Font tag for toggling between preset fonts or selecting a new font manually
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Sep 2018 16:41:41 +0000 (12:41 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 17 Sep 2018 16:41:41 +0000 (12:41 -0400)
TODO.md
inc/edit.h
inc/win.h
lib/config.c
lib/x11.c
tide.c

diff --git a/TODO.md b/TODO.md
index 498088a8dbf7fc81a496d3d17fa410e0292db120..2a2cc531062b2c891fcde36f9098adea016d22b0 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -22,7 +22,6 @@ Tags:
 * Clear - Clear the current window's edit buffer
 * Line - Get the current line number(s) containing the selection
 * Kill - Kill a background command
-* Font - Toggle font between monospace and proportional or set the font
 * ID - Get window id of the X window
 * Zerox - Create a copy of the window
 
@@ -30,15 +29,16 @@ The Future:
 
 * Wily-like rc file for registering builtins
 * Case insensitive search
-* use transaction ids to only mark buffer dirty when it really is
 * 100% coverage with unit and unit-integration tests
-* tab inserts dont coalesce like one would expect
 * move by words is inconsistent. Example:
     var infoId = 'readerinfo'+reader.id;
 
 Maybe think about addressing these later:
 
-* add current dir to path]'\\\''''''''''''''''''''''''''''' char is newline
+* add current dir to path
+* add support for guidefiles
+* Shift+Insert should insert primary selection
+* Find shortcut should select previous word if current char is newline
 
 # Auxillary Programs
 
index 4a198bb54aa0d0461bb1ae2e54d1f820aebfafa4..bffdbe0ec0777629a486cf416d6fde30a3470505 100644 (file)
@@ -186,7 +186,7 @@ enum { /* Color Names */
     ClrCount
 };
 
-extern char *TagString, *FontString;
+extern char *TagString, *Fonts[2];
 extern int Palette[ClrCount];
 extern int WinWidth, WinHeight, ScrollWidth, Timeout, TabWidth, ScrollBy,
            ClickTime, CopyIndent, TrimOnSave, ExpandTabs, DosLineFeed;
index 5cbf2b6994c12003d8b59c9deaca5dcf8f901132..9610219be46b0dea433e900812d73e2df6ce29b1 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -133,6 +133,7 @@ typedef struct {
 
 void win_init(KeyBinding* bindings);
 void win_title(char* path);
+void win_font(char* font);
 void win_prop_set(char* xname, char* ename, char* value);
 void win_update(int ms);
 void win_loop(void);
index 4f712edab72b459cb30abb7d636bc80b09bbfec3..1ce32cfd231884082b72efde434023711f0562dc 100644 (file)
@@ -4,8 +4,11 @@
 #include <utf.h>
 #include <edit.h>
 
-char* TagString = "Del Put Undo Redo Find ";
-char* FontString = "Verdana:size=11";
+char* TagString = "Del Put Undo Redo | Font Tabs | Find ";
+char* Fonts[2] = {
+    "Verdana:size=11",
+    "Liberation Mono:size=11"
+};
 
 int /* Integer config options */
     WinWidth = 640,
index 09f569692e53384397035ee078fe5fee7432d071..d0f0d376319da5efb591d8d874e38278baccf070 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -49,6 +49,7 @@ static View Regions[NREGIONS];
 static KeyBinding* Keys = NULL;
 static int Divider;
 static Atom SelTarget;
+static int FontSel;
 static struct XSel Selections[] = {
     { .name = "PRIMARY" },
     { .name = "CLIPBOARD" },
@@ -543,7 +544,7 @@ void win_init(KeyBinding* bindings) {
     X.colormap = wa.colormap;
     X.screen   = DefaultScreen(X.display);
     X.depth    = DefaultDepth(X.display, X.screen);
-    font_load(FontString);
+    font_load(Fonts[FontSel = 0]);
     x11_window("unnamed");
     /* initialize selection atoms */
     for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++)
@@ -561,6 +562,14 @@ void win_title(char* path) {
     XStoreName(X.display, X.self, path);
 }
 
+void win_font(char* font) {
+    if (font) {
+        font_load(font);
+    } else {
+        font_load(Fonts[++FontSel % nelem(Fonts)]);
+    }
+}
+
 void win_prop_set(char* xname, char* ename, char* value) {
     if (!value) return;
     Atom propname = XInternAtom(X.display, xname, 0);
diff --git a/tide.c b/tide.c
index 3762814f8f611f00494c87a8c058811ba7f7265f..ecebb7f71441a86d0396912d92188c383a497e05 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -46,10 +46,10 @@ static Tag* tag_lookup(char* cmd) {
 
 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));
+    if (!arg || *arg) arg = view_getstr(win_view(TAGS));
+    if (!arg || *arg) arg = view_getstr(win_view(EDIT));
     /* execute the tag handler */
-    tag->action(arg);
+    tag->action(arg || *arg ? NULL : arg);
     free(arg);
 }
 
@@ -400,6 +400,7 @@ static Tag Builtins[] = {
     { .tag = "Redo",   .action = tag_redo  },
     { .tag = "Tabs",   .action = tabs      },
     { .tag = "Undo",   .action = tag_undo  },
+    { .tag = "Font",   .action = win_font  },
     { .tag = NULL,     .action = NULL      }
 };
 
@@ -459,12 +460,10 @@ static KeyBinding Bindings[] = {
 static void usage(void) {
     printf(
         "Usage: %s [FLAGS] [FILE]\n"
-        "\n    -S 0,1  Enable/disable syntax highlighting"
         "\n    -I 0,1  Enable/disable automatic indenting"
         "\n    -W 0,1  Enable/disable trimming whitespace on save"
         "\n    -E 0,1  Enable/disable expanding tabs to spaces"
         "\n    -N 0,1  Enable/disable dos line ending style"
-        "\n    -F str  Set the font to use"
         "\n    -T str  String to use for the tags region"
         "\n    -C str  Set the shell to use for command execution\n",
         ARGV0);
@@ -480,7 +479,6 @@ int main(int argc, char** argv) {
         case 'W': TrimOnSave  = BOOLARG(); break;
         case 'E': ExpandTabs  = BOOLARG(); break;
         case 'N': DosLineFeed = BOOLARG(); break;
-        case 'F': FontString  = STRARG();  break;
         case 'T': TagString   = STRARG();  break;
         case 'C': ShellCmd[0] = STRARG();  break;
     } OPTEND;