Skip to content

Instantly share code, notes, and snippets.

@wellle
Created June 3, 2013 21:20
Show Gist options
  • Save wellle/5701522 to your computer and use it in GitHub Desktop.
Save wellle/5701522 to your computer and use it in GitHub Desktop.
support multi-byte 'fillchars' in custom 'statusline' https://groups.google.com/forum/#!topic/vim_dev/0Cta0HGEHI8
diff -r 99b2236c037c src/buffer.c
--- a/src/buffer.c Mon Jun 03 12:17:05 2013 +0200
+++ b/src/buffer.c Mon Jun 03 16:23:39 2013 +0200
@@ -3567,11 +3567,6 @@
if (fillchar == 0)
fillchar = ' ';
-#ifdef FEAT_MBYTE
- /* Can't handle a multi-byte fill character yet. */
- else if (mb_char2len(fillchar) > 1)
- fillchar = '-';
-#endif
/* Get line & check if empty (cursorpos will show "0-1"). Note that
* p will become invalid when getting another buffer line. */
@@ -4278,12 +4273,17 @@
break;
if (l < itemcnt)
{
- p = item[l].start + maxwidth - width;
+ int middlelength = (maxwidth - width) * MB_CHAR2LEN(fillchar);
+ p = item[l].start + middlelength;
STRMOVE(p, item[l].start);
- for (s = item[l].start; s < p; s++)
- *s = fillchar;
+ for (s = item[l].start; s < p;)
+#ifdef FEAT_MBYTE
+ s += (*mb_char2bytes)(fillchar, s);
+#else
+ *s++ = fillchar;
+#endif
for (l++; l < itemcnt; l++)
- item[l].start += maxwidth - width;
+ item[l].start += middlelength;
width = maxwidth;
}
}
diff -r 99b2236c037c src/macros.h
--- a/src/macros.h Mon Jun 03 12:17:05 2013 +0200
+++ b/src/macros.h Mon Jun 03 16:23:39 2013 +0200
@@ -261,6 +261,8 @@
#ifdef FEAT_MBYTE
/* Get the length of the character p points to */
# define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
+/* Get the byte length of the character p */
+# define MB_CHAR2LEN(p) (has_mbyte ? (*mb_char2len)(p) : 1)
/* Advance multi-byte pointer, skip over composing chars. */
# define mb_ptr_adv(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1
/* Advance multi-byte pointer, do not skip over composing chars. */
@@ -275,6 +277,7 @@
# define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p))
#else
# define MB_PTR2LEN(p) 1
+# define MB_CHAR2LEN(p) 1
# define mb_ptr_adv(p) ++p
# define mb_cptr_adv(p) ++p
# define mb_ptr_back(s, p) --p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment