Am trying to disable save command though a plugin. Tried below but did not work.
class PHPLinter(sublime_plugin.EventListener):
def on_post_save(self, view):
return False
Am trying to disable save command though a plugin. Tried below but did not work.
class PHPLinter(sublime_plugin.EventListener):
def on_post_save(self, view):
return False
“post save” means “after save”, so you can’t disable something that has already happened.
You probably want on_pre_save
instead. Doesn’t seem like it accepts a boolean return value to prevent saving though…
As far as I am aware, on_(post|pre)_save
hooks are fired after/before the save no matter what you do. I don’t think you can disable those.
What can be done though is using a ViewEventListener
to restrict only those views where you want to disable save
and then intercepting the save
command and executing noop
in on_text_command
hook.
Something like
import sublime
import sublime_plugin
class DisableSaveListener(sublime_plugin.ViewEventListener):
@classmethod
def is_applicable(cls, settings):
syntax = settings.get("syntax")
return syntax == "Packages/Text/Plain text.tmLanguage"
def on_text_command(self, command_name, args):
if command_name == "save":
return ("noop", {})
return None
Ideally, this should disable save
on plain text files (see is_applicable
), but unfortunately, I can’t get this to work on Windows on the latest dev build.
Called when a text command is issued. The listener may return a
(command, arguments)
tuple to rewrite the command, orNone
to run the command unmodified.
So may return ('noop', {})
.
Instead of def is_applicable(cls, settings):
shuold be def is_applicable(self, settings):
but still not working on windows 10 ST4.
Command name save
is not detected. All other commands are detected:
drag_select
left_delete
Also needed to comment out is_applicable
and @classmethod
. i already have a file with .python-version 3.8 and tried changed version to 3.3 but still not working
Ah, thanks ! That explains why. However, even with returning ("noop", {})
, it still doesn’t function. Not sure why.
is_applicable
is a class method, so it would receive the class as it’s first argument and not an instance of the class i.e. self
Yes, because I made a silly mistake on line 14. It was returning None
, which basically means to run the save
command as is. So the plugin was useless. As pointed out, it should return ("noop", {})
to basically nullify save
(noop
is a non existent command)
Yes. As I said, no idea why it isn’t working. It could either be a bug that save
is not being caught in on_text_command
or I have done some mistake in the plugin that I am not able to catch so far.
Neither on_text_command
nor on_window_command
respond to save
, so I am not sure