<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 20, 2013 at 3:01 AM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank" class="cremed">alexfh@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alexfh<br>
Date: Fri Jul 19 20:01:25 2013<br>
New Revision: 186740<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=186740&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=186740&view=rev</a><br>
Log:<br>
Use -lines option instead of -offset/-length. This fixes problems with files using dos newlines (<CR><LF>).<br>
<br>
Modified:<br>
    cfe/trunk/tools/clang-format/clang-format.py<br>
<br>
Modified: cfe/trunk/tools/clang-format/clang-format.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=186740&r1=186739&r2=186740&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=186740&r1=186739&r2=186740&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/tools/clang-format/clang-format.py (original)<br>
+++ cfe/trunk/tools/clang-format/clang-format.py Fri Jul 19 20:01:25 2013<br>
@@ -35,10 +35,7 @@ text = '\n'.join(buf)<br>
<br>
 # Determine range to format.<br>
 cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2<br></blockquote><div><br></div><div>The cursor value will still be wrong in this case. I think right now there is not much we can do (short of calculating it ourselves). I think what we need to do is:</div>
<div>1. Make clang-format work with <CR><NL> line endings.</div><div>2. Replace the '\n'.join(buf) with the appropriate ending (dependent vim.eval('&fileformat') == 'dos')</div><div>
<br></div><div>Any thoughts?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-offset = int(vim.eval('line2byte(' +<br>
-                      str(vim.current.range.start + 1) + ')')) - 1<br>
-length = int(vim.eval('line2byte(' +<br>
-                      str(vim.current.range.end + 2) + ')')) - offset - 2<br>
+lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)<br>
<br>
 # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.<br>
 startupinfo = None<br>
@@ -48,8 +45,8 @@ if sys.platform.startswith('win32'):<br>
   startupinfo.wShowWindow = subprocess.SW_HIDE<br>
<br>
 # Call formatter.<br>
-p = subprocess.Popen([binary, '-offset', str(offset), '-length', str(length),<br>
-                      '-style', style, '-cursor', str(cursor)],<br>
+p = subprocess.Popen([binary, '-lines', lines, '-style', style,<br>
+                      '-cursor', str(cursor)],<br>
                      stdout=subprocess.PIPE, stderr=subprocess.PIPE,<br>
                      stdin=subprocess.PIPE, startupinfo=startupinfo)<br>
 stdout, stderr = p.communicate(input=text)<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" class="cremed">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>