Sublime Forum

Switch back and forth between layouts

#1

When coding on my laptop, I tend to switch between two columns with small fonts, and single layout with bigger fonts. Two columns are often needed when working on two files at the same time but the fonts are quite small on a small screen. So whenever I can, I focus on one file. I increase the font size and shift the center on the layout so I can see the 80 columns of the file I work on. I’m wondering if it’s possible to automate this behavior.

One option could be to define a command that switches layout and change font size, but when switching back from single to two columns, I lose the previous tabs distribution. Any idea?

0 Likes

#2

You can relativly easy create commands to save and restore the groups: You may integrate that into your other commands.

import sublime
import sublime_plugin


class SaveGroupsCommand(sublime_plugin.WindowCommand):
    def run(self):
        window = self.window
        groups = [
            (
                [v.id() for v in window.views_in_group(g)],
                window.active_view_in_group(g).id()
            )
            for g in range(window.num_groups())
        ], window.active_group()
        window.settings().set("user.saved_groups", groups)


class RestoreGroupsCommand(sublime_plugin.WindowCommand):
    def run(self):
        window = self.window
        groups, active_group = window.settings().get("user.saved_groups", ([], 0))
        if window.num_groups() != len(groups):
            sublime.error_message(
                "Invalid number of groups {} instead of {}",
                window.num_groups(), len(groups))
            return
        for g, ginfo in enumerate(groups):
            vids, activeid = ginfo
            for vid in reversed(vids):
                v = sublime.View(vid)
                if not v.is_valid():
                    continue
                window.set_view_index(v, g, 0)
            v = sublime.View(activeid)
            if v.is_valid():
                window.focus_view(v)
5 Likes

#3

Thanks very much, it was what I needed. I’ll try to use this.

0 Likes