all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* server-start preempted by other emacs window
@ 2004-01-28 16:34 John Russell
  2004-01-28 18:33 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: John Russell @ 2004-01-28 16:34 UTC (permalink / raw)


Is there a way to have emacs check to see if another server process
is running before it runs server-start?

My issue is that if I have one emacs window open (my IDE) and then
open another one for gnus, the last one opened always destroys any
server process in existence.  So all emacsclient calls go to the gnus
window, and when that window gets closed, there is no longer any
server running at all.

I was hoping for a boolean function call or something, but apropos
wasn't helpful.  Any ideas?  Thanks.


John

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

* Re: server-start preempted by other emacs window
  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 18:39   ` Thorsten Bonow
  2004-01-28 18:43 ` Kevin Rodgers
  2004-01-29  7:19 ` Klaus Zeitler
  2 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2004-01-28 18:33 UTC (permalink / raw)


> Is there a way to have emacs check to see if another server process
> is running before it runs server-start?

Not really.  It's pretty tricky to do.
One way is to see if the socket file is present in /tmp.
But then it might be left over from a previous Emacs that's not running
any more.  You could try and make sure that Emacs removes the socket file
when it exits, but if it crashes, you're still left with a dead socket in
/tmp.
A more robust way is to check whether you can connect to the socket.
In Emacs-CVS you could do that with make-network-stream.

But what people usually do is that they do not start-server automatically
for each and every Emacs process, instead they either do it manually for
the Emacs process they care about, or they do it via arguments passed to
Emacs when starting up.
E.g. I start my main emacs as `emacs-server' which is an alias for
something like `emacs -geometry AxB+C+Z -f my-server-mode' where
my-server-mode is a function defined in my .emacs that calls server-start
and does a few other things that I only want done in my main Emacs but not
in the Emacs I use to read Gnus, e.g.


        Stefan

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

* Re: server-start preempted by other emacs window
  2004-01-28 16:34 server-start preempted by other emacs window John Russell
  2004-01-28 18:33 ` Stefan Monnier
@ 2004-01-28 18:43 ` Kevin Rodgers
  2004-01-28 20:31   ` John Russell
  2004-01-29  7:19 ` Klaus Zeitler
  2 siblings, 1 reply; 10+ messages in thread
From: Kevin Rodgers @ 2004-01-28 18:43 UTC (permalink / raw)


John Russell wrote:

> Is there a way to have emacs check to see if another server process
> is running before it runs server-start?
> 
> My issue is that if I have one emacs window open (my IDE) and then
> open another one for gnus, the last one opened always destroys any
> server process in existence.  So all emacsclient calls go to the gnus
> window, and when that window gets closed, there is no longer any
> server running at all.
> 
> I was hoping for a boolean function call or something, but apropos
> wasn't helpful.  Any ideas?  Thanks.

C-h v server-process
C-h v server-clients

-- 
Kevin Rodgers

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

* Re: server-start preempted by other emacs window
  2004-01-28 18:43 ` Kevin Rodgers
@ 2004-01-28 20:31   ` John Russell
  0 siblings, 0 replies; 10+ messages in thread
From: John Russell @ 2004-01-28 20:31 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> John Russell wrote:
> 
> > Is there a way to have emacs check to see if another server process
> > is running before it runs server-start?
> > My issue is that if I have one emacs window open (my IDE) and then
> > open another one for gnus, the last one opened always destroys any
> > server process in existence.  So all emacsclient calls go to the gnus
> > window, and when that window gets closed, there is no longer any
> > server running at all.
> > I was hoping for a boolean function call or something, but apropos
> > wasn't helpful.  Any ideas?  Thanks.
> 
> C-h v server-process

server-process shows #<process server> after the server starts but it
stays that way if another emacs instance takes over the server socket
so its not useful as a test.


> C-h v server-clients

This list is nil if there are no pending client buffers, Also if you run
emacsclient with -n,  which I do because I use it in my filemanager
to edit files all in one window so I want emacsclient to return
immediately. 


Thanks anyway.

John


>
> 
> -- 
> Kevin Rodgers

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

* Re: server-start preempted by other emacs window
  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
  1 sibling, 1 reply; 10+ messages in thread
From: John Russell @ 2004-01-28 20:33 UTC (permalink / raw)


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?
> 
> Not really.  It's pretty tricky to do.
> One way is to see if the socket file is present in /tmp.
> But then it might be left over from a previous Emacs that's not running
> any more.  You could try and make sure that Emacs removes the socket file
> when it exits, but if it crashes, you're still left with a dead socket in
> /tmp.

Yeah, that doesn't sound like the perfect solution.


> A more robust way is to check whether you can connect to the socket.
> In Emacs-CVS you could do that with make-network-stream.

that has promise, I'll look into that.



> 
> But what people usually do is that they do not start-server automatically
> for each and every Emacs process, instead they either do it manually for
> the Emacs process they care about, or they do it via arguments passed to
> Emacs when starting up.
> E.g. I start my main emacs as `emacs-server' which is an alias for
> something like `emacs -geometry AxB+C+Z -f my-server-mode' where
> my-server-mode is a function defined in my .emacs that calls server-start
> and does a few other things that I only want done in my main Emacs but not
> in the Emacs I use to read Gnus, e.g.
>

That's a good idea.  I have an alternate startup for emacs which just
starts the most minimal set of things possible and just runs in the
terminal.  Its a replacement for vi for sys-admin stuff when I don't
want the whole big emacs IDE thingy.  But this could also work for
gnus as well.  Thanks for the tip.

John

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

* Re: server-start preempted by other emacs window
  2004-01-28 16:34 server-start preempted by other emacs window John Russell
  2004-01-28 18:33 ` Stefan Monnier
  2004-01-28 18:43 ` Kevin Rodgers
@ 2004-01-29  7:19 ` Klaus Zeitler
  2 siblings, 0 replies; 10+ messages in thread
From: Klaus Zeitler @ 2004-01-29  7:19 UTC (permalink / raw)


>>>>> "John" == John Russell <jorussel@cisco.com> writes:
    John> 
    John> Is there a way to have emacs check to see if another server process
    John> is running before it runs server-start?
    John> 
    John> My issue is that if I have one emacs window open (my IDE) and then

I'm not sure what you mean with window here. I guess you mean a 2nd emacs.
For emacs a window is something different.

    John> open another one for gnus, the last one opened always destroys any
    John> server process in existence.  So all emacsclient calls go to the gnus
    John> window, and when that window gets closed, there is no longer any
    John> server running at all.

I've been using the following for years. I'm using gnuserv/gnudoit instead
of the standard emacsclient. It's been a long time that I've used emacsclient,
and IIRC old versions could only accept a file and no elisp code. I think
that was the reason why I switched to gnuserv/gnudoit. Thus I'm not sure
if one can do this similar with emacsclient. I think at least CVS emacs
has an improved emacsclient.

;; The following function allows to check if a server process is already running
;; (in case we start more than one emacs)
(defun gnuserv-running-p () "Checks whether a useful gnuserv is already running"
    (let ((output "")
	  (proc (condition-case ()
		    (start-process "gnudoit" nil "gnudoit" "1234")
		  (error nil))))

      (if proc
	  (progn
	    (set-process-filter proc
				(function
				 (lambda (proc string)
				   (setq output (concat output string)))))

	    ;; wait for output from gnudoit with a timeout of 4 seconds
	    (accept-process-output proc 4)
	    (set-process-filter proc nil)
	    ;;(message "server check returns: '%s'" output)
	    (eq (string-match "1234" output) 0)))))

(if (gnuserv-running-p)
    (message "Server is already running")
  (gnuserv-start))

HTH

Klaus

-- 
 ------------------------------------------
|  Klaus Zeitler      Lucent Technologies  |
 ------------------------------------------
---
My opinions may have changed, but not the fact that I am right.

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

* Re: server-start preempted by other emacs window
  2004-01-28 20:33   ` John Russell
@ 2004-01-29 16:52     ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2004-01-29 16:52 UTC (permalink / raw)


>> A more robust way is to check whether you can connect to the socket.
>> In Emacs-CVS you could do that with make-network-stream.

> that has promise, I'll look into that.

It might be interesting to integrate the resulting code in server.el.


        Stefan

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

* Re: server-start preempted by other emacs window
  2004-01-28 18:33 ` Stefan Monnier
  2004-01-28 20:33   ` John Russell
@ 2004-01-29 18:39   ` Thorsten Bonow
  2004-01-29 21:11     ` kgold
  2004-02-08  9:50     ` Jari Aalto+mail.linux
  1 sibling, 2 replies; 10+ messages in thread
From: Thorsten Bonow @ 2004-01-29 18:39 UTC (permalink / raw)


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

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

* Re: server-start preempted by other emacs window
  2004-01-29 18:39   ` Thorsten Bonow
@ 2004-01-29 21:11     ` kgold
  2004-02-08  9:50     ` Jari Aalto+mail.linux
  1 sibling, 0 replies; 10+ messages in thread
From: kgold @ 2004-01-29 21:11 UTC (permalink / raw)


I don't know if what I do is relevant, but in Unix, I start one
emacs session at login, which I keep running forever as a server.
>From then on, everything uses gnuclient for editing.

Curiously, in Windows I don't even have to do that.  gnuclient seems
smart enough to start the server if it isn't running.

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

* Re: server-start preempted by other emacs window
  2004-01-29 18:39   ` Thorsten Bonow
  2004-01-29 21:11     ` kgold
@ 2004-02-08  9:50     ` Jari Aalto+mail.linux
  1 sibling, 0 replies; 10+ messages in thread
From: Jari Aalto+mail.linux @ 2004-02-08  9:50 UTC (permalink / raw)


* Thu 2004-01-29 Thorsten Bonow <thorsten.bonow <AT> post.rwth-aachen.de>
* <http://groups.google.com/groups?oi=djq&as_umsgid=%3C87ad46ob01.fsf@herrrossi.mmweg.rwth-aachen.de>
| >>>>> "Stefan" == Stefan Monnier <monnier <AT> iro.umontreal.ca> writes:
| 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)

Unfortunately the emacsclient that Cygwin or Debian provides, does not
know --eval option. The above code fails, because the filter function
expects "t\n", when the real output is:

    /bin/emacsclient: unrecognized option `--eval'                           
    Usage: /bin/emacsclient [-a ALTERNATE-EDITOR] [-n] [--no-wait] [+LINE[:COLUMN]]\
     FILENAME                                                                       
    Or /bin/emacsclient --version                                                   
    Report bugs to bug-gnu-emacs <AT> gnu.org. 

It seems to be impossible to make and automatic test to see if one
Emacs is already running as server. Stefan's remark to upcoming network
connection functions offers a  solution.

Jari

-- 
http://tiny-tools.sourceforge.net/
Swatch @time   http://www.mir.com.my/iTime/itime.htm
               http://www.ryanthiessen.com/swatch/resources.htm
Use Licenses!  http://www.linuxjournal.com/article.php?sid=6225
Which Licence? http://www.linuxjournal.com/article.php?sid=4825
OSI Licences   http://www.opensource.org/licenses/

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

end of thread, other threads:[~2004-02-08  9:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.