关于ubuntu的崇高文本3:如何使工作成为haskell构建系统?

时间:2016-03-28 18:31:30

标签: ubuntu haskell sublimetext3 sublimetext

我想创建一个构建系统来编译haskell文件;请注意,我不想替换常见的" CTRL + B"在ST窗口中运行当前文件的快捷方式。

所以,在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。

你可以帮帮我吗?

EDIT 谢谢你的第一个消息! 它工作,但现在我有另一个问题:我想删除目录中的所有文件,除了源文件和二进制文件。 我可以启动这个插件:

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)

但它不会删除文件。你可以再次帮助我吗?

1 个答案:

答案 0 :(得分:1)

只需几点:

  1. 您可以在Packages的子文件夹中创建插件,例如用户文件夹
  2. 键映射中的命令名称为snake_case,结尾Command被删除
  3. 您应该使用WindowCommand代替TextCommand构建系统
  4. 您应该按f1而不是fn+f1
  5. exec命令不会扩展变量
  6. 要创建您的行为,请按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)
    

    然后打开你的keymap并插入键绑定:

    {
        "keys": ["f1"],
        "command": "make_haskell",
        "context":
        [
            { "key": "selector", "operator": "equal", "operand": "source.haskell" }
        ]
    },
    

    编辑: 如果您希望之后使用shell rm命令进行清理,则应使用shell_cmd而不是cmd。 (exec假定shell_cmd为字符串,cmd为数组(why)) 之后我稍微修改了插件以进行清理:

    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)