aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorJuanma Barranquero2006-11-30 22:49:38 +0000
committerJuanma Barranquero2006-11-30 22:49:38 +0000
commitc66648e0c761739084ff5a6bafa1943363bb6c3e (patch)
treee988c983149131d29e4ece0323685b3417ccf7dc /lib-src
parent9219db75bfd2185408cfe4fea6fef0a424b853b4 (diff)
downloademacs-c66648e0c761739084ff5a6bafa1943363bb6c3e.tar.gz
emacs-c66648e0c761739084ff5a6bafa1943363bb6c3e.zip
(emacs_pid): New variable.
(message): Remove leftover code. (get_server_config): Set emacs_pid. Don't allow Emacs to grab the focus yet; emacsclient can still display an informational message before sending requests to Emacs. (main): Allow Emacs to grab the focus. Simplify message() call.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c65
1 files changed, 30 insertions, 35 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 5985a98c39a..f05b98eccee 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -129,6 +129,9 @@ char *socket_name = NULL;
129/* If non-NULL, the filename of the authentication file. */ 129/* If non-NULL, the filename of the authentication file. */
130char *server_file = NULL; 130char *server_file = NULL;
131 131
132/* PID of the Emacs server process. */
133int emacs_pid = 0;
134
132void print_help_and_exit () NO_RETURN; 135void print_help_and_exit () NO_RETURN;
133 136
134struct option longopts[] = 137struct option longopts[] =
@@ -168,18 +171,10 @@ w32_window_app()
168void 171void
169message (int is_error, char *message, ...) 172message (int is_error, char *message, ...)
170{ 173{
171 char buf [2048]; 174 char msg [2048];
172 char *msg = buf;
173 va_list args; 175 va_list args;
174 176
175 va_start (args, message); 177 va_start (args, message);
176
177 if (is_error)
178 {
179 sprintf (buf, "%s: ", progname);
180 msg = strchr (buf, '\0');
181 }
182
183 vsprintf (msg, message, args); 178 vsprintf (msg, message, args);
184 va_end (args); 179 va_end (args);
185 180
@@ -555,29 +550,7 @@ get_server_config (server, authentication)
555 550
556 fclose (config); 551 fclose (config);
557 552
558#ifdef WINDOWSNT 553 emacs_pid = atoi (pid);
559 /*
560 Modern Windows restrict which processes can set the foreground window.
561 So, for emacsclient to be able to force Emacs into the foreground, we
562 have to call AllowSetForegroundWindow(). Unfortunately, older Windows
563 (W95, W98 and NT) don't have this function, so we have to check first.
564
565 We're doing this here because it has to be done before sending info
566 to Emacs, and otherwise we'll need a global variable just to pass around
567 the pid, which is also inelegant.
568 */
569 {
570 HMODULE hUser32;
571
572 if (hUser32 = LoadLibrary ("user32.dll"))
573 {
574 FARPROC set_fg;
575 if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
576 set_fg (atoi (pid));
577 FreeLibrary (hUser32);
578 }
579 }
580#endif
581 554
582 return TRUE; 555 return TRUE;
583} 556}
@@ -871,15 +844,37 @@ main (argc, argv)
871 if (cwd == 0) 844 if (cwd == 0)
872 { 845 {
873 /* getwd puts message in STRING if it fails. */ 846 /* getwd puts message in STRING if it fails. */
874#ifdef HAVE_GETCWD
875 message (TRUE, "%s: %s (%s)\n", progname, 847 message (TRUE, "%s: %s (%s)\n", progname,
876 "Cannot get current working directory", strerror (errno)); 848#ifdef HAVE_GETCWD
849 "Cannot get current working directory",
877#else 850#else
878 message (TRUE, "%s: %s (%s)\n", progname, string, strerror (errno)); 851 string,
879#endif 852#endif
853 strerror (errno));
880 fail (argc, argv); 854 fail (argc, argv);
881 } 855 }
882 856
857#ifdef WINDOWSNT
858 /*
859 Modern Windows restrict which processes can set the foreground window.
860 emacsclient can allow Emacs to grab the focus by calling the function
861 AllowSetForegroundWindow(). Unfortunately, older Windows (W95, W98
862 and NT) lack this function, so we have to check its availability.
863 */
864 if (emacs_pid)
865 {
866 HMODULE hUser32;
867
868 if (hUser32 = LoadLibrary ("user32.dll"))
869 {
870 FARPROC set_fg;
871 if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
872 set_fg (emacs_pid);
873 FreeLibrary (hUser32);
874 }
875 }
876#endif
877
883 if (nowait) 878 if (nowait)
884 SEND_STRING ("-nowait "); 879 SEND_STRING ("-nowait ");
885 880