[dev] [st] [PATCH] Change the behavior of word snapping on delimiters

From: Ivan Delalande <colona_AT_ycc.fr>
Date: Wed, 20 Aug 2014 21:20:44 +0200

This makes any sequence of identical delimiters be considered a single
word in word-snapping mode. This seems more coherent for this mode and
is similar to what xterm does.
---
 st.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/st.c b/st.c
index 4bc9e70..e929407 100644
--- a/st.c
+++ b/st.c
_AT_@ -708,7 +708,8 @@ selected(int x, int y) {
 void
 selsnap(int mode, int *x, int *y, int direction) {
 	int newx, newy, xt, yt;
-	Glyph *gp;
+	bool delim, prevdelim;
+	Glyph *gp, *prevgp;
 
 	switch(mode) {
 	case SNAP_WORD:
_AT_@ -716,6 +717,8 @@ selsnap(int mode, int *x, int *y, int direction) {
 		 * Snap around if the word wraps around at the end or
 		 * beginning of a line.
 		 */
+		prevgp = &term.line[*y][*x];
+		prevdelim = strchr(worddelimiters, prevgp->c[0]) != NULL;
 		for(;;) {
 			newx = *x + direction;
 			newy = *y;
_AT_@ -737,11 +740,15 @@ selsnap(int mode, int *x, int *y, int direction) {
 				break;
 
 			gp = &term.line[newy][newx];
-			if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0]))
+			delim = strchr(worddelimiters, gp->c[0]) != NULL;
+			if(!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
+					|| (delim && gp->c[0] != prevgp->c[0])))
 				break;
 
 			*x = newx;
 			*y = newy;
+			prevgp = gp;
+			prevdelim = delim;
 		}
 		break;
 	case SNAP_LINE:
-- 
2.0.4
-- 
Ivan "Colona" Delalande
Received on Wed Aug 20 2014 - 21:20:44 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 20 2014 - 21:24:12 CEST