如何从 atom 命令脚本 select JSON 语法?
How to select JSON grammar from atom command script?
我在下面的 init.js 中使用 Atom,objective 是:
- select全部
- 美化json
- 将语法更改为 json
我在执行第 3 步时遇到困难,下面是我的脚本:
atom.commands.add("atom-workspace", {
"custom:prettify-json": function() {
var view;
view = atom.views.getView(atom.workspace.getActiveTextEditor());
atom.commands.dispatch(view, "core:select-all");
atom.commands.dispatch(view, "pretty-json:prettify");
atom.commands.dispatch(view, "grammar-selector:show");
return true;
}
});
目前只发现grammar-sellector只有show功能,请问有什么方法可以选择“source.json”吗?
私有方法 setGrammar()
一直存在。它应该可以完成任务,除非开发人员决定在未来的版本中 remove/replace 它。
atom.commands.add("atom-workspace", {
"custom:prettify-json": function() {
const editor = atom.workspace.getActiveTextEditor();
const view = atom.views.getView(editor);
atom.commands.dispatch(view, "core:select-all");
atom.commands.dispatch(view, "pretty-json:prettify");
editor.setGrammar(atom.grammars.grammarForScopeName('source.json'));
return true;
}
});
我在下面的 init.js 中使用 Atom,objective 是:
- select全部
- 美化json
- 将语法更改为 json
我在执行第 3 步时遇到困难,下面是我的脚本:
atom.commands.add("atom-workspace", {
"custom:prettify-json": function() {
var view;
view = atom.views.getView(atom.workspace.getActiveTextEditor());
atom.commands.dispatch(view, "core:select-all");
atom.commands.dispatch(view, "pretty-json:prettify");
atom.commands.dispatch(view, "grammar-selector:show");
return true;
}
});
目前只发现grammar-sellector只有show功能,请问有什么方法可以选择“source.json”吗?
私有方法 setGrammar()
一直存在。它应该可以完成任务,除非开发人员决定在未来的版本中 remove/replace 它。
atom.commands.add("atom-workspace", {
"custom:prettify-json": function() {
const editor = atom.workspace.getActiveTextEditor();
const view = atom.views.getView(editor);
atom.commands.dispatch(view, "core:select-all");
atom.commands.dispatch(view, "pretty-json:prettify");
editor.setGrammar(atom.grammars.grammarForScopeName('source.json'));
return true;
}
});