键绑定的原子数据 - 语法语法

问题描述 投票:3回答:2

有人可以完整解释Atom的数据语法属性(用于键绑定选择器)的语法吗?

例如,有什么区别

[data-grammar='source example']

[data-grammar~='source example']

?

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

如果已经存在关于这个的文档,我还没有找到它,但是会很感激被指向它。

atom-editor
2个回答
5
投票

Quick Example:

keymap.cson:

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

Grammar Information & Documentation

我开始看看file-types包。 sourcetext对语言进行分类 - source处理开发语言,而text处理文档/日志格式。您可以通过阅读航班手册来添加和自定义语言识别。我已将以下某些特定部分与之相关联。

飞行手册|基本定制:

Language Recognition

Language Specific Settings

[data-grammar]合作:

给出的小文档列在Keymaps in Depth部分下。

飞行手册|深度密钥图

Selectors and Custom Packages

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

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

我如何在我的keymap.cson配置中使用数据语法选项的一个例子是这样的(这里我使用的是latex包):

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

~不是数据语法所需功能的正确语法。相反,使用像"atom-text-editor:not([data-grammar='<name>'])":这样的东西

请注意,你不会在像data-grammar这样的东西中使用config.cson。语言细节的语法看起来像这样:

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

额外有用的信息 - 注册的语法列表

通过Dev Console转储Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n')的输出(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

2
投票

为了补充Mr G's answer,使用atom-text-editor[data-grammar~='html']~=意味着将<atom-text-editor> HTML元素与data-grammar属性匹配,该属性在任何其他可能的空格分隔的单词中包含“html”。

例如,如果文件的当前语言是PHP,那么文本编辑器HTML元素将如下所示:

<atom-text-editor data-grammar="text html php">

atom-text-editor[data-grammar~='html']将匹配这一点。

有关属性选择器的更多信息:https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

至于尝试选择多个语法,我认为除非他们在data-grammar属性中共享一个常用词,否则它是不可能的,例如,HTML和PHP共享“html”,或者C和JavaScript共享“源”(但在此案例许多其他语法共享“源”)。唯一的另一种方法是为每个语法单独指定一个键映射,即使它是相同的键组合。

© www.soinside.com 2019 - 2024. All rights reserved.