diff options
author | Daniel Jasper <djasper@google.com> | 2013-05-21 12:21:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-05-21 12:21:39 +0000 |
commit | 6bd3b93200c6ae141d0f7444ffb4cacd52b183ed (patch) | |
tree | 85ddc2eac780535408f50371bbde4f8a6a674729 /tools/clang-format/ClangFormat.cpp | |
parent | 800ff45b49e306a5706f249d3289281dc224dcb3 (diff) |
Let clang-format move the cursor appropriately.
With this patch, clang-format will try to keep the cursor at the
original code position in editor integrations (implemented for emacs and
vim). This means, after formatting, clang-format will try to keep the
cursor on the same character of the same token.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182373 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index fccd6bf257..340ef5587f 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -77,6 +77,11 @@ static cl::opt<bool> cl::desc("Dump configuration options to stdout and exit.\n" "Can be used with -style option."), cl::cat(ClangFormatCategory)); +static cl::opt<unsigned> + Cursor("cursor", + cl::desc("The position of the cursor when invoking clang-format from" + " an editor integration"), + cl::init(0), cl::cat(ClangFormatCategory)); static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"), cl::cat(ClangFormatCategory)); @@ -221,6 +226,9 @@ static bool format(std::string FileName) { Rewrite.getEditBuffer(ID).write(FileStream); FileStream.flush(); } else { + if (Cursor != 0) + outs() << "{ \"Cursor\": " << tooling::shiftedCodePosition( + Replaces, Cursor) << " }\n"; Rewrite.getEditBuffer(ID).write(outs()); } } |