Skip to content

Commit 5d69da4

Browse files
committed
patch 8.0.1738: ":args" output is hard to read
Problem: ":args" output is hard to read. Solution: Make columns with the names if the output is more than one line.
1 parent 02e802b commit 5d69da4

4 files changed

Lines changed: 99 additions & 40 deletions

File tree

‎src/ex_cmds2.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,17 +2751,18 @@ ex_args(exarg_T *eap)
27512751
*/
27522752
if (ARGCOUNT > 0)
27532753
{
2754-
/* Overwrite the command, for a short list there is no scrolling
2755-
* required and no wait_return(). */
2756-
gotocmdline(TRUE);
2757-
for (i = 0; i < ARGCOUNT; ++i)
2754+
char **items = (char **)alloc(sizeof(char *) * ARGCOUNT);
2755+
2756+
if (items != NULL)
27582757
{
2759-
if (i == curwin->w_arg_idx)
2760-
msg_putchar('[');
2761-
msg_outtrans(alist_name(&ARGLIST[i]));
2762-
if (i == curwin->w_arg_idx)
2763-
msg_putchar(']');
2764-
msg_putchar(' ');
2758+
/* Overwrite the command, for a short list there is no
2759+
* scrolling required and no wait_return(). */
2760+
gotocmdline(TRUE);
2761+
2762+
for (i = 0; i < ARGCOUNT; ++i)
2763+
items[i] = (char *)alist_name(&ARGLIST[i]);
2764+
list_in_columns(items, ARGCOUNT, curwin->w_arg_idx);
2765+
vim_free(items);
27652766
}
27662767
}
27672768
}

‎src/proto/version.pro‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ void make_version(void);
33
int highest_patch(void);
44
int has_patch(int n);
55
void ex_version(exarg_T *eap);
6+
void list_in_columns(char_u **items, int size, int current);
67
void list_version(void);
78
void maybe_intro_message(void);
89
void intro_message(int colon);

‎src/testdir/test_arglist.vim‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ func Test_argument()
122122
call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
123123

124124
redir => result
125-
ar
125+
args
126126
redir END
127-
call assert_true(result =~# 'a b \[c] d')
127+
call assert_equal('a b [c] d', trim(result))
128128

129129
.argd
130130
call assert_equal(['a', 'b', 'd'], argv())
@@ -170,6 +170,34 @@ func Test_argument()
170170
call assert_fails('argument', 'E163:')
171171
endfunc
172172

173+
func Test_list_arguments()
174+
" Clean the argument list
175+
arga a | %argd
176+
177+
" four args half the screen width makes two lines with two columns
178+
let aarg = repeat('a', &columns / 2 - 4)
179+
let barg = repeat('b', &columns / 2 - 4)
180+
let carg = repeat('c', &columns / 2 - 4)
181+
let darg = repeat('d', &columns / 2 - 4)
182+
exe 'argadd ' aarg barg carg darg
183+
184+
redir => result
185+
args
186+
redir END
187+
call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
188+
189+
" if one arg is longer than half the screen make one column
190+
exe 'argdel' aarg
191+
let aarg = repeat('a', &columns / 2 + 2)
192+
exe '0argadd' aarg
193+
redir => result
194+
args
195+
redir END
196+
call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
197+
198+
%argdelete
199+
endfunc
200+
173201
" Test for 0argadd and 0argedit
174202
" Ported from the test_argument_0count.in test script
175203
func Test_zero_argadd()

‎src/version.c‎

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ char *longVersion = VIM_VERSION_LONG;
5757
#endif
5858

5959
static void list_features(void);
60-
static void version_msg(char *s);
6160

6261
static char *(features[]) =
6362
{
@@ -762,6 +761,8 @@ static char *(features[]) =
762761

763762
static int included_patches[] =
764763
{ /* Add new patch number below this line */
764+
/**/
765+
1738,
765766
/**/
766767
1737,
767768
/**/
@@ -4294,36 +4295,76 @@ ex_version(exarg_T *eap)
42944295
}
42954296
}
42964297

4298+
/*
4299+
* Output a string for the version message. If it's going to wrap, output a
4300+
* newline, unless the message is too long to fit on the screen anyway.
4301+
* When "wrap" is TRUE wrap the string in [].
4302+
*/
4303+
static void
4304+
version_msg_wrap(char_u *s, int wrap)
4305+
{
4306+
int len = (int)vim_strsize(s) + (wrap ? 2 : 0);
4307+
4308+
if (!got_int && len < (int)Columns && msg_col + len >= (int)Columns
4309+
&& *s != '\n')
4310+
msg_putchar('\n');
4311+
if (!got_int)
4312+
{
4313+
if (wrap)
4314+
MSG_PUTS("[");
4315+
MSG_PUTS(s);
4316+
if (wrap)
4317+
MSG_PUTS("]");
4318+
}
4319+
}
4320+
4321+
static void
4322+
version_msg(char *s)
4323+
{
4324+
version_msg_wrap((char_u *)s, FALSE);
4325+
}
4326+
42974327
/*
42984328
* List all features aligned in columns, dictionary style.
42994329
*/
43004330
static void
43014331
list_features(void)
4332+
{
4333+
list_in_columns((char_u **)features, -1, -1);
4334+
}
4335+
4336+
/*
4337+
* List string items nicely aligned in columns.
4338+
* When "size" is < 0 then the last entry is marked with NULL.
4339+
* The entry with index "current" is inclosed in [].
4340+
*/
4341+
void
4342+
list_in_columns(char_u **items, int size, int current)
43024343
{
43034344
int i;
43044345
int ncol;
43054346
int nrow;
4306-
int nfeat = 0;
4347+
int item_count = 0;
43074348
int width = 0;
43084349

4309-
/* Find the length of the longest feature name, use that + 1 as the column
4310-
* width */
4311-
for (i = 0; features[i] != NULL; ++i)
4350+
/* Find the length of the longest item, use that + 1 as the column
4351+
* width. */
4352+
for (i = 0; size < 0 ? items[i] != NULL : i < size; ++i)
43124353
{
4313-
int l = (int)STRLEN(features[i]);
4354+
int l = (int)vim_strsize(items[i]) + (i == current ? 2 : 0);
43144355

43154356
if (l > width)
43164357
width = l;
4317-
++nfeat;
4358+
++item_count;
43184359
}
43194360
width += 1;
43204361

43214362
if (Columns < width)
43224363
{
43234364
/* Not enough screen columns - show one per line */
4324-
for (i = 0; features[i] != NULL; ++i)
4365+
for (i = 0; items[i] != NULL; ++i)
43254366
{
4326-
version_msg(features[i]);
4367+
version_msg_wrap(items[i], i == current);
43274368
if (msg_col > 0)
43284369
msg_putchar('\n');
43294370
}
@@ -4333,18 +4374,22 @@ list_features(void)
43334374
/* The rightmost column doesn't need a separator.
43344375
* Sacrifice it to fit in one more column if possible. */
43354376
ncol = (int) (Columns + 1) / width;
4336-
nrow = nfeat / ncol + (nfeat % ncol ? 1 : 0);
4377+
nrow = item_count / ncol + (item_count % ncol ? 1 : 0);
43374378

43384379
/* i counts columns then rows. idx counts rows then columns. */
43394380
for (i = 0; !got_int && i < nrow * ncol; ++i)
43404381
{
43414382
int idx = (i / ncol) + (i % ncol) * nrow;
43424383

4343-
if (idx < nfeat)
4384+
if (idx < item_count)
43444385
{
43454386
int last_col = (i + 1) % ncol == 0;
43464387

4347-
msg_puts((char_u *)features[idx]);
4388+
if (idx == current)
4389+
msg_putchar('[');
4390+
msg_puts(items[idx]);
4391+
if (idx == current)
4392+
msg_putchar(']');
43484393
if (last_col)
43494394
{
43504395
if (msg_col > 0)
@@ -4636,22 +4681,6 @@ list_version(void)
46364681
#endif
46374682
}
46384683

4639-
/*
4640-
* Output a string for the version message. If it's going to wrap, output a
4641-
* newline, unless the message is too long to fit on the screen anyway.
4642-
*/
4643-
static void
4644-
version_msg(char *s)
4645-
{
4646-
int len = (int)STRLEN(s);
4647-
4648-
if (!got_int && len < (int)Columns && msg_col + len >= (int)Columns
4649-
&& *s != '\n')
4650-
msg_putchar('\n');
4651-
if (!got_int)
4652-
MSG_PUTS(s);
4653-
}
4654-
46554684
static void do_intro_line(int row, char_u *mesg, int add_version, int attr);
46564685

46574686
/*

0 commit comments

Comments
 (0)