aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-06-08 11:35:53 +0200
committerDaniel Hahler <git@thequod.de>2019-07-24 06:09:28 +0200
commite134cc9d4a13034401a1323e0515ceb19d43dfea (patch)
tree1eb5b729261951fa1747f91a1db3d9dfe03978fb
parent8fc93241d680f7c73e3013d679adb70c09cb3d57 (diff)
downloadrneovim-e134cc9d4a13034401a1323e0515ceb19d43dfea.tar.gz
rneovim-e134cc9d4a13034401a1323e0515ceb19d43dfea.tar.bz2
rneovim-e134cc9d4a13034401a1323e0515ceb19d43dfea.zip
vim-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. https://github.com/vim/vim/commit/5d69da462f584a3aefb3427b127334bf9af3a4b0 vim-patch:8.0.1740: warning for signed-unsigned incompatibility Problem: Warning for signed-unsigned incompatibility. Solution: Change type from "char *" to "char_u *". (John Marriott) https://github.com/vim/vim/commit/405dadb63ea2b7aa4c8c659807506a35a8a9504c Removes ported legacy test that was re-added later. Ref: https://github.com/neovim/neovim/pull/10147#issuecomment-512609513
-rw-r--r--src/nvim/ex_cmds2.c22
-rw-r--r--src/nvim/testdir/test_arglist.vim32
-rw-r--r--src/nvim/version.c93
-rw-r--r--test/functional/legacy/arglist_spec.lua68
4 files changed, 101 insertions, 114 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index c092036ce9..9e915dfc8b 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -43,6 +43,7 @@
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/undo.h"
+#include "nvim/version.h"
#include "nvim/window.h"
#include "nvim/profile.h"
#include "nvim/os/os.h"
@@ -1791,18 +1792,17 @@ void ex_args(exarg_T *eap)
} else if (eap->cmdidx == CMD_args) {
// ":args": list arguments.
if (ARGCOUNT > 0) {
- // Overwrite the command, for a short list there is no scrolling
- // required and no wait_return().
- gotocmdline(true);
- for (int i = 0; i < ARGCOUNT; i++) {
- if (i == curwin->w_arg_idx) {
- msg_putchar('[');
+ char_u **items = xmalloc(sizeof(char_u *) * (size_t)ARGCOUNT);
+
+ if (items != NULL) {
+ // Overwrite the command, for a short list there is no scrolling
+ // required and no wait_return().
+ gotocmdline(true);
+ for (int i = 0; i < ARGCOUNT; i++) {
+ items[i] = alist_name(&ARGLIST[i]);
}
- msg_outtrans(alist_name(&ARGLIST[i]));
- if (i == curwin->w_arg_idx) {
- msg_putchar(']');
- }
- msg_putchar(' ');
+ list_in_columns(items, ARGCOUNT, curwin->w_arg_idx);
+ xfree(items);
}
}
} else if (eap->cmdidx == CMD_arglocal) {
diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim
index 6468819198..6628a74b3c 100644
--- a/src/nvim/testdir/test_arglist.vim
+++ b/src/nvim/testdir/test_arglist.vim
@@ -123,9 +123,9 @@ func Test_argument()
call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers)
redir => result
- ar
+ args
redir END
- call assert_true(result =~# 'a b \[c] d')
+ call assert_equal('a b [c] d', trim(result))
.argd
call assert_equal(['a', 'b', 'd'], argv())
@@ -180,6 +180,34 @@ func Test_args_with_quote()
endif
endfunc
+func Test_list_arguments()
+ " Clean the argument list
+ arga a | %argd
+
+ " four args half the screen width makes two lines with two columns
+ let aarg = repeat('a', &columns / 2 - 4)
+ let barg = repeat('b', &columns / 2 - 4)
+ let carg = repeat('c', &columns / 2 - 4)
+ let darg = repeat('d', &columns / 2 - 4)
+ exe 'argadd ' aarg barg carg darg
+
+ redir => result
+ args
+ redir END
+ call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result))
+
+ " if one arg is longer than half the screen make one column
+ exe 'argdel' aarg
+ let aarg = repeat('a', &columns / 2 + 2)
+ exe '0argadd' aarg
+ redir => result
+ args
+ redir END
+ call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result))
+
+ %argdelete
+endfunc
+
" Test for 0argadd and 0argedit
" Ported from the test_argument_0count.in test script
func Test_zero_argadd()
diff --git a/src/nvim/version.c b/src/nvim/version.c
index f85607be77..ee5a12feb0 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -2002,29 +2002,69 @@ void ex_version(exarg_T *eap)
}
}
+/// Output a string for the version message. If it's going to wrap, output a
+/// newline, unless the message is too long to fit on the screen anyway.
+/// When "wrap" is TRUE wrap the string in [].
+/// @param s
+/// @param wrap
+static void version_msg_wrap(char_u *s, int wrap)
+{
+ int len = (int)vim_strsize(s) + (wrap ? 2 : 0);
+
+ if (!got_int
+ && (len < Columns)
+ && (msg_col + len >= Columns)
+ && (*s != '\n')) {
+ msg_putchar('\n');
+ }
+
+ if (!got_int) {
+ if (wrap) {
+ msg_puts("[");
+ }
+ msg_puts((char *)s);
+ if (wrap) {
+ msg_puts("]");
+ }
+ }
+}
+
+static void version_msg(char *s)
+{
+ version_msg_wrap((char_u *)s, false);
+}
+
/// List all features aligned in columns, dictionary style.
static void list_features(void)
{
- int nfeat = 0;
+ list_in_columns((char_u **)features, -1, -1);
+ MSG_PUTS("See \":help feature-compile\"\n\n");
+}
+
+/// List string items nicely aligned in columns.
+/// When "size" is < 0 then the last entry is marked with NULL.
+/// The entry with index "current" is inclosed in [].
+void list_in_columns(char_u **items, int size, int current)
+{
+ int item_count = 0;
int width = 0;
- // Find the length of the longest feature name, use that + 1 as the column
- // width
+ // Find the length of the longest item, use that + 1 as the column width.
int i;
- for (i = 0; features[i] != NULL; ++i) {
- int l = (int)STRLEN(features[i]);
+ for (i = 0; size < 0 ? items[i] != NULL : i < size; i++) {
+ int l = (int)vim_strsize(items[i]) + (i == current ? 2 : 0);
if (l > width) {
width = l;
}
- nfeat++;
+ item_count++;
}
width += 1;
if (Columns < width) {
// Not enough screen columns - show one per line
- for (i = 0; features[i] != NULL; ++i) {
- version_msg(features[i]);
+ for (i = 0; items[i] != NULL; i++) {
+ version_msg_wrap(items[i], i == current);
if (msg_col > 0) {
msg_putchar('\n');
}
@@ -2035,20 +2075,28 @@ static void list_features(void)
// The rightmost column doesn't need a separator.
// Sacrifice it to fit in one more column if possible.
int ncol = (int)(Columns + 1) / width;
- int nrow = nfeat / ncol + (nfeat % ncol ? 1 : 0);
+ int nrow = item_count / ncol + (item_count % ncol ? 1 : 0);
// i counts columns then rows. idx counts rows then columns.
for (i = 0; !got_int && i < nrow * ncol; ++i) {
int idx = (i / ncol) + (i % ncol) * nrow;
- if (idx < nfeat) {
+ if (idx < item_count) {
int last_col = (i + 1) % ncol == 0;
- msg_puts(features[idx]);
+ if (idx == current) {
+ msg_putchar('[');
+ }
+ msg_puts((char *)items[idx]);
+ if (idx == current) {
+ msg_putchar(']');
+ }
if (last_col) {
if (msg_col > 0) {
msg_putchar('\n');
}
} else {
- msg_putchar(' ');
+ while (msg_col % width) {
+ msg_putchar(' ');
+ }
}
} else {
if (msg_col > 0) {
@@ -2056,7 +2104,6 @@ static void list_features(void)
}
}
}
- MSG_PUTS("See \":help feature-compile\"\n\n");
}
void list_lua_version(void)
@@ -2121,26 +2168,6 @@ void list_version(void)
version_msg("\nRun :checkhealth for more info");
}
-/// Output a string for the version message. If it's going to wrap, output a
-/// newline, unless the message is too long to fit on the screen anyway.
-///
-/// @param s
-static void version_msg(char *s)
-{
- int len = (int)STRLEN(s);
-
- if (!got_int
- && (len < Columns)
- && (msg_col + len >= Columns)
- && (*s != '\n')) {
- msg_putchar('\n');
- }
-
- if (!got_int) {
- MSG_PUTS(s);
- }
-}
-
/// Show the intro message when not editing a file.
void maybe_intro_message(void)
diff --git a/test/functional/legacy/arglist_spec.lua b/test/functional/legacy/arglist_spec.lua
index bd65e549ef..241a19d940 100644
--- a/test/functional/legacy/arglist_spec.lua
+++ b/test/functional/legacy/arglist_spec.lua
@@ -92,74 +92,6 @@ describe('argument list commands', function()
eq(0, eval('len(argv())'))
end)
- it('test for [count]argument and [count]argdelete commands', function()
- reset_arglist()
- command('let save_hidden = &hidden')
- command('set hidden')
- command('let g:buffers = []')
- command('augroup TEST')
- command([[au BufEnter * call add(buffers, expand('%:t'))]])
- command('augroup END')
-
- command('argadd a b c d')
- command('$argu')
- command('$-argu')
- command('-argu')
- command('1argu')
- command('+2argu')
-
- command('augroup TEST')
- command('au!')
- command('augroup END')
-
- eq({'d', 'c', 'b', 'a', 'c'}, eval('g:buffers'))
-
- command('redir => result')
- command('ar')
- command('redir END')
- eq(1, eval([[result =~# 'a b \[c] d']]))
-
- command('.argd')
- eq({'a', 'b', 'd'}, eval('argv()'))
-
- command('-argd')
- eq({'a', 'd'}, eval('argv()'))
-
- command('$argd')
- eq({'a'}, eval('argv()'))
-
- command('1arga c')
- command('1arga b')
- command('$argu')
- command('$arga x')
- eq({'a', 'b', 'c', 'x'}, eval('argv()'))
-
- command('0arga Y')
- eq({'Y', 'a', 'b', 'c', 'x'}, eval('argv()'))
-
- command('%argd')
- eq({}, eval('argv()'))
-
- command('arga a b c d e f')
- command('2,$-argd')
- eq({'a', 'f'}, eval('argv()'))
-
- command('let &hidden = save_hidden')
-
- -- Setting the argument list should fail when the current buffer has
- -- unsaved changes
- command('%argd')
- command('enew!')
- command('set modified')
- assert_fails('args x y z', 'E37:')
- command('args! x y z')
- eq({'x', 'y', 'z'}, eval('argv()'))
- eq('x', eval('expand("%:t")'))
-
- command('%argdelete')
- assert_fails('argument', 'E163:')
- end)
-
it('test for 0argadd and 0argedit', function()
reset_arglist()