From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johannes Weiner Newsgroups: gmane.emacs.devel Subject: Re: start emacs without creating frames and connect with emacsclient later Date: Wed, 13 Aug 2008 18:40:49 +0200 Message-ID: <874p5oamwe.fsf@skyscraper.fehenstaub.lan> References: <200808131610.m7DGAkvk020047@sallyv1.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1218645700 11575 80.91.229.12 (13 Aug 2008 16:41:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Aug 2008 16:41:40 +0000 (UTC) Cc: emacs-devel@gnu.org To: Dan Nicolaescu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 13 18:42:32 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KTJQS-0002Mh-Ss for ged-emacs-devel@m.gmane.org; Wed, 13 Aug 2008 18:42:21 +0200 Original-Received: from localhost ([127.0.0.1]:41054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTJPW-0001mO-EJ for ged-emacs-devel@m.gmane.org; Wed, 13 Aug 2008 12:41:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KTJPS-0001m3-Iw for emacs-devel@gnu.org; Wed, 13 Aug 2008 12:41:18 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KTJPR-0001ln-2h for emacs-devel@gnu.org; Wed, 13 Aug 2008 12:41:18 -0400 Original-Received: from [199.232.76.173] (port=48085 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTJPQ-0001lf-Ui for emacs-devel@gnu.org; Wed, 13 Aug 2008 12:41:16 -0400 Original-Received: from saeurebad.de ([85.214.36.134]:36209) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KTJPQ-0003my-Cc for emacs-devel@gnu.org; Wed, 13 Aug 2008 12:41:16 -0400 Original-Received: by saeurebad.de (Postfix, from userid 107) id 417FC2F00CA; Wed, 13 Aug 2008 18:41:14 +0200 (CEST) Original-Received: from localhost (83-221-69-159.dynamic.primacom.net [83.221.69.159]) by saeurebad.de (Postfix) with ESMTP id 22B6F2F00C4; Wed, 13 Aug 2008 18:41:13 +0200 (CEST) In-Reply-To: <200808131610.m7DGAkvk020047@sallyv1.ics.uci.edu> (Dan Nicolaescu's message of "Wed, 13 Aug 2008 09:10:46 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.1.3 X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:102411 Archived-At: Hi, Dan Nicolaescu 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 #include #include #include #include #include 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; }