How can a Sublime Text build system access the contents of a buffer, not a file?

柔情痞子 提交于 2019-12-04 10:58:16

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

"target": "my_plugin_class"

to your .sublime-build file instead of the standard

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

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.

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.

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!