Skip to content

Commit

Permalink
Fixes gornostal#79 - Take into account `view.settings().get(default_l…
Browse files Browse the repository at this point in the history
…ine_ending)` when choosing what line endings to use
  • Loading branch information
gornostal committed Nov 18, 2014
1 parent ec014bc commit d910b21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Modific.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,21 @@ def tf_diff_command(self, file_name):
vcs_options = self.settings.get('vcs_options', {}).get('tf') or ['-format:unified']
return [get_user_command('tf') or 'tf', 'diff'] + vcs_options + [file_name]

def join_lines(self, lines):
"""
Join lines using os.linesep.join(), unless another method is specified in ST settings
"""
le = self.view.settings().get('default_line_ending')
if self.settings.get('debug'):
print("use line endings:", le)

if le == 'windows':
return "\r\n".join(lines)
elif le == 'unix':
return "\n".join(lines)

return os.linesep.join(lines)


class ShowDiffCommand(DiffCommand, sublime_plugin.TextCommand):
def diff_done(self, result):
Expand Down Expand Up @@ -506,7 +521,7 @@ def run(self, edit):
(row, col) = self.view.rowcol(self.view.sel()[0].begin())
(lines, start, replace_lines) = diff_parser.get_original_part(row + 1)
if lines is not None:
self.panel(os.linesep.join(lines))
self.panel(self.join_lines(lines))


class ReplaceModifiedPartCommand(DiffCommand, sublime_plugin.TextCommand):
Expand All @@ -523,7 +538,7 @@ def run(self, edit):
print('replace', (lines, current, replace_lines))
if lines is not None:
begin = self.view.text_point(current - 1, 0)
content = os.linesep.join(lines)
content = self.join_lines(lines)
if replace_lines:
end = self.view.line(self.view.text_point(replace_lines + current - 2, 0)).end()
region = sublime.Region(begin, end)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ If you are using SVN 1.7 you may want to turn on option `svn_use_internal_diff`.
This instructs Subversion to use its built-in differencing engine
despite any external differencing mechanism that may be specified for use in the user's runtime configuration.

### Line endings
Modific takes into account `default_line_ending` setting that you can change in your "User Settings" (or per project/file basis).
It determines what characters to use to join lines when Modific does "Revert change" action.
Valid values: `system` (OS-dependent), `windows` (CRLF) and `unix` (LF).


Thanks to
---------

Expand Down

0 comments on commit d910b21

Please sign in to comment.