I need to set the view settings when a new view is created:
I also found problems with @ThomSmith answer, as variables used but not declared.
This is a variation of @ThomSmith answer, where it supports settings inheritance from the current window, in case you create a new window with Ctrl+Shift+N:
Then, create these keybinds:
{ "keys": ["ctrl++"], "command": "increment_setting", "args": {"setting": "font_size", "increment": 1} },
{ "keys": ["ctrl+-"], "command": "increment_setting", "args": {"setting": "font_size", "increment": -1} },
I built th…
class ToggleSettingsCommandListener(sublime_plugin.EventListener):
def on_load(self, view):
global capture_new_window_from
window = sublime.active_window()
...
But, it does not work when I create a new view with Ctrl+N
, i.e., the on_load
event is not fired.
Then, I added the on_new
event to trigger on_load
:
class ToggleSettingsCommandListener(sublime_plugin.EventListener):
def on_new(self, view):
self.on_load(view)
def on_load(self, view):
global capture_new_window_from
...
Now, it seems to be working when I create new views with Ctrl+N
.
Why do I need both on_load
and on_new
?
Every time I open some file, I am not creating a “new” buffer?
Can I only use on_new
instead of on_load
? All I do is set the view settings.
Related threads:
Hi ST forum! I'm new here, so I apologize if this is the wrong section or something.
Previously, if you wanted to edit the same file in two different views simultaneously side-by-side, you would need to:
Go to File -> New View Into File
Split the view, i.e. alt+shift+2
Drag the copied file into the new view
(To undo it) Close the file (getting a save prompt for some reason), and reset the view layout to 1
So I wrote this plugin to do all that for me. I have the command mapped to f1:
*.s…
Is it possible to distinguish it from an "honest" on_load that happens when a file is opened for real?
In my plugin I want to typecheck loaded files, so that the user instantly gets error highlighting and other good stuff. It's usually 1-2s of background work, so it's not a problem at all.
Except when I use goto anything. Then simply typing a name of the file I want might produce a bunch of file previews, each of them potentially triggering a typecheck. Now that might be a problem.
I'd like to make my plugin more user-friendly: if the file is in preview mode, skip the rest actions.
Using "Goto Anything" menu entry and navigating files with up and down keys will fire on_load event.
Single-click on files in Side Bar will fire on_load and on_activated events (exactly same as double-click).
I searched the forum and wrote something like this:
def is_preview(self, view):
window = view.window()
if not window:
return True
return view.file_name() not in [v.file_name(…
It would be nice if there was access in the API to determine if a given view is transient (preview). I have tried every way I can think of, but I cannot seem to pin down when a view is actually opened or if it is a preview.
I have a plugin in which I need to perform some action when the file is actually opened. on_load is triggered when the preview is shown and never again, so I cannot use that or it will trigger during "goto anything". The attributes of the view in every way seen to look…