[cfe-dev] emacs integration: problem with formatting C++ buffers before saving

Adam McKee Adam.Matthew.McKee at gmail.com
Thu Jan 1 05:18:12 PST 2015


Hi list,

I added this to my .emacs to clang-format C++ buffers before they are saved:

; on-save: clang-format
(add-hook 'c++-mode-hook
    (lambda()
        (add-hook 'before-save-hook 'clang-format-buffer)))

This is fine if I save an individual buffer with "C-x C-s", but if I do
"C-x s" (save-some-buffers), the buffer is clang-formatted (as expected)
but sadly I lose my place in the buffer (window-start is moved to the
beginning, and the point is moved to beginning-of-line about halfway down
the window).  Does anyone know what's going on with that?  I'm not much
good with elisp, but so far I've overcome that deficit enough to understand
most of clang-format.el.  Unfortunately, I haven't identified the problem
yet.  I'm prepared to spend some more time on this tomorrow, and if I come
up with any improvement to clang-format.el I'll share it of course.  Any
clue you may have would be much appreciated.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150101/605832df/attachment.html>


More information about the cfe-dev mailing list