include-fixer: Don't overwrite buffer changes

Raise a signal if the buffer has been modified before replacing it, to
avoid overwriting users' changes.

Patch by Philipp Stephani.

llvm-svn: 285060
This commit is contained in:
Manuel Klimek 2016-10-25 11:31:22 +00:00
parent 8e5f5ff4c1
commit 63c6989d70
1 changed files with 7 additions and 1 deletions

View File

@ -244,7 +244,13 @@ clang-include-fixer to insert the selected header."
(clang-include-fixer--select-header context)
;; Call clang-include-fixer again to insert the selected header.
(clang-include-fixer--start
#'clang-include-fixer--replace-buffer
(let ((old-tick (buffer-chars-modified-tick)))
(lambda (stdout)
(when (/= old-tick (buffer-chars-modified-tick))
;; Replacing the buffer now would undo the users changes.
(user-error (concat "The buffer has been changed "
"before the header could be inserted")))
(clang-include-fixer--replace-buffer stdout)))
(format "-insert-header=%s"
(clang-include-fixer--encode-json context)))))))
nil)