r186740 - Use -lines option instead of -offset/-length. This fixes problems with files using dos newlines (<CR><LF>).
Daniel Jasper
djasper at google.com
Sun Jul 21 03:34:22 PDT 2013
On Sat, Jul 20, 2013 at 3:01 AM, Alexander Kornienko <alexfh at google.com>wrote:
> Author: alexfh
> Date: Fri Jul 19 20:01:25 2013
> New Revision: 186740
>
> URL: http://llvm.org/viewvc/llvm-project?rev=186740&view=rev
> Log:
> Use -lines option instead of -offset/-length. This fixes problems with
> files using dos newlines (<CR><LF>).
>
> Modified:
> cfe/trunk/tools/clang-format/clang-format.py
>
> Modified: cfe/trunk/tools/clang-format/clang-format.py
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=186740&r1=186739&r2=186740&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-format/clang-format.py (original)
> +++ cfe/trunk/tools/clang-format/clang-format.py Fri Jul 19 20:01:25 2013
> @@ -35,10 +35,7 @@ text = '\n'.join(buf)
>
> # Determine range to format.
> cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
>
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:
1. Make clang-format work with <CR><NL> line endings.
2. Replace the '\n'.join(buf) with the appropriate ending (dependent
vim.eval('&fileformat') == 'dos')
Any thoughts?
-offset = int(vim.eval('line2byte(' +
> - str(vim.current.range.start + 1) + ')')) - 1
> -length = int(vim.eval('line2byte(' +
> - str(vim.current.range.end + 2) + ')')) - offset - 2
> +lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
>
> # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking
> clang-format.
> startupinfo = None
> @@ -48,8 +45,8 @@ if sys.platform.startswith('win32'):
> startupinfo.wShowWindow = subprocess.SW_HIDE
>
> # Call formatter.
> -p = subprocess.Popen([binary, '-offset', str(offset), '-length',
> str(length),
> - '-style', style, '-cursor', str(cursor)],
> +p = subprocess.Popen([binary, '-lines', lines, '-style', style,
> + '-cursor', str(cursor)],
> stdout=subprocess.PIPE, stderr=subprocess.PIPE,
> stdin=subprocess.PIPE, startupinfo=startupinfo)
> stdout, stderr = p.communicate(input=text)
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130721/3abaf0c4/attachment.html>
More information about the cfe-commits
mailing list