Index: test/Format/cursor.cpp =================================================================== --- test/Format/cursor.cpp +++ test/Format/cursor.cpp @@ -1,6 +1,6 @@ // RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp // RUN: clang-format -style=LLVM %t2.cpp -cursor=6 > %t.cpp // RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s -// CHECK: {{^\{ "Cursor": 4 \}$}} +// CHECK: {{^\{ "Cursor": 4, }} // CHECK: {{^int\ \i;$}} int i; Index: test/Format/incomplete.cpp =================================================================== --- test/Format/incomplete.cpp +++ test/Format/incomplete.cpp @@ -1,6 +1,8 @@ // RUN: grep -Ev "// *[A-Z-]+:" %s > %t2.cpp -// RUN: clang-format -style=LLVM %t2.cpp -cursor=6 > %t.cpp +// RUN: clang-format -style=LLVM %t2.cpp > %t.cpp // RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s -// CHECK: {{^\{ "Cursor": 4 \}$}} +// CHECK: {{^\{ "IncompleteFormat": true }} // CHECK: {{^int\ \i;$}} int i; +// CHECK: {{^f \( g \(;$}} +f ( g (; Index: tools/clang-format/ClangFormat.cpp =================================================================== --- tools/clang-format/ClangFormat.cpp +++ tools/clang-format/ClangFormat.cpp @@ -225,14 +225,17 @@ FormatStyle FormatStyle = getStyle( Style, (FileName == "-") ? AssumeFilename : FileName, FallbackStyle); - tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges); + bool IncompleteFormat = false; + tooling::Replacements Replaces = reformat(FormatStyle, Sources, ID, Ranges, &IncompleteFormat); if (OutputXML) { - llvm::outs() - << "\n\n"; + llvm::outs() << "\n\n"; if (Cursor.getNumOccurrences() != 0) llvm::outs() << "" << tooling::shiftedCodePosition(Replaces, Cursor) << "\n"; + for (tooling::Replacements::const_iterator I = Replaces.begin(), E = Replaces.end(); I != E; ++I) { @@ -252,9 +255,12 @@ else if (Rewrite.overwriteChangedFiles()) return true; } else { + outs() << "{"; if (Cursor.getNumOccurrences() != 0) - outs() << "{ \"Cursor\": " - << tooling::shiftedCodePosition(Replaces, Cursor) << " }\n"; + outs() << " \"Cursor\": " + << tooling::shiftedCodePosition(Replaces, Cursor) << ","; + outs() << " \"IncompleteFormat\": " + << (IncompleteFormat ? "true" : "false") << " }\n"; Rewrite.getEditBuffer(ID).write(outs()); } } Index: tools/clang-format/clang-format.el =================================================================== --- tools/clang-format/clang-format.el +++ tools/clang-format/clang-format.el @@ -61,6 +61,7 @@ (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements)) (error "Expected node")) (let ((nodes (xml-node-children xml-node)) + (incomplete-format (xml-get-attribute xml-node 'incomplete_format)) replacements cursor) (dolist (node nodes) @@ -89,7 +90,7 @@ (and (= (car a) (car b)) (> (cadr a) (cadr b))))))) - (cons replacements cursor))) + (list replacements cursor (string= incomplete-format "true")))) (defun clang-format--replace (offset length &optional text) (let ((start (byte-to-position (1+ offset))) @@ -142,20 +143,24 @@ ((stringp status) (error "(clang-format killed by signal %s%s)" status stderr)) ((not (equal 0 status)) - (error "(clang-format failed with code %d%s)" status stderr)) - (t (message "(clang-format succeeded%s)" stderr))) + (error "(clang-format failed with code %d%s)" status stderr))) (with-current-buffer temp-buffer (setq operations (clang-format--extract (car (xml-parse-region))))) - (let ((replacements (car operations)) - (cursor (cdr operations))) + (let ((replacements (nth 0 operations)) + (cursor (nth 1 operations)) + (incomplete-format (nth 2 operations))) (save-excursion (mapc (lambda (rpl) (apply #'clang-format--replace rpl)) replacements)) (when cursor - (goto-char (byte-to-position (1+ cursor)))))) + (goto-char (byte-to-position (1+ cursor)))) + (message "%s" incomplete-format) + (if incomplete-format + (message "(clang-format: incomplete (syntax errors)%s)" stderr) + (message "(clang-format: success%s)" stderr)))) (delete-file temp-file) (when (buffer-name temp-buffer) (kill-buffer temp-buffer)))))