Skip to content

Commit b13d5c0

Browse files
committed
updated for version 7.3.826
Problem: List of features in :version output is hard to read. Solution: Make columns. (Nazri Ramliy)
1 parent 153f4ba commit b13d5c0

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed

src/version.c

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ static char *mediumVersion = VIM_VERSION_MEDIUM;
3434
# if (defined(VMS) && defined(VAXC)) || defined(PROTO)
3535
char longVersion[sizeof(VIM_VERSION_LONG_DATE) + sizeof(__DATE__)
3636
+ sizeof(__TIME__) + 3];
37+
38+
static void list_features __ARGS((void));
39+
3740
void
3841
make_version()
3942
{
@@ -725,6 +728,8 @@ static char *(features[]) =
725728

726729
static int included_patches[] =
727730
{ /* Add new patch number below this line */
731+
/**/
732+
826,
728733
/**/
729734
825,
730735
/**/
@@ -2435,6 +2440,74 @@ ex_version(eap)
24352440
}
24362441
}
24372442

2443+
/*
2444+
* List all features aligned in columns, dictionary style.
2445+
*/
2446+
static void
2447+
list_features()
2448+
{
2449+
int i;
2450+
int ncol;
2451+
int nrow;
2452+
int nfeat = 0;
2453+
int width = 0;
2454+
2455+
/* Find the length of the longest feature name, use that + 1 as the column
2456+
* width */
2457+
for (i = 0; features[i] != NULL; ++i)
2458+
{
2459+
int l = STRLEN(features[i]);
2460+
2461+
if (l > width)
2462+
width = l;
2463+
++nfeat;
2464+
}
2465+
width += 1;
2466+
2467+
if (Columns < width)
2468+
{
2469+
/* Not enough screen columns - show one per line */
2470+
for (i = 0; features[i] != NULL; ++i)
2471+
{
2472+
version_msg(features[i]);
2473+
if (msg_col > 0)
2474+
msg_putchar('\n');
2475+
}
2476+
return;
2477+
}
2478+
2479+
ncol = (int) Columns / width;
2480+
/* The rightmost column doesn't need a separator.
2481+
* Sacrifice it to fit in one more column if possible. */
2482+
if (Columns % width == width - 1)
2483+
ncol++;
2484+
2485+
nrow = nfeat / ncol + (nfeat % ncol ? 1 : 0);
2486+
2487+
for (i = 0; !got_int && i < nrow * ncol; ++i)
2488+
{
2489+
int idx = (i / ncol) + (i % ncol) * nrow;
2490+
2491+
if (idx < nfeat)
2492+
{
2493+
int last_col = (i + 1) % ncol == 0;
2494+
2495+
msg_puts((char_u *)features[idx]);
2496+
if (last_col)
2497+
{
2498+
if (msg_col > 0)
2499+
msg_putchar('\n');
2500+
}
2501+
else
2502+
{
2503+
while (msg_col % width)
2504+
msg_putchar(' ');
2505+
}
2506+
}
2507+
else
2508+
msg_putchar('\n');
2509+
}
2510+
}
24382511
void
24392512
list_version()
24402513
{
@@ -2632,15 +2705,8 @@ list_version()
26322705
#endif
26332706
version_msg(_(" Features included (+) or not (-):\n"));
26342707

2635-
/* print all the features */
2636-
for (i = 0; features[i] != NULL; ++i)
2637-
{
2638-
version_msg(features[i]);
2639-
if (msg_col > 0)
2640-
version_msg(" ");
2641-
}
2708+
list_features();
26422709

2643-
version_msg("\n");
26442710
#ifdef SYS_VIMRC_FILE
26452711
version_msg(_(" system vimrc file: \""));
26462712
version_msg(SYS_VIMRC_FILE);

0 commit comments

Comments
 (0)