tex: do not reorder/highlight lines longer than lim - neatvi - [fork] simple vi-type editor with UTF-8 support (HTM) git clone git://src.adamsgaard.dk/neatvi (DIR) Log (DIR) Files (DIR) Refs (DIR) README --- (DIR) commit 73484384d37bca6602d718a7aa946a01af44a56a (DIR) parent caead42d731b8e10d6401d6028f63be6962fb0b2 (HTM) Author: Ali Gholami Rudi <ali@rudi.ir> Date: Thu, 17 Feb 2022 12:20:49 +0330 ex: do not reorder/highlight lines longer than lim Diffstat: M ex.c | 2 ++ M ren.c | 22 ++++++++++++++++++++-- M vi.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) --- (DIR) diff --git a/ex.c b/ex.c t@@ -22,6 +22,7 @@ int xshape = 1; /* perform letter shaping */ int xorder = 1; /* change the order of characters */ int xkmap = 0; /* the current keymap */ int xkmap_alt = 1; /* the alternate keymap */ +int xlim = 256; /* do not process lines longer than this */ static char xkwd[EXLEN]; /* the last searched keyword */ static char xrep[EXLEN]; /* the last replacement */ static int xkwddir; /* the last search direction */ t@@ -769,6 +770,7 @@ static struct option { {"order", "xorder", &xorder}, {"hl", "highlight", &xhl}, {"hll", "highlightline", &xhll}, + {"lim", "linelimit", &xlim}, }; static char *cutword(char *s, char *d) (DIR) diff --git a/ren.c b/ren.c t@@ -5,8 +5,8 @@ #include <string.h> #include "vi.h" -/* specify the screen position of the characters in s */ -int *ren_position(char *s) +/* specify the screen position of the characters in s; reordering version */ +int *ren_position_reorder(char *s) { int i, n; char **chrs = uc_chop(s, &n); t@@ -30,6 +30,24 @@ int *ren_position(char *s) return pos; } +/* specify the screen position of the characters in s; fast version */ +int *ren_position(char *s) +{ + int cpos = 0; + int *pos; + int i; + int n = uc_slen(s); + if (n <= xlim && xorder) + return ren_position_reorder(s); + pos = malloc((n + 1) * sizeof(pos[0])); + for (i = 0; i < n; i++, s += uc_len(s)) { + pos[i] = cpos; + cpos += ren_cwid(s, cpos); + } + pos[i] = cpos; + return pos; +} + int ren_wid(char *s) { int *pos = ren_position(s); (DIR) diff --git a/vi.h b/vi.h t@@ -213,3 +213,4 @@ extern int xhl; extern int xhll; extern int xkmap; extern int xkmap_alt; +extern int xlim;