【问题标题】:Atom -- snippets not workingAtom——片段不工作
【发布时间】:2017-11-29 10:30:24
【问题描述】:

以下是我在 sn-ps.cson 文件中编写的两个 sn-ps:

'.source.python':
  'print statement':
    'prefix': 'pr'
    'body' : 'print "${1:Hello world}"'


'.source.python':
  'Argument variables import':
    'prefix' : 'argv'
    'body' : 'from sys import argv'

第一个不起作用,但第二个起作用。请帮忙。

附言

当我第一次在我的机器上安装 atom 时,sn-ps 文件是空白的。我使用 Ubuntu 16.04。这正常吗?

【问题讨论】:

    标签: atom-editor


    【解决方案1】:

    我相信你的问题的根源是你的范围 .source.python 被声明了两次。

    首先回答您的第二个问题,不,我的 sn-ps.cson 文件在我第一次打开时不是空白的。相反,它包含以下内容:

    # Your snippets
    #
    # Atom snippets allow you to enter a simple prefix in the editor and hit tab to
    # expand the prefix into a larger code block with templated values.
    #
    # You can create a new snippet in this file by typing "snip" and then hitting
    # tab.
    #
    # An example CoffeeScript snippet to expand log to console.log:
    #
    # '.source.coffee':
    #   'Console log':
    #     'prefix': 'log'
    #     'body': 'console.log $1'
    #
    # Each scope (e.g. '.source.coffee' above) can only be declared once.
    #
    # This file uses CoffeeScript Object Notation (CSON).
    # If you are unfamiliar with CSON, you can read more about it in the
    # Atom Flight Manual:
    # http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson
    

    (不过,这是在 MacOS 上)。

    注意它是如何告诉你每个作用域只能声明一次的。我认为如果您修改两个 sn-ps 以包含在同一范围内,它们将按预期工作。

    将您的 snippets.cson 更改为以下似乎对我有用:

    '.source.python':
      'print statement':
        'prefix': 'pr'
        'body' : 'print "${1:Hello world}"'
    
      'Argument variables import':
        'prefix' : 'argv'
        'body' : 'from sys import argv'
    

    一旦我将.source.python 范围设为唯一,我就可以从 sn-ps 导入菜单访问这两个 sn-ps。

    【讨论】:

    • 我之前在 Windows 10 上安装过 atom,我记得读过类似的内容。然而,在 Ubuntu 上,实际上是空白的。\
    • 哪个声明优先?之前还是之后?
    • 我怀疑是之后的,因为它似乎是一种声明性语言。此外,OP 建议他的第二个 sn-p 正在工作,但不是第一个。
    • @NageshEranki 这很有趣。我怀疑这是 Ubuntu 的一个错误,可能应该与 Atom 项目一起提交。不过,我不会怀疑这是依赖于平台的东西。
    • @NageshEranki 如果它对您有用,请随时接受答案。 ;)
    【解决方案2】:

    Ubuntu 20.10 上的 Atom 1.53.0 x64(“groovy gorilla”):

    我必须在核心包“language-html”(0.53.1)的“设置”中禁用“内置”sn-ps。从那里我复制了 sn-p 作为前缀,将其粘贴到我自己的本地 sn-ps.cson 并根据我的需要进行更改。

    我还必须重新启动 Atom 才能让编辑器显示我的自定义 sn-p 以供使用。

    在我的情况下,原始的 sn-ps.cson 也是空白的。没有提示,没有例子。 纯vi-feeling :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      相关资源
      最近更新 更多