4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
10 Patch 6.2.194 (after 6.2.068)
11 Problem: For NetBeans, instead of writing the file and sending an event
12 about it, tell NetBeans to write the file.
13 Solution: Add the "save" command, "netbeansBuffer" command and
14 "buttonRelease" event to the netbeans protocol. Updated the
15 interface to version 2.2. (Gordon Prieur)
16 Also: open a fold when the cursor has been positioned.
17 Also: fix memory leak, free result of nb_quote().
18 Files: runtime/doc/netbeans.txt, src/fileio.c, src/netbeans.c,
19 src/normal.c, src/proto/netbeans.pro, src/structs.h
22 *** ../vim-6.2.193/runtime/doc/netbeans.txt Sun Oct 12 16:42:14 2003
23 --- runtime/doc/netbeans.txt Sat Jan 17 16:38:31 2004
26 ! *netbeans.txt* For Vim version 6.2. Last change: 2003 Sep 12
29 VIM REFERENCE MANUAL by Gordon Prieur
31 ! *netbeans.txt* For Vim version 6.2. Last change: 2004 Jan 17
34 VIM REFERENCE MANUAL by Gordon Prieur
37 6. Obtaining the External Editor Module |obtaining-exted|
38 7. Setting up NetBeans to run with Vim |netbeans-setup|
39 8. Messages |netbeans-messages|
40 ! 9. Running Vim from Netbeans |netbeans-run|
41 ! 10. Netbeans protocol |netbeans-protocol|
42 11. Known problems |netbeans-problems|
44 {Vi does not have any of these features}
46 6. Obtaining the External Editor Module |obtaining-exted|
47 7. Setting up NetBeans to run with Vim |netbeans-setup|
48 8. Messages |netbeans-messages|
49 ! 9. Running Vim from NetBeans |netbeans-run|
50 ! 10. NetBeans protocol |netbeans-protocol|
51 11. Known problems |netbeans-problems|
53 {Vi does not have any of these features}
57 NetBeans is an open source Integrated Development Environment developed
58 jointly by Sun Microsystems, Inc. and the netbeans.org developer community.
59 ! Initialy just a Java IDE, NetBeans has had C, C++, and Fortran support added
62 For more information visit the main NetBeans web site http://www.netbeans.org
65 NetBeans is an open source Integrated Development Environment developed
66 jointly by Sun Microsystems, Inc. and the netbeans.org developer community.
67 ! Initially just a Java IDE, NetBeans has had C, C++, and Fortran support added
70 For more information visit the main NetBeans web site http://www.netbeans.org
74 The Win32 support is now in beta stage.
76 ! To use XPM signs on Win32 (e.g. when using with Netbeans) you can compile
77 XPM by yourself or use precompiled libraries from http://iamphet.nm.ru/xpm
78 (for MS Visual C++) or http://gnuwin32.sourceforge.net (for MinGW).
82 The Win32 support is now in beta stage.
84 ! To use XPM signs on Win32 (e.g. when using with NetBeans) you can compile
85 XPM by yourself or use precompiled libraries from http://iamphet.nm.ru/xpm
86 (for MS Visual C++) or http://gnuwin32.sourceforge.net (for MinGW).
90 Unfortunately, some versions do not have this module in their update
91 center. If you cannot download via the update center you will need to
92 download sources and build the module. I will try and get the module
93 ! available from the NetBeans Update Center so building will be unnecesary.
94 Also check http://externaleditor.netbeans.org for other availability options.
96 To download the External Editor sources via CVS and build your own module,
98 Unfortunately, some versions do not have this module in their update
99 center. If you cannot download via the update center you will need to
100 download sources and build the module. I will try and get the module
101 ! available from the NetBeans Update Center so building will be unnecessary.
102 Also check http://externaleditor.netbeans.org for other availability options.
104 To download the External Editor sources via CVS and build your own module,
107 an Expert tab. In the Properties tab make sure the "Editor Type" is set
108 to "Vim". In the Expert tab make sure the "Vim Command" is correct.
110 ! You should be carefull if you change the "Vim Command". There are command
111 line options there which must be there for the connection to be properly
112 set up. You can change the command name but thats about it. If your gvim
113 can be found by your $PATH then the VIM Command can start with "gvim". If
115 an Expert tab. In the Properties tab make sure the "Editor Type" is set
116 to "Vim". In the Expert tab make sure the "Vim Command" is correct.
118 ! You should be careful if you change the "Vim Command". There are command
119 line options there which must be there for the connection to be properly
120 set up. You can change the command name but thats about it. If your gvim
121 can be found by your $PATH then the VIM Command can start with "gvim". If
124 ==============================================================================
125 8. Messages *netbeans-messages*
127 ! These messages are specific for Netbeans:
130 Region is guarded, cannot modify
131 ! Netbeans defines guarded areas in the text, which you cannot
134 ==============================================================================
135 ! 9. Running Vim from Netbeans *netbeans-run*
137 ! Netbeans starts Vim with the |-nb| argument. The full form is: >
138 -nb:{hostname}:{addr}:{password}
140 ! {hostname} is the name of the machine where Netbeans is running. When omitted
141 the environment variable "__NETBEANS_HOST" is used or the default "localhost".
143 ! {addr} is the port number for Netbeans. When omitted the environment variable
144 "__NETBEANS_SOCKET" is used or the default 3219.
146 ! {password} is the password for connecting to Netbeans. When omitted the
147 environment variable "__NETBEANS_VIM_PASSWORD" is used or "changeme".
149 ==============================================================================
150 ! 10. Netbeans protocol *netbeans-protocol*
152 ! The communication between Netbeans and Vim uses plain text messages. This
153 protocol was first designed to work with the external editor module of
154 ! Netbeans (see http://externaleditor.netbeans.org). Later it was extended to
155 work with Agide (A-A-P GUI IDE, see http://www.a-a-p.org). The extensions are
156 marked with "version 2.1".
158 The messages are currently sent over a socket. Since the messages are in
159 plain UTF-8 text this protocol could also be used with any other communication
162 ==============================================================================
163 8. Messages *netbeans-messages*
165 ! These messages are specific for NetBeans:
168 Region is guarded, cannot modify
169 ! NetBeans defines guarded areas in the text, which you cannot
173 + NetBeans dissallows writes of unmodified buffers
174 + NetBeans does not support writes of unmodified buffers that
175 + were opened from NetBeans.
178 + Partial writes disallowed for NetBeans buffers
179 + NetBeans does not support partial writes for buffers that were
180 + opened from NetBeans.
182 ==============================================================================
183 ! 9. Running Vim from NetBeans *netbeans-run*
185 ! NetBeans starts Vim with the |-nb| argument. The full form is: >
186 -nb:{hostname}:{addr}:{password}
188 ! {hostname} is the name of the machine where NetBeans is running. When omitted
189 the environment variable "__NETBEANS_HOST" is used or the default "localhost".
191 ! {addr} is the port number for NetBeans. When omitted the environment variable
192 "__NETBEANS_SOCKET" is used or the default 3219.
194 ! {password} is the password for connecting to NetBeans. When omitted the
195 environment variable "__NETBEANS_VIM_PASSWORD" is used or "changeme".
197 ==============================================================================
198 ! 10. NetBeans protocol *netbeans-protocol*
200 ! The communication between NetBeans and Vim uses plain text messages. This
201 protocol was first designed to work with the external editor module of
202 ! NetBeans (see http://externaleditor.netbeans.org). Later it was extended to
203 work with Agide (A-A-P GUI IDE, see http://www.a-a-p.org). The extensions are
204 marked with "version 2.1".
206 + Version 2.2 of the protocol has several minor changes which should only
207 + affect NetBeans users (ie, not Agide users). However, a bug was fixed which
208 + could cause confusion. The netbeans_saved() function sent a "save" protocol
209 + command. In protocol version 2.1 and earlier this was incorrectly interpreted
210 + as a notification that a write had taken place. In reality, it told NetBeans
211 + to save the file so multiple writes were being done. This caused various
212 + problems and has been fixed in 2.2. To decrease the likelyhood of this
213 + confusion happening again, netbeans_saved() has been renamed to
214 + netbeans_save_buffer().
216 The messages are currently sent over a socket. Since the messages are in
217 plain UTF-8 text this protocol could also be used with any other communication
221 typeNum number sequence number of the annotation
222 defined with defineAnnoType for this
224 ! off number offset where annotion is to be placed
226 In version 2.1 "lnum/col" can be used instead of "off".
229 typeNum number sequence number of the annotation
230 defined with defineAnnoType for this
232 ! off number offset where annotation is to be placed
234 In version 2.1 "lnum/col" can be used instead of "off".
239 create Creates a buffer without a name. Replaces the current buffer
240 (it's hidden when it was changed).
241 ! Netbeans uses this as the first command for a file that is
242 being opened. The sequence of commands could be:
244 setCaretListener (ignored)
247 create Creates a buffer without a name. Replaces the current buffer
248 (it's hidden when it was changed).
249 ! NetBeans uses this as the first command for a file that is
250 being opened. The sequence of commands could be:
252 setCaretListener (ignored)
255 moveAnnoToFront serNum
258 putBufferNumber pathname
259 Associate a buffer number with the Vim buffer by the name
260 "pathname", a string argument. To be used when the editor
261 ! repored editing another file to the IDE and the IDE needs to
262 tell the editor what buffer number it will use for this file.
263 Also marks the buffer as initialized.
266 moveAnnoToFront serNum
269 + netbeansBuffer isNetbeansBuffer
270 + If "isNetbeansBuffer" is "T" then this buffer is ``owned'' by
272 + New in version 2.2.
274 putBufferNumber pathname
275 Associate a buffer number with the Vim buffer by the name
276 "pathname", a string argument. To be used when the editor
277 ! reported editing another file to the IDE and the IDE needs to
278 tell the editor what buffer number it will use for this file.
279 Also marks the buffer as initialized.
284 Remove a previously place annotation for this buffer.
285 "serNum" is the same number used in addAnno.
287 + save Save the buffer when it was modified. The other side of the
288 + interface is expected to write the buffer and invoke
289 + "setModified" to reset the "changed" flag of the buffer.
290 + The writing is skipped when one of these conditions is true:
291 + - 'write' is not set
292 + - the buffer is read-only
293 + - the buffer does not have a file name
294 + - 'buftype' disallows writing
295 + New in version 2.2.
297 setAsUser Not implemented.
299 setBufferNumber pathname
304 Set the title for the buffer to "name", a string argument.
305 ! The title is only used for Netbeans functions, not by Vim.
308 When the boolean argument "visible" is "T", goto the buffer.
312 Set the title for the buffer to "name", a string argument.
313 ! The title is only used for NetBeans functions, not by Vim.
316 When the boolean argument "visible" is "T", goto the buffer.
323 + buttonRelease button lnum col
324 + Report which button was pressed and the location of the cursor
325 + at the time of the release. Only for buffers that are owned
326 + by NetBeans. This event is not sent if the button was
327 + released while the mouse was in the status line or in a
328 + separator line. If col is less than 1 the button release was
330 + New in version 2.2.
332 fileClosed Not implemented.
334 fileModified Not implemented.
337 A file was opened by the user.
339 pathname string name of the file
340 ! open boolean always "F"
341 modified boolean always "F"
343 geometry cols rows x y
345 A file was opened by the user.
347 pathname string name of the file
348 ! open boolean always "T"
349 modified boolean always "F"
351 geometry cols rows x y
354 Only fired when enabled, see "startDocumentListen".
356 version vers Report the version of the interface implementation. Vim
357 ! reports "2.1" (including the quotes).
360 10.6 Special messages *nb-special*
362 Only fired when enabled, see "startDocumentListen".
364 version vers Report the version of the interface implementation. Vim
365 ! reports "2.2" (including the quotes).
368 10.6 Special messages *nb-special*
369 *** ../vim-6.2.193/src/fileio.c Sun Jan 18 21:04:53 2004
370 --- src/fileio.c Thu Jan 15 22:07:40 2004
377 + #ifdef FEAT_NETBEANS_INTG
378 + if (usingNetbeans && isNetbeansBuffer(buf))
382 + if (buf->b_changed)
384 + netbeans_save_buffer(buf);
389 + errnum = (char_u *)"E656: ";
390 + errmsg = (char_u *)_("NetBeans dissallows writes of unmodified buffers");
397 + errnum = (char_u *)"E657: ";
398 + errmsg = (char_u *)_("Partial writes disallowed for NetBeans buffers");
405 if (shortmess(SHM_OVER) && !exiting)
406 msg_scroll = FALSE; /* overwrite previous file message */
411 unchanged(buf, TRUE);
413 - #ifdef FEAT_NETBEANS_INTG
414 - netbeans_saved(buf);
420 *** ../vim-6.2.193/src/netbeans.c Mon Dec 29 20:14:44 2003
421 --- src/netbeans.c Tue Jan 13 13:55:27 2004
425 /* The first implementation (working only with Netbeans) returned "1.1". The
426 * protocol implemented here also supports A-A-P. */
427 ! static char *ExtEdProtocolVersion = "2.1";
429 static long pos2off __ARGS((buf_T *, pos_T *));
430 static pos_T *off2pos __ARGS((buf_T *, long));
433 /* The first implementation (working only with Netbeans) returned "1.1". The
434 * protocol implemented here also supports A-A-P. */
435 ! static char *ExtEdProtocolVersion = "2.2";
437 static long pos2off __ARGS((buf_T *, pos_T *));
438 static pos_T *off2pos __ARGS((buf_T *, long));
443 cmdno = strtol((char *)q, (char **)&q, 10);
447 if (nb_do_cmd(bufno, verb, isfunc, cmdno, q) == FAIL)
449 nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd));
456 + * Is this a NetBeans-owned buffer?
459 + isNetbeansBuffer(buf_T *bufp)
461 + return bufp->b_netbeans_file;
465 * Given a Netbeans buffer number, return the netbeans buffer.
466 * Returns NULL for 0 or a negative number. A 0 bufno means a
467 * non-buffer related command has been sent.
473 ! nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s", p));
481 ! nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s\n",
488 off = strtol((char *)args, (char **)&args, 10);
490 /* get text to be inserted */
491 ! ++args; /* skip space */
492 args = to_free = (char_u *)nb_unquote(args, NULL);
494 if (buf == NULL || buf->bufp == NULL)
496 off = strtol((char *)args, (char **)&args, 10);
498 /* get text to be inserted */
499 ! args = skipwhite(args);
500 args = to_free = (char_u *)nb_unquote(args, NULL);
502 if (buf == NULL || buf->bufp == NULL)
507 vim_free(buf->displayname);
508 ! buf->displayname = nb_unquote(++args, NULL);
509 nbdebug((" SETTITLE %d %s\n", bufno, buf->displayname));
510 /* =====================================================================*/
515 vim_free(buf->displayname);
516 ! buf->displayname = nb_unquote(args, NULL);
517 nbdebug((" SETTITLE %d %s\n", bufno, buf->displayname));
518 /* =====================================================================*/
522 EMSG("E641: null buf in setBufferNumber");
525 ! to_free = (char_u *)nb_unquote(++args, NULL);
528 bufp = buflist_findname(to_free);
530 EMSG("E641: null buf in setBufferNumber");
533 ! to_free = (char_u *)nb_unquote(args, NULL);
536 bufp = buflist_findname(to_free);
541 vim_free(buf->displayname);
542 ! buf->displayname = nb_unquote(++args, NULL);
543 nbdebug((" SETFULLNAME %d %s\n", bufno, buf->displayname));
545 netbeansReadFile = 0; /* don't try to open disk file */
549 vim_free(buf->displayname);
550 ! buf->displayname = nb_unquote(args, NULL);
551 nbdebug((" SETFULLNAME %d %s\n", bufno, buf->displayname));
553 netbeansReadFile = 0; /* don't try to open disk file */
557 /* Edit a file: like create + setFullName + read the file. */
558 vim_free(buf->displayname);
559 ! buf->displayname = nb_unquote(++args, NULL);
560 nbdebug((" EDITFILE %d %s\n", bufno, buf->displayname));
561 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
562 ECMD_HIDE + ECMD_OLDBUF);
565 /* Edit a file: like create + setFullName + read the file. */
566 vim_free(buf->displayname);
567 ! buf->displayname = nb_unquote(args, NULL);
568 nbdebug((" EDITFILE %d %s\n", bufno, buf->displayname));
569 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
570 ECMD_HIDE + ECMD_OLDBUF);
574 else if (streq((char *)cmd, "setVisible"))
577 if (buf == NULL || buf->bufp == NULL)
579 /* EMSG("E645: null bufp in setVisible"); */
584 else if (streq((char *)cmd, "setModified"))
587 if (buf == NULL || buf->bufp == NULL)
589 /* EMSG("E646: null bufp in setModified"); */
593 if (balloonEval != NULL)
596 ! text = nb_unquote(++args, NULL);
598 gui_mch_post_balloon(balloonEval, (char_u *)text);
601 if (balloonEval != NULL)
604 ! text = nb_unquote(args, NULL);
606 gui_mch_post_balloon(balloonEval, (char_u *)text);
614 if (buf == NULL || buf->bufp == NULL)
616 EMSG("E647: null bufp in setDot");
622 /* =====================================================================*/
624 + else if (streq((char *)cmd, "save"))
626 + if (buf == NULL || buf->bufp == NULL)
628 + nbdebug((" null bufp in %s command", cmd));
632 + /* the following is taken from ex_cmds.c (do_wqall function) */
633 + if (bufIsChanged(buf->bufp))
635 + /* Only write if the buffer can be written. */
637 + && !buf->bufp->b_p_ro
638 + && buf->bufp->b_ffname != NULL
639 + #ifdef FEAT_QUICKFIX
640 + && !bt_dontwrite(buf->bufp)
644 + buf_write_all(buf->bufp, FALSE);
645 + #ifdef FEAT_AUTOCMD
646 + /* an autocommand may have deleted the buffer */
647 + if (!buf_valid(buf->bufp))
652 + /* =====================================================================*/
654 + else if (streq((char *)cmd, "netbeansBuffer"))
656 + if (buf == NULL || buf->bufp == NULL)
658 + nbdebug((" null bufp in %s command", cmd));
661 + buf->bufp->b_netbeans_file = *args == 'T' ? TRUE : FALSE;
662 + /* =====================================================================*/
664 else if (streq((char *)cmd, "version"))
666 nbdebug((" Version = %s\n", (char *) args));
669 sprintf(buffer, "0:fileOpened=%d \"%s\" %s %s\n",
672 ! "F", /* open in NetBeans */
677 sprintf(buffer, "0:fileOpened=%d \"%s\" %s %s\n",
680 ! "T", /* open in NetBeans */
690 + * Send a button release event back to netbeans. Its up to netbeans
691 + * to decide what to do (if anything) with this event.
694 + netbeans_button_release(int button)
699 + bufno = nb_getbufno(curbuf);
701 + if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
703 + int lnum = curwin->w_cursor.lnum;
704 + int col = mouse_col - curwin->w_wincol - (curwin->w_p_nu ? 9 : 1);
706 + sprintf(buf, "%d:buttonRelease=%d %d %d %d\n", bufno, cmdno, button, lnum, col);
707 + nbdebug(("EVT: %s", buf));
708 + nb_send(buf, "netbeans_button_release");
714 * Send a keypress event back to netbeans. This usualy simulates some
715 * kind of function key press.
719 * Send a save event to netbeans.
722 ! netbeans_saved(buf_T *bufp)
727 * Send a save event to netbeans.
730 ! netbeans_save_buffer(buf_T *bufp)
737 sprintf((char *)buf, "%d:save=%d\n", bufno, cmdno);
738 nbdebug(("EVT: %s", buf));
739 ! nb_send((char *)buf, "netbeans_saved");
745 sprintf((char *)buf, "%d:save=%d\n", bufno, cmdno);
746 nbdebug(("EVT: %s", buf));
747 ! nb_send((char *)buf, "netbeans_save_buffer");
751 *** ../vim-6.2.193/src/normal.c Sun Jan 18 21:27:18 2004
752 --- src/normal.c Sun Jan 18 18:49:04 2004
756 in_sep_line = (jump_flags & IN_SEP_LINE);
759 + #ifdef FEAT_NETBEANS_INTG
760 + if (usingNetbeans && isNetbeansBuffer(curbuf)
761 + && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE)))
763 + int key = KEY2TERMCAP1(c);
765 + if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE
766 + || key == (int)KE_RIGHTRELEASE)
767 + netbeans_button_release(which_button);
771 /* When jumping to another window, clear a pending operator. That's a bit
772 * friendlier than beeping and not jumping to that window. */
773 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
774 *** ../vim-6.2.193/src/proto/netbeans.pro Sun Oct 12 16:42:14 2003
775 --- src/proto/netbeans.pro Tue Jan 13 13:48:34 2004
779 void netbeans_gtk_connect __ARGS((void));
780 void netbeans_w32_connect __ARGS((void));
781 void messageFromNetbeansW32 __ARGS((void));
782 + int isNetbeansBuffer __ARGS((buf_T *bufp));
783 void netbeans_end __ARGS((void));
784 void netbeans_startup_done __ARGS((void));
785 void netbeans_frame_moved __ARGS((int new_x, int new_y));
788 void netbeans_inserted __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, int oldlen, char_u *txt, int newlen));
789 void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, long len));
790 void netbeans_unmodified __ARGS((buf_T *bufp));
791 void netbeans_keycommand __ARGS((int key));
792 ! void netbeans_saved __ARGS((buf_T *bufp));
793 void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
794 int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));
795 void netbeans_draw_multisign_indicator __ARGS((int row));
797 void netbeans_inserted __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, int oldlen, char_u *txt, int newlen));
798 void netbeans_removed __ARGS((buf_T *bufp, linenr_T linenr, colnr_T col, long len));
799 void netbeans_unmodified __ARGS((buf_T *bufp));
800 + void netbeans_button_release __ARGS((int button));
801 void netbeans_keycommand __ARGS((int key));
802 ! void netbeans_save_buffer __ARGS((buf_T *bufp));
803 void netbeans_deleted_all_lines __ARGS((buf_T *bufp));
804 int netbeans_is_guarded __ARGS((linenr_T top, linenr_T bot));
805 void netbeans_draw_multisign_indicator __ARGS((int row));
806 *** ../vim-6.2.193/src/structs.h Sun Jan 18 21:12:26 2004
807 --- src/structs.h Tue Jan 13 12:57:23 2004
811 signlist_T *b_signlist; /* list of signs to draw */
814 + #ifdef FEAT_NETBEANS_INTG
815 + int b_netbeans_file; /* TRUE when buffer is owned by NetBeans */
821 *** ../vim-6.2.193/src/version.c Sun Jan 18 21:27:18 2004
822 --- src/version.c Sun Jan 18 21:29:39 2004
826 { /* Add new patch number below this line */
832 `When any government, or any church for that matter, undertakes to say to
833 its subjects, "This you may not read, this you must not see, this you are
834 forbidden to know," the end result is tyranny and oppression no matter how
835 holy the motives' -- Robert A Heinlein, "If this goes on --"
837 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
838 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
839 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
840 \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///