]> git.mdlowis.com Git - projs/tide.git/commitdiff
moved configuration stuff to config.h for easier tweaking and customization
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 25 May 2017 18:25:49 +0000 (14:25 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 25 May 2017 18:25:49 +0000 (14:25 -0400)
14 files changed:
TODO.md
config.h [new file with mode: 0644]
config.mk
inc/edit.h
inc/x11.h
lib/buf.c
lib/utf8.c
lib/view.c
lib/win.c
lib/x11.c
term.c
tests/xedit.c
xedit.c
xpick.c

diff --git a/TODO.md b/TODO.md
index 07058e0d7b108ed319c590bf571c6b64666c48c1..541018ee0b1b6cc263db883e1614a4eddee35bf4 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -5,6 +5,9 @@ Up Next:
 * Make Fn keys execute nth command in the tags buffers
 * move by words is inconsistent. Example:
     var infoId = 'readerinfo'+reader.id;
+* Add a way to CD using a builtin
+* diagnostic messages should steal focus.
+* Ctrl+Shift+N to set a mark, Ctrl+N to jump to a mark
 
 The Future:
 
@@ -20,6 +23,12 @@ The Future:
 * implement command diffing logic to optimize the undo/redo log
 * Status line should omit characters from beginning of path to make file path fit
 
+* Ctrl+Shift+g to jump to undo a goto line action
+* Shortcut to warp cursor to middle of current screen.
+* Find shortcut should select previous word if current char is newline
+* diagnostic messages can stack up if deselected and not resolved
+* highlight all matches of search term
+
 # Auxillary Programs
 
 * Visual diff tool
diff --git a/config.h b/config.h
new file mode 100644 (file)
index 0000000..5ff5bfe
--- /dev/null
+++ b/config.h
@@ -0,0 +1,78 @@
+/* extern the config variables */
+extern char *FontString, *DefaultTags;
+extern unsigned int ColorPalette[16];
+extern char *ShellCmd[], *SedCmd[], *PickFileCmd[], *PickTagCmd[], *OpenCmd[];
+
+/* OS-Specific Config
+ ******************************************************************************/
+#ifdef __MACH__
+#define FONT    "Monaco:size=10:antialias=true:autohint=true"
+#define LNSPACE 0
+#else
+#define FONT    "Liberation Mono:pixelsize=14:antialias=true:autohint=true"
+#define LNSPACE 2
+#endif
+
+/* General Config
+ ******************************************************************************/
+enum {
+    Width          = 640,     /* default window width */
+    Height         = 480,     /* default window height */
+    TabWidth       = 4,       /* maximum number of spaces used to represent a tab */
+    ScrollLines    = 4,       /* number of lines to scroll by for mouse wheel scrolling */
+    BufSize        = 8192,    /* default buffer size */
+    FontCacheSize  = 16,      /* Maximum number of fonts allowed in the font cache */
+    EventTimeout   = 50,      /* Maximum blocking wait time for events */
+    TrimOnSave     = 1,       /* Enable trimming of trailing whitespace on save */
+    DefaultCRLF    = 0,       /* Default to Unix line endings */
+    DefaultCharset = UTF_8,   /* We assume UTF-8 because nothing else matters */
+    LineSpacing    = LNSPACE, /* Set the vertical spacing between lines */
+    DblClickTime   = 250,     /* Millisecond time for detecting double clicks */
+    RulePosition   = 80,      /* Column in which the vertical ruler appears */
+};
+
+#ifdef INCLUDE_DEFS
+
+/* Default contents of the tags region */
+char* DefaultTags = "Quit Save Undo Redo Cut Copy Paste | Find ";
+
+/* Default font string */
+char* FontString = FONT;
+
+/* 16 color palette used for drawing */
+unsigned int ColorPalette[16] = {
+    0xff002b36,
+    0xff073642,
+    0xff586e75,
+    0xff657b83,
+    0xff839496,
+    0xff93a1a1,
+    0xffeee8d5,
+    0xfffdf6e3,
+    0xffb58900,
+    0xffcb4b16,
+    0xffdc322f,
+    0xffd33682,
+    0xff6c71c4,
+    0xff268bd2,
+    0xff2aa198,
+    0xff859900
+};
+
+/* The shell: Filled in with $SHELL. Used to execute commands */
+char* ShellCmd[] = { NULL, "-c", NULL, NULL };
+
+/* Sed command used to execute commands marked with ':' sigil */
+char* SedCmd[] = { "sed", "-e", NULL, NULL };
+
+/* Fuzzy Picker for files in the current directory and subdirectories */
+char* PickFileCmd[] = { "xfilepick", ".", NULL };
+
+/* Fuzzy picker for tags in a ctags database. */
+char* PickTagCmd[] = { "xtagpick", NULL, "tags", NULL, NULL };
+
+/* Open a new instance of the editor */
+char* OpenCmd[] = { "xedit", NULL, NULL };
+
+#undef INCLUDE_DEFS
+#endif
index 3a522b139fb0821a6ed091e0ed1fc22fca940bc8..583123a3e7cf72da1c8220cb20d106ee3c3e7e15 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -5,7 +5,8 @@ PREFIX = $(HOME)
 
 # OSX X11 Flags
 INCS += -I/usr/X11/include           \
-               -I/usr/X11/include/freetype2
+               -I/usr/X11/include/freetype2 \
+               -I.
 LIBS += -L/usr/X11/lib
 
 # Linux Freetype2 Flags
index 6c8e295eeabd3b81a3f650bbac2ca10b74ad2c70..4a83fd391108984b6bad30e3af52a897498075d6 100644 (file)
@@ -214,52 +214,3 @@ enum ColorId {
     CLR_GREEN   = 15,
     CLR_COUNT   = 16
 };
-
-/* Configuration
- *****************************************************************************/
-enum {
-    Width         = 640,  /* default window width */
-    Height        = 480,  /* default window height */
-    TabWidth      = 4,    /* maximum number of spaces used to represent a tab */
-    ScrollLines   = 4,    /* number of lines to scroll by for mouse wheel scrolling */
-    BufSize       = 8192, /* default buffer size */
-    FontCacheSize = 16,   /* Maximum number of fonts allowed in the font cache */
-    EventTimeout  = 100,  /* Maximum blocking wait time for events */
-    TrimOnSave    = 1,    /* Enable trimming of trailing whitespace on save */
-#ifdef __MACH__
-    LineSpacing   = 0,    /* Number of pixels for spacing between lines */
-#else
-    LineSpacing   = 2,    /* Number of pixels for spacing between lines */
-#endif
-};
-
-/* choose the font to  use for xft */
-#ifdef __MACH__
-#define FONTNAME "Monaco:size=10:antialias=true:autohint=true"
-#else
-#define FONTNAME "Liberation Mono:pixelsize=14:antialias=true:autohint=true"
-#endif
-#define DEFAULT_COLORSCHEME DARK
-#define DEFAULT_CRLF 0
-#define DEFAULT_CHARSET UTF_8
-#define COLOR_PALETTE \
-    {                 \
-        0xff002b36,   \
-        0xff073642,   \
-        0xff586e75,   \
-        0xff657b83,   \
-        0xff839496,   \
-        0xff93a1a1,   \
-        0xffeee8d5,   \
-        0xfffdf6e3,   \
-        0xffb58900,   \
-        0xffcb4b16,   \
-        0xffdc322f,   \
-        0xffd33682,   \
-        0xff6c71c4,   \
-        0xff268bd2,   \
-        0xff2aa198,   \
-        0xff859900    \
-    }
-#define DEFAULT_TAGS "Quit Save Undo Redo Cut Copy Paste | Find "
-
index a7588427777242895a240da3121acbd263dd08f5..8fd3bcd0c65d66b3527f0d3632bb0ea004bddc97 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -5,7 +5,6 @@ typedef struct {
     void (*set_focus)(bool focus);
     void (*mouse_drag)(int state, int x, int y);
     void (*mouse_btn)(int state, bool pressed, int x, int y);
-    uint32_t palette[16];
 } XConfig;
 
 typedef void* XFont;
index 649c35a28c7194b00973c55337cdd57b0a9791e0..f03f24d9451bd2b53bce49f15861a5e45fa79722 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -4,6 +4,7 @@
 #include <edit.h>
 #include <ctype.h>
 #include <unistd.h>
+#include <config.h>
 
 static void buf_resize(Buf* buf, size_t sz);
 
@@ -182,8 +183,8 @@ void buf_init(Buf* buf, void (*errfn)(char*)) {
     buf->modified    = false;
     buf->expand_tabs = true;
     buf->copy_indent = true;
-    buf->charset     = DEFAULT_CHARSET;
-    buf->crlf        = DEFAULT_CRLF;
+    buf->charset     = DefaultCharset;
+    buf->crlf        = DefaultCRLF;
     buf->bufsize     = BufSize;
     buf->bufstart    = (Rune*)malloc(buf->bufsize * sizeof(Rune));
     buf->bufend      = buf->bufstart + buf->bufsize;
index c363bb4864fe99c8851b51ea6c34d1fd13455730..77f6bee961e12eecc6e299a8d4e96ef62458ca75 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
+#include <config.h>
 #define __USE_XOPEN
 #include <wchar.h>
 #include <ctype.h>
index 02aa2832d046ef08751a4d5a4a96120ad62e1933..ea60100d4e46dff4bec5876034f4d01bf5fa4f6d 100644 (file)
@@ -2,6 +2,7 @@
 #include <utf.h>
 #include <edit.h>
 #include <ctype.h>
+#include <config.h>
 
 #define ATTR_NORMAL   (CLR_BASE03 << 8 | CLR_BASE0)
 #define ATTR_SELECTED (CLR_BASE0  << 8 | CLR_BASE03)
index f6cfc62e4a3ed81c2dd9d02d8d65cc7b83e43833..2260bdda93245c47c2e9d0eaf3465c1179411912 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -4,6 +4,7 @@
 #include <x11.h>
 #include <win.h>
 #include <ctype.h>
+#include <config.h>
 
 static void onredraw(int height, int width);
 static void oninput(int mods, Rune key);
@@ -25,7 +26,6 @@ static XConfig Config = {
     .set_focus    = onfocus,
     .mouse_drag   = onmousedrag,
     .mouse_btn    = onmousebtn,
-    .palette      = COLOR_PALETTE
 };
 static WinRegion Focused = EDIT;
 static Region Regions[NREGIONS] = {0};
@@ -35,7 +35,7 @@ static void win_init(void (*errfn)(char*)) {
     for (int i = 0; i < SCROLL; i++)
         view_init(&(Regions[i].view), NULL, errfn);
     x11_init(&Config);
-    Font = x11_font_load(FONTNAME);
+    Font = x11_font_load(FontString);
 }
 
 void win_window(char* name, void (*errfn)(char*)) {
index 38d3dc1711baa4105bb3fbc5f7eeddd6f25feb21..6bc1d572e97a481042d0dfc6614258bb62e5d32d 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -5,6 +5,7 @@
 #include <x11.h>
 #include <utf.h>
 #include <edit.h>
+#include <config.h>
 #include <locale.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -118,7 +119,7 @@ void x11_window(char* name, int width, int height) {
         X.width,
         X.height,
         0, X.depth,
-        Config->palette[0]);
+        ColorPalette[0]);
 
     /* register interest in the delete window message */
     Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
@@ -414,7 +415,7 @@ size_t x11_font_descent(XFont fnt) {
 
 void x11_draw_rect(int color, int x, int y, int width, int height) {
     XftColor clr;
-    xftcolor(&clr, Config->palette[color]);
+    xftcolor(&clr, ColorPalette[color]);
     XftDrawRect(X.xft, &clr, x, y, width, height);
     XftColorFree(X.display, X.visual, X.colormap, &clr);
 }
@@ -492,12 +493,12 @@ void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs) {
         XftTextExtentsUtf8(X.display, font, (const FcChar8*)"0", 1, &extent);
         int w = extent.xOff;
         int h = (font->height - font->descent) + LineSpacing;
-        xftcolor(&bgc, Config->palette[bg]);
+        xftcolor(&bgc, ColorPalette[bg]);
         size_t width = specs[nspecs-1].x - specs[0].x + w;
         x11_draw_rect(bg, specs[0].x, specs[0].y - h, width, font->height + LineSpacing);
         XftColorFree(X.display, X.visual, X.colormap, &bgc);
     }
-    xftcolor(&fgc, Config->palette[fg]);
+    xftcolor(&fgc, ColorPalette[fg]);
     XftDrawGlyphFontSpec(X.xft, &fgc, (XftGlyphFontSpec*)specs, nspecs);
     XftColorFree(X.display, X.visual, X.colormap, &fgc);
 }
diff --git a/term.c b/term.c
index a8ab0162ee444985d5cb1efbfdc8dcfc0378f779..c8eb02b79d6cd725d22103062b94674632eadad8 100644 (file)
--- a/term.c
+++ b/term.c
@@ -5,6 +5,9 @@
 #include <ctype.h>
 #include <win.h>
 
+#define INCLUDE_DEFS
+#include "config.h"
+
 void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) {
 }
 
index e917d9f9fc07bec382d3db4ae6ff651508e0bc29..652bc1ca7e2969ea27367cffdd15ac1fd5709ad9 100644 (file)
@@ -607,77 +607,77 @@ TEST_SUITE(UnitTests) {
         CHECK(win_view(EDIT)->selection.beg == 0);
         CHECK(win_view(EDIT)->selection.end == 3);
     }
-    
+
     TEST(ctrl+h should nothing for empty buffer) {
         setup_view(EDIT, "", CRLF, 0);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 0);
         CHECK(win_sel(EDIT)->end == 0);
     }
-    
+
     TEST(ctrl+h should highlight content in parens from left paren) {
         setup_view(EDIT, " (foo bar) ", CRLF, 1);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 2);
         CHECK(win_sel(EDIT)->end == 9);
     }
-    
+
     TEST(ctrl+h should highlight content in parens from right paren) {
         setup_view(EDIT, " (foo bar) ", CRLF, 9);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 9);
         CHECK(win_sel(EDIT)->end == 2);
     }
-    
+
     TEST(ctrl+h should highlight content in parens from left bracket) {
         setup_view(EDIT, " [foo bar] ", CRLF, 1);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 2);
         CHECK(win_sel(EDIT)->end == 9);
     }
-    
+
     TEST(ctrl+h should highlight content in parens from right bracket) {
         setup_view(EDIT, " [foo bar] ", CRLF, 9);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 9);
         CHECK(win_sel(EDIT)->end == 2);
     }
-    
+
     TEST(ctrl+h should highlight content in parens from left brace) {
         setup_view(EDIT, " {foo bar} ", CRLF, 1);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 2);
         CHECK(win_sel(EDIT)->end == 9);
     }
-    
+
     TEST(ctrl+h should highlight content in parens from right brace) {
         setup_view(EDIT, " {foo bar} ", CRLF, 9);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 9);
         CHECK(win_sel(EDIT)->end == 2);
     }
-    
+
     TEST(ctrl+h should highlight whole line from bol) {
         setup_view(EDIT, "foo bar\n", CRLF, 0);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 0);
         CHECK(win_sel(EDIT)->end == 8);
     }
-    
+
     TEST(ctrl+h should highlight whole line from eol) {
         setup_view(EDIT, "foo bar\n", CRLF, 7);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 0);
         CHECK(win_sel(EDIT)->end == 8);
     }
-    
+
     TEST(ctrl+h should highlight word under cursor) {
         setup_view(EDIT, " foo.bar \n", CRLF, 1);
         send_keys(ModCtrl, XK_h);
         CHECK(win_sel(EDIT)->beg == 1);
         CHECK(win_sel(EDIT)->end == 4);
     }
-    
+
     TEST(ctrl+h should highlight word under cursor) {
         setup_view(EDIT, " foo.bar \n", CRLF, 4);
         send_keys(ModCtrl, XK_h);
@@ -773,7 +773,7 @@ TEST_SUITE(UnitTests) {
         usleep(251 * 1000);
         exec("Quit");
         CHECK(ExitCode == 42);
-        CHECK(verify_text(TAGS, "File is modified. Repeat action twice in < 250ms to quit."));
+        CHECK(verify_text(TAGS, "File is modified. Repeat action twice quickly to quit."));
     }
 
     TEST(Quit should discard changes if quit executed twice in less than 250 ms) {
@@ -786,12 +786,12 @@ TEST_SUITE(UnitTests) {
         EXPECT_EXIT {
             exec("Quit");
             CHECK(ExitCode == 42);
-            CHECK(verify_text(TAGS, "File is modified. Repeat action twice in < 250ms to quit."));
+            CHECK(verify_text(TAGS, "File is modified. Repeat action twice quickly to quit."));
             exec("Quit");
         }
         ExitExpected = false;
         CHECK(ExitCode == 0);
-        CHECK(verify_text(TAGS, "File is modified. Repeat action twice in < 250ms to quit."));
+        CHECK(verify_text(TAGS, "File is modified. Repeat action twice quickly to quit."));
     }
 
     TEST(Save should save changes to disk with crlf line endings) {
diff --git a/xedit.c b/xedit.c
index 0897ea92f2f0333868ff398dd1ba02be3d19418d..dcd6d5f44a53015de600e1ab23c3da86e623f67c 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -6,6 +6,9 @@
 #include <win.h>
 #include <shortcuts.h>
 
+#define INCLUDE_DEFS
+#include "config.h"
+
 typedef struct {
     char* tag;
     union {
@@ -14,12 +17,6 @@ typedef struct {
     } action;
 } Tag;
 
-/* The shell: Filled in with $SHELL. Used to execute commands */
-static char* ShellCmd[] = { NULL, "-c", NULL, NULL };
-static char* SedCmd[] = { "sed", "-e", NULL, NULL };
-static char* PickFileCmd[] = { "xfilepick", ".", NULL };
-static char* PickTagCmd[] = { "xtagpick", NULL, "tags", NULL, NULL };
-static char* OpenCmd[] = { "xedit", NULL, NULL };
 static Tag Builtins[];
 static int SearchDir = DOWN;
 static char* SearchTerm = NULL;
@@ -136,7 +133,7 @@ static void trim_whitespace(void) {
 static void quit(void) {
     static uint64_t before = 0;
     uint64_t now = getmillis();
-    if (!win_buf(EDIT)->modified || (now-before) <= 250) {
+    if (!win_buf(EDIT)->modified || (now-before) <= DblClickTime) {
         #ifndef TEST
         x11_deinit();
         #else
@@ -144,7 +141,7 @@ static void quit(void) {
         #endif
     } else {
         view_append(win_view(TAGS),
-            "File is modified. Repeat action twice in < 250ms to quit.");
+            "File is modified. Repeat action twice quickly to quit.");
     }
     before = now;
 }
@@ -179,7 +176,7 @@ void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) {
     static uint64_t before = 0;
     if (!pressed) return;
     uint64_t now = getmillis();
-    count = ((now-before) <= 250 ? count+1 : 1);
+    count = ((now-before) <= DblClickTime ? count+1 : 1);
     before = now;
 
     if (count == 1) {
@@ -241,7 +238,7 @@ static void tag_redo(void) {
 
 static void search(void) {
     char* str;
-    SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);
+    SearchDir *= (x11_keymodsset(ModShift) ? UP : DOWN);
     if (x11_keymodsset(ModAlt) && SearchTerm)
         str = stringdup(SearchTerm);
     else
@@ -262,7 +259,7 @@ static void execute(void) {
 }
 
 static void find(char* arg) {
-    SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);
+    SearchDir *= (x11_keymodsset(ModShift) ? UP : DOWN);
     view_findstr(win_view(EDIT), SearchDir, arg);
 }
 
@@ -511,13 +508,13 @@ void onshutdown(void) {
 #ifndef TEST
 int main(int argc, char** argv) {
     /* setup the shell */
-    ShellCmd[0] = getenv("SHELL");
+    if (!ShellCmd[0]) ShellCmd[0] = getenv("SHELL");
     if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh";
     /* Create the window and enter the event loop */
     win_window("edit", onerror);
     char* tags = getenv("EDITTAGS");
-    win_settext(TAGS, (tags ? tags : DEFAULT_TAGS));
-    win_setruler(80);
+    win_settext(TAGS, (tags ? tags : DefaultTags));
+    win_setruler(RulePosition);
     view_init(win_view(EDIT), (argc > 1 ? argv[1] : NULL), onerror);
     win_setkeys(Bindings);
     win_loop();
diff --git a/xpick.c b/xpick.c
index 9d7b3096bfe1e6e28515e0b6d2a866bc1c712f8a..d7134bbe825fc0f62798c47f6bc3d22fc555fe7c 100644 (file)
--- a/xpick.c
+++ b/xpick.c
@@ -7,6 +7,9 @@
 #include <ctype.h>
 #include <shortcuts.h>
 
+#define INCLUDE_DEFS
+#include "config.h"
+
 typedef struct {
     float score;
     char* string;