blob: 759ffa61e129833663f7603e674714e1dbbab509 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 * Netbeans integration by David Weatherford
5 * Adopted for Win32 by Sergey Khorev
6 *
7 * Do ":help uganda" in Vim to read copying and usage conditions.
8 * Do ":help credits" in Vim to see a list of people who contributed.
9 */
10
11/*
12 * Implements client side of org.netbeans.modules.emacs editor
13 * integration protocol. Be careful! The protocol uses offsets
14 * which are *between* characters, whereas vim uses line number
15 * and column number which are *on* characters.
16 * See ":help netbeans-protocol" for explanation.
Bram Moolenaare3cc6d42011-10-20 21:58:34 +020017 *
18 * The Netbeans messages are received and queued in the gui event loop, or in
19 * the select loop when Vim runs in a terminal. These messages are processed
20 * by netbeans_parse_messages() which is invoked in the idle loop when Vim is
21 * waiting for user input. The function netbeans_parse_messages() is also
22 * called from the ":sleep" command, to allow the execution of test cases that
23 * may not invoke the idle loop.
Bram Moolenaar071d4272004-06-13 20:20:40 +000024 */
25
26#include "vim.h"
27
28#if defined(FEAT_NETBEANS_INTG) || defined(PROTO)
29
Bram Moolenaard04a0202016-01-26 23:30:18 +010030#ifndef WIN32
Bram Moolenaar3e53c702016-01-24 22:17:03 +010031# include <netdb.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000032# ifdef HAVE_LIBGEN_H
33# include <libgen.h>
34# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000035#endif
36
37#include "version.h"
38
Bram Moolenaar071d4272004-06-13 20:20:40 +000039#define GUARDED 10000 /* typenr for "guarded" annotation */
40#define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */
Bram Moolenaar67c53842010-05-22 18:28:27 +020041#define MAX_COLOR_LENGTH 32 /* max length of color name in defineAnnoType */
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
43/* The first implementation (working only with Netbeans) returned "1.1". The
44 * protocol implemented here also supports A-A-P. */
Bram Moolenaar67c53842010-05-22 18:28:27 +020045static char *ExtEdProtocolVersion = "2.5";
Bram Moolenaar071d4272004-06-13 20:20:40 +000046
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +010047static long pos2off(buf_T *, pos_T *);
48static pos_T *off2pos(buf_T *, long);
49static pos_T *get_off_or_lnum(buf_T *buf, char_u **argp);
50static long get_buf_size(buf_T *);
51static int netbeans_keystring(char_u *keystr);
52static void postpone_keycommand(char_u *keystr);
53static void special_keys(char_u *args);
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +010055static int netbeans_connect(char *, int);
56static int getConnInfo(char *file, char **host, char **port, char **password);
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +010058static void nb_init_graphics(void);
59static void coloncmd(char *cmd, ...);
60static void nb_set_curbuf(buf_T *buf);
61static void nb_parse_cmd(char_u *);
62static int nb_do_cmd(int, char_u *, int, int, char_u *);
63static void nb_send(char *buf, char *fun);
64static void nb_free(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
Bram Moolenaar77073442016-02-13 23:23:53 +010066#define NETBEANS_OPEN (channel_can_write_to(nb_channel))
67static channel_T *nb_channel = NULL;
Bram Moolenaar67c53842010-05-22 18:28:27 +020068
Bram Moolenaar89d40322006-08-29 15:30:07 +000069static int r_cmdno; /* current command number for reply */
Bram Moolenaar009b2592004-10-24 19:18:58 +000070static int dosetvisible = FALSE;
71
Bram Moolenaar071d4272004-06-13 20:20:40 +000072/*
73 * Include the debugging code if wanted.
74 */
75#ifdef NBDEBUG
76# include "nbdebug.c"
77#endif
78
Bram Moolenaarb26e6322010-05-22 21:34:09 +020079static int needupdate = 0;
80static int inAtomic = 0;
81
Bram Moolenaar7ad7d012010-11-16 15:49:02 +010082/*
Bram Moolenaard04a0202016-01-26 23:30:18 +010083 * Callback invoked when the channel is closed.
Bram Moolenaar7ad7d012010-11-16 15:49:02 +010084 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000085 static void
Bram Moolenaard04a0202016-01-26 23:30:18 +010086nb_channel_closed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000087{
Bram Moolenaar77073442016-02-13 23:23:53 +010088 nb_channel = NULL;
Bram Moolenaar7ad7d012010-11-16 15:49:02 +010089}
90
91/*
92 * Close the connection and cleanup.
Bram Moolenaard04a0202016-01-26 23:30:18 +010093 * May be called when the socket was closed earlier.
Bram Moolenaar7ad7d012010-11-16 15:49:02 +010094 */
95 static void
96netbeans_close(void)
97{
98 if (NETBEANS_OPEN)
99 {
100 netbeans_send_disconnect();
Bram Moolenaar77073442016-02-13 23:23:53 +0100101 if (nb_channel != NULL)
Bram Moolenaard04a0202016-01-26 23:30:18 +0100102 /* Close the socket and remove the input handlers. */
Bram Moolenaar77073442016-02-13 23:23:53 +0100103 channel_close(nb_channel);
104 nb_channel = NULL;
Bram Moolenaar7ad7d012010-11-16 15:49:02 +0100105 }
106
Bram Moolenaar67c53842010-05-22 18:28:27 +0200107#ifdef FEAT_BEVAL
Bram Moolenaard62bec82005-03-07 22:56:57 +0000108 bevalServers &= ~BEVAL_NETBEANS;
Bram Moolenaar67c53842010-05-22 18:28:27 +0200109#endif
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200110
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200111 needupdate = 0;
112 inAtomic = 0;
113 nb_free();
114
115 /* remove all signs and update the screen after gutter removal */
116 coloncmd(":sign unplace *");
117 changed_window_setting();
118 update_screen(CLEAR);
119 setcursor();
Bram Moolenaar96bcc5e2011-04-01 15:33:59 +0200120 cursor_on();
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200121 out_flush();
122#ifdef FEAT_GUI
Bram Moolenaard54a6882010-08-09 22:49:00 +0200123 if (gui.in_use)
124 {
125 gui_update_cursor(TRUE, FALSE);
126 gui_mch_flush();
127 }
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130
131#define NB_DEF_HOST "localhost"
132#define NB_DEF_ADDR "3219"
133#define NB_DEF_PASS "changeme"
134
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200135 static int
Bram Moolenaarf506c5b2010-06-22 06:28:58 +0200136netbeans_connect(char *params, int doabort)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137{
Bram Moolenaard04a0202016-01-26 23:30:18 +0100138 int port;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139 char buf[32];
140 char *hostname = NULL;
141 char *address = NULL;
142 char *password = NULL;
143 char *fname;
144 char *arg = NULL;
145
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200146 if (*params == '=')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000147 {
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200148 /* "=fname": Read info from specified file. */
Bram Moolenaare0874f82016-01-24 20:36:41 +0100149 if (getConnInfo(params + 1, &hostname, &address, &password) == FAIL)
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200150 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151 }
152 else
153 {
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200154 if (*params == ':')
155 /* ":<host>:<addr>:<password>": get info from argument */
156 arg = params + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157 if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL)
158 {
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200159 /* "": get info from file specified in environment */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160 if (getConnInfo(fname, &hostname, &address, &password) == FAIL)
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200161 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162 }
163 else
164 {
165 if (arg != NULL)
166 {
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200167 /* ":<host>:<addr>:<password>": get info from argument */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168 hostname = arg;
169 address = strchr(hostname, ':');
170 if (address != NULL)
171 {
172 *address++ = '\0';
173 password = strchr(address, ':');
174 if (password != NULL)
175 *password++ = '\0';
176 }
177 }
178
179 /* Get the missing values from the environment. */
180 if (hostname == NULL || *hostname == '\0')
181 hostname = getenv("__NETBEANS_HOST");
182 if (address == NULL)
183 address = getenv("__NETBEANS_SOCKET");
184 if (password == NULL)
185 password = getenv("__NETBEANS_VIM_PASSWORD");
186
187 /* Move values to allocated memory. */
188 if (hostname != NULL)
189 hostname = (char *)vim_strsave((char_u *)hostname);
190 if (address != NULL)
191 address = (char *)vim_strsave((char_u *)address);
192 if (password != NULL)
193 password = (char *)vim_strsave((char_u *)password);
194 }
195 }
196
197 /* Use the default when a value is missing. */
198 if (hostname == NULL || *hostname == '\0')
199 {
200 vim_free(hostname);
201 hostname = (char *)vim_strsave((char_u *)NB_DEF_HOST);
202 }
203 if (address == NULL || *address == '\0')
204 {
205 vim_free(address);
206 address = (char *)vim_strsave((char_u *)NB_DEF_ADDR);
207 }
208 if (password == NULL || *password == '\0')
209 {
210 vim_free(password);
211 password = (char *)vim_strsave((char_u *)NB_DEF_PASS);
212 }
Bram Moolenaard04a0202016-01-26 23:30:18 +0100213 if (hostname != NULL && address != NULL && password != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214 {
Bram Moolenaard04a0202016-01-26 23:30:18 +0100215 port = atoi(address);
Bram Moolenaar77073442016-02-13 23:23:53 +0100216 nb_channel = channel_open(hostname, port, 0, nb_channel_closed);
217 if (nb_channel != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218 {
Bram Moolenaard04a0202016-01-26 23:30:18 +0100219 /* success */
220# ifdef FEAT_BEVAL
221 bevalServers |= BEVAL_NETBEANS;
222# endif
Bram Moolenaarc39125d2010-05-23 12:06:58 +0200223
Bram Moolenaard04a0202016-01-26 23:30:18 +0100224 /* success, login */
225 vim_snprintf(buf, sizeof(buf), "AUTH %s\n", password);
226 nb_send(buf, "netbeans_connect");
227
228 sprintf(buf, "0:version=0 \"%s\"\n", ExtEdProtocolVersion);
229 nb_send(buf, "externaleditor_version");
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230 }
231 }
232
Bram Moolenaar77073442016-02-13 23:23:53 +0100233 if (nb_channel == NULL && doabort)
Bram Moolenaard04a0202016-01-26 23:30:18 +0100234 getout(1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236 vim_free(hostname);
237 vim_free(address);
238 vim_free(password);
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200239 return NETBEANS_OPEN ? OK : FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240}
241
242/*
243 * Obtain the NetBeans hostname, port address and password from a file.
244 * Return the strings in allocated memory.
245 * Return FAIL if the file could not be read, OK otherwise (no matter what it
246 * contains).
247 */
248 static int
249getConnInfo(char *file, char **host, char **port, char **auth)
250{
251 FILE *fp;
252 char_u buf[BUFSIZ];
253 char_u *lp;
Bram Moolenaar309cbc32012-01-10 22:31:31 +0100254 char_u *nlp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255#ifdef UNIX
256 struct stat st;
257
258 /*
259 * For Unix only accept the file when it's not accessible by others.
260 * The open will then fail if we don't own the file.
261 */
262 if (mch_stat(file, &st) == 0 && (st.st_mode & 0077) != 0)
263 {
Bram Moolenaarf2330482008-06-24 20:19:36 +0000264 nbdebug(("Wrong access mode for NetBeans connection info file: \"%s\"\n",
265 file));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266 EMSG2(_("E668: Wrong access mode for NetBeans connection info file: \"%s\""),
267 file);
268 return FAIL;
269 }
270#endif
271
272 fp = mch_fopen(file, "r");
273 if (fp == NULL)
274 {
Bram Moolenaarf2330482008-06-24 20:19:36 +0000275 nbdebug(("Cannot open NetBeans connection info file\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 PERROR("E660: Cannot open NetBeans connection info file");
277 return FAIL;
278 }
279
280 /* Read the file. There should be one of each parameter */
281 while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL)
282 {
Bram Moolenaar309cbc32012-01-10 22:31:31 +0100283 if ((nlp = vim_strchr(lp, '\n')) != NULL)
284 *nlp = 0; /* strip off the trailing newline */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285
286 if (STRNCMP(lp, "host=", 5) == 0)
287 {
288 vim_free(*host);
289 *host = (char *)vim_strsave(&buf[5]);
290 }
291 else if (STRNCMP(lp, "port=", 5) == 0)
292 {
293 vim_free(*port);
294 *port = (char *)vim_strsave(&buf[5]);
295 }
296 else if (STRNCMP(lp, "auth=", 5) == 0)
297 {
298 vim_free(*auth);
299 *auth = (char *)vim_strsave(&buf[5]);
300 }
301 }
302 fclose(fp);
303
304 return OK;
305}
306
307
308struct keyqueue
309{
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100310 char_u *keystr;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311 struct keyqueue *next;
312 struct keyqueue *prev;
313};
314
315typedef struct keyqueue keyQ_T;
316
317static keyQ_T keyHead; /* dummy node, header for circular queue */
318
319
320/*
321 * Queue up key commands sent from netbeans.
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100322 * We store the string, because it may depend on the global mod_mask and
323 * :nbkey doesn't have a key number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324 */
325 static void
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100326postpone_keycommand(char_u *keystr)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000327{
328 keyQ_T *node;
329
330 node = (keyQ_T *)alloc(sizeof(keyQ_T));
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100331 if (node == NULL)
332 return; /* out of memory, drop the key */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333
334 if (keyHead.next == NULL) /* initialize circular queue */
335 {
336 keyHead.next = &keyHead;
337 keyHead.prev = &keyHead;
338 }
339
340 /* insert node at tail of queue */
341 node->next = &keyHead;
342 node->prev = keyHead.prev;
343 keyHead.prev->next = node;
344 keyHead.prev = node;
345
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100346 node->keystr = vim_strsave(keystr);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347}
348
349/*
350 * Handle any queued-up NetBeans keycommands to be send.
351 */
352 static void
353handle_key_queue(void)
354{
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100355 int postponed = FALSE;
356
357 while (!postponed && keyHead.next && keyHead.next != &keyHead)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358 {
359 /* first, unlink the node */
360 keyQ_T *node = keyHead.next;
361 keyHead.next = node->next;
362 node->next->prev = node->prev;
363
Bram Moolenaar8065d7f2010-01-19 15:13:14 +0100364 /* Now, send the keycommand. This may cause it to be postponed again
365 * and change keyHead. */
366 if (node->keystr != NULL)
367 postponed = !netbeans_keystring(node->keystr);
368 vim_free(node->keystr);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369
370 /* Finally, dispose of the node */
371 vim_free(node);
372 }
373}
374
375
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376/*
377 * While there's still a command in the work queue, parse and execute it.
378 */
Bram Moolenaarf2330482008-06-24 20:19:36 +0000379 void
380netbeans_parse_messages(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381{
Bram Moolenaard04a0202016-01-26 23:30:18 +0100382 char_u *buffer;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000383 char_u *p;
Bram Moolenaar863053d2010-12-02 17:09:54 +0100384 int own_node;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000385
Bram Moolenaar77073442016-02-13 23:23:53 +0100386 while (nb_channel != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387 {
Bram Moolenaar77073442016-02-13 23:23:53 +0100388 buffer = channel_peek(nb_channel);
Bram Moolenaard04a0202016-01-26 23:30:18 +0100389 if (buffer == NULL)
390 break; /* nothing to read */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000391
392 /* Locate the first line in the first buffer. */
Bram Moolenaard04a0202016-01-26 23:30:18 +0100393 p = vim_strchr(buffer, '\n');
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394 if (p == NULL)
395 {
396 /* Command isn't complete. If there is no following buffer,
397 * return (wait for more). If there is another buffer following,
398 * prepend the text to that buffer and delete this one. */
Bram Moolenaar77073442016-02-13 23:23:53 +0100399 if (channel_collapse(nb_channel) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000400 return;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000401 }
402 else
403 {
404 /* There is a complete command at the start of the buffer.
405 * Terminate it with a NUL. When no more text is following unlink
406 * the buffer. Do this before executing, because new buffers can
407 * be added while busy handling the command. */
408 *p++ = NUL;
409 if (*p == NUL)
410 {
Bram Moolenaar863053d2010-12-02 17:09:54 +0100411 own_node = TRUE;
Bram Moolenaar77073442016-02-13 23:23:53 +0100412 channel_get(nb_channel);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413 }
Bram Moolenaar863053d2010-12-02 17:09:54 +0100414 else
415 own_node = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416
417 /* now, parse and execute the commands */
Bram Moolenaard04a0202016-01-26 23:30:18 +0100418 nb_parse_cmd(buffer);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000419
Bram Moolenaar863053d2010-12-02 17:09:54 +0100420 if (own_node)
Bram Moolenaard04a0202016-01-26 23:30:18 +0100421 /* buffer finished, dispose of it */
422 vim_free(buffer);
423 else
424 /* more follows, move it to the start */
425 STRMOVE(buffer, p);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426 }
427 }
428}
429
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430/*
431 * Handle one NUL terminated command.
432 *
433 * format of a command from netbeans:
434 *
435 * 6:setTitle!84 "a.c"
436 *
437 * bufno
438 * colon
439 * cmd
440 * !
441 * cmdno
442 * args
443 *
444 * for function calls, the ! is replaced by a /
445 */
446 static void
447nb_parse_cmd(char_u *cmd)
448{
Bram Moolenaar349b2f62004-10-11 10:00:50 +0000449 char *verb;
450 char *q;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451 int bufno;
452 int isfunc = -1;
453
454 if (STRCMP(cmd, "DISCONNECT") == 0)
455 {
456 /* We assume the server knows that we can safely exit! */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457 /* Disconnect before exiting, Motif hangs in a Select error
458 * message otherwise. */
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200459 netbeans_close();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460 getout(0);
461 /* NOTREACHED */
462 }
463
Bram Moolenaard04a0202016-01-26 23:30:18 +0100464 if (STRCMP(cmd, "\"DETACH\"") == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465 {
Bram Moolenaard04a0202016-01-26 23:30:18 +0100466 buf_T *buf;
467
468 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
469 buf->b_has_sign_column = FALSE;
470
Bram Moolenaar071d4272004-06-13 20:20:40 +0000471 /* The IDE is breaking the connection. */
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200472 netbeans_close();
Bram Moolenaar071d4272004-06-13 20:20:40 +0000473 return;
474 }
475
Bram Moolenaar349b2f62004-10-11 10:00:50 +0000476 bufno = strtol((char *)cmd, &verb, 10);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000477
478 if (*verb != ':')
479 {
Bram Moolenaarf2330482008-06-24 20:19:36 +0000480 nbdebug((" missing colon: %s\n", cmd));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481 EMSG2("E627: missing colon: %s", cmd);
482 return;
483 }
484 ++verb; /* skip colon */
485
486 for (q = verb; *q; q++)
487 {
488 if (*q == '!')
489 {
490 *q++ = NUL;
491 isfunc = 0;
492 break;
493 }
494 else if (*q == '/')
495 {
496 *q++ = NUL;
497 isfunc = 1;
498 break;
499 }
500 }
501
502 if (isfunc < 0)
503 {
Bram Moolenaarf2330482008-06-24 20:19:36 +0000504 nbdebug((" missing ! or / in: %s\n", cmd));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 EMSG2("E628: missing ! or / in: %s", cmd);
506 return;
507 }
508
Bram Moolenaar89d40322006-08-29 15:30:07 +0000509 r_cmdno = strtol(q, &q, 10);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510
Bram Moolenaar349b2f62004-10-11 10:00:50 +0000511 q = (char *)skipwhite((char_u *)q);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512
Bram Moolenaar89d40322006-08-29 15:30:07 +0000513 if (nb_do_cmd(bufno, (char_u *)verb, isfunc, r_cmdno, (char_u *)q) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 {
Bram Moolenaar009b2592004-10-24 19:18:58 +0000515#ifdef NBDEBUG
516 /*
Bram Moolenaar2660c0e2010-01-19 14:59:56 +0100517 * This happens because the ExtEd can send a command or 2 after
Bram Moolenaar009b2592004-10-24 19:18:58 +0000518 * doing a stopDocumentListen command. It doesn't harm anything
519 * so I'm disabling it except for debugging.
520 */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521 nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd));
522 EMSG("E629: bad return from nb_do_cmd");
Bram Moolenaar009b2592004-10-24 19:18:58 +0000523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 }
525}
526
527struct nbbuf_struct
528{
529 buf_T *bufp;
530 unsigned int fireChanges:1;
531 unsigned int initDone:1;
Bram Moolenaar009b2592004-10-24 19:18:58 +0000532 unsigned int insertDone:1;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 unsigned int modified:1;
Bram Moolenaar009b2592004-10-24 19:18:58 +0000534 int nbbuf_number;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 char *displayname;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 int *signmap;
537 short_u signmaplen;
538 short_u signmapused;
539};
540
541typedef struct nbbuf_struct nbbuf_T;
542
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200543static nbbuf_T *buf_list = NULL;
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000544static int buf_list_size = 0; /* size of buf_list */
545static int buf_list_used = 0; /* nr of entries in buf_list actually in use */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200547static char **globalsignmap = NULL;
548static int globalsignmaplen = 0;
549static int globalsignmapused = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +0100551static int mapsigntype(nbbuf_T *, int localsigntype);
552static void addsigntype(nbbuf_T *, int localsigntype, char_u *typeName,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 char_u *tooltip, char_u *glyphfile,
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +0100554 char_u *fg, char_u *bg);
555static void print_read_msg(nbbuf_T *buf);
556static void print_save_msg(nbbuf_T *buf, off_t nchars);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557
558static int curPCtype = -1;
559
560/*
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200561 * Free netbeans resources.
562 */
563 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +0100564nb_free(void)
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200565{
566 keyQ_T *key_node = keyHead.next;
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200567 nbbuf_T buf;
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200568 int i;
569
570 /* free the netbeans buffer list */
571 for (i = 0; i < buf_list_used; i++)
572 {
573 buf = buf_list[i];
574 vim_free(buf.displayname);
575 vim_free(buf.signmap);
Bram Moolenaare980d8a2010-12-08 13:11:21 +0100576 if (buf.bufp != NULL)
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200577 {
578 buf.bufp->b_netbeans_file = FALSE;
579 buf.bufp->b_was_netbeans_file = FALSE;
580 }
581 }
582 vim_free(buf_list);
583 buf_list = NULL;
584 buf_list_size = 0;
585 buf_list_used = 0;
586
587 /* free the queued key commands */
Bram Moolenaar8d4eecc2012-11-20 17:19:01 +0100588 while (key_node != NULL && key_node != &keyHead)
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200589 {
590 keyQ_T *next = key_node->next;
591 vim_free(key_node->keystr);
592 vim_free(key_node);
593 if (next == &keyHead)
594 {
595 keyHead.next = &keyHead;
596 keyHead.prev = &keyHead;
597 break;
598 }
599 key_node = next;
600 }
601
602 /* free the queued netbeans commands */
Bram Moolenaar77073442016-02-13 23:23:53 +0100603 if (nb_channel != NULL)
604 channel_clear(nb_channel);
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200605}
606
607/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608 * Get the Netbeans buffer number for the specified buffer.
609 */
610 static int
611nb_getbufno(buf_T *bufp)
612{
613 int i;
614
615 for (i = 0; i < buf_list_used; i++)
616 if (buf_list[i].bufp == bufp)
617 return i;
618 return -1;
619}
620
621/*
622 * Is this a NetBeans-owned buffer?
623 */
624 int
625isNetbeansBuffer(buf_T *bufp)
626{
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200627 return NETBEANS_OPEN && bufp->b_netbeans_file;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628}
629
630/*
631 * NetBeans and Vim have different undo models. In Vim, the file isn't
632 * changed if changes are undone via the undo command. In NetBeans, once
633 * a change has been made the file is marked as modified until saved. It
634 * doesn't matter if the change was undone.
635 *
636 * So this function is for the corner case where Vim thinks a buffer is
637 * unmodified but NetBeans thinks it IS modified.
638 */
639 int
640isNetbeansModified(buf_T *bufp)
641{
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200642 if (isNetbeansBuffer(bufp))
Bram Moolenaar009b2592004-10-24 19:18:58 +0000643 {
644 int bufno = nb_getbufno(bufp);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645
Bram Moolenaar009b2592004-10-24 19:18:58 +0000646 if (bufno > 0)
647 return buf_list[bufno].modified;
648 else
649 return FALSE;
650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651 else
652 return FALSE;
653}
654
655/*
656 * Given a Netbeans buffer number, return the netbeans buffer.
657 * Returns NULL for 0 or a negative number. A 0 bufno means a
658 * non-buffer related command has been sent.
659 */
660 static nbbuf_T *
661nb_get_buf(int bufno)
662{
663 /* find or create a buffer with the given number */
664 int incr;
665
666 if (bufno <= 0)
667 return NULL;
668
669 if (!buf_list)
670 {
671 /* initialize */
672 buf_list = (nbbuf_T *)alloc_clear(100 * sizeof(nbbuf_T));
673 buf_list_size = 100;
674 }
675 if (bufno >= buf_list_used) /* new */
676 {
677 if (bufno >= buf_list_size) /* grow list */
678 {
Bram Moolenaar9abd5c62015-02-10 18:34:01 +0100679 nbbuf_T *t_buf_list = buf_list;
680
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 incr = bufno - buf_list_size + 90;
682 buf_list_size += incr;
683 buf_list = (nbbuf_T *)vim_realloc(
684 buf_list, buf_list_size * sizeof(nbbuf_T));
Bram Moolenaar9abd5c62015-02-10 18:34:01 +0100685 if (buf_list == NULL)
686 {
687 vim_free(t_buf_list);
688 buf_list_size = 0;
689 return NULL;
690 }
Bram Moolenaar7db5fc82010-05-24 11:59:29 +0200691 vim_memset(buf_list + buf_list_size - incr, 0,
692 incr * sizeof(nbbuf_T));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000693 }
694
695 while (buf_list_used <= bufno)
696 {
697 /* Default is to fire text changes. */
698 buf_list[buf_list_used].fireChanges = 1;
699 ++buf_list_used;
700 }
701 }
702
703 return buf_list + bufno;
704}
705
706/*
707 * Return the number of buffers that are modified.
708 */
709 static int
710count_changed_buffers(void)
711{
712 buf_T *bufp;
713 int n;
714
715 n = 0;
716 for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next)
717 if (bufp->b_changed)
718 ++n;
719 return n;
720}
721
722/*
723 * End the netbeans session.
724 */
725 void
726netbeans_end(void)
727{
728 int i;
729 static char buf[128];
730
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200731 if (!NETBEANS_OPEN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 return;
733
734 for (i = 0; i < buf_list_used; i++)
735 {
736 if (!buf_list[i].bufp)
737 continue;
738 if (netbeansForcedQuit)
739 {
740 /* mark as unmodified so NetBeans won't put up dialog on "killed" */
Bram Moolenaar89d40322006-08-29 15:30:07 +0000741 sprintf(buf, "%d:unmodified=%d\n", i, r_cmdno);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 nbdebug(("EVT: %s", buf));
743 nb_send(buf, "netbeans_end");
744 }
Bram Moolenaar89d40322006-08-29 15:30:07 +0000745 sprintf(buf, "%d:killed=%d\n", i, r_cmdno);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000746 nbdebug(("EVT: %s", buf));
Bram Moolenaarb26e6322010-05-22 21:34:09 +0200747 /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */
Bram Moolenaard04a0202016-01-26 23:30:18 +0100748 nb_send(buf, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750}
751
752/*
753 * Send a message to netbeans.
Bram Moolenaard04a0202016-01-26 23:30:18 +0100754 * When "fun" is NULL no error is given.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000755 */
756 static void
757nb_send(char *buf, char *fun)
758{
Bram Moolenaar77073442016-02-13 23:23:53 +0100759 if (nb_channel != NULL)
760 channel_send(nb_channel, (char_u *)buf, fun);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761}
762
763/*
764 * Some input received from netbeans requires a response. This function
765 * handles a response with no information (except the command number).
766 */
767 static void
768nb_reply_nil(int cmdno)
769{
770 char reply[32];
771
Bram Moolenaar009b2592004-10-24 19:18:58 +0000772 nbdebug(("REP %d: <none>\n", cmdno));
773
Bram Moolenaar7ad7d012010-11-16 15:49:02 +0100774 /* Avoid printing an annoying error message. */
775 if (!NETBEANS_OPEN)
776 return;
777
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778 sprintf(reply, "%d\n", cmdno);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779 nb_send(reply, "nb_reply_nil");
780}
781
782
783/*
784 * Send a response with text.
785 * "result" must have been quoted already (using nb_quote()).
786 */
787 static void
788nb_reply_text(int cmdno, char_u *result)
789{
790 char_u *reply;
791
Bram Moolenaar009b2592004-10-24 19:18:58 +0000792 nbdebug(("REP %d: %s\n", cmdno, (char *)result));
793
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000794 reply = alloc((unsigned)STRLEN(result) + 32);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795 sprintf((char *)reply, "%d %s\n", cmdno, (char *)result);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796 nb_send((char *)reply, "nb_reply_text");
797
798 vim_free(reply);
799}
800
801
802/*
803 * Send a response with a number result code.
804 */
805 static void
806nb_reply_nr(int cmdno, long result)
807{
808 char reply[32];
809
Bram Moolenaar009b2592004-10-24 19:18:58 +0000810 nbdebug(("REP %d: %ld\n", cmdno, result));
811
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812 sprintf(reply, "%d %ld\n", cmdno, result);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000813 nb_send(reply, "nb_reply_nr");
814}
815
816
817/*
818 * Encode newline, ret, backslash, double quote for transmission to NetBeans.
819 */
820 static char_u *
821nb_quote(char_u *txt)
822{
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000823 char_u *buf = alloc((unsigned)(2 * STRLEN(txt) + 1));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824 char_u *p = txt;
825 char_u *q = buf;
826
827 if (buf == NULL)
828 return NULL;
829 for (; *p; p++)
830 {
831 switch (*p)
832 {
833 case '\"':
834 case '\\':
835 *q++ = '\\'; *q++ = *p; break;
836 /* case '\t': */
837 /* *q++ = '\\'; *q++ = 't'; break; */
838 case '\n':
839 *q++ = '\\'; *q++ = 'n'; break;
840 case '\r':
841 *q++ = '\\'; *q++ = 'r'; break;
842 default:
843 *q++ = *p;
844 break;
845 }
846 }
Bram Moolenaar2660c0e2010-01-19 14:59:56 +0100847 *q = '\0';
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848
849 return buf;
850}
851
852
853/*
854 * Remove top level double quotes; convert backslashed chars.
855 * Returns an allocated string (NULL for failure).
856 * If "endp" is not NULL it is set to the character after the terminating
857 * quote.
858 */
859 static char *
860nb_unquote(char_u *p, char_u **endp)
861{
862 char *result = 0;
863 char *q;
864 int done = 0;
865
866 /* result is never longer than input */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000867 result = (char *)alloc_clear((unsigned)STRLEN(p) + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868 if (result == NULL)
869 return NULL;
870
871 if (*p++ != '"')
872 {
873 nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s\n",
874 p));
875 result[0] = NUL;
876 return result;
877 }
878
879 for (q = result; !done && *p != NUL;)
880 {
881 switch (*p)
882 {
883 case '"':
884 /*
885 * Unbackslashed dquote marks the end, if first char was dquote.
886 */
887 done = 1;
888 break;
889
890 case '\\':
891 ++p;
892 switch (*p)
893 {
894 case '\\': *q++ = '\\'; break;
895 case 'n': *q++ = '\n'; break;
896 case 't': *q++ = '\t'; break;
897 case 'r': *q++ = '\r'; break;
898 case '"': *q++ = '"'; break;
899 case NUL: --p; break;
900 /* default: skip over illegal chars */
901 }
902 ++p;
903 break;
904
905 default:
906 *q++ = *p++;
907 }
908 }
909
910 if (endp != NULL)
911 *endp = p;
912
913 return result;
914}
915
Bram Moolenaar5eaf8722008-01-05 17:07:13 +0000916/*
917 * Remove from "first" byte to "last" byte (inclusive), at line "lnum" of the
918 * current buffer. Remove to end of line when "last" is MAXCOL.
919 */
920 static void
921nb_partialremove(linenr_T lnum, colnr_T first, colnr_T last)
922{
923 char_u *oldtext, *newtext;
924 int oldlen;
925 int lastbyte = last;
926
927 oldtext = ml_get(lnum);
Bram Moolenaarcb4cef22008-03-16 15:04:34 +0000928 oldlen = (int)STRLEN(oldtext);
Bram Moolenaarb3c70982008-01-18 10:40:55 +0000929 if (first >= (colnr_T)oldlen || oldlen == 0) /* just in case */
Bram Moolenaar5eaf8722008-01-05 17:07:13 +0000930 return;
931 if (lastbyte >= oldlen)
932 lastbyte = oldlen - 1;
933 newtext = alloc(oldlen - (int)(lastbyte - first));
934 if (newtext != NULL)
935 {
936 mch_memmove(newtext, oldtext, first);
Bram Moolenaarf2330482008-06-24 20:19:36 +0000937 STRMOVE(newtext + first, oldtext + lastbyte + 1);
Bram Moolenaar5eaf8722008-01-05 17:07:13 +0000938 nbdebug((" NEW LINE %d: %s\n", lnum, newtext));
939 ml_replace(lnum, newtext, FALSE);
940 }
941}
942
943/*
944 * Replace the "first" line with the concatenation of the "first" and
945 * the "other" line. The "other" line is not removed.
946 */
947 static void
948nb_joinlines(linenr_T first, linenr_T other)
949{
950 int len_first, len_other;
951 char_u *p;
952
Bram Moolenaarcb4cef22008-03-16 15:04:34 +0000953 len_first = (int)STRLEN(ml_get(first));
954 len_other = (int)STRLEN(ml_get(other));
Bram Moolenaar5eaf8722008-01-05 17:07:13 +0000955 p = alloc((unsigned)(len_first + len_other + 1));
956 if (p != NULL)
957 {
958 mch_memmove(p, ml_get(first), len_first);
959 mch_memmove(p + len_first, ml_get(other), len_other + 1);
960 ml_replace(first, p, FALSE);
961 }
962}
963
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964#define SKIP_STOP 2
965#define streq(a,b) (strcmp(a,b) == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966
967/*
968 * Do the actual processing of a single netbeans command or function.
Bram Moolenaar143c38c2007-05-10 16:41:10 +0000969 * The difference between a command and function is that a function
970 * gets a response (it's required) but a command does not.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 * For arguments see comment for nb_parse_cmd().
972 */
973 static int
974nb_do_cmd(
975 int bufno,
976 char_u *cmd,
977 int func,
978 int cmdno,
979 char_u *args) /* points to space before arguments or NUL */
980{
Bram Moolenaar70b2a562012-01-10 22:26:17 +0100981 int do_update = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 long off = 0;
983 nbbuf_T *buf = nb_get_buf(bufno);
984 static int skip = 0;
985 int retval = OK;
Bram Moolenaar349b2f62004-10-11 10:00:50 +0000986 char *cp; /* for when a char pointer is needed */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987
988 nbdebug(("%s %d: (%d) %s %s\n", (func) ? "FUN" : "CMD", cmdno, bufno, cmd,
989 STRCMP(cmd, "insert") == 0 ? "<text>" : (char *)args));
990
991 if (func)
992 {
993/* =====================================================================*/
994 if (streq((char *)cmd, "getModified"))
995 {
996 if (buf == NULL || buf->bufp == NULL)
997 /* Return the number of buffers that are modified. */
998 nb_reply_nr(cmdno, (long)count_changed_buffers());
999 else
1000 /* Return whether the buffer is modified. */
1001 nb_reply_nr(cmdno, (long)(buf->bufp->b_changed
1002 || isNetbeansModified(buf->bufp)));
1003/* =====================================================================*/
1004 }
1005 else if (streq((char *)cmd, "saveAndExit"))
1006 {
1007 /* Note: this will exit Vim if successful. */
1008 coloncmd(":confirm qall");
1009
1010 /* We didn't exit: return the number of changed buffers. */
1011 nb_reply_nr(cmdno, (long)count_changed_buffers());
1012/* =====================================================================*/
1013 }
1014 else if (streq((char *)cmd, "getCursor"))
1015 {
1016 char_u text[200];
1017
1018 /* Note: nb_getbufno() may return -1. This indicates the IDE
1019 * didn't assign a number to the current buffer in response to a
1020 * fileOpened event. */
1021 sprintf((char *)text, "%d %ld %d %ld",
1022 nb_getbufno(curbuf),
1023 (long)curwin->w_cursor.lnum,
1024 (int)curwin->w_cursor.col,
1025 pos2off(curbuf, &curwin->w_cursor));
1026 nb_reply_text(cmdno, text);
1027/* =====================================================================*/
1028 }
Bram Moolenaarc65c4912006-11-14 17:29:46 +00001029 else if (streq((char *)cmd, "getAnno"))
1030 {
1031 long linenum = 0;
1032#ifdef FEAT_SIGNS
1033 if (buf == NULL || buf->bufp == NULL)
1034 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001035 nbdebug((" Invalid buffer identifier in getAnno\n"));
1036 EMSG("E652: Invalid buffer identifier in getAnno");
Bram Moolenaarc65c4912006-11-14 17:29:46 +00001037 retval = FAIL;
1038 }
1039 else
1040 {
1041 int serNum;
1042
1043 cp = (char *)args;
1044 serNum = strtol(cp, &cp, 10);
1045 /* If the sign isn't found linenum will be zero. */
1046 linenum = (long)buf_findsign(buf->bufp, serNum);
1047 }
1048#endif
1049 nb_reply_nr(cmdno, linenum);
1050/* =====================================================================*/
1051 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 else if (streq((char *)cmd, "getLength"))
1053 {
1054 long len = 0;
1055
1056 if (buf == NULL || buf->bufp == NULL)
1057 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001058 nbdebug((" invalid buffer identifier in getLength\n"));
1059 EMSG("E632: invalid buffer identifier in getLength");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 retval = FAIL;
1061 }
1062 else
1063 {
1064 len = get_buf_size(buf->bufp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 }
1066 nb_reply_nr(cmdno, len);
1067/* =====================================================================*/
1068 }
1069 else if (streq((char *)cmd, "getText"))
1070 {
1071 long len;
1072 linenr_T nlines;
1073 char_u *text = NULL;
1074 linenr_T lno = 1;
1075 char_u *p;
1076 char_u *line;
1077
1078 if (buf == NULL || buf->bufp == NULL)
1079 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001080 nbdebug((" invalid buffer identifier in getText\n"));
1081 EMSG("E633: invalid buffer identifier in getText");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 retval = FAIL;
1083 }
1084 else
1085 {
1086 len = get_buf_size(buf->bufp);
1087 nlines = buf->bufp->b_ml.ml_line_count;
1088 text = alloc((unsigned)((len > 0)
1089 ? ((len + nlines) * 2) : 4));
1090 if (text == NULL)
1091 {
1092 nbdebug((" nb_do_cmd: getText has null text field\n"));
1093 retval = FAIL;
1094 }
1095 else
1096 {
1097 p = text;
1098 *p++ = '\"';
1099 for (; lno <= nlines ; lno++)
1100 {
1101 line = nb_quote(ml_get_buf(buf->bufp, lno, FALSE));
1102 if (line != NULL)
1103 {
1104 STRCPY(p, line);
1105 p += STRLEN(line);
1106 *p++ = '\\';
1107 *p++ = 'n';
Bram Moolenaar009b2592004-10-24 19:18:58 +00001108 vim_free(line);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 }
1111 *p++ = '\"';
1112 *p = '\0';
1113 }
1114 }
1115 if (text == NULL)
1116 nb_reply_text(cmdno, (char_u *)"");
1117 else
1118 {
1119 nb_reply_text(cmdno, text);
1120 vim_free(text);
1121 }
1122/* =====================================================================*/
1123 }
1124 else if (streq((char *)cmd, "remove"))
1125 {
1126 long count;
1127 pos_T first, last;
1128 pos_T *pos;
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001129 pos_T *next;
1130 linenr_T del_from_lnum, del_to_lnum; /* lines to be deleted as a whole */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 int oldFire = netbeansFireChanges;
1132 int oldSuppress = netbeansSuppressNoLines;
1133 int wasChanged;
1134
1135 if (skip >= SKIP_STOP)
1136 {
1137 nbdebug((" Skipping %s command\n", (char *) cmd));
1138 nb_reply_nil(cmdno);
1139 return OK;
1140 }
1141
1142 if (buf == NULL || buf->bufp == NULL)
1143 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001144 nbdebug((" invalid buffer identifier in remove\n"));
1145 EMSG("E634: invalid buffer identifier in remove");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 retval = FAIL;
1147 }
1148 else
1149 {
1150 netbeansFireChanges = FALSE;
1151 netbeansSuppressNoLines = TRUE;
1152
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001153 nb_set_curbuf(buf->bufp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 wasChanged = buf->bufp->b_changed;
Bram Moolenaar349b2f62004-10-11 10:00:50 +00001155 cp = (char *)args;
1156 off = strtol(cp, &cp, 10);
1157 count = strtol(cp, &cp, 10);
1158 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 /* delete "count" chars, starting at "off" */
1160 pos = off2pos(buf->bufp, off);
1161 if (!pos)
1162 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001163 nbdebug((" !bad position\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 nb_reply_text(cmdno, (char_u *)"!bad position");
1165 netbeansFireChanges = oldFire;
1166 netbeansSuppressNoLines = oldSuppress;
1167 return FAIL;
1168 }
1169 first = *pos;
Bram Moolenaarfa68b0f2009-09-11 12:19:51 +00001170 nbdebug((" FIRST POS: line %d, col %d\n",
1171 first.lnum, first.col));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 pos = off2pos(buf->bufp, off+count-1);
1173 if (!pos)
1174 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001175 nbdebug((" !bad count\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 nb_reply_text(cmdno, (char_u *)"!bad count");
1177 netbeansFireChanges = oldFire;
1178 netbeansSuppressNoLines = oldSuppress;
1179 return FAIL;
1180 }
1181 last = *pos;
Bram Moolenaarfa68b0f2009-09-11 12:19:51 +00001182 nbdebug((" LAST POS: line %d, col %d\n",
1183 last.lnum, last.col));
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001184 del_from_lnum = first.lnum;
1185 del_to_lnum = last.lnum;
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001186 do_update = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001188 /* Get the position of the first byte after the deleted
1189 * section. "next" is NULL when deleting to the end of the
1190 * file. */
1191 next = off2pos(buf->bufp, off + count);
1192
1193 /* Remove part of the first line. */
Bram Moolenaarfa68b0f2009-09-11 12:19:51 +00001194 if (first.col != 0
1195 || (next != NULL && first.lnum == next->lnum))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001197 if (first.lnum != last.lnum
1198 || (next != NULL && first.lnum != next->lnum))
1199 {
1200 /* remove to the end of the first line */
1201 nb_partialremove(first.lnum, first.col,
1202 (colnr_T)MAXCOL);
1203 if (first.lnum == last.lnum)
1204 {
1205 /* Partial line to remove includes the end of
1206 * line. Join the line with the next one, have
1207 * the next line deleted below. */
1208 nb_joinlines(first.lnum, next->lnum);
1209 del_to_lnum = next->lnum;
1210 }
1211 }
1212 else
1213 {
1214 /* remove within one line */
1215 nb_partialremove(first.lnum, first.col, last.col);
1216 }
1217 ++del_from_lnum; /* don't delete the first line */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 }
1219
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001220 /* Remove part of the last line. */
1221 if (first.lnum != last.lnum && next != NULL
1222 && next->col != 0 && last.lnum == next->lnum)
1223 {
1224 nb_partialremove(last.lnum, 0, last.col);
1225 if (del_from_lnum > first.lnum)
1226 {
1227 /* Join end of last line to start of first line; last
1228 * line is deleted below. */
1229 nb_joinlines(first.lnum, last.lnum);
1230 }
1231 else
1232 /* First line is deleted as a whole, keep the last
1233 * line. */
1234 --del_to_lnum;
1235 }
1236
1237 /* First is partial line; last line to remove includes
1238 * the end of line; join first line to line following last
1239 * line; line following last line is deleted below. */
1240 if (first.lnum != last.lnum && del_from_lnum > first.lnum
1241 && next != NULL && last.lnum != next->lnum)
1242 {
1243 nb_joinlines(first.lnum, next->lnum);
1244 del_to_lnum = next->lnum;
1245 }
1246
1247 /* Delete whole lines if there are any. */
1248 if (del_to_lnum >= del_from_lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 {
1250 int i;
1251
1252 /* delete signs from the lines being deleted */
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001253 for (i = del_from_lnum; i <= del_to_lnum; i++)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254 {
1255 int id = buf_findsign_id(buf->bufp, (linenr_T)i);
1256 if (id > 0)
1257 {
Bram Moolenaarfa68b0f2009-09-11 12:19:51 +00001258 nbdebug((" Deleting sign %d on line %d\n",
1259 id, i));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 buf_delsign(buf->bufp, id);
1261 }
1262 else
Bram Moolenaarb85cb212009-05-17 14:24:23 +00001263 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 nbdebug((" No sign on line %d\n", i));
Bram Moolenaarb85cb212009-05-17 14:24:23 +00001265 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266 }
1267
Bram Moolenaarfa68b0f2009-09-11 12:19:51 +00001268 nbdebug((" Deleting lines %d through %d\n",
1269 del_from_lnum, del_to_lnum));
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001270 curwin->w_cursor.lnum = del_from_lnum;
1271 curwin->w_cursor.col = 0;
1272 del_lines(del_to_lnum - del_from_lnum + 1, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 }
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00001274
1275 /* Leave cursor at first deleted byte. */
1276 curwin->w_cursor = first;
1277 check_cursor_lnum();
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278 buf->bufp->b_changed = wasChanged; /* logically unchanged */
1279 netbeansFireChanges = oldFire;
1280 netbeansSuppressNoLines = oldSuppress;
1281
1282 u_blockfree(buf->bufp);
1283 u_clearall(buf->bufp);
1284 }
1285 nb_reply_nil(cmdno);
1286/* =====================================================================*/
1287 }
1288 else if (streq((char *)cmd, "insert"))
1289 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 char_u *to_free;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291
1292 if (skip >= SKIP_STOP)
1293 {
1294 nbdebug((" Skipping %s command\n", (char *) cmd));
1295 nb_reply_nil(cmdno);
1296 return OK;
1297 }
1298
1299 /* get offset */
Bram Moolenaar349b2f62004-10-11 10:00:50 +00001300 cp = (char *)args;
1301 off = strtol(cp, &cp, 10);
1302 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303
1304 /* get text to be inserted */
1305 args = skipwhite(args);
1306 args = to_free = (char_u *)nb_unquote(args, NULL);
Bram Moolenaar009b2592004-10-24 19:18:58 +00001307 /*
1308 nbdebug((" CHUNK[%d]: %d bytes at offset %d\n",
1309 buf->bufp->b_ml.ml_line_count, STRLEN(args), off));
1310 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311
1312 if (buf == NULL || buf->bufp == NULL)
1313 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001314 nbdebug((" invalid buffer identifier in insert\n"));
1315 EMSG("E635: invalid buffer identifier in insert");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 retval = FAIL;
1317 }
1318 else if (args != NULL)
1319 {
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001320 int ff_detected = EOL_UNKNOWN;
1321 int buf_was_empty = (buf->bufp->b_ml.ml_flags & ML_EMPTY);
1322 size_t len = 0;
1323 int added = 0;
1324 int oldFire = netbeansFireChanges;
1325 int old_b_changed;
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001326 char_u *nlp;
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001327 linenr_T lnum;
1328 linenr_T lnum_start;
1329 pos_T *pos;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 netbeansFireChanges = 0;
1332
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001333 /* Jump to the buffer where we insert. After this "curbuf"
1334 * can be used. */
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001335 nb_set_curbuf(buf->bufp);
Bram Moolenaara3227e22006-03-08 21:32:40 +00001336 old_b_changed = curbuf->b_changed;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001338 /* Convert the specified character offset into a lnum/col
1339 * position. */
Bram Moolenaara3227e22006-03-08 21:32:40 +00001340 pos = off2pos(curbuf, off);
1341 if (pos != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001343 if (pos->lnum <= 0)
1344 lnum_start = 1;
1345 else
1346 lnum_start = pos->lnum;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 }
1348 else
1349 {
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001350 /* If the given position is not found, assume we want
Bram Moolenaar071d4272004-06-13 20:20:40 +00001351 * the end of the file. See setLocAndSize HACK. */
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001352 if (buf_was_empty)
1353 lnum_start = 1; /* above empty line */
1354 else
1355 lnum_start = curbuf->b_ml.ml_line_count + 1;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001356 }
1357
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001358 /* "lnum" is the line where we insert: either append to it or
1359 * insert a new line above it. */
1360 lnum = lnum_start;
1361
1362 /* Loop over the "\n" separated lines of the argument. */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001363 do_update = 1;
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001364 while (*args != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001366 nlp = vim_strchr(args, '\n');
1367 if (nlp == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001369 /* Incomplete line, probably truncated. Next "insert"
1370 * command should append to this one. */
1371 len = STRLEN(args);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001373 else
1374 {
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001375 len = nlp - args;
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001376
1377 /*
1378 * We need to detect EOL style, because the commands
1379 * use a character offset.
1380 */
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001381 if (nlp > args && nlp[-1] == '\r')
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001382 {
1383 ff_detected = EOL_DOS;
1384 --len;
1385 }
1386 else
1387 ff_detected = EOL_UNIX;
1388 }
1389 args[len] = NUL;
1390
1391 if (lnum == lnum_start
1392 && ((pos != NULL && pos->col > 0)
1393 || (lnum == 1 && buf_was_empty)))
1394 {
1395 char_u *oldline = ml_get(lnum);
1396 char_u *newline;
1397
Bram Moolenaare4365282012-04-20 19:47:05 +02001398 /* Insert halfway a line. */
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001399 newline = alloc_check(
1400 (unsigned)(STRLEN(oldline) + len + 1));
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001401 if (newline != NULL)
1402 {
Bram Moolenaare4365282012-04-20 19:47:05 +02001403 mch_memmove(newline, oldline, (size_t)pos->col);
1404 newline[pos->col] = NUL;
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001405 STRCAT(newline, args);
Bram Moolenaare4365282012-04-20 19:47:05 +02001406 STRCAT(newline, oldline + pos->col);
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001407 ml_replace(lnum, newline, FALSE);
1408 }
1409 }
1410 else
1411 {
1412 /* Append a new line. Not that we always do this,
1413 * also when the text doesn't end in a "\n". */
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001414 ml_append((linenr_T)(lnum - 1), args,
1415 (colnr_T)(len + 1), FALSE);
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001416 ++added;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001417 }
1418
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001419 if (nlp == NULL)
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001420 break;
1421 ++lnum;
Bram Moolenaar309cbc32012-01-10 22:31:31 +01001422 args = nlp + 1;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001423 }
1424
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001425 /* Adjust the marks below the inserted lines. */
1426 appended_lines_mark(lnum_start - 1, (long)added);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001428 /*
1429 * When starting with an empty buffer set the fileformat.
1430 * This is just guessing...
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 */
1432 if (buf_was_empty)
1433 {
1434 if (ff_detected == EOL_UNKNOWN)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001435#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 ff_detected = EOL_DOS;
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001437#else
1438 ff_detected = EOL_UNIX;
1439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440 set_fileformat(ff_detected, OPT_LOCAL);
Bram Moolenaara3227e22006-03-08 21:32:40 +00001441 curbuf->b_start_ffc = *curbuf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 }
1443
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 /*
1445 * XXX - GRP - Is the next line right? If I've inserted
1446 * text the buffer has been updated but not written. Will
1447 * netbeans guarantee to write it? Even if I do a :q! ?
1448 */
Bram Moolenaara3227e22006-03-08 21:32:40 +00001449 curbuf->b_changed = old_b_changed; /* logically unchanged */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 netbeansFireChanges = oldFire;
1451
Bram Moolenaar0fd92892006-03-09 22:27:48 +00001452 /* Undo info is invalid now... */
Bram Moolenaara3227e22006-03-08 21:32:40 +00001453 u_blockfree(curbuf);
1454 u_clearall(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 }
1456 vim_free(to_free);
1457 nb_reply_nil(cmdno); /* or !error */
1458 }
1459 else
1460 {
1461 nbdebug(("UNIMPLEMENTED FUNCTION: %s\n", cmd));
1462 nb_reply_nil(cmdno);
1463 retval = FAIL;
1464 }
1465 }
1466 else /* Not a function; no reply required. */
1467 {
1468/* =====================================================================*/
1469 if (streq((char *)cmd, "create"))
1470 {
1471 /* Create a buffer without a name. */
1472 if (buf == NULL)
1473 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001474 nbdebug((" invalid buffer identifier in create\n"));
1475 EMSG("E636: invalid buffer identifier in create");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 return FAIL;
1477 }
1478 vim_free(buf->displayname);
1479 buf->displayname = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480
1481 netbeansReadFile = 0; /* don't try to open disk file */
Bram Moolenaar701f7af2008-11-15 13:12:07 +00001482 do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 netbeansReadFile = 1;
1484 buf->bufp = curbuf;
1485 maketitle();
Bram Moolenaar009b2592004-10-24 19:18:58 +00001486 buf->insertDone = FALSE;
Bram Moolenaar67c53842010-05-22 18:28:27 +02001487#if defined(FEAT_MENU) && defined(FEAT_GUI)
Bram Moolenaard54a6882010-08-09 22:49:00 +02001488 if (gui.in_use)
1489 gui_update_menus(0);
Bram Moolenaar67c53842010-05-22 18:28:27 +02001490#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491/* =====================================================================*/
1492 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001493 else if (streq((char *)cmd, "insertDone"))
1494 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001495 if (buf == NULL || buf->bufp == NULL)
1496 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001497 nbdebug((" invalid buffer identifier in insertDone\n"));
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001498 }
1499 else
1500 {
1501 buf->bufp->b_start_eol = *args == 'T';
1502 buf->insertDone = TRUE;
1503 args += 2;
1504 buf->bufp->b_p_ro = *args == 'T';
1505 print_read_msg(buf);
1506 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001507/* =====================================================================*/
1508 }
1509 else if (streq((char *)cmd, "saveDone"))
1510 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001511 long savedChars = atol((char *)args);
1512
1513 if (buf == NULL || buf->bufp == NULL)
1514 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001515 nbdebug((" invalid buffer identifier in saveDone\n"));
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001516 }
1517 else
1518 print_save_msg(buf, savedChars);
Bram Moolenaar009b2592004-10-24 19:18:58 +00001519/* =====================================================================*/
1520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 else if (streq((char *)cmd, "startDocumentListen"))
1522 {
1523 if (buf == NULL)
1524 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001525 nbdebug((" invalid buffer identifier in startDocumentListen\n"));
1526 EMSG("E637: invalid buffer identifier in startDocumentListen");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001527 return FAIL;
1528 }
1529 buf->fireChanges = 1;
1530/* =====================================================================*/
1531 }
1532 else if (streq((char *)cmd, "stopDocumentListen"))
1533 {
1534 if (buf == NULL)
1535 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001536 nbdebug((" invalid buffer identifier in stopDocumentListen\n"));
1537 EMSG("E638: invalid buffer identifier in stopDocumentListen");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 return FAIL;
1539 }
1540 buf->fireChanges = 0;
Bram Moolenaar24c088a2005-02-02 22:55:47 +00001541 if (buf->bufp != NULL && buf->bufp->b_was_netbeans_file)
Bram Moolenaar009b2592004-10-24 19:18:58 +00001542 {
Bram Moolenaar24c088a2005-02-02 22:55:47 +00001543 if (!buf->bufp->b_netbeans_file)
Bram Moolenaarf2330482008-06-24 20:19:36 +00001544 {
1545 nbdebug(("E658: NetBeans connection lost for buffer %ld\n", buf->bufp->b_fnum));
Bram Moolenaar009b2592004-10-24 19:18:58 +00001546 EMSGN(_("E658: NetBeans connection lost for buffer %ld"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 buf->bufp->b_fnum);
Bram Moolenaarf2330482008-06-24 20:19:36 +00001548 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001549 else
1550 {
Bram Moolenaar24c088a2005-02-02 22:55:47 +00001551 /* NetBeans uses stopDocumentListen when it stops editing
1552 * a file. It then expects the buffer in Vim to
1553 * disappear. */
1554 do_bufdel(DOBUF_DEL, (char_u *)"", 1,
1555 buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE);
Bram Moolenaar009b2592004-10-24 19:18:58 +00001556 vim_memset(buf, 0, sizeof(nbbuf_T));
1557 }
1558 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559/* =====================================================================*/
1560 }
1561 else if (streq((char *)cmd, "setTitle"))
1562 {
1563 if (buf == NULL)
1564 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001565 nbdebug((" invalid buffer identifier in setTitle\n"));
1566 EMSG("E639: invalid buffer identifier in setTitle");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 return FAIL;
1568 }
1569 vim_free(buf->displayname);
1570 buf->displayname = nb_unquote(args, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571/* =====================================================================*/
1572 }
1573 else if (streq((char *)cmd, "initDone"))
1574 {
1575 if (buf == NULL || buf->bufp == NULL)
1576 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001577 nbdebug((" invalid buffer identifier in initDone\n"));
1578 EMSG("E640: invalid buffer identifier in initDone");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 return FAIL;
1580 }
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001581 do_update = 1;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001582 buf->initDone = TRUE;
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001583 nb_set_curbuf(buf->bufp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584#if defined(FEAT_AUTOCMD)
1585 apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp);
1586#endif
1587
1588 /* handle any postponed key commands */
1589 handle_key_queue();
1590/* =====================================================================*/
1591 }
1592 else if (streq((char *)cmd, "setBufferNumber")
1593 || streq((char *)cmd, "putBufferNumber"))
1594 {
Bram Moolenaar009b2592004-10-24 19:18:58 +00001595 char_u *path;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 buf_T *bufp;
1597
1598 if (buf == NULL)
1599 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001600 nbdebug((" invalid buffer identifier in setBufferNumber\n"));
1601 EMSG("E641: invalid buffer identifier in setBufferNumber");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001602 return FAIL;
1603 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001604 path = (char_u *)nb_unquote(args, NULL);
1605 if (path == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 return FAIL;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001607 bufp = buflist_findname(path);
1608 vim_free(path);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001609 if (bufp == NULL)
1610 {
Bram Moolenaarec906222009-02-21 21:14:00 +00001611 nbdebug((" File %s not found in setBufferNumber\n", args));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612 EMSG2("E642: File %s not found in setBufferNumber", args);
1613 return FAIL;
1614 }
1615 buf->bufp = bufp;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001616 buf->nbbuf_number = bufp->b_fnum;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617
1618 /* "setBufferNumber" has the side effect of jumping to the buffer
1619 * (don't know why!). Don't do that for "putBufferNumber". */
1620 if (*cmd != 'p')
1621 coloncmd(":buffer %d", bufp->b_fnum);
1622 else
1623 {
Bram Moolenaar009b2592004-10-24 19:18:58 +00001624 buf->initDone = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625
1626 /* handle any postponed key commands */
1627 handle_key_queue();
1628 }
1629
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630/* =====================================================================*/
1631 }
1632 else if (streq((char *)cmd, "setFullName"))
1633 {
1634 if (buf == NULL)
1635 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001636 nbdebug((" invalid buffer identifier in setFullName\n"));
1637 EMSG("E643: invalid buffer identifier in setFullName");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 return FAIL;
1639 }
1640 vim_free(buf->displayname);
1641 buf->displayname = nb_unquote(args, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642
1643 netbeansReadFile = 0; /* don't try to open disk file */
1644 do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE,
Bram Moolenaar701f7af2008-11-15 13:12:07 +00001645 ECMD_HIDE + ECMD_OLDBUF, curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646 netbeansReadFile = 1;
1647 buf->bufp = curbuf;
1648 maketitle();
Bram Moolenaar67c53842010-05-22 18:28:27 +02001649#if defined(FEAT_MENU) && defined(FEAT_GUI)
Bram Moolenaard54a6882010-08-09 22:49:00 +02001650 if (gui.in_use)
1651 gui_update_menus(0);
Bram Moolenaar67c53842010-05-22 18:28:27 +02001652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653/* =====================================================================*/
1654 }
1655 else if (streq((char *)cmd, "editFile"))
1656 {
1657 if (buf == NULL)
1658 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001659 nbdebug((" invalid buffer identifier in editFile\n"));
1660 EMSG("E644: invalid buffer identifier in editFile");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 return FAIL;
1662 }
1663 /* Edit a file: like create + setFullName + read the file. */
1664 vim_free(buf->displayname);
1665 buf->displayname = nb_unquote(args, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
Bram Moolenaar701f7af2008-11-15 13:12:07 +00001667 ECMD_HIDE + ECMD_OLDBUF, curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 buf->bufp = curbuf;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001669 buf->initDone = TRUE;
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001670 do_update = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671#if defined(FEAT_TITLE)
1672 maketitle();
1673#endif
Bram Moolenaar67c53842010-05-22 18:28:27 +02001674#if defined(FEAT_MENU) && defined(FEAT_GUI)
Bram Moolenaard54a6882010-08-09 22:49:00 +02001675 if (gui.in_use)
1676 gui_update_menus(0);
Bram Moolenaar67c53842010-05-22 18:28:27 +02001677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678/* =====================================================================*/
1679 }
1680 else if (streq((char *)cmd, "setVisible"))
1681 {
1682 if (buf == NULL || buf->bufp == NULL)
1683 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001684 nbdebug((" invalid buffer identifier in setVisible\n"));
1685 /* This message was commented out, probably because it can
1686 * happen when shutting down. */
1687 if (p_verbose > 0)
1688 EMSG("E645: invalid buffer identifier in setVisible");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 return FAIL;
1690 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001691 if (streq((char *)args, "T") && buf->bufp != curbuf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 {
1693 exarg_T exarg;
1694 exarg.cmd = (char_u *)"goto";
1695 exarg.forceit = FALSE;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001696 dosetvisible = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 goto_buffer(&exarg, DOBUF_FIRST, FORWARD, buf->bufp->b_fnum);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001698 do_update = 1;
Bram Moolenaar009b2592004-10-24 19:18:58 +00001699 dosetvisible = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700
Bram Moolenaar67c53842010-05-22 18:28:27 +02001701#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702 /* Side effect!!!. */
Bram Moolenaard54a6882010-08-09 22:49:00 +02001703 if (gui.in_use)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 gui_mch_set_foreground();
Bram Moolenaar67c53842010-05-22 18:28:27 +02001705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001707/* =====================================================================*/
1708 }
1709 else if (streq((char *)cmd, "raise"))
1710 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02001711#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 /* Bring gvim to the foreground. */
Bram Moolenaard54a6882010-08-09 22:49:00 +02001713 if (gui.in_use)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 gui_mch_set_foreground();
Bram Moolenaar67c53842010-05-22 18:28:27 +02001715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716/* =====================================================================*/
1717 }
1718 else if (streq((char *)cmd, "setModified"))
1719 {
Bram Moolenaarff064e12008-06-09 13:10:45 +00001720 int prev_b_changed;
1721
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 if (buf == NULL || buf->bufp == NULL)
1723 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001724 nbdebug((" invalid buffer identifier in setModified\n"));
1725 /* This message was commented out, probably because it can
1726 * happen when shutting down. */
1727 if (p_verbose > 0)
1728 EMSG("E646: invalid buffer identifier in setModified");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 return FAIL;
1730 }
Bram Moolenaarff064e12008-06-09 13:10:45 +00001731 prev_b_changed = buf->bufp->b_changed;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 if (streq((char *)args, "T"))
Bram Moolenaarff064e12008-06-09 13:10:45 +00001733 buf->bufp->b_changed = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 else
1735 {
1736 struct stat st;
1737
1738 /* Assume NetBeans stored the file. Reset the timestamp to
1739 * avoid "file changed" warnings. */
1740 if (buf->bufp->b_ffname != NULL
1741 && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0)
1742 buf_store_time(buf->bufp, &st, buf->bufp->b_ffname);
Bram Moolenaarff064e12008-06-09 13:10:45 +00001743 buf->bufp->b_changed = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 }
1745 buf->modified = buf->bufp->b_changed;
Bram Moolenaarff064e12008-06-09 13:10:45 +00001746 if (prev_b_changed != buf->bufp->b_changed)
1747 {
1748#ifdef FEAT_WINDOWS
1749 check_status(buf->bufp);
1750 redraw_tabline = TRUE;
1751#endif
1752#ifdef FEAT_TITLE
1753 maketitle();
1754#endif
1755 update_screen(0);
1756 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757/* =====================================================================*/
1758 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00001759 else if (streq((char *)cmd, "setModtime"))
1760 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001761 if (buf == NULL || buf->bufp == NULL)
Bram Moolenaarf2330482008-06-24 20:19:36 +00001762 nbdebug((" invalid buffer identifier in setModtime\n"));
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001763 else
1764 buf->bufp->b_mtime = atoi((char *)args);
Bram Moolenaar009b2592004-10-24 19:18:58 +00001765/* =====================================================================*/
1766 }
1767 else if (streq((char *)cmd, "setReadOnly"))
1768 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001769 if (buf == NULL || buf->bufp == NULL)
Bram Moolenaarf2330482008-06-24 20:19:36 +00001770 nbdebug((" invalid buffer identifier in setReadOnly\n"));
Bram Moolenaareb3593b2006-04-22 22:33:57 +00001771 else if (streq((char *)args, "T"))
Bram Moolenaar009b2592004-10-24 19:18:58 +00001772 buf->bufp->b_p_ro = TRUE;
1773 else
1774 buf->bufp->b_p_ro = FALSE;
1775/* =====================================================================*/
1776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 else if (streq((char *)cmd, "setMark"))
1778 {
1779 /* not yet */
1780/* =====================================================================*/
1781 }
1782 else if (streq((char *)cmd, "showBalloon"))
1783 {
1784#if defined(FEAT_BEVAL)
1785 static char *text = NULL;
1786
1787 /*
1788 * Set up the Balloon Expression Evaluation area.
1789 * Ignore 'ballooneval' here.
1790 * The text pointer must remain valid for a while.
1791 */
1792 if (balloonEval != NULL)
1793 {
1794 vim_free(text);
1795 text = nb_unquote(args, NULL);
1796 if (text != NULL)
1797 gui_mch_post_balloon(balloonEval, (char_u *)text);
1798 }
1799#endif
1800/* =====================================================================*/
1801 }
1802 else if (streq((char *)cmd, "setDot"))
1803 {
1804 pos_T *pos;
1805#ifdef NBDEBUG
1806 char_u *s;
1807#endif
1808
1809 if (buf == NULL || buf->bufp == NULL)
1810 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001811 nbdebug((" invalid buffer identifier in setDot\n"));
1812 EMSG("E647: invalid buffer identifier in setDot");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 return FAIL;
1814 }
1815
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00001816 nb_set_curbuf(buf->bufp);
1817
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 /* Don't want Visual mode now. */
1819 if (VIsual_active)
1820 end_visual_mode();
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821#ifdef NBDEBUG
1822 s = args;
1823#endif
1824 pos = get_off_or_lnum(buf->bufp, &args);
1825 if (pos)
1826 {
1827 curwin->w_cursor = *pos;
1828 check_cursor();
1829#ifdef FEAT_FOLDING
1830 foldOpenCursor();
1831#endif
1832 }
1833 else
Bram Moolenaarb85cb212009-05-17 14:24:23 +00001834 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 nbdebug((" BAD POSITION in setDot: %s\n", s));
Bram Moolenaarb85cb212009-05-17 14:24:23 +00001836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837
1838 /* gui_update_cursor(TRUE, FALSE); */
1839 /* update_curbuf(NOT_VALID); */
1840 update_topline(); /* scroll to show the line */
1841 update_screen(VALID);
1842 setcursor();
Bram Moolenaar96bcc5e2011-04-01 15:33:59 +02001843 cursor_on();
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 out_flush();
Bram Moolenaar67c53842010-05-22 18:28:27 +02001845#ifdef FEAT_GUI
Bram Moolenaard54a6882010-08-09 22:49:00 +02001846 if (gui.in_use)
1847 {
1848 gui_update_cursor(TRUE, FALSE);
1849 gui_mch_flush();
1850 }
Bram Moolenaar67c53842010-05-22 18:28:27 +02001851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 /* Quit a hit-return or more prompt. */
1853 if (State == HITRETURN || State == ASKMORE)
1854 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855#ifdef FEAT_GUI_GTK
Bram Moolenaard54a6882010-08-09 22:49:00 +02001856 if (gui.in_use && gtk_main_level() > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 gtk_main_quit();
1858#endif
1859 }
1860/* =====================================================================*/
1861 }
1862 else if (streq((char *)cmd, "close"))
1863 {
1864#ifdef NBDEBUG
1865 char *name = "<NONE>";
1866#endif
1867
1868 if (buf == NULL)
1869 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001870 nbdebug((" invalid buffer identifier in close\n"));
1871 EMSG("E648: invalid buffer identifier in close");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 return FAIL;
1873 }
1874
1875#ifdef NBDEBUG
1876 if (buf->displayname != NULL)
1877 name = buf->displayname;
1878#endif
Bram Moolenaarf2330482008-06-24 20:19:36 +00001879 if (buf->bufp == NULL)
1880 {
1881 nbdebug((" invalid buffer identifier in close\n"));
1882 /* This message was commented out, probably because it can
1883 * happen when shutting down. */
1884 if (p_verbose > 0)
1885 EMSG("E649: invalid buffer identifier in close");
1886 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 nbdebug((" CLOSE %d: %s\n", bufno, name));
Bram Moolenaar67c53842010-05-22 18:28:27 +02001888#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 need_mouse_correct = TRUE;
Bram Moolenaar67c53842010-05-22 18:28:27 +02001890#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 if (buf->bufp != NULL)
1892 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD,
1893 buf->bufp->b_fnum, TRUE);
Bram Moolenaar8d602722006-08-08 19:34:19 +00001894 buf->bufp = NULL;
1895 buf->initDone = FALSE;
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001896 do_update = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897/* =====================================================================*/
1898 }
1899 else if (streq((char *)cmd, "setStyle")) /* obsolete... */
1900 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001901 nbdebug((" setStyle is obsolete!\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902/* =====================================================================*/
1903 }
1904 else if (streq((char *)cmd, "setExitDelay"))
1905 {
Bram Moolenaar009b2592004-10-24 19:18:58 +00001906 /* Only used in version 2.1. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907/* =====================================================================*/
1908 }
1909 else if (streq((char *)cmd, "defineAnnoType"))
1910 {
1911#ifdef FEAT_SIGNS
1912 int typeNum;
1913 char_u *typeName;
1914 char_u *tooltip;
1915 char_u *p;
1916 char_u *glyphFile;
Bram Moolenaar67c53842010-05-22 18:28:27 +02001917 int parse_error = FALSE;
1918 char_u *fg;
1919 char_u *bg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920
1921 if (buf == NULL)
1922 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001923 nbdebug((" invalid buffer identifier in defineAnnoType\n"));
1924 EMSG("E650: invalid buffer identifier in defineAnnoType");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 return FAIL;
1926 }
1927
Bram Moolenaar349b2f62004-10-11 10:00:50 +00001928 cp = (char *)args;
1929 typeNum = strtol(cp, &cp, 10);
1930 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 args = skipwhite(args);
1932 typeName = (char_u *)nb_unquote(args, &args);
1933 args = skipwhite(args + 1);
1934 tooltip = (char_u *)nb_unquote(args, &args);
1935 args = skipwhite(args + 1);
1936
1937 p = (char_u *)nb_unquote(args, &args);
1938 glyphFile = vim_strsave_escaped(p, escape_chars);
1939 vim_free(p);
1940
1941 args = skipwhite(args + 1);
Bram Moolenaar67c53842010-05-22 18:28:27 +02001942 p = skiptowhite(args);
1943 if (*p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02001945 *p = NUL;
1946 p = skipwhite(p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 }
Bram Moolenaar67c53842010-05-22 18:28:27 +02001948 fg = vim_strsave(args);
1949 bg = vim_strsave(p);
1950 if (STRLEN(fg) > MAX_COLOR_LENGTH || STRLEN(bg) > MAX_COLOR_LENGTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02001952 EMSG("E532: highlighting color name too long in defineAnnoType");
1953 vim_free(typeName);
1954 parse_error = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 }
Bram Moolenaar67c53842010-05-22 18:28:27 +02001956 else if (typeName != NULL && tooltip != NULL && glyphFile != NULL)
1957 addsigntype(buf, typeNum, typeName, tooltip, glyphFile, fg, bg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 else
1959 vim_free(typeName);
1960
1961 /* don't free typeName; it's used directly in addsigntype() */
Bram Moolenaar67c53842010-05-22 18:28:27 +02001962 vim_free(fg);
1963 vim_free(bg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 vim_free(tooltip);
1965 vim_free(glyphFile);
Bram Moolenaar67c53842010-05-22 18:28:27 +02001966 if (parse_error)
1967 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968
1969#endif
1970/* =====================================================================*/
1971 }
1972 else if (streq((char *)cmd, "addAnno"))
1973 {
1974#ifdef FEAT_SIGNS
1975 int serNum;
1976 int localTypeNum;
1977 int typeNum;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 pos_T *pos;
1979
1980 if (buf == NULL || buf->bufp == NULL)
1981 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00001982 nbdebug((" invalid buffer identifier in addAnno\n"));
1983 EMSG("E651: invalid buffer identifier in addAnno");
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 return FAIL;
1985 }
1986
Bram Moolenaar70b2a562012-01-10 22:26:17 +01001987 do_update = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988
Bram Moolenaar349b2f62004-10-11 10:00:50 +00001989 cp = (char *)args;
1990 serNum = strtol(cp, &cp, 10);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991
1992 /* Get the typenr specific for this buffer and convert it to
1993 * the global typenumber, as used for the sign name. */
Bram Moolenaar349b2f62004-10-11 10:00:50 +00001994 localTypeNum = strtol(cp, &cp, 10);
1995 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 typeNum = mapsigntype(buf, localTypeNum);
1997
1998 pos = get_off_or_lnum(buf->bufp, &args);
1999
Bram Moolenaar349b2f62004-10-11 10:00:50 +00002000 cp = (char *)args;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00002001 ignored = (int)strtol(cp, &cp, 10);
Bram Moolenaar349b2f62004-10-11 10:00:50 +00002002 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003# ifdef NBDEBUG
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00002004 if (ignored != -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002006 nbdebug((" partial line annotation -- Not Yet Implemented!\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 }
2008# endif
2009 if (serNum >= GUARDEDOFFSET)
2010 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002011 nbdebug((" too many annotations! ignoring...\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012 return FAIL;
2013 }
2014 if (pos)
2015 {
Bram Moolenaarec906222009-02-21 21:14:00 +00002016 coloncmd(":sign place %d line=%ld name=%d buffer=%d",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 serNum, pos->lnum, typeNum, buf->bufp->b_fnum);
2018 if (typeNum == curPCtype)
2019 coloncmd(":sign jump %d buffer=%d", serNum,
2020 buf->bufp->b_fnum);
2021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022#endif
2023/* =====================================================================*/
2024 }
2025 else if (streq((char *)cmd, "removeAnno"))
2026 {
2027#ifdef FEAT_SIGNS
2028 int serNum;
2029
2030 if (buf == NULL || buf->bufp == NULL)
2031 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002032 nbdebug((" invalid buffer identifier in removeAnno\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 return FAIL;
2034 }
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002035 do_update = 1;
Bram Moolenaar349b2f62004-10-11 10:00:50 +00002036 cp = (char *)args;
2037 serNum = strtol(cp, &cp, 10);
2038 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 coloncmd(":sign unplace %d buffer=%d",
2040 serNum, buf->bufp->b_fnum);
2041 redraw_buf_later(buf->bufp, NOT_VALID);
2042#endif
2043/* =====================================================================*/
2044 }
2045 else if (streq((char *)cmd, "moveAnnoToFront"))
2046 {
2047#ifdef FEAT_SIGNS
Bram Moolenaarf2330482008-06-24 20:19:36 +00002048 nbdebug((" moveAnnoToFront: Not Yet Implemented!\n"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049#endif
2050/* =====================================================================*/
2051 }
2052 else if (streq((char *)cmd, "guard") || streq((char *)cmd, "unguard"))
2053 {
2054 int len;
2055 pos_T first;
2056 pos_T last;
2057 pos_T *pos;
2058 int un = (cmd[0] == 'u');
2059 static int guardId = GUARDEDOFFSET;
2060
2061 if (skip >= SKIP_STOP)
2062 {
2063 nbdebug((" Skipping %s command\n", (char *) cmd));
2064 return OK;
2065 }
2066
2067 nb_init_graphics();
2068
2069 if (buf == NULL || buf->bufp == NULL)
2070 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002071 nbdebug((" invalid buffer identifier in %s command\n", cmd));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 return FAIL;
2073 }
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002074 nb_set_curbuf(buf->bufp);
Bram Moolenaar349b2f62004-10-11 10:00:50 +00002075 cp = (char *)args;
2076 off = strtol(cp, &cp, 10);
2077 len = strtol(cp, NULL, 10);
2078 args = (char_u *)cp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 pos = off2pos(buf->bufp, off);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002080 do_update = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 if (!pos)
2082 nbdebug((" no such start pos in %s, %ld\n", cmd, off));
2083 else
2084 {
2085 first = *pos;
2086 pos = off2pos(buf->bufp, off + len - 1);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002087 if (pos != NULL && pos->col == 0)
2088 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 /*
2090 * In Java Swing the offset is a position between 2
2091 * characters. If col == 0 then we really want the
2092 * previous line as the end.
2093 */
2094 pos = off2pos(buf->bufp, off + len - 2);
2095 }
2096 if (!pos)
2097 nbdebug((" no such end pos in %s, %ld\n",
2098 cmd, off + len - 1));
2099 else
2100 {
2101 long lnum;
2102 last = *pos;
2103 /* set highlight for region */
2104 nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un) ? "UN" : "",
2105 first.lnum, first.col,
2106 last.lnum, last.col));
2107#ifdef FEAT_SIGNS
2108 for (lnum = first.lnum; lnum <= last.lnum; lnum++)
2109 {
2110 if (un)
2111 {
2112 /* never used */
2113 }
2114 else
2115 {
2116 if (buf_findsigntype_id(buf->bufp, lnum,
2117 GUARDED) == 0)
2118 {
2119 coloncmd(
Bram Moolenaarec906222009-02-21 21:14:00 +00002120 ":sign place %d line=%ld name=%d buffer=%d",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 guardId++, lnum, GUARDED,
2122 buf->bufp->b_fnum);
2123 }
2124 }
2125 }
2126#endif
2127 redraw_buf_later(buf->bufp, NOT_VALID);
2128 }
2129 }
2130/* =====================================================================*/
2131 }
2132 else if (streq((char *)cmd, "startAtomic"))
2133 {
2134 inAtomic = 1;
2135/* =====================================================================*/
2136 }
2137 else if (streq((char *)cmd, "endAtomic"))
2138 {
2139 inAtomic = 0;
2140 if (needupdate)
2141 {
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002142 do_update = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 needupdate = 0;
2144 }
2145/* =====================================================================*/
2146 }
2147 else if (streq((char *)cmd, "save"))
2148 {
Bram Moolenaar009b2592004-10-24 19:18:58 +00002149 /*
2150 * NOTE - This command is obsolete wrt NetBeans. Its left in
2151 * only for historical reasons.
2152 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 if (buf == NULL || buf->bufp == NULL)
2154 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002155 nbdebug((" invalid buffer identifier in %s command\n", cmd));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 return FAIL;
2157 }
2158
2159 /* the following is taken from ex_cmds.c (do_wqall function) */
2160 if (bufIsChanged(buf->bufp))
2161 {
2162 /* Only write if the buffer can be written. */
2163 if (p_write
2164 && !buf->bufp->b_p_ro
2165 && buf->bufp->b_ffname != NULL
2166#ifdef FEAT_QUICKFIX
2167 && !bt_dontwrite(buf->bufp)
2168#endif
2169 )
2170 {
2171 buf_write_all(buf->bufp, FALSE);
2172#ifdef FEAT_AUTOCMD
2173 /* an autocommand may have deleted the buffer */
2174 if (!buf_valid(buf->bufp))
2175 buf->bufp = NULL;
2176#endif
2177 }
2178 }
Bram Moolenaarf2330482008-06-24 20:19:36 +00002179 else
2180 {
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002181 nbdebug((" Buffer has no changes!\n"));
Bram Moolenaarf2330482008-06-24 20:19:36 +00002182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183/* =====================================================================*/
2184 }
2185 else if (streq((char *)cmd, "netbeansBuffer"))
2186 {
2187 if (buf == NULL || buf->bufp == NULL)
2188 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002189 nbdebug((" invalid buffer identifier in %s command\n", cmd));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 return FAIL;
2191 }
2192 if (*args == 'T')
2193 {
2194 buf->bufp->b_netbeans_file = TRUE;
2195 buf->bufp->b_was_netbeans_file = TRUE;
2196 }
2197 else
2198 buf->bufp->b_netbeans_file = FALSE;
2199/* =====================================================================*/
2200 }
Bram Moolenaar009b2592004-10-24 19:18:58 +00002201 else if (streq((char *)cmd, "specialKeys"))
2202 {
2203 special_keys(args);
2204/* =====================================================================*/
2205 }
2206 else if (streq((char *)cmd, "actionMenuItem"))
2207 {
2208 /* not used yet */
2209/* =====================================================================*/
2210 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 else if (streq((char *)cmd, "version"))
2212 {
Bram Moolenaar009b2592004-10-24 19:18:58 +00002213 /* not used yet */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002214 }
Bram Moolenaarf2330482008-06-24 20:19:36 +00002215 else
2216 {
2217 nbdebug(("Unrecognised command: %s\n", cmd));
2218 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 /*
2220 * Unrecognized command is ignored.
2221 */
2222 }
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002223 if (inAtomic && do_update)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {
2225 needupdate = 1;
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002226 do_update = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 }
2228
Bram Moolenaar009b2592004-10-24 19:18:58 +00002229 /*
2230 * Is this needed? I moved the netbeans_Xt_connect() later during startup
2231 * and it may no longer be necessary. If its not needed then needupdate
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002232 * and do_update can also be removed.
Bram Moolenaar009b2592004-10-24 19:18:58 +00002233 */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01002234 if (buf != NULL && buf->initDone && do_update)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235 {
2236 update_screen(NOT_VALID);
2237 setcursor();
Bram Moolenaar96bcc5e2011-04-01 15:33:59 +02002238 cursor_on();
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 out_flush();
Bram Moolenaar67c53842010-05-22 18:28:27 +02002240#ifdef FEAT_GUI
Bram Moolenaard54a6882010-08-09 22:49:00 +02002241 if (gui.in_use)
2242 {
2243 gui_update_cursor(TRUE, FALSE);
2244 gui_mch_flush();
2245 }
Bram Moolenaar67c53842010-05-22 18:28:27 +02002246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 /* Quit a hit-return or more prompt. */
2248 if (State == HITRETURN || State == ASKMORE)
2249 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250#ifdef FEAT_GUI_GTK
Bram Moolenaard54a6882010-08-09 22:49:00 +02002251 if (gui.in_use && gtk_main_level() > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252 gtk_main_quit();
2253#endif
2254 }
2255 }
2256
2257 return retval;
2258}
2259
2260
2261/*
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002262 * If "buf" is not the current buffer try changing to a window that edits this
2263 * buffer. If there is no such window then close the current buffer and set
2264 * the current buffer as "buf".
2265 */
2266 static void
Bram Moolenaar5eaf8722008-01-05 17:07:13 +00002267nb_set_curbuf(buf_T *buf)
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002268{
Bram Moolenaar404c9422015-03-14 15:35:52 +01002269 if (curbuf != buf) {
2270 if (buf_jump_open_win(buf) != NULL)
2271 return;
2272# ifdef FEAT_WINDOWS
2273 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf) != NULL)
2274 return;
2275# endif
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002276 set_curbuf(buf, DOBUF_GOTO);
Bram Moolenaar404c9422015-03-14 15:35:52 +01002277 }
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00002278}
2279
2280/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 * Process a vim colon command.
2282 */
2283 static void
2284coloncmd(char *cmd, ...)
2285{
2286 char buf[1024];
2287 va_list ap;
2288
2289 va_start(ap, cmd);
Bram Moolenaar0dc79e82009-06-24 14:50:12 +00002290 vim_vsnprintf(buf, sizeof(buf), cmd, ap, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 va_end(ap);
2292
2293 nbdebug((" COLONCMD %s\n", buf));
2294
2295/* ALT_INPUT_LOCK_ON; */
2296 do_cmdline((char_u *)buf, NULL, NULL, DOCMD_NOWAIT | DOCMD_KEYTYPED);
2297/* ALT_INPUT_LOCK_OFF; */
2298
2299 setcursor(); /* restore the cursor position */
2300 out_flush(); /* make sure output has been written */
2301
Bram Moolenaar67c53842010-05-22 18:28:27 +02002302#ifdef FEAT_GUI
Bram Moolenaard54a6882010-08-09 22:49:00 +02002303 if (gui.in_use)
2304 {
2305 gui_update_cursor(TRUE, FALSE);
2306 gui_mch_flush();
2307 }
Bram Moolenaar67c53842010-05-22 18:28:27 +02002308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309}
2310
2311
2312/*
Bram Moolenaar009b2592004-10-24 19:18:58 +00002313 * Parse the specialKeys argument and issue the appropriate map commands.
2314 */
2315 static void
2316special_keys(char_u *args)
2317{
2318 char *save_str = nb_unquote(args, NULL);
2319 char *tok = strtok(save_str, " ");
2320 char *sep;
2321 char keybuf[64];
2322 char cmdbuf[256];
2323
2324 while (tok != NULL)
2325 {
2326 int i = 0;
2327
2328 if ((sep = strchr(tok, '-')) != NULL)
2329 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002330 *sep = NUL;
Bram Moolenaar009b2592004-10-24 19:18:58 +00002331 while (*tok)
2332 {
2333 switch (*tok)
2334 {
2335 case 'A':
2336 case 'M':
2337 case 'C':
2338 case 'S':
2339 keybuf[i++] = *tok;
2340 keybuf[i++] = '-';
2341 break;
2342 }
2343 tok++;
2344 }
2345 tok++;
2346 }
2347
2348 strcpy(&keybuf[i], tok);
Bram Moolenaar9c13b352005-05-19 20:53:52 +00002349 vim_snprintf(cmdbuf, sizeof(cmdbuf),
2350 "<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002351 do_map(0, (char_u *)cmdbuf, NORMAL, FALSE);
2352 tok = strtok(NULL, " ");
2353 }
2354 vim_free(save_str);
2355}
2356
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002357 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01002358ex_nbclose(exarg_T *eap UNUSED)
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002359{
2360 netbeans_close();
2361}
Bram Moolenaar009b2592004-10-24 19:18:58 +00002362
2363 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01002364ex_nbkey(exarg_T *eap)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002365{
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002366 (void)netbeans_keystring(eap->arg);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002367}
2368
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002369 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01002370ex_nbstart(
2371 exarg_T *eap)
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002372{
Bram Moolenaarc2a406b2010-09-30 21:03:26 +02002373#ifdef FEAT_GUI
2374# if !defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK) \
Bram Moolenaar7ad7d012010-11-16 15:49:02 +01002375 && !defined(FEAT_GUI_W32)
Bram Moolenaarc2a406b2010-09-30 21:03:26 +02002376 if (gui.in_use)
2377 {
Bram Moolenaar7ad7d012010-11-16 15:49:02 +01002378 EMSG(_("E838: netbeans is not supported with this GUI"));
2379 return;
Bram Moolenaarc2a406b2010-09-30 21:03:26 +02002380 }
2381# endif
2382#endif
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002383 netbeans_open((char *)eap->arg, FALSE);
2384}
Bram Moolenaar009b2592004-10-24 19:18:58 +00002385
2386/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 * Initialize highlights and signs for use by netbeans (mostly obsolete)
2388 */
2389 static void
2390nb_init_graphics(void)
2391{
2392 static int did_init = FALSE;
2393
2394 if (!did_init)
2395 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02002396 coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black"
2397 " ctermbg=LightCyan ctermfg=Black");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
2399
2400 did_init = TRUE;
2401 }
2402}
2403
2404/*
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002405 * Convert key to netbeans name. This uses the global "mod_mask".
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 */
2407 static void
2408netbeans_keyname(int key, char *buf)
2409{
2410 char *name = 0;
2411 char namebuf[2];
2412 int ctrl = 0;
2413 int shift = 0;
2414 int alt = 0;
2415
2416 if (mod_mask & MOD_MASK_CTRL)
2417 ctrl = 1;
2418 if (mod_mask & MOD_MASK_SHIFT)
2419 shift = 1;
2420 if (mod_mask & MOD_MASK_ALT)
2421 alt = 1;
2422
2423
2424 switch (key)
2425 {
2426 case K_F1: name = "F1"; break;
2427 case K_S_F1: name = "F1"; shift = 1; break;
2428 case K_F2: name = "F2"; break;
2429 case K_S_F2: name = "F2"; shift = 1; break;
2430 case K_F3: name = "F3"; break;
2431 case K_S_F3: name = "F3"; shift = 1; break;
2432 case K_F4: name = "F4"; break;
2433 case K_S_F4: name = "F4"; shift = 1; break;
2434 case K_F5: name = "F5"; break;
2435 case K_S_F5: name = "F5"; shift = 1; break;
2436 case K_F6: name = "F6"; break;
2437 case K_S_F6: name = "F6"; shift = 1; break;
2438 case K_F7: name = "F7"; break;
2439 case K_S_F7: name = "F7"; shift = 1; break;
2440 case K_F8: name = "F8"; break;
2441 case K_S_F8: name = "F8"; shift = 1; break;
2442 case K_F9: name = "F9"; break;
2443 case K_S_F9: name = "F9"; shift = 1; break;
2444 case K_F10: name = "F10"; break;
2445 case K_S_F10: name = "F10"; shift = 1; break;
2446 case K_F11: name = "F11"; break;
2447 case K_S_F11: name = "F11"; shift = 1; break;
2448 case K_F12: name = "F12"; break;
2449 case K_S_F12: name = "F12"; shift = 1; break;
2450 default:
2451 if (key >= ' ' && key <= '~')
2452 {
2453 /* Allow ASCII characters. */
2454 name = namebuf;
2455 namebuf[0] = key;
2456 namebuf[1] = NUL;
2457 }
2458 else
2459 name = "X";
2460 break;
2461 }
2462
2463 buf[0] = '\0';
2464 if (ctrl)
2465 strcat(buf, "C");
2466 if (shift)
2467 strcat(buf, "S");
2468 if (alt)
2469 strcat(buf, "M"); /* META */
2470 if (ctrl || shift || alt)
2471 strcat(buf, "-");
2472 strcat(buf, name);
2473}
2474
Bram Moolenaar67c53842010-05-22 18:28:27 +02002475#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476/*
2477 * Function to be called for balloon evaluation. Grabs the text under the
2478 * cursor and sends it to the debugger for evaluation. The debugger should
2479 * respond with a showBalloon command when there is a useful result.
2480 */
Bram Moolenaard62bec82005-03-07 22:56:57 +00002481 void
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482netbeans_beval_cb(
2483 BalloonEval *beval,
Bram Moolenaarb85cb212009-05-17 14:24:23 +00002484 int state UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002485{
Bram Moolenaard62bec82005-03-07 22:56:57 +00002486 win_T *wp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 char_u *text;
Bram Moolenaard62bec82005-03-07 22:56:57 +00002488 linenr_T lnum;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 int col;
Bram Moolenaard9462e32011-04-11 21:35:11 +02002490 char *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 char_u *p;
2492
2493 /* Don't do anything when 'ballooneval' is off, messages scrolled the
2494 * windows up or we have no connection. */
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002495 if (!p_beval || msg_scrolled > 0 || !NETBEANS_OPEN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 return;
2497
Bram Moolenaard62bec82005-03-07 22:56:57 +00002498 if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {
2500 /* Send debugger request. Only when the text is of reasonable
2501 * length. */
2502 if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
2503 {
Bram Moolenaard9462e32011-04-11 21:35:11 +02002504 buf = (char *)alloc(MAXPATHL * 2 + 25);
2505 if (buf != NULL)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002506 {
Bram Moolenaard9462e32011-04-11 21:35:11 +02002507 p = nb_quote(text);
2508 if (p != NULL)
2509 {
2510 vim_snprintf(buf, MAXPATHL * 2 + 25,
2511 "0:balloonText=%d \"%s\"\n", r_cmdno, p);
2512 vim_free(p);
2513 }
2514 nbdebug(("EVT: %s", buf));
2515 nb_send(buf, "netbeans_beval_cb");
2516 vim_free(buf);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 }
2519 vim_free(text);
2520 }
2521}
2522#endif
2523
2524/*
Bram Moolenaare0874f82016-01-24 20:36:41 +01002525 * Return TRUE when the netbeans connection is active.
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002526 */
2527 int
2528netbeans_active(void)
2529{
2530 return NETBEANS_OPEN;
2531}
2532
Bram Moolenaar67c53842010-05-22 18:28:27 +02002533/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 * Tell netbeans that the window was opened, ready for commands.
2535 */
2536 void
Bram Moolenaarf506c5b2010-06-22 06:28:58 +02002537netbeans_open(char *params, int doabort)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538{
2539 char *cmd = "0:startupDone=0\n";
2540
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002541 if (NETBEANS_OPEN)
2542 {
2543 EMSG(_("E511: netbeans already connected"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 return;
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546
Bram Moolenaarf506c5b2010-06-22 06:28:58 +02002547 if (netbeans_connect(params, doabort) != OK)
Bram Moolenaar67c53842010-05-22 18:28:27 +02002548 return;
Bram Moolenaard62bec82005-03-07 22:56:57 +00002549
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 nbdebug(("EVT: %s", cmd));
2551 nb_send(cmd, "netbeans_startup_done");
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002552
2553 /* update the screen after having added the gutter */
2554 changed_window_setting();
2555 update_screen(CLEAR);
2556 setcursor();
Bram Moolenaar96bcc5e2011-04-01 15:33:59 +02002557 cursor_on();
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002558 out_flush();
2559#ifdef FEAT_GUI
Bram Moolenaard54a6882010-08-09 22:49:00 +02002560 if (gui.in_use)
2561 {
2562 gui_update_cursor(TRUE, FALSE);
2563 gui_mch_flush();
2564 }
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566}
2567
Bram Moolenaar009b2592004-10-24 19:18:58 +00002568/*
2569 * Tell netbeans that we're exiting. This should be called right
2570 * before calling exit.
2571 */
2572 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01002573netbeans_send_disconnect(void)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002574{
2575 char buf[128];
2576
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002577 if (NETBEANS_OPEN)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002578 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00002579 sprintf(buf, "0:disconnect=%d\n", r_cmdno);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002580 nbdebug(("EVT: %s", buf));
2581 nb_send(buf, "netbeans_disconnect");
2582 }
2583}
2584
Bram Moolenaar173c9852010-09-29 17:27:01 +02002585#if defined(FEAT_GUI_X11) || defined(FEAT_GUI_W32) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586/*
2587 * Tell netbeans that the window was moved or resized.
2588 */
2589 void
2590netbeans_frame_moved(int new_x, int new_y)
2591{
2592 char buf[128];
2593
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002594 if (!NETBEANS_OPEN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 return;
2596
2597 sprintf(buf, "0:geometry=%d %d %d %d %d\n",
Bram Moolenaar89d40322006-08-29 15:30:07 +00002598 r_cmdno, (int)Columns, (int)Rows, new_x, new_y);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002599 /*nbdebug(("EVT: %s", buf)); happens too many times during a move */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 nb_send(buf, "netbeans_frame_moved");
2601}
2602#endif
2603
2604/*
Bram Moolenaar009b2592004-10-24 19:18:58 +00002605 * Tell netbeans the user opened or activated a file.
2606 */
2607 void
2608netbeans_file_activated(buf_T *bufp)
2609{
2610 int bufno = nb_getbufno(bufp);
2611 nbbuf_T *bp = nb_get_buf(bufno);
2612 char buffer[2*MAXPATHL];
2613 char_u *q;
2614
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002615 if (!NETBEANS_OPEN || !bufp->b_netbeans_file || dosetvisible)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002616 return;
2617
2618 q = nb_quote(bufp->b_ffname);
Bram Moolenaareb3593b2006-04-22 22:33:57 +00002619 if (q == NULL || bp == NULL)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002620 return;
2621
Bram Moolenaar9c13b352005-05-19 20:53:52 +00002622 vim_snprintf(buffer, sizeof(buffer), "%d:fileOpened=%d \"%s\" %s %s\n",
Bram Moolenaar009b2592004-10-24 19:18:58 +00002623 bufno,
2624 bufno,
2625 (char *)q,
2626 "T", /* open in NetBeans */
2627 "F"); /* modified */
2628
2629 vim_free(q);
2630 nbdebug(("EVT: %s", buffer));
2631
2632 nb_send(buffer, "netbeans_file_opened");
2633}
2634
2635/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 * Tell netbeans the user opened a file.
2637 */
2638 void
Bram Moolenaar009b2592004-10-24 19:18:58 +00002639netbeans_file_opened(buf_T *bufp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640{
Bram Moolenaar009b2592004-10-24 19:18:58 +00002641 int bufno = nb_getbufno(bufp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 char buffer[2*MAXPATHL];
2643 char_u *q;
Bram Moolenaar009b2592004-10-24 19:18:58 +00002644 nbbuf_T *bp = nb_get_buf(nb_getbufno(bufp));
2645 int bnum;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002647 if (!NETBEANS_OPEN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 return;
2649
Bram Moolenaar009b2592004-10-24 19:18:58 +00002650 q = nb_quote(bufp->b_ffname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 if (q == NULL)
2652 return;
Bram Moolenaar009b2592004-10-24 19:18:58 +00002653 if (bp != NULL)
2654 bnum = bufno;
2655 else
2656 bnum = 0;
2657
Bram Moolenaar9c13b352005-05-19 20:53:52 +00002658 vim_snprintf(buffer, sizeof(buffer), "%d:fileOpened=%d \"%s\" %s %s\n",
Bram Moolenaar009b2592004-10-24 19:18:58 +00002659 bnum,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 0,
2661 (char *)q,
2662 "T", /* open in NetBeans */
2663 "F"); /* modified */
2664
2665 vim_free(q);
2666 nbdebug(("EVT: %s", buffer));
2667
2668 nb_send(buffer, "netbeans_file_opened");
Bram Moolenaar009b2592004-10-24 19:18:58 +00002669 if (p_acd && vim_chdirfile(bufp->b_ffname) == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 shorten_fnames(TRUE);
2671}
2672
2673/*
Bram Moolenaard7f8f5c2009-01-06 15:14:30 +00002674 * Tell netbeans that a file was deleted or wiped out.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 */
2676 void
Bram Moolenaard7f8f5c2009-01-06 15:14:30 +00002677netbeans_file_killed(buf_T *bufp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678{
2679 int bufno = nb_getbufno(bufp);
2680 nbbuf_T *nbbuf = nb_get_buf(bufno);
2681 char buffer[2*MAXPATHL];
2682
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002683 if (!NETBEANS_OPEN || bufno == -1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 return;
2685
Bram Moolenaard7f8f5c2009-01-06 15:14:30 +00002686 nbdebug(("netbeans_file_killed:\n"));
2687 nbdebug((" Killing bufno: %d", bufno));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688
Bram Moolenaar89d40322006-08-29 15:30:07 +00002689 sprintf(buffer, "%d:killed=%d\n", bufno, r_cmdno);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690
2691 nbdebug(("EVT: %s", buffer));
2692
Bram Moolenaard7f8f5c2009-01-06 15:14:30 +00002693 nb_send(buffer, "netbeans_file_killed");
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694
2695 if (nbbuf != NULL)
2696 nbbuf->bufp = NULL;
2697}
2698
2699/*
2700 * Get a pointer to the Netbeans buffer for Vim buffer "bufp".
2701 * Return NULL if there is no such buffer or changes are not to be reported.
2702 * Otherwise store the buffer number in "*bufnop".
2703 */
2704 static nbbuf_T *
2705nb_bufp2nbbuf_fire(buf_T *bufp, int *bufnop)
2706{
2707 int bufno;
2708 nbbuf_T *nbbuf;
2709
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002710 if (!NETBEANS_OPEN || !netbeansFireChanges)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 return NULL; /* changes are not reported at all */
2712
2713 bufno = nb_getbufno(bufp);
2714 if (bufno <= 0)
2715 return NULL; /* file is not known to NetBeans */
2716
2717 nbbuf = nb_get_buf(bufno);
2718 if (nbbuf != NULL && !nbbuf->fireChanges)
2719 return NULL; /* changes in this buffer are not reported */
2720
2721 *bufnop = bufno;
2722 return nbbuf;
2723}
2724
2725/*
2726 * Tell netbeans the user inserted some text.
2727 */
2728 void
2729netbeans_inserted(
2730 buf_T *bufp,
2731 linenr_T linenr,
2732 colnr_T col,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 char_u *txt,
2734 int newlen)
2735{
2736 char_u *buf;
2737 int bufno;
2738 nbbuf_T *nbbuf;
2739 pos_T pos;
2740 long off;
2741 char_u *p;
2742 char_u *newtxt;
2743
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002744 if (!NETBEANS_OPEN)
2745 return;
2746
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
2748 if (nbbuf == NULL)
2749 return;
2750
Bram Moolenaar009b2592004-10-24 19:18:58 +00002751 /* Don't mark as modified for initial read */
2752 if (nbbuf->insertDone)
2753 nbbuf->modified = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754
2755 pos.lnum = linenr;
2756 pos.col = col;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 off = pos2off(bufp, &pos);
2758
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 /* send the "insert" EVT */
2760 newtxt = alloc(newlen + 1);
Bram Moolenaarb6356332005-07-18 21:40:44 +00002761 vim_strncpy(newtxt, txt, newlen);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 p = nb_quote(newtxt);
2763 if (p != NULL)
2764 {
Bram Moolenaar009b2592004-10-24 19:18:58 +00002765 buf = alloc(128 + 2*newlen);
Bram Moolenaar89d40322006-08-29 15:30:07 +00002766 sprintf((char *)buf, "%d:insert=%d %ld \"%s\"\n",
2767 bufno, r_cmdno, off, p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 nbdebug(("EVT: %s", buf));
2769 nb_send((char *)buf, "netbeans_inserted");
Bram Moolenaar009b2592004-10-24 19:18:58 +00002770 vim_free(p);
2771 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00002773 vim_free(newtxt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774}
2775
2776/*
2777 * Tell netbeans some bytes have been removed.
2778 */
2779 void
2780netbeans_removed(
2781 buf_T *bufp,
2782 linenr_T linenr,
2783 colnr_T col,
2784 long len)
2785{
2786 char_u buf[128];
2787 int bufno;
2788 nbbuf_T *nbbuf;
2789 pos_T pos;
2790 long off;
2791
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002792 if (!NETBEANS_OPEN)
2793 return;
2794
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
2796 if (nbbuf == NULL)
2797 return;
2798
2799 if (len < 0)
2800 {
Bram Moolenaarf2330482008-06-24 20:19:36 +00002801 nbdebug(("Negative len %ld in netbeans_removed()!\n", len));
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 return;
2803 }
2804
2805 nbbuf->modified = 1;
2806
2807 pos.lnum = linenr;
2808 pos.col = col;
2809
2810 off = pos2off(bufp, &pos);
2811
Bram Moolenaar89d40322006-08-29 15:30:07 +00002812 sprintf((char *)buf, "%d:remove=%d %ld %ld\n", bufno, r_cmdno, off, len);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 nbdebug(("EVT: %s", buf));
2814 nb_send((char *)buf, "netbeans_removed");
2815}
2816
2817/*
Bram Moolenaar2660c0e2010-01-19 14:59:56 +01002818 * Send netbeans an unmodified command.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002819 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 void
Bram Moolenaarb85cb212009-05-17 14:24:23 +00002821netbeans_unmodified(buf_T *bufp UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822{
Bram Moolenaar09092152010-08-08 16:38:42 +02002823 /* This is a no-op, because NetBeans considers a buffer modified
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 * even when all changes have been undone. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825}
2826
2827/*
2828 * Send a button release event back to netbeans. Its up to netbeans
2829 * to decide what to do (if anything) with this event.
2830 */
2831 void
2832netbeans_button_release(int button)
2833{
2834 char buf[128];
2835 int bufno;
2836
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002837 if (!NETBEANS_OPEN)
2838 return;
2839
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 bufno = nb_getbufno(curbuf);
2841
2842 if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
2843 {
Bram Moolenaar64486672010-05-16 15:46:46 +02002844 int col = mouse_col - W_WINCOL(curwin)
Bram Moolenaar67c53842010-05-22 18:28:27 +02002845 - ((curwin->w_p_nu || curwin->w_p_rnu) ? 9 : 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 long off = pos2off(curbuf, &curwin->w_cursor);
2847
2848 /* sync the cursor position */
Bram Moolenaar89d40322006-08-29 15:30:07 +00002849 sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 nbdebug(("EVT: %s", buf));
2851 nb_send(buf, "netbeans_button_release[newDotAndMark]");
2852
Bram Moolenaar89d40322006-08-29 15:30:07 +00002853 sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, r_cmdno,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 button, (long)curwin->w_cursor.lnum, col);
2855 nbdebug(("EVT: %s", buf));
2856 nb_send(buf, "netbeans_button_release");
2857 }
2858}
2859
2860
2861/*
Bram Moolenaar143c38c2007-05-10 16:41:10 +00002862 * Send a keypress event back to netbeans. This usually simulates some
Bram Moolenaar009b2592004-10-24 19:18:58 +00002863 * kind of function key press. This function operates on a key code.
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002864 * Return TRUE when the key was sent, FALSE when the command has been
2865 * postponed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 */
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002867 int
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868netbeans_keycommand(int key)
2869{
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 char keyName[60];
Bram Moolenaar009b2592004-10-24 19:18:58 +00002871
2872 netbeans_keyname(key, keyName);
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002873 return netbeans_keystring((char_u *)keyName);
Bram Moolenaar009b2592004-10-24 19:18:58 +00002874}
2875
2876
2877/*
Bram Moolenaar143c38c2007-05-10 16:41:10 +00002878 * Send a keypress event back to netbeans. This usually simulates some
Bram Moolenaar009b2592004-10-24 19:18:58 +00002879 * kind of function key press. This function operates on a key string.
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002880 * Return TRUE when the key was sent, FALSE when the command has been
2881 * postponed.
Bram Moolenaar009b2592004-10-24 19:18:58 +00002882 */
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002883 static int
2884netbeans_keystring(char_u *keyName)
Bram Moolenaar009b2592004-10-24 19:18:58 +00002885{
2886 char buf[2*MAXPATHL];
2887 int bufno = nb_getbufno(curbuf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 long off;
2889 char_u *q;
2890
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002891 if (!NETBEANS_OPEN)
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002892 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 if (bufno == -1)
2895 {
2896 nbdebug(("got keycommand for non-NetBeans buffer, opening...\n"));
2897 q = curbuf->b_ffname == NULL ? (char_u *)""
2898 : nb_quote(curbuf->b_ffname);
2899 if (q == NULL)
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002900 return TRUE;
Bram Moolenaar9c13b352005-05-19 20:53:52 +00002901 vim_snprintf(buf, sizeof(buf), "0:fileOpened=%d \"%s\" %s %s\n", 0,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 q,
2903 "T", /* open in NetBeans */
2904 "F"); /* modified */
2905 if (curbuf->b_ffname != NULL)
2906 vim_free(q);
2907 nbdebug(("EVT: %s", buf));
2908 nb_send(buf, "netbeans_keycommand");
2909
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002910 postpone_keycommand(keyName);
2911 return FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 }
2913
2914 /* sync the cursor position */
2915 off = pos2off(curbuf, &curwin->w_cursor);
Bram Moolenaar89d40322006-08-29 15:30:07 +00002916 sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, r_cmdno, off, off);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 nbdebug(("EVT: %s", buf));
2918 nb_send(buf, "netbeans_keycommand");
2919
2920 /* To work on Win32 you must apply patch to ExtEditor module
2921 * from ExtEdCaret.java.diff - make EVT_newDotAndMark handler
2922 * more synchronous
2923 */
2924
2925 /* now send keyCommand event */
Bram Moolenaar9c13b352005-05-19 20:53:52 +00002926 vim_snprintf(buf, sizeof(buf), "%d:keyCommand=%d \"%s\"\n",
Bram Moolenaar89d40322006-08-29 15:30:07 +00002927 bufno, r_cmdno, keyName);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 nbdebug(("EVT: %s", buf));
2929 nb_send(buf, "netbeans_keycommand");
2930
2931 /* New: do both at once and include the lnum/col. */
Bram Moolenaar9c13b352005-05-19 20:53:52 +00002932 vim_snprintf(buf, sizeof(buf), "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n",
Bram Moolenaar89d40322006-08-29 15:30:07 +00002933 bufno, r_cmdno, keyName,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col);
2935 nbdebug(("EVT: %s", buf));
2936 nb_send(buf, "netbeans_keycommand");
Bram Moolenaar8065d7f2010-01-19 15:13:14 +01002937 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938}
2939
2940
2941/*
2942 * Send a save event to netbeans.
2943 */
2944 void
2945netbeans_save_buffer(buf_T *bufp)
2946{
2947 char_u buf[64];
2948 int bufno;
2949 nbbuf_T *nbbuf;
2950
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002951 if (!NETBEANS_OPEN)
2952 return;
2953
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
2955 if (nbbuf == NULL)
2956 return;
2957
2958 nbbuf->modified = 0;
2959
Bram Moolenaar89d40322006-08-29 15:30:07 +00002960 sprintf((char *)buf, "%d:save=%d\n", bufno, r_cmdno);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 nbdebug(("EVT: %s", buf));
2962 nb_send((char *)buf, "netbeans_save_buffer");
2963}
2964
2965
2966/*
2967 * Send remove command to netbeans (this command has been turned off).
2968 */
2969 void
2970netbeans_deleted_all_lines(buf_T *bufp)
2971{
2972 char_u buf[64];
2973 int bufno;
2974 nbbuf_T *nbbuf;
2975
Bram Moolenaarb26e6322010-05-22 21:34:09 +02002976 if (!NETBEANS_OPEN)
2977 return;
2978
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
2980 if (nbbuf == NULL)
2981 return;
2982
Bram Moolenaar009b2592004-10-24 19:18:58 +00002983 /* Don't mark as modified for initial read */
2984 if (nbbuf->insertDone)
2985 nbbuf->modified = 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986
Bram Moolenaar89d40322006-08-29 15:30:07 +00002987 sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, r_cmdno);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 nbdebug(("EVT(suppressed): %s", buf));
2989/* nb_send(buf, "netbeans_deleted_all_lines"); */
2990}
2991
2992
2993/*
2994 * See if the lines are guarded. The top and bot parameters are from
2995 * u_savecommon(), these are the line above the change and the line below the
2996 * change.
2997 */
2998 int
2999netbeans_is_guarded(linenr_T top, linenr_T bot)
3000{
3001 signlist_T *p;
3002 int lnum;
3003
Bram Moolenaarb26e6322010-05-22 21:34:09 +02003004 if (!NETBEANS_OPEN)
3005 return FALSE;
3006
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 for (p = curbuf->b_signlist; p != NULL; p = p->next)
3008 if (p->id >= GUARDEDOFFSET)
3009 for (lnum = top + 1; lnum < bot; lnum++)
3010 if (lnum == p->lnum)
3011 return TRUE;
3012
3013 return FALSE;
3014}
3015
Bram Moolenaar173c9852010-09-29 17:27:01 +02003016#if defined(FEAT_GUI_X11) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017/*
3018 * We have multiple signs to draw at the same location. Draw the
3019 * multi-sign indicator instead. This is the Motif version.
3020 */
3021 void
3022netbeans_draw_multisign_indicator(int row)
3023{
3024 int i;
3025 int y;
3026 int x;
3027
Bram Moolenaarb26e6322010-05-22 21:34:09 +02003028 if (!NETBEANS_OPEN)
3029 return;
3030
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 x = 0;
3032 y = row * gui.char_height + 2;
3033
3034 for (i = 0; i < gui.char_height - 3; i++)
3035 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y++);
3036
3037 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+0, y);
3038 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
3039 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+4, y++);
3040 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+1, y);
3041 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
3042 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+3, y++);
3043 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
3044}
Bram Moolenaar173c9852010-09-29 17:27:01 +02003045#endif /* FEAT_GUI_X11 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046
Bram Moolenaar64404472010-06-26 06:24:45 +02003047#if defined(FEAT_GUI_GTK) && !defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048/*
3049 * We have multiple signs to draw at the same location. Draw the
3050 * multi-sign indicator instead. This is the GTK/Gnome version.
3051 */
3052 void
3053netbeans_draw_multisign_indicator(int row)
3054{
3055 int i;
3056 int y;
3057 int x;
3058 GdkDrawable *drawable = gui.drawarea->window;
3059
Bram Moolenaarb26e6322010-05-22 21:34:09 +02003060 if (!NETBEANS_OPEN)
3061 return;
3062
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 x = 0;
3064 y = row * gui.char_height + 2;
3065
3066 for (i = 0; i < gui.char_height - 3; i++)
3067 gdk_draw_point(drawable, gui.text_gc, x+2, y++);
3068
3069 gdk_draw_point(drawable, gui.text_gc, x+0, y);
3070 gdk_draw_point(drawable, gui.text_gc, x+2, y);
3071 gdk_draw_point(drawable, gui.text_gc, x+4, y++);
3072 gdk_draw_point(drawable, gui.text_gc, x+1, y);
3073 gdk_draw_point(drawable, gui.text_gc, x+2, y);
3074 gdk_draw_point(drawable, gui.text_gc, x+3, y++);
3075 gdk_draw_point(drawable, gui.text_gc, x+2, y);
3076}
3077#endif /* FEAT_GUI_GTK */
3078
3079/*
3080 * If the mouse is clicked in the gutter of a line with multiple
3081 * annotations, cycle through the set of signs.
3082 */
3083 void
3084netbeans_gutter_click(linenr_T lnum)
3085{
3086 signlist_T *p;
3087
Bram Moolenaarb26e6322010-05-22 21:34:09 +02003088 if (!NETBEANS_OPEN)
3089 return;
3090
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 for (p = curbuf->b_signlist; p != NULL; p = p->next)
3092 {
3093 if (p->lnum == lnum && p->next && p->next->lnum == lnum)
3094 {
3095 signlist_T *tail;
3096
3097 /* remove "p" from list, reinsert it at the tail of the sublist */
3098 if (p->prev)
3099 p->prev->next = p->next;
3100 else
3101 curbuf->b_signlist = p->next;
3102 p->next->prev = p->prev;
3103 /* now find end of sublist and insert p */
3104 for (tail = p->next;
3105 tail->next && tail->next->lnum == lnum
3106 && tail->next->id < GUARDEDOFFSET;
3107 tail = tail->next)
3108 ;
3109 /* tail now points to last entry with same lnum (except
3110 * that "guarded" annotations are always last) */
3111 p->next = tail->next;
3112 if (tail->next)
3113 tail->next->prev = p;
3114 p->prev = tail;
3115 tail->next = p;
3116 update_debug_sign(curbuf, lnum);
3117 break;
3118 }
3119 }
3120}
3121
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122/*
Bram Moolenaar2660c0e2010-01-19 14:59:56 +01003123 * Add a sign of the requested type at the requested location.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 *
3125 * Reverse engineering:
3126 * Apparently an annotation is defined the first time it is used in a buffer.
3127 * When the same annotation is used in two buffers, the second time we do not
3128 * need to define a new sign name but reuse the existing one. But since the
3129 * ID number used in the second buffer starts counting at one again, a mapping
3130 * is made from the ID specifically for the buffer to the global sign name
3131 * (which is a number).
3132 *
3133 * globalsignmap[] stores the signs that have been defined globally.
3134 * buf->signmapused[] maps buffer-local annotation IDs to an index in
3135 * globalsignmap[].
3136 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 static void
3138addsigntype(
3139 nbbuf_T *buf,
3140 int typeNum,
3141 char_u *typeName,
Bram Moolenaarb85cb212009-05-17 14:24:23 +00003142 char_u *tooltip UNUSED,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 char_u *glyphFile,
Bram Moolenaar67c53842010-05-22 18:28:27 +02003144 char_u *fg,
3145 char_u *bg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146{
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 int i, j;
Bram Moolenaar67c53842010-05-22 18:28:27 +02003148 int use_fg = (*fg && STRCMP(fg, "none") != 0);
3149 int use_bg = (*bg && STRCMP(bg, "none") != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150
3151 for (i = 0; i < globalsignmapused; i++)
3152 if (STRCMP(typeName, globalsignmap[i]) == 0)
3153 break;
3154
3155 if (i == globalsignmapused) /* not found; add it to global map */
3156 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02003157 nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%s,%s)\n",
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 typeNum, typeName, tooltip, glyphFile, fg, bg));
3159 if (use_fg || use_bg)
3160 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02003161 char fgbuf[2 * (8 + MAX_COLOR_LENGTH) + 1];
3162 char bgbuf[2 * (8 + MAX_COLOR_LENGTH) + 1];
3163 char *ptr;
3164 int value;
3165
3166 value = strtol((char *)fg, &ptr, 10);
3167 if (ptr != (char *)fg)
3168 sprintf(fgbuf, "guifg=#%06x", value & 0xFFFFFF);
3169 else
3170 sprintf(fgbuf, "guifg=%s ctermfg=%s", fg, fg);
3171
3172 value = strtol((char *)bg, &ptr, 10);
3173 if (ptr != (char *)bg)
3174 sprintf(bgbuf, "guibg=#%06x", value & 0xFFFFFF);
3175 else
3176 sprintf(bgbuf, "guibg=%s ctermbg=%s", bg, bg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177
3178 coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "",
3179 (use_bg) ? bgbuf : "");
3180 if (*glyphFile == NUL)
3181 /* no glyph, line highlighting only */
3182 coloncmd(":sign define %d linehl=NB_%s", i + 1, typeName);
3183 else if (vim_strsize(glyphFile) <= 2)
3184 /* one- or two-character glyph name, use as text glyph with
3185 * texthl */
3186 coloncmd(":sign define %d text=%s texthl=NB_%s", i + 1,
3187 glyphFile, typeName);
3188 else
3189 /* glyph, line highlighting */
3190 coloncmd(":sign define %d icon=%s linehl=NB_%s", i + 1,
3191 glyphFile, typeName);
3192 }
3193 else
3194 /* glyph, no line highlighting */
3195 coloncmd(":sign define %d icon=%s", i + 1, glyphFile);
3196
3197 if (STRCMP(typeName,"CurrentPC") == 0)
3198 curPCtype = typeNum;
3199
3200 if (globalsignmapused == globalsignmaplen)
3201 {
3202 if (globalsignmaplen == 0) /* first allocation */
3203 {
3204 globalsignmaplen = 20;
3205 globalsignmap = (char **)alloc_clear(globalsignmaplen*sizeof(char *));
3206 }
3207 else /* grow it */
3208 {
3209 int incr;
3210 int oldlen = globalsignmaplen;
Bram Moolenaar9abd5c62015-02-10 18:34:01 +01003211 char **t_globalsignmap = globalsignmap;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212
3213 globalsignmaplen *= 2;
3214 incr = globalsignmaplen - oldlen;
3215 globalsignmap = (char **)vim_realloc(globalsignmap,
3216 globalsignmaplen * sizeof(char *));
Bram Moolenaar9abd5c62015-02-10 18:34:01 +01003217 if (globalsignmap == NULL)
3218 {
3219 vim_free(t_globalsignmap);
3220 globalsignmaplen = 0;
3221 return;
3222 }
Bram Moolenaar7db5fc82010-05-24 11:59:29 +02003223 vim_memset(globalsignmap + oldlen, 0, incr * sizeof(char *));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224 }
3225 }
3226
3227 globalsignmap[i] = (char *)typeName;
3228 globalsignmapused = i + 1;
3229 }
3230
3231 /* check local map; should *not* be found! */
3232 for (j = 0; j < buf->signmapused; j++)
3233 if (buf->signmap[j] == i + 1)
3234 return;
3235
3236 /* add to local map */
3237 if (buf->signmapused == buf->signmaplen)
3238 {
3239 if (buf->signmaplen == 0) /* first allocation */
3240 {
3241 buf->signmaplen = 5;
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003242 buf->signmap = (int *)alloc_clear(buf->signmaplen * sizeof(int));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 }
3244 else /* grow it */
3245 {
3246 int incr;
3247 int oldlen = buf->signmaplen;
Bram Moolenaar9abd5c62015-02-10 18:34:01 +01003248 int *t_signmap = buf->signmap;
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003249
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250 buf->signmaplen *= 2;
3251 incr = buf->signmaplen - oldlen;
3252 buf->signmap = (int *)vim_realloc(buf->signmap,
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003253 buf->signmaplen * sizeof(int));
Bram Moolenaar9abd5c62015-02-10 18:34:01 +01003254 if (buf->signmap == NULL)
3255 {
3256 vim_free(t_signmap);
3257 buf->signmaplen = 0;
3258 return;
3259 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003260 vim_memset(buf->signmap + oldlen, 0, incr * sizeof(int));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261 }
3262 }
3263
3264 buf->signmap[buf->signmapused++] = i + 1;
3265
3266}
3267
3268
3269/*
3270 * See if we have the requested sign type in the buffer.
3271 */
3272 static int
3273mapsigntype(nbbuf_T *buf, int localsigntype)
3274{
3275 if (--localsigntype >= 0 && localsigntype < buf->signmapused)
3276 return buf->signmap[localsigntype];
3277
3278 return 0;
3279}
3280
3281
3282/*
3283 * Compute length of buffer, don't print anything.
3284 */
3285 static long
3286get_buf_size(buf_T *bufp)
3287{
3288 linenr_T lnum;
3289 long char_count = 0;
3290 int eol_size;
3291 long last_check = 100000L;
3292
3293 if (bufp->b_ml.ml_flags & ML_EMPTY)
3294 return 0;
3295 else
3296 {
3297 if (get_fileformat(bufp) == EOL_DOS)
3298 eol_size = 2;
3299 else
3300 eol_size = 1;
3301 for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
3302 {
Bram Moolenaarfa68b0f2009-09-11 12:19:51 +00003303 char_count += (long)STRLEN(ml_get_buf(bufp, lnum, FALSE))
3304 + eol_size;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305 /* Check for a CTRL-C every 100000 characters */
3306 if (char_count > last_check)
3307 {
3308 ui_breakcheck();
3309 if (got_int)
3310 return char_count;
3311 last_check = char_count + 100000L;
3312 }
3313 }
3314 /* Correction for when last line doesn't have an EOL. */
Bram Moolenaar34d72d42015-07-17 14:18:08 +02003315 if (!bufp->b_p_eol && (bufp->b_p_bin || !bufp->b_p_fixeol))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316 char_count -= eol_size;
3317 }
3318
3319 return char_count;
3320}
3321
3322/*
3323 * Convert character offset to lnum,col
3324 */
3325 static pos_T *
3326off2pos(buf_T *buf, long offset)
3327{
3328 linenr_T lnum;
3329 static pos_T pos;
3330
3331 pos.lnum = 0;
3332 pos.col = 0;
3333#ifdef FEAT_VIRTUALEDIT
3334 pos.coladd = 0;
3335#endif
3336
3337 if (!(buf->b_ml.ml_flags & ML_EMPTY))
3338 {
3339 if ((lnum = ml_find_line_or_offset(buf, (linenr_T)0, &offset)) < 0)
3340 return NULL;
3341 pos.lnum = lnum;
3342 pos.col = offset;
3343 }
3344
3345 return &pos;
3346}
3347
3348/*
3349 * Convert an argument in the form "1234" to an offset and compute the
3350 * lnum/col from it. Convert an argument in the form "123/12" directly to a
3351 * lnum/col.
3352 * "argp" is advanced to after the argument.
3353 * Return a pointer to the position, NULL if something is wrong.
3354 */
3355 static pos_T *
3356get_off_or_lnum(buf_T *buf, char_u **argp)
3357{
3358 static pos_T mypos;
3359 long off;
3360
3361 off = strtol((char *)*argp, (char **)argp, 10);
3362 if (**argp == '/')
3363 {
3364 mypos.lnum = (linenr_T)off;
3365 ++*argp;
3366 mypos.col = strtol((char *)*argp, (char **)argp, 10);
3367#ifdef FEAT_VIRTUALEDIT
3368 mypos.coladd = 0;
3369#endif
3370 return &mypos;
3371 }
3372 return off2pos(buf, off);
3373}
3374
3375
3376/*
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00003377 * Convert (lnum,col) to byte offset in the file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 */
3379 static long
3380pos2off(buf_T *buf, pos_T *pos)
3381{
3382 long offset = 0;
3383
3384 if (!(buf->b_ml.ml_flags & ML_EMPTY))
3385 {
3386 if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
3387 return 0;
3388 offset += pos->col;
3389 }
3390
3391 return offset;
3392}
3393
3394
Bram Moolenaar009b2592004-10-24 19:18:58 +00003395/*
3396 * This message is printed after NetBeans opens a new file. Its
3397 * similar to the message readfile() uses, but since NetBeans
3398 * doesn't normally call readfile, we do our own.
3399 */
3400 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003401print_read_msg(nbbuf_T *buf)
Bram Moolenaar009b2592004-10-24 19:18:58 +00003402{
3403 int lnum = buf->bufp->b_ml.ml_line_count;
Bram Moolenaar914703b2010-05-31 21:59:46 +02003404 off_t nchars = buf->bufp->b_orig_size;
Bram Moolenaar009b2592004-10-24 19:18:58 +00003405 char_u c;
3406
3407 msg_add_fname(buf->bufp, buf->bufp->b_ffname);
3408 c = FALSE;
3409
3410 if (buf->bufp->b_p_ro)
3411 {
3412 STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
3413 c = TRUE;
3414 }
3415 if (!buf->bufp->b_start_eol)
3416 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02003417 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]")
3418 : _("[Incomplete last line]"));
Bram Moolenaar009b2592004-10-24 19:18:58 +00003419 c = TRUE;
3420 }
3421 msg_add_lines(c, (long)lnum, nchars);
3422
3423 /* Now display it */
3424 vim_free(keep_msg);
3425 keep_msg = NULL;
3426 msg_scrolled_ign = TRUE;
3427 msg_trunc_attr(IObuff, FALSE, 0);
3428 msg_scrolled_ign = FALSE;
3429}
3430
3431
3432/*
Bram Moolenaar67c53842010-05-22 18:28:27 +02003433 * Print a message after NetBeans writes the file. This message should be
3434 * identical to the standard message a non-netbeans user would see when
3435 * writing a file.
Bram Moolenaar009b2592004-10-24 19:18:58 +00003436 */
3437 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003438print_save_msg(nbbuf_T *buf, off_t nchars)
Bram Moolenaar009b2592004-10-24 19:18:58 +00003439{
3440 char_u c;
3441 char_u *p;
3442
3443 if (nchars >= 0)
3444 {
Bram Moolenaar67c53842010-05-22 18:28:27 +02003445 /* put fname in IObuff with quotes */
3446 msg_add_fname(buf->bufp, buf->bufp->b_ffname);
Bram Moolenaar009b2592004-10-24 19:18:58 +00003447 c = FALSE;
3448
3449 msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
Bram Moolenaar914703b2010-05-31 21:59:46 +02003450 buf->bufp->b_orig_size);
Bram Moolenaar009b2592004-10-24 19:18:58 +00003451
3452 vim_free(keep_msg);
3453 keep_msg = NULL;
3454 msg_scrolled_ign = TRUE;
3455 p = msg_trunc_attr(IObuff, FALSE, 0);
3456 if ((msg_scrolled && !need_wait_return) || !buf->initDone)
3457 {
3458 /* Need to repeat the message after redrawing when:
3459 * - When reading from stdin (the screen will be cleared next).
3460 * - When restart_edit is set (otherwise there will be a delay
3461 * before redrawing).
3462 * - When the screen was scrolled but there is no wait-return
3463 * prompt. */
Bram Moolenaar030f0df2006-02-21 22:02:53 +00003464 set_keep_msg(p, 0);
Bram Moolenaar009b2592004-10-24 19:18:58 +00003465 }
3466 msg_scrolled_ign = FALSE;
3467 /* add_to_input_buf((char_u *)"\f", 1); */
3468 }
3469 else
3470 {
Bram Moolenaaref9d6aa2011-04-11 16:56:35 +02003471 char_u msgbuf[IOSIZE];
Bram Moolenaar009b2592004-10-24 19:18:58 +00003472
Bram Moolenaaref9d6aa2011-04-11 16:56:35 +02003473 vim_snprintf((char *)msgbuf, IOSIZE,
3474 _("E505: %s is read-only (add ! to override)"), IObuff);
3475 nbdebug((" %s\n", msgbuf));
3476 emsg(msgbuf);
Bram Moolenaar009b2592004-10-24 19:18:58 +00003477 }
3478}
3479
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480#endif /* defined(FEAT_NETBEANS_INTG) */