Included the patch to support netbeans in a terminal.
diff --git a/src/edit.c b/src/edit.c
index 88943cd..a80f196 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -9433,8 +9433,7 @@
 #ifdef FEAT_NETBEANS_INTG
 	    if (usingNetbeans)
 	    {
-		netbeans_removed(curbuf, fpos.lnum, cursor->col,
-							       (long)(i + 1));
+		netbeans_removed(curbuf, fpos.lnum, cursor->col, (long)(i + 1));
 		netbeans_inserted(curbuf, fpos.lnum, cursor->col,
 							   (char_u *)"\t", 1);
 	    }
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 1f9a7f2..bcbcc8b 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -3815,10 +3815,10 @@
     DO_AUTOCHDIR
 
 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG)
-    if (gui.in_use && curbuf->b_ffname != NULL)
+    if (curbuf->b_ffname != NULL)
     {
 # ifdef FEAT_SUN_WORKSHOP
-	if (usingSunWorkShop)
+	if (gui.in_use && usingSunWorkShop)
 	    workshop_file_opened((char *)curbuf->b_ffname, curbuf->b_p_ro);
 # endif
 # ifdef FEAT_NETBEANS_INTG
diff --git a/src/feature.h b/src/feature.h
index 4568ffc..6b8f600 100644
--- a/src/feature.h
+++ b/src/feature.h
@@ -1193,11 +1193,9 @@
 #endif
 
 /*
- * The Netbeans features currently only work with Motif and GTK and Win32.
- * It also requires +listcmds and +eval.
+ * The Netbeans feature requires +listcmds and +eval.
  */
-#if ((!defined(FEAT_GUI_MOTIF) && !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_W32)) \
-		|| !defined(FEAT_LISTCMDS) || !defined(FEAT_EVAL)) \
+#if (!defined(FEAT_LISTCMDS) || !defined(FEAT_EVAL)) \
 	&& defined(FEAT_NETBEANS_INTG)
 # undef FEAT_NETBEANS_INTG
 #endif
diff --git a/src/getchar.c b/src/getchar.c
index d28eef5..ca0cca7 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -2941,7 +2941,8 @@
 
 #if defined(FEAT_NETBEANS_INTG)
 	/* Process the queued netbeans messages. */
-	netbeans_parse_messages();
+	if (usingNetbeans)
+	    netbeans_parse_messages();
 #endif
 
 	if (got_int || (script_char = getc(scriptin[curscript])) < 0)
diff --git a/src/gui.c b/src/gui.c
index ccf6e39..0b69689 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -593,11 +593,6 @@
 	    gui_mch_disable_beval_area(balloonEval);
 #endif
 
-#ifdef FEAT_NETBEANS_INTG
-	if (starting == 0 && usingNetbeans)
-	    /* Tell the client that it can start sending commands. */
-	    netbeans_startup_done();
-#endif
 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
 	if (!im_xim_isvalid_imactivate())
 	    EMSG(_("E599: Value of 'imactivatekey' is invalid"));
@@ -2367,7 +2362,8 @@
     if (draw_sign)
 	/* Draw the sign on top of the spaces. */
 	gui_mch_drawsign(gui.row, col, gui.highlight_mask);
-# ifdef FEAT_NETBEANS_INTG
+# if defined(FEAT_NETBEANS_INTG) && (defined(FEAT_GUI_MOTIF) \
+	|| defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32))
     if (multi_sign)
 	netbeans_draw_multisign_indicator(gui.row);
 # endif
@@ -4784,6 +4780,10 @@
 	 * of the argument ending up after the shell prompt. */
 	msg_clr_eos_force();
 	gui_start();
+#ifdef FEAT_NETBEANS_INTG
+	if (usingNetbeans)
+	    netbeans_gui_register();
+#endif
     }
     if (!ends_excmd(*eap->arg))
 	ex_next(eap);
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index baaed59..4caf0bb 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -6596,7 +6596,8 @@
 
 #if defined(FEAT_NETBEANS_INTG)
 	/* Process the queued netbeans messages. */
-	netbeans_parse_messages();
+	if (usingNetbeans)
+	    netbeans_parse_messages();
 #endif
 
 	/*
diff --git a/src/gui_w48.c b/src/gui_w48.c
index 477acfa..b1ea568 100644
--- a/src/gui_w48.c
+++ b/src/gui_w48.c
@@ -1732,7 +1732,7 @@
 #ifdef FEAT_NETBEANS_INTG
     if (msg.message == WM_NETBEANS)
     {
-	messageFromNetbeansW32();
+	netbeans_read();
 	return;
     }
 #endif
@@ -1999,7 +1999,8 @@
 
 #ifdef FEAT_NETBEANS_INTG
 	/* Process the queued netbeans messages. */
-	netbeans_parse_messages();
+	if (usingNetbeans)
+	    netbeans_parse_messages();
 #endif
 
 	/*
diff --git a/src/gui_x11.c b/src/gui_x11.c
index 4110fc6..522f923 100644
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -635,8 +635,8 @@
     gui_mch_update();
 }
 
-#if (defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)) \
-	|| defined(PROTO)
+#if ((defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)) \
+	&& defined(FEAT_GUI_MOTIF)) || defined(PROTO)
 /*
  * This function fills in the XRectangle object with the current x,y
  * coordinates and height, width so that an XtVaSetValues to the same shell of
@@ -709,7 +709,7 @@
 	workshop_frame_moved(rec.x, rec.y, rec.width, rec.height);
     }
 #endif
-#ifdef FEAT_NETBEANS_INTG
+#if defined(FEAT_NETBEANS_INTG) && defined(FEAT_GUI_MOTIF)
     if (usingNetbeans)
     {
 	XRectangle  rec;
diff --git a/src/main.c b/src/main.c
index b9e9209..14921ff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -528,10 +528,6 @@
      * Set the default values for the options that use Rows and Columns.
      */
     ui_get_shellsize();		/* inits Rows and Columns */
-#ifdef FEAT_NETBEANS_INTG
-    if (usingNetbeans)
-	Columns += 2;		/* leave room for glyph gutter */
-#endif
     win_init_size();
 #ifdef FEAT_DIFF
     /* Set the 'diff' option now, so that it can be checked for in a .vimrc
@@ -937,8 +933,20 @@
 
 #ifdef FEAT_NETBEANS_INTG
     if (usingNetbeans)
+    {
+# ifdef FEAT_GUI
+#  if !defined(FEAT_GUI_MOTIF) && !defined(FEAT_GUI_GTK)  \
+		&& !defined(FEAT_GUI_W32)
+	if (gui.in_use)
+	{
+	    mch_errmsg(_("netbeans is not supported with this GUI\n"));
+	    mch_exit(2);
+	}
+#  endif
+# endif
 	/* Tell the client that it can start sending commands. */
 	netbeans_startup_done();
+    }
 #endif
 
     TIME_MSG("before starting main loop");
@@ -1616,10 +1624,10 @@
 # endif
 # ifndef FEAT_NETBEANS_INTG
 	else if (strncmp(argv[i], "-nb", (size_t)3) == 0)
-        {
-            mch_errmsg(_("'-nb' cannot be used: not enabled at compile time\n"));
-            mch_exit(2);
-        }
+	{
+	    mch_errmsg(_("'-nb' cannot be used: not enabled at compile time\n"));
+	    mch_exit(2);
+	}
 # endif
 
     }
@@ -1879,6 +1887,16 @@
 		break;
 
 	    case 'n':		/* "-n" no swap file */
+#ifdef FEAT_NETBEANS_INTG
+		/* checking for "-nb", netbeans parameters */
+		if (argv[0][argv_idx] == 'b')
+		{
+		    ++usingNetbeans;
+		    netbeansArg = argv[0];
+		    argv_idx = -1;	    /* skip to next argument */
+		}
+		else
+#endif
 		parmp->no_swap_file = TRUE;
 		break;
 
diff --git a/src/netbeans.c b/src/netbeans.c
index 93a9aea..f1bae59 100644
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -61,10 +61,11 @@
 
 #define GUARDED		10000 /* typenr for "guarded" annotation */
 #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */
+#define MAX_COLOR_LENGTH 32 /* max length of color name in defineAnnoType */
 
 /* The first implementation (working only with Netbeans) returned "1.1".  The
  * protocol implemented here also supports A-A-P. */
-static char *ExtEdProtocolVersion = "2.4";
+static char *ExtEdProtocolVersion = "2.5";
 
 static long pos2off __ARGS((buf_T *, pos_T *));
 static pos_T *off2pos __ARGS((buf_T *, long));
@@ -90,6 +91,11 @@
 static int  nb_do_cmd __ARGS((int, char_u *, int, int, char_u *));
 static void nb_send __ARGS((char *buf, char *fun));
 
+/* TRUE when netbeans is running with a GUI. */
+#ifdef FEAT_GUI
+# define NB_HAS_GUI (gui.in_use || gui.starting)
+#endif
+
 #ifdef WIN64
 typedef __int64 NBSOCK;
 #else
@@ -110,16 +116,6 @@
 static int r_cmdno;			/* current command number for reply */
 static int haveConnection = FALSE;	/* socket is connected and
 					   initialization is done */
-#ifdef FEAT_GUI_MOTIF
-static void netbeans_Xt_connect __ARGS((void *context));
-#endif
-#ifdef FEAT_GUI_GTK
-static void netbeans_gtk_connect __ARGS((void));
-#endif
-#ifdef FEAT_GUI_W32
-static void netbeans_w32_connect __ARGS((void));
-#endif
-
 static int dosetvisible = FALSE;
 
 /*
@@ -130,101 +126,39 @@
 #endif
 
 /* Connect back to Netbeans process */
-#ifdef FEAT_GUI_MOTIF
-    static void
-netbeans_Xt_connect(void *context)
-{
-    netbeans_connect();
-    if (sd > 0)
-    {
-	/* tell notifier we are interested in being called
-	 * when there is input on the editor connection socket
-	 */
-	inputHandler = XtAppAddInput((XtAppContext)context, sd,
-			     (XtPointer)(XtInputReadMask + XtInputExceptMask),
-						   messageFromNetbeans, NULL);
-    }
-}
-
     static void
 netbeans_disconnect(void)
 {
+#ifdef FEAT_GUI_MOTIF
     if (inputHandler != (XtInputId)NULL)
     {
 	XtRemoveInput(inputHandler);
 	inputHandler = (XtInputId)NULL;
     }
-    sd = -1;
-    haveConnection = FALSE;
-# ifdef FEAT_BEVAL
-    bevalServers &= ~BEVAL_NETBEANS;
-# endif
-}
-#endif /* FEAT_MOTIF_GUI */
-
-#ifdef FEAT_GUI_GTK
-    static void
-netbeans_gtk_connect(void)
-{
-    netbeans_connect();
-    if (sd > 0)
-    {
-	/*
-	 * Tell gdk we are interested in being called when there
-	 * is input on the editor connection socket
-	 */
-	inputHandler = gdk_input_add((gint)sd, (GdkInputCondition)
-		((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
-						   messageFromNetbeans, NULL);
-    }
-}
-
-    static void
-netbeans_disconnect(void)
-{
+#else
+# ifdef FEAT_GUI_GTK
     if (inputHandler != 0)
     {
 	gdk_input_remove(inputHandler);
 	inputHandler = 0;
     }
-    sd = -1;
-    haveConnection = FALSE;
-# ifdef FEAT_BEVAL
-    bevalServers &= ~BEVAL_NETBEANS;
-# endif
-}
-#endif /* FEAT_GUI_GTK */
-
-#if defined(FEAT_GUI_W32) || defined(PROTO)
-    static void
-netbeans_w32_connect(void)
-{
-    netbeans_connect();
-    if (sd > 0)
-    {
-	/*
-	 * Tell Windows we are interested in receiving message when there
-	 * is input on the editor connection socket
-	 */
-	inputHandler = WSAAsyncSelect(sd, s_hwnd, WM_NETBEANS, FD_READ);
-    }
-}
-
-    static void
-netbeans_disconnect(void)
-{
+# else
+#  ifdef FEAT_GUI_W32
     if (inputHandler == 0)
     {
 	WSAAsyncSelect(sd, s_hwnd, 0, 0);
 	inputHandler = -1;
     }
+#  endif
+# endif
+#endif
+
     sd = -1;
     haveConnection = FALSE;
-# ifdef FEAT_BEVAL
+#ifdef FEAT_BEVAL
     bevalServers &= ~BEVAL_NETBEANS;
-# endif
+#endif
 }
-#endif /* FEAT_GUI_W32 */
 
 #define NB_DEF_HOST "localhost"
 #define NB_DEF_ADDR "3219"
@@ -240,7 +174,7 @@
     u_short		port;
 # else
     int			port;
-#endif
+# endif
 #else
     struct sockaddr_un	server;
 #endif
@@ -709,31 +643,35 @@
 #define MAXMSGSIZE 4096
 
 /*
- * Read and process a command from netbeans.
+ * Read a command from netbeans.
  */
-#if defined(FEAT_GUI_W32) || defined(PROTO)
-/* Use this one when generating prototypes, the others are static. */
-    void
-messageFromNetbeansW32()
-#else
-# ifdef FEAT_GUI_MOTIF
+#ifdef FEAT_GUI_MOTIF
     static void
 messageFromNetbeans(XtPointer clientData UNUSED,
 		    int *unused1 UNUSED,
 		    XtInputId *unused2 UNUSED)
-# endif
-# ifdef FEAT_GUI_GTK
+{
+    netbeans_read();
+}
+#endif
+
+#ifdef FEAT_GUI_GTK
     static void
 messageFromNetbeans(gpointer clientData UNUSED,
 		    gint unused1 UNUSED,
 		    GdkInputCondition unused2 UNUSED)
-# endif
+{
+    netbeans_read();
+}
 #endif
+
+    void
+netbeans_read()
 {
     static char_u	*buf = NULL;
     int			len = 0;
     int			readlen = 0;
-#ifndef FEAT_GUI_GTK
+#if defined(NB_HAS_GUI) && !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_W32)
     static int		level = 0;
 #endif
 #ifdef HAVE_SELECT
@@ -751,8 +689,11 @@
 	return;
     }
 
-#ifndef FEAT_GUI_GTK
-    ++level;  /* recursion guard; this will be called from the X event loop */
+#if defined(NB_HAS_GUI) && !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_W32)
+    /* recursion guard; this will be called from the X event loop at unknown
+     * moments */
+    if (NB_HAS_GUI)
+	++level;
 #endif
 
     /* Allocate a buffer to read into. */
@@ -770,17 +711,17 @@
     {
 #ifdef HAVE_SELECT
 	FD_ZERO(&rfds);
-        FD_SET(sd, &rfds);
-        tval.tv_sec = 0;
-        tval.tv_usec = 0;
-        if (select(sd + 1, &rfds, NULL, NULL, &tval) <= 0)
-            break;
+	FD_SET(sd, &rfds);
+	tval.tv_sec = 0;
+	tval.tv_usec = 0;
+	if (select(sd + 1, &rfds, NULL, NULL, &tval) <= 0)
+	    break;
 #else
 # ifdef HAVE_POLL
 	fds.fd = sd;
 	fds.events = POLLIN;
-        if (poll(&fds, 1, 0) <= 0)
-            break;
+	if (poll(&fds, 1, 0) <= 0)
+	    break;
 # endif
 #endif
 	len = sock_read(sd, buf, MAXMSGSIZE);
@@ -807,18 +748,21 @@
 	return; /* don't try to parse it */
     }
 
-#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32)
+#if defined(NB_HAS_GUI) && !defined(FEAT_GUI_W32)
     /* Let the main loop handle messages. */
+    if (NB_HAS_GUI)
+    {
 # ifdef FEAT_GUI_GTK
-    if (gtk_main_level() > 0)
-	gtk_main_quit();
-# endif
-#else
-    /* Parse the messages now, but avoid recursion. */
-    if (level == 1)
-	netbeans_parse_messages();
+	if (gtk_main_level() > 0)
+	    gtk_main_quit();
+# else
+	/* Parse the messages now, but avoid recursion. */
+	if (level == 1)
+	    netbeans_parse_messages();
 
-    --level;
+	--level;
+# endif
+    }
 #endif
 }
 
@@ -945,7 +889,7 @@
 static int  mapsigntype __ARGS((nbbuf_T *, int localsigntype));
 static void addsigntype __ARGS((nbbuf_T *, int localsigntype, char_u *typeName,
 			char_u *tooltip, char_u *glyphfile,
-			int usefg, int fg, int usebg, int bg));
+			char_u *fg, char_u *bg));
 static void print_read_msg __ARGS((nbbuf_T *buf));
 static void print_save_msg __ARGS((nbbuf_T *buf, long nchars));
 
@@ -1848,7 +1792,9 @@
 	    buf->bufp = curbuf;
 	    maketitle();
 	    buf->insertDone = FALSE;
+#if defined(FEAT_MENU) && defined(FEAT_GUI)
 	    gui_update_menus(0);
+#endif
 /* =====================================================================*/
 	}
 	else if (streq((char *)cmd, "insertDone"))
@@ -2012,7 +1958,9 @@
 	    netbeansReadFile = 1;
 	    buf->bufp = curbuf;
 	    maketitle();
+#if defined(FEAT_MENU) && defined(FEAT_GUI)
 	    gui_update_menus(0);
+#endif
 /* =====================================================================*/
 	}
 	else if (streq((char *)cmd, "editFile"))
@@ -2034,7 +1982,9 @@
 #if defined(FEAT_TITLE)
 	    maketitle();
 #endif
+#if defined(FEAT_MENU) && defined(FEAT_GUI)
 	    gui_update_menus(0);
+#endif
 /* =====================================================================*/
 	}
 	else if (streq((char *)cmd, "setVisible"))
@@ -2058,17 +2008,21 @@
 		doupdate = 1;
 		dosetvisible = FALSE;
 
+#ifdef FEAT_GUI
 		/* Side effect!!!. */
 		if (!gui.starting)
 		    gui_mch_set_foreground();
+#endif
 	    }
 /* =====================================================================*/
 	}
 	else if (streq((char *)cmd, "raise"))
 	{
+#ifdef FEAT_GUI
 	    /* Bring gvim to the foreground. */
 	    if (!gui.starting)
 		gui_mch_set_foreground();
+#endif
 /* =====================================================================*/
 	}
 	else if (streq((char *)cmd, "setModified"))
@@ -2199,8 +2153,10 @@
 	    update_screen(VALID);
 	    setcursor();
 	    out_flush();
+#ifdef FEAT_GUI
 	    gui_update_cursor(TRUE, FALSE);
 	    gui_mch_flush();
+#endif
 	    /* Quit a hit-return or more prompt. */
 	    if (State == HITRETURN || State == ASKMORE)
 	    {
@@ -2237,7 +2193,9 @@
 		    EMSG("E649: invalid buffer identifier in close");
 	    }
 	    nbdebug(("    CLOSE %d: %s\n", bufno, name));
+#ifdef FEAT_GUI
 	    need_mouse_correct = TRUE;
+#endif
 	    if (buf->bufp != NULL)
 		do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD,
 						     buf->bufp->b_fnum, TRUE);
@@ -2264,10 +2222,9 @@
 	    char_u *tooltip;
 	    char_u *p;
 	    char_u *glyphFile;
-	    int use_fg = 0;
-	    int use_bg = 0;
-	    int fg = -1;
-	    int bg = -1;
+	    int parse_error = FALSE;
+	    char_u *fg;
+	    char_u *bg;
 
 	    if (buf == NULL)
 	    {
@@ -2290,33 +2247,32 @@
 	    vim_free(p);
 
 	    args = skipwhite(args + 1);
-	    if (STRNCMP(args, "none", 4) == 0)
-		args += 5;
-	    else
+	    p = skiptowhite(args);
+	    if (*p != NUL)
 	    {
-		use_fg = 1;
-		cp = (char *)args;
-		fg = strtol(cp, &cp, 10);
-		args = (char_u *)cp;
+		*p = NUL;
+		p = skipwhite(p + 1);
 	    }
-	    if (STRNCMP(args, "none", 4) == 0)
-		args += 5;
-	    else
+	    fg = vim_strsave(args);
+	    bg = vim_strsave(p);
+	    if (STRLEN(fg) > MAX_COLOR_LENGTH || STRLEN(bg) > MAX_COLOR_LENGTH)
 	    {
-		use_bg = 1;
-		cp = (char *)args;
-		bg = strtol(cp, &cp, 10);
-		args = (char_u *)cp;
+		EMSG("E532: highlighting color name too long in defineAnnoType");
+		vim_free(typeName);
+		parse_error = TRUE;
 	    }
-	    if (typeName != NULL && tooltip != NULL && glyphFile != NULL)
-		addsigntype(buf, typeNum, typeName, tooltip, glyphFile,
-						      use_fg, fg, use_bg, bg);
+	    else if (typeName != NULL && tooltip != NULL && glyphFile != NULL)
+		addsigntype(buf, typeNum, typeName, tooltip, glyphFile, fg, bg);
 	    else
 		vim_free(typeName);
 
 	    /* don't free typeName; it's used directly in addsigntype() */
+	    vim_free(fg);
+	    vim_free(bg);
 	    vim_free(tooltip);
 	    vim_free(glyphFile);
+	    if (parse_error)
+		return FAIL;
 
 #endif
 /* =====================================================================*/
@@ -2588,8 +2544,10 @@
 	update_screen(NOT_VALID);
 	setcursor();
 	out_flush();
+#ifdef FEAT_GUI
 	gui_update_cursor(TRUE, FALSE);
 	gui_mch_flush();
+#endif
 	/* Quit a hit-return or more prompt. */
 	if (State == HITRETURN || State == ASKMORE)
 	{
@@ -2638,8 +2596,10 @@
     setcursor();		/* restore the cursor position */
     out_flush();		/* make sure output has been written */
 
+#ifdef FEAT_GUI
     gui_update_cursor(TRUE, FALSE);
     gui_mch_flush();
+#endif
 }
 
 
@@ -2707,7 +2667,8 @@
 
     if (!did_init)
     {
-	coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black");
+	coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
+			    " ctermbg=LightCyan ctermfg=Black");
 	coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
 
 	did_init = TRUE;
@@ -2785,7 +2746,7 @@
     strcat(buf, name);
 }
 
-#ifdef FEAT_BEVAL
+#if defined(FEAT_BEVAL) || defined(PROTO)
 /*
  * Function to be called for balloon evaluation.  Grabs the text under the
  * cursor and sends it to the debugger for evaluation.  The debugger should
@@ -2830,6 +2791,64 @@
 #endif
 
 /*
+ * Return netbeans file descriptor.
+ */
+    int
+netbeans_filedesc (void)
+{
+    return sd;
+}
+
+#if defined(FEAT_GUI) || defined(PROTO)
+/*
+ * Register our file descriptor with the gui event handling system.
+ */
+    void
+netbeans_gui_register(void)
+{
+    if (!NB_HAS_GUI)
+	return;
+
+    if (sd > 0)
+    {
+# ifdef FEAT_GUI_MOTIF
+	/* tell notifier we are interested in being called
+	 * when there is input on the editor connection socket
+	 */
+	if (inputHandler == (XtInputId)NULL)
+	    inputHandler = XtAppAddInput((XtAppContext)app_context, sd,
+			     (XtPointer)(XtInputReadMask + XtInputExceptMask),
+						   messageFromNetbeans, NULL);
+# else
+#  ifdef FEAT_GUI_GTK
+	/*
+	 * Tell gdk we are interested in being called when there
+	 * is input on the editor connection socket
+	 */
+	if (inputHandler == 0)
+	    inputHandler = gdk_input_add((gint)sd, (GdkInputCondition)
+		((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
+						   messageFromNetbeans, NULL);
+#  else
+#   ifdef FEAT_GUI_W32
+	/*
+	 * Tell Windows we are interested in receiving message when there
+	 * is input on the editor connection socket
+	 */
+	if (inputHandler == -1)
+	    inputHandler = WSAAsyncSelect(sd, s_hwnd, WM_NETBEANS, FD_READ);
+#   endif
+#  endif
+# endif
+    }
+
+# ifdef FEAT_BEVAL
+    bevalServers |= BEVAL_NETBEANS;
+# endif
+}
+#endif
+
+/*
  * Tell netbeans that the window was opened, ready for commands.
  */
     void
@@ -2837,24 +2856,14 @@
 {
     char *cmd = "0:startupDone=0\n";
 
-    if (usingNetbeans)
-#ifdef FEAT_GUI_MOTIF
-	netbeans_Xt_connect(app_context);
-#else
-# ifdef FEAT_GUI_GTK
-	netbeans_gtk_connect();
-# else
-#  ifdef FEAT_GUI_W32
-	netbeans_w32_connect();
-#  endif
-# endif
-#endif
-
-    if (!haveConnection)
+    if (!usingNetbeans)
 	return;
 
-#ifdef FEAT_BEVAL
-    bevalServers |= BEVAL_NETBEANS;
+    netbeans_connect();
+    if (!haveConnection)
+	return;
+#ifdef FEAT_GUI
+    netbeans_gui_register();
 #endif
 
     nbdebug(("EVT: %s", cmd));
@@ -3144,7 +3153,7 @@
     if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
     {
 	int col = mouse_col - W_WINCOL(curwin)
-		  - ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
+			      - ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
 	long off = pos2off(curbuf, &curwin->w_cursor);
 
 	/* sync the cursor position */
@@ -3404,7 +3413,6 @@
     }
 }
 
-
 /*
  * Add a sign of the requested type at the requested location.
  *
@@ -3427,14 +3435,12 @@
     char_u	*typeName,
     char_u	*tooltip UNUSED,
     char_u	*glyphFile,
-    int		use_fg,
-    int		fg,
-    int		use_bg,
-    int		bg)
+    char_u	*fg,
+    char_u	*bg)
 {
-    char fgbuf[32];
-    char bgbuf[32];
     int i, j;
+    int use_fg = (*fg && STRCMP(fg, "none") != 0);
+    int use_bg = (*bg && STRCMP(bg, "none") != 0);
 
     for (i = 0; i < globalsignmapused; i++)
 	if (STRCMP(typeName, globalsignmap[i]) == 0)
@@ -3442,12 +3448,26 @@
 
     if (i == globalsignmapused) /* not found; add it to global map */
     {
-	nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%d,%d)\n",
+	nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%s,%s)\n",
 			    typeNum, typeName, tooltip, glyphFile, fg, bg));
 	if (use_fg || use_bg)
 	{
-	    sprintf(fgbuf, "guifg=#%06x", fg & 0xFFFFFF);
-	    sprintf(bgbuf, "guibg=#%06x", bg & 0xFFFFFF);
+	    char fgbuf[2 * (8 + MAX_COLOR_LENGTH) + 1];
+	    char bgbuf[2 * (8 + MAX_COLOR_LENGTH) + 1];
+	    char *ptr;
+	    int value;
+
+	    value = strtol((char *)fg, &ptr, 10);
+	    if (ptr != (char *)fg)
+		sprintf(fgbuf, "guifg=#%06x", value & 0xFFFFFF);
+	    else
+		sprintf(fgbuf, "guifg=%s ctermfg=%s", fg, fg);
+
+	    value = strtol((char *)bg, &ptr, 10);
+	    if (ptr != (char *)bg)
+		sprintf(bgbuf, "guibg=#%06x", value & 0xFFFFFF);
+	    else
+		sprintf(bgbuf, "guibg=%s ctermbg=%s", bg, bg);
 
 	    coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "",
 		     (use_bg) ? bgbuf : "");
@@ -3674,7 +3694,8 @@
     }
     if (!buf->bufp->b_start_eol)
     {
-	STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]"));
+	STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]")
+					       : _("[Incomplete last line]"));
 	c = TRUE;
     }
     msg_add_lines(c, (long)lnum, nchars);
@@ -3689,8 +3710,9 @@
 
 
 /*
- * Print a message after NetBeans writes the file. This message should be identical
- * to the standard message a non-netbeans user would see when writing a file.
+ * Print a message after NetBeans writes the file. This message should be
+ * identical to the standard message a non-netbeans user would see when
+ * writing a file.
  */
     static void
 print_save_msg(buf, nchars)
@@ -3702,7 +3724,8 @@
 
     if (nchars >= 0)
     {
-	msg_add_fname(buf->bufp, buf->bufp->b_ffname);   /* fname in IObuff with quotes */
+	/* put fname in IObuff with quotes */
+	msg_add_fname(buf->bufp, buf->bufp->b_ffname);
 	c = FALSE;
 
 	msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
diff --git a/src/os_unix.c b/src/os_unix.c
index 5e11eea..5059ab1 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -220,7 +220,7 @@
 {
     SmcConn smcconn;	    /* The SM connection ID */
     IceConn iceconn;	    /* The ICE connection ID */
-    char *clientid;         /* The client ID for the current smc session */
+    char *clientid;	    /* The client ID for the current smc session */
     Bool save_yourself;     /* If we're in the middle of a save_yourself */
     Bool shutdown;	    /* If we're in shutdown mode */
 } xsmp_config_T;
@@ -366,6 +366,12 @@
 {
     int		len;
 
+#ifdef FEAT_NETBEANS_INTG
+    /* Process the queued netbeans messages. */
+    if (usingNetbeans)
+	netbeans_parse_messages();
+#endif
+
     /* Check if window changed size while we were busy, perhaps the ":set
      * columns=99" command was used. */
     while (do_resize)
@@ -378,6 +384,11 @@
 	    if (!do_resize)	/* return if not interrupted by resize */
 		return 0;
 	    handle_resize();
+#ifdef FEAT_NETBEANS_INTG
+	    /* Process the queued netbeans messages. */
+	    if (usingNetbeans)
+		netbeans_parse_messages();
+#endif
 	}
     }
     else	/* wtime == -1 */
@@ -407,12 +418,22 @@
     {
 	while (do_resize)    /* window changed size */
 	    handle_resize();
+
+#ifdef FEAT_NETBEANS_INTG
+	/* Process the queued netbeans messages. */
+	if (usingNetbeans)
+	    netbeans_parse_messages();
+#endif
 	/*
 	 * we want to be interrupted by the winch signal
+	 * or by an event on the monitored file descriptors
 	 */
-	WaitForChar(-1L);
-	if (do_resize)	    /* interrupted by SIGWINCH signal */
-	    continue;
+	if (WaitForChar(-1L) == 0)
+	{
+	    if (do_resize)	    /* interrupted by SIGWINCH signal */
+		handle_resize();
+	    return 0;
+	}
 
 	/* If input was put directly in typeahead buffer bail out here. */
 	if (typebuf_changed(tb_change_cnt))
@@ -1324,7 +1345,7 @@
  *			     return TRUE
  * "when" == SIGNAL_BLOCK:   Going to be busy, block signals
  * "when" == SIGNAL_UNBLOCK: Going to wait, unblock signals, use postponed
- *                           signal
+ *			     signal
  * Returns TRUE when Vim should exit.
  */
     int
@@ -4766,6 +4787,9 @@
     int		*check_for_gpm UNUSED;
 {
     int		ret;
+#ifdef FEAT_NETBEANS_INTG
+    int		nb_fd = (usingNetbeans ? netbeans_filedesc() : -1);
+#endif
 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME)
     static int	busy = FALSE;
 
@@ -4815,7 +4839,7 @@
 # endif
 #endif
 #ifndef HAVE_SELECT
-	struct pollfd   fds[5];
+	struct pollfd   fds[6];
 	int		nfd;
 # ifdef FEAT_XCLIPBOARD
 	int		xterm_idx = -1;
@@ -4826,6 +4850,9 @@
 # ifdef USE_XSMP
 	int		xsmp_idx = -1;
 # endif
+# ifdef FEAT_NETBEANS_INTG
+	int		nb_idx = -1;
+# endif
 	int		towait = (int)msec;
 
 # ifdef FEAT_MZSCHEME
@@ -4876,6 +4903,15 @@
 	    nfd++;
 	}
 # endif
+#ifdef FEAT_NETBEANS_INTG
+	if (nb_fd != -1)
+	{
+	    nb_idx = nfd;
+	    fds[nfd].fd = nb_fd;
+	    fds[nfd].events = POLLIN;
+	    nfd++;
+	}
+#endif
 
 	ret = poll(fds, nfd, towait);
 # ifdef FEAT_MZSCHEME
@@ -4929,6 +4965,13 @@
 		finished = FALSE;	/* Try again */
 	}
 # endif
+#ifdef FEAT_NETBEANS_INTG
+	if (ret > 0 && nb_idx != -1 && fds[nb_idx].revents & POLLIN)
+	{
+	    netbeans_read();
+	    --ret;
+	}
+#endif
 
 
 #else /* HAVE_SELECT */
@@ -5010,6 +5053,14 @@
 		maxfd = xsmp_icefd;
 	}
 # endif
+#ifdef FEAT_NETBEANS_INTG
+	if (nb_fd != -1)
+	{
+	    FD_SET(nb_fd, &rfds);
+	    if (maxfd < nb_fd)
+		maxfd = nb_fd;
+	}
+#endif
 
 # ifdef OLD_VMS
 	/* Old VMS as v6.2 and older have broken select(). It waits more than
@@ -5087,6 +5138,13 @@
 	    }
 	}
 # endif
+#ifdef FEAT_NETBEANS_INTG
+	if (ret > 0 && nb_fd != -1 && FD_ISSET(nb_fd, &rfds))
+	{
+	    netbeans_read();
+	    --ret;
+	}
+#endif
 
 #endif /* HAVE_SELECT */
 
diff --git a/src/proto.h b/src/proto.h
index dd2e146..2b248a5 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -181,6 +181,16 @@
 #  include "if_ruby.pro"
 # endif
 
+/* Ugly solution for "BalloonEval" not being defined while it's used in some
+ * .pro files. */
+# ifndef FEAT_BEVAL
+#  define BalloonEval int
+# endif
+
+# ifdef FEAT_NETBEANS_INTG
+#  include "netbeans.pro"
+# endif
+
 # ifdef FEAT_GUI
 #  include "gui.pro"
 #  if defined(UNIX) || defined(MACOS)
@@ -195,11 +205,6 @@
 #  ifdef FEAT_GUI_W16
 #   include "gui_w16.pro"
 #  endif
-    /* Ugly solution for "BalloonEval" not being defined while it's used in
-     * the prototypes. */
-#  ifndef FEAT_BEVAL
-#   define BalloonEval int
-#  endif
 #  ifdef FEAT_GUI_W32
 #   include "gui_w32.pro"
 #  endif
@@ -232,9 +237,6 @@
 #  ifdef FEAT_SUN_WORKSHOP
 #   include "workshop.pro"
 #  endif
-#  ifdef FEAT_NETBEANS_INTG
-#   include "netbeans.pro"
-#  endif
 # endif	/* FEAT_GUI */
 
 # ifdef FEAT_OLE
diff --git a/src/proto/netbeans.pro b/src/proto/netbeans.pro
index 789ac9f..e070c51 100644
--- a/src/proto/netbeans.pro
+++ b/src/proto/netbeans.pro
@@ -1,11 +1,13 @@
 /* netbeans.c */
 void netbeans_parse_messages __ARGS((void));
-void messageFromNetbeansW32 __ARGS((void));
+void netbeans_read __ARGS((void));
 int isNetbeansBuffer __ARGS((buf_T *bufp));
 int isNetbeansModified __ARGS((buf_T *bufp));
 void netbeans_end __ARGS((void));
 void ex_nbkey __ARGS((exarg_T *eap));
 void netbeans_beval_cb __ARGS((BalloonEval *beval, int state));
+int netbeans_filedesc __ARGS((void));
+void netbeans_gui_register __ARGS((void));
 void netbeans_startup_done __ARGS((void));
 void netbeans_send_disconnect __ARGS((void));
 void netbeans_frame_moved __ARGS((int new_x, int new_y));