diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-03-15 07:14:42 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-03-15 12:14:42 +0100 |
commit | 680252aa15159f0e969f6d169d01a8fbad097fa4 (patch) | |
tree | a778b6677b7b23e33dfe25c2556ca818e220e8ec /src/nvim/edit.c | |
parent | ced980ff17e18267e3d7a55fc1c513d967790e5e (diff) | |
download | rneovim-680252aa15159f0e969f6d169d01a8fbad097fa4.tar.gz rneovim-680252aa15159f0e969f6d169d01a8fbad097fa4.tar.bz2 rneovim-680252aa15159f0e969f6d169d01a8fbad097fa4.zip |
vim-patch:8.1.0728: avoid breaking after single space #9733
Problem: Cannot avoid breaking after a single space.
Solution: Add the 'p' flag to 'formatoptions'. (Tom Ryder)
https://github.com/vim/vim/commit/c3c3158756ae074052b0db2a3e3a7ba192df5330
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r-- | src/nvim/edit.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 667bc54e2e..aae63c0490 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -5486,16 +5486,33 @@ internal_format ( /* remember position of blank just before text */ end_col = curwin->w_cursor.col; - /* find start of sequence of blanks */ + // find start of sequence of blanks + int wcc = 0; // counter for whitespace chars while (curwin->w_cursor.col > 0 && WHITECHAR(cc)) { dec_cursor(); cc = gchar_cursor(); + + // Increment count of how many whitespace chars in this + // group; we only need to know if it's more than one. + if (wcc < 2) { + wcc++; + } } - if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) - break; /* only spaces in front of text */ - /* Don't break until after the comment leader */ - if (curwin->w_cursor.col < leader_len) + if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) { + break; // only spaces in front of text + } + + // Don't break after a period when 'formatoptions' has 'p' and + // there are less than two spaces. + if (has_format_option(FO_PERIOD_ABBR) && cc == '.' && wcc < 2) { + continue; + } + + // Don't break until after the comment leader + if (curwin->w_cursor.col < leader_len) { break; + } + if (has_format_option(FO_ONE_LETTER)) { /* do not break after one-letter words */ if (curwin->w_cursor.col == 0) |