mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 19:25:11 -07:00
Merge #9034 'swapfile: always show dialog'
This commit is contained in:
commit
f8f83579ff
@ -535,6 +535,7 @@ void ml_open_file(buf_T *buf)
|
||||
void check_need_swap(int newfile)
|
||||
{
|
||||
int old_msg_silent = msg_silent; // might be reset by an E325 message
|
||||
msg_silent = 0; // If swap dialog prompts for input, user needs to see it!
|
||||
|
||||
if (curbuf->b_may_swap && (!curbuf->b_p_ro || !newfile)) {
|
||||
ml_open_file(curbuf);
|
||||
|
@ -1269,7 +1269,8 @@ static void normal_redraw(NormalState *s)
|
||||
xfree(p);
|
||||
}
|
||||
|
||||
if (need_fileinfo) { // show file info after redraw
|
||||
// show fileinfo after redraw
|
||||
if (need_fileinfo && !shortmess(SHM_FILEINFO)) {
|
||||
fileinfo(false, true, false);
|
||||
need_fileinfo = false;
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local lfs = require('lfs')
|
||||
local feed_command, eq, clear, eval, feed, expect, source =
|
||||
helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed,
|
||||
helpers.expect, helpers.source
|
||||
local command = helpers.command
|
||||
local ok = helpers.ok
|
||||
local rmdir = helpers.rmdir
|
||||
|
||||
describe(':recover', function()
|
||||
before_each(clear)
|
||||
|
||||
it('fails if given a non-existent swapfile', function()
|
||||
local swapname = 'bogus-swapfile'
|
||||
feed_command('recover '..swapname) -- This should not segfault. #2117
|
||||
eq('E305: No swap file found for '..swapname, eval('v:errmsg'))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe(':preserve', function()
|
||||
local swapdir = lfs.currentdir()..'/testdir_recover_spec'
|
||||
before_each(function()
|
||||
clear()
|
||||
rmdir(swapdir)
|
||||
lfs.mkdir(swapdir)
|
||||
end)
|
||||
after_each(function()
|
||||
command('%bwipeout!')
|
||||
rmdir(swapdir)
|
||||
end)
|
||||
|
||||
it("saves to custom 'directory' and (R)ecovers (issue #1836)", function()
|
||||
local testfile = 'testfile_recover_spec'
|
||||
-- Put swapdir at the start of the 'directory' list. #1836
|
||||
-- Note: `set swapfile` *must* go after `set directory`: otherwise it may
|
||||
-- attempt to create a swapfile in different directory.
|
||||
local init = [[
|
||||
set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
|
||||
set swapfile fileformat=unix undolevels=-1
|
||||
]]
|
||||
|
||||
source(init)
|
||||
command('edit! '..testfile)
|
||||
feed('isometext<esc>')
|
||||
command('preserve')
|
||||
source('redir => g:swapname | silent swapname | redir END')
|
||||
|
||||
local swappath1 = eval('g:swapname')
|
||||
|
||||
--TODO(justinmk): this is an ugly hack to force `helpers` to support
|
||||
--multiple sessions.
|
||||
local nvim2 = helpers.spawn({helpers.nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'},
|
||||
true)
|
||||
helpers.set_session(nvim2)
|
||||
|
||||
source(init)
|
||||
|
||||
-- Use the "SwapExists" event to choose the (R)ecover choice at the dialog.
|
||||
command('autocmd SwapExists * let v:swapchoice = "r"')
|
||||
command('silent edit! '..testfile)
|
||||
source('redir => g:swapname | silent swapname | redir END')
|
||||
|
||||
local swappath2 = eval('g:swapname')
|
||||
|
||||
expect('sometext')
|
||||
-- swapfile from session 1 should end in .swp
|
||||
eq(testfile..'.swp', string.match(swappath1, '[^%%]+$'))
|
||||
-- swapfile from session 2 should end in .swo
|
||||
eq(testfile..'.swo', string.match(swappath2, '[^%%]+$'))
|
||||
-- Verify that :swapname was not truncated (:help 'shortmess').
|
||||
ok(nil == string.find(swappath1, '%.%.%.'))
|
||||
ok(nil == string.find(swappath2, '%.%.%.'))
|
||||
end)
|
||||
|
||||
end)
|
154
test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
Normal file
154
test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
Normal file
@ -0,0 +1,154 @@
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local lfs = require('lfs')
|
||||
local feed_command, eq, eval, expect, source =
|
||||
helpers.feed_command, helpers.eq, helpers.eval, helpers.expect, helpers.source
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local feed = helpers.feed
|
||||
local nvim_prog = helpers.nvim_prog
|
||||
local ok = helpers.ok
|
||||
local rmdir = helpers.rmdir
|
||||
local set_session = helpers.set_session
|
||||
local spawn = helpers.spawn
|
||||
|
||||
describe(':recover', function()
|
||||
before_each(clear)
|
||||
|
||||
it('fails if given a non-existent swapfile', function()
|
||||
local swapname = 'bogus-swapfile'
|
||||
feed_command('recover '..swapname) -- This should not segfault. #2117
|
||||
eq('E305: No swap file found for '..swapname, eval('v:errmsg'))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe(':preserve', function()
|
||||
local swapdir = lfs.currentdir()..'/Xtest_recover_dir'
|
||||
before_each(function()
|
||||
clear()
|
||||
rmdir(swapdir)
|
||||
lfs.mkdir(swapdir)
|
||||
end)
|
||||
after_each(function()
|
||||
command('%bwipeout!')
|
||||
rmdir(swapdir)
|
||||
end)
|
||||
|
||||
it("saves to custom 'directory' and (R)ecovers #1836", function()
|
||||
local testfile = 'Xtest_recover_file1'
|
||||
-- Put swapdir at the start of the 'directory' list. #1836
|
||||
-- Note: `set swapfile` *must* go after `set directory`: otherwise it may
|
||||
-- attempt to create a swapfile in different directory.
|
||||
local init = [[
|
||||
set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
|
||||
set swapfile fileformat=unix undolevels=-1
|
||||
]]
|
||||
|
||||
source(init)
|
||||
command('edit! '..testfile)
|
||||
feed('isometext<esc>')
|
||||
command('preserve')
|
||||
source('redir => g:swapname | silent swapname | redir END')
|
||||
|
||||
local swappath1 = eval('g:swapname')
|
||||
|
||||
-- Start another Nvim instance.
|
||||
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'},
|
||||
true)
|
||||
set_session(nvim2)
|
||||
|
||||
source(init)
|
||||
|
||||
-- Use the "SwapExists" event to choose the (R)ecover choice at the dialog.
|
||||
command('autocmd SwapExists * let v:swapchoice = "r"')
|
||||
command('silent edit! '..testfile)
|
||||
source('redir => g:swapname | silent swapname | redir END')
|
||||
|
||||
local swappath2 = eval('g:swapname')
|
||||
|
||||
expect('sometext')
|
||||
-- swapfile from session 1 should end in .swp
|
||||
eq(testfile..'.swp', string.match(swappath1, '[^%%]+$'))
|
||||
-- swapfile from session 2 should end in .swo
|
||||
eq(testfile..'.swo', string.match(swappath2, '[^%%]+$'))
|
||||
-- Verify that :swapname was not truncated (:help 'shortmess').
|
||||
ok(nil == string.find(swappath1, '%.%.%.'))
|
||||
ok(nil == string.find(swappath2, '%.%.%.'))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('swapfile detection', function()
|
||||
local swapdir = lfs.currentdir()..'/Xtest_swapdialog_dir'
|
||||
before_each(function()
|
||||
clear()
|
||||
rmdir(swapdir)
|
||||
lfs.mkdir(swapdir)
|
||||
end)
|
||||
after_each(function()
|
||||
command('%bwipeout!')
|
||||
rmdir(swapdir)
|
||||
end)
|
||||
|
||||
it('always show swapfile dialog #8840 #9027', function()
|
||||
local testfile = 'Xtest_swapdialog_file1'
|
||||
-- Put swapdir at the start of the 'directory' list. #1836
|
||||
-- Note: `set swapfile` *must* go after `set directory`: otherwise it may
|
||||
-- attempt to create a swapfile in different directory.
|
||||
local init = [[
|
||||
set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[//
|
||||
set swapfile fileformat=unix undolevels=-1 hidden
|
||||
]]
|
||||
|
||||
local expected_no_dialog = '^'..(' '):rep(256)..'|\n'
|
||||
for _=1,37 do
|
||||
expected_no_dialog = expected_no_dialog..'~'..(' '):rep(255)..'|\n'
|
||||
end
|
||||
expected_no_dialog = expected_no_dialog..testfile..(' '):rep(216)..'0,0-1 All|\n'
|
||||
expected_no_dialog = expected_no_dialog..(' '):rep(256)..'|\n'
|
||||
|
||||
source(init)
|
||||
command('edit! '..testfile)
|
||||
feed('isometext<esc>')
|
||||
command('preserve')
|
||||
|
||||
-- Start another Nvim instance.
|
||||
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'},
|
||||
true)
|
||||
set_session(nvim2)
|
||||
local screen2 = Screen.new(256, 40)
|
||||
screen2:attach()
|
||||
source(init)
|
||||
|
||||
-- With shortmess+=F
|
||||
command('set shortmess+=F')
|
||||
feed(':edit '..testfile..'<CR>')
|
||||
screen2:expect{any=[[E325: ATTENTION.*]]..'\n'..[[Found a swap file by the name ".*]]
|
||||
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
||||
feed('e') -- Chose "Edit" at the swap dialog.
|
||||
screen2:expect(expected_no_dialog)
|
||||
|
||||
-- With :silent and shortmess+=F
|
||||
feed(':silent edit %<CR>')
|
||||
screen2:expect{any=[[Found a swap file by the name ".*]]
|
||||
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
||||
feed('e') -- Chose "Edit" at the swap dialog.
|
||||
screen2:expect(expected_no_dialog)
|
||||
|
||||
-- With :silent! and shortmess+=F
|
||||
feed(':silent! edit %<CR>')
|
||||
screen2:expect{any=[[Found a swap file by the name ".*]]
|
||||
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
||||
feed('e') -- Chose "Edit" at the swap dialog.
|
||||
screen2:expect(expected_no_dialog)
|
||||
|
||||
-- With API (via eval/VimL) call and shortmess+=F
|
||||
feed(':call nvim_command("edit %")<CR>')
|
||||
screen2:expect{any=[[Found a swap file by the name ".*]]
|
||||
..[[Xtest_swapdialog_dir[/\].*]]..testfile..[[%.swp"]]}
|
||||
feed('e') -- Chose "Edit" at the swap dialog.
|
||||
feed('<c-c>')
|
||||
screen2:expect(expected_no_dialog)
|
||||
end)
|
||||
end)
|
@ -1,43 +1,96 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
local clear = helpers.clear
|
||||
local command = helpers.command
|
||||
local clear, feed_command = helpers.clear, helpers.feed_command
|
||||
|
||||
if helpers.pending_win32(pending) then return end
|
||||
local eq = helpers.eq
|
||||
local eval = helpers.eval
|
||||
local feed = helpers.feed
|
||||
|
||||
describe("'shortmess'", function()
|
||||
local screen
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = Screen.new(25, 5)
|
||||
screen = Screen.new(42, 5)
|
||||
screen:attach()
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
screen:detach()
|
||||
end)
|
||||
|
||||
describe('"F" flag', function()
|
||||
it('hides messages about the files read', function()
|
||||
command("set shortmess-=F")
|
||||
feed_command('e test')
|
||||
it('hides :edit fileinfo messages', function()
|
||||
command('set hidden')
|
||||
command('set shortmess-=F')
|
||||
feed(':edit foo<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
"test" is a directory |
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
"foo" [New File] |
|
||||
]])
|
||||
feed_command('set shortmess=F')
|
||||
feed_command('e test')
|
||||
eq(1, eval('bufnr("%")'))
|
||||
|
||||
command('set shortmess+=F')
|
||||
feed(':edit bar<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
:e test |
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
:edit bar |
|
||||
]])
|
||||
eq(2, eval('bufnr("%")'))
|
||||
end)
|
||||
|
||||
it('hides :bnext, :bprevious fileinfo messages', function()
|
||||
command('set hidden')
|
||||
command('set shortmess-=F')
|
||||
feed(':edit foo<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
"foo" [New File] |
|
||||
]])
|
||||
eq(1, eval('bufnr("%")'))
|
||||
feed(':edit bar<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
"bar" [New File] |
|
||||
]])
|
||||
eq(2, eval('bufnr("%")'))
|
||||
feed(':bprevious<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
"foo" [New file] --No lines in buffer-- |
|
||||
]])
|
||||
eq(1, eval('bufnr("%")'))
|
||||
|
||||
command('set shortmess+=F')
|
||||
feed(':bnext<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
:bnext |
|
||||
]])
|
||||
eq(2, eval('bufnr("%")'))
|
||||
feed(':bprevious<CR>')
|
||||
screen:expect([[
|
||||
^ |
|
||||
~ |
|
||||
~ |
|
||||
~ |
|
||||
:bprevious |
|
||||
]])
|
||||
eq(1, eval('bufnr("%")'))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
@ -40,24 +40,24 @@ describe('highlight: `:syntax manual`', function()
|
||||
end)
|
||||
|
||||
it("works with buffer switch and 'hidden'", function()
|
||||
feed_command('e tmp1.vim')
|
||||
feed_command('e Xtest-functional-ui-highlight.tmp.vim')
|
||||
feed_command('filetype on')
|
||||
feed_command('syntax manual')
|
||||
feed_command('set ft=vim')
|
||||
feed_command('set syntax=ON')
|
||||
command('e tmp1.vim')
|
||||
command('e Xtest-functional-ui-highlight.tmp.vim')
|
||||
command('filetype on')
|
||||
command('syntax manual')
|
||||
command('set ft=vim')
|
||||
command('set syntax=ON')
|
||||
feed('iecho 1<esc>0')
|
||||
|
||||
feed_command('set hidden')
|
||||
feed_command('w')
|
||||
feed_command('bn')
|
||||
command('set hidden')
|
||||
command('w')
|
||||
command('bn')
|
||||
feed_command('bp')
|
||||
screen:expect([[
|
||||
{1:^echo} 1 |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
<f 1 --100%-- col 1 |
|
||||
:bp |
|
||||
]])
|
||||
end)
|
||||
|
||||
@ -919,7 +919,7 @@ describe("'winhighlight' highlight", function()
|
||||
aa |
|
||||
{0:~ }|
|
||||
{4:[No Name] [+] }|
|
||||
<f 1 --100%-- col 1 |
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
|
@ -645,8 +645,38 @@ local function hexdump(str)
|
||||
return dump .. hex .. string.rep(" ", 8 - len % 8) .. asc
|
||||
end
|
||||
|
||||
local function read_file(name)
|
||||
local file = io.open(name, 'r')
|
||||
-- Reads text lines from `filename` into a table.
|
||||
--
|
||||
-- filename: path to file
|
||||
-- start: start line (1-indexed), negative means "lines before end" (tail)
|
||||
local function read_file_list(filename, start)
|
||||
local lnum = (start ~= nil and type(start) == 'number') and start or 1
|
||||
local tail = (lnum < 0)
|
||||
local maxlines = tail and math.abs(lnum) or nil
|
||||
local file = io.open(filename, 'r')
|
||||
if not file then
|
||||
return nil
|
||||
end
|
||||
local lines = {}
|
||||
local i = 1
|
||||
for line in file:lines() do
|
||||
if i >= start then
|
||||
table.insert(lines, line)
|
||||
if #lines > maxlines then
|
||||
table.remove(lines, 1)
|
||||
end
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
file:close()
|
||||
return lines
|
||||
end
|
||||
|
||||
-- Reads the entire contents of `filename` into a string.
|
||||
--
|
||||
-- filename: path to file
|
||||
local function read_file(filename)
|
||||
local file = io.open(filename, 'r')
|
||||
if not file then
|
||||
return nil
|
||||
end
|
||||
@ -684,18 +714,13 @@ end
|
||||
-- Also removes the file, if the current environment looks like CI.
|
||||
local function read_nvim_log()
|
||||
local logfile = os.getenv('NVIM_LOG_FILE') or '.nvimlog'
|
||||
local logtext = read_file(logfile)
|
||||
local lines = {}
|
||||
for l in string.gmatch(logtext or '', "[^\n]+") do -- Split at newlines.
|
||||
table.insert(lines, l)
|
||||
end
|
||||
local keep = isCI() and 999 or 10
|
||||
local lines = read_file_list(logfile, -keep) or {}
|
||||
local log = (('-'):rep(78)..'\n'
|
||||
..string.format('$NVIM_LOG_FILE: %s\n', logfile)
|
||||
..(logtext and (isCI() and '' or '(last 10 lines)\n') or '(empty)\n'))
|
||||
local keep = (isCI() and #lines or math.min(10, #lines))
|
||||
local startidx = math.max(1, #lines - keep + 1)
|
||||
for i = startidx, (startidx + keep - 1) do
|
||||
log = log..lines[i]..'\n'
|
||||
..(#lines > 0 and '(last '..tostring(keep)..' lines)\n' or '(empty)\n'))
|
||||
for _,line in ipairs(lines) do
|
||||
log = log..line..'\n'
|
||||
end
|
||||
log = log..('-'):rep(78)..'\n'
|
||||
if isCI() then
|
||||
@ -733,6 +758,7 @@ local module = {
|
||||
popen_r = popen_r,
|
||||
popen_w = popen_w,
|
||||
read_file = read_file,
|
||||
read_file_list = read_file_list,
|
||||
read_nvim_log = read_nvim_log,
|
||||
repeated_read_cmd = repeated_read_cmd,
|
||||
shallowcopy = shallowcopy,
|
||||
|
Loading…
Reference in New Issue
Block a user