sandy

text editor
git clone git://git.suckless.org/sandy
Log | Files | Refs | README | LICENSE

commit 01ff300e87ad69c3dff71de8853ea1a80b33c72d
parent b55e85b730136a073724c9f149ebe174ce27eefa
Author: Rafael Garcia <rafael.garcia.gallego@gmail.com>
Date:   Wed, 10 Aug 2011 13:16:01 +0200

Tidy up config file a little. Solve a smallish bug in capitalize awk line.
Diffstat:
config.def.h | 76++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 42 insertions(+), 34 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -21,9 +21,9 @@ static const char nlstr[1] = { 0 }; #endif /* Helper config functions, not used in main code */ -static void f_moveb(const Arg*); -static void f_pipeb(const Arg*); -static void f_pipelines(const Arg*); +static void f_move2(const Arg*); +static void f_pipe2(const Arg*); +static void f_pipe3(const Arg*); /* Args to f_spawn */ #define PROMPT(prompt, default, cmd) { .v = (const char *[]){ "/bin/sh", "-c", \ @@ -40,12 +40,22 @@ static void f_pipelines(const Arg*); #define SED PROMPT("Sed:", "", "!sed 2>/dev/null ") #define CMD_P PROMPT("Command:", "/\n?\nw\n!\nsyntax\noffset", "") -/* Args to f_pipe / f_pipero */ +/* Args to f_pipe and friends, simple examples are inlined instead */ /* TODO: make sandy-sel to wrap xsel or standalone */ -#define TOCLIP { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -ib || cat > /tmp/.sandy.clipboard.$USER" } -#define FROMCLIP { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -ob || cat /tmp/.sandy.clipboard.$USER" } -#define TOSEL { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -i || cat > /tmp/.sandy.selection.$USER" } -#define FROMSEL { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -o || cat /tmp/.sandy.selection.$USER" } +#define TOCLIP { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -ib || cat > /tmp/.sandy.clipboard.$USER" } +#define FROMCLIP { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -ob || cat /tmp/.sandy.clipboard.$USER" } +#define TOSEL { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -i || cat > /tmp/.sandy.selection.$USER" } +#define FROMSEL { .v = "xsel -h >/dev/null 2>&1 && test -n \"$DISPLAY\" && xsel -o || cat /tmp/.sandy.selection.$USER" } +#define AUTOINDENT { .v = "awk 'BEGIN{ l=\"\\n\" }; \ + { if(match($0, \"^[\t ]+[^\t ]\")) l=substr($0, RSTART, RLENGTH-1); \ + else l=\"\"; \ + if(FNR==NR && $0 ~ /^[\t ]+$/) print \"\"; \ + else print }; \ + END{ ORS=\"\"; print l }' 2>/dev/null" } +#define CAPITALIZE { .v = "awk 'BEGIN{ ORS=\"\" }; \ + { for ( i=1; i <= NF; i++) { $i=tolower($i) ; sub(\".\", substr(toupper($i),1,1) , $i) } \ + if(FNR==NF) print $0; \ + else print $0\"\\n\" }' 2>/dev/null" } /* Hooks are launched from the main code */ #define HOOK_SAVE_NO_FILE f_spawn (&(const Arg)SAVEAS) @@ -68,18 +78,18 @@ static const Key curskeys[] = { /* Plain keys here, no CONTROL or META */ { .keyv.i = KEY_SDC, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } }, { .keyv.i = KEY_SDC, { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } }, { .keyv.i = KEY_SIC, { t_rw, 0, 0, 0 }, f_pipe, FROMCLIP }, -{ .keyv.i = KEY_HOME, { 0, 0, 0, 0 }, f_moveb, { .m = m_bol } }, -{ .keyv.i = KEY_END, { 0, 0, 0, 0 }, f_moveb, { .m = m_eol } }, -{ .keyv.i = KEY_SHOME, { 0, 0, 0, 0 }, f_moveb, { .m = m_bof } }, -{ .keyv.i = KEY_SEND, { 0, 0, 0, 0 }, f_moveb, { .m = m_eof } }, -{ .keyv.i = KEY_PPAGE, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevscr } }, -{ .keyv.i = KEY_NPAGE, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextscr } }, -{ .keyv.i = KEY_UP, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevline } }, -{ .keyv.i = KEY_DOWN, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextline } }, -{ .keyv.i = KEY_LEFT, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevchar } }, -{ .keyv.i = KEY_RIGHT, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextchar } }, -{ .keyv.i = KEY_SLEFT, { 0, 0, 0, 0 }, f_moveb, { .m = m_prevword } }, -{ .keyv.i = KEY_SRIGHT, { 0, 0, 0, 0 }, f_moveb, { .m = m_nextword } }, +{ .keyv.i = KEY_HOME, { 0, 0, 0, 0 }, f_move2, { .m = m_bol } }, +{ .keyv.i = KEY_END, { 0, 0, 0, 0 }, f_move2, { .m = m_eol } }, +{ .keyv.i = KEY_SHOME, { 0, 0, 0, 0 }, f_move2, { .m = m_bof } }, +{ .keyv.i = KEY_SEND, { 0, 0, 0, 0 }, f_move2, { .m = m_eof } }, +{ .keyv.i = KEY_PPAGE, { 0, 0, 0, 0 }, f_move2, { .m = m_prevscr } }, +{ .keyv.i = KEY_NPAGE, { 0, 0, 0, 0 }, f_move2, { .m = m_nextscr } }, +{ .keyv.i = KEY_UP, { 0, 0, 0, 0 }, f_move2, { .m = m_prevline } }, +{ .keyv.i = KEY_DOWN, { 0, 0, 0, 0 }, f_move2, { .m = m_nextline } }, +{ .keyv.i = KEY_LEFT, { 0, 0, 0, 0 }, f_move2, { .m = m_prevchar } }, +{ .keyv.i = KEY_RIGHT, { 0, 0, 0, 0 }, f_move2, { .m = m_nextchar } }, +{ .keyv.i = KEY_SLEFT, { 0, 0, 0, 0 }, f_move2, { .m = m_prevword } }, +{ .keyv.i = KEY_SRIGHT, { 0, 0, 0, 0 }, f_move2, { .m = m_nextword } }, }; static const Key stdkeys[] = { @@ -93,7 +103,7 @@ static const Key stdkeys[] = { { .keyv.c = CONTROL('C'), { t_warn,t_mod,0, 0 }, f_toggle, { .i = S_Running } }, { .keyv.c = CONTROL('C'), { t_mod, 0, 0, 0 }, f_toggle, { .i = S_Warned } }, { .keyv.c = CONTROL('C'), { 0, 0, 0, 0 }, f_toggle, { .i = S_Running } }, -{ .keyv.c = META('c'), { t_sel, t_rw, 0, 0 }, f_pipe, { .v = "awk '{ for ( i=1; i <= NF; i++) { $i=tolower($i) ; sub(\".\", substr(toupper($i),1,1) , $i) } print }'" } }, +{ .keyv.c = META('c'), { t_sel, t_rw, 0, 0 }, f_pipe, CAPITALIZE }, { .keyv.c = CONTROL('D'), { t_sel, t_rw, 0, 0 }, f_pipe, TOCLIP }, { .keyv.c = CONTROL('D'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_nextchar } }, { .keyv.c = META('d'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_nextword } }, @@ -104,14 +114,14 @@ static const Key stdkeys[] = { { .keyv.c = CONTROL('H'), { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } }, { .keyv.c = CONTROL('H'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } }, { .keyv.c = CONTROL('I'), { t_rw, 0, 0, 0 }, f_insert, { .v = "\t" } }, -{ .keyv.c = CONTROL('J'), { t_rw, t_ai, 0, 0 }, f_pipeb, { .v = "awk 'BEGIN{ l=\"\\n\" } ; { if(match($0, \"^[\t ]+[^\t ]\")) l=substr($0, RSTART, RLENGTH-1); else l=\"\"; if(FNR==NR && $0 ~ /^[\t ]+$/) print \"\" ; else print }; END{ ORS=\"\"; print l }'" } } , +{ .keyv.c = CONTROL('J'), { t_rw, t_ai, 0, 0 }, f_pipe2, AUTOINDENT } , { .keyv.c = CONTROL('J'), { t_rw, 0, 0, 0 }, f_insert, { .v = "\n" } }, { .keyv.c = CONTROL('J'), { 0, 0, 0, 0 }, f_move, { .m = m_nextline } }, { .keyv.c = CONTROL('K'), { t_eol, t_rw, 0, 0 }, f_delete, { .m = m_nextchar } }, { .keyv.c = CONTROL('K'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } }, { .keyv.c = CONTROL('L'), { 0, 0, 0, 0 }, f_center, { 0 } }, -{ .keyv.c = META('l'), { t_sel, t_rw, 0, 0 }, f_pipe, { .v = "tr [A-Z] [a-z]" } }, -{ .keyv.c = CONTROL('M'), { t_rw, t_ai, 0, 0 }, f_pipeb, { .v = "awk 'BEGIN{ l=\"\\n\" } ; { if(match($0, \"^[\t ]+[^\t ]\")) l=substr($0, RSTART, RLENGTH-1); else l=\"\"; if(FNR==NR && $0 ~ /^[\t ]+$/) print \"\" ; else print }; END{ ORS=\"\"; print l }'" } } , +{ .keyv.c = META('l'), { t_sel, t_rw, 0, 0 }, f_pipe, { .v = "tr [A-Z] [a-z]" } }, /* Lowercase */ +{ .keyv.c = CONTROL('M'), { t_rw, t_ai, 0, 0 }, f_pipe2, AUTOINDENT } , { .keyv.c = CONTROL('M'), { t_rw, 0, 0, 0 }, f_insert, { .v = "\n" } }, { .keyv.c = CONTROL('M'), { 0, 0, 0, 0 }, f_move, { .m = m_nextline } }, { .keyv.c = CONTROL('N'), { 0, 0, 0, 0 }, f_move, { .m = m_nextline } }, @@ -127,7 +137,7 @@ static const Key stdkeys[] = { { .keyv.c = CONTROL('T'), { 0, 0, 0, 0 }, f_pipero , TOCLIP }, { .keyv.c = CONTROL('U'), { t_bol, t_rw, 0, 0 }, f_delete, { .m = m_prevchar } }, { .keyv.c = CONTROL('U'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_bol } }, -{ .keyv.c = META('u'), { t_sel, t_rw, 0, 0 }, f_pipe, { .v = "tr [a-z] [A-Z]" } }, +{ .keyv.c = META('u'), { t_sel, t_rw, 0, 0 }, f_pipe, { .v = "tr [a-z] [A-Z]" } }, /* Uppercase */ { .keyv.c = CONTROL('V'), { 0, 0, 0, 0 }, f_move, { .m = m_prevscr } }, { .keyv.c = META('v'), { 0, 0, 0, 0 }, f_move, { .m = m_nextscr } }, { .keyv.c = CONTROL('W'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevword } }, @@ -142,7 +152,7 @@ static const Key stdkeys[] = { { .keyv.c = CONTROL(']'), { 0, 0, 0, 0 }, f_extsel, { .i = ExtDefault } }, { .keyv.c = CONTROL('^'), { t_redo,t_rw, 0, 0 }, f_undo, { .i = -1 } }, { .keyv.c = CONTROL('^'), { t_rw, 0, 0, 0 }, f_repeat, { 0 } }, -{ .keyv.c = META('6'), { t_rw, 0, 0, 0 }, f_pipelines, { .v = "tr -d '\n'" } }, +{ .keyv.c = META('6'), { t_rw, 0, 0, 0 }, f_pipe3, { .v = "tr -d '\n'" } }, /* Join lines */ { .keyv.c = META('5'), { t_sel, t_rw, 0, 0 }, f_spawn, REPLACE }, { .keyv.c = CONTROL('_'), { t_undo,t_rw, 0, 0 }, f_undo, { .i = 1 } }, { .keyv.c = CONTROL('?'), { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } }, @@ -301,22 +311,20 @@ static const short bgcolors[LastBG] = { /* Helper config functions implementation */ void /* Move cursor as per arg->m, then cancel selection */ -f_moveb(const Arg *arg) { +f_move2(const Arg *arg) { fsel=fcur=arg->m(fcur); } -void /* Pipe selection from bol, then cancel selection */ -f_pipeb(const Arg *arg) { +void /* Pipe selection from bol, then select last lain only */ +f_pipe2(const Arg *arg) { i_sortpos(&fsel, &fcur); fsel.o=0; f_pipe(arg); - fsel=fcur; + fsel.l=fcur.l; fsel.o=0; } void /* Pipe full lines including the selection */ -f_pipelines(const Arg *arg) { +f_pipe3(const Arg *arg) { f_extsel(&(const Arg){ .i = ExtLines }); - i_pipetext(arg->v); - statusflags|=S_Modified; - lastaction=LastPipe; + f_pipe(arg); }