summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2017-02-23 16:02:53 +0000
committerManuel Klimek <klimek@google.com>2017-02-23 16:02:53 +0000
commitc38cd69256e1bd35dc98778905b5a369233bef71 (patch)
tree74c0c20f3d0268491f3b8e4e0664f8c385574cf0
parent2c7169d00c5a7a0f8be5028061e418f3e1193f57 (diff)
downloadbcm5719-llvm-c38cd69256e1bd35dc98778905b5a369233bef71.tar.gz
bcm5719-llvm-c38cd69256e1bd35dc98778905b5a369233bef71.zip
Make clang-include-fixer--insert-line work when the difference is on an empty line
`clang-include-fixer--insert-line` has an off-by-one error because it uses `(goto-char (point-min)) (forward-char chars)`, which is (goto-char (1+ chars))`. Because of this, when the first difference was on an empty line (i.e. an include was appended to the block of includes), the pointer in the `to` buffer would be on the next line. Also wrapped calls inside another process sentinel inside `with-local-quit`. Patch by Torsten Marek. Differential Revision: https://reviews.llvm.org/D30292 llvm-svn: 295988
-rw-r--r--clang-tools-extra/include-fixer/tool/clang-include-fixer-test.el12
-rw-r--r--clang-tools-extra/include-fixer/tool/clang-include-fixer.el13
2 files changed, 18 insertions, 7 deletions
diff --git a/clang-tools-extra/include-fixer/tool/clang-include-fixer-test.el b/clang-tools-extra/include-fixer/tool/clang-include-fixer-test.el
index 22b17a2e5c1..03d9e4b0529 100644
--- a/clang-tools-extra/include-fixer/tool/clang-include-fixer-test.el
+++ b/clang-tools-extra/include-fixer/tool/clang-include-fixer-test.el
@@ -23,6 +23,18 @@
(should (equal (buffer-string) "aa\nab\nac\nad\n")))))
(should (equal (buffer-string) "aa\nab\nac\nad\n"))))
+(ert-deftest clang-include-fixer--insert-line-diff-on-empty-line ()
+ "Unit test for `clang-include-fixer--insert-line'."
+ (with-temp-buffer
+ (insert "aa\nab\n\nac\nad\n")
+ (let ((from (current-buffer)))
+ (with-temp-buffer
+ (insert "aa\n\nac\nad\n")
+ (let ((to (current-buffer)))
+ (should (clang-include-fixer--insert-line from to))
+ (should (equal (buffer-string) "aa\nab\n\nac\nad\n")))))
+ (should (equal (buffer-string) "aa\nab\n\nac\nad\n"))))
+
(ert-deftest clang-include-fixer--symbol-at-point ()
"Unit test for `clang-include-fixer--symbol-at-point'."
(with-temp-buffer
diff --git a/clang-tools-extra/include-fixer/tool/clang-include-fixer.el b/clang-tools-extra/include-fixer/tool/clang-include-fixer.el
index 191d0bdcab5..a04097fb125 100644
--- a/clang-tools-extra/include-fixer/tool/clang-include-fixer.el
+++ b/clang-tools-extra/include-fixer/tool/clang-include-fixer.el
@@ -213,16 +213,14 @@ return nil. Buffer restrictions are ignored."
(if (zerop chars)
;; Buffer contents are equal, nothing to do.
t
- (goto-char (point-min))
- (forward-char chars)
+ (goto-char chars)
;; We might have ended up in the middle of a line if the
;; current line partially matches. In this case we would
;; have to insert more than a line. Move to the beginning of
;; the line to avoid this situation.
(beginning-of-line)
(with-current-buffer from
- (goto-char (point-min))
- (forward-char chars)
+ (goto-char chars)
(beginning-of-line)
(let ((from-begin (point))
(from-end (progn (forward-line) (point)))
@@ -268,9 +266,10 @@ clang-include-fixer to insert the selected header."
(clang-include-fixer--replace-buffer stdout)
(let-alist context
(let-alist (car .HeaderInfos)
- (run-hook-with-args 'clang-include-fixer-add-include-hook
- (substring .Header 1 -1)
- (string= (substring .Header 0 1) "<"))))))
+ (with-local-quit
+ (run-hook-with-args 'clang-include-fixer-add-include-hook
+ (substring .Header 1 -1)
+ (string= (substring .Header 0 1) "<")))))))
(format "-insert-header=%s"
(clang-include-fixer--encode-json context))))))))
nil)
OpenPOWER on IntegriCloud