Index: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el =================================================================== --- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer-test.el +++ clang-tools-extra/trunk/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 Index: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el =================================================================== --- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el +++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.el @@ -213,16 +213,14 @@ (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--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)