Sublime Forum

How to set focus to "exec.output" panel?

#1

Hello
I tried to set focus to “exec.output” with a plugin like this:

import sublime
import sublime_plugin

class ExecOutputFocusCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    window = self.sublime.active_window()
    window.focus_view(window.find_output_panel("exec"))

But this does not have any effect - focus does not go to “exec.output” panel.
How can I do that? Thanks

1 Like

#2

I think this is what you want:

import sublime
import sublime_plugin

class ExecOutputFocusCommand(sublime_plugin.WindowCommand):
  def run(self):
    self.window.run_command('show_panel', args={'panel': 'output.exec'})

In fact, you can just make a key-binding for this. Go to Preferences -> Key Bindings and add the following in the right file (your user keybindings):

[
    {
        "keys": ["super+shift+v"], 
        "command": "show_panel", 
        "args": 
        {
            "panel": "output.exec"
        }
    }
]

“super” is macOS-specific, you can of course use any sort of key combination.

I found this by opening the Python console (with “ctrl” + “~”) and typing

sublime.log_commands(True)

This will print all the sublime commands to the console as you execute them. When I click on Tools -> Build Results -> Show Build Results, the show_panel command popped up in the console.

1 Like

#3

"show_panel" only opens the "output.exec" panel, but does not set focus on it.
It often happens that the text does not fit on the panel and I want to scroll it.
I click on the panel with the mouse for this and then scroll with the keyboard, but I would like to switch to the panel using keyboard shortcuts.
How can I do it using the keyboard?

0 Likes

#4

You wrote self.sublime.active_window() instead of sublime.active_window(). However I would use a WindowCommand and use self.window instead.

1 Like

#5

Many thanks!
This works great:

import sublime
import sublime_plugin

class ExecOutputFocusCommand(sublime_plugin.WindowCommand):
  def run(self):
    self.window.run_command('show_panel', args={'panel': 'output.exec'})
    self.window.focus_view(self.window.find_output_panel("exec"))
4 Likes