Sublime Forum

Custom file type hander

#1

Hello and thanks for your great work!

Would it be possible to create a plugin for unsupported file type (lets say exe, mkv whatnot) which instead of trying to open binary blob would generate custom markdown file from its metadata and display that?

I took a quick look at api reference (+some rough google searches) and wasnt able to find methods that would enable that, but that was really quick look :D. Most interested in part where default hex view would be replaced with some custom content. Thanks!

0 Likes

#2

Achievable with TERRIBLE performance and UX.

  • Open a .mkv file, which may takes a really LONG time
  • Plugin with on_loaded hook to get the file path of that .mkv file (there is no pre_load hook in ST)
  • Plugin closes that .mkv file
  • Plugin do what you want to do with the .mkv file path. You may fake a text buffer or something.
0 Likes

#3

If you want to create a generic plugin, then there is probably no good way for custom file type handlers. But for personal use you could do something like the following:

If you have opened a folder in the side bar in Sublime Text, which contains the file, then it should be possible to get the filepath without loading the file if you set the “preview_on_click” setting to false or "only_left" and then add a custom context menu item via Side Bar.sublime-menu. Then in the corresponding command use the files keyword argument, for example like

def run(self, **kwargs):
    files = kwargs.get('files')
    if files:
        path = files[0]

But maybe an easier alternative would be if you have ffmpeg installed, to use a small command line or script file that you would call directly from the file explorer / shell (or add to your file explorer’s context menu) and then just pipe the result to subl.

ffprobe -hide_banner "file.mkv" 2>&1 | subl -
0 Likes