From: Michael D. Lowis Date: Thu, 25 May 2017 18:25:49 +0000 (-0400) Subject: moved configuration stuff to config.h for easier tweaking and customization X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=dd803505dc8e511d6b8ee05daf555f940948f7e1;p=projs%2Ftide.git moved configuration stuff to config.h for easier tweaking and customization --- diff --git a/TODO.md b/TODO.md index 07058e0..541018e 100644 --- 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 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 diff --git a/config.mk b/config.mk index 3a522b1..583123a 100644 --- 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 diff --git a/inc/edit.h b/inc/edit.h index 6c8e295..4a83fd3 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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 " - diff --git a/inc/x11.h b/inc/x11.h index a758842..8fd3bcd 100644 --- 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; diff --git a/lib/buf.c b/lib/buf.c index 649c35a..f03f24d 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -4,6 +4,7 @@ #include #include #include +#include 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; diff --git a/lib/utf8.c b/lib/utf8.c index c363bb4..77f6bee 100644 --- a/lib/utf8.c +++ b/lib/utf8.c @@ -1,6 +1,7 @@ #include #include #include +#include #define __USE_XOPEN #include #include diff --git a/lib/view.c b/lib/view.c index 02aa283..ea60100 100644 --- a/lib/view.c +++ b/lib/view.c @@ -2,6 +2,7 @@ #include #include #include +#include #define ATTR_NORMAL (CLR_BASE03 << 8 | CLR_BASE0) #define ATTR_SELECTED (CLR_BASE0 << 8 | CLR_BASE03) diff --git a/lib/win.c b/lib/win.c index f6cfc62..2260bdd 100644 --- a/lib/win.c +++ b/lib/win.c @@ -4,6 +4,7 @@ #include #include #include +#include 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*)) { diff --git a/lib/x11.c b/lib/x11.c index 38d3dc1..6bc1d57 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -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 a8ab016..c8eb02b 100644 --- a/term.c +++ b/term.c @@ -5,6 +5,9 @@ #include #include +#define INCLUDE_DEFS +#include "config.h" + void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) { } diff --git a/tests/xedit.c b/tests/xedit.c index e917d9f..652bc1c 100644 --- a/tests/xedit.c +++ b/tests/xedit.c @@ -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 0897ea9..dcd6d5f 100644 --- a/xedit.c +++ b/xedit.c @@ -6,6 +6,9 @@ #include #include +#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 9d7b309..d7134bb 100644 --- a/xpick.c +++ b/xpick.c @@ -7,6 +7,9 @@ #include #include +#define INCLUDE_DEFS +#include "config.h" + typedef struct { float score; char* string;