Sublime Forum

Color scheme will not activate automatically for markdown files (ikiwiki plugin)

#1

I am working a lot with ikiwiki, which is a wiki compiler. Since I use the tagging feature a lot, I thought it would be a good idea, to have autocompletion for the tag directive via a completion file. The way sublime text 3 decides where to autocomplete stuff is via a scope selector, which means, that the specific scope has to be defined in a syntax file. I really like the features of the MarkdownEditing package though and so rely heavily on it. Thankfully there seemed to be a good starting point: the AcademicMarkdown package, which seems to be nothing more that a slightly adapted subset - theme, syntax, and so on - of what MarkdownEditing provides.

What I did was to fork the AcademicMarkdown package on github and create my own ikiwikiEditing package as a starting point of a package that includes e.g. scopes, etc. for ikiwikis own directives.

First I renamed all the files from AcademicMarkdown to ikiwikiEditing and made sure that anything in the files themselves was derivate from this new naming scheme.

With help of the PackageDev package, I converted the ikiwikiMarkdown.tmLanguage file to YAML and added under patterns my pattern for the tag directive:

- comment: tags directive
  name: tag.directives.ikiwiki
  match: \[\[!tag.*?\]\]

Afterwards I converted the file back to json.

I made sure that AcademicMarkdown was removed from my ST3 config, since ikiwikiMarkdown had the same feature set (and more) and restarted ST to see if it would work.

Alas, it only kinda did. I could see that ST could identify the newly added scope correctly, so in theory I could start building up a completion file, but hereā€™s the problem: If ikikiwikiEditing is used the color scheme of MarkdownEditing, or rather the enhanced one from AcademicMarkdown is simply ignored for all my markdown files! I checked the preferences for the plugin (which lives simply in packages/ikiwikiEditing/ btw.), the path for the ā€œcolor_schemeā€ setting and everything else for hours yesterday but could not figure out the problem. I removed ikiwikiEditing from my path and reinstalled AcademicMarkdown and it worked like a charm. I am at a loss. I donā€™t know why it wouldnā€™t work or what I could check anymore, so I turn to you. Any help is appreciated and thanks in advance!

0 Likes

Including .tmLanguage file in .sublime-syntax file
#2

As it turned out, the problem was with my syntax file. By redoing everything, but this time not converting the .tmLanguage but editing it directly I finally got it to work.

0 Likes

#3

Sublime doesnā€™t use tmlanguage-yaml files. You have to convert them back to tmLanguage in order to use them.

Also since build 3103 Sublime officially uses.sublime-syntax for syntax file, I recommend that you use the new format which is more powerful and more human-friendly

0 Likes

#4

Thanks. Since for now Iā€™m simply adding to the syntax file of MarkdownEditing, I will wait for them to switch. Since you canā€™t have two syntax files interpreting the currently open file, if I understood that correctly, I am not able to develop my own additional syntax so to speak for only the ikiwiki parts of my files.

0 Likes

#5

Check out the with_prototype section in the new syntax docs: http://www.sublimetext.com/docs/3/syntax.html

0 Likes

#6

Right now it seems to be still impossible to simply include the MarkdownEditing-Syntax, since:

Note that while Sublime Text supports both .sublime-syntax and .tmLanguage files, itā€™s not possible to include a .tmLanguage file within a .sublime-syntax one.

So for now I have to wait. But thanks for the suggestion @FichteFoll!

0 Likes

#7

Or you can convert the syntax yourself. You just have to open a file with the syntax you want to convert and use ā€˜new syntax fromā€™ in the Tool menu

0 Likes

#8

That statement is outdated, actually. You can include .tmLanguage files by their base scop now using the include: scope:<source.ext> include, where <source.ext> stands for the actual scope name obviously.

0 Likes

#9

Where and how would I need to do this? This is the minimal syntax file I would need (for now):

%YAML1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: text.html.markdown.ikiwikimarkdown
contexts:
  main:
    - match: \[\[!tag.*?\]\]
      scope: tag.directive.ikiwiki
      comment: ikiwiki tag directive

The <source.ext> should in my case be text.html.markdown.gfm, correct? Thatā€™s the one in the specific .tmLanguage-File I would like to includeā€¦

Thanks for your help so far!

0 Likes

#10

Something like this:

%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: IkiWikiMarkdown
scope: text.html.markdown.ikiwikimarkdown

contexts:
  main:
    - match: ''
      push: scope:text.html.markdown.gfm
      with_prototype:
        - match: \[\[!tag.*?\]\]
          scope: tag.directive.ikiwiki

0 Likes

Including .tmLanguage file in .sublime-syntax file
#11

Thanks @FichteFoll, but it doesnā€™t seem to work. I simply get a ā€œno such targetā€ error. This holds true with the most simple scope text as with the more complicated one text.html.markdown.gfm.

Might this be a problem that is related to the .tmLanguage file being part of another plugin (MarkdownEditing)?

0 Likes

#12

Sorry, forgot the scope: prefix in front of the markdown GFM scope. I just verified that it works that way.

1 Like

#13

Thanks! It works now.

EDIT:

This is the fully working .sublime-syntax file with included .tmLanguage file via the scope:

%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: IkiWikiMarkdown
scope: text.html.markdown.ikiwikimarkdown

contexts:
  main:
    - match: ''
      push: scope:text.html.markdown.gfm
      with_prototype:
        - match: \[\[!tag.*?\]\]
          scope: tag.directive.ikiwiki

Note, that thereā€™s no space between scope: and text.html.markdown.gfm.

0 Likes