unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Johannes Weiner <hannes@saeurebad.de>
To: Dan Nicolaescu <dann@ics.uci.edu>
Cc: emacs-devel@gnu.org
Subject: Re: start emacs without creating frames and connect with emacsclient later
Date: Wed, 13 Aug 2008 18:40:49 +0200	[thread overview]
Message-ID: <874p5oamwe.fsf@skyscraper.fehenstaub.lan> (raw)
In-Reply-To: <200808131610.m7DGAkvk020047@sallyv1.ics.uci.edu> (Dan Nicolaescu's message of "Wed, 13 Aug 2008 09:10:46 -0700")

Hi,

Dan Nicolaescu <dann@ics.uci.edu> 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;
}




  reply	other threads:[~2008-08-13 16:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13 16:10 start emacs without creating frames and connect with emacsclient later Dan Nicolaescu
2008-08-13 16:40 ` Johannes Weiner [this message]
2008-08-13 20:49 ` Stefan Monnier
2008-08-14  5:19 ` Richard M. Stallman
2008-08-14 17:21   ` Stefan Monnier
2008-08-15 12:44     ` Richard M. Stallman
2008-08-15 15:25       ` Dan Nicolaescu
2008-08-21 17:20   ` Dan Nicolaescu
2008-08-21 22:55     ` David De La Harpe Golden
2008-08-21 23:55       ` Dan Nicolaescu
2008-08-22  5:59         ` tomas
2008-08-22  7:24       ` Paul R
2008-08-22 11:58     ` David Hansen
2008-09-01 14:03       ` Dan Nicolaescu
2008-09-01 14:02   ` Dan Nicolaescu
2008-09-01 18:29     ` Stefan Monnier
2008-09-01 23:11       ` Dan Nicolaescu
2008-09-02 19:53         ` Stefan Monnier
2008-09-03  6:43           ` Dan Nicolaescu
2008-09-03  6:50             ` martin rudalics
2008-09-03 11:53               ` Dan Nicolaescu
2008-09-03 12:38                 ` martin rudalics
2008-09-03 20:14                   ` Dan Nicolaescu
     [not found]             ` <jwv7i9tyzk5.fsf-monnier+emacs@gnu.org>
     [not found]               ` <200809211007.m8LA7TLQ014367@mothra.ics.uci.edu>
     [not found]                 ` <87k5d5u359.fsf@cyd.mit.edu>
     [not found]                   ` <jwvabe14o4w.fsf-monnier+emacs@gnu.org>
     [not found]                     ` <200809211826.m8LIQBbq016320@mothra.ics.uci.edu>
     [not found]                       ` <jwvskrt2tbz.fsf-monnier+emacs@gnu.org>
2008-09-21 23:36                         ` Dan Nicolaescu
2008-08-15 15:36 ` Phil Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874p5oamwe.fsf@skyscraper.fehenstaub.lan \
    --to=hannes@saeurebad.de \
    --cc=dann@ics.uci.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).