[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: server-start preempted by other emacs window
From: |
Thorsten Bonow |
Subject: |
Re: server-start preempted by other emacs window |
Date: |
Thu, 29 Jan 2004 19:39:10 +0100 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Rational FORTRAN, linux) |
>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Is there a way to have emacs check to see if another server
>> process is running before it runs server-start?
Stefan> Not really. It's pretty tricky to do. One way is to see
Stefan> if the socket file is present in /tmp. But then it might
Stefan> be left over from a previous Emacs that's not running any
Stefan> more. You could try and make sure that Emacs removes the
Stefan> socket file when it exits, but if it crashes, you're still
Stefan> left with a dead socket in /tmp. A more robust way is to
Stefan> check whether you can connect to the socket. In Emacs-CVS
Stefan> you could do that with make-network-stream.
Stefan> [...]
Stefan> Stefan
Hi, this was discussed before. I could not find the thread, but since
then I have this solution in my .emacs to prevent starting a second
server if one is already running:
--- cut here ---
;; ** emacsclient
(defun my-server-start-filter-function (process output)
"Filter function for `my-server-start', which checks for an
accessible Emacs process acting as a server by calling
`emacsclient --eval t' as an external asynchronous
process. Process output is filtered by this function which only
calls `server-start' when no server is running, id est the call
to emacsclient has failed."
(if (equal output "t\n")
(message "Not starting server, one instance already running...")
(message "Starting server...")
(server-start)))
;;
(defun my-server-start ()
"Call `server-start' only if no other accessible Emacs process
is already acting as a server for client processes."
(let ((process-connection-type nil))
(set-process-filter (start-process "my-process" nil "emacsclient" "--eval"
"t")
'my-server-start-filter-function)))
;;
(my-server-start)
--- cut here ---
Toto
--
Contact information and PGP key at
http://www-users.rwth-aachen.de/thorsten.bonow
Daydreaming while smoking cigars can be a fire hazard. It can be as
dangerous as drugs and booze unless you know what you're doing. If you
know what you're doing, it can be as safe as walking down the street.
Friedman, Kinky (1993), When the cat's away. New York (Wings Books),
418