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:
parent
8e5f5ff4c1
commit
63c6989d70
|
|
@ -244,7 +244,13 @@ clang-include-fixer to insert the selected header."
|
||||||
(clang-include-fixer--select-header context)
|
(clang-include-fixer--select-header context)
|
||||||
;; Call clang-include-fixer again to insert the selected header.
|
;; Call clang-include-fixer again to insert the selected header.
|
||||||
(clang-include-fixer--start
|
(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 user’s 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"
|
(format "-insert-header=%s"
|
||||||
(clang-include-fixer--encode-json context)))))))
|
(clang-include-fixer--encode-json context)))))))
|
||||||
nil)
|
nil)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue