mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
:cquit : take an error code argument #7336
closes #2699 ex_cmds.lua: use flags consistent with similar commands such as `cnext`. upstream discussion: "[patch] :qcuit can take exit code" https://groups.google.com/d/msg/vim_dev/_PjyNbUKyRc/oPgr5_ZXc6AJ
This commit is contained in:
parent
bead15f10d
commit
9db42d4ce9
@ -138,11 +138,15 @@ processing a quickfix or location list command, it will be aborted.
|
|||||||
current window is used instead of the quickfix list.
|
current window is used instead of the quickfix list.
|
||||||
|
|
||||||
*:cq* *:cquit*
|
*:cq* *:cquit*
|
||||||
:cq[uit][!] Quit Vim with an error code, so that the compiler
|
:[count]cq[uit] Quit Nvim with an error code, or the code specified in
|
||||||
will not compile the same file again.
|
[count]. Useful when Nvim is called from another
|
||||||
WARNING: All changes in files are lost! Also when the
|
program: e.g. `git commit` will abort the comitting
|
||||||
[!] is not used. It works like ":qall!" |:qall|,
|
process, `fc` (built-in for shells like bash and zsh)
|
||||||
except that Vim returns a non-zero exit code.
|
will not execute the command.
|
||||||
|
|
||||||
|
WARNING: All changes in files are lost. It works like
|
||||||
|
":qall!" |:qall|, except that Nvim exits non-zero or
|
||||||
|
[count].
|
||||||
|
|
||||||
*:cf* *:cfile*
|
*:cf* *:cfile*
|
||||||
:cf[ile][!] [errorfile] Read the error file and jump to the first error.
|
:cf[ile][!] [errorfile] Read the error file and jump to the first error.
|
||||||
@ -1534,4 +1538,4 @@ by Vim.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:noet:tw=78:ts=8:ft=help:norl:
|
||||||
|
@ -620,7 +620,7 @@ return {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
command='cquit',
|
command='cquit',
|
||||||
flags=bit.bor(TRLBAR, BANG),
|
flags=bit.bor(RANGE, NOTADR, COUNT, ZEROR, TRLBAR, BANG),
|
||||||
addr_type=ADDR_LINES,
|
addr_type=ADDR_LINES,
|
||||||
func='ex_cquit',
|
func='ex_cquit',
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
@ -5995,7 +5996,7 @@ static void ex_quit(exarg_T *eap)
|
|||||||
*/
|
*/
|
||||||
static void ex_cquit(exarg_T *eap)
|
static void ex_cquit(exarg_T *eap)
|
||||||
{
|
{
|
||||||
getout(1);
|
getout(eap->addr_count > 0 ? (int)eap->line2 : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2,8 +2,12 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
|
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
local eq, neq = helpers.eq, helpers.neq
|
local eq = helpers.eq
|
||||||
local run = helpers.run
|
local run = helpers.run
|
||||||
|
local funcs = helpers.funcs
|
||||||
|
local nvim_prog = helpers.nvim_prog
|
||||||
|
local redir_exec = helpers.redir_exec
|
||||||
|
local wait = helpers.wait
|
||||||
|
|
||||||
describe('v:exiting', function()
|
describe('v:exiting', function()
|
||||||
local cid
|
local cid
|
||||||
@ -29,18 +33,53 @@ describe('v:exiting', function()
|
|||||||
end
|
end
|
||||||
run(on_request, nil, on_setup)
|
run(on_request, nil, on_setup)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
it('is non-zero after :cquit', function()
|
describe(':cquit', function()
|
||||||
local function on_setup()
|
local function test_cq(cmdline, exit_code, redir_msg)
|
||||||
command('autocmd VimLeavePre * call rpcrequest('..cid..', "")')
|
if redir_msg then
|
||||||
command('autocmd VimLeave * call rpcrequest('..cid..', "")')
|
eq('\n' .. redir_msg, redir_exec(cmdline))
|
||||||
command('cquit')
|
wait()
|
||||||
|
eq(2, eval("1+1")) -- Still alive?
|
||||||
|
else
|
||||||
|
funcs.system({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', '--cmd', cmdline})
|
||||||
|
eq(exit_code, eval('v:shell_error'))
|
||||||
end
|
end
|
||||||
local function on_request()
|
end
|
||||||
neq(0, eval('v:exiting'))
|
|
||||||
return ''
|
before_each(function()
|
||||||
end
|
helpers.clear()
|
||||||
run(on_request, nil, on_setup)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('exits with non-zero after :cquit', function()
|
||||||
|
test_cq('cquit', 1, nil)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with non-zero after :cquit 123', function()
|
||||||
|
test_cq('cquit 123', 123, nil)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with non-zero after :123 cquit', function()
|
||||||
|
test_cq('123 cquit', 123, nil)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with 0 after :cquit 0', function()
|
||||||
|
test_cq('cquit 0', 0, nil)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with 0 after :0 cquit', function()
|
||||||
|
test_cq('0 cquit', 0, nil)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with redir msg for multiple exit codes after :cquit 1 2', function()
|
||||||
|
test_cq('cquit 1 2', nil, 'E488: Trailing characters: cquit 1 2')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with redir msg for non-number exit code after :cquit X', function()
|
||||||
|
test_cq('cquit X', nil, 'E488: Trailing characters: cquit X')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('exits with redir msg for negative exit code after :cquit -1', function()
|
||||||
|
test_cq('cquit -1', nil, 'E488: Trailing characters: cquit -1')
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user