Skip to content

Instantly share code, notes, and snippets.

@yangg
Created May 23, 2012 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangg/2773051 to your computer and use it in GitHub Desktop.
Save yangg/2773051 to your computer and use it in GitHub Desktop.
Start emacsclient across multi plaform
windres -O coff icon.rc icon.res
gcc icon.res startemacs.c -o startemacs
1 ICON "emacs.ico"
#include <stdio.h>
int main (int argc, char *argv[])
{
char *filename, appname[255];
size_t size = 200;
sprintf(appname, "%s/%s", getcwd(appname, size), argv[0]);
if(argc > 1) {
filename = argv[1];
} else {
filename = "newfile";
}
printf("%s\n%s\n", appname, filename);
if(!strcmp(filename, "--install")) {
char cmd[500];
sprintf(cmd, "reg add \"HKCR\\*\\shell\\openwithemacs\\command\" /ve /d \"\\\"%s\\\" \\\"%%1\\\"\" /f", appname);
system("reg add \"HKCR\\*\\shell\\openwithemacs\" /ve /d \"Edit With Emacs\" /f");
system(cmd);
} else if(!strcmp(filename, "--uninstall")) {
system("reg delete \"HKCR\\*\\shell\\openwithemacs\" /f");
} else {
char cmd[255];
sprintf(cmd, "emacsclientw.exe --alternate-editor=\"runemacs.exe\" \"%s\"", filename);
// TODO: quote & cmd window & waitexit
system(cmd);
}
return 0;
}
// exec http://www.gnu.org/software/libc/manual/html_node/Executing-a-File.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment