patch 9.1.0120: hard to get visual region using Vim script
Problem: hard to get visual region using Vim script
Solution: Add getregion() Vim script function
(Shougo Matsushita, Jakub Łuczyński)
closes: #13998
closes: #11579
Co-authored-by: =?UTF-8?q?Jakub=20=C5=81uczy=C5=84ski?= <doubleloop@o2.pl>
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/ops.c b/src/ops.c
index 3fefbc8..e66b4b5 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -2415,6 +2415,84 @@
}
/*
+ * Get block text from "start" to "end"
+ */
+ void
+charwise_block_prep(
+ pos_T start,
+ pos_T end,
+ struct block_def *bdp,
+ linenr_T lnum,
+ int inclusive)
+{
+ colnr_T startcol = 0, endcol = MAXCOL;
+ int is_oneChar = FALSE;
+ colnr_T cs, ce;
+ char_u *p;
+
+ p = ml_get(lnum);
+ bdp->startspaces = 0;
+ bdp->endspaces = 0;
+
+ if (lnum == start.lnum)
+ {
+ startcol = start.col;
+ if (virtual_op)
+ {
+ getvcol(curwin, &start, &cs, NULL, &ce);
+ if (ce != cs && start.coladd > 0)
+ {
+ // Part of a tab selected -- but don't
+ // double-count it.
+ bdp->startspaces = (ce - cs + 1)
+ - start.coladd;
+ if (bdp->startspaces < 0)
+ bdp->startspaces = 0;
+ startcol++;
+ }
+ }
+ }
+
+ if (lnum == end.lnum)
+ {
+ endcol = end.col;
+ if (virtual_op)
+ {
+ getvcol(curwin, &end, &cs, NULL, &ce);
+ if (p[endcol] == NUL || (cs + end.coladd < ce
+ // Don't add space for double-wide
+ // char; endcol will be on last byte
+ // of multi-byte char.
+ && (*mb_head_off)(p, p + endcol) == 0))
+ {
+ if (start.lnum == end.lnum
+ && start.col == end.col)
+ {
+ // Special case: inside a single char
+ is_oneChar = TRUE;
+ bdp->startspaces = end.coladd
+ - start.coladd + inclusive;
+ endcol = startcol;
+ }
+ else
+ {
+ bdp->endspaces = end.coladd
+ + inclusive;
+ endcol -= inclusive;
+ }
+ }
+ }
+ }
+ if (endcol == MAXCOL)
+ endcol = (colnr_T)STRLEN(p);
+ if (startcol > endcol || is_oneChar)
+ bdp->textlen = 0;
+ else
+ bdp->textlen = endcol - startcol + inclusive;
+ bdp->textstart = p + startcol;
+}
+
+/*
* Handle the add/subtract operator.
*/
void