Sublime Forum

Why doesn't .tmPreferences doesn't work like in TextMate?

#1

I’m looking to change editors from TextMate (Mac) and one of the problems, I’ve found is that .tmPreferences and symbols don’t work like in TextMate.

In TextMate the code below would result in “• TFoo” being added to the symbol list (Goto Symbol in Sublime) but in Sublime Text it’s capturing “• TFoo” (correctly) and also “• end;” for some reason. Another strange thing is even if I set “showInSymbolList” to 0, “Foo” is also added to the list (from procedure Foo;) and I have no idea where it’s getting that from.

Does anyone know why this may not be working in Sublime Text? The manual says it’s compatible so I don’t have any other ideas since this works in Text Mate. Thanks.

The example syntax:

type
	TFoo = class (TObject)
		procedure Foo;
	end;

The .tmPreferences file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Symbol List: Class</string>
	<key>scope</key>
	<string>meta.class.definition.pascal</string>
	<key>settings</key>
	<dict>
		<key>showInSymbolList</key>
		<integer>1</integer>
		<key>symbolTransformation</key>
		<string>
		s/=\s*(class|object|objcclass|objccategory|objcprotocol|interface)\s*(external)*\s*(?i:(name)*\s*)*('\w+')*\s*(\((.*)\))*//;			# class names
		s/^\s*//;				# spaces from start of word
		s/(\w+)/  • $1/;		# class names
		</string>
	</dict>
	<key>uuid</key>
	<string>BBE77F44-D14D-4DE3-A0E0-40E994E8D572</string>
</dict>
</plist>
0 Likes

#2

I guess the scope is spanned to large. You’d need to scope the second line TFoo = class (TObject) wis a normal scope and extract TFoo from it, I guess? Why capturing the whole class declaration body and strip it?

Not sure which syntax file you use, but I would add a pattern to match TFoo as storage.type.class in the syntax and use it as selector for the tmPreferences. Would be much faster and more straight forward. You need to scope TFoo anyway to highlight it as keyword.

This happens if the Foo after procedure keyword is scoped as entity.name.function ST adds everything scoped as such to the symbol list by default. You need another Symbol List to disable it for your language.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Symbol List - Hide ordinary functions</string>
	<key>scope</key>
	<string>source.pascal entity.name.function</string>
	<key>settings</key>
	<dict>
		<key>showInSymbolList</key>
		<integer>0</integer>
		<key>showInIndexedSymbolList</key>
		<integer>0</integer>
	</dict>
</dict>
</plist>

Just replace the source.pascal by your language.

0 Likes

#3

Yeah you’re right about me designing the syntax stupidly so that I need to re-parse the symbol names again but the .tmPreference file should have only captured the first part based on the regex. The scope “meta.class.definition.pascal” does span until the “end;” but isn’t that what the symbolTransformation option is for? I can re-do the .tmLanguage file if I need to but I’d like to avoid that if possible.

Thanks for the tip about the entity.name.function’s.

0 Likes