SublimeText 2 和 SublimeText 2 scala.sublime-build 文件

发布于 2024-12-15 03:39:45 字数 921 浏览 0 评论 0原文

我正在尝试使用 Sublime Text 2 在 Windows 7 64 位下使用 Scala 2.9.1 编辑和运行 Scala 脚本。我创建了以下 scala.submline-build 文件,尝试跟踪从命令行输入以下内容时发生的情况:

C:\work\Scala>scala ScalaGreetings.scala
Greetings from Scala...
C:\work\Scala>

scala.sublime-build 的内容如下:

{
    "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat $File"]
}

在 Sublime 中加载简单的 Scala 脚本在“文本”选项卡上,按 F7 键会导致 Scala 解释器被加载并运行,但脚本不会按预期执行。 “构建”窗口中将显示以下内容:

Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java    1.7.0_01).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 

考虑到这一点,我将感谢您对以下问题的帮助和反馈;

1.) 我可以在 Sublime Text 2 中执行 Scala 脚本,并在成功解释脚本后将其输出显示在“构建”窗口中吗?

2.)假设上述问题的答案是肯定的,我的 scala.sublime-text 文件缺少什么和/或不正确?

3.) 在将 Sublime Text 2 与 Scala 一起使用时,我应该查看任何其他资源吗,特别是 Scala 的 Sublime 项目文件?

I'm trying to use Sublime Text 2 to edit and run Scala script under Windows 7 64-Bit using Scala 2.9.1. I've created the following scala.submline-build file, attempting to follow what happens when I enter the following from the command line:

C:\work\Scala>scala ScalaGreetings.scala
Greetings from Scala...
C:\work\Scala>

The contents of the scala.sublime-build are as follows:

{
    "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat $File"]
}

With the simple Scala script loaded in a Sublime Text tab, pressing the F7 key results in the Scala interpreter being loaded and running, but the script does not execute as expected. The following appears in the Build window:

Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java    1.7.0_01).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 

With this in mind, I would appreciate your help and feedback with the following questions;

1.) Can I execute a Scala script from within Sublime Text 2 and have its output display inside the Build window after the script is successfully interpreted?

2.) Assuming the answer to the question above is yes, what is missing and/or incorrect with my scala.sublime-text file?

3.) Are there any additional resources I should look at on using Sublime Text 2 with Scala, especially in the way of Sublime Project files for Scala?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

时光匆匆的小流年 2024-12-22 03:39:45

尝试使用这个代替:

{
    "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat", "$File"]
}

Try using this instead:

{
    "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat", "$File"]
}
那小子欠揍 2024-12-22 03:39:45

尝试这个构建设置,

{
    "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat","$file"]
}

我可以用它来解决。

try this build setting

{
    "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat","$file"]
}

i could solve with it.

寻找一个思念的角度 2024-12-22 03:39:45
{
  "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat", "$file"],
  "selector": "source.scala"
}

请注意,由于变量名称区分大小写,因此 $file 必须为小写。

selector 设置帮助 Sublime 自动选择构建系统。

有关详细信息,请查看 Sublime Text 的有关构建系统的参考

{
  "cmd": ["C:\\scala-2.9.1.final\\bin\\scala.bat", "$file"],
  "selector": "source.scala"
}

Note that since variable names are case-sensitive, $file must be in lower-case.

The selector setting helps Sublime automatically choose the build system.

For more info check the Sublime Text's reference on build systems.

§普罗旺斯的薰衣草 2024-12-22 03:39:45

我在构建 .scala 文件时遇到了一些问题,我注意到我需要将 shell 参数设置为 true 所以这是我的 build_systems >

"build_systems": 
[
    {
        "name": "Compile",
        "cmd": ["scalac", "Main.scala"],
        "shell": true,
        "working_dir": "<path to project folder>"
    },
    {
        "name": "Run",
        "cmd": ["scala", "Main.scala"],
        "shell": true,
        "working_dir": "<path to project folder>"
    }

]

我也总是设置 working_dir 参数,但我想这并不那么重要。

所以回答你的问题:

  1. 是的,是的,在脚本执行后,你可以在 sublime 中看到输出。

  2. 我希望我上面的配置能够帮助您。

  3. 我强烈建议您尝试 SublimeREPL 插件

I had some problems building .scala-files and what i noticed is that I needed to have the shell parameter set to true so here are my build_systems

"build_systems": 
[
    {
        "name": "Compile",
        "cmd": ["scalac", "Main.scala"],
        "shell": true,
        "working_dir": "<path to project folder>"
    },
    {
        "name": "Run",
        "cmd": ["scala", "Main.scala"],
        "shell": true,
        "working_dir": "<path to project folder>"
    }

]

I always set the working_dir parameter as well, but I guess that is not as important.

So to answer your questions:

  1. Yes, yeas you can see the output in sublime after the script has been executed.

  2. I hope my config above will help you with that.

  3. I highly recommend that you try the SublimeREPL plugin.

凌乱心跳 2024-12-22 03:39:45

这是针对 Mac OS X 的介绍,但我认为与 Windows,尤其是 Linux 没有太大区别。

在 Scala 中你有两个选择。

第一个选项是使用 Scala 解释器 scala

{
    "cmd": ["/usr/local/scala/bin/scala", "$file"], 
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.scala"
}

在我的例子中,我下载的 scala 文件夹位于 /usr/本地/


第二个选项是编译源代码。这有点困难。

{
    "cmd": ["build_scala.sh", "$file"], 
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.scala"
}

当然,您必须添加 build_scala.sh bash 脚本文件,例如在 /usr/bin/ 中:

#!/bin/bash          
# compiles all java files within directory and runs first argument
for file in *.scala
do
echo "Compiling $file"
/usr/local/scala/bin/scalac $file
done
echo "Running $1"
/usr/local/scala/bin/scala $1

通过输入 which build_scala 在终端中测试脚本。嘘

This is an introduction for Mac OS X, but I do not think, there is a big difference to Windows and especially to Linux.

In Scala you have two options.

First option is using the Scala interpreter scala:

{
    "cmd": ["/usr/local/scala/bin/scala", "$file"], 
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.scala"
}

In my case the scala folder, I have downloaded, are placed in /usr/local/.


The second option is to compile your source. This is a little bit more difficult.

{
    "cmd": ["build_scala.sh", "$file"], 
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.scala"
}

Of course you have to add the build_scala.sh bash script file, e. g. in /usr/bin/:

#!/bin/bash          
# compiles all java files within directory and runs first argument
for file in *.scala
do
echo "Compiling $file"
/usr/local/scala/bin/scalac $file
done
echo "Running $1"
/usr/local/scala/bin/scala $1

Test the script in your terminal by typing which build_scala.sh

穿透光 2024-12-22 03:39:45

对于 Windows,将 scala 路径添加到环境变量中
使用以下命令设置 Scala.sublime-build 文件:

{
"cmd": ["scala.bat", "$file"],
"selector": "source.scala"
}

For windows add scala path to your environment variable
Set the Scala.sublime-build file with following:

{
"cmd": ["scala.bat", "$file"],
"selector": "source.scala"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文