st-line_snap_delimiter-3bd7e43.diff (2300B)
1 From 3bd7e43c2666084814b09a4a4412029a0b53eb37 Mon Sep 17 00:00:00 2001 2 From: Michael Buch <michaelbuch12@gmail.com> 3 Date: Sun, 9 Jan 2022 19:37:07 +0000 4 Subject: [PATCH] [st][patches] Ignore configurable delimiter on line snap 5 selection 6 7 Adds ability to ignore certain characters when snap selecting 8 an entire line (e.g., triple mouse button press). 9 --- 10 config.def.h | 1 + 11 st.c | 22 +++++++++++++++++++++- 12 st.h | 1 + 13 3 files changed, 23 insertions(+), 1 deletion(-) 14 15 diff --git a/config.def.h b/config.def.h 16 index 91ab8ca..272fdc5 100644 17 --- a/config.def.h 18 +++ b/config.def.h 19 @@ -35,6 +35,7 @@ static float chscale = 1.0; 20 * More advanced example: L" `'\"()[]{}" 21 */ 22 wchar_t *worddelimiters = L" "; 23 +wchar_t *snap_line_delimiters = L"│"; 24 25 /* selection timeouts (in milliseconds) */ 26 static unsigned int doubleclicktimeout = 300; 27 diff --git a/st.c b/st.c 28 index 51049ba..0d57a7e 100644 29 --- a/st.c 30 +++ b/st.c 31 @@ -42,6 +42,7 @@ 32 #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) 33 #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) 34 #define ISDELIM(u) (u && wcschr(worddelimiters, u)) 35 +#define IS_SNAP_LINE_DELIM(u) (u && wcschr(snap_line_delimiters, u)) 36 37 enum term_mode { 38 MODE_WRAP = 1 << 0, 39 @@ -563,12 +564,31 @@ selsnap(int *x, int *y, int direction) 40 } 41 break; 42 case SNAP_LINE: 43 + /* 44 + * Don't snap past a line snap delimiter 45 + * (see 'snap_line_delimiters' in config.h) 46 + */ 47 + for(;;) { 48 + newx = *x + direction; 49 + 50 + if (!BETWEEN(newx, 0, term.col - 1)) { 51 + break; 52 + } 53 + 54 + gp = &term.line[*y][newx]; 55 + 56 + if(IS_SNAP_LINE_DELIM(gp->u)) { 57 + break; 58 + } 59 + 60 + *x = newx; 61 + } 62 + 63 /* 64 * Snap around if the the previous line or the current one 65 * has set ATTR_WRAP at its end. Then the whole next or 66 * previous line will be selected. 67 */ 68 - *x = (direction < 0) ? 0 : term.col - 1; 69 if (direction < 0) { 70 for (; *y > 0; *y += direction) { 71 if (!(term.line[*y-1][term.col-1].mode 72 diff --git a/st.h b/st.h 73 index 519b9bd..9a97472 100644 74 --- a/st.h 75 +++ b/st.h 76 @@ -119,6 +119,7 @@ extern char *scroll; 77 extern char *stty_args; 78 extern char *vtiden; 79 extern wchar_t *worddelimiters; 80 +extern wchar_t *snap_line_delimiters; 81 extern int allowaltscreen; 82 extern int allowwindowops; 83 extern char *termname; 84 -- 85 2.32.0 86