The code for this comes from the Default
package and is in the trim_trailing_white_space.py
plugin file, where the command is triggered by an event listener that listens for files about to be saved:
class EnsureNewlineAtEofCommand(sublime_plugin.TextCommand):
def run(self, edit):
if self.view.size() > 0 and self.view.substr(self.view.size() - 1) != '\n':
self.view.insert(edit, self.view.size(), "\n")
class EnsureNewlineAtEof(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get("ensure_newline_at_eof_on_save") is True:
if view.size() > 0 and view.substr(view.size() - 1) != '\n':
view.run_command("ensure_newline_at_eof")
It’s definitely checking that the setting is set to True
prior to trying to run the command.
As a test, you can open up the Sublime console with View > Show console
, then enter view.settings().get("ensure_newline_at_eof_on_save")
in the input area and see what it says.
In a clean Sublime, I get this result:
>>> view.settings().get("ensure_newline_at_eof_on_save")
False
If you see False
, the first thing I would suspect is that another plugin somewhere (either in your User
package or in a third party package) has an event listener similar to the default one, but it’s always invoking the command instead of respecting the setting. If that’s the case you would have to temporarily revert to a freshly installed state (check if the problem still exists) and then slowly re-enable your third party packages to see if one of them causes it to start happening.
If you see True
, then something somewhere is forcing the setting to be True
even though your preferences are setting it to False
. My first guess would be a typo, but since was happening before you tried to disable it that seems unlikely.
Syntax specific settings and project specific settings can alter settings from the defaults. You should check the syntax specific settings for one of the affected file types to see, but since there are so many of them affected that seems like an unlikely candidate.
If you’re using a project, I would check the project settings to see if something perhaps put the setting in there.