在选定的tex上建立的系统

2024-04-16 18:40:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有Postgres的构建系统:

{
    "cmd": ["psql", "-U", "postgres", "-d", "test", "-o", "c:/app/sql/result.txt", "-f", "$file"]
}

它工作正常,执行当前文件并将结果发送到文件^{{cd1>}。

我想修改它,以自动将当前选择保存到文件中,并在该文件上运行^{cd2>}。它能在构建系统中完成吗?


Tags: 文件testtxtcmdappsql系统postgres
1条回答
网友
1楼 · 发布于 2024-04-16 18:40:25

既然我的学习结出了果实,让我回答我自己的问题。简单插件将选定的文本保存在文件中并调用构建系统:

import sublime, sublime_plugin

class ExecuteSelectedSqlCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.sel():  
            if not region.empty():  
                with open('/a/temporary/file', 'w') as f:
                    f.write(self.view.substr(region))
                self.view.window().run_command('build')
                break

相关问题 更多 >