Search code examples
scalaensime

How to make ensime work in windows?


I'm new to emacs and I want to use ensime in Windows. I had a try but it doesn't work. It seems that it doesn't work because there is a *nix format file named "\ensime\bin\server.sh" . Very appreciate if someone give me some tips.

EDIT: I follow VonC's suggestion but it doesn't work perfect. I'm sure I have missed something. alt text I have installed emacs23.1 in dir D:\Dev\emacs-23.1 ,scala-mode in D:\Dev\emacs-23.1\scala-mode and ensime in D:\Dev\emacs-23.1\ensime.

Here is my .emacs file content:

;;禁用工具栏
(tool-bar-mode nil)

;;显示行号
(global-linum-mode t)

;;使用scala mode
(add-to-list 'load-path "D:/Dev/emacs-23.1/scala-mode/")
(require 'scala-mode)

(add-to-list 'auto-mode-alist '("\\.scala$" . scala-mode))
(add-to-list 'load-path "D:/Dev/emacs-23.1/ensime/src/elisp/")
(require 'ensime)
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)

and here is my D:\Dev\emacs-23.1\ensime.ensime file content:

(
:server-root "D:/Dev/emacs-23.1/ensime/"
:server-cmd  "D:/Dev/emacs-23.1/ensime/bin/server.bat"
:server-host "localhost"
:server-env ()

:project-package "com.ensime"
:source ("src")
:exclude-source ()
:classpath ("lib/jnotify/jnotify-0.93.jar"
        "lib/scala/scala-library.jar"
        "lib/scala/scala-compiler.jar")
)

and here is my D:\Dev\emacs-23.1\ensime\bin\server.bat file content:

@echo off
set PORT_FILE=%1
set CLASSPATH=D:\Dev\emacs-23.1\ensime\lib\jnotify\jnotify-0.93.jar;D:\Dev\emacs-23.1\ensime\lib\scala\scala-library.jar;D:\Dev\emacs-23.1\ensime\lib\scala\scala-compiler.jar;D:\Dev\emacs-23.1\ensime\dist\ensime.jar
java -classpath %CLASSPATH% -Djava.library.path=D:\Dev\emacs-23.1\ensime\lib\jnotify com.ensime.server.Server %PORT_FILE%

alt text http://www.turboimagehost.com/p/3350328/3769883.PNG.html


Solution

  • It should be a simple matter of porting the shell script in DOS in a server.bat:

    @echo off
    set PORT_FILE=%1
    set CLASSPATH=lib\scala\scala-library.jar;lib\scala\scala-compiler.jar;dist\ensime.jar
    java -classpath %CLASSPATH% -Djava.library.path=lib\jnotify com.ensime.server.Server %PORT_FILE%
    

    to be executed from the ensime directory.

    a more independent version (executable from any directory) would be:

    @echo off
    set t=%~dp0
    set adp0=%t::\=:\"%"
    cd %adp0%..
    set CLASSPATH=lib\scala\scala-library.jar;lib\scala\scala-compiler.jar;dist\ensime.jar
    java -classpath %CLASSPATH% -Djava.library.path=lib\jnotify com.ensime.server.Server %PORT_FILE%
    

    Even if ensime is in a path with spaces in it, it should work.

    • %~dp0 is the full path of the server.bat (path with potential spaces in it)
    • set adp0=%t::\=:\"%" will add double quotes around that path
    • %adp0%.. will refer to the ensime directory