bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to run server-start only if not already running?


From: Andreas Schwab
Subject: Re: How to run server-start only if not already running?
Date: Wed, 07 Nov 2007 00:35:47 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.1 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]