如何在Atom文本编辑器中按文件类型设置默认语法? [英] How do I make a default syntax by filetype in Atom text editor?

查看:214
本文介绍了如何在Atom文本编辑器中按文件类型设置默认语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的.ejs文件具有html语法,但是,它始终以纯文本格式打开文件.

I want my .ejs files to have html syntax, however, it always opens the files as Plain Text.

在高级状态下,您可以选择使用当前扩展名全部打开...",然后选择语法.

In sublime you can choose "Open all with current extension as..." then choose your syntax.

我看到您可以在左下角更改语法.

I see that you can change the syntax in the left bottom corner

如何打开具有特定语法的特定类型的文件?

How do you open files with a certain type with a specific syntax?

推荐答案

简易模式:包含

如果您的语言确实只是HTML,则可以设置一个简单的程序包来处理此问题.

Easy mode: include

If your language really is just HTML, you can set up a simple package to handle this.

创建一个名为langugage-ejs的程序包,在grammars/ejs.cson中,您可以将HTML包含为您所关心的模式:

Create a package called langugage-ejs and in grammars/ejs.cson you can include HTML as having the patterns you care about:

'fileTypes': [
  'ejs'
]

'name': 'Embedded JavaScript'

'patterns': [
  {
    'include': 'source.html'
  }
]

'scopeName': 'source.ejs'

语言-ipynb 当然可以通过扩展JSON来实现.

language-ipynb certainly does this by extending JSON.

实际上,在HTML上有一些模板标记,您想让编辑器识别它们.我能找到的最佳示例是

In reality though, you have template tags on top of HTML that you would want to make the editor recognize. The best example I can find is for erb (Embedded Ruby templates). It sources from HTML but also adds on other tags as shown in this snippet:

...
'patterns': [
  {
    'begin': '<%+#'
    'captures':
      '0':
        'name': 'punctuation.definition.comment.erb'
    'end': '%>'
    'name': 'comment.block.erb'
  }
  {
    'begin': '<%+(?!>)[-=]?'
    'captures':
      '0':
        'name': 'punctuation.section.embedded.ruby'
    'end': '-?%>'
    'name': 'source.ruby.rails.embedded.html'
    'patterns': [
      {
        'captures':
          '1':
            'name': 'punctuation.definition.comment.ruby'
        'match': '(#).*?(?=-?%>)'
        'name': 'comment.line.number-sign.ruby'
      }
      {
        'include': 'source.ruby.rails'
      }
    ]
  }
  {
    'include': 'text.html.basic'
  }
]
...

这篇关于如何在Atom文本编辑器中按文件类型设置默认语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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