3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.396
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.396
3ef2ca
Problem:    When 'clipboard' is "unnamed", :g/pat/d is very slow. (Praful)
3ef2ca
Solution:   Only set the clipboard after the last delete. (Christian Brabandt)
3ef2ca
Files:	    src/ex_cmds.c, src/ex_cmds2.c, src/ex_docmd.c, src/globals.h,
3ef2ca
	    src/ops.c, src/proto/ui.pro, src/ui.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.395/src/ex_cmds.c	2014-07-09 21:17:59.755550204 +0200
3ef2ca
--- src/ex_cmds.c	2014-08-06 18:06:37.931152276 +0200
3ef2ca
***************
3ef2ca
*** 5514,5520 ****
3ef2ca
--- 5514,5528 ----
3ef2ca
  	    smsg((char_u *)_("Pattern not found: %s"), pat);
3ef2ca
      }
3ef2ca
      else
3ef2ca
+     {
3ef2ca
+ #ifdef FEAT_CLIPBOARD
3ef2ca
+ 	start_global_changes();
3ef2ca
+ #endif
3ef2ca
  	global_exe(cmd);
3ef2ca
+ #ifdef FEAT_CLIPBOARD
3ef2ca
+ 	end_global_changes();
3ef2ca
+ #endif
3ef2ca
+     }
3ef2ca
  
3ef2ca
      ml_clearmarked();	   /* clear rest of the marks */
3ef2ca
      vim_regfree(regmatch.regprog);
3ef2ca
*** ../vim-7.4.395/src/ex_cmds2.c	2014-04-05 19:44:36.903160723 +0200
3ef2ca
--- src/ex_cmds2.c	2014-08-06 18:05:07.563152926 +0200
3ef2ca
***************
3ef2ca
*** 2464,2469 ****
3ef2ca
--- 2464,2472 ----
3ef2ca
  	 * great speed improvement. */
3ef2ca
  	save_ei = au_event_disable(",Syntax");
3ef2ca
  #endif
3ef2ca
+ #ifdef FEAT_CLIPBOARD
3ef2ca
+     start_global_changes();
3ef2ca
+ #endif
3ef2ca
  
3ef2ca
      if (eap->cmdidx == CMD_windo
3ef2ca
  	    || eap->cmdidx == CMD_tabdo
3ef2ca
***************
3ef2ca
*** 2591,2596 ****
3ef2ca
--- 2594,2602 ----
3ef2ca
  					       curbuf->b_fname, TRUE, curbuf);
3ef2ca
      }
3ef2ca
  #endif
3ef2ca
+ #ifdef FEAT_CLIPBOARD
3ef2ca
+     end_global_changes();
3ef2ca
+ #endif
3ef2ca
  }
3ef2ca
  
3ef2ca
  /*
3ef2ca
***************
3ef2ca
*** 2750,2757 ****
3ef2ca
   * used.
3ef2ca
   * Returns OK when at least one match found, FAIL otherwise.
3ef2ca
   *
3ef2ca
!  * If "name" is NULL calls callback for each entry in runtimepath. Cookie is 
3ef2ca
!  * passed by reference in this case, setting it to NULL indicates that callback 
3ef2ca
   * has done its job.
3ef2ca
   */
3ef2ca
      int
3ef2ca
--- 2756,2763 ----
3ef2ca
   * used.
3ef2ca
   * Returns OK when at least one match found, FAIL otherwise.
3ef2ca
   *
3ef2ca
!  * If "name" is NULL calls callback for each entry in runtimepath. Cookie is
3ef2ca
!  * passed by reference in this case, setting it to NULL indicates that callback
3ef2ca
   * has done its job.
3ef2ca
   */
3ef2ca
      int
3ef2ca
*** ../vim-7.4.395/src/ex_docmd.c	2014-06-17 17:48:21.780628008 +0200
3ef2ca
--- src/ex_docmd.c	2014-08-06 18:05:07.563152926 +0200
3ef2ca
***************
3ef2ca
*** 11534,11539 ****
3ef2ca
--- 11534,11543 ----
3ef2ca
  {
3ef2ca
      linenr_T	lnum;
3ef2ca
  
3ef2ca
+ #ifdef FEAT_CLIPBOARD
3ef2ca
+     start_global_changes();
3ef2ca
+ #endif
3ef2ca
+ 
3ef2ca
      /* First set the marks for all lines closed/open. */
3ef2ca
      for (lnum = eap->line1; lnum <= eap->line2; ++lnum)
3ef2ca
  	if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed))
3ef2ca
***************
3ef2ca
*** 11542,11546 ****
3ef2ca
--- 11546,11553 ----
3ef2ca
      /* Execute the command on the marked lines. */
3ef2ca
      global_exe(eap->arg);
3ef2ca
      ml_clearmarked();	   /* clear rest of the marks */
3ef2ca
+ #ifdef FEAT_CLIPBOARD
3ef2ca
+     end_global_changes();
3ef2ca
+ #endif
3ef2ca
  }
3ef2ca
  #endif
3ef2ca
*** ../vim-7.4.395/src/globals.h	2014-07-30 17:21:53.815518506 +0200
3ef2ca
--- src/globals.h	2014-08-06 18:05:07.563152926 +0200
3ef2ca
***************
3ef2ca
*** 533,538 ****
3ef2ca
--- 533,540 ----
3ef2ca
  EXTERN int	clip_autoselectml INIT(= FALSE);
3ef2ca
  EXTERN int	clip_html INIT(= FALSE);
3ef2ca
  EXTERN regprog_T *clip_exclude_prog INIT(= NULL);
3ef2ca
+ EXTERN int	clip_did_set_selection INIT(= TRUE);
3ef2ca
+ EXTERN int	clip_unnamed_saved INIT(= 0);
3ef2ca
  #endif
3ef2ca
  
3ef2ca
  /*
3ef2ca
*** ../vim-7.4.395/src/ops.c	2014-06-25 14:39:35.106348584 +0200
3ef2ca
--- src/ops.c	2014-08-06 18:05:07.563152926 +0200
3ef2ca
***************
3ef2ca
*** 1597,1605 ****
3ef2ca
  {
3ef2ca
      /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard',
3ef2ca
       * use '*' or '+' reg, respectively. "unnamedplus" prevails. */
3ef2ca
!     if (*rp == 0 && clip_unnamed != 0)
3ef2ca
! 	*rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available)
3ef2ca
  								  ? '+' : '*';
3ef2ca
      if (!clip_star.available && *rp == '*')
3ef2ca
  	*rp = 0;
3ef2ca
      if (!clip_plus.available && *rp == '+')
3ef2ca
--- 1597,1611 ----
3ef2ca
  {
3ef2ca
      /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard',
3ef2ca
       * use '*' or '+' reg, respectively. "unnamedplus" prevails. */
3ef2ca
!     if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0))
3ef2ca
!     {
3ef2ca
! 	if (clip_unnamed != 0)
3ef2ca
! 	    *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available)
3ef2ca
! 								  ? '+' : '*';
3ef2ca
! 	else
3ef2ca
! 	    *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available)
3ef2ca
  								  ? '+' : '*';
3ef2ca
+     }
3ef2ca
      if (!clip_star.available && *rp == '*')
3ef2ca
  	*rp = 0;
3ef2ca
      if (!clip_plus.available && *rp == '+')
3ef2ca
***************
3ef2ca
*** 3203,3209 ****
3ef2ca
      if (clip_star.available
3ef2ca
  	    && (curr == &(y_regs[STAR_REGISTER])
3ef2ca
  		|| (!deleting && oap->regname == 0
3ef2ca
! 					   && (clip_unnamed & CLIP_UNNAMED))))
3ef2ca
      {
3ef2ca
  	if (curr != &(y_regs[STAR_REGISTER]))
3ef2ca
  	    /* Copy the text from register 0 to the clipboard register. */
3ef2ca
--- 3209,3215 ----
3ef2ca
      if (clip_star.available
3ef2ca
  	    && (curr == &(y_regs[STAR_REGISTER])
3ef2ca
  		|| (!deleting && oap->regname == 0
3ef2ca
! 		   && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED))))
3ef2ca
      {
3ef2ca
  	if (curr != &(y_regs[STAR_REGISTER]))
3ef2ca
  	    /* Copy the text from register 0 to the clipboard register. */
3ef2ca
***************
3ef2ca
*** 3224,3230 ****
3ef2ca
      if (clip_plus.available
3ef2ca
  	    && (curr == &(y_regs[PLUS_REGISTER])
3ef2ca
  		|| (!deleting && oap->regname == 0
3ef2ca
! 				      && (clip_unnamed & CLIP_UNNAMED_PLUS))))
3ef2ca
      {
3ef2ca
  	if (curr != &(y_regs[PLUS_REGISTER]))
3ef2ca
  	    /* Copy the text from register 0 to the clipboard register. */
3ef2ca
--- 3230,3237 ----
3ef2ca
      if (clip_plus.available
3ef2ca
  	    && (curr == &(y_regs[PLUS_REGISTER])
3ef2ca
  		|| (!deleting && oap->regname == 0
3ef2ca
! 		  && ((clip_unnamed | clip_unnamed_saved) &
3ef2ca
! 		      CLIP_UNNAMED_PLUS))))
3ef2ca
      {
3ef2ca
  	if (curr != &(y_regs[PLUS_REGISTER]))
3ef2ca
  	    /* Copy the text from register 0 to the clipboard register. */
3ef2ca
*** ../vim-7.4.395/src/proto/ui.pro	2013-08-10 13:37:29.000000000 +0200
3ef2ca
--- src/proto/ui.pro	2014-08-06 18:05:07.563152926 +0200
3ef2ca
***************
3ef2ca
*** 14,19 ****
3ef2ca
--- 14,21 ----
3ef2ca
  void clip_update_selection __ARGS((VimClipboard *clip));
3ef2ca
  void clip_own_selection __ARGS((VimClipboard *cbd));
3ef2ca
  void clip_lose_selection __ARGS((VimClipboard *cbd));
3ef2ca
+ void start_global_changes __ARGS((void));
3ef2ca
+ void end_global_changes __ARGS((void));
3ef2ca
  void clip_auto_select __ARGS((void));
3ef2ca
  int clip_isautosel_star __ARGS((void));
3ef2ca
  int clip_isautosel_plus __ARGS((void));
3ef2ca
*** ../vim-7.4.395/src/ui.c	2014-06-25 14:39:35.114348584 +0200
3ef2ca
--- src/ui.c	2014-08-06 18:13:13.475149434 +0200
3ef2ca
***************
3ef2ca
*** 558,563 ****
3ef2ca
--- 558,608 ----
3ef2ca
  }
3ef2ca
  
3ef2ca
  /*
3ef2ca
+  * Save and restore clip_unnamed before doing possibly many changes. This
3ef2ca
+  * prevents accessing the clipboard very often which might slow down Vim
3ef2ca
+  * considerably.
3ef2ca
+  */
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
+  * Save clip_unnamed and reset it.
3ef2ca
+  */
3ef2ca
+     void
3ef2ca
+ start_global_changes()
3ef2ca
+ {
3ef2ca
+     clip_unnamed_saved = clip_unnamed;
3ef2ca
+ 
3ef2ca
+     if (clip_did_set_selection)
3ef2ca
+     {
3ef2ca
+ 	clip_unnamed = FALSE;
3ef2ca
+ 	clip_did_set_selection = FALSE;
3ef2ca
+     }
3ef2ca
+ }
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
+  * Restore clip_unnamed and set the selection when needed.
3ef2ca
+  */
3ef2ca
+     void
3ef2ca
+ end_global_changes()
3ef2ca
+ {
3ef2ca
+     if (!clip_did_set_selection)
3ef2ca
+     {
3ef2ca
+ 	clip_did_set_selection = TRUE;
3ef2ca
+ 	clip_unnamed = clip_unnamed_saved;
3ef2ca
+ 	if (clip_unnamed & CLIP_UNNAMED)
3ef2ca
+ 	{
3ef2ca
+ 	    clip_own_selection(&clip_star);
3ef2ca
+ 	    clip_gen_set_selection(&clip_star);
3ef2ca
+ 	}
3ef2ca
+ 	if (clip_unnamed & CLIP_UNNAMED_PLUS)
3ef2ca
+ 	{
3ef2ca
+ 	    clip_own_selection(&clip_plus);
3ef2ca
+ 	    clip_gen_set_selection(&clip_plus);
3ef2ca
+ 	}
3ef2ca
+     }
3ef2ca
+     clip_unnamed_saved = FALSE;
3ef2ca
+ }
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
   * Called when Visual mode is ended: update the selection.
3ef2ca
   */
3ef2ca
      void
3ef2ca
***************
3ef2ca
*** 1428,1433 ****
3ef2ca
--- 1473,1487 ----
3ef2ca
  clip_gen_set_selection(cbd)
3ef2ca
      VimClipboard	*cbd;
3ef2ca
  {
3ef2ca
+     if (!clip_did_set_selection)
3ef2ca
+     {
3ef2ca
+ 	/* Updating postponed, so that accessing the system clipboard won't
3ef2ca
+ 	 * hang Vim when accessing it many times (e.g. on a :g comand). */
3ef2ca
+ 	if (cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS))
3ef2ca
+ 	    return;
3ef2ca
+ 	else if (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED))
3ef2ca
+ 	    return;
3ef2ca
+     }
3ef2ca
  #ifdef FEAT_XCLIPBOARD
3ef2ca
  # ifdef FEAT_GUI
3ef2ca
      if (gui.in_use)
3ef2ca
*** ../vim-7.4.395/src/version.c	2014-08-06 17:44:09.867161966 +0200
3ef2ca
--- src/version.c	2014-08-06 18:04:47.359153071 +0200
3ef2ca
***************
3ef2ca
*** 743,744 ****
3ef2ca
--- 743,746 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     396,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
You have heard the saying that if you put a thousand monkeys in a room with a
3ef2ca
thousand typewriters and waited long enough, eventually you would have a room
3ef2ca
full of dead monkeys.
3ef2ca
				(Scott Adams - The Dilbert principle)
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///