]> granicus.if.org Git - vim/commitdiff
patch 8.2.0095: cannot specify exit code for :cquit v8.2.0095
authorBram Moolenaar <Bram@vim.org>
Mon, 6 Jan 2020 20:47:21 +0000 (21:47 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 6 Jan 2020 20:47:21 +0000 (21:47 +0100)
Problem:    Cannot specify exit code for :cquit.
Solution:   Add optional argument. (Thinca, Yegappan Lakshmanan, closes #5442)

runtime/doc/quickfix.txt
src/ex_cmds.h
src/ex_docmd.c
src/testdir/test_quickfix.vim
src/version.c

index 5879727d2bed2f3115af8360a16165401cda2f94..ae45819156b98805ee9ed9c10baf60d741591c38 100644 (file)
@@ -229,8 +229,17 @@ processing a quickfix or location list command, it will be aborted.
                        current window is used instead of the quickfix list.
 
                                                        *:cq* *:cquit*
-:cq[uit][!]            Quit Vim with an error code, so that the compiler
-                       will not compile the same file again.
+:cq[uit][!]
+:{N}cq[uit][!]
+:cq[uit][!] {N}                Quit Vim with error code {N}.  {N} defaults to one.
+                       Useful when Vim is called from another program:
+                       e.g., a compiler will not compile the same file again,
+                       `git commit` will abort the committing process, `fc`
+                       (built-in for shells like bash and zsh) will not
+                       execute the command, etc.  will not compile the same
+                       file again.
+                       {N} can also be zero, in which case Vim exits
+                       normally.
                        WARNING: All changes in files are lost!  Also when the
                        [!] is not used.  It works like ":qall!" |:qall|,
                        except that Vim returns a non-zero exit code.
index 14b43bda4410dc557f1430aa3ef6192839628bb7..928b1100d8206c0c6105e8eedaacb39145985972 100644 (file)
@@ -407,7 +407,7 @@ EXCMD(CMD_cpfile,   "cpfile",       ex_cnext,
        EX_RANGE|EX_COUNT|EX_TRLBAR|EX_BANG,
        ADDR_OTHER),
 EXCMD(CMD_cquit,       "cquit",        ex_cquit,
-       EX_TRLBAR|EX_BANG,
+       EX_RANGE|EX_COUNT|EX_ZEROR|EX_TRLBAR|EX_BANG,
        ADDR_NONE),
 EXCMD(CMD_crewind,     "crewind",      ex_cc,
        EX_RANGE|EX_COUNT|EX_TRLBAR|EX_BANG,
index a3442edbe7507b6aecb8ad55b20e72818f8bf494..de8fb49617d867f070450dcb626085356c0773e9 100644 (file)
@@ -4920,8 +4920,8 @@ ex_quit(exarg_T *eap)
     static void
 ex_cquit(exarg_T *eap UNUSED)
 {
-    getout(1); // this does not always pass on the exit code to the Manx
-               // compiler. why?
+    // this does not always pass on the exit code to the Manx compiler. why?
+    getout(eap->addr_count > 0 ? (int)eap->line2 : EXIT_FAILURE);
 }
 
 /*
index f7c73f4c38ea004fa640e8bcb24243e913108623..b7b4281962217b6b0c6f7bf57523d2488b37219b 100644 (file)
@@ -4674,4 +4674,29 @@ func Test_search_in_dirstack()
   call delete('Xtestdir', 'rf')
 endfunc
 
+" Test for :cquit
+func Test_cquit()
+  " Exit Vim with a non-zero value
+  if RunVim([], ["cquit 7"], '')
+    call assert_equal(7, v:shell_error)
+  endif
+
+  if RunVim([], ["50cquit"], '')
+    call assert_equal(50, v:shell_error)
+  endif
+
+  " Exit Vim with default value
+  if RunVim([], ["cquit"], '')
+    call assert_equal(1, v:shell_error)
+  endif
+
+  " Exit Vim with zero value
+  if RunVim([], ["cquit 0"], '')
+    call assert_equal(0, v:shell_error)
+  endif
+
+  " Exit Vim with negative value
+  call assert_fails('-3cquit', 'E16:')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 41a6d3701299ab9e938d3591e7a6035e92fb0a7b..d007585eaca4a994aec918c04a5582551d2ef482 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    95,
 /**/
     94,
 /**/