forked from aniani/vim
		
	patch 8.1.0728: cannot avoid breaking after a single space.
Problem: Cannot avoid breaking after a single space. Solution: Add the 'p' flag to 'formatoptions'. (Tom Ryder)
This commit is contained in:
		| @@ -1720,6 +1720,17 @@ j	Where it makes sense, remove a comment leader when joining lines.  For | |||||||
| 		         // in the list ~ | 		         // in the list ~ | ||||||
| 	Becomes: | 	Becomes: | ||||||
| 		int i;   // the index in the list ~ | 		int i;   // the index in the list ~ | ||||||
|  | p	Don't break lines at single spaces that follow periods.  This is | ||||||
|  | 	intended to complement 'joinspaces' and |cpo-J|, for prose with | ||||||
|  | 	sentences separated by two spaces.  For example, with 'textwidth' set | ||||||
|  | 	to 28: > | ||||||
|  | 		Surely you're joking, Mr. Feynman! | ||||||
|  | <	Becomes: > | ||||||
|  | 		Surely you're joking, | ||||||
|  | 		Mr. Feynman! | ||||||
|  | <	Instead of: > | ||||||
|  | 		Surely you're joking, Mr. | ||||||
|  | 		Feynman! | ||||||
|  |  | ||||||
|  |  | ||||||
| With 't' and 'c' you can specify when Vim performs auto-wrapping: | With 't' and 'c' you can specify when Vim performs auto-wrapping: | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								src/edit.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/edit.c
									
									
									
									
									
								
							| @@ -6498,6 +6498,7 @@ internal_format( | |||||||
| 	char_u	*saved_text = NULL; | 	char_u	*saved_text = NULL; | ||||||
| 	colnr_T	col; | 	colnr_T	col; | ||||||
| 	colnr_T	end_col; | 	colnr_T	end_col; | ||||||
|  | 	int	wcc;			// counter for whitespace chars | ||||||
|  |  | ||||||
| 	virtcol = get_nolist_virtcol() | 	virtcol = get_nolist_virtcol() | ||||||
| 		+ char2cells(c != NUL ? c : gchar_cursor()); | 		+ char2cells(c != NUL ? c : gchar_cursor()); | ||||||
| @@ -6559,14 +6560,26 @@ internal_format( | |||||||
| 		/* remember position of blank just before text */ | 		/* remember position of blank just before text */ | ||||||
| 		end_col = curwin->w_cursor.col; | 		end_col = curwin->w_cursor.col; | ||||||
|  |  | ||||||
| 		/* find start of sequence of blanks */ | 		// find start of sequence of blanks | ||||||
|  | 		wcc = 0; | ||||||
| 		while (curwin->w_cursor.col > 0 && WHITECHAR(cc)) | 		while (curwin->w_cursor.col > 0 && WHITECHAR(cc)) | ||||||
| 		{ | 		{ | ||||||
| 		    dec_cursor(); | 		    dec_cursor(); | ||||||
| 		    cc = gchar_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)) | 		if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) | ||||||
| 		    break;		/* only spaces in front of text */ | 		    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; | ||||||
|  |  | ||||||
| #ifdef FEAT_COMMENTS | #ifdef FEAT_COMMENTS | ||||||
| 		/* Don't break until after the comment leader */ | 		/* Don't break until after the comment leader */ | ||||||
| 		if (curwin->w_cursor.col < leader_len) | 		if (curwin->w_cursor.col < leader_len) | ||||||
|   | |||||||
| @@ -101,10 +101,11 @@ | |||||||
| #define FO_WHITE_PAR	'w'	/* trailing white space continues paragr. */ | #define FO_WHITE_PAR	'w'	/* trailing white space continues paragr. */ | ||||||
| #define FO_AUTO		'a'	/* automatic formatting */ | #define FO_AUTO		'a'	/* automatic formatting */ | ||||||
| #define FO_REMOVE_COMS	'j'	/* remove comment leaders when joining lines */ | #define FO_REMOVE_COMS	'j'	/* remove comment leaders when joining lines */ | ||||||
|  | #define FO_PERIOD_ABBR	'p'	/* don't break a single space after a period */ | ||||||
|  |  | ||||||
| #define DFLT_FO_VI	"vt" | #define DFLT_FO_VI	"vt" | ||||||
| #define DFLT_FO_VIM	"tcq" | #define DFLT_FO_VIM	"tcq" | ||||||
| #define FO_ALL		"tcroq2vlb1mMBn,awj"	/* for do_set() */ | #define FO_ALL		"tcroq2vlb1mMBn,awjp"	/* for do_set() */ | ||||||
|  |  | ||||||
| /* characters for the p_cpo option: */ | /* characters for the p_cpo option: */ | ||||||
| #define CPO_ALTREAD	'a'	/* ":read" sets alternate file name */ | #define CPO_ALTREAD	'a'	/* ":read" sets alternate file name */ | ||||||
|   | |||||||
| @@ -163,6 +163,32 @@ func Test_text_format() | |||||||
| 	      \ '# 1 xxxxx', | 	      \ '# 1 xxxxx', | ||||||
| 	      \ '#   foobar'], getline(1, 2)) | 	      \ '#   foobar'], getline(1, 2)) | ||||||
|  |  | ||||||
|  |   " Test the 'p' flag for 'formatoptions' | ||||||
|  |   " First test without the flag: that it will break "Mr. Feynman" at the space | ||||||
|  |   normal ggdG | ||||||
|  |   setl tw=28 fo=tcq | ||||||
|  |   call setline('.', 'Surely you''re joking, Mr. Feynman!') | ||||||
|  |   normal gqq | ||||||
|  |   call assert_equal([ | ||||||
|  |               \ 'Surely you''re joking, Mr.', | ||||||
|  |               \ 'Feynman!'], getline(1, 2)) | ||||||
|  |   " Now test with the flag: that it will push the name with the title onto the | ||||||
|  |   " next line | ||||||
|  |   normal ggdG | ||||||
|  |   setl fo+=p | ||||||
|  |   call setline('.', 'Surely you''re joking, Mr. Feynman!') | ||||||
|  |   normal gqq | ||||||
|  |   call assert_equal([ | ||||||
|  |               \ 'Surely you''re joking,', | ||||||
|  |               \ 'Mr. Feynman!'], getline(1, 2)) | ||||||
|  |   " Ensure that it will still break if two spaces are entered | ||||||
|  |   normal ggdG | ||||||
|  |   call setline('.', 'Surely you''re joking, Mr.  Feynman!') | ||||||
|  |   normal gqq | ||||||
|  |   call assert_equal([ | ||||||
|  |               \ 'Surely you''re joking, Mr.', | ||||||
|  |               \ 'Feynman!'], getline(1, 2)) | ||||||
|  |  | ||||||
|   setl ai& tw& fo& si& comments& |   setl ai& tw& fo& si& comments& | ||||||
|   enew! |   enew! | ||||||
| endfunc | endfunc | ||||||
|   | |||||||
| @@ -795,6 +795,8 @@ static char *(features[]) = | |||||||
|  |  | ||||||
| static int included_patches[] = | static int included_patches[] = | ||||||
| {   /* Add new patch number below this line */ | {   /* Add new patch number below this line */ | ||||||
|  | /**/ | ||||||
|  |     728, | ||||||
| /**/ | /**/ | ||||||
|     727, |     727, | ||||||
| /**/ | /**/ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user