Fixed slightly differently (using the built-in byte-to-position instead of rolling our own, and getting a little structure into where we do the mappings) in r226445.<div><br></div><div>Thanks for reporting!</div><div>Cheers,</div><div>/Manuel<br><div><div><br><div class="gmail_quote">On Mon Jan 19 2015 at 7:53:49 AM Kirill Ignatiev <<a href="mailto:kirill.ignatiev@gmail.com">kirill.ignatiev@gmail.com</a>> 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-<u></u>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-<u></u>bytes offset))<br>
> (end (clang-format--position-from-<u></u>bytes (+ offset length))))<br>
> (goto-char start)<br>
> (delete-region start end))<br>
> (when text (insert text)))<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div></div></div>