<div dir="ltr">Johann's clang-format.el is now working great for me. For some reason, the XML library in my emacs 23.4 (from Debian wheezy) was complaining about multiple root tags in the XML from clang-format, but when I upgraded to emacs 24.4 that problem disappeared. It's strange because a) there were not multiple root tags, and b) Johann tested with the same version of emacs from wheezy and that worked for him. Despite that little mystery, from my point of view all's well that ends well.<div><br></div><div>For thoroughness, after upgrading my emacs, I also re-tested the clang-format.el from clang-format-3.6, and I still had the same problem with window-starts getting moved to the start of the buffer when doing "C-x s" (save-some-buffers).<br><div><br></div><div>Maybe Johann's clang-format.el should be adopted into clang-format?</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 6, 2015 at 11:54 AM, Johann Klähn <span dir="ltr"><<a href="mailto:kljohann@gmail.com" target="_blank">kljohann@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have a prototype[1] that does adjustments via single edit operations<br>
based on the '-output-replacements-xml' option (instead of replacing<br>
the whole buffer; this would be similar to the difflib-approach, I<br>
guess?). But when using this option the JSON-header containing the<br>
'-cursor' information is not returned, so I have to rely on markers<br>
inserted into the buffer to keep the cursor position. On the upside<br>
this allows me to track the cursor per-window.<br>
<br>
[1] <a href="https://github.com/kljohann/clang-format.el/tree/xml" target="_blank">https://github.com/kljohann/clang-format.el/tree/xml</a><br>
<div class="HOEnZb"><div class="h5"><br>
On Sat, Jan 3, 2015 at 9:31 AM, Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:<br>
> I have not heard of this problem before, but I am also not personally using<br>
> emacs. Adding Johann Klähn, who has just proposed improvements to the emacs<br>
> integration. Maybe he has experienced this problem, too.<br>
><br>
> I think the "right" solution here might be what we do for the vim<br>
> integration. Instead of replacing the entire buffer, we just compute a diff<br>
> and only apply the diff chunks individually. This makes fiddling with the<br>
> window starts completely unnecessary.<br>
><br>
> On Fri, Jan 2, 2015 at 2:41 AM, Adam McKee <<a href="mailto:Adam.Matthew.McKee@gmail.com">Adam.Matthew.McKee@gmail.com</a>><br>
> wrote:<br>
>><br>
>> As I wrote earlier, I've put this in my ~/.emacs to format my C++ buffers<br>
>> before they're saved:<br>
>><br>
>> (add-hook 'c++-mode-hook<br>
>> (lambda()<br>
>> (add-hook 'before-save-hook 'clang-format-buffer)))<br>
>><br>
>> This worked fine when saving individual files with "C-x C-s". However, I<br>
>> encountered a problem when using "C-x s" (save-some-buffers) where the<br>
>> window-start would be moved to the very first line, and the point would be<br>
>> moved to the left margin on the middle line in the window. In<br>
>> clang-format.el, I added some debug messages to show what's happening with<br>
>> the calls to goto-char() and set-window-start(). What I found is that<br>
>> there's nothing wrong with those calls in the (save-some-buffers) case, and<br>
>> they are the exact same as in the case where I save the buffer individually<br>
>> with "C-x C-s". Despite (clang-format-buffer) doing apparently the same<br>
>> thing in both cases, with (save-some-buffers) _something_ is moving<br>
>> window-start to the start of the file, which is not acceptable.<br>
>><br>
>> I don't see a problem with clang-format.el to be fixed, and I don't know<br>
>> how to proceed with this any more, so here I just wanted to give an account<br>
>> of my experience with this, in the hope that it could be useful.<br>
>><br>
>> What I've done to my clang-format.el for now is to remove the loop at the<br>
>> end of the function that restores the window-starts of the windows showing<br>
>> the formatted buffer. The result of that is still is slightly disorienting<br>
>> because the line containing the point is centered on the screen (if<br>
>> possible), but it's far better than having the window-start moved to the<br>
>> first line.<br>
>><br>
>> Clang-formatting before save must be quite a common practice, so is anyone<br>
>> doing so _not_ seeing the same window-start dislocation problem with<br>
>> (save-some-buffers)? If I can duplicate an emacs setup that doesn't have<br>
>> this problem, that would help.<br>
>><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>
>><br>
><br>
</div></div></blockquote></div><br></div>