To: vim-dev@vim.org Subject: Patch 6.1.390 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.390 (depends on 6.1.389) Problem: It's not possible to tell Vim to save and exit through the Netbeans interface. Would still try to send balloon eval text after the connection is closed. Can't use Unicode characters for sign text. Solution: Add functions "saveAndExit" and "getModified". Check for a working connection before sending a balloonText event. various other cleanups. Support any character for sign text. (Daniel Elstner) Files: runtime/doc/netbeans.txt, runtime/doc/sign.txt, src/ex_cmds.c, src/netbeans.c, src/screen.c *** ../vim61.389/runtime/doc/netbeans.txt Sat Mar 8 20:33:31 2003 --- runtime/doc/netbeans.txt Wed Mar 12 12:39:30 2003 *************** *** 1,4 **** ! *netbeans.txt* For Vim version 6.1. Last change: 2003 Mar 06 VIM REFERENCE MANUAL by Gordon Prieur --- 1,4 ---- ! *netbeans.txt* For Vim version 6.1. Last change: 2003 Mar 12 VIM REFERENCE MANUAL by Gordon Prieur *************** *** 448,453 **** --- 448,464 ---- getDot Not implemented. + getCursor Return the current buffer and cursor position. + The reply is: + seqno bufID lnum col off + seqno = sequence number of the function + bufID = buffer ID of the current buffer (if this is unknown -1 + is used) + lnum = line number of the cursor (first line is one) + col = column number of the cursor (in bytes, zero based) + off = offset of the cursor in the buffer (in bytes) + New in version 2.1. + getLength Return the length of the buffer in bytes. Reply example for a buffer with 5000 bytes: 123 5000 *************** *** 455,460 **** --- 466,478 ---- getMark Not implemented. + getModified When a buffer is specified: Return zero if the buffer does not + have changes, one if it does have changes. + When no buffer is specified (buffer number zero): Return the + number of buffers with changes. When the result is zero it's + safe to tell Vim to exit. + New in version 2.1. + getText Return the contents of the buffer as a string. Reply example for a buffer with two lines 123 "first line\nsecond line\n" *************** *** 477,482 **** --- 495,508 ---- 123 !message failed Note that the message in the reply is not quoted. + saveAndExit Perform the equivalent of closing Vim: ":confirm qall". + If there are no changed files or the user does not cancel the + operation Vim exits and no result is sent back. The IDE can + consider closing the connection as a successful result. + If the user cancels the operation the number of modified + buffers that remains is returned and Vim does not exit. + New in version 2.1. + 10.5 Events *nb-events* *************** *** 592,597 **** --- 618,628 ---- DISCONNECT IDE -> editor: break the connection. The editor will exit. The IDE must only send this message when there are no unsaved changes! + + DETACH IDE -> editor: break the connection without exiting the + editor. Used when the IDE exits without bringing down the + editor as well. + New in version 2.1. REJECT Not used. *** ../vim61.389/runtime/doc/sign.txt Fri Mar 22 21:18:38 2002 --- runtime/doc/sign.txt Wed Mar 12 17:56:13 2003 *************** *** 1,4 **** ! *sign.txt* For Vim version 6.1. Last change: 2002 Feb 24 VIM REFERENCE MANUAL by Gordon Prieur --- 1,4 ---- ! *sign.txt* For Vim version 6.1. Last change: 2003 Mar 12 VIM REFERENCE MANUAL by Gordon Prieur *************** *** 31,37 **** Signs and highlights are not useful just for debuggers. Sun's Visual WorkShop uses signs and highlights to mark build errors and SourceBrowser hits. Additionally, the debugger supports 8 to 10 different signs and ! highlight colors. |workshop| There are two steps in using signs: --- 31,37 ---- Signs and highlights are not useful just for debuggers. Sun's Visual WorkShop uses signs and highlights to mark build errors and SourceBrowser hits. Additionally, the debugger supports 8 to 10 different signs and ! highlight colors. |workshop| Same for Netbeans |netbeans|. There are two steps in using signs: *************** *** 50,55 **** --- 50,64 ---- ============================================================================== 2. Commands *sign-commands* *:sig* *:sign* + Here is an example that places a sign piet, displayed with the text ">>", in + line 23 of the current file: > + :sign define piet text=>> texthl=Search + :exe ":sign place 2 line=23 name=piet file=" . expand("%:p") + + And here is the command to delete it again: > + :sign unplace 2 + + DEFINING A SIGN. *:sign-define* *E255* *E160* :sign define {name} {argument}... *************** *** 72,79 **** text={text} *E239* Define the text that is displayed when there is no icon or the ! GUI is not being used. Thus currently must be two ASCII ! characters. texthl={group} Highlighting group used for the text item. --- 86,93 ---- text={text} *E239* Define the text that is displayed when there is no icon or the ! GUI is not being used. Only printable characters are allowed ! and they must occupy one or two display cells. texthl={group} Highlighting group used for the text item. *** ../vim61.389/src/ex_cmds.c Sat Mar 8 20:33:31 2003 --- src/ex_cmds.c Wed Mar 12 18:02:54 2003 *************** *** 5276,5291 **** } else if (STRNCMP(arg, "text=", 5) == 0) { arg += 5; ! /* Currently must have two printable characters. */ ! if (!vim_isprintc(arg[0]) || !vim_isprintc(arg[1]) ! || p - arg != 2) { EMSG2(_("E239: Invalid sign text: %s"), arg); return; } vim_free(sp->sn_text); ! sp->sn_text = vim_strnsave(arg, (int)(p - arg)); } else if (STRNCMP(arg, "linehl=", 7) == 0) { --- 5276,5322 ---- } else if (STRNCMP(arg, "text=", 5) == 0) { + char_u *s; + int cells; + int len; + arg += 5; ! #ifdef FEAT_MBYTE ! /* Count cells and check for non-printable chars */ ! if (has_mbyte) ! { ! cells = 0; ! for (s = arg; s < p; s += (*mb_ptr2len_check)(s)) ! { ! if (!vim_isprintc((*mb_ptr2char)(s))) ! break; ! cells += (*mb_ptr2cells)(s); ! } ! } ! else ! #endif { + for (s = arg; s < p; ++s) + if (!vim_isprintc(*s)) + break; + cells = s - arg; + } + /* Currently must be one or two display cells */ + if (s != p || cells < 1 || cells > 2) + { + *p = NUL; EMSG2(_("E239: Invalid sign text: %s"), arg); return; } + vim_free(sp->sn_text); ! /* Allocate one byte more if we need to pad up ! * with a space. */ ! len = p - arg + ((cells == 1) ? 1 : 0); ! sp->sn_text = vim_strnsave(arg, len); ! ! if (sp->sn_text != NULL && cells == 1) ! STRCPY(sp->sn_text + len - 1, " "); } else if (STRNCMP(arg, "linehl=", 7) == 0) { *** ../vim61.389/src/netbeans.c Tue Mar 11 12:59:06 2003 --- src/netbeans.c Wed Mar 12 16:43:31 2003 *************** *** 69,75 **** static gint inputHandler; /* Cookie for input */ #endif static int cmdno; /* current command number for reply */ - static int needGraphicsInit = 1; static int haveConnection = FALSE; /* socket is connected and initialization is done */ static int oldFire = 1; --- 69,74 ---- *************** *** 646,651 **** --- 645,659 ---- /* NOTREACHED */ } + if (STRCMP(cmd, "DETACH") == 0) + { + /* The IDE is breaking the connection. */ + if (sd >= 0) + close(sd); + netbeans_disconnect(); + return; + } + bufno = strtol((char *)cmd, (char **)&verb, 10); if (*verb != ':') *************** *** 779,784 **** --- 787,808 ---- } /* + * Return the number of buffers that are modified. + */ + static int + count_changed_buffers(void) + { + buf_T *bufp; + int n; + + n = 0; + for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next) + if (bufp->b_changed) + ++n; + return n; + } + + /* * End the netbeans session. */ void *************** *** 833,839 **** static void nb_reply_nil(int cmdno) { ! static char reply[32]; if (!haveConnection) return; --- 857,863 ---- static void nb_reply_nil(int cmdno) { ! char reply[32]; if (!haveConnection) return; *************** *** 868,879 **** /* ! * Send a response with an integer result code. */ static void ! nb_reply_int(int cmdno, long result) { ! static char reply[32]; if (!haveConnection) return; --- 892,903 ---- /* ! * Send a response with a number result code. */ static void ! nb_reply_nr(int cmdno, long result) { ! char reply[32]; if (!haveConnection) return; *************** *** 882,888 **** nbdebug(("REPLY: %s", reply)); ! nb_send(reply, "nb_reply_int"); } --- 906,912 ---- nbdebug(("REPLY: %s", reply)); ! nb_send(reply, "nb_reply_nr"); } *************** *** 1011,1017 **** if (func) { /* =====================================================================*/ ! if (streq((char *)cmd, "getLength")) { long len = 0; --- 1035,1075 ---- if (func) { /* =====================================================================*/ ! if (streq((char *)cmd, "getModified")) ! { ! if (buf == NULL || buf->bufp == NULL) ! /* Return the number of buffers that are modified. */ ! nb_reply_nr(cmdno, (long)count_changed_buffers()); ! else ! /* Return whether the buffer is modified. */ ! nb_reply_nr(cmdno, (long)buf->bufp->b_changed); ! /* =====================================================================*/ ! } ! else if (streq((char *)cmd, "saveAndExit")) ! { ! /* Note: this will exit Vim if successful. */ ! coloncmd(":confirm qall"); ! ! /* We didn't exit: return the number of changed buffers. */ ! nb_reply_nr(cmdno, (long)count_changed_buffers()); ! /* =====================================================================*/ ! } ! else if (streq((char *)cmd, "getCursor")) ! { ! char_u text[200]; ! ! /* Note: nb_getbufno() may return -1. This indicates the IDE ! * didn't assign a number to the current buffer in response to a ! * fileOpened event. */ ! sprintf((char *)text, "%d %ld %d %ld", ! nb_getbufno(curbuf), ! (long)curwin->w_cursor.lnum, ! (int)curwin->w_cursor.col, ! pos2off(curbuf, &curwin->w_cursor)); ! nb_reply_text(cmdno, text); ! /* =====================================================================*/ ! } ! else if (streq((char *)cmd, "getLength")) { long len = 0; *************** *** 1031,1037 **** len += STRLEN(buf->partial_line); } } ! nb_reply_int(cmdno, len); /* =====================================================================*/ } else if (streq((char *)cmd, "getText")) --- 1089,1095 ---- len += STRLEN(buf->partial_line); } } ! nb_reply_nr(cmdno, len); /* =====================================================================*/ } else if (streq((char *)cmd, "getText")) *************** *** 1546,1552 **** --- 1604,1613 ---- #endif pos = get_off_or_lnum(buf->bufp, &args); if (pos) + { curwin->w_cursor = *pos; + check_cursor(); + } else nbdebug((" BAD POSITION in setDot: %s\n", s)); *************** *** 1745,1752 **** return OK; } ! if (needGraphicsInit) ! nb_init_graphics(); if (buf == NULL || buf->bufp == NULL) { --- 1806,1812 ---- return OK; } ! nb_init_graphics(); if (buf == NULL || buf->bufp == NULL) { *************** *** 2029,2073 **** static void nb_init_graphics(void) { ! /* char *basedir = "../../pixmaps/netbeans"; */ ! /* char buf[MAXPATHLEN]; */ ! /* nbdebug(("looking for pixmaps in %s/%s\n", rundir, basedir)); */ ! ! /* sprintf(buf, "%s/%s", rundir, basedir); */ ! ! /* if (access(buf, R_OK) < 0) { */ ! /* basedir = "../pixmaps/netbeans"; */ ! /* sprintf(buf, "%s/%s", rundir, basedir); */ ! /* nbdebug(("looking for pixmaps in %s/%s\n", rundir, basedir)); */ ! /* if (access(buf, R_OK) < 0) { */ ! /* fprintf(stderr, _("Cannot open pixmap directory.")); */ ! /* return; */ ! /* } */ ! /* } */ ! ! coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"); ! /* coloncmd(":highlight NBBreakpoint guibg=Red guifg=White"); */ ! /* coloncmd(":highlight NBCurrent guibg=Blue guifg=White"); */ ! /* coloncmd(":highlight NBError guibg=Yellow guifg=Black"); */ ! ! coloncmd(":sign define %d linehl=NBGuarded", ! GUARDED); ! /* coloncmd(":sign define %d icon=%s/%s/%s linehl=NBBreakpoint text=XX", */ ! /* BREAKPOINT, rundir, basedir, "enabled-breakpoint.xpm"); */ ! /* coloncmd(":sign define %d icon=%s/%s/%s linehl=NBCurrent text=->", */ ! /* CURRENT, rundir, basedir, "currentpc.xpm"); */ ! /* coloncmd(":sign define %d icon=%s/%s/%s linehl=NBError text=!!", */ ! /* ERROR, rundir, basedir, "error.xpm"); */ ! ! /* coloncmd(":sign define %d icon=%s/%s/%s linehl=NBBreakpoint", */ ! /* WASGUARDED+BREAKPOINT, rundir, basedir, "enabled-breakpoint.xpm"); */ ! /* coloncmd(":sign define %d icon=%s/%s/%s linehl=NBCurrent", */ ! /* WASGUARDED+CURRENT, rundir, basedir, "currentpc.xpm"); */ ! /* coloncmd(":sign define %d icon=%s/%s/%s linehl=NBError", */ ! /* WASGUARDED+ERROR, rundir, basedir, "error.xpm"); */ ! needGraphicsInit = 0; } /* --- 2089,2103 ---- static void nb_init_graphics(void) { ! static int did_init = FALSE; ! if (!did_init) ! { ! coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"); ! coloncmd(":sign define %d linehl=NBGuarded", GUARDED); ! did_init = TRUE; ! } } /* *************** *** 2160,2168 **** char buf[MAXPATHLEN * 2 + 25]; char_u *p; ! /* Don't do anything when 'ballooneval' is off or messages scrolled the ! * windows up. */ ! if (!p_beval || msg_scrolled > 0) return; if (gui_mch_get_beval_info(beval, &filename, &line, &text, &col) == OK) --- 2190,2198 ---- char buf[MAXPATHLEN * 2 + 25]; char_u *p; ! /* Don't do anything when 'ballooneval' is off, messages scrolled the ! * windows up or we have no connection. */ ! if (!p_beval || msg_scrolled > 0 || !haveConnection) return; if (gui_mch_get_beval_info(beval, &filename, &line, &text, &col) == OK) *** ../vim61.389/src/screen.c Sun Mar 9 17:49:38 2003 --- src/screen.c Wed Mar 12 17:58:30 2003 *************** *** 2864,2870 **** int_u icon_sign; # endif ! /* Draw two bytes with the sign value or blank. */ c_extra = ' '; char_attr = 0; n_extra = 2; --- 2865,2871 ---- int_u icon_sign; # endif ! /* Draw two cells with the sign value or blank. */ c_extra = ' '; char_attr = 0; n_extra = 2; *************** *** 2891,2896 **** --- 2892,2898 ---- { p_extra = sign_get_text(text_sign); c_extra = NUL; + n_extra = STRLEN(p_extra); char_attr = sign_get_attr(text_sign, FALSE); } } *** ../vim61.389/src/version.c Tue Mar 11 12:59:06 2003 --- src/version.c Wed Mar 12 18:46:52 2003 *************** *** 613,614 **** --- 613,616 ---- { /* Add new patch number below this line */ + /**/ + 390, /**/ -- Seen it all, done it all, can't remember most of it. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///