Skip to content

Commit

Permalink
Added additional settings for 'surplus on save', and 'operate on whol…
Browse files Browse the repository at this point in the history
…e file or not'
  • Loading branch information
NicholasBuse committed Apr 5, 2018
1 parent 0b67da7 commit d9cc256
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 15 additions & 3 deletions DeleteBlankLines.py
Expand Up @@ -16,14 +16,19 @@ class DeleteBlankLinesCommand( sublime_plugin.TextCommand ):
def run( self, edit, surplus=False):
newSelections = []

settings = sublime.load_settings('DeleteBlankLines.sublime-settings')

# Create an() edit object, demarcating an undo group.
if (st_version == 2):
edit = self.view.begin_edit()

# If there is no (empty) selection, operate on the whole file.
# else, operate only on each selection (update the selection for changes)
if len(self.view.sel()) == 1 and self.view.substr(self.view.sel()[0]) == "":
self.strip( edit, sublime.Region(0, self.view.size()), surplus )
if (settings and
settings.has('operate_on_whole_file_when_selection_empty') and
settings.get("operate_on_whole_file_when_selection_empty") is True):
self.strip( edit, sublime.Region(0, self.view.size()), surplus )
else:
# Loop through user selections.
for currentSelection in self.view.sel():
Expand Down Expand Up @@ -72,5 +77,12 @@ def strip( self, edit, currentSelection, surplus ):
class DeleteBlankLines(sublime_plugin.EventListener):
def on_pre_save(self, view):
settings = sublime.load_settings('DeleteBlankLines.sublime-settings')
if settings and settings.has('delete_blank_lines_on_save') and settings.get("delete_blank_lines_on_save") is True:
view.run_command("delete_blank_lines")
if settings:
if (settings.has('delete_surplus_blank_lines_on_save') and
settings.get("delete_surplus_blank_lines_on_save") is True):
view.run_command("delete_blank_lines", { "surplus": True })

elif (settings.has('delete_blank_lines_on_save') and
settings.get("delete_blank_lines_on_save") is True):
view.run_command("delete_blank_lines")

11 changes: 9 additions & 2 deletions DeleteBlankLines.sublime-settings
@@ -1,3 +1,10 @@
{
"delete_blank_lines_on_save": false
}
// Settings to control "Delete Blank Lines on_pre_save()"
// If 'delete_surplus_blank_lines_on_save' is set, it takes presidence over
// 'delete_blank_lines_on_save'
"delete_blank_lines_on_save": false,
"delete_surplus_blank_lines_on_save": false,

// If there is no text selection, operate on the whole file.
"operate_on_whole_file_when_selection_empty": true
}

0 comments on commit d9cc256

Please sign in to comment.