Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XML] add [sublime-snippet] syntax definition #576

Closed
wants to merge 6 commits into from

Conversation

keith-hall
Copy link
Collaborator

...which will highlight as plain XML initially, until the content is reached, whereby it will also highlight (nested) placeholders and their optional regular expression replacements

...which will highlight as XML initially, until the content is reached, whereby it will also highlight (nested) placeholders and their optional regular expression replacements
@keith-hall
Copy link
Collaborator Author

Note that the syntax test file deliberately doesn't have a sublime-snippet extension - so that ST doesn't try to read it as an actual snippet! (it would fail due to being invalid XML as it contains the syntax test header line...)

@jrappen
Copy link
Contributor

jrappen commented Aug 13, 2016

Maybe it would make sense to suggest a fixed syntax test file extension to Jon and Will?

- include: regex_replacement
- include: scope:source.regexp#base-literal

regex_replacement: # http://www.boost.org/doc/libs/1_56_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keith-hall
Copy link
Collaborator Author

Maybe it would make sense to suggest a fixed syntax test file extension to Jon and Will?

I get by with the following tiny plugin, which, when a syntax_test file is opened, will set the syntax to the one specified in the syntax test header line - maybe it could be added to the Default package that ships with ST3:

import sublime, sublime_plugin

class HighlightSyntaxTestsListener(sublime_plugin.EventListener):
    def on_load_async(self, view):
        if view.file_name().startswith('syntax_test_'):
            first_line = view.substr(view.line(0))
            comment, file = first_line.split(' SYNTAX TEST ', 1)
            file = file.split('"')[1]
            view.set_syntax_file(file)

scope: text.xml.sublime-snippet
contexts:
main:
- match: '(<)(content)(>)(<!\[CDATA\[)'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <![CDATA[ part may be provided on the next line (or even be skipped entirely) afaik.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FichteFoll thanks for the heads up - I've done some testing and you are correct. Also, if more than one CDATA section is used, ST ignores any but the first, so I've marked any others as illegal.

@FichteFoll
Copy link
Collaborator

FichteFoll commented Aug 15, 2016

By the way, I'd like to use this for the next PackageDev update, unless Jon decides he wants special highlighting for ST's internal configuration to ship by default – if I may.

Related: #95

@wbond
Copy link
Member

wbond commented Nov 28, 2016

I think this probably makes sense to add. I will check it out further and try it on my machine. From a quick glance at the code, I am wondering if a suffix of .snippet would make more sense than .sublime-snippet-content. The later seems very long/wordy.

@FichteFoll
Copy link
Collaborator

FichteFoll commented Nov 28, 2016

If it makes sense to add this, does that mean that syntax definitions for other resource files should be added as well (thinking about sublime-syntax, sublime-keymap, sublime-commands, sublime-mousemap, sublime-menu, sublime-project) ...? See also #95 (comment).

file_extensions:
- sublime-snippet
name: Sublime Text Snippet (XML)
scope: text.xml.sublime-snippet
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the new_snippet command in Packages/Default/new_templates.py currently references the normal XML syntax, and this should be changed in the ST3 codebase after merging.

v.assign_syntax('Packages/XML/XML.sublime-syntax')

@keith-hall
Copy link
Collaborator Author

@wbond there are currently 2 syntax definitions included in this PR, one for the snippet XML and one for the <content> tag inside the XML. It is useful to split them because maybe one day, a syntax definition for keybindings could reference the snippet content syntax for the insert_snippet command. Currently, the scopes are sublime-snippet and sublime-snippet-content. We could shorten them, but I would like us to make sure that it is clear which scope refers to what. Maybe snippet and snippet-content would achieve both goals?

@FichteFoll
Copy link
Collaborator

In packagedev we use raw-snippet iirc.

@keith-hall
Copy link
Collaborator Author

Did you ever try this out @wbond ? :) The main reason why I'd like this definition added is because a lot of people put an unescaped $ in their snippets and wonder why it doesn't work the way they expect.

@wbond
Copy link
Member

wbond commented Feb 22, 2017

I haven't yet - been primarily working on non-package stuff recently.

@wbond
Copy link
Member

wbond commented Jul 22, 2020

Based on the decision in #95, I think I am going to decide to not include this for now. My understanding is that https://packagecontrol.io/packages/PackageDev is the goto package to include augmented syntaxes and helpers. I think that makes sense for the time being.

We may revisit this in the future and decide that including syntaxes and helpers for the built in formats makes sense. For now, users can use the default XML syntax, or install something like Package Dev.

@wbond wbond closed this Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants