From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rustom Newsgroups: gmane.emacs.help Subject: emacs as a service Date: Sun, 8 Mar 2009 06:52:01 -0700 (PDT) Organization: http://groups.google.com Message-ID: <25226f9f-0d90-4350-99b6-eb1becce3cb2@l37g2000vba.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1236523252 17470 80.91.229.12 (8 Mar 2009 14:40:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Mar 2009 14:40:52 +0000 (UTC) Cc: Scott Turner To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 08 15:42:08 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LgKCc-0000GQ-Qv for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Mar 2009 15:42:07 +0100 Original-Received: from localhost ([127.0.0.1]:55597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LgKBH-0005MD-5L for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Mar 2009 10:40:43 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!l37g2000vba.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 120 Original-NNTP-Posting-Host: 220.225.70.2 Original-X-Trace: posting.google.com 1236520321 1175 127.0.0.1 (8 Mar 2009 13:52:01 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sun, 8 Mar 2009 13:52:01 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l37g2000vba.googlegroups.com; posting-host=220.225.70.2; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui User-Agent: G2/1.0 X-HTTP-Via: 1.1 PT-PROXY2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167460 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62759 Archived-At: 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!)