Commit Graph

31 Commits

Author SHA1 Message Date
Vedant Kumar 0972da7870 [clang-format] Another attempt at python 3 compatibility
The entries in vim.current.buffer appear to be decoded strings, which
means that python3 won't allow invoking 'decode' on them. Keep the old
behavior when running under python2, but skip the error-inducing decode
step with python3..

llvm-svn: 289308
2016-12-10 00:54:13 +00:00
Alexander Kornienko 115d225cf1 Attempt to make clang-format.py python 3 - compatible.
llvm-svn: 285301
2016-10-27 15:15:23 +00:00
Alexander Kornienko 179e803abd Fix warnings from python difflib.
llvm-svn: 285291
2016-10-27 13:46:49 +00:00
Alexander Kornienko f51bf96977 Fix clang-format vim integration issue with non-ascii characters
clang-format.py currently seems to treat vim.current.buf as ascii-encoded data,
which leads to an UnicodeDecodeError when trying to format any text containing
non-ascii characters:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../tools/clang/tools/clang-format/clang-format.py", line 110, in <module>
    main()
  File ".../tools/clang/tools/clang-format/clang-format.py", line 87, in main
    stdout, stderr = p.communicate(input=text.encode(encoding))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3996: ordinal not in range(128)

llvm-svn: 284988
2016-10-24 16:31:26 +00:00
Luke Drummond ff7c77f906 [clang-format-vim] Support vim linked against py3
clang-format.py previously only worked in vim compiled against python2.

This patch adds the necessary syntax changes to make this work with vim
linked against python3, which is now shipped by default for at least Ubuntu16 and Arch.

Differential Revision: https://reviews.llvm.org/D23319

Subscribers: cfe-commits
llvm-svn: 280240
2016-08-31 13:36:36 +00:00
Daniel Jasper da44677082 clang-format: Enable #include sorting by default.
This has seen quite some usage and I am not aware of any issues. Also
add a style option to enable/disable include sorting. The existing
command line flag can from now on be used to override whatever is set
in the style.

llvm-svn: 253202
2015-11-16 12:38:56 +00:00
Daniel Jasper d89ae9d3ac clang-format: Add initial #include sorting capabilities.
To implement this nicely, add a function that merges two sets of
replacements that are meant to be done in sequence. This functionality
will also be useful for other applications, e.g. formatting the result
of clang-tidy fixes.

llvm-svn: 248367
2015-09-23 08:30:47 +00:00
Daniel Jasper 1a5ea6eb20 clang-format: Extend vim integration so that a line range can be passed in.
llvm-svn: 241976
2015-07-11 06:46:26 +00:00
Chandler Carruth c925a905f7 Fix terrible python goof in clang-format.py which broke my vim
integration.

Nothing is more important in life than clang-format integration with
vim. ;]

llvm-svn: 239098
2015-06-04 21:23:07 +00:00
Manuel Klimek 995901756f Make vim also output a helpful message in some error cases.
When clang-format encounters a syntax error, it will not format that
line; we're now using the same mechanism we're already using in emacs to
show a helpful error message to the user.

llvm-svn: 238823
2015-06-02 12:01:50 +00:00
Daniel Jasper 0fe44465c3 clang-format: Add default fallback style.
Thanks to Michael Schlottke.

llvm-svn: 235162
2015-04-17 07:59:19 +00:00
Daniel Jasper 23341446e8 clang-format: add an option for fallback style in vimrc
With this patch, clang-format.py will search and use existing .clang-format
file if there is one and fallback to the specific format style if
not. It should cover the projects which don't have .clang-format
files in their source. As the option fallback-style is available in
clang 3.5 or later, it is safe to use.

Patch by "Chilledheart" (http://reviews.llvm.org/D8489).

llvm-svn: 235080
2015-04-16 08:26:37 +00:00
Daniel Jasper 20bc4b0f5c clang-format: Fix vim integration if g:clang_format_binary doesn't exist
llvm-svn: 221254
2014-11-04 10:40:26 +00:00
Saleem Abdulrasool 4d195ed4b2 clang-format: permit setting the path to clang in vimrc
If g:clang_format_path is set in the vimrc, that path will take precedence over
the hard coded path (which is reliant on the PATH environment variable).  This
provides an easy mechanism for switching the selected clang-format binary during
development.

llvm-svn: 221108
2014-11-02 21:27:59 +00:00
Saleem Abdulrasool 8bbed0b63a docs: remove double carriage-return
The double carriage return would silence a warning due to a missing
.clang-format.  Permit the error to bubble through.

llvm-svn: 221107
2014-11-02 21:27:52 +00:00
Saleem Abdulrasool 1f060a8552 clang-format: improve vim integration docs
Improve the documentation for vim integration of clang-format.  Prefer the use
of <c-o> to do the normal mode command execution to avoid side-effects of the
escape and re-insertion (cursor movement).  Tweak the macros to use a double
return to avoid having to manually return control to the editor from the
subprocess.

llvm-svn: 220685
2014-10-27 17:13:33 +00:00
Daniel Jasper 62f73ec1ef clang-format: Fix vim-integration for empty files.
Discovered by Ahmed Charles in http://reviews.llvm.org/D3018.

llvm-svn: 209417
2014-05-22 11:37:05 +00:00
Nico Weber ffaf29a07b clang-format.py: Don't omit the first two words from error messages.
This reverts r172072.  clang-format used to use DiagnosticEngine to output
errors: http://llvm.org/viewvc/llvm-project?view=revision&revision=172071. Now
it doesn't, so this code is obsolete.

llvm-svn: 206479
2014-04-17 17:51:57 +00:00
Ahmed Charles f9e1e5f8de Add a main function to the clang-format.py vim integration.
This will allow using an early return statement in a subsequent change.

llvm-svn: 203501
2014-03-10 22:12:14 +00:00
Nico Weber 8bdd1ee021 clang-format.py: Make formatting unnamed buffers work again (broke in r190691).
llvm-svn: 193433
2013-10-25 20:06:20 +00:00
Daniel Jasper e488f5dd1e clang-format: Add -assume-filename option for editor integrations.
With -style=file, clang-format now starts to search for a .clang-format
file starting at the file given with -assume-filename if it reads from
stdin. Otherwise, it would start searching from the current directory,
which is not helpful for editor integrations.

Also changed vim, emacs and sublime integrations to actually make use of
this flag.

This fixes llvm.org/PR17072.

llvm-svn: 190691
2013-09-13 13:40:24 +00:00
Hans Wennborg 9f6581bb88 Allow _clang-format as alternative to .clang-format config filename
Dotfiles are impractical on Windows. This makes clang-format search
for the style configuration file as '_clang-format' in addition to
the usual '.clang-format'. This is similar to how VIM searches for
'_vimrc' on Windows.

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

llvm-svn: 190413
2013-09-10 15:41:12 +00:00
Chandler Carruth bc36e6e099 Switch the default mode for clang-format to '-file'. Make 'LLVM' the
fallback syntax used when we fail to find a '.clang-format' file. Adjust
variable names appropriately.

Update the editor integration pieces that specify a '-style' option to
specify it as '-style=file'. I left the functionality in place because
even if the preferred method is to use '.clang-format' files, this way
if someone needs to clobber the style in their editor we show how to do
so in these examples.

Also check in a '.clang-format' file for Clang to ensure that separate
checkouts and builds of Clang from LLVM can still get the nice
formatting. =] This unfortunately required nuking the test for the
absence of a '.clang-format' file as now the directory happening to be
under your clang source tree will cause there to always be a file. ;]

llvm-svn: 189741
2013-09-02 07:42:02 +00:00
Daniel Jasper 8e2c20a77d Fix bug in clang-format's vim integration cause by r186789.
After the first operation, the buffer contents has changed and thus all
other operations would be invalid. Executing the operations in reversed
order should fix this.

llvm-svn: 186840
2013-07-22 16:22:13 +00:00
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
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 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
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 9be2c5cf17 Add clang-format binary to cfe.
llvm-svn: 177506
2013-03-20 09:53:23 +00:00