Commit Graph

85 Commits

Author SHA1 Message Date
Daniel Jasper 68c03c82df clang-format: Smarter replacement in the vim integration.
With this fix, only changed regions will be replaced in vim's buffer.
Thereby, marks should mostly be left intact. Furthermore, this is a
better fix for the performance problem in conjunction with
'foldmethod=syntax' (see r186660).

llvm-svn: 186789
2013-07-21 10:45:33 +00:00
Alexander Kornienko 5884aa9617 Use -lines option instead of -offset/-length. This fixes problems with files using dos newlines (<CR><LF>).
llvm-svn: 186740
2013-07-20 01:01:25 +00:00
Daniel Jasper b11c2c2838 Improve clang-format vim integration.
The previous line-by-line replacement causes vim to take a long time if
the foldmethod is set to 'syntax'. This should significantly improve
performance in that case.

llvm-svn: 186660
2013-07-19 09:30:44 +00:00
Alexander Kornienko a49732ff28 Added -lines X:Y option to specify line range to process. This is a more human-friendly alternative to -offset and -length.
Differential Revision: http://llvm-reviews.chandlerc.com/D1160

llvm-svn: 186625
2013-07-18 22:54:56 +00:00
Rafael Espindola 16125fb652 Update for llvm API change.
llvm-svn: 186448
2013-07-16 19:44:23 +00:00
Daniel Jasper 095737413f Prevent error message when formatting an empty file.
This fixes llvm.org/PR16514.

llvm-svn: 185531
2013-07-03 12:22:18 +00:00
Daniel Jasper a3fc21a0f1 Fix ranges computed by git clang-format.
Before, the computed byte range would include the trailing newline.
clang-format on the other hand counts whitespace as belonging to the
following token, so that git-clang-format inadvertendly reformats the
first unmodified line as well.

It is not entirely clear whether clang-format's behavior itself should
be modified, but for now this seems to be a safe change.

llvm-svn: 185423
2013-07-02 13:20:35 +00:00
Alexander Kornienko 1e80887d63 Use lexing mode based on FormatStyle.Standard.
Summary:
Some valid pre-C++11 constructs change meaning when lexed in C++11
mode, e.g.
#define x(_a) printf("foo"_a);
(example from http://llvm.org/bugs/show_bug.cgi?id=16342). "foo"_a is treated as
a user-defined string literal when parsed in C++11 mode.
In order to deal with this correctly, we need to set lexing mode according to
which standard the code conforms to. We already have a configuration value for
this (FormatStyle.Standard), which seems to be appropriate to use in this case
as well.

Reviewers: klimek

CC: cfe-commits, gribozavr

Differential Revision: http://llvm-reviews.chandlerc.com/D1028

llvm-svn: 185149
2013-06-28 12:51:24 +00:00
Reid Kleckner 898229ab4b [Driver] Refactor clang driver to use LLVM's Option library
The big changes are:
- Deleting Driver/(Arg|Opt)*
- Rewriting includes to llvm/Option/ and re-sorting
- 'using namespace llvm::opt' in clang::driver
- Fixing the autoconf build by adding option everywhere

As discussed in the review, this change includes using directives in
header files.  I'll make follow up changes to remove those in favor of
name specifiers.

Reviewers: espindola

Differential Revision: http://llvm-reviews.chandlerc.com/D975

llvm-svn: 183989
2013-06-14 17:17:23 +00:00
Manuel Klimek c00dd83583 Make it possible to assign clang-format-buffer to a keybinding.
Patch by Chris Gray.

llvm-svn: 183739
2013-06-11 12:00:24 +00:00
Reid Kleckner 99dfe95bdd [clang-format] Don't flash an ugly cmd prompt in Vim on Windows
Reviewers: klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D941

llvm-svn: 183654
2013-06-10 14:16:26 +00:00
Daniel Jasper 2714ba03f6 Fix default value of clang-format-diff's -p option.
This way, it has the same default as 'patch' and also the example in the
code makes more sense as it is explicitly setting -p 1.

llvm-svn: 182923
2013-05-30 11:50:20 +00:00
Daniel Jasper e7a500160e clang-format integration for git.
Put this somewhere on your path and use:

git clang-format

Awesome work by Mark Lodato. Many thanks!

llvm-svn: 182596
2013-05-23 17:53:42 +00:00
Daniel Jasper a3c14575ef Fix off-by-one error in clang-format's emacs integration.
llvm-svn: 182395
2013-05-21 17:05:40 +00:00
Daniel Jasper a8048b8216 Fix behavior of clang-format's -cursor flag.
llvm-svn: 182386
2013-05-21 14:21:46 +00:00
Daniel Jasper 2a250b8b49 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.

llvm-svn: 182373
2013-05-21 12:21:39 +00:00
Alexander Kornienko 006b5c89ce Clang-format: allow -style="{yaml/json}" on command line
Summary: + improved handling of default style and predefined styles.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D813

llvm-svn: 182205
2013-05-19 00:53:30 +00:00
Daniel Jasper 5b38f744e8 Add basic clang-format integration for sublime text.
llvm-svn: 182015
2013-05-16 15:08:25 +00:00
Daniel Jasper 6e3506f212 Update clang-format emacs integration.
- Remove free variables
- Add function clang-format-buffer, e.g. for before-save-hooks
- Wrap restoring windows in an unwind-protect

Patch by Stephen Gildea!

llvm-svn: 181766
2013-05-14 08:48:24 +00:00
Alexander Kornienko 88a0d939de Reformat clang-format help strings, filter out irrelevant options.
Summary: +updated ClangFormat.rst

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D780

llvm-svn: 181617
2013-05-10 18:12:00 +00:00
Alexander Kornienko 70f6b3b631 Updated clang-format help messages for -offset and -length
llvm-svn: 181593
2013-05-10 13:18:17 +00:00
Alexander Kornienko fa94cbb70f Minor clarifications in help messages and a comment.
llvm-svn: 181591
2013-05-10 13:04:20 +00:00
Alexander Kornienko 49149677d9 Config file support for clang-format, part 2.
Summary:
Adds actual config file reading to the clang-format utility.
Configuration file name is .clang-format. It is looked up for each input file
in its parent directories starting from immediate one. First found .clang-format
file is used. When using standard input, .clang-format is searched starting from
the current directory.
Added -dump-config option to easily create configuration files.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, jordan_rose, kimgr

Differential Revision: http://llvm-reviews.chandlerc.com/D758

llvm-svn: 181589
2013-05-10 11:56:10 +00:00
Daniel Jasper ee48c856e2 Further fix to clang-format emacs integration.
This is just a slight improvement for the fix in r181299, which fixes
formatting the very last line of a file.

llvm-svn: 181303
2013-05-07 10:04:47 +00:00
Daniel Jasper f7bec9b4ed Fix clang-format emacs integration in last line.
Emacs seems to have a line that is just past the last character of the
buffers content. This needs to be handled specially so that clang-format
is not called with an invalid -offset.

llvm-svn: 181299
2013-05-07 09:25:29 +00:00
Alexander Kornienko c860266e0f Added Mozilla style, cleaned get*Style methods.
Summary: Patch based on a patch by Ehsan Akhgari.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D750

llvm-svn: 181196
2013-05-06 14:11:27 +00:00
Daniel Jasper 5f99742632 Basic clang-format integration for BBEdit.
Thanks to Avi Drissman!

llvm-svn: 180933
2013-05-02 17:37:36 +00:00
Daniel Jasper a04337e22b Fix scrolling bug in clang-format's emacs integration.
This patch ensure that nothing scrolls even if the same buffer is opened
in multiple windows.

llvm-svn: 180252
2013-04-25 07:06:48 +00:00
Alexander Kornienko 3fbee010c6 clang-format support for multiple input files.
Summary:
Added support for multiple input files, that can be used both with and
without in-place edit (-i) option. Added checks for -offset and -length options:
don't allow them on multiple files, check that they don't fall outside input
file, made both options unsigned, so that there's no need to check for negative
values. Removed "-1 can be used for end-of-file" from -length description.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D719

llvm-svn: 180185
2013-04-24 12:46:44 +00:00
Daniel Jasper dd77743af8 Small improvements to clang-format documentation and integration
scripts.

llvm-svn: 179676
2013-04-17 07:55:02 +00:00
Daniel Jasper 31f916ac51 Fix clang-format-diff.py script.
llvm-svn: 179377
2013-04-12 13:42:36 +00:00
Daniel Jasper 92a3130509 Provide better emacs integration.
The new emacs integration is simpler, does not save the current file
before reformatting and ensures that emacs does not scroll as a result
of formatting.

Also explicitly set the style in clang-format tests to make them more
robust.

llvm-svn: 179372
2013-04-12 10:12:01 +00:00
Daniel Jasper e4549a2391 Improvements to clang-format integrations.
This adds an emacs editor integration (thanks to Ami Fischman). Also
pulls out the style into a variable for the vi integration and just
uses clang-formats defaults style in clang-format-diff.py.

llvm-svn: 179098
2013-04-09 15:23:04 +00:00
Daniel Jasper 4b14f4f9e6 Remove outdated part of help message.
The styles are now documented with the -style option. This fixes
llvm.org/PR15689.

llvm-svn: 179017
2013-04-08 10:50:02 +00:00
Daniel Jasper 9be2c5cf17 Add clang-format binary to cfe.
llvm-svn: 177506
2013-03-20 09:53:23 +00:00