[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacsclient commandline
From: |
Rustom Mody |
Subject: |
Re: emacsclient commandline |
Date: |
Thu, 21 Aug 2008 11:20:17 +0530 |
On Wed, Aug 20, 2008 at 9:04 PM, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:
> Rustom Mody wrote:
>> Another minor point:
>> When emacsclient is used with the -a option and there is no server
>> running it pops up a window saying ERROR No error !!
>> I guess this is an error (in emacsclient) :-)
>>
>> Starting from the vbs file on the emacswiki Ive constructed my own
>> launch-emacs as below but I dont like the loop and the sql and all the
>> heavy stuff, hence this attempt.
>>
>> My launch-emacs-client.vbs
>
> There is some stuff on EmacsWiki about this.
>
As I said I got this from there:
http://www.emacswiki.org/cgi-bin/wiki/EmacsClient#toc6
But I dont like this code. There are a number of reasons (it is hip
to dislike vb not being one of them)
a) emacsclient already has a mechanism builtin (via the alternate
editor) to do the equivalent of
if emacs-server running then do X else do Y
b) It uses a for loop going through all the processes whereas it
should stop when it finds an emacs running
c) It does nothing useful when it is called without an argument.
So I wrote the below code. It corrects (c) by spelling out 4 explicit cases:
-- Argument (file) given and emacs-server running
-- Arg given and server not running
-- No arg and server running
-- No arg and no server
My code below corrects c. My question was for correcting a. If that
is done b gets solved automatically else if anyone knows how to solve
b that is fine (though that is really a vbs/wscript question not an
emacs/elisp one)
Heres my current code. Below that the code on emacswiki
----------------------------------
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)
-------------------------
emacswiki code
------------------------
Set objShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count = 1 Then
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
If isRunning Then
objShell.Run(fso.GetParentFolderName(WScript.ScriptFullName) &
"/emacsclientw.exe -n """ & WScript.Arguments(0) & """")
Else
objShell.Run(fso.GetParentFolderName(WScript.ScriptFullName) &
"/runemacs.exe """ & WScript.Arguments(0) & """")
End If
Else
objShell.Run(fso.GetParentFolderName(WScript.ScriptFullName) &
"/runemacs.exe")
End If