summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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