Minor improvements in 'restart-emacs' on MS-Windows

* src/w32.c (w32_reexec_emacs): Explicitly request a new console
for the restarted Emacs -nw, and specify its dimensions.  Specify
NULL instead of security attributes, per examples on the Internet.
* src/w32console.c (initialize_w32_display): Check errors in call
to GetConsoleCursorInfo.
This commit is contained in:
Eli Zaretskii 2022-04-18 21:04:57 +03:00
parent 850074636e
commit a45c1c45a2
2 changed files with 38 additions and 27 deletions

View file

@ -10628,41 +10628,46 @@ int
w32_reexec_emacs (char *cmd_line, const char *wdir)
{
STARTUPINFO si;
SECURITY_ATTRIBUTES sec_attrs;
BOOL status;
PROCESS_INFORMATION proc_info;
DWORD dwCreationFlags = NORMAL_PRIORITY_CLASS;
GetStartupInfo (&si); /* Use the same startup info as the caller. */
sec_attrs.nLength = sizeof (sec_attrs);
sec_attrs.lpSecurityDescriptor = NULL;
sec_attrs.bInheritHandle = FALSE;
if (inhibit_window_system)
{
HANDLE screen_handle;
CONSOLE_SCREEN_BUFFER_INFO screen_info;
screen_handle = GetStdHandle (STD_OUTPUT_HANDLE);
if (screen_handle != INVALID_HANDLE_VALUE
&& GetConsoleScreenBufferInfo (screen_handle, &screen_info))
{
/* Make the restarted Emacs's console window the same
dimensions as ours. FIXME: for some reason this doesn't
seem to work! */
si.dwFlags |= STARTF_USECOUNTCHARS;
si.dwXCountChars = screen_info.dwSize.X;
si.dwYCountChars = screen_info.dwSize.Y;
}
/* This is a kludge: it causes the restarted "emacs -nw" to have
a new console window created for it, and that new window
might have different (default) properties, not the ones of
the parent process's console window. But without this,
restarting Emacs in the -nw mode simply doesn't work.
FIXME! */
dwCreationFlags = CREATE_NEW_CONSOLE;
}
/* Make sure we are in the original directory, in case the command
line specifies the program as a relative file name. */
chdir (wdir);
/* This is a kludge: it causes the restarted "emacs -nw" to have a
new console window created for it, and that new window might have
different (default) properties, not the ones of the parent
process's console window. But without this, restarting Emacs in
the -nw mode simply doesn't work. FIXME! */
if (inhibit_window_system)
{
if (!FreeConsole ())
{
errno = ENOEXEC;
return -1;
}
}
status = CreateProcess (NULL, /* program */
status = CreateProcess (NULL, /* no program, take from command line */
cmd_line, /* command line */
&sec_attrs, /* process attributes */
NULL,
NULL, /* thread attributes */
TRUE, /* inherit handles? */
inhibit_window_system
? 0 /* inherit parent's console */
: NORMAL_PRIORITY_CLASS,
FALSE, /* unherit handles? */
dwCreationFlags,
NULL, /* environment */
wdir, /* initial directory */
&si, /* startup info */

View file

@ -716,10 +716,10 @@ initialize_w32_display (struct terminal *term, int *width, int *height)
if (cur_screen == INVALID_HANDLE_VALUE)
{
printf ("CreateConsoleScreenBuffer failed in ResetTerm\n");
printf ("CreateConsoleScreenBuffer failed in initialize_w32_display\n");
printf ("LastError = 0x%lx\n", GetLastError ());
fflush (stdout);
exit (0);
exit (1);
}
#else
cur_screen = prev_screen;
@ -760,7 +760,13 @@ initialize_w32_display (struct terminal *term, int *width, int *height)
}
}
GetConsoleScreenBufferInfo (cur_screen, &info);
if (!GetConsoleScreenBufferInfo (cur_screen, &info))
{
printf ("GetConsoleScreenBufferInfo failed in initialize_w32_display\n");
printf ("LastError = 0x%lx\n", GetLastError ());
fflush (stdout);
exit (1);
}
char_attr_normal = info.wAttributes;