unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* emacs as a service
@ 2009-03-08 13:52 rustom
  2009-03-08 14:08 ` Marc Tfardy
  2009-03-08 20:39 ` B. T. Raven
  0 siblings, 2 replies; 20+ messages in thread
From: rustom @ 2009-03-08 13:52 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Scott Turner

This is about tweaking emacs to run (somewhat like) a service.
Environment is emacs22 on win-XP.

I describing my current configuration with questions here and there in
the hope that some (better) solutions will come out.

Normally emacs runs with 1 or more windows (frames in emacsspeak)
multiple emacs processes have no relation wilth each other.

So in sort the typical setup is:
0 or more emacses each having 1 or more frame.

By a server setup I mean the following (which may not be proper usage
from the os service point of view)
0 or 1 emacs having 0 or more frames.

So first thing I did
--------------
; from http://www.emacswiki.org/cgi-bin/wiki/RupertSwarbrick#toc1
 (defun buffer-used-elsewhere-p (&optional buf)
   "Returns true if more than one window is attached to BUF in all
 frames. If buf is nil or not supplied, search
 for (CURRENT-BUFFER)."
   (unless buf (setq buf (current-buffer)))
   (< 1 (length (get-buffer-window-list buf nil t))))

 (defun delete-frame-ex ()
   "Delete frame as normal, unless we're on the last frame, in
   which case, exit emacs as we would normally do"
   (interactive)
   (if (eq (selected-frame) (next-frame (selected-frame) 0))
       ;; This is the last frame
       (save-buffers-kill-emacs)
    ;; There's more!
     (unless (buffer-used-elsewhere-p) (kill-buffer nil))
     (delete-frame)))

(global-set-key "\C-x\C-c" 'delete-frame-ex)
-----------------

This basically makes C-x C-c kill frames rather than kill emacs except
for the last one in which case it kills emacs.

Then recently got some solutions from Scott Turner that prompted me to
try again:

I changed the line
       (save-buffers-kill-emacs)
above to
       (make-frame-invisible (car (frame-list)) t)
which makes the last frame behavior consistent with the others (and
emacs unkillable unless one uses explicit M-x kill-emacs).  Basically
emacs disappears rather than dying.

Q: Obviously the (car (frame-list)) thingy is clumsy. Any better way?
Also I want to bind the X on the window top right to function delete-
frame-ex
rather than the default save-buffer-kill-emacs. How to do that?

To move to a more client-server oriented model.
The default emacs program that runs is to be replaced by this vbs
script
------------
Set objShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")

Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
Dim isRunning
isRunning = False

For Each objItem in colItems
  If InStr(objItem.CommandLine, "emacs.exe") Then
    isRunning = True
  End If
Next

parent = fso.GetParentFolderName(WScript.ScriptFullName)
If WScript.Arguments.Count = 1 Then
  If isRunning Then
    callString = parent & "/emacsclientw.exe -n """ & WScript.Arguments
(0) & """"
  Else
    callString = parent & "/runemacs.exe """ & WScript.Arguments(0) &
""""
  End If
Else
  If isRunning Then
    callString = parent & "/emacsclientw.exe -n -e ""(raise-frame)"""
  else
    callString = parent & "/runemacs.exe"
  End If
End if
objShell.Run(callString)
-------------
Q: Whats the diff between emacs and runemacs?
Q: The for loop is ugly but my windows/vbs is out of depth here

This script basically does a 4=2x2 way check:
Is emacs server running or not?
Is the script called with an argument or not?
And the default bindings for emacs-ish files (in my case .txt, .org)
is bound to this script in the registry.

If someone can offer HKEY magic to automate this that'd be nice.

Now one fragile aspect of this is that if 2 emacsservers run well the
system is borked!  How is the (server-start) to be enclosed in a
(if server-not-started-p ...) ?

And one (entirely windowsy) related question:
How to catch the system login, logout, shutdown etc events?
Once I can get some script to give me some control for this I can use
emacsclient to do appropriate actions.

Thanks (if you read so far!)


^ permalink raw reply	[flat|nested] 20+ messages in thread
* emacs as a service
@ 2008-08-29  6:42 Rustom Mody
  2008-08-29  9:46 ` Nikolaj Schumacher
  0 siblings, 1 reply; 20+ messages in thread
From: Rustom Mody @ 2008-08-29  6:42 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

I want to start emacs as a service (This is under windows)
The emacs-y side is easy (server-start)
But I want to do it also from the windows perspective.
This involves:
-- starting emacs as a service (using Sc perhaps??)
-- emacs should not (by default) show in a tab on the desktop
-- C-x C-c should close a frame not emacs
-- it should be possible for emacs to be running without there being any
frame

Anyone done somethng like this?

[-- Attachment #2: Type: text/html, Size: 574 bytes --]

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

end of thread, other threads:[~2009-03-09 22:01 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.17859.1219992155.18990.help-gnu-emacs@gnu.org>
2008-08-29  6:52 ` emacs as a service Torsten Mueller
2008-08-29 15:06 ` Chet
2008-08-29 16:04 ` Ken Goldman
2008-08-29 16:24 ` Dan Espen
2009-03-08 13:52 rustom
2009-03-08 14:08 ` Marc Tfardy
2009-03-08 20:39 ` B. T. Raven
2009-03-09 11:42   ` rustom
2009-03-09 22:01     ` Chris McMahan
  -- strict thread matches above, loose matches on Subject: below --
2008-08-29  6:42 Rustom Mody
2008-08-29  9:46 ` Nikolaj Schumacher
2008-08-29 11:41   ` Rustom Mody
2008-08-29 13:41     ` Nikolaj Schumacher
2008-08-29 14:40       ` Eli Zaretskii
2008-08-29 16:40         ` Nikolaj Schumacher
2008-08-30 10:53       ` Rustom Mody
     [not found]       ` <mailman.17988.1220093630.18990.help-gnu-emacs@gnu.org>
2008-09-02 18:00         ` Ken Goldman
2008-09-02 18:34           ` Richard G Riley
2008-09-02 18:42             ` Pascal J. Bourguignon
     [not found]   ` <mailman.17876.1220010121.18990.help-gnu-emacs@gnu.org>
2008-08-29 13:05     ` Torsten Mueller

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