Skip to content

Commit

Permalink
Override "translate_tabs_to_spaces"
Browse files Browse the repository at this point in the history
- tabs cannot be inserted if "translate_tabs_to_spaces" is set, so this must be overridden.
  • Loading branch information
facelessuser committed Mar 26, 2015
1 parent 9e093a3 commit c06390a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions rr_replacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def __init__(self, view, edit, find_only, full_file, selection_only, max_sweeps,
settings = sublime.load_settings('reg_replace.sublime-settings')
self.extend = bool(settings.get("extended_back_references", False))

def view_replace(self, region, replacement):
tabs_to_spaces = self.view.settings().get('translate_tabs_to_spaces', False)
if tabs_to_spaces:
self.view.settings().set('translate_tabs_to_spaces', False)
self.view.replace(self.edit, region, replacement)
if tabs_to_spaces:
self.view.settings().set('translate_tabs_to_spaces', True)

def close(self):
"""
Clean up for the object. Mainly clean up the tracked loaded plugins.
Expand Down Expand Up @@ -148,7 +156,7 @@ def greedy_replace(self, find, replace, regions, scope_filter):
self.target_regions.append(region)
else:
# Apply replace
self.view.replace(self.edit, region, replace[count])
self.view_replace(region, replace[count])
count -= 1
return replaced

Expand Down Expand Up @@ -208,7 +216,7 @@ def non_greedy_replace(self, find, replace, regions, scope_filter):
self.target_regions.append(selected_region)
else:
# Apply replace
self.view.replace(self.edit, selected_region, replace[selection_index])
self.view_replace(selected_region, replace[selection_index])
return replaced

def expand(self, m, replace):
Expand Down Expand Up @@ -382,7 +390,7 @@ def greedy_scope_literal_replace(self, regions, find, replace, greedy_replace):
if self.find_only or self.action is not None:
self.target_regions.append(region)
else:
self.view.replace(self.edit, region, extraction)
self.view_replace(region, extraction)
return total_replaced

def non_greedy_scope_literal_replace(self, regions, find, replace, greedy_replace):
Expand Down Expand Up @@ -457,7 +465,7 @@ def non_greedy_scope_literal_replace(self, regions, find, replace, greedy_replac
self.target_regions.append(selected_region)
else:
# Apply replace
self.view.replace(self.edit, selected_region, selected_extraction)
self.view_replace(selected_region, selected_extraction)
return total_replaced

def greedy_scope_replace(self, regions, re_find, replace, greedy_replace, multi):
Expand All @@ -476,7 +484,7 @@ def greedy_scope_replace(self, regions, re_find, replace, greedy_replace, multi)
if self.find_only or self.action is not None:
self.target_regions.append(region)
else:
self.view.replace(self.edit, region, extraction)
self.view_replace(region, extraction)
except Exception as err:
print(str(traceback.format_exc()))
error('REGEX ERROR: %s' % str(err))
Expand Down Expand Up @@ -548,7 +556,7 @@ def non_greedy_scope_replace(self, regions, re_find, replace, greedy_replace, mu
self.target_regions.append(selected_region)
else:
# Apply replace
self.view.replace(self.edit, selected_region, selected_extraction)
self.view_replace(selected_region, selected_extraction)
return total_replaced

def select_scope_regions(self, regions, greedy_scope):
Expand Down

0 comments on commit c06390a

Please sign in to comment.