ubuntu 上的 sublime text 3:如何使用 haskell 构建系统?
sublime text 3 on ubuntu : how to make work an haskell build system?
我想创建一个构建系统以编译 haskell 个文件;请注意,我不想替换在 ST window.
中运行当前文件的常见 "CTRL+B" 快捷方式
所以,在 this messages 之后,我创建了这个文件,位于目录“/opt/sublime_text”中:
import sublime, sublime_plugin
class MakeHaskellCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command('exec', {"working_dir":"${project_path:${folder}}",'cmd': ["ghc","$file"]})
然后,我修改了sublime-haskell包的用户键绑定:
[
{
"keys": ["f1"],
"context": [
{ "key": "haskell_source" },
{ "key": "scanned_source" } ],
"command": "MakeHaskellCommand"
}
]
但是在ST重启后,按FN+F1没有任何反应。
你能帮帮我吗?
编辑
感谢您的第一条消息!
它有效,但现在我有另一个问题:我想删除目录中的所有文件,除了源文件和二进制文件。
我可以启动这个插件:
import sublime
import sublime_plugin
class MakeHaskell2Command(sublime_plugin.WindowCommand):
def run(self):
variables = self.window.extract_variables()
args = sublime.expand_variables({
"working_dir": "${project_path:${file_path}}",
"cmd": ["rm", "*.hi"],
"cmd": ["rm", "*.o"]
}, variables)
self.window.run_command('exec', args)
但它不会删除文件。你能再帮我一下吗?
几点:
- 您在包的子文件夹中创建插件,例如用户文件夹
- 键盘映射中的命令名称是 snake_case,删除了结尾
Command
- 您应该使用
WindowCommand
而不是构建系统 TextCommand
- 你应该按
f1
而不是 fn+f1
- exec命令不展开变量
要创建您的行为,请按 Tools >>> New Plugin...
,粘贴并保存:
import sublime
import sublime_plugin
class MakeHaskellCommand(sublime_plugin.WindowCommand):
def run(self):
variables = self.window.extract_variables()
args = sublime.expand_variables({
"working_dir": "${project_path:${file_path}}",
"cmd": ["ghc", "$file"]
}, variables)
self.window.run_command('exec', args)
然后打开您的键盘映射并插入键绑定:
{
"keys": ["f1"],
"command": "make_haskell",
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.haskell" }
]
},
编辑:
如果你想在之后使用 shell rm
命令进行清理,那么你应该使用 shell_cmd
而不是 cmd
。 (exec
假设 shell_cmd
是一个字符串,cmd
是一个数组())
我稍微修改了插件以进行清理:
import sublime
import sublime_plugin
class MakeHaskellCommand(sublime_plugin.WindowCommand):
def run(self):
variables = self.window.extract_variables()
args = sublime.expand_variables({
"working_dir": "$file_path",
"shell_cmd": "ghc $file && rm $file_base_name.o $file_base_name.hi"
}, variables)
self.window.run_command('exec', args)
我想创建一个构建系统以编译 haskell 个文件;请注意,我不想替换在 ST window.
中运行当前文件的常见 "CTRL+B" 快捷方式所以,在 this messages 之后,我创建了这个文件,位于目录“/opt/sublime_text”中:
import sublime, sublime_plugin
class MakeHaskellCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command('exec', {"working_dir":"${project_path:${folder}}",'cmd': ["ghc","$file"]})
然后,我修改了sublime-haskell包的用户键绑定:
[
{
"keys": ["f1"],
"context": [
{ "key": "haskell_source" },
{ "key": "scanned_source" } ],
"command": "MakeHaskellCommand"
}
]
但是在ST重启后,按FN+F1没有任何反应。
你能帮帮我吗?
编辑 感谢您的第一条消息! 它有效,但现在我有另一个问题:我想删除目录中的所有文件,除了源文件和二进制文件。 我可以启动这个插件:
import sublime
import sublime_plugin
class MakeHaskell2Command(sublime_plugin.WindowCommand):
def run(self):
variables = self.window.extract_variables()
args = sublime.expand_variables({
"working_dir": "${project_path:${file_path}}",
"cmd": ["rm", "*.hi"],
"cmd": ["rm", "*.o"]
}, variables)
self.window.run_command('exec', args)
但它不会删除文件。你能再帮我一下吗?
几点:
- 您在包的子文件夹中创建插件,例如用户文件夹
- 键盘映射中的命令名称是 snake_case,删除了结尾
Command
- 您应该使用
WindowCommand
而不是构建系统TextCommand
- 你应该按
f1
而不是fn+f1
- exec命令不展开变量
要创建您的行为,请按 Tools >>> New Plugin...
,粘贴并保存:
import sublime
import sublime_plugin
class MakeHaskellCommand(sublime_plugin.WindowCommand):
def run(self):
variables = self.window.extract_variables()
args = sublime.expand_variables({
"working_dir": "${project_path:${file_path}}",
"cmd": ["ghc", "$file"]
}, variables)
self.window.run_command('exec', args)
然后打开您的键盘映射并插入键绑定:
{
"keys": ["f1"],
"command": "make_haskell",
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.haskell" }
]
},
编辑:
如果你想在之后使用 shell rm
命令进行清理,那么你应该使用 shell_cmd
而不是 cmd
。 (exec
假设 shell_cmd
是一个字符串,cmd
是一个数组(
import sublime
import sublime_plugin
class MakeHaskellCommand(sublime_plugin.WindowCommand):
def run(self):
variables = self.window.extract_variables()
args = sublime.expand_variables({
"working_dir": "$file_path",
"shell_cmd": "ghc $file && rm $file_base_name.o $file_base_name.hi"
}, variables)
self.window.run_command('exec', args)