Skip to content

Commit

Permalink
Remove forward-compatibility with ST3
Browse files Browse the repository at this point in the history
This only changes the do_fish_indent plugin, and simplifies it slightly
by removing any ST3-specific code
  • Loading branch information
Phidica committed Aug 30, 2019
1 parent 0cfa306 commit 40afc18
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions do_fish_indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Only a TextCommand can use replace()
class DoFishIndentCommand(sublime_plugin.TextCommand):
def is_enabled(self):
# We are very incompatible with ST1 and probably ST4 one day
return 2 <= int(sublime.version()[0]) <= 3
# We are very incompatible with ST1, and kind of with ST3
return int(sublime.version()[0]) == 2

def is_visible(self):
# Syntax will be like "Packages/fish/fish.tmLanguage"
Expand All @@ -16,8 +16,6 @@ def description(self):
return 'Indent and Prettify'

def run(self, edit):
versionAPI = int(sublime.version()[0])

# Check for executable, expanding search to valid fish installs on Windows
exe = 'fish_indent'
pathToDir = self.view.settings().get('fish_indent_directory')
Expand Down Expand Up @@ -79,7 +77,7 @@ def run(self, edit):
p = subprocess.Popen(exe, stdin = subprocess.PIPE, stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
out, err = p.communicate(input = inputContent.encode(enc))
except OSError: # Soft compatibility with Python 2
except OSError:
msg = "Couldn't find {0}".format(exe)
if not pathToDir:
msg += ". Specify a nonstandard install location in Preferences > " \
Expand Down Expand Up @@ -139,10 +137,7 @@ def run(self, edit):
if restoreSelection:
# Put back the original zero-width regions of the selection
self.view.sel().clear()
if versionAPI == 3:
self.view.sel().add_all(restoreSelection)
elif versionAPI == 2:
map(self.view.sel().add, restoreSelection)
map(self.view.sel().add, restoreSelection)

# Ensure view doesn't drift off with repeated runs
self.view.show(self.view.visible_region(), False)
Expand All @@ -152,23 +147,10 @@ class DoFishIndentBuildCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('do_fish_indent')

if sublime.version()[0] == '3':
class DoFishIndentOnSave(sublime_plugin.ViewEventListener):
def is_applicable(self):
# In non-fish files the setting is unset (hence, we ask for False), or if
# the user set it to False then it will be False even in fish files
return self.get('indent_on_save', False)

def on_pre_save(self):
# Skip blacklisted files
if self.view.window().extract_variables()['file_name'] in self.view.settings().get('blacklist'):
return
self.view.run_command('do_fish_indent')
elif sublime.version()[0] == '2':
class DoFishIndentOnSave(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get('indent_on_save') is not True:
return
if view.settings().has('blacklist') and os.path.basename(view.file_name()) in view.settings().get('blacklist'):
return
view.run_command('do_fish_indent')
class DoFishIndentOnSave(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get('indent_on_save') is not True:
return
if view.settings().has('blacklist') and os.path.basename(view.file_name()) in view.settings().get('blacklist'):
return
view.run_command('do_fish_indent')

0 comments on commit 40afc18

Please sign in to comment.