Hi,

once using vim with multiple tabs open I attempted to close one by
middle-clicking it - just as accustomed to by the behavior of firefox,
jumanji and other tab-providing programs.

As a result of this feature missing I wrote the attached patch,
providing the feature for terminal- and gtk-mode.
Constructive criticism on that is truely welcome.

kind regards,
Max

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r 2cfb68fa26cd src/gui.c
--- a/src/gui.c	Wed Mar 28 20:51:51 2012 +0200
+++ b/src/gui.c	Wed Apr 04 12:55:07 2012 +0200
@@ -3691,16 +3691,39 @@ send_tabline_event(nr)
     string[2] = KE_FILLER;
     add_to_input_buf(string, 3);
     string[0] = nr;
     add_to_input_buf_csi(string, 1);
     return TRUE;
 }
 
 /*
+ * Send the event for clicking to close tab page "nr" via middle button.
+ */
+    int
+send_tabline_close_event(nr)
+    int	    nr;
+{
+    char_u string[3];
+
+    /* Don't put events in the input queue now. */
+    if (hold_gui_events)
+	return;
+
+    string[0] = CSI;
+    string[1] = KS_TABMENU;
+    string[2] = KE_FILLER;
+    add_to_input_buf(string, 3);
+    string[0] = nr;
+    string[1] = (char_u)(long)TABLINE_MENU_CLOSE;
+    add_to_input_buf_csi(string, 2);
+    return TRUE;
+}
+
+/*
  * Send a tabline menu event
  */
     void
 send_tabline_menu_event(tabidx, event)
     int	    tabidx;
     int	    event;
 {
     char_u	    string[3];
diff -r 2cfb68fa26cd src/gui_gtk_x11.c
--- a/src/gui_gtk_x11.c	Wed Mar 28 20:51:51 2012 +0200
+++ b/src/gui_gtk_x11.c	Wed Apr 04 12:55:07 2012 +0200
@@ -2878,16 +2878,26 @@ on_tabline_menu(GtkWidget *widget, GdkEv
 	/* If the event was generated for 3rd button popup the menu. */
 	if (bevent->button == 3)
 	{
 	    gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL,
 						bevent->button, bevent->time);
 	    /* We handled the event. */
 	    return TRUE;
 	}
+	/* If the event was generated for 2nd button close the tab. */
+	else if (bevent->button == 2)
+	{
+	    if (clicked_page == 0)
+		return FALSE; /* We didn't handle the event. */
+
+		send_tabline_close_event(clicked_page);
+	    /* We handled the event. */
+	    return TRUE;
+	}
 	else if (bevent->button == 1)
 	{
 	    if (clicked_page == 0)
 	    {
 		/* Click after all tabs moves to next tab page.  When "x" is
 		 * small guess it's the left button. */
 		send_tabline_event(x < 50 ? -1 : 0);
 	    }
diff -r 2cfb68fa26cd src/normal.c
--- a/src/normal.c	Wed Mar 28 20:51:51 2012 +0200
+++ b/src/normal.c	Wed Apr 04 12:55:07 2012 +0200
@@ -2634,16 +2634,29 @@ do_mouse(oap, c, dir, count, fixindent)
 		{
 		    /* double click opens new page */
 		    end_visual_mode();
 		    tabpage_new();
 		    tabpage_move(c1 == 0 ? 9999 : c1 - 1);
 		}
 		else
 		{
+			/* close tab on middle click */
+			if(which_button == MOUSE_MIDDLE){
+				tabpage_T	*tp;
+		    	tp = find_tabpage(c1);
+				if (tp == curtab)
+				{
+				    if (first_tabpage->tp_next != NULL)
+					tabpage_close(FALSE);
+				}
+				else if (tp != NULL)
+				    tabpage_close_other(tp, FALSE);
+			}
+
 		    /* Go to specified tab page, or next one if not clicking
 		     * on a label. */
 		    goto_tabpage(c1);
 
 		    /* It's like clicking on the status line of a window. */
 		    if (curwin != old_curwin)
 			end_visual_mode();
 		}

Raspunde prin e-mail lui