unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thorsten Bonow <thorsten.bonow@post.rwth-aachen.de>
Subject: Re: server-start preempted by other emacs window
Date: Thu, 29 Jan 2004 19:39:10 +0100	[thread overview]
Message-ID: <87ad46ob01.fsf@herrrossi.mmweg.rwth-aachen.de> (raw)
In-Reply-To: jwv8yjskk8o.fsf-monnier+gnu.emacs.help@asado.iro.umontreal.ca

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

  parent reply	other threads:[~2004-01-29 18:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-28 16:34 server-start preempted by other emacs window John Russell
2004-01-28 18:33 ` Stefan Monnier
2004-01-28 20:33   ` John Russell
2004-01-29 16:52     ` Stefan Monnier
2004-01-29 18:39   ` Thorsten Bonow [this message]
2004-01-29 21:11     ` kgold
2004-02-08  9:50     ` Jari Aalto+mail.linux
2004-01-28 18:43 ` Kevin Rodgers
2004-01-28 20:31   ` John Russell
2004-01-29  7:19 ` Klaus Zeitler

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87ad46ob01.fsf@herrrossi.mmweg.rwth-aachen.de \
    --to=thorsten.bonow@post.rwth-aachen.de \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).