Sublime Forum

User Defined Variables in "command"

#1

Apologies, it’s not a great question title, and I may struggle with defining the question…
The behaviour I’d like: to save the contents of a couple of tabs ( or maybe all the tabs open in a pane depending on what’s available) and then build one of them, preferably the tab that is currently active, and return to that active tab.
The command I have at the moment always saves tab 0 and tab 1 and then returns to tab 0, but I’d like to return to the tab that was active when I did the build (maybe in a different pane, or perhaps there are four tabs open in the first pane for example). What this seems to need is some way of saving my starting state (in terms of panes and active tab), do what I want to do (save build etc), and then go back to my original state ie back to the tab that was active .(obvs post saving and building)

Currently, the keybinding changes focus, saves, builds, but then I’ve got no way of going back to my original focus, and have to change back manually (if it isn’t the right focus by chance…

Here's my key binding
   {
    "keys": [
      "alt+b"
    ],
    "command": "multicommand",
    "args": {
      "commands": [
        {
          "command": "save"
        },
        {
        	"command" : "focus_group", "args": { "group": 0 }
        },
      	{
          "command": "select_by_index", "args": { "index": 0 }
        },
        {
          "command": "save"
        },
        {
          "command": "select_by_index", "args": { "index": 1 }
        },
        {
          "command": "save"
        },
        {
          "command": "build"
        },
        {
          "command": "select_by_index", "args": { "index": 0 }
        }
      ]
    }
  },

Here’s my Pseudo key binding
{
“keys”: [
“alt+b”
],
“command”: “multicommand”,
“args”: {
“commands”: [
{
"command": “store current focus group value” args "User_Val"
},
{
“command” : “focus_group”, “args”: { “group”: 0 }
},
{
“command”: “select_by_index”, “args”: { “index”: 0 }
},
{
“command”: “save”
},
{
“command”: “select_by_index”, “args”: { “index”: 1 }
},
{
“command”: “save”
},
{
“command”: “build”
},
{
"command": “select_by_index”, “args”: { “index”: User_Val}
}
]
}
* }*,

Is this as clear as mud ? If so more than happy to clarify (if I can) !

Regards Lozminda

Ps Sorry all the formatting’s gone a bit weird, don’t seem to be able to do bold and italic together, am always having these troubles on this forum, I’ll see if I can find my old post and try and sort…

0 Likes

#2

If you turn on Save all on build in the Tools menu, any time you trigger a build every file that already has a name on disk will be saved before the build happens. So if it’s alright with you that all of your unsaved files be persisted, you can do that without requiring any sort of key binding at all other than the default.

If you want to do something more specific than that, you’d need a plugin that’s capable of saving and restoring whatever the current state is, or at least new commands you can execute as a part of your key binding here that would save the state and then restore it later. I’m not aware of any built-in way to save that kind of state otherwise.

0 Likes

#3

If I’ve understood, when “Save All” is used, just the open tabs are saved? Is that all the open tabs in all the open panes (in all the open projects? ) ? I’m assuming it’s not all the files in the side bar?

0 Likes

#4

If you mean File > Save All, it only saves the content of open tabs that have unsaved changes. Specifically, if you have opened a file and modified it, it will be saved. If you opened a file and did nothing, it’s not saved, and if you create a new tab and type something into it, Save All will save that tab as well, prompting you for the name to use since it doesn’t have one.

Tools > Save All on Build, when checked, only does the first of these. If you have opened a file that already exists on disk and modified it, then executing a build will cause that file to be saved before the build command executes, even if it’s not the active file.

Both of these only deal with files in the current window, and neither one will try to save changes to any file you don’t have open or which has not changed.

0 Likes

#5

Thank you for that clarification, wicked !!

0 Likes