Skip to content

Instantly share code, notes, and snippets.

@xaizek
Last active November 20, 2015 09:08
Show Gist options
  • Save xaizek/142faeab446f2133cec7 to your computer and use it in GitHub Desktop.
Save xaizek/142faeab446f2133cec7 to your computer and use it in GitHub Desktop.
Crude patch to limit width of a fold line in Vim.
diff --git a/src/screen.c b/src/screen.c
index d80ad6f..fbd2c41 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -2366,6 +2366,10 @@ compute_foldcolumn(wp, col)
if (fdc > wwidth - (col + wmw))
fdc = wwidth - (col + wmw);
+
+ if (fdc > 80)
+ fdc = 80;
+
return fdc;
}
@@ -2455,9 +2459,22 @@ fold_line(wp, fold_count, foldinfo, lnum, row)
ScreenAttrs[off + (p) + ri] = v
#endif
+ const int fold_len = number_width(wp) + comp_textwidth(FALSE) + 1;
+ int max_col;
+
/* Set all attributes of the 'number' or 'relativenumber' column and the
* text */
- RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col);
+ if (fold_len >= W_WIDTH(wp) - col)
+ {
+ RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col);
+ max_col = W_WIDTH(wp);
+ }
+ else
+ {
+ RL_MEMSET(col, hl_attr(HLF_FL), fold_len);
+ RL_MEMSET(col + fold_len, hl_attr(HLF_AT), W_WIDTH(wp) - col - fold_len);
+ max_col = fold_len;
+ }
#ifdef FEAT_SIGNS
/* If signs are being displayed, add two spaces. */
@@ -2665,7 +2682,7 @@ fold_line(wp, fold_count, foldinfo, lnum, row)
if (wp->w_p_rl)
col -= txtcol;
#endif
- while (col < W_WIDTH(wp)
+ while (col < max_col
#ifdef FEAT_RIGHTLEFT
- (wp->w_p_rl ? txtcol : 0)
#endif
@xaizek
Copy link
Author

xaizek commented Nov 20, 2015

Demonstration (left part is with the patch applied, right part is without it):
vim-fold-limit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment