aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2022-04-18 21:04:57 +0300
committerEli Zaretskii2022-04-18 21:04:57 +0300
commita45c1c45a29cbf9416bb03f77c99b383db43e7a0 (patch)
treef259753ae762ea7c86f1ed1b18d3452c1806c528 /src
parent850074636e73509b09c28e965c1af054a84f4069 (diff)
downloademacs-a45c1c45a29cbf9416bb03f77c99b383db43e7a0.tar.gz
emacs-a45c1c45a29cbf9416bb03f77c99b383db43e7a0.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/w32.c51
-rw-r--r--src/w32console.c12
2 files changed, 37 insertions, 26 deletions
diff --git a/src/w32.c b/src/w32.c
index e4237579d84..74923ffece9 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -10628,41 +10628,46 @@ int
10628w32_reexec_emacs (char *cmd_line, const char *wdir) 10628w32_reexec_emacs (char *cmd_line, const char *wdir)
10629{ 10629{
10630 STARTUPINFO si; 10630 STARTUPINFO si;
10631 SECURITY_ATTRIBUTES sec_attrs;
10632 BOOL status; 10631 BOOL status;
10633 PROCESS_INFORMATION proc_info; 10632 PROCESS_INFORMATION proc_info;
10633 DWORD dwCreationFlags = NORMAL_PRIORITY_CLASS;
10634 10634
10635 GetStartupInfo (&si); /* Use the same startup info as the caller. */ 10635 GetStartupInfo (&si); /* Use the same startup info as the caller. */
10636 sec_attrs.nLength = sizeof (sec_attrs);
10637 sec_attrs.lpSecurityDescriptor = NULL;
10638 sec_attrs.bInheritHandle = FALSE;
10639
10640 /* Make sure we are in the original directory, in case the command
10641 line specifies the program as a relative file name. */
10642 chdir (wdir);
10643
10644 /* This is a kludge: it causes the restarted "emacs -nw" to have a
10645 new console window created for it, and that new window might have
10646 different (default) properties, not the ones of the parent
10647 process's console window. But without this, restarting Emacs in
10648 the -nw mode simply doesn't work. FIXME! */
10649 if (inhibit_window_system) 10636 if (inhibit_window_system)
10650 { 10637 {
10651 if (!FreeConsole ()) 10638 HANDLE screen_handle;
10639 CONSOLE_SCREEN_BUFFER_INFO screen_info;
10640
10641 screen_handle = GetStdHandle (STD_OUTPUT_HANDLE);
10642 if (screen_handle != INVALID_HANDLE_VALUE
10643 && GetConsoleScreenBufferInfo (screen_handle, &screen_info))
10652 { 10644 {
10653 errno = ENOEXEC; 10645 /* Make the restarted Emacs's console window the same
10654 return -1; 10646 dimensions as ours. FIXME: for some reason this doesn't
10647 seem to work! */
10648 si.dwFlags |= STARTF_USECOUNTCHARS;
10649 si.dwXCountChars = screen_info.dwSize.X;
10650 si.dwYCountChars = screen_info.dwSize.Y;
10655 } 10651 }
10652 /* This is a kludge: it causes the restarted "emacs -nw" to have
10653 a new console window created for it, and that new window
10654 might have different (default) properties, not the ones of
10655 the parent process's console window. But without this,
10656 restarting Emacs in the -nw mode simply doesn't work.
10657 FIXME! */
10658 dwCreationFlags = CREATE_NEW_CONSOLE;
10656 } 10659 }
10657 10660
10658 status = CreateProcess (NULL, /* program */ 10661 /* Make sure we are in the original directory, in case the command
10662 line specifies the program as a relative file name. */
10663 chdir (wdir);
10664
10665 status = CreateProcess (NULL, /* no program, take from command line */
10659 cmd_line, /* command line */ 10666 cmd_line, /* command line */
10660 &sec_attrs, /* process attributes */ 10667 NULL,
10661 NULL, /* thread attributes */ 10668 NULL, /* thread attributes */
10662 TRUE, /* inherit handles? */ 10669 FALSE, /* unherit handles? */
10663 inhibit_window_system 10670 dwCreationFlags,
10664 ? 0 /* inherit parent's console */
10665 : NORMAL_PRIORITY_CLASS,
10666 NULL, /* environment */ 10671 NULL, /* environment */
10667 wdir, /* initial directory */ 10672 wdir, /* initial directory */
10668 &si, /* startup info */ 10673 &si, /* startup info */
diff --git a/src/w32console.c b/src/w32console.c
index 12e1f397894..09749126e03 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -716,10 +716,10 @@ initialize_w32_display (struct terminal *term, int *width, int *height)
716 716
717 if (cur_screen == INVALID_HANDLE_VALUE) 717 if (cur_screen == INVALID_HANDLE_VALUE)
718 { 718 {
719 printf ("CreateConsoleScreenBuffer failed in ResetTerm\n"); 719 printf ("CreateConsoleScreenBuffer failed in initialize_w32_display\n");
720 printf ("LastError = 0x%lx\n", GetLastError ()); 720 printf ("LastError = 0x%lx\n", GetLastError ());
721 fflush (stdout); 721 fflush (stdout);
722 exit (0); 722 exit (1);
723 } 723 }
724#else 724#else
725 cur_screen = prev_screen; 725 cur_screen = prev_screen;
@@ -760,7 +760,13 @@ initialize_w32_display (struct terminal *term, int *width, int *height)
760 } 760 }
761 } 761 }
762 762
763 GetConsoleScreenBufferInfo (cur_screen, &info); 763 if (!GetConsoleScreenBufferInfo (cur_screen, &info))
764 {
765 printf ("GetConsoleScreenBufferInfo failed in initialize_w32_display\n");
766 printf ("LastError = 0x%lx\n", GetLastError ());
767 fflush (stdout);
768 exit (1);
769 }
764 770
765 char_attr_normal = info.wAttributes; 771 char_attr_normal = info.wAttributes;
766 772