lkundrak / rpms / vim

Forked from rpms/vim 4 years ago
Clone
b96ca66
To: vim_dev@googlegroups.com
b96ca66
Subject: Patch 7.3.124
b96ca66
Fcc: outbox
b96ca66
From: Bram Moolenaar <Bram@moolenaar.net>
b96ca66
Mime-Version: 1.0
b96ca66
Content-Type: text/plain; charset=UTF-8
b96ca66
Content-Transfer-Encoding: 8bit
b96ca66
------------
b96ca66
b96ca66
Patch 7.3.124
b96ca66
Problem:    When writing a file in binary mode it may be missing the final EOL
b96ca66
	    if a file previously read was missing the EOL. (Kevin Goodsell)
b96ca66
Solution:   Move the write_no_eol_lnum into the buffer struct.
b96ca66
Files:	    src/structs.h, src/fileio.c, src/globals.h, src/os_unix.c
b96ca66
b96ca66
b96ca66
*** ../vim-7.3.123/src/structs.h	2010-10-20 21:22:17.000000000 +0200
b96ca66
--- src/structs.h	2011-02-15 17:06:34.000000000 +0100
b96ca66
***************
b96ca66
*** 1564,1569 ****
b96ca66
--- 1564,1572 ----
b96ca66
  
b96ca66
      /* end of buffer options */
b96ca66
  
b96ca66
+     linenr_T	b_no_eol_lnum;	/* non-zero lnum when last line of next binary
b96ca66
+ 				 * write should not have an end-of-line */
b96ca66
+ 
b96ca66
      int		b_start_eol;	/* last line had eol when it was read */
b96ca66
      int		b_start_ffc;	/* first char of 'ff' when edit started */
b96ca66
  #ifdef FEAT_MBYTE
b96ca66
*** ../vim-7.3.123/src/fileio.c	2011-02-09 16:44:45.000000000 +0100
b96ca66
--- src/fileio.c	2011-02-15 17:30:54.000000000 +0100
b96ca66
***************
b96ca66
*** 317,323 ****
b96ca66
      int		using_b_fname;
b96ca66
  #endif
b96ca66
  
b96ca66
!     write_no_eol_lnum = 0;	/* in case it was set by the previous read */
b96ca66
  
b96ca66
      /*
b96ca66
       * If there is no file name yet, use the one for the read file.
b96ca66
--- 317,323 ----
b96ca66
      int		using_b_fname;
b96ca66
  #endif
b96ca66
  
b96ca66
!     curbuf->b_no_eol_lnum = 0;	/* in case it was set by the previous read */
b96ca66
  
b96ca66
      /*
b96ca66
       * If there is no file name yet, use the one for the read file.
b96ca66
***************
b96ca66
*** 2599,2608 ****
b96ca66
  
b96ca66
      /*
b96ca66
       * Trick: We remember if the last line of the read didn't have
b96ca66
!      * an eol for when writing it again.  This is required for
b96ca66
       * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
b96ca66
       */
b96ca66
!     write_no_eol_lnum = read_no_eol_lnum;
b96ca66
  
b96ca66
      /* When reloading a buffer put the cursor at the first line that is
b96ca66
       * different. */
b96ca66
--- 2599,2609 ----
b96ca66
  
b96ca66
      /*
b96ca66
       * Trick: We remember if the last line of the read didn't have
b96ca66
!      * an eol even when 'binary' is off, for when writing it again with
b96ca66
!      * 'binary' on.  This is required for
b96ca66
       * ":autocmd FileReadPost *.gz set bin|'[,']!gunzip" to work.
b96ca66
       */
b96ca66
!     curbuf->b_no_eol_lnum = read_no_eol_lnum;
b96ca66
  
b96ca66
      /* When reloading a buffer put the cursor at the first line that is
b96ca66
       * different. */
b96ca66
***************
b96ca66
*** 2650,2662 ****
b96ca66
  							    FALSE, NULL, eap);
b96ca66
  	if (msg_scrolled == n)
b96ca66
  	    msg_scroll = m;
b96ca66
! #ifdef FEAT_EVAL
b96ca66
  	if (aborting())	    /* autocmds may abort script processing */
b96ca66
  	    return FAIL;
b96ca66
! #endif
b96ca66
      }
b96ca66
  #endif
b96ca66
  
b96ca66
      if (recoverymode && error)
b96ca66
  	return FAIL;
b96ca66
      return OK;
b96ca66
--- 2651,2667 ----
b96ca66
  							    FALSE, NULL, eap);
b96ca66
  	if (msg_scrolled == n)
b96ca66
  	    msg_scroll = m;
b96ca66
! # ifdef FEAT_EVAL
b96ca66
  	if (aborting())	    /* autocmds may abort script processing */
b96ca66
  	    return FAIL;
b96ca66
! # endif
b96ca66
      }
b96ca66
  #endif
b96ca66
  
b96ca66
+     /* Reset now, following writes should not omit the EOL.  Also, the line
b96ca66
+      * number will become invalid because of edits. */
b96ca66
+     curbuf->b_no_eol_lnum = 0;
b96ca66
+ 
b96ca66
      if (recoverymode && error)
b96ca66
  	return FAIL;
b96ca66
      return OK;
b96ca66
***************
b96ca66
*** 4560,4566 ****
b96ca66
  	if (end == 0
b96ca66
  		|| (lnum == end
b96ca66
  		    && write_bin
b96ca66
! 		    && (lnum == write_no_eol_lnum
b96ca66
  			|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
b96ca66
  	{
b96ca66
  	    ++lnum;			/* written the line, count it */
b96ca66
--- 4565,4571 ----
b96ca66
  	if (end == 0
b96ca66
  		|| (lnum == end
b96ca66
  		    && write_bin
b96ca66
! 		    && (lnum == buf->b_no_eol_lnum
b96ca66
  			|| (lnum == buf->b_ml.ml_line_count && !buf->b_p_eol))))
b96ca66
  	{
b96ca66
  	    ++lnum;			/* written the line, count it */
b96ca66
***************
b96ca66
*** 5086,5093 ****
b96ca66
      {
b96ca66
  	aco_save_T	aco;
b96ca66
  
b96ca66
- 	write_no_eol_lnum = 0;	/* in case it was set by the previous read */
b96ca66
- 
b96ca66
  	/*
b96ca66
  	 * Apply POST autocommands.
b96ca66
  	 * Careful: The autocommands may call buf_write() recursively!
b96ca66
--- 5091,5096 ----
b96ca66
***************
b96ca66
*** 7256,7263 ****
b96ca66
  write_lnum_adjust(offset)
b96ca66
      linenr_T	offset;
b96ca66
  {
b96ca66
!     if (write_no_eol_lnum != 0)		/* only if there is a missing eol */
b96ca66
! 	write_no_eol_lnum += offset;
b96ca66
  }
b96ca66
  
b96ca66
  #if defined(TEMPDIRNAMES) || defined(PROTO)
b96ca66
--- 7259,7266 ----
b96ca66
  write_lnum_adjust(offset)
b96ca66
      linenr_T	offset;
b96ca66
  {
b96ca66
!     if (curbuf->b_no_eol_lnum != 0)	/* only if there is a missing eol */
b96ca66
! 	curbuf->b_no_eol_lnum += offset;
b96ca66
  }
b96ca66
  
b96ca66
  #if defined(TEMPDIRNAMES) || defined(PROTO)
b96ca66
*** ../vim-7.3.123/src/globals.h	2010-12-02 21:43:10.000000000 +0100
b96ca66
--- src/globals.h	2011-02-15 17:06:06.000000000 +0100
b96ca66
***************
b96ca66
*** 1057,1066 ****
b96ca66
  			;
b96ca66
  #endif
b96ca66
  
b96ca66
- EXTERN linenr_T	write_no_eol_lnum INIT(= 0); /* non-zero lnum when last line
b96ca66
- 						of next binary write should
b96ca66
- 						not have an end-of-line */
b96ca66
- 
b96ca66
  #ifdef FEAT_WINDOWS
b96ca66
  EXTERN int	postponed_split INIT(= 0);  /* for CTRL-W CTRL-] command */
b96ca66
  EXTERN int	postponed_split_flags INIT(= 0);  /* args for win_split() */
b96ca66
--- 1057,1062 ----
b96ca66
*** ../vim-7.3.123/src/os_unix.c	2011-02-09 18:47:36.000000000 +0100
b96ca66
--- src/os_unix.c	2011-02-15 17:07:22.000000000 +0100
b96ca66
***************
b96ca66
*** 4245,4251 ****
b96ca66
  				 * should not have one. */
b96ca66
  				if (lnum != curbuf->b_op_end.lnum
b96ca66
  					|| !curbuf->b_p_bin
b96ca66
! 					|| (lnum != write_no_eol_lnum
b96ca66
  					    && (lnum !=
b96ca66
  						    curbuf->b_ml.ml_line_count
b96ca66
  						    || curbuf->b_p_eol)))
b96ca66
--- 4245,4251 ----
b96ca66
  				 * should not have one. */
b96ca66
  				if (lnum != curbuf->b_op_end.lnum
b96ca66
  					|| !curbuf->b_p_bin
b96ca66
! 					|| (lnum != curbuf->b_no_eol_lnum
b96ca66
  					    && (lnum !=
b96ca66
  						    curbuf->b_ml.ml_line_count
b96ca66
  						    || curbuf->b_p_eol)))
b96ca66
***************
b96ca66
*** 4588,4597 ****
b96ca66
  		    {
b96ca66
  			append_ga_line(&ga);
b96ca66
  			/* remember that the NL was missing */
b96ca66
! 			write_no_eol_lnum = curwin->w_cursor.lnum;
b96ca66
  		    }
b96ca66
  		    else
b96ca66
! 			write_no_eol_lnum = 0;
b96ca66
  		    ga_clear(&ga);
b96ca66
  		}
b96ca66
  
b96ca66
--- 4588,4597 ----
b96ca66
  		    {
b96ca66
  			append_ga_line(&ga);
b96ca66
  			/* remember that the NL was missing */
b96ca66
! 			curbuf->b_no_eol_lnum = curwin->w_cursor.lnum;
b96ca66
  		    }
b96ca66
  		    else
b96ca66
! 			curbuf->b_no_eol_lnum = 0;
b96ca66
  		    ga_clear(&ga);
b96ca66
  		}
b96ca66
  
b96ca66
*** ../vim-7.3.123/src/version.c	2011-02-15 16:29:54.000000000 +0100
b96ca66
--- src/version.c	2011-02-15 17:37:38.000000000 +0100
b96ca66
***************
b96ca66
*** 716,717 ****
b96ca66
--- 716,719 ----
b96ca66
  {   /* Add new patch number below this line */
b96ca66
+ /**/
b96ca66
+     124,
b96ca66
  /**/
b96ca66
b96ca66
-- 
b96ca66
hundred-and-one symptoms of being an internet addict:
b96ca66
270. You are subscribed to a mailing list for every piece of software
b96ca66
     you use.
b96ca66
b96ca66
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
b96ca66
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
b96ca66
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
b96ca66
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///