Mercurial > emacs
changeset 74342:c6cb776ffbb7
(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.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 30 Nov 2006 22:49:38 +0000 |
parents | 32079f79e240 |
children | 42c1ec783c51 |
files | lib-src/emacsclient.c |
diffstat | 1 files changed, 30 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/lib-src/emacsclient.c Thu Nov 30 21:58:53 2006 +0000 +++ b/lib-src/emacsclient.c Thu Nov 30 22:49:38 2006 +0000 @@ -129,6 +129,9 @@ /* If non-NULL, the filename of the authentication file. */ char *server_file = NULL; +/* PID of the Emacs server process. */ +int emacs_pid = 0; + void print_help_and_exit () NO_RETURN; struct option longopts[] = @@ -168,18 +171,10 @@ void message (int is_error, char *message, ...) { - char buf [2048]; - char *msg = buf; + char msg [2048]; va_list args; va_start (args, message); - - if (is_error) - { - sprintf (buf, "%s: ", progname); - msg = strchr (buf, '\0'); - } - vsprintf (msg, message, args); va_end (args); @@ -555,29 +550,7 @@ fclose (config); -#ifdef WINDOWSNT - /* - Modern Windows restrict which processes can set the foreground window. - So, for emacsclient to be able to force Emacs into the foreground, we - have to call AllowSetForegroundWindow(). Unfortunately, older Windows - (W95, W98 and NT) don't have this function, so we have to check first. - - We're doing this here because it has to be done before sending info - to Emacs, and otherwise we'll need a global variable just to pass around - the pid, which is also inelegant. - */ - { - HMODULE hUser32; - - if (hUser32 = LoadLibrary ("user32.dll")) - { - FARPROC set_fg; - if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) - set_fg (atoi (pid)); - FreeLibrary (hUser32); - } - } -#endif + emacs_pid = atoi (pid); return TRUE; } @@ -871,15 +844,37 @@ if (cwd == 0) { /* getwd puts message in STRING if it fails. */ + message (TRUE, "%s: %s (%s)\n", progname, #ifdef HAVE_GETCWD - message (TRUE, "%s: %s (%s)\n", progname, - "Cannot get current working directory", strerror (errno)); + "Cannot get current working directory", #else - message (TRUE, "%s: %s (%s)\n", progname, string, strerror (errno)); + string, #endif + strerror (errno)); fail (argc, argv); } +#ifdef WINDOWSNT + /* + Modern Windows restrict which processes can set the foreground window. + emacsclient can allow Emacs to grab the focus by calling the function + AllowSetForegroundWindow(). Unfortunately, older Windows (W95, W98 + and NT) lack this function, so we have to check its availability. + */ + if (emacs_pid) + { + HMODULE hUser32; + + if (hUser32 = LoadLibrary ("user32.dll")) + { + FARPROC set_fg; + if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) + set_fg (emacs_pid); + FreeLibrary (hUser32); + } + } +#endif + if (nowait) SEND_STRING ("-nowait ");