Karsten Hopp 6df853
To: vim-dev@vim.org
Karsten Hopp 6df853
Subject: Patch 7.2.334
Karsten Hopp 6df853
Fcc: outbox
Karsten Hopp 6df853
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6df853
Mime-Version: 1.0
Karsten Hopp 6df853
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6df853
Content-Transfer-Encoding: 8bit
Karsten Hopp 6df853
------------
Karsten Hopp 6df853
Karsten Hopp 6df853
Patch 7.2.334
Karsten Hopp 6df853
Problem:    Postponing keys in Netbeans interface does not work properly.
Karsten Hopp 6df853
Solution:   Store the key string instead of the number.  Avoid an infinite
Karsten Hopp 6df853
	    loop. (Mostly by Xavier de Gaye)
Karsten Hopp 6df853
Files:	    src/netbeans.c, src/proto/netbeans.pro
Karsten Hopp 6df853
Karsten Hopp 6df853
Karsten Hopp 6df853
*** ../vim-7.2.333/src/netbeans.c	2010-01-19 14:59:14.000000000 +0100
Karsten Hopp 6df853
--- src/netbeans.c	2010-01-19 15:12:17.000000000 +0100
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 70,76 ****
Karsten Hopp 6df853
  static pos_T *off2pos __ARGS((buf_T *, long));
Karsten Hopp 6df853
  static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
Karsten Hopp 6df853
  static long get_buf_size __ARGS((buf_T *));
Karsten Hopp 6df853
! static void netbeans_keystring __ARGS((int key, char *keystr));
Karsten Hopp 6df853
  static void special_keys __ARGS((char_u *args));
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  static void netbeans_connect __ARGS((void));
Karsten Hopp 6df853
--- 70,77 ----
Karsten Hopp 6df853
  static pos_T *off2pos __ARGS((buf_T *, long));
Karsten Hopp 6df853
  static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
Karsten Hopp 6df853
  static long get_buf_size __ARGS((buf_T *));
Karsten Hopp 6df853
! static int netbeans_keystring __ARGS((char_u *keystr));
Karsten Hopp 6df853
! static void postpone_keycommand __ARGS((char_u *keystr));
Karsten Hopp 6df853
  static void special_keys __ARGS((char_u *args));
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  static void netbeans_connect __ARGS((void));
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 502,508 ****
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  struct keyqueue
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
!     int		     key;
Karsten Hopp 6df853
      struct keyqueue *next;
Karsten Hopp 6df853
      struct keyqueue *prev;
Karsten Hopp 6df853
  };
Karsten Hopp 6df853
--- 503,509 ----
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  struct keyqueue
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
!     char_u	    *keystr;
Karsten Hopp 6df853
      struct keyqueue *next;
Karsten Hopp 6df853
      struct keyqueue *prev;
Karsten Hopp 6df853
  };
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 514,526 ****
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
   * Queue up key commands sent from netbeans.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
      static void
Karsten Hopp 6df853
! postpone_keycommand(int key)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
      keyQ_T *node;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      node = (keyQ_T *)alloc(sizeof(keyQ_T));
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      if (keyHead.next == NULL) /* initialize circular queue */
Karsten Hopp 6df853
      {
Karsten Hopp 6df853
--- 515,531 ----
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
   * Queue up key commands sent from netbeans.
Karsten Hopp 6df853
+  * We store the string, because it may depend on the global mod_mask and
Karsten Hopp 6df853
+  * :nbkey doesn't have a key number.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
      static void
Karsten Hopp 6df853
! postpone_keycommand(char_u *keystr)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
      keyQ_T *node;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      node = (keyQ_T *)alloc(sizeof(keyQ_T));
Karsten Hopp 6df853
+     if (node == NULL)
Karsten Hopp 6df853
+ 	return;  /* out of memory, drop the key */
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      if (keyHead.next == NULL) /* initialize circular queue */
Karsten Hopp 6df853
      {
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 534,540 ****
Karsten Hopp 6df853
      keyHead.prev->next = node;
Karsten Hopp 6df853
      keyHead.prev = node;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
!     node->key = key;
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
--- 539,545 ----
Karsten Hopp 6df853
      keyHead.prev->next = node;
Karsten Hopp 6df853
      keyHead.prev = node;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
!     node->keystr = vim_strsave(keystr);
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 543,557 ****
Karsten Hopp 6df853
      static void
Karsten Hopp 6df853
  handle_key_queue(void)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
!     while (keyHead.next && keyHead.next != &keyHead)
Karsten Hopp 6df853
      {
Karsten Hopp 6df853
  	/* first, unlink the node */
Karsten Hopp 6df853
  	keyQ_T *node = keyHead.next;
Karsten Hopp 6df853
  	keyHead.next = node->next;
Karsten Hopp 6df853
  	node->next->prev = node->prev;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
! 	/* now, send the keycommand */
Karsten Hopp 6df853
! 	netbeans_keycommand(node->key);
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  	/* Finally, dispose of the node */
Karsten Hopp 6df853
  	vim_free(node);
Karsten Hopp 6df853
--- 548,567 ----
Karsten Hopp 6df853
      static void
Karsten Hopp 6df853
  handle_key_queue(void)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
!     int postponed = FALSE;
Karsten Hopp 6df853
! 
Karsten Hopp 6df853
!     while (!postponed && keyHead.next && keyHead.next != &keyHead)
Karsten Hopp 6df853
      {
Karsten Hopp 6df853
  	/* first, unlink the node */
Karsten Hopp 6df853
  	keyQ_T *node = keyHead.next;
Karsten Hopp 6df853
  	keyHead.next = node->next;
Karsten Hopp 6df853
  	node->next->prev = node->prev;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
! 	/* Now, send the keycommand.  This may cause it to be postponed again
Karsten Hopp 6df853
! 	 * and change keyHead. */
Karsten Hopp 6df853
! 	if (node->keystr != NULL)
Karsten Hopp 6df853
! 	    postponed = !netbeans_keystring(node->keystr);
Karsten Hopp 6df853
! 	vim_free(node->keystr);
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  	/* Finally, dispose of the node */
Karsten Hopp 6df853
  	vim_free(node);
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 2495,2501 ****
Karsten Hopp 6df853
  	    }
Karsten Hopp 6df853
  	    else
Karsten Hopp 6df853
  	    {
Karsten Hopp 6df853
! 	        nbdebug(("    Buffer has no changes!\n"));
Karsten Hopp 6df853
  	    }
Karsten Hopp 6df853
  /* =====================================================================*/
Karsten Hopp 6df853
  	}
Karsten Hopp 6df853
--- 2505,2511 ----
Karsten Hopp 6df853
  	    }
Karsten Hopp 6df853
  	    else
Karsten Hopp 6df853
  	    {
Karsten Hopp 6df853
! 		nbdebug(("    Buffer has no changes!\n"));
Karsten Hopp 6df853
  	    }
Karsten Hopp 6df853
  /* =====================================================================*/
Karsten Hopp 6df853
  	}
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 2658,2664 ****
Karsten Hopp 6df853
  ex_nbkey(eap)
Karsten Hopp 6df853
      exarg_T	*eap;
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
!     netbeans_keystring(0, (char *)eap->arg);
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
--- 2668,2674 ----
Karsten Hopp 6df853
  ex_nbkey(eap)
Karsten Hopp 6df853
      exarg_T	*eap;
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
!     (void)netbeans_keystring(eap->arg);
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 2680,2686 ****
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
!  * Convert key to netbeans name.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
      static void
Karsten Hopp 6df853
  netbeans_keyname(int key, char *buf)
Karsten Hopp 6df853
--- 2690,2696 ----
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
!  * Convert key to netbeans name.  This uses the global "mod_mask".
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
      static void
Karsten Hopp 6df853
  netbeans_keyname(int key, char *buf)
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 3127,3149 ****
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
   * Send a keypress event back to netbeans. This usually simulates some
Karsten Hopp 6df853
   * kind of function key press. This function operates on a key code.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
!     void
Karsten Hopp 6df853
  netbeans_keycommand(int key)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
      char	keyName[60];
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      netbeans_keyname(key, keyName);
Karsten Hopp 6df853
!     netbeans_keystring(key, keyName);
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
   * Send a keypress event back to netbeans. This usually simulates some
Karsten Hopp 6df853
   * kind of function key press. This function operates on a key string.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
!     static void
Karsten Hopp 6df853
! netbeans_keystring(int key, char *keyName)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
      char	buf[2*MAXPATHL];
Karsten Hopp 6df853
      int		bufno = nb_getbufno(curbuf);
Karsten Hopp 6df853
--- 3137,3163 ----
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
   * Send a keypress event back to netbeans. This usually simulates some
Karsten Hopp 6df853
   * kind of function key press. This function operates on a key code.
Karsten Hopp 6df853
+  * Return TRUE when the key was sent, FALSE when the command has been
Karsten Hopp 6df853
+  * postponed.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
!     int
Karsten Hopp 6df853
  netbeans_keycommand(int key)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
      char	keyName[60];
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      netbeans_keyname(key, keyName);
Karsten Hopp 6df853
!     return netbeans_keystring((char_u *)keyName);
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  /*
Karsten Hopp 6df853
   * Send a keypress event back to netbeans. This usually simulates some
Karsten Hopp 6df853
   * kind of function key press. This function operates on a key string.
Karsten Hopp 6df853
+  * Return TRUE when the key was sent, FALSE when the command has been
Karsten Hopp 6df853
+  * postponed.
Karsten Hopp 6df853
   */
Karsten Hopp 6df853
!     static int
Karsten Hopp 6df853
! netbeans_keystring(char_u *keyName)
Karsten Hopp 6df853
  {
Karsten Hopp 6df853
      char	buf[2*MAXPATHL];
Karsten Hopp 6df853
      int		bufno = nb_getbufno(curbuf);
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 3151,3157 ****
Karsten Hopp 6df853
      char_u	*q;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      if (!haveConnection)
Karsten Hopp 6df853
! 	return;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      if (bufno == -1)
Karsten Hopp 6df853
--- 3165,3171 ----
Karsten Hopp 6df853
      char_u	*q;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      if (!haveConnection)
Karsten Hopp 6df853
! 	return TRUE;
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      if (bufno == -1)
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 3160,3166 ****
Karsten Hopp 6df853
  	q = curbuf->b_ffname == NULL ? (char_u *)""
Karsten Hopp 6df853
  						 : nb_quote(curbuf->b_ffname);
Karsten Hopp 6df853
  	if (q == NULL)
Karsten Hopp 6df853
! 	    return;
Karsten Hopp 6df853
  	vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0,
Karsten Hopp 6df853
  		q,
Karsten Hopp 6df853
  		"T",  /* open in NetBeans */
Karsten Hopp 6df853
--- 3174,3180 ----
Karsten Hopp 6df853
  	q = curbuf->b_ffname == NULL ? (char_u *)""
Karsten Hopp 6df853
  						 : nb_quote(curbuf->b_ffname);
Karsten Hopp 6df853
  	if (q == NULL)
Karsten Hopp 6df853
! 	    return TRUE;
Karsten Hopp 6df853
  	vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0,
Karsten Hopp 6df853
  		q,
Karsten Hopp 6df853
  		"T",  /* open in NetBeans */
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 3170,3178 ****
Karsten Hopp 6df853
  	nbdebug(("EVT: %s", buf));
Karsten Hopp 6df853
  	nb_send(buf, "netbeans_keycommand");
Karsten Hopp 6df853
  
Karsten Hopp 6df853
! 	if (key > 0)
Karsten Hopp 6df853
! 	    postpone_keycommand(key);
Karsten Hopp 6df853
! 	return;
Karsten Hopp 6df853
      }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      /* sync the cursor position */
Karsten Hopp 6df853
--- 3184,3191 ----
Karsten Hopp 6df853
  	nbdebug(("EVT: %s", buf));
Karsten Hopp 6df853
  	nb_send(buf, "netbeans_keycommand");
Karsten Hopp 6df853
  
Karsten Hopp 6df853
! 	postpone_keycommand(keyName);
Karsten Hopp 6df853
! 	return FALSE;
Karsten Hopp 6df853
      }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
      /* sync the cursor position */
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 3198,3203 ****
Karsten Hopp 6df853
--- 3211,3217 ----
Karsten Hopp 6df853
  		off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col);
Karsten Hopp 6df853
      nbdebug(("EVT: %s", buf));
Karsten Hopp 6df853
      nb_send(buf, "netbeans_keycommand");
Karsten Hopp 6df853
+     return TRUE;
Karsten Hopp 6df853
  }
Karsten Hopp 6df853
  
Karsten Hopp 6df853
  
Karsten Hopp 6df853
*** ../vim-7.2.333/src/proto/netbeans.pro	2009-01-06 16:13:42.000000000 +0100
Karsten Hopp 6df853
--- src/proto/netbeans.pro	2010-01-19 13:31:01.000000000 +0100
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 16,22 ****
Karsten Hopp 6df853
  void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, long len));
Karsten Hopp 6df853
  void netbeans_unmodified __ARGS((buf_T *bufp));
Karsten Hopp 6df853
  void netbeans_button_release __ARGS((int button));
Karsten Hopp 6df853
! void netbeans_keycommand __ARGS((int key));
Karsten Hopp 6df853
  void netbeans_save_buffer __ARGS((buf_T *bufp));
Karsten Hopp 6df853
  void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
Karsten Hopp 6df853
  int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));
Karsten Hopp 6df853
--- 16,22 ----
Karsten Hopp 6df853
  void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, long len));
Karsten Hopp 6df853
  void netbeans_unmodified __ARGS((buf_T *bufp));
Karsten Hopp 6df853
  void netbeans_button_release __ARGS((int button));
Karsten Hopp 6df853
! int netbeans_keycommand __ARGS((int key));
Karsten Hopp 6df853
  void netbeans_save_buffer __ARGS((buf_T *bufp));
Karsten Hopp 6df853
  void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
Karsten Hopp 6df853
  int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));
Karsten Hopp 6df853
*** ../vim-7.2.333/src/version.c	2010-01-19 14:59:14.000000000 +0100
Karsten Hopp 6df853
--- src/version.c	2010-01-19 15:08:44.000000000 +0100
Karsten Hopp 6df853
***************
Karsten Hopp 6df853
*** 683,684 ****
Karsten Hopp 6df853
--- 683,686 ----
Karsten Hopp 6df853
  {   /* Add new patch number below this line */
Karsten Hopp 6df853
+ /**/
Karsten Hopp 6df853
+     334,
Karsten Hopp 6df853
  /**/
Karsten Hopp 6df853
Karsten Hopp 6df853
-- 
Karsten Hopp 6df853
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 6df853
119. You are reading a book and look for the scroll bar to get to
Karsten Hopp 6df853
     the next page.
Karsten Hopp 6df853
Karsten Hopp 6df853
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6df853
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6df853
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 6df853
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///