Sublime Forum

[SOLVED] find_resources does not use os.sep, how does this affect different OS's?

#1

I’m working on an autocomplete plugin, and am in the process of implementing file-specific completions.

A small issue I noticed is that sublime.find_resources returns a path that does not use os.sep
( side note: is there any reason for this? )

I know I could easily replace all instances of / with os.sep, but am wondering if sublime.find_resources returns the same output on non-windows operating systems.

 

If it does, I can simply implement the previously mentioned method.

If it doesn’t, I would just need to know what separator characters to use for each OS so I can replace them appropriately.

 



matchTest:

matchFile   = sublime.find_resources( "TEST.custom-completions" )[0]
currentFile = view.file_name()

print ( "matchFile   = " + matchFile )
print ( "currentFile = " + currentFile )

if currentFile.endswith ( matchFile ):
	print ( "match = TRUE" )
else:
	print ( "match = FALSE" )

print ( "os.sep = " + os.sep )

Results:

matchFile   = Packages/CustomCompletions/Completion Files/TEST.custom-completions
currentFile = C:\Users\Fico\AppData\Roaming\Sublime Text 3\Packages\CustomCompletions\Completion Files\TEST.custom-completions
match       = FALSE
os.sep      = \
1 Like

#2

sublime.find_resources always returns a relative path to the data dir with forward slashes. The same kind of path is used for sublime.load_resource and other situations like view.set_syntax_file or the color scheme setting or as a parameter to the insert_snippet command. Interestingly, run_macro_file is always used with a res:// protocol prefix in the default bindings.

2 Likes

#3

 
Is that like a reference to sublime.find_resources?

EG: would it allow you to do something like:
res://MacroName.sublime-macro
without the need for a particular directory?

1 Like

#4

It’s a reference to the internal “resource loader”, which is capable of loading from the normal packages folder, the shipped packages folder and the installed packages folder while also considering override packages (where a .sublime-package file and a corresponding directory in Packages exist). I imagine the path is always relative to the data folder.

2 Likes