[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacsclientw
From: |
Jason Rumney |
Subject: |
emacsclientw |
Date: |
Mon, 13 Nov 2006 11:41:14 +0000 |
User-agent: |
Thunderbird 1.5.0.8 (Windows/20061025) |
Have you tested the emacsclientw.exe build with MSVC?
I think there is also a need for something that starts Emacs if it is
not already running, so I came up with the following (based on
runemacs.c), which I intended to check into the nt directory. The
intention is to use this to associate Emacs with file types in Explorer
and other applications that allow external editors.
/* Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/*
Simple program to start emacsclient or emacs with its console window
hidden.
This program is provided for conveniently associating emacs with
files in Windows Explorer and other GUI programs.
*/
#include <windows.h>
#include <string.h>
#include <malloc.h>
int launch_app(char *dir_name, char *app_name, LPSTR cmd_line)
{
STARTUPINFO start;
SECURITY_ATTRIBUTES sec_attrs;
PROCESS_INFORMATION child;
int wait_for_child = FALSE;
DWORD priority_class = NORMAL_PRIORITY_CLASS;
DWORD ret_code = 0;
char *new_cmd_line;
new_cmd_line = alloca (MAX_PATH + strlen (cmd_line) + 3);
/* Quote executable name in case of spaces in the path. */
*new_cmd_line = '"';
strcpy (new_cmd_line + 1, dir_name);
strcat (new_cmd_line, "\\");
strcat (new_cmd_line, app_name);
strcat (new_cmd_line, "\" ");
/* Append original arguments if any. */
strcat (new_cmd_line, cmd_line);
memset (&start, 0, sizeof (start));
start.cb = sizeof (start);
start.dwFlags = STARTF_USESHOWWINDOW | STARTF_USECOUNTCHARS;
start.wShowWindow = SW_HIDE;
/* Ensure that we don't waste memory if the user has specified a huge
default screen buffer for command windows. */
start.dwXCountChars = 80;
start.dwYCountChars = 25;
sec_attrs.nLength = sizeof (sec_attrs);
sec_attrs.lpSecurityDescriptor = NULL;
sec_attrs.bInheritHandle = FALSE;
if (CreateProcess (NULL, new_cmd_line, &sec_attrs, NULL, TRUE, priority_class,
NULL, NULL, &start, &child))
{
WaitForSingleObject (child.hProcess, INFINITE);
GetExitCodeProcess (child.hProcess, &ret_code);
CloseHandle (child.hThread);
CloseHandle (child.hProcess);
}
else
ret_code = 1;
return ret_code;
}
int WINAPI
WinMain (HINSTANCE self, HINSTANCE prev, LPSTR cmd_line, int show)
{
char dir_name[MAX_PATH];
char *p;
/* Figure out what directory this is run from, so we can find the
emacsclient and emacs executables. */
if (!GetModuleFileName (NULL, dir_name, MAX_PATH))
goto error;
if ((p = strrchr (dir_name, '\\')) == NULL)
goto error;
*p = 0;
if ((launch_app (dir_name, "emacsclient.exe", cmd_line) == 0)
|| launch_app(dir_name, "emacs.exe", cmd_line) == 0)
return 0;
error:
MessageBox (NULL, "Could not start Emacs", "Error", MB_ICONSTOP);
return 1;
}
- Re: I can't build from cvs sources on cygwin for some time now, (continued)
- Re: I can't build from cvs sources on cygwin for some time now, Jason Rumney, 2006/11/12
- Re: I can't build from cvs sources on cygwin for some time now, Juanma Barranquero, 2006/11/12
- Re: I can't build from cvs sources on cygwin for some time now, Juanma Barranquero, 2006/11/12
- Re: I can't build from cvs sources on cygwin for some time now, Eric Lilja, 2006/11/13
- Re: I can't build from cvs sources on cygwin for some time now, Jason Rumney, 2006/11/13
- Re: I can't build from cvs sources on cygwin for some time now, Juanma Barranquero, 2006/11/13
- emacsclientw,
Jason Rumney <=
- Re: emacsclientw, Juanma Barranquero, 2006/11/13
- Re: emacsclientw, Lennart Borgman, 2006/11/13
- Re: emacsclientw, dhruva, 2006/11/13
- Re: emacsclientw, Juanma Barranquero, 2006/11/13
- Re: emacsclientw, dhruva, 2006/11/13
- Re: emacsclientw, Juanma Barranquero, 2006/11/13
- Re: emacsclientw, Jason Rumney, 2006/11/13
- Re: emacsclientw, Lennart Borgman, 2006/11/13
- Re: emacsclientw, dhruva, 2006/11/13
- Re: emacsclientw, Mathias Dahl, 2006/11/14