To: vim_dev@googlegroups.com Subject: Patch 8.1.0050 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0050 (after 8.1.0049) Problem: $VIM_TERMINAL is also set when not in a terminal window. Solution: Pass a flag to indicate whether the job runs in a terminal. Files: src/channel.c, src/proto/channel.pro, src/evalfunc.c, src/terminal.c, src/os_unix.c, src/proto/os_unix.pro, src/os_win32.c *** ../vim-8.1.0049/src/channel.c 2018-06-03 14:42:17.840505115 +0200 --- src/channel.c 2018-06-12 20:13:06.460135822 +0200 *************** *** 5525,5531 **** * Returns NULL when out of memory. */ job_T * ! job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg) { job_T *job; char_u *cmd = NULL; --- 5525,5535 ---- * Returns NULL when out of memory. */ job_T * ! job_start( ! typval_T *argvars, ! char **argv_arg, ! jobopt_T *opt_arg, ! int is_terminal UNUSED) { job_T *job; char_u *cmd = NULL; *************** *** 5679,5685 **** ch_log(NULL, "Starting job: %s", (char *)ga.ga_data); ga_clear(&ga); } ! mch_job_start(argv, job, &opt); #else ch_log(NULL, "Starting job: %s", (char *)cmd); mch_job_start((char *)cmd, job, &opt); --- 5683,5689 ---- ch_log(NULL, "Starting job: %s", (char *)ga.ga_data); ga_clear(&ga); } ! mch_job_start(argv, job, &opt, is_terminal); #else ch_log(NULL, "Starting job: %s", (char *)cmd); mch_job_start((char *)cmd, job, &opt); *** ../vim-8.1.0049/src/proto/channel.pro 2018-06-03 14:42:17.848505102 +0200 --- src/proto/channel.pro 2018-06-12 20:08:25.045683595 +0200 *************** *** 66,72 **** void job_stop_on_exit(void); int has_pending_job(void); void job_check_ended(void); ! job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg); char *job_status(job_T *job); void job_info(job_T *job, dict_T *dict); void job_info_all(list_T *l); --- 66,72 ---- void job_stop_on_exit(void); int has_pending_job(void); void job_check_ended(void); ! job_T *job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg, int is_terminal); char *job_status(job_T *job); void job_info(job_T *job, dict_T *dict); void job_info_all(list_T *l); *** ../vim-8.1.0049/src/evalfunc.c 2018-06-07 18:17:42.278227523 +0200 --- src/evalfunc.c 2018-06-12 20:05:33.630628161 +0200 *************** *** 7254,7260 **** rettv->v_type = VAR_JOB; if (check_restricted() || check_secure()) return; ! rettv->vval.v_job = job_start(argvars, NULL, NULL); } /* --- 7254,7260 ---- rettv->v_type = VAR_JOB; if (check_restricted() || check_secure()) return; ! rettv->vval.v_job = job_start(argvars, NULL, NULL, FALSE); } /* *** ../vim-8.1.0049/src/terminal.c 2018-06-04 17:28:04.729961269 +0200 --- src/terminal.c 2018-06-12 20:06:16.926389419 +0200 *************** *** 5769,5775 **** #endif /* This may change a string in "argvar". */ ! term->tl_job = job_start(argvar, argv, opt); if (term->tl_job != NULL) ++term->tl_job->jv_refcount; --- 5769,5775 ---- #endif /* This may change a string in "argvar". */ ! term->tl_job = job_start(argvar, argv, opt, TRUE); if (term->tl_job != NULL) ++term->tl_job->jv_refcount; *** ../vim-8.1.0049/src/os_unix.c 2018-06-12 18:04:28.038267855 +0200 --- src/os_unix.c 2018-06-12 20:11:20.272719511 +0200 *************** *** 4159,4165 **** * Set the environment for a child process. */ static void ! set_child_environment(long rows, long columns, char *term) { # ifdef HAVE_SETENV char envbuf[50]; --- 4159,4169 ---- * Set the environment for a child process. */ static void ! set_child_environment( ! long rows, ! long columns, ! char *term, ! int is_terminal UNUSED) { # ifdef HAVE_SETENV char envbuf[50]; *************** *** 4169,4175 **** --- 4173,4181 ---- static char envbuf_Lines[20]; static char envbuf_Columns[20]; static char envbuf_Colors[20]; + # ifdef FEAT_TERMINAL static char envbuf_Version[20]; + # endif # ifdef FEAT_CLIENTSERVER static char envbuf_Servername[60]; # endif *************** *** 4190,4197 **** setenv("COLUMNS", (char *)envbuf, 1); sprintf((char *)envbuf, "%ld", colors); setenv("COLORS", (char *)envbuf, 1); ! sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION)); ! setenv("VIM_TERMINAL", (char *)envbuf, 1); # ifdef FEAT_CLIENTSERVER setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1); # endif --- 4196,4208 ---- setenv("COLUMNS", (char *)envbuf, 1); sprintf((char *)envbuf, "%ld", colors); setenv("COLORS", (char *)envbuf, 1); ! # ifdef FEAT_TERMINAL ! if (is_terminal) ! { ! sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION)); ! setenv("VIM_TERMINAL", (char *)envbuf, 1); ! } ! # endif # ifdef FEAT_CLIENTSERVER setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1); # endif *************** *** 4212,4220 **** putenv(envbuf_Columns); vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors); putenv(envbuf_Colors); ! vim_snprintf(envbuf_Version, sizeof(envbuf_Version), "VIM_TERMINAL=%ld", ! get_vim_var_nr(VV_VERSION)); ! putenv(envbuf_Version); # ifdef FEAT_CLIENTSERVER vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername), "VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName); --- 4223,4236 ---- putenv(envbuf_Columns); vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors); putenv(envbuf_Colors); ! # ifdef FEAT_TERMINAL ! if (is_terminal) ! { ! vim_snprintf(envbuf_Version, sizeof(envbuf_Version), ! "VIM_TERMINAL=%ld", get_vim_var_nr(VV_VERSION)); ! putenv(envbuf_Version); ! } ! # endif # ifdef FEAT_CLIENTSERVER vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername), "VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName); *************** *** 4224,4232 **** } static void ! set_default_child_environment(void) { ! set_child_environment(Rows, Columns, "dumb"); } #endif --- 4240,4248 ---- } static void ! set_default_child_environment(int is_terminal) { ! set_child_environment(Rows, Columns, "dumb", is_terminal); } #endif *************** *** 4689,4695 **** # endif } # endif ! set_default_child_environment(); /* * stderr is only redirected when using the GUI, so that a --- 4705,4711 ---- # endif } # endif ! set_default_child_environment(FALSE); /* * stderr is only redirected when using the GUI, so that a *************** *** 5367,5373 **** #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) void ! mch_job_start(char **argv, job_T *job, jobopt_T *options) { pid_t pid; int fd_in[2] = {-1, -1}; /* for stdin */ --- 5383,5389 ---- #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) void ! mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal) { pid_t pid; int fd_in[2] = {-1, -1}; /* for stdin */ *************** *** 5515,5525 **** set_child_environment( (long)options->jo_term_rows, (long)options->jo_term_cols, ! term); } else # endif ! set_default_child_environment(); if (options->jo_env != NULL) { --- 5531,5542 ---- set_child_environment( (long)options->jo_term_rows, (long)options->jo_term_cols, ! term, ! is_terminal); } else # endif ! set_default_child_environment(is_terminal); if (options->jo_env != NULL) { *** ../vim-8.1.0049/src/proto/os_unix.pro 2018-05-17 13:52:48.000000000 +0200 --- src/proto/os_unix.pro 2018-06-12 20:08:29.497659084 +0200 *************** *** 62,68 **** void mch_new_shellsize(void); void may_send_sigint(int c, pid_t pid, pid_t wpid); int mch_call_shell(char_u *cmd, int options); ! void mch_job_start(char **argv, job_T *job, jobopt_T *options); char *mch_job_status(job_T *job); job_T *mch_detect_ended_job(job_T *job_list); int mch_signal_job(job_T *job, char_u *how); --- 62,68 ---- void mch_new_shellsize(void); void may_send_sigint(int c, pid_t pid, pid_t wpid); int mch_call_shell(char_u *cmd, int options); ! void mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal); char *mch_job_status(job_T *job); job_T *mch_detect_ended_job(job_T *job_list); int mch_signal_job(job_T *job, char_u *how); *** ../vim-8.1.0049/src/os_win32.c 2018-06-12 18:04:28.038267855 +0200 --- src/os_win32.c 2018-06-12 20:18:53.770228655 +0200 *************** *** 5275,5300 **** } } ! if (is_terminal) { ! # ifdef FEAT_CLIENTSERVER char_u *servername = get_vim_var_str(VV_SEND_SERVER); size_t servername_len = STRLEN(servername); ! # endif char_u *version = get_vim_var_str(VV_VERSION); size_t version_len = STRLEN(version); // size of "VIM_SERVERNAME=" and value, // plus "VIM_TERMINAL=" and value, // plus two terminating NULs size_t n = 0 ! # ifdef FEAT_CLIENTSERVER + 15 + servername_len ! # endif ! + 13 + version_len + 2; if (ga_grow(gap, (int)n) == OK) { ! # ifdef FEAT_CLIENTSERVER for (n = 0; n < 15; n++) *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)"VIM_SERVERNAME="[n]; --- 5275,5305 ---- } } ! # if defined(FEAT_CLIENTSERVER) || defined(FEAT_TERMINAL) { ! # ifdef FEAT_CLIENTSERVER char_u *servername = get_vim_var_str(VV_SEND_SERVER); size_t servername_len = STRLEN(servername); ! # endif ! # ifdef FEAT_TERMINAL char_u *version = get_vim_var_str(VV_VERSION); size_t version_len = STRLEN(version); + # endif // size of "VIM_SERVERNAME=" and value, // plus "VIM_TERMINAL=" and value, // plus two terminating NULs size_t n = 0 ! # ifdef FEAT_CLIENTSERVER + 15 + servername_len ! # endif ! # ifdef FEAT_TERMINAL ! + 13 + version_len + 2 ! # endif ! ; if (ga_grow(gap, (int)n) == OK) { ! # ifdef FEAT_CLIENTSERVER for (n = 0; n < 15; n++) *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)"VIM_SERVERNAME="[n]; *************** *** 5302,5315 **** *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)servername[n]; *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; ! # endif ! for (n = 0; n < 13; n++) ! *((WCHAR*)gap->ga_data + gap->ga_len++) = ! (WCHAR)"VIM_TERMINAL="[n]; ! for (n = 0; n < version_len; n++) ! *((WCHAR*)gap->ga_data + gap->ga_len++) = ! (WCHAR)version[n]; ! *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; } } } --- 5307,5325 ---- *((WCHAR*)gap->ga_data + gap->ga_len++) = (WCHAR)servername[n]; *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; ! # endif ! # ifdef FEAT_TERMINAL ! if (is_terminal) ! { ! for (n = 0; n < 13; n++) ! *((WCHAR*)gap->ga_data + gap->ga_len++) = ! (WCHAR)"VIM_TERMINAL="[n]; ! for (n = 0; n < version_len; n++) ! *((WCHAR*)gap->ga_data + gap->ga_len++) = ! (WCHAR)version[n]; ! *((WCHAR*)gap->ga_data + gap->ga_len++) = L'\0'; ! } ! # endif } } } *** ../vim-8.1.0049/src/version.c 2018-06-12 18:04:28.042267834 +0200 --- src/version.c 2018-06-12 20:21:54.749235631 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 50, /**/ -- Change is inevitable, except from a vending machine. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///