@@ -274,9 +274,9 @@ readfile(
274274 int msg_save = msg_scroll ;
275275 linenr_T read_no_eol_lnum = 0 ; /* non-zero lnum when last line of
276276 * last read was missing the eol */
277- int try_mac = ( vim_strchr ( p_ffs , 'm' ) != NULL ) ;
278- int try_dos = ( vim_strchr ( p_ffs , 'd' ) != NULL ) ;
279- int try_unix = ( vim_strchr ( p_ffs , 'x' ) != NULL ) ;
277+ int try_mac ;
278+ int try_dos ;
279+ int try_unix ;
280280 int file_rewind = FALSE;
281281#ifdef FEAT_MBYTE
282282 int can_retry ;
@@ -738,6 +738,10 @@ readfile(
738738 curbuf -> b_op_start .lnum = ((from == 0 ) ? 1 : from );
739739 curbuf -> b_op_start .col = 0 ;
740740
741+ try_mac = (vim_strchr (p_ffs , 'm' ) != NULL );
742+ try_dos = (vim_strchr (p_ffs , 'd' ) != NULL );
743+ try_unix = (vim_strchr (p_ffs , 'x' ) != NULL );
744+
741745#ifdef FEAT_AUTOCMD
742746 if (!read_buffer )
743747 {
@@ -769,6 +773,11 @@ readfile(
769773 else
770774 apply_autocmds_exarg (EVENT_FILEREADPRE , sfname , sfname ,
771775 FALSE, NULL , eap );
776+ /* autocommands may have changed it */
777+ try_mac = (vim_strchr (p_ffs , 'm' ) != NULL );
778+ try_dos = (vim_strchr (p_ffs , 'd' ) != NULL );
779+ try_unix = (vim_strchr (p_ffs , 'x' ) != NULL );
780+
772781 if (msg_scrolled == n )
773782 msg_scroll = m ;
774783
@@ -2242,8 +2251,9 @@ readfile(
22422251 len = (colnr_T )(ptr - line_start + 1 );
22432252 if (fileformat == EOL_DOS )
22442253 {
2245- if (ptr [-1 ] == CAR ) /* remove CR */
2254+ if (ptr > line_start && ptr [-1 ] == CAR )
22462255 {
2256+ /* remove CR before NL */
22472257 ptr [-1 ] = NUL ;
22482258 -- len ;
22492259 }
0 commit comments