diff --git a/clang_format.py b/clang_format.py index 39b4188..d1539de 100644 --- a/clang_format.py +++ b/clang_format.py @@ -285,10 +285,19 @@ def run(self, edit, whole_buffer=False): return # If there were no errors, we replace the view with the outputted buf. + # Temporarily disable tabs to space so that tabs elsewhere in the file + # do not get modified if they were not part of the formatted selection + prev_tabs_to_spaces = self.view.settings().get('translate_tabs_to_spaces') + self.view.settings().set('translate_tabs_to_spaces', False) + self.view.replace( edit, sublime.Region(0, self.view.size()), output.decode(encoding)) + # Re-enable previous tabs to space setting + self.view.settings().set('translate_tabs_to_spaces', prev_tabs_to_spaces) + + # TODO: better semantics for re-positioning cursors!