mirror of
https://github.com/neovim/neovim.git
synced 2025-12-02 06:53:05 +00:00
Merge PR #3611 'Add file selection prompt on ":oldfiles!"'
This commit is contained in:
@@ -1164,10 +1164,11 @@ running) you have additional options:
|
|||||||
:wv[iminfo][!] [file] Deprecated alias to |:wshada| command.
|
:wv[iminfo][!] [file] Deprecated alias to |:wshada| command.
|
||||||
|
|
||||||
*:o* *:ol* *:oldfiles*
|
*:o* *:ol* *:oldfiles*
|
||||||
:o[ldfiles] List the files that have marks stored in the ShaDa
|
:o[ldfiles][!] List the files that have marks stored in the ShaDa
|
||||||
file. This list is read on startup and only changes
|
file. This list is read on startup and only changes
|
||||||
afterwards with ":rshada!". Also see |v:oldfiles|.
|
afterwards with ":rshada!". Also see |v:oldfiles|.
|
||||||
The number can be used with |c_#<|.
|
The number can be used with |c_#<|.
|
||||||
|
Use ! to get a file selection prompt.
|
||||||
|
|
||||||
:bro[wse] o[ldfiles][!]
|
:bro[wse] o[ldfiles][!]
|
||||||
List file names as with |:oldfiles|, and then prompt
|
List file names as with |:oldfiles|, and then prompt
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ Additional differences:
|
|||||||
compatibility reasons.
|
compatibility reasons.
|
||||||
- |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old
|
- |:wviminfo| was renamed to |:wshada|, |:rviminfo| to |:rshada|. Old
|
||||||
commands are still kept.
|
commands are still kept.
|
||||||
|
- |:oldfiles| supports !.
|
||||||
- When writing (|:wshada| without bang or at exit) it merges much more data,
|
- When writing (|:wshada| without bang or at exit) it merges much more data,
|
||||||
and does this according to the timestamp. Vim merges only marks.
|
and does this according to the timestamp. Vim merges only marks.
|
||||||
|shada-merging|
|
|shada-merging|
|
||||||
|
|||||||
@@ -21208,9 +21208,9 @@ void last_set_msg(scid_T scriptID)
|
|||||||
*/
|
*/
|
||||||
void ex_oldfiles(exarg_T *eap)
|
void ex_oldfiles(exarg_T *eap)
|
||||||
{
|
{
|
||||||
list_T *l = vimvars[VV_OLDFILES].vv_list;
|
list_T *l = get_vim_var_list(VV_OLDFILES);
|
||||||
listitem_T *li;
|
listitem_T *li;
|
||||||
int nr = 0;
|
long nr = 0;
|
||||||
|
|
||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
msg((char_u *)_("No old files"));
|
msg((char_u *)_("No old files"));
|
||||||
@@ -21218,7 +21218,7 @@ void ex_oldfiles(exarg_T *eap)
|
|||||||
msg_start();
|
msg_start();
|
||||||
msg_scroll = TRUE;
|
msg_scroll = TRUE;
|
||||||
for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) {
|
for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) {
|
||||||
msg_outnum((long)++nr);
|
msg_outnum(++nr);
|
||||||
MSG_PUTS(": ");
|
MSG_PUTS(": ");
|
||||||
msg_outtrans(get_tv_string(&li->li_tv));
|
msg_outtrans(get_tv_string(&li->li_tv));
|
||||||
msg_putchar('\n');
|
msg_putchar('\n');
|
||||||
@@ -21228,6 +21228,23 @@ void ex_oldfiles(exarg_T *eap)
|
|||||||
/* Assume "got_int" was set to truncate the listing. */
|
/* Assume "got_int" was set to truncate the listing. */
|
||||||
got_int = FALSE;
|
got_int = FALSE;
|
||||||
|
|
||||||
|
// File selection prompt on ":oldfiles!"
|
||||||
|
if (eap->forceit) {
|
||||||
|
quit_more = false;
|
||||||
|
nr = prompt_for_number(false);
|
||||||
|
msg_starthere();
|
||||||
|
if (nr > 0 && nr <= l->lv_len) {
|
||||||
|
char_u *p = list_find_str(l, nr);
|
||||||
|
if (p == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p = expand_env_save(p);
|
||||||
|
eap->arg = p;
|
||||||
|
eap->cmdidx = CMD_edit;
|
||||||
|
do_exedit(eap, NULL);
|
||||||
|
xfree(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
test/functional/ex_cmds/oldfiles_spec.lua
Normal file
49
test/functional/ex_cmds/oldfiles_spec.lua
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
local h = require('test.functional.helpers')
|
||||||
|
|
||||||
|
local buf = h.curbufmeths
|
||||||
|
local command = h.command
|
||||||
|
local eq = h.eq
|
||||||
|
local execute = h.execute
|
||||||
|
local feed = h.feed
|
||||||
|
local nvim = h.nvim
|
||||||
|
|
||||||
|
local shada_file = 'test.shada'
|
||||||
|
|
||||||
|
-- h.clear() uses "-i NONE", which is not useful for this test.
|
||||||
|
local function clear()
|
||||||
|
if session then
|
||||||
|
session:exit(0)
|
||||||
|
end
|
||||||
|
h.set_session(h.spawn({h.nvim_prog,
|
||||||
|
'-u', 'NONE',
|
||||||
|
'--cmd', 'set noswapfile undodir=. directory=. viewdir=. backupdir=.',
|
||||||
|
'--embed'}))
|
||||||
|
end
|
||||||
|
|
||||||
|
describe(':oldfiles', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it('shows most recently used files', function()
|
||||||
|
command('edit testfile1')
|
||||||
|
command('edit testfile2')
|
||||||
|
command('wshada ' .. shada_file)
|
||||||
|
command('rshada! ' .. shada_file)
|
||||||
|
assert(string.find(nvim('command_output', 'oldfiles'), 'testfile2'))
|
||||||
|
os.remove(shada_file)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe(':oldfiles!', function()
|
||||||
|
it('provides a file selection prompt and edits the chosen file', function()
|
||||||
|
command('edit testfile1')
|
||||||
|
command('edit testfile2')
|
||||||
|
local filename = buf.get_name()
|
||||||
|
command('wshada ' .. shada_file)
|
||||||
|
clear()
|
||||||
|
command('rshada! ' .. shada_file)
|
||||||
|
execute('oldfiles!')
|
||||||
|
feed('2<cr>')
|
||||||
|
eq(filename, buf.get_name())
|
||||||
|
os.remove(shada_file)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user