本文介绍了按键绑定的Atom数据语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以对Atom的data-grammar属性的语法(在键绑定选择器中使用)进行完整的解释吗?

Can someone give a full explanation of the syntax for Atom's data-grammar attribute (used in keybinding selectors)?

例如,

[data-grammar='source example']

[data-grammar~='source example']

?

此外,您如何指定多个语法?例如,您如何指定键绑定应限制为html或xml格式?

Also, how do you specify multiple grammars? For instance, how would you specify that a key binding should be limited to html or xml formats?

如果某处已经有文档,我还没有找到它,但是希望您指出来.

If there already exists documentation on this somewhere, I have not yet found it, but would appreciate being pointed to it.

推荐答案

快速示例:

keymap.cson :

"atom-text-editor[data-grammar='text tex latex']":
  'f5':'latex:build'

语法信息和文档

我首先查看了 file-types 包. sourcetext对语言进行分类-source处理开发语言,而text处理文档/日志格式.您可以通过阅读飞行手册来添加和自定义语言识别.我已经在下面链接了一些特定的部分,对此很有帮助.

Grammar Information & Documentation

I began by looking at the file-types package. source and text categorize languages - source deals with development languages, while text deals with documentation/logs formats. You can add and customize language recognition by reading the flight manual. I've linked some specific sections below that are helpful for that.

语言特定设置

使用[data-grammar]:

在深度"的键盘映射"部分中列出了所提供的少量文档.

Working with [data-grammar]:

The little doocumentation given is listed under the Keymaps in Depth section.

这也描述了下面使用的not([...])功能以及如何操作各种规则.

This also describes the not([...]) functionality used below and how to manipulate various rules.

尽管在上面,语法以点格式(即source.c)列出,要在[data-grammar='<name>']格式中使用它们,则需要空格.

Although in the above, grammars are listed in a dot format, ie source.c, to use them in the [data-grammar='<name>'] format spaces are instead required.

我如何在keymap.cson配置中使用数据语法选项的示例如下(在这里,我使用的是Latex包):

An example of how I might use the data grammar option in my keymap.cson config is as such (here I'm using the latex package):

"atom-text-editor[data-grammar='text tex latex']":
  'f5':'latex:build'

对于所需的数据语法功能,~不是正确的语法.而是使用"atom-text-editor:not([data-grammar='<name>'])":

The ~ is not the correct syntax for desired functionality with data-grammar. Instead, use something like "atom-text-editor:not([data-grammar='<name>'])":

请注意,您不会在config.cson之类的内容中使用data-grammar.特定于语言的语法看起来像这样:

Note that you wouldn't use data-grammar in something like config.cson. The syntax for language specifics looks something like this instead:

# **config.cson**
".latex.tex.text":
  editor:
    softWrap: true

其他有用信息-已注册语法的列表

通过开发控制台转储Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n')的输出(查看>开发人员>切换开发人员选项>控制台)

Extra useful information - List of registered Grammars

A dump of the output of Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n') through the Dev Console (View > Developer > Toggle Developer Options > Console)

source.c
source.cake
source.clojure
source.coffee
source.cpp
source.cs
source.css
source.css.less
source.css.scss
source.csx
source.diff
source.gfm
source.git-config
source.go
source.gotemplate
source.java
source.java-properties
source.js
source.js.rails source.js.jquery
source.js.regexp
source.js.regexp.replacement
source.json
source.litcoffee
source.makefile
source.nant-build
source.objc
source.objcpp
source.perl
source.perl6
source.plist
source.python
source.python.django
source.regexp.python
source.ruby
source.ruby.gemfile
source.ruby.rails
source.ruby.rails.rjs
source.sass
source.shell
source.sql
source.sql.mustache
source.sql.ruby
source.strings
source.toml
source.verilog
source.yaml
text.bibtex
text.git-commit
text.git-rebase
text.html.basic
text.html.erb
text.html.gohtml
text.html.jsp
text.html.mustache
text.html.php
text.html.ruby
text.hyperlink
text.junit-test-report
text.log.latex
text.plain
text.plain.null-grammar
text.python.console
text.python.traceback
text.shell-session
text.tex
text.tex.latex
text.tex.latex.beamer
text.tex.latex.memoir
text.todo
text.xml
text.xml.plist
text.xml.xsl

这篇关于按键绑定的Atom数据语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 10:33