[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: start emacs without creating frames and connect with emacsclient lat
From: |
Johannes Weiner |
Subject: |
Re: start emacs without creating frames and connect with emacsclient later |
Date: |
Wed, 13 Aug 2008 18:40:49 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Hi,
Dan Nicolaescu <address@hidden> writes:
> It seemed that this TODO item shouldn't be that hard to do given that we
> have all the infrastructure:
>
> ** Make "emacs --daemon" start emacs without showing any frame.
> Use emacsclient later to open frames.
>
>
> 10 minutes later it turned out to be true.
>
> The patch below implements it.
>
> emacs -daemon &
Uhm, hardly a daemon if it quits when I quit the shell.
> will start emacs without creating any frames, and it starts the server.
>
> Later you can do:
>
> emacsclient -t FILENAME
>
> will create a tty frame.
>
> and
> emacsclient -c FILENAME
>
> will create an X11 frame.
>
> Not sure what to do about:
> emacsclient FILENAME
>
> it won't do anything visibe if no other frame is available. Should it
> create one?
I think a good solution would be to do it like emacs itself does it:
Start a graphical frame (unless -nw) when that is possible, otherwise a
terminal frame.
Right now I use the below program as a workaround, perhaps someone might
find it interesting.
Hannes
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
static const char emacs[] = "emacs";
static char *args[] = { "emacs", "-f", "server-start", NULL };
/* Run the emacs server */
void child_emacs(char *slavename)
{
int slave;
setsid();
slave = open(slavename, O_RDWR);
dup2(slave, 0);
dup2(slave, 1);
dup2(slave, 2);
execvp(emacs, args);
abort();
}
/* Run the reader that unblocks emacs' terminal */
void child_reader(int master)
{
char buf[512];
setsid();
/* could be used for debugging in the future */
while (read(master, buf, sizeof(buf)))
/* do nothing */;
}
int main(void)
{
int master;
char *slavename;
/* Open master terminal */
master = open("/dev/ptmx", O_RDWR);
grantpt(master);
unlockpt(master);
slavename = ptsname(master);
/* Fork the emacs process */
switch (fork()) {
case -1:
abort();
break;
case 0:
child_emacs(slavename);
break;
default:
/* Fork the reader process */
switch (fork()) {
case -1:
abort();
break;
case 0:
child_reader(master);
break;
}
}
return 0;
}