summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <bram@vim.org>2015-03-08 14:48:49 +0100
committerBram Moolenaar <bram@vim.org>2015-03-08 14:48:49 +0100
commitf55c9d512cfb1f30c68f9107a95fcd4187182d25 (patch)
tree2551d264b24d3d879545746aa20ebaf0a08b9e2a
parent668eea4fc849d4b0320bf93c3646175aeb0419df (diff)
downloadvim-7.4.658.tar.gz
updated for version 7.4.658v7.4.658v7-4-658
Problem: 'formatexpr' is evaluated too often. Solution: Only invoke it when beyond the 'textwidth' column, as it is documented. (James McCoy)
-rw-r--r--src/edit.c12
-rw-r--r--src/version.c2
2 files changed, 10 insertions, 4 deletions
diff --git a/src/edit.c b/src/edit.c
index e8563cb2..48e4b131 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -5879,8 +5879,9 @@ insertchar(c, flags, second_indent)
char_u *p;
#endif
int fo_ins_blank;
+ int force_format = flags & INSCHAR_FORMAT;
- textwidth = comp_textwidth(flags & INSCHAR_FORMAT);
+ textwidth = comp_textwidth(force_format);
fo_ins_blank = has_format_option(FO_INS_BLANK);
/*
@@ -5899,7 +5900,7 @@ insertchar(c, flags, second_indent)
* before 'textwidth'
*/
if (textwidth > 0
- && ((flags & INSCHAR_FORMAT)
+ && (force_format
|| (!vim_iswhite(c)
&& !((State & REPLACE_FLAG)
#ifdef FEAT_VREPLACE
@@ -5916,9 +5917,12 @@ insertchar(c, flags, second_indent)
/* Format with 'formatexpr' when it's set. Use internal formatting
* when 'formatexpr' isn't set or it returns non-zero. */
#if defined(FEAT_EVAL)
- int do_internal = TRUE;
+ int do_internal = TRUE;
+ colnr_T virtcol = get_nolist_virtcol()
+ + char2cells(c != NUL ? c : gchar_cursor());
- if (*curbuf->b_p_fex != NUL && (flags & INSCHAR_NO_FEX) == 0)
+ if (*curbuf->b_p_fex != NUL && (flags & INSCHAR_NO_FEX) == 0
+ && (force_format || virtcol > (colnr_T)textwidth))
{
do_internal = (fex_format(curwin->w_cursor.lnum, 1L, c) != 0);
/* It may be required to save for undo again, e.g. when setline()
diff --git a/src/version.c b/src/version.c
index 0e39cfbf..6e579e0c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 658,
+/**/
657,
/**/
656,