Sublime Forum

Bug Report: Syntax highlighting theme not recognized sometimes for she-bangs

#1

I have a custom syntax min.tmTheme at:

~/Library/Application Support/Sublime Text 3/Packages/User/min.tmTheme

With the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Monokai</string>
	<key>settings</key>
	<array>
		<dict>
			<key>settings</key>
			<dict>
				<key>background</key>
				<string>#272822</string>
				<key>caret</key>
				<string>#F8F8F0</string>
				<key>foreground</key>
				<string>#F8F8F2</string>
				<key>invisibles</key>
				<string>#3B3A32</string>
				<key>lineHighlight</key>
				<string>#3E3D32</string>
				<key>selection</key>
				<string>#49483E</string>
				<key>findHighlight</key>
				<string>#FFE792</string>
				<key>findHighlightForeground</key>
				<string>#000000</string>
				<key>selectionBorder</key>
				<string>#222218</string>
				<key>activeGuide</key>
				<string>#9D550FB0</string>

				<key>bracketsForeground</key>
				<string>#F8F8F2A5</string>
				<key>bracketsOptions</key>
				<string>underline</string>

				<key>bracketContentsForeground</key>
				<string>#F8F8F2A5</string>
				<key>bracketContentsOptions</key>
				<string>underline</string>

				<key>tagsOptions</key>
				<string>stippled_underline</string>
			</dict>
		</dict>
	</array>
	<key>uuid</key>
	<string>D8D5E82E-3D5B-46B5-B38E-8C841C21347D</string>
</dict>
</plist>

It is basically just the default but without any colors.
I’ve set it for my Ruby theme:

in Ruby.sublime-settings

// These settings override both User and Default settings for the Ruby syntax
{
    "color_scheme": "Packages/User/min.tmTheme",
    "tab_size": 2,
    "translate_tabs_to_spaces": true,
    "auto_complete": false
}

This works fine when I click on .rb files or when I manually set the syntax to Ruby.
However if I’m clicking on an executable, or a file is previewing via Command+p then the old highlighting is used instead of mine. These two cases are shown below, along with what it looks like when I manually change the syntax back to Ruby.

Is there anything I can do for my custom ruby syntax theme to be applied to #!/usr/bin/env ruby executables all the time?

Clicking from sidebar

Using Command + P

Manually changing to Ruby syntax

0 Likes

#2

In the first two screenshots, which syntax is active? You can check with view.settings().get('syntax') in the console.

0 Likes

#3

I don’t think Sublime natively recognizes shebangs, but I do know ApplySyntax can be configured to do so.

0 Likes

#4

.sublime-syntax files have a first_line_match field that can and does recognize shebangs. File extentions take priority, however. Docs: https://www.sublimetext.com/docs/3/syntax.html

0 Likes

#5

Awesome. I’ve only touched the surface of new syntax stuff. Recent contributions to the default syntax files have been been great, and I haven’t had to dive into syntax stuff in a long while now. So yeah, ideally this should be addressed in the syntax if it is possible. But it is also possible via a plugin as listed above if for whatever reason it is not solvable, or if you need stopgap solution.

0 Likes

#6

This is weird. In all cases the syntax is set to 'Packages/Ruby/Ruby.sublime-syntax'.
Shouldn’t my custom color_scheme be recognized?

First clicking on executable with ruby shebang

Manually changing syntax to Ruby

First clicking on file with .rb extension

0 Likes

#7

Okay, this is unexpected. Could be a bug in core. I’ll try to reproduce later and open an issue if I can.

1 Like

#8

@FichteFoll Thank you for taking a look.

Wanted to add an observation I came across today in case it helps:

Using the File: revert command will enable my user settings:

0 Likes