Inline errors are nice, but since the first error is usually the only one I care about I would like to start editing at the error immediately without the inline errors still visible. Using the mouse to click is fine, but it will be nice to be able to use only the keyboard for the flow of Build -> Goto Error -> (dismiss phantoms) -> edit -> save -> build.
Keyboard binding to dismiss inline build errors
Indeed, by default, it is not possible to press Esc to dismiss [build error] phantoms…
and it seems it is currently not possible to create a keybinding for it either, due to:
- there not being a
command
to dismiss them inexec.py
- there not being a
context
to tell when [build error] phantoms are shown
CC @wbond because it isn’t in the Technical Support topic and you might miss this essential accessibility improvement idea otherwise
ofc, build error phantoms will be removed/updated on the next build run, so it is possible to edit the source code with the build errors showing, and execute a new build without dismissing the phantoms…
but I understand the desire to hide them first in certain circumstances the phantom might disappear when the text it relates to is edited, which could be used as a “workaround” for having no keyboard shortcut to dismiss them for now
An example is when C++ errors + warnings + notes take over the screen - sometime a C++ template error is pages of brackets and barely readable content.
Screenshot of such a case is below, where editing a “line” that spans half a screen is confusing when you navigate with the keyboard.
heh, yeah - definitely useful to dismiss them with a keybinding you could go back to the old behavior in the meantime though of showing the build output panel by putting "show_errors_inline": false
in your user preferences file.
Try:
{
"keys": ["ctrl+l"],
"command": "exec",
"args": {
"hide_phantoms_only": true
}
},
Or for vim modes:
{
"keys": ["ctrl+l"],
"command": "exec",
"args": {
"hide_phantoms_only": true
},
"context": [
{ "key": "setting.command_mode" }
]
},
Ideally there should be a toggle.
I thought a toggle could be hacked together using an "update_phantoms_only": false
but apparently not.
I figured it out from the default package exec.py
source.
How do I hide inline errors/phantoms with a key binding?
I have written a plugin(SublimeBuildErrorHider) to do this better.
SublimeBuildErrorHider uses the Esc key to hide phantoms and it has no conflicts with other commands and plugins.
SublimeBuildErrorHider does this by adding a subclass of ViewEventListener
, with only one member function named on_query_context
to check if a view has a "error_phantom_visible"
entry in it settings or not, to satisfy context checking of ST; and making some changes to the default ExecCommand class of ST’s build system, with changing its member functions update_phantoms
and hide_phantoms
, to add 2 extra jobs:
-
Add a
"error_phantom_visible"
entry to settings of the involved views whenupdate_phantoms
is called. -
Erase the
"error_phantom_visible"
entry from settings of the involved views whenhide_phantoms
is called.
The source code is simple
import sublime
import sublime_plugin
def plugin_loaded():
from Default.exec import ExecCommand
old_hide_phantoms = ExecCommand.hide_phantoms
old_update_phantoms = ExecCommand.update_phantoms
def new_hide_phantoms(self):
for file, errs in self.errs_by_file.items():
view = self.window.find_open_file(file)
if view:
view.settings().erase("error_phantom_visible")
old_hide_phantoms(self)
def new_update_phantoms(self):
old_update_phantoms(self)
for file, errs in self.errs_by_file.items():
view = self.window.find_open_file(file)
if view:
view.settings().set("error_phantom_visible", True)
ExecCommand.hide_phantoms = new_hide_phantoms
ExecCommand.update_phantoms = new_update_phantoms
class HidePhantomListener(sublime_plugin.ViewEventListener):
def on_query_context(self, key, operator, operand, match_all):
return self.view.settings().get('error_phantom_visible', False)
And the key binding is
[
{
"keys": ["escape"],
"command": "exec",
"args": { "hide_phantoms_only": true },
"context":
[
{ "key": "error_phantom_visible", "operator": "equal", "operand": true }
]
}
]