Sublime Forum

Force open_file to always open the given file again

#1

I’m looking for a way to load a file with open_file, even if it’s already open somewhere else. Is this possible? I know there is clone_file for creating a new View with an existing file, but that only works for the file that currently has focus.

Is this possible?

0 Likes

#2

So you want two views of the same file?
Or, you just want to make it reloaded?

0 Likes

#3

I want to have 2 views with the same file. Background is, I’d like to preview a already open file in the current group even if it is open in a different group / tab. Currently open_file will give focus to that view/group if it’s already open

0 Likes

#4

I only know that window.run_command('clone_file') can create a cloned view for the current active view (and, it’s not a preview…). But clone_file seems to be a low-level command (not written in python) so I cannot find the source code of that command and do not know whether there are extra args or not.

0 Likes

#5

There is an undocumented sublime.FORCE_GROUP flag you can pass to the Window.open_file method. It’s used in the Default/symbol.py plugin.

You can also specify the group to open in with the undocumented group parameter. Example from said file:

        window.open_file(
            fname + ":" + str(row) + ":" + str(col),
            group=window.active_group(),
            flags=sublime.TRANSIENT | sublime.ENCODED_POSITION | sublime.FORCE_GROUP)
3 Likes

#6

Exactly what I was looking for. Thanks for the tip!

0 Likes