@@ -243,7 +243,6 @@ static void set_b0_dir_flag(ZERO_BL *b0p, buf_T *buf);
243243static void add_b0_fenc (ZERO_BL * b0p , buf_T * buf );
244244static time_t swapfile_info (char_u * );
245245static int recov_file_names (char_u * * , char_u * , int prepend_dot );
246- static int ml_append_int (buf_T * , linenr_T , char_u * , colnr_T , int , int );
247246static int ml_delete_int (buf_T * , linenr_T , int );
248247static char_u * findswapname (buf_T * , char_u * * , char_u * );
249248static void ml_flush_line (buf_T * );
@@ -2744,56 +2743,6 @@ add_text_props_for_append(
27442743 * tofree = new_line ;
27452744 * len = new_len ;
27462745}
2747- #endif
2748-
2749- /*
2750- * Append a line after lnum (may be 0 to insert a line in front of the file).
2751- * "line" does not need to be allocated, but can't be another line in a
2752- * buffer, unlocking may make it invalid.
2753- *
2754- * newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum
2755- * will be set for recovery
2756- * Check: The caller of this function should probably also call
2757- * appended_lines().
2758- *
2759- * return FAIL for failure, OK otherwise
2760- */
2761- int
2762- ml_append (
2763- linenr_T lnum , /* append after this line (can be 0) */
2764- char_u * line , /* text of the new line */
2765- colnr_T len , /* length of new line, including NUL, or 0 */
2766- int newfile ) /* flag, see above */
2767- {
2768- /* When starting up, we might still need to create the memfile */
2769- if (curbuf -> b_ml .ml_mfp == NULL && open_buffer (FALSE, NULL , 0 ) == FAIL )
2770- return FAIL ;
2771-
2772- if (curbuf -> b_ml .ml_line_lnum != 0 )
2773- ml_flush_line (curbuf );
2774- return ml_append_int (curbuf , lnum , line , len , newfile , FALSE);
2775- }
2776-
2777- #if defined(FEAT_SPELL ) || defined(FEAT_QUICKFIX ) || defined(PROTO )
2778- /*
2779- * Like ml_append() but for an arbitrary buffer. The buffer must already have
2780- * a memline.
2781- */
2782- int
2783- ml_append_buf (
2784- buf_T * buf ,
2785- linenr_T lnum , /* append after this line (can be 0) */
2786- char_u * line , /* text of the new line */
2787- colnr_T len , /* length of new line, including NUL, or 0 */
2788- int newfile ) /* flag, see above */
2789- {
2790- if (buf -> b_ml .ml_mfp == NULL )
2791- return FAIL ;
2792-
2793- if (buf -> b_ml .ml_line_lnum != 0 )
2794- ml_flush_line (buf );
2795- return ml_append_int (buf , lnum , line , len , newfile , FALSE);
2796- }
27972746#endif
27982747
27992748 static int
@@ -2834,14 +2783,6 @@ ml_append_int(
28342783 if (len == 0 )
28352784 len = (colnr_T )STRLEN (line ) + 1 ; // space needed for the text
28362785
2837- #ifdef FEAT_EVAL
2838- // When inserting above recorded changes: flush the changes before changing
2839- // the text. Then flush the cached line, it may become invalid.
2840- may_invoke_listeners (buf , lnum + 1 , lnum + 1 , 1 );
2841- if (curbuf -> b_ml .ml_line_lnum != 0 )
2842- ml_flush_line (curbuf );
2843- #endif
2844-
28452786#ifdef FEAT_TEXT_PROP
28462787 if (curbuf -> b_has_textprop && lnum > 0 )
28472788 // Add text properties that continue from the previous line.
@@ -3325,6 +3266,79 @@ ml_append_int(
33253266 return ret ;
33263267}
33273268
3269+ /*
3270+ * Flush any pending change and call ml_append_int()
3271+ */
3272+ static int
3273+ ml_append_flush (
3274+ buf_T * buf ,
3275+ linenr_T lnum , // append after this line (can be 0)
3276+ char_u * line , // text of the new line
3277+ colnr_T len , // length of line, including NUL, or 0
3278+ int newfile ) // flag, see above
3279+ {
3280+ if (lnum > buf -> b_ml .ml_line_count )
3281+ return FAIL ; // lnum out of range
3282+
3283+ if (buf -> b_ml .ml_line_lnum != 0 )
3284+ // This may also invoke ml_append_int().
3285+ ml_flush_line (buf );
3286+
3287+ #ifdef FEAT_EVAL
3288+ // When inserting above recorded changes: flush the changes before changing
3289+ // the text. Then flush the cached line, it may become invalid.
3290+ may_invoke_listeners (buf , lnum + 1 , lnum + 1 , 1 );
3291+ if (buf -> b_ml .ml_line_lnum != 0 )
3292+ ml_flush_line (buf );
3293+ #endif
3294+
3295+ return ml_append_int (buf , lnum , line , len , newfile , FALSE);
3296+ }
3297+
3298+ /*
3299+ * Append a line after lnum (may be 0 to insert a line in front of the file).
3300+ * "line" does not need to be allocated, but can't be another line in a
3301+ * buffer, unlocking may make it invalid.
3302+ *
3303+ * newfile: TRUE when starting to edit a new file, meaning that pe_old_lnum
3304+ * will be set for recovery
3305+ * Check: The caller of this function should probably also call
3306+ * appended_lines().
3307+ *
3308+ * return FAIL for failure, OK otherwise
3309+ */
3310+ int
3311+ ml_append (
3312+ linenr_T lnum , /* append after this line (can be 0) */
3313+ char_u * line , /* text of the new line */
3314+ colnr_T len , /* length of new line, including NUL, or 0 */
3315+ int newfile ) /* flag, see above */
3316+ {
3317+ /* When starting up, we might still need to create the memfile */
3318+ if (curbuf -> b_ml .ml_mfp == NULL && open_buffer (FALSE, NULL , 0 ) == FAIL )
3319+ return FAIL ;
3320+ return ml_append_flush (curbuf , lnum , line , len , newfile );
3321+ }
3322+
3323+ #if defined(FEAT_SPELL ) || defined(FEAT_QUICKFIX ) || defined(PROTO )
3324+ /*
3325+ * Like ml_append() but for an arbitrary buffer. The buffer must already have
3326+ * a memline.
3327+ */
3328+ int
3329+ ml_append_buf (
3330+ buf_T * buf ,
3331+ linenr_T lnum , /* append after this line (can be 0) */
3332+ char_u * line , /* text of the new line */
3333+ colnr_T len , /* length of new line, including NUL, or 0 */
3334+ int newfile ) /* flag, see above */
3335+ {
3336+ if (buf -> b_ml .ml_mfp == NULL )
3337+ return FAIL ;
3338+ return ml_append_flush (buf , lnum , line , len , newfile );
3339+ }
3340+ #endif
3341+
33283342/*
33293343 * Replace line lnum, with buffering, in current buffer.
33303344 *
0 commit comments