Skip to content

Commit

Permalink
Fixed removing tabs in non-formatted code (#52)
Browse files Browse the repository at this point in the history
When using the translate_tabs_to_spaces settings, all
of the tabs of a file would be translated to spaces
even if they were not part of the formatted code. This
 could be anoying with bigger file containing both spaces
and tabs for formatting.

The issue comes from the fact that we overwrite all of the
file even when formatting  selected text. Therefore Sublime
would translate the copied tabs to spaces even when not part
of the formatted code.

To fix this, we simply temporarily disable the
translate_tabs_to_spaces setting and set it back once the code
has been copied.
  • Loading branch information
reicrof authored and sailormoon committed Nov 22, 2017
1 parent 8d6613f commit 5f77ec1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!


Expand Down

0 comments on commit 5f77ec1

Please sign in to comment.