<div dir="ltr">Manuel, can you fix this?</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 19, 2015 at 4:12 AM, Kirill Ignatiev <span dir="ltr"><<a href="mailto:kirill.ignatiev@gmail.com" target="_blank">kirill.ignatiev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is this the right mailing list?<br>
<br>
The clang-format emacs package asks clang-format to return replacement<br>
rules, which are specified using byte offsets, not character offsets,<br>
and emacs always works with character offsets, not byte offsets.<br>
<br>
So if you have some multi-byte utf8 characters in a file, the emacs<br>
function clang-format-region will apply the rules incorrectly because<br>
byte offsets would not be equal to character offsets.<br>
<br>
In the function clang-format-region, the input parameters start and<br>
end are char offsets, so they should be converted to byte offsets:<br>
<br>
112a122,124<br>
>   (setq start (position-bytes start)<br>
>         end (position-bytes end))<br>
<br>
and in clang-format--replace, offset and length should be converted to<br>
char offsets, for example, like so:<br>
<br>
93a95,101<br>
> (defun clang-format--position-from-bytes (offset)<br>
>   (when offset<br>
>     (save-excursion<br>
>       (goto-char offset)<br>
>       (while (> (position-bytes (point)) offset) (forward-char -1))<br>
>       (point))))<br>
<br>
95,98c103,107<br>
<   (goto-char offset)<br>
<   (delete-char length)<br>
<   (when text<br>
<     (insert text)))<br>
---<br>
>   (let ((start (clang-format--position-from-bytes offset))<br>
>         (end (clang-format--position-from-bytes (+ offset length))))<br>
>     (goto-char start)<br>
>     (delete-region start end))<br>
>   (when text (insert text)))<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>