Sublime Text构建系统如何访问缓冲区而不是文件的内容? [英] How can a Sublime Text build system access the contents of a buffer, not a file?

查看:95
本文介绍了Sublime Text构建系统如何访问缓冲区而不是文件的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在Sublime Text 3(ST3)中打开了一个新缓冲区;如何从构建系统访问该缓冲区的内容? ie 假设我有一个构建系统,它将通过 node 运行一个文件,在这种情况下,我可以简单地使用 $文件,但据我所知,当前缓冲区的内容没有构建系统变量。有什么方法可以将当前选定的未保存缓冲区的内容拉入构建过程中?

Let's say I open a new buffer in Sublime Text 3 (ST3); how can I access the contents of that buffer from my build system? i.e. Let's say I have a build system that will run a file thorough node—in that case I can simply use $file, but as far as I can tell, there is no build system variable for the current buffer's contents. Is there any way to pull the contents of the currently selected, unsaved buffer into a build process?

推荐答案

为此,您将需要编写一个自定义插件来执行构建过程,然后添加

To do this you will need to write a custom plugin to perform the build process, then add

"target": "my_plugin_class"

到您的。sublime-构建文件而不是标准文件

"cmd": ["external_program", "option1", "option2", "$file"]

在您的插件中,您然后可以引用当前的视图,甚至是当前的窗口处理。您的插件可以很简单,例如将当前视图的内容写入临时文件,例如使用Python运行它,然后在完成后删除该临时文件。

In your plugin, you can then reference the current view, or even the current window if you have more than one tab open that you'd like to process. Your plugin could be as simple as writing the current view's contents to a temp file, running it with Python, for example, then deleting the temp file when you're done.

要了解如何执行标准构建过程,请查看 Packages / Default / exec.py 。您可以通过选择 Preferences->直接在Sublime Text 2中浏览该文件。浏览软件包... 。在ST3中,所有默认软件包都包装在 .sublime-package zip文件中,因此您需要安装出色的 PackageResourceViewer 插件。安装完成后,通过( Ctrl / Shift P 工具->命令面板 ,键入 prv 以显示 P ackage R esource V 浏览器选项,选择 PackageResourceViewer:打开资源 ,然后通过菜单选择默认-> exec.py

To get an idea of how the standard build process is executed, check out Packages/Default/exec.py. You can browse to this file directly in Sublime Text 2 by selecting Preferences -> Browse Packages.... In ST3, all default packages are wrapped up in .sublime-package zip files, so you'll need to install the excellent PackageResourceViewer plugin. Once installed, open the Command Palette with (Ctrl/)ShiftP or Tools -> Command Palette, type prv to bring up the PackageResourceViewer options, select PackageResourceViewer: Open Resource, then go through the menus to select Default -> exec.py.

祝你好运!

这篇关于Sublime Text构建系统如何访问缓冲区而不是文件的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆