[hackers] [sandy] Various improvements (by Evil_Bob) || Dimitris Zervas

From: <git_AT_suckless.org>
Date: Sun, 20 Jul 2014 21:43:39 +0200

commit fa3342980e41e35331659a098c9cc5d688dcd301
Author: Dimitris Zervas <dzervas_AT_dzervas.gr>
Date: Sun Jul 20 22:40:24 2014 +0300

    Various improvements (by Evil_Bob)

diff --git a/config.def.h b/config.def.h
index a6bc066..be4cf4b 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -34,7 +34,7 @@ static void f_pipenull(const Arg*);
         "dmenu -v >/dev/null 2>&1 || DISPLAY=\"\";"\
         "if [ -n \"$DISPLAY\" ]; then arg=\"`echo \\"" default "\\" | dmenu $DMENU_OPTS -p '" prompt "'`\";" \
         "else if slmenu -v >/dev/null 2>&1; then arg=\"`echo \\"" default "\\" | slmenu -t -p '" prompt "'`\";" \
- "else printf \""prompt" \" >&2; read arg; fi; fi &&" \
+ "else printf \""prompt" \" >&2; read -r arg; fi; fi &&" \
         "echo " cmd "\"$arg\" > ${SANDY_FIFO}", NULL } }
 
 #define FIND PROMPT("Find:", "${SANDY_FIND}", "/")
_AT_@ -173,7 +173,8 @@ static const Key stdkeys[] = {
 };
 
 #if VIM_BINDINGS
-// TODO: add better paste support (if whole line was yanked, append above, not where you are)
+/* TODO: add better paste support (if whole line was yanked, append above,
+ * not where you are) */
 static const Key commkeys[] = { /* Command mode keys here */
 /* keyv.c, tests, func, arg */
 { .keyv.c = { '$' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_eol } },
_AT_@ -193,7 +194,7 @@ static const Key commkeys[] = { /* Command mode keys here */
 { .keyv.c = { 'C' }, { t_rw, 0, 0, 0 }, f_toggle, { .i = S_Command } },
 { .keyv.c = { 'd' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
 { .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } },
-//{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_pipe, { .m = m_sentence, .v = TOCLIP } },
+/*{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_pipe, { .m = m_sentence, .v = TOCLIP } }, */
 { .keyv.c = { 'D' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } },
 { .keyv.c = { 'g' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_bof } },
 { .keyv.c = { 'g' }, { 0, 0, 0, 0 }, f_move, { .m = m_bof } },
_AT_@ -238,7 +239,8 @@ static const Key commkeys[] = { /* Command mode keys here */
 { .keyv.c = { 'x' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_nextchar } },
 { .keyv.c = { 'X' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
 { .keyv.c = { 'X' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } },
-{ .keyv.c = { 'y' }, { t_rw, 0, 0, 0 }, f_pipero, { .m = m_sentence, .v = TOCLIP } }, /* TODO: won't work since Arg is a union */
+/* TODO: won't work since Arg is a union */
+{ .keyv.c = { 'y' }, { t_rw, 0, 0, 0 }, f_pipero, { .m = m_sentence, .v = TOCLIP } },
 { .keyv.c = { ';' }, { 0, 0, 0, 0 }, f_spawn, CMD_P },
 { .keyv.c = { ':' }, { 0, 0, 0, 0 }, f_spawn, CMD_P },
 { .keyv.c = { '\'' }, { 0, 0, 0, 0 }, f_move, { .m = m_tomark } },
_AT_@ -262,9 +264,10 @@ static const Click clks[] = {
 {BUTTON1_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, 0, { 0 } },
 {BUTTON3_CLICKED, { TRUE , FALSE }, { t_sel, 0, 0 }, f_pipero, { .v = TOSEL } },
 {BUTTON2_CLICKED, { FALSE, FALSE }, { t_rw, 0, 0 }, f_pipenull, { .v = FROMSEL } },
-//{BUTTON4_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_prevscr } },
-//{BUTTON5_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_nextscr } },
-/* ^^ NCurses is a sad old library.... it does not include button 5 nor cursor movement in its mouse declaration by default */
+/*{BUTTON4_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_prevscr } },*/
+/*{BUTTON5_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_nextscr } },*/
+/* ^^ NCurses is a sad old library.... it does not include button 5 nor
+ * cursor movement in its mouse declaration by default */
 {BUTTON1_DOUBLE_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, f_extsel, { .i = ExtWord } },
 {BUTTON1_TRIPLE_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, f_extsel, { .i = ExtLines } },
 };
_AT_@ -378,7 +381,7 @@ static const Syntax syntaxes[] = {
 /* Colors */
 static const short fgcolors[LastFG] = {
         [DefFG] = -1,
- [CurFG] = (HILIGHT_CURRENT?COLOR_BLACK:-1),
+ [CurFG] = (HILIGHT_CURRENT?COLOR_BLACK : -1),
         [SelFG] = COLOR_BLACK,
         [SpcFG] = COLOR_WHITE,
         [CtrlFG] = COLOR_RED,
_AT_@ -424,9 +427,9 @@ static const int bwattrs[LastFG] = {
         [Syn7FG] = A_BOLD,
 };
 
-static const short bgcolors[LastBG] = {
+static const short bgcolors[LastBG] = {
         [DefBG] = -1,
- [CurBG] = (HILIGHT_CURRENT?COLOR_CYAN:-1),
+ [CurBG] = (HILIGHT_CURRENT ? COLOR_CYAN : -1),
         [SelBG] = COLOR_YELLOW,
 };
 
_AT_@ -434,9 +437,9 @@ static const short bgcolors[LastBG] = {
 void /* Pipe selection from bol, then select last line only, special for autoindenting */
 f_pipeai(const Arg *arg) {
         i_sortpos(&fsel, &fcur);
- fsel.o=0;
+ fsel.o = 0;
         f_pipe(arg);
- fsel=fcur;
+ fsel = fcur;
 }
 
 void /* Pipe full lines including the selection */
_AT_@ -447,6 +450,6 @@ f_pipeline(const Arg *arg) {
 
 void /* Pipe empty text */
 f_pipenull(const Arg *arg) {
- fsel=fcur;
+ fsel = fcur;
         f_pipe(arg);
 }
diff --git a/config.h b/config.h
index a6bc066..be4cf4b 100644
--- a/config.h
+++ b/config.h
_AT_@ -34,7 +34,7 @@ static void f_pipenull(const Arg*);
         "dmenu -v >/dev/null 2>&1 || DISPLAY=\"\";"\
         "if [ -n \"$DISPLAY\" ]; then arg=\"`echo \\"" default "\\" | dmenu $DMENU_OPTS -p '" prompt "'`\";" \
         "else if slmenu -v >/dev/null 2>&1; then arg=\"`echo \\"" default "\\" | slmenu -t -p '" prompt "'`\";" \
- "else printf \""prompt" \" >&2; read arg; fi; fi &&" \
+ "else printf \""prompt" \" >&2; read -r arg; fi; fi &&" \
         "echo " cmd "\"$arg\" > ${SANDY_FIFO}", NULL } }
 
 #define FIND PROMPT("Find:", "${SANDY_FIND}", "/")
_AT_@ -173,7 +173,8 @@ static const Key stdkeys[] = {
 };
 
 #if VIM_BINDINGS
-// TODO: add better paste support (if whole line was yanked, append above, not where you are)
+/* TODO: add better paste support (if whole line was yanked, append above,
+ * not where you are) */
 static const Key commkeys[] = { /* Command mode keys here */
 /* keyv.c, tests, func, arg */
 { .keyv.c = { '$' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_eol } },
_AT_@ -193,7 +194,7 @@ static const Key commkeys[] = { /* Command mode keys here */
 { .keyv.c = { 'C' }, { t_rw, 0, 0, 0 }, f_toggle, { .i = S_Command } },
 { .keyv.c = { 'd' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
 { .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_sentence } },
-//{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_pipe, { .m = m_sentence, .v = TOCLIP } },
+/*{ .keyv.c = { 'd' }, { t_rw, 0, 0, 0 }, f_pipe, { .m = m_sentence, .v = TOCLIP } }, */
 { .keyv.c = { 'D' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_eol } },
 { .keyv.c = { 'g' }, { t_sent,0, 0, 0 }, f_adjective, { .m = m_bof } },
 { .keyv.c = { 'g' }, { 0, 0, 0, 0 }, f_move, { .m = m_bof } },
_AT_@ -238,7 +239,8 @@ static const Key commkeys[] = { /* Command mode keys here */
 { .keyv.c = { 'x' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_nextchar } },
 { .keyv.c = { 'X' }, { t_sel, t_rw, 0, 0 }, f_delete, { .m = m_tosel } },
 { .keyv.c = { 'X' }, { t_rw, 0, 0, 0 }, f_delete, { .m = m_prevchar } },
-{ .keyv.c = { 'y' }, { t_rw, 0, 0, 0 }, f_pipero, { .m = m_sentence, .v = TOCLIP } }, /* TODO: won't work since Arg is a union */
+/* TODO: won't work since Arg is a union */
+{ .keyv.c = { 'y' }, { t_rw, 0, 0, 0 }, f_pipero, { .m = m_sentence, .v = TOCLIP } },
 { .keyv.c = { ';' }, { 0, 0, 0, 0 }, f_spawn, CMD_P },
 { .keyv.c = { ':' }, { 0, 0, 0, 0 }, f_spawn, CMD_P },
 { .keyv.c = { '\'' }, { 0, 0, 0, 0 }, f_move, { .m = m_tomark } },
_AT_@ -262,9 +264,10 @@ static const Click clks[] = {
 {BUTTON1_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, 0, { 0 } },
 {BUTTON3_CLICKED, { TRUE , FALSE }, { t_sel, 0, 0 }, f_pipero, { .v = TOSEL } },
 {BUTTON2_CLICKED, { FALSE, FALSE }, { t_rw, 0, 0 }, f_pipenull, { .v = FROMSEL } },
-//{BUTTON4_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_prevscr } },
-//{BUTTON5_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_nextscr } },
-/* ^^ NCurses is a sad old library.... it does not include button 5 nor cursor movement in its mouse declaration by default */
+/*{BUTTON4_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_prevscr } },*/
+/*{BUTTON5_CLICKED, { FALSE, FALSE }, { 0, 0, 0 }, f_move, { .m = m_nextscr } },*/
+/* ^^ NCurses is a sad old library.... it does not include button 5 nor
+ * cursor movement in its mouse declaration by default */
 {BUTTON1_DOUBLE_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, f_extsel, { .i = ExtWord } },
 {BUTTON1_TRIPLE_CLICKED, { TRUE , TRUE }, { 0, 0, 0 }, f_extsel, { .i = ExtLines } },
 };
_AT_@ -378,7 +381,7 @@ static const Syntax syntaxes[] = {
 /* Colors */
 static const short fgcolors[LastFG] = {
         [DefFG] = -1,
- [CurFG] = (HILIGHT_CURRENT?COLOR_BLACK:-1),
+ [CurFG] = (HILIGHT_CURRENT?COLOR_BLACK : -1),
         [SelFG] = COLOR_BLACK,
         [SpcFG] = COLOR_WHITE,
         [CtrlFG] = COLOR_RED,
_AT_@ -424,9 +427,9 @@ static const int bwattrs[LastFG] = {
         [Syn7FG] = A_BOLD,
 };
 
-static const short bgcolors[LastBG] = {
+static const short bgcolors[LastBG] = {
         [DefBG] = -1,
- [CurBG] = (HILIGHT_CURRENT?COLOR_CYAN:-1),
+ [CurBG] = (HILIGHT_CURRENT ? COLOR_CYAN : -1),
         [SelBG] = COLOR_YELLOW,
 };
 
_AT_@ -434,9 +437,9 @@ static const short bgcolors[LastBG] = {
 void /* Pipe selection from bol, then select last line only, special for autoindenting */
 f_pipeai(const Arg *arg) {
         i_sortpos(&fsel, &fcur);
- fsel.o=0;
+ fsel.o = 0;
         f_pipe(arg);
- fsel=fcur;
+ fsel = fcur;
 }
 
 void /* Pipe full lines including the selection */
_AT_@ -447,6 +450,6 @@ f_pipeline(const Arg *arg) {
 
 void /* Pipe empty text */
 f_pipenull(const Arg *arg) {
- fsel=fcur;
+ fsel = fcur;
         f_pipe(arg);
 }
diff --git a/sandy.c b/sandy.c
index 22d1fdb..fae15df 100644
--- a/sandy.c
+++ b/sandy.c
_AT_@ -293,9 +293,9 @@ static regex_t *syntax_file_res[LENGTH(syntaxes)];
 static regex_t *syntax_res[LENGTH(syntaxes)][SYN_COLORS];
 
 /* F_* FUNCTIONS
- Can be linked to an action or keybinding. Always return void and take const Arg* */
+ * Can be linked to an action or keybinding. Always return void and take
+ * const Arg* */
 
-#if VIM_BINDINGS
 void
 f_adjective(const Arg * arg) {
         statusflags &= ~S_Sentence;
_AT_@ -309,7 +309,6 @@ f_adjective(const Arg * arg) {
 
         i_multiply(verb, varg);
 }
-#endif /* VIM_BINDINGS */
 
 /* Make cursor line the one in the middle of the screen if possible, refresh screen */
 void
_AT_@ -876,17 +875,13 @@ i_deltext(Filepos pos0, Filepos pos1) {
 /* test an array of t_ functions */
 bool
 i_dotests(bool(*const a[])(void)) {
- int i = 0;
+ int i;
 
- /* Somehow LENGTH() did not work here */
- while(1) {
- if(a[i]) {
- if(!a[i++]())
- return FALSE;
- } else {
- return TRUE;
- }
+ for(i = 0; a[i]; i++) {
+ if(!(a[i]()))
+ return FALSE;
         }
+ return TRUE;
 }
 
 void
_AT_@ -921,7 +916,8 @@ i_dokeys(const Key bindings[], int length_bindings) {
                                 break;
                         }
 
- /* Handle parameter sentences (verb is used here to define the command to execute) */
+ /* Handle parameter sentences (verb is used here to define the
+ command to execute) */
                         if(statusflags & S_Parameter) {
                                 statusflags &= ~S_Parameter;
                                 i_multiply(verb, (const Arg) { .v = c });
_AT_@ -1142,8 +1138,7 @@ i_killundos(Undo ** list) {
 
         for(; *list;) {
                 u = (*list)->prev;
- if((*list)->str)
- free((*list)->str);
+ free((*list)->str);
                 free(*list);
                 *list = u;
         }
_AT_@ -1357,8 +1352,7 @@ i_pipetext(const char *cmd) {
         }
 
         /* Things I want back to normal */
- if(s)
- free(s);
+ free(s);
 }
 
 /* Read the command fifo */
Received on Sun Jul 20 2014 - 21:43:39 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 20 2014 - 21:48:08 CEST