<div dir="ltr">I have not heard of this problem before, but I am also not personally using emacs. Adding Johann Klähn, who has just proposed improvements to the emacs integration. Maybe he has experienced this problem, too.<div><br></div><div>I think the "right" solution here might be what we do for the vim integration. Instead of replacing the entire buffer, we just compute a diff and only apply the diff chunks individually. This makes fiddling with the window starts completely unnecessary.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 2, 2015 at 2:41 AM, Adam McKee <span dir="ltr"><<a href="mailto:Adam.Matthew.McKee@gmail.com" target="_blank">Adam.Matthew.McKee@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>As I wrote earlier, I've put this in my ~/.emacs to format my C++ buffers before they're saved:<br></div><div><br></div><div>(add-hook 'c++-mode-hook</div><div>    (lambda()</div><div>        (add-hook 'before-save-hook 'clang-format-buffer)))</div><div><br></div><div>This worked fine when saving individual files with "C-x C-s".  However, I encountered a problem when using "C-x s" (save-some-buffers) where the window-start would be moved to the very first line, and the point would be moved to the left margin on the middle line in the window.  In clang-format.el, I added some debug messages to show what's happening with the calls to goto-char() and set-window-start().  What I found is that there's nothing wrong with those calls in the (save-some-buffers) case, and they are the exact same as in the case where I save the buffer individually with "C-x C-s".  Despite (clang-format-buffer) doing apparently the same thing in both cases, with (save-some-buffers) _something_ is moving window-start to the start of the file, which is not acceptable.</div><div><br></div><div>I don't see a problem with clang-format.el to be fixed, and I don't know how to proceed with this any more, so here I just wanted to give an account of my experience with this, in the hope that it could be useful.</div><div><br></div><div>What I've done to my clang-format.el for now is to remove the loop at the end of the function that restores the window-starts of the windows showing the formatted buffer.  The result of that is still is slightly disorienting because the line containing the point is centered on the screen (if possible), but it's far better than having the window-start moved to the first line.</div><div><br></div><div>Clang-formatting before save must be quite a common practice, so is anyone doing so _not_ seeing the same window-start dislocation problem with (save-some-buffers)?  If I can duplicate an emacs setup that doesn't have this problem, that would help.</div></div>
<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></blockquote></div><br></div>