[clang-tools-extra] r285060 - include-fixer: Don't overwrite buffer changes
Manuel Klimek via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 25 04:31:22 PDT 2016
Author: klimek
Date: Tue Oct 25 06:31:22 2016
New Revision: 285060
URL: http://llvm.org/viewvc/llvm-project?rev=285060&view=rev
Log:
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.
Modified:
clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el?rev=285060&r1=285059&r2=285060&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el Tue Oct 25 06:31:22 2016
@@ -244,7 +244,13 @@ clang-include-fixer to insert the select
(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 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"
(clang-include-fixer--encode-json context)))))))
nil)
More information about the cfe-commits
mailing list