3838 * in tl_scrollback are no longer used.
3939 *
4040 * TODO:
41- * - Make terminal close by default when started without a command. Add
42- * ++noclose argument.
4341 * - Win32: In the GUI use a terminal emulator for :!cmd.
4442 * - Add a way to set the 16 ANSI colors, to be used for 'termguicolors' and in
4543 * the GUI.
@@ -123,7 +121,11 @@ struct terminal_S {
123121
124122 int tl_normal_mode ; /* TRUE: Terminal-Normal mode */
125123 int tl_channel_closed ;
126- int tl_finish ; /* 'c' for ++close, 'o' for ++open */
124+ int tl_finish ;
125+ #define TL_FINISH_UNSET NUL
126+ #define TL_FINISH_CLOSE 'c' /* ++close or :terminal without argument */
127+ #define TL_FINISH_NOCLOSE 'n' /* ++noclose */
128+ #define TL_FINISH_OPEN 'o' /* ++open */
127129 char_u * tl_opencmd ;
128130 char_u * tl_eof_chars ;
129131
@@ -643,6 +645,8 @@ ex_terminal(exarg_T *eap)
643645
644646 if ((int )(p - cmd ) == 5 && STRNICMP (cmd , "close" , 5 ) == 0 )
645647 opt .jo_term_finish = 'c' ;
648+ else if ((int )(p - cmd ) == 7 && STRNICMP (cmd , "noclose" , 7 ) == 0 )
649+ opt .jo_term_finish = 'n' ;
646650 else if ((int )(p - cmd ) == 4 && STRNICMP (cmd , "open" , 4 ) == 0 )
647651 opt .jo_term_finish = 'o' ;
648652 else if ((int )(p - cmd ) == 6 && STRNICMP (cmd , "curwin" , 6 ) == 0 )
@@ -696,9 +700,15 @@ ex_terminal(exarg_T *eap)
696700 cmd = skipwhite (p );
697701 }
698702 if (* cmd == NUL )
703+ {
699704 /* Make a copy of 'shell', an autocommand may change the option. */
700705 tofree = cmd = vim_strsave (p_sh );
701706
707+ /* default to close when the shell exits */
708+ if (opt .jo_term_finish == NUL )
709+ opt .jo_term_finish = 'c' ;
710+ }
711+
702712 if (eap -> addr_count > 0 )
703713 {
704714 /* Write lines from current buffer to the job. */
@@ -1535,7 +1545,7 @@ set_terminal_mode(term_T *term, int normal_mode)
15351545 static void
15361546cleanup_vterm (term_T * term )
15371547{
1538- if (term -> tl_finish != 'c' )
1548+ if (term -> tl_finish != TL_FINISH_CLOSE )
15391549 move_terminal_to_buffer (term );
15401550 term_free_vterm (term );
15411551 set_terminal_mode (term , FALSE);
@@ -2603,7 +2613,7 @@ term_channel_closed(channel_T *ch)
26032613
26042614 cleanup_vterm (term );
26052615
2606- if (term -> tl_finish == 'c' )
2616+ if (term -> tl_finish == TL_FINISH_CLOSE )
26072617 {
26082618 aco_save_T aco ;
26092619
@@ -2614,7 +2624,8 @@ term_channel_closed(channel_T *ch)
26142624 aucmd_restbuf (& aco );
26152625 break ;
26162626 }
2617- if (term -> tl_finish == 'o' && term -> tl_buffer -> b_nwindows == 0 )
2627+ if (term -> tl_finish == TL_FINISH_OPEN
2628+ && term -> tl_buffer -> b_nwindows == 0 )
26182629 {
26192630 char buf [50 ];
26202631
0 commit comments