From 44bc2cb4b953dce6f53a960dbb31ed3f4c353a85 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 10 Jan 2022 14:32:00 +0300 Subject: [PATCH] line_snap_delimiter patch --- 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 8d49106..f86667e 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 62def59..2e85b84 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, @@ -556,12 +557,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 fd3b0d8..c4b9930 100644 --- a/st.h +++ b/st.h @@ -117,6 +117,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.44.0