On Sep 11, 10:45Â pm, Oleksandr Gavenko gmail.com> wrote:
> Rustom Mody wrote:
>> I am trying to construct a command line such that:
>
>> if emacs is running the client asks the server to raise-frame else it
>> calls runemacs.
>
>> The command line Ive given is:
>> $ emacsclient -a runemacs -e "(raise-frame)"
>
>> But this opens a file (or buffer) called '(raise-frame)' Â !!
>
>> Of course just
>> $ emacsclient -e "(raise-frame)"
>
>> raises the emacs frame alright but fails for the case of no server.
>
>> 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
>> ------------------------
>> 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)
>
> On Windows I wrote e.bat. Usually at Total Commander or Far file manager
> Â I find file by cursor, type e and emacs popup with
> opened file (if it already not opened I get error and quickly type
> ). As for me `--no-wait' very useful not needed type C-x # and I
> can come back to the opened file later typing C-x b.
>
> @echo off
> REM Copyright (C) 2008 by Oleksandr Gavenko gmail.com>
>
> REM View file in emacs buffer using emacsclientw.
> REM If emacs not already running, run it.
> REM Put this file (e.bat) in your PATH.
> REM Name `e' because `edit'.
>
> if "%%1" == "-h" Â Â goto usage
> if "%%1" == "-help" Â goto usage
> if "%%1" == "--help" goto usage
>
> %%HOME%%\..\bin\emacs\bin\emacsclientw.exe -a emacs -n "%%*"
> goto EOF
>
> :usage
> @echo Win emacs run script.
> @echo Usage
> @echo e [-h^|--help] ^
>
> :EOF
The emacs-wiki code is better because it does not 'error'
And my code is better because it does something useful in all 4 cases:
(with and without file argument; with and without emacs server
running)
My question was basically about some way of making the VBS code more
efficient and shorter.