all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Reuben Thomas <rrt@sc3d.org>
Cc: Emacs Bugs <bug-gnu-emacs@gnu.org>
Subject: Re: How to run server-start only if not already running?
Date: Wed, 07 Nov 2007 00:35:47 +0100	[thread overview]
Message-ID: <jer6j3rlpo.fsf@sykes.suse.de> (raw)
In-Reply-To: <alpine.DEB.0.9999.0711062132520.11917@localhost.localdomain> (Reuben Thomas's message of "Tue\, 6 Nov 2007 21\:41\:42 +0000 \(GMT\)")

Reuben Thomas <rrt@sc3d.org> writes:

> Sometimes, normally by error, I start a second Emacs. Since my .emacs runs
> server-start, this overrides the server I run in my normally-running
> Emacs. After quitting the erroneously-started Emacs, I no longer have a
> server and need manually to restart it. Is there some way to run
> server-start in my .emacs only if there's no server currently? It'd be
> nice to make this easy!

I'm using this:

(when (and (file-exists-p (expand-file-name server-name server-socket-dir))
	   (let ((status (call-process "/usr/bin/lsof"
				       nil nil nil
				       (expand-file-name server-name
							 server-socket-dir))))
	     (or (not (numberp status)) (equal status 0))))
  (setq server-name (format "%s-%d" server-name (emacs-pid)))
  (add-hook 'kill-emacs-hook
    (lambda () (condition-case nil
		   (delete-file (expand-file-name server-name
						  server-socket-dir))
		 (error nil)))))
(server-start)

> Possibly alternatively, it'd be nice to enable emacsclient to start a
> server process if there's already a running Emacs but no server running in
> it.

Kinda chicken-and-egg: how do you contact the running Emacs without the
server?

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




  reply	other threads:[~2007-11-06 23:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-06 21:41 How to run server-start only if not already running? Reuben Thomas
2007-11-06 23:35 ` Andreas Schwab [this message]
2007-11-06 23:38   ` Reuben Thomas
2007-11-06 23:56     ` Lennart Borgman (gmail)
2007-11-07  0:00       ` Reuben Thomas
2007-11-06 23:46   ` Reuben Thomas
2007-11-07  7:56   ` Richard Stallman
2007-11-07  9:42     ` Andreas Schwab
2007-11-08  4:41       ` Richard Stallman
2007-11-08  9:49         ` Andreas Schwab

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

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

  git send-email \
    --in-reply-to=jer6j3rlpo.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=bug-gnu-emacs@gnu.org \
    --cc=rrt@sc3d.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.