From 3bd7e43c2666084814b09a4a4412029a0b53eb37 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Sun, 9 Jan 2022 19:37:07 +0000 Subject: [PATCH] [st][patches] Ignore configurable delimiter on line snap selection Adds ability to ignore certain characters when snap selecting an entire line (e.g., triple mouse button press). --- config.def.h | 1 + st.c | 22 +++++++++++++++++++++- st.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 91ab8ca..272fdc5 100644 --- a/config.def.h +++ b/config.def.h @@ -35,6 +35,7 @@ static float chscale = 1.0; * More advanced example: L" `'\"()[]{}" */ wchar_t *worddelimiters = L" "; +wchar_t *snap_line_delimiters = L"│"; /* selection timeouts (in milliseconds) */ static unsigned int doubleclicktimeout = 300; diff --git a/st.c b/st.c index 51049ba..0d57a7e 100644 --- a/st.c +++ b/st.c @@ -42,6 +42,7 @@ #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) #define ISDELIM(u) (u && wcschr(worddelimiters, u)) +#define IS_SNAP_LINE_DELIM(u) (u && wcschr(snap_line_delimiters, u)) enum term_mode { MODE_WRAP = 1 << 0, @@ -563,12 +564,31 @@ selsnap(int *x, int *y, int direction) } break; case SNAP_LINE: + /* + * Don't snap past a line snap delimiter + * (see 'snap_line_delimiters' in config.h) + */ + for(;;) { + newx = *x + direction; + + if (!BETWEEN(newx, 0, term.col - 1)) { + break; + } + + gp = &term.line[*y][newx]; + + if(IS_SNAP_LINE_DELIM(gp->u)) { + break; + } + + *x = newx; + } + /* * Snap around if the the previous line or the current one * has set ATTR_WRAP at its end. Then the whole next or * previous line will be selected. */ - *x = (direction < 0) ? 0 : term.col - 1; if (direction < 0) { for (; *y > 0; *y += direction) { if (!(term.line[*y-1][term.col-1].mode diff --git a/st.h b/st.h index 519b9bd..9a97472 100644 --- a/st.h +++ b/st.h @@ -119,6 +119,7 @@ extern char *scroll; extern char *stty_args; extern char *vtiden; extern wchar_t *worddelimiters; +extern wchar_t *snap_line_delimiters; extern int allowaltscreen; extern int allowwindowops; extern char *termname; -- 2.32.0