Sublime Forum

Index global constants for Python

#1

Hi!

I quite like the built-in Indexing feature. As I understand by default constants are not indexed. I was wondering how would one configure sublime to also include constants in index. So that I can jump to definition and usage (reference).

Thanks!

0 Likes

#2

In order for constants to be indexed they would need a special scope set by the syntax definition. As this is not the case by default you would have to modify the syntax definition in order to index constants. I’m also not sure whether it’s possible to do this properly due to the significant indentation in Python. You’d likely have to use a standard like ALL_CAPS for global constants in order to detect them properly.

0 Likes

#3

What about variable.other.constant.python? That seems like a suitable candidate for this use case.

0 Likes

#4

So far I’ve come up with following solution:

Contents of Packages/User/Python.tmPreferences

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Symbol Index: Python Constants</string>
	<key>scope</key>
	<string>source.python variable.other.constant.python</string>
	<key>settings</key>
	<dict>
		<key>showInIndexedSymbolList</key>
		<integer>1</integer>
	</dict>
</dict>
</plist>

This gets me some way, but there is no distinction between constance definition and reference (where it is defined).

Also on a side note: this functionality is documented in such a cryptic way :disappointed:

0 Likes

#5

There are still some unanswered questions regarding the proper scope names (that no ST dev has commented on yet, *nudge*), but this is definitely on my list of things to do as I would like to see it myself.

0 Likes