all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to run server-start only if not already running?
@ 2007-11-06 21:41 Reuben Thomas
  2007-11-06 23:35 ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Reuben Thomas @ 2007-11-06 21:41 UTC (permalink / raw)
  To: Emacs Bugs

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!

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.

-- 
http://rrt.sc3d.org/ | dumb blonde, n. susbt. phr.  peroxymoron




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-06 21:41 How to run server-start only if not already running? Reuben Thomas
@ 2007-11-06 23:35 ` Andreas Schwab
  2007-11-06 23:38   ` Reuben Thomas
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Andreas Schwab @ 2007-11-06 23:35 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Emacs Bugs

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."




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-06 23:35 ` Andreas Schwab
@ 2007-11-06 23:38   ` Reuben Thomas
  2007-11-06 23:56     ` Lennart Borgman (gmail)
  2007-11-06 23:46   ` Reuben Thomas
  2007-11-07  7:56   ` Richard Stallman
  2 siblings, 1 reply; 10+ messages in thread
From: Reuben Thomas @ 2007-11-06 23:38 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Emacs Bugs

On Wed, 7 Nov 2007, Andreas Schwab wrote:

[useful code]

Thanks for that. Could something like this be built in as an option to 
server-start?

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

I don't know. I was hoping there was an answer.

-- 
http://rrt.sc3d.org/ | habit, n.  a shackle for the free (Bierce)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-06 23:35 ` Andreas Schwab
  2007-11-06 23:38   ` Reuben Thomas
@ 2007-11-06 23:46   ` Reuben Thomas
  2007-11-07  7:56   ` Richard Stallman
  2 siblings, 0 replies; 10+ messages in thread
From: Reuben Thomas @ 2007-11-06 23:46 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Emacs Bugs

On Wed, 7 Nov 2007, Andreas Schwab wrote:

> (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)

I needed to add (require 'server) to the start. After that it does exactly 
what I want, thanks.

-- 
http://rrt.sc3d.org/ | punline, n.  a punch line that really hurts




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-06 23:38   ` Reuben Thomas
@ 2007-11-06 23:56     ` Lennart Borgman (gmail)
  2007-11-07  0:00       ` Reuben Thomas
  0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2007-11-06 23:56 UTC (permalink / raw)
  To: Reuben Thomas; +Cc: Emacs Bugs

Reuben Thomas wrote:
> On Wed, 7 Nov 2007, Andreas Schwab wrote:
> 
> [useful code]
> 
> Thanks for that. Could something like this be built in as an option to 
> server-start?
> 
>> Kinda chicken-and-egg: how do you contact the running Emacs without the
>> server?
> 
> I don't know. I was hoping there was an answer.

What is possible is to make emacsclient start Emacs and the server, but 
I guess that is not what you want?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-06 23:56     ` Lennart Borgman (gmail)
@ 2007-11-07  0:00       ` Reuben Thomas
  0 siblings, 0 replies; 10+ messages in thread
From: Reuben Thomas @ 2007-11-07  0:00 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Bugs

On Wed, 7 Nov 2007, Lennart Borgman (gmail) wrote:

> Reuben Thomas wrote:
>> On Wed, 7 Nov 2007, Andreas Schwab wrote:
>> 
>> [useful code]
>> 
>> Thanks for that. Could something like this be built in as an option to 
>> server-start?
>> 
>>> Kinda chicken-and-egg: how do you contact the running Emacs without the
>>> server?
>> 
>> I don't know. I was hoping there was an answer.
>
> What is possible is to make emacsclient start Emacs and the server, but I 
> guess that is not what you want?

That's right. If I just have emacs and no server, it would be nice to get 
emacs to start the server.

-- 
http://rrt.sc3d.org/
Reality is what refuses to disappear when you stop believing in it (Dick)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-06 23:35 ` Andreas Schwab
  2007-11-06 23:38   ` Reuben Thomas
  2007-11-06 23:46   ` Reuben Thomas
@ 2007-11-07  7:56   ` Richard Stallman
  2007-11-07  9:42     ` Andreas Schwab
  2 siblings, 1 reply; 10+ messages in thread
From: Richard Stallman @ 2007-11-07  7:56 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: bug-gnu-emacs, rrt

      (add-hook 'kill-emacs-hook
	(lambda () (condition-case nil
		       (delete-file (expand-file-name server-name
						      server-socket-dir))
		     (error nil))))

Is it necessary to delete a socket explicitly when the process that
created it dies?  If so, shouldn't server.el do this normally?  It
appears currently to do delete the file only when you start a server,
not when you kill the Emacs.

If that change were made, your hack would be simpler, and we could
put into server.el too.  Why not?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-07  7:56   ` Richard Stallman
@ 2007-11-07  9:42     ` Andreas Schwab
  2007-11-08  4:41       ` Richard Stallman
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2007-11-07  9:42 UTC (permalink / raw)
  To: rms; +Cc: bug-gnu-emacs, rrt

Richard Stallman <rms@gnu.org> writes:

>       (add-hook 'kill-emacs-hook
> 	(lambda () (condition-case nil
> 		       (delete-file (expand-file-name server-name
> 						      server-socket-dir))
> 		     (error nil))))
>
> Is it necessary to delete a socket explicitly when the process that
> created it dies?

This is for compatibility with older versions of server.el, which didn't
do it by itself.

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."




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-07  9:42     ` Andreas Schwab
@ 2007-11-08  4:41       ` Richard Stallman
  2007-11-08  9:49         ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Stallman @ 2007-11-08  4:41 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: bug-gnu-emacs, rrt

    This is for compatibility with older versions of server.el, which didn't
    do it by itself.

That's good.  Would you like to write a patch for the trunk's server.el
to provide a feature more or less like this?
The two behaviors that seem possibly desirable are to
start the second server with a different name,
or not start a second server at all.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to run server-start only if not already running?
  2007-11-08  4:41       ` Richard Stallman
@ 2007-11-08  9:49         ` Andreas Schwab
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2007-11-08  9:49 UTC (permalink / raw)
  To: rms; +Cc: bug-gnu-emacs, rrt

Richard Stallman <rms@gnu.org> writes:

>     This is for compatibility with older versions of server.el, which didn't
>     do it by itself.
>
> That's good.  Would you like to write a patch for the trunk's server.el
> to provide a feature more or less like this?

The problem is that it needs to find out whether another process is
using the socket, which is not quite a portable thing to do.

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."




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-11-08  9:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-06 21:41 How to run server-start only if not already running? Reuben Thomas
2007-11-06 23:35 ` Andreas Schwab
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

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.