7
|
1 /* 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.
|
|
17 */
|
|
18
|
|
19 #include "vim.h"
|
|
20
|
|
21 #if defined(FEAT_NETBEANS_INTG) || defined(PROTO)
|
|
22
|
|
23 /* Note: when making changes here also adjust configure.in. */
|
|
24 # include <stdarg.h>
|
|
25 # include <fcntl.h>
|
|
26 #ifdef WIN32
|
|
27 # ifdef DEBUG
|
|
28 # include <tchar.h> /* for _T definition for TRACEn macros */
|
|
29 # endif
|
|
30 # include <io.h>
|
|
31 /* WinSock API is separated from C API, thus we can't use read(), write(),
|
|
32 * errno... */
|
|
33 # define sock_errno WSAGetLastError()
|
|
34 # define ECONNREFUSED WSAECONNREFUSED
|
|
35 # ifdef EINTR
|
|
36 # undef EINTR
|
|
37 # endif
|
|
38 # define EINTR WSAEINTR
|
|
39 # define sock_write(sd, buf, len) send(sd, buf, len, 0)
|
|
40 # define sock_read(sd, buf, len) recv(sd, buf, len, 0)
|
|
41 # define sock_close(sd) closesocket(sd)
|
|
42 # define sleep(t) Sleep(t*1000) /* WinAPI Sleep() accepts milliseconds */
|
|
43 #else
|
|
44 # include <netdb.h>
|
|
45 # include <netinet/in.h>
|
|
46 # include <sys/socket.h>
|
|
47 # ifdef HAVE_LIBGEN_H
|
|
48 # include <libgen.h>
|
|
49 # endif
|
|
50 # define sock_errno errno
|
|
51 # define sock_write(sd, buf, len) write(sd, buf, len)
|
|
52 # define sock_read(sd, buf, len) read(sd, buf, len)
|
|
53 # define sock_close(sd) close(sd)
|
|
54 #endif
|
|
55
|
|
56 #include "version.h"
|
|
57
|
|
58 #define INET_SOCKETS
|
|
59
|
|
60 #define GUARDED 10000 /* typenr for "guarded" annotation */
|
|
61 #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */
|
|
62
|
|
63 /* The first implementation (working only with Netbeans) returned "1.1". The
|
|
64 * protocol implemented here also supports A-A-P. */
|
33
|
65 static char *ExtEdProtocolVersion = "2.3";
|
7
|
66
|
|
67 static long pos2off __ARGS((buf_T *, pos_T *));
|
|
68 static pos_T *off2pos __ARGS((buf_T *, long));
|
|
69 static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
|
|
70 static long get_buf_size __ARGS((buf_T *));
|
33
|
71 static void netbeans_keystring __ARGS((int key, char *keystr));
|
|
72 static void special_keys __ARGS((char_u *args));
|
7
|
73
|
|
74 static void netbeans_connect __ARGS((void));
|
|
75 static int getConnInfo __ARGS((char *file, char **host, char **port, char **password));
|
|
76
|
|
77 static void nb_init_graphics __ARGS((void));
|
|
78 static void coloncmd __ARGS((char *cmd, ...));
|
|
79 #ifdef FEAT_GUI_MOTIF
|
|
80 static void messageFromNetbeans __ARGS((XtPointer, int *, XtInputId *));
|
|
81 #endif
|
|
82 #ifdef FEAT_GUI_GTK
|
|
83 static void messageFromNetbeans __ARGS((gpointer, gint, GdkInputCondition));
|
|
84 #endif
|
|
85 static void nb_parse_cmd __ARGS((char_u *));
|
|
86 static int nb_do_cmd __ARGS((int, char_u *, int, int, char_u *));
|
|
87 static void nb_send __ARGS((char *buf, char *fun));
|
|
88
|
|
89 static int sd = -1; /* socket fd for Netbeans connection */
|
|
90 #ifdef FEAT_GUI_MOTIF
|
|
91 static XtInputId inputHandler; /* Cookie for input */
|
|
92 #endif
|
|
93 #ifdef FEAT_GUI_GTK
|
|
94 static gint inputHandler; /* Cookie for input */
|
|
95 #endif
|
|
96 #ifdef FEAT_GUI_W32
|
|
97 static int inputHandler = -1; /* simply ret.value of WSAAsyncSelect() */
|
|
98 extern HWND s_hwnd; /* Gvim's Window handle */
|
|
99 #endif
|
|
100 static int cmdno; /* current command number for reply */
|
|
101 static int haveConnection = FALSE; /* socket is connected and
|
|
102 initialization is done */
|
|
103 static int oldFire = 1;
|
|
104
|
33
|
105 #ifdef FEAT_GUI_MOTIF
|
|
106 static void netbeans_Xt_connect __ARGS((void *context));
|
167
|
107 #endif
|
|
108 #ifdef FEAT_GUI_GTK
|
33
|
109 static void netbeans_gtk_connect __ARGS((void));
|
167
|
110 #endif
|
|
111 #ifdef FEAT_GUI_W32
|
33
|
112 static void netbeans_w32_connect __ARGS((void));
|
|
113 #endif
|
|
114
|
|
115 static int dosetvisible = FALSE;
|
|
116
|
7
|
117 /*
|
|
118 * Include the debugging code if wanted.
|
|
119 */
|
|
120 #ifdef NBDEBUG
|
|
121 # include "nbdebug.c"
|
|
122 #endif
|
|
123
|
|
124 /* Connect back to Netbeans process */
|
33
|
125 #ifdef FEAT_GUI_MOTIF
|
|
126 static void
|
7
|
127 netbeans_Xt_connect(void *context)
|
|
128 {
|
|
129 netbeans_connect();
|
|
130 if (sd > 0)
|
|
131 {
|
|
132 /* tell notifier we are interested in being called
|
|
133 * when there is input on the editor connection socket
|
|
134 */
|
|
135 inputHandler = XtAppAddInput((XtAppContext)context, sd,
|
|
136 (XtPointer)(XtInputReadMask + XtInputExceptMask),
|
|
137 messageFromNetbeans, NULL);
|
|
138 }
|
|
139 }
|
|
140
|
|
141 static void
|
|
142 netbeans_disconnect(void)
|
|
143 {
|
|
144 if (inputHandler != (XtInputId)NULL)
|
|
145 {
|
|
146 XtRemoveInput(inputHandler);
|
|
147 inputHandler = (XtInputId)NULL;
|
|
148 }
|
|
149 sd = -1;
|
|
150 haveConnection = FALSE;
|
183
|
151 # ifdef FEAT_BEVAL
|
|
152 bevalServers &= ~BEVAL_NETBEANS;
|
|
153 # endif
|
7
|
154 }
|
|
155 #endif /* FEAT_MOTIF_GUI */
|
|
156
|
33
|
157 #ifdef FEAT_GUI_GTK
|
|
158 static void
|
7
|
159 netbeans_gtk_connect(void)
|
|
160 {
|
|
161 netbeans_connect();
|
|
162 if (sd > 0)
|
|
163 {
|
|
164 /*
|
|
165 * Tell gdk we are interested in being called when there
|
|
166 * is input on the editor connection socket
|
|
167 */
|
|
168 inputHandler = gdk_input_add(sd, (GdkInputCondition)
|
|
169 ((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION),
|
|
170 messageFromNetbeans, NULL);
|
|
171 }
|
|
172 }
|
|
173
|
|
174 static void
|
|
175 netbeans_disconnect(void)
|
|
176 {
|
|
177 if (inputHandler != 0)
|
|
178 {
|
|
179 gdk_input_remove(inputHandler);
|
|
180 inputHandler = 0;
|
|
181 }
|
|
182 sd = -1;
|
|
183 haveConnection = FALSE;
|
183
|
184 # ifdef FEAT_BEVAL
|
|
185 bevalServers &= ~BEVAL_NETBEANS;
|
|
186 # endif
|
7
|
187 }
|
|
188 #endif /* FEAT_GUI_GTK */
|
|
189
|
143
|
190 #if defined(FEAT_GUI_W32) || defined(PROTO)
|
7
|
191 void
|
|
192 netbeans_w32_connect(void)
|
|
193 {
|
|
194 netbeans_connect();
|
|
195 if (sd > 0)
|
|
196 {
|
|
197 /*
|
|
198 * Tell Windows we are interested in receiving message when there
|
|
199 * is input on the editor connection socket
|
|
200 */
|
|
201 inputHandler = WSAAsyncSelect(sd, s_hwnd, WM_NETBEANS, FD_READ);
|
|
202 }
|
|
203 }
|
|
204
|
|
205 static void
|
|
206 netbeans_disconnect(void)
|
|
207 {
|
|
208 if (inputHandler == 0)
|
|
209 {
|
|
210 WSAAsyncSelect(sd, s_hwnd, 0, 0);
|
|
211 inputHandler = -1;
|
|
212 }
|
|
213 sd = -1;
|
|
214 haveConnection = FALSE;
|
183
|
215 # ifdef FEAT_BEVAL
|
|
216 bevalServers &= ~BEVAL_NETBEANS;
|
|
217 # endif
|
7
|
218 }
|
|
219 #endif /* FEAT_GUI_W32 */
|
|
220
|
|
221 #define NB_DEF_HOST "localhost"
|
|
222 #define NB_DEF_ADDR "3219"
|
|
223 #define NB_DEF_PASS "changeme"
|
|
224
|
|
225 static void
|
|
226 netbeans_connect(void)
|
|
227 {
|
|
228 #ifdef INET_SOCKETS
|
|
229 struct sockaddr_in server;
|
|
230 struct hostent * host;
|
|
231 # ifdef FEAT_GUI_W32
|
|
232 u_short port;
|
|
233 # else
|
|
234 int port;
|
|
235 #endif
|
|
236 #else
|
|
237 struct sockaddr_un server;
|
|
238 #endif
|
|
239 char buf[32];
|
|
240 char *hostname = NULL;
|
|
241 char *address = NULL;
|
|
242 char *password = NULL;
|
|
243 char *fname;
|
|
244 char *arg = NULL;
|
|
245
|
|
246 if (netbeansArg[3] == '=')
|
|
247 {
|
|
248 /* "-nb=fname": Read info from specified file. */
|
|
249 if (getConnInfo(netbeansArg + 4, &hostname, &address, &password)
|
|
250 == FAIL)
|
|
251 return;
|
|
252 }
|
|
253 else
|
|
254 {
|
|
255 if (netbeansArg[3] == ':')
|
|
256 /* "-nb:<host>:<addr>:<password>": get info from argument */
|
|
257 arg = netbeansArg + 4;
|
|
258 if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL)
|
|
259 {
|
|
260 /* "-nb": get info from file specified in environment */
|
|
261 if (getConnInfo(fname, &hostname, &address, &password) == FAIL)
|
|
262 return;
|
|
263 }
|
|
264 else
|
|
265 {
|
|
266 if (arg != NULL)
|
|
267 {
|
|
268 /* "-nb:<host>:<addr>:<password>": get info from argument */
|
|
269 hostname = arg;
|
|
270 address = strchr(hostname, ':');
|
|
271 if (address != NULL)
|
|
272 {
|
|
273 *address++ = '\0';
|
|
274 password = strchr(address, ':');
|
|
275 if (password != NULL)
|
|
276 *password++ = '\0';
|
|
277 }
|
|
278 }
|
|
279
|
|
280 /* Get the missing values from the environment. */
|
|
281 if (hostname == NULL || *hostname == '\0')
|
|
282 hostname = getenv("__NETBEANS_HOST");
|
|
283 if (address == NULL)
|
|
284 address = getenv("__NETBEANS_SOCKET");
|
|
285 if (password == NULL)
|
|
286 password = getenv("__NETBEANS_VIM_PASSWORD");
|
|
287
|
|
288 /* Move values to allocated memory. */
|
|
289 if (hostname != NULL)
|
|
290 hostname = (char *)vim_strsave((char_u *)hostname);
|
|
291 if (address != NULL)
|
|
292 address = (char *)vim_strsave((char_u *)address);
|
|
293 if (password != NULL)
|
|
294 password = (char *)vim_strsave((char_u *)password);
|
|
295 }
|
|
296 }
|
|
297
|
|
298 /* Use the default when a value is missing. */
|
|
299 if (hostname == NULL || *hostname == '\0')
|
|
300 {
|
|
301 vim_free(hostname);
|
|
302 hostname = (char *)vim_strsave((char_u *)NB_DEF_HOST);
|
|
303 }
|
|
304 if (address == NULL || *address == '\0')
|
|
305 {
|
|
306 vim_free(address);
|
|
307 address = (char *)vim_strsave((char_u *)NB_DEF_ADDR);
|
|
308 }
|
|
309 if (password == NULL || *password == '\0')
|
|
310 {
|
|
311 vim_free(password);
|
|
312 password = (char *)vim_strsave((char_u *)NB_DEF_PASS);
|
|
313 }
|
|
314 if (hostname == NULL || address == NULL || password == NULL)
|
|
315 goto theend; /* out of memory */
|
|
316
|
|
317 #ifdef INET_SOCKETS
|
|
318 port = atoi(address);
|
|
319
|
|
320 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
|
321 {
|
|
322 PERROR("socket() in netbeans_connect()");
|
|
323 goto theend;
|
|
324 }
|
|
325
|
|
326 /* Get the server internet address and put into addr structure */
|
|
327 /* fill in the socket address structure and connect to server */
|
|
328 memset((char *)&server, '\0', sizeof(server));
|
|
329 server.sin_family = AF_INET;
|
|
330 server.sin_port = htons(port);
|
|
331 if ((host = gethostbyname(hostname)) == NULL)
|
|
332 {
|
|
333 if (mch_access(hostname, R_OK) >= 0)
|
|
334 {
|
|
335 /* DEBUG: input file */
|
|
336 sd = mch_open(hostname, O_RDONLY, 0);
|
|
337 goto theend;
|
|
338 }
|
|
339 PERROR("gethostbyname() in netbeans_connect()");
|
|
340 sd = -1;
|
|
341 goto theend;
|
|
342 }
|
|
343 memcpy((char *)&server.sin_addr, host->h_addr, host->h_length);
|
|
344 #else
|
|
345 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
|
346 {
|
|
347 PERROR("socket()");
|
|
348 goto theend;
|
|
349 }
|
|
350
|
|
351 server.sun_family = AF_UNIX;
|
|
352 strcpy(server.sun_path, address);
|
|
353 #endif
|
|
354 /* Connect to server */
|
|
355 if (connect(sd, (struct sockaddr *)&server, sizeof(server)))
|
|
356 {
|
|
357 nbdebug(("netbeans_connect: Connect failed with errno %d\n", sock_errno));
|
|
358 if (sock_errno == ECONNREFUSED)
|
|
359 {
|
|
360 sock_close(sd);
|
|
361 #ifdef INET_SOCKETS
|
|
362 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
|
363 {
|
|
364 PERROR("socket()#2 in netbeans_connect()");
|
|
365 goto theend;
|
|
366 }
|
|
367 #else
|
|
368 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
|
369 {
|
|
370 PERROR("socket()#2 in netbeans_connect()");
|
|
371 goto theend;
|
|
372 }
|
|
373 #endif
|
|
374 if (connect(sd, (struct sockaddr *)&server, sizeof(server)))
|
|
375 {
|
|
376 int retries = 36;
|
|
377 int success = FALSE;
|
|
378 while (retries--
|
|
379 && ((sock_errno == ECONNREFUSED) || (sock_errno == EINTR)))
|
|
380 {
|
|
381 nbdebug(("retrying...\n"));
|
|
382 sleep(5);
|
|
383 if (connect(sd, (struct sockaddr *)&server,
|
|
384 sizeof(server)) == 0)
|
|
385 {
|
|
386 success = TRUE;
|
|
387 break;
|
|
388 }
|
|
389 }
|
|
390 if (!success)
|
|
391 {
|
|
392 /* Get here when the server can't be found. */
|
|
393 PERROR(_("Cannot connect to Netbeans #2"));
|
|
394 getout(1);
|
|
395 }
|
|
396 }
|
|
397
|
|
398 }
|
|
399 else
|
|
400 {
|
|
401 PERROR(_("Cannot connect to Netbeans"));
|
|
402 getout(1);
|
|
403 }
|
|
404 }
|
|
405
|
|
406 sprintf(buf, "AUTH %s\n", password);
|
|
407 nb_send(buf, "netbeans_connect");
|
|
408
|
|
409 sprintf(buf, "0:version=0 \"%s\"\n", ExtEdProtocolVersion);
|
|
410 nb_send(buf, "externaleditor_version");
|
|
411
|
|
412 /* nb_init_graphics(); delay until needed */
|
|
413
|
|
414 haveConnection = TRUE;
|
|
415
|
|
416 theend:
|
|
417 vim_free(hostname);
|
|
418 vim_free(address);
|
|
419 vim_free(password);
|
|
420 return;
|
|
421 }
|
|
422
|
|
423 /*
|
|
424 * Obtain the NetBeans hostname, port address and password from a file.
|
|
425 * Return the strings in allocated memory.
|
|
426 * Return FAIL if the file could not be read, OK otherwise (no matter what it
|
|
427 * contains).
|
|
428 */
|
|
429 static int
|
|
430 getConnInfo(char *file, char **host, char **port, char **auth)
|
|
431 {
|
|
432 FILE *fp;
|
|
433 char_u buf[BUFSIZ];
|
|
434 char_u *lp;
|
|
435 char_u *nl;
|
|
436 #ifdef UNIX
|
|
437 struct stat st;
|
|
438
|
|
439 /*
|
|
440 * For Unix only accept the file when it's not accessible by others.
|
|
441 * The open will then fail if we don't own the file.
|
|
442 */
|
|
443 if (mch_stat(file, &st) == 0 && (st.st_mode & 0077) != 0)
|
|
444 {
|
|
445 EMSG2(_("E668: Wrong access mode for NetBeans connection info file: \"%s\""),
|
|
446 file);
|
|
447 return FAIL;
|
|
448 }
|
|
449 #endif
|
|
450
|
|
451 fp = mch_fopen(file, "r");
|
|
452 if (fp == NULL)
|
|
453 {
|
|
454 PERROR("E660: Cannot open NetBeans connection info file");
|
|
455 return FAIL;
|
|
456 }
|
|
457
|
|
458 /* Read the file. There should be one of each parameter */
|
|
459 while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL)
|
|
460 {
|
|
461 if ((nl = vim_strchr(lp, '\n')) != NULL)
|
|
462 *nl = 0; /* strip off the trailing newline */
|
|
463
|
|
464 if (STRNCMP(lp, "host=", 5) == 0)
|
|
465 {
|
|
466 vim_free(*host);
|
|
467 *host = (char *)vim_strsave(&buf[5]);
|
|
468 }
|
|
469 else if (STRNCMP(lp, "port=", 5) == 0)
|
|
470 {
|
|
471 vim_free(*port);
|
|
472 *port = (char *)vim_strsave(&buf[5]);
|
|
473 }
|
|
474 else if (STRNCMP(lp, "auth=", 5) == 0)
|
|
475 {
|
|
476 vim_free(*auth);
|
|
477 *auth = (char *)vim_strsave(&buf[5]);
|
|
478 }
|
|
479 }
|
|
480 fclose(fp);
|
|
481
|
|
482 return OK;
|
|
483 }
|
|
484
|
|
485
|
|
486 struct keyqueue
|
|
487 {
|
|
488 int key;
|
|
489 struct keyqueue *next;
|
|
490 struct keyqueue *prev;
|
|
491 };
|
|
492
|
|
493 typedef struct keyqueue keyQ_T;
|
|
494
|
|
495 static keyQ_T keyHead; /* dummy node, header for circular queue */
|
|
496
|
|
497
|
|
498 /*
|
|
499 * Queue up key commands sent from netbeans.
|
|
500 */
|
|
501 static void
|
|
502 postpone_keycommand(int key)
|
|
503 {
|
|
504 keyQ_T *node;
|
|
505
|
|
506 node = (keyQ_T *)alloc(sizeof(keyQ_T));
|
|
507
|
|
508 if (keyHead.next == NULL) /* initialize circular queue */
|
|
509 {
|
|
510 keyHead.next = &keyHead;
|
|
511 keyHead.prev = &keyHead;
|
|
512 }
|
|
513
|
|
514 /* insert node at tail of queue */
|
|
515 node->next = &keyHead;
|
|
516 node->prev = keyHead.prev;
|
|
517 keyHead.prev->next = node;
|
|
518 keyHead.prev = node;
|
|
519
|
|
520 node->key = key;
|
|
521 }
|
|
522
|
|
523 /*
|
|
524 * Handle any queued-up NetBeans keycommands to be send.
|
|
525 */
|
|
526 static void
|
|
527 handle_key_queue(void)
|
|
528 {
|
|
529 while (keyHead.next && keyHead.next != &keyHead)
|
|
530 {
|
|
531 /* first, unlink the node */
|
|
532 keyQ_T *node = keyHead.next;
|
|
533 keyHead.next = node->next;
|
|
534 node->next->prev = node->prev;
|
|
535
|
|
536 /* now, send the keycommand */
|
|
537 netbeans_keycommand(node->key);
|
|
538
|
|
539 /* Finally, dispose of the node */
|
|
540 vim_free(node);
|
|
541 }
|
|
542 }
|
|
543
|
|
544
|
|
545 struct cmdqueue
|
|
546 {
|
|
547 char_u *buffer;
|
|
548 struct cmdqueue *next;
|
|
549 struct cmdqueue *prev;
|
|
550 };
|
|
551
|
|
552 typedef struct cmdqueue queue_T;
|
|
553
|
|
554 static queue_T head; /* dummy node, header for circular queue */
|
|
555
|
|
556
|
|
557 /*
|
|
558 * Put the buffer on the work queue; possibly save it to a file as well.
|
|
559 */
|
|
560 static void
|
|
561 save(char_u *buf, int len)
|
|
562 {
|
|
563 queue_T *node;
|
|
564
|
|
565 node = (queue_T *)alloc(sizeof(queue_T));
|
|
566 if (node == NULL)
|
|
567 return; /* out of memory */
|
|
568 node->buffer = alloc(len + 1);
|
|
569 if (node->buffer == NULL)
|
|
570 {
|
|
571 vim_free(node);
|
|
572 return; /* out of memory */
|
|
573 }
|
|
574 mch_memmove(node->buffer, buf, (size_t)len);
|
|
575 node->buffer[len] = NUL;
|
|
576
|
|
577 if (head.next == NULL) /* initialize circular queue */
|
|
578 {
|
|
579 head.next = &head;
|
|
580 head.prev = &head;
|
|
581 }
|
|
582
|
|
583 /* insert node at tail of queue */
|
|
584 node->next = &head;
|
|
585 node->prev = head.prev;
|
|
586 head.prev->next = node;
|
|
587 head.prev = node;
|
|
588
|
|
589 #ifdef NBDEBUG
|
|
590 {
|
|
591 static int outfd = -2;
|
|
592
|
|
593 /* possibly write buffer out to a file */
|
|
594 if (outfd == -3)
|
|
595 return;
|
|
596
|
|
597 if (outfd == -2)
|
|
598 {
|
|
599 char *file = getenv("__NETBEANS_SAVE");
|
|
600 if (file == NULL)
|
|
601 outfd = -3;
|
|
602 else
|
|
603 outfd = mch_open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
|
604 }
|
|
605
|
|
606 if (outfd >= 0)
|
|
607 write(outfd, buf, len);
|
|
608 }
|
|
609 #endif
|
|
610 }
|
|
611
|
|
612
|
|
613 /*
|
|
614 * While there's still a command in the work queue, parse and execute it.
|
|
615 */
|
|
616 static void
|
|
617 nb_parse_messages(void)
|
|
618 {
|
|
619 char_u *p;
|
|
620 queue_T *node;
|
|
621
|
|
622 while (head.next != &head)
|
|
623 {
|
|
624 node = head.next;
|
|
625
|
|
626 /* Locate the first line in the first buffer. */
|
|
627 p = vim_strchr(node->buffer, '\n');
|
|
628 if (p == NULL)
|
|
629 {
|
|
630 /* Command isn't complete. If there is no following buffer,
|
|
631 * return (wait for more). If there is another buffer following,
|
|
632 * prepend the text to that buffer and delete this one. */
|
|
633 if (node->next == &head)
|
|
634 return;
|
|
635 p = alloc(STRLEN(node->buffer) + STRLEN(node->next->buffer) + 1);
|
|
636 if (p == NULL)
|
|
637 return; /* out of memory */
|
|
638 STRCPY(p, node->buffer);
|
|
639 STRCAT(p, node->next->buffer);
|
|
640 vim_free(node->next->buffer);
|
|
641 node->next->buffer = p;
|
|
642
|
|
643 /* dispose of the node and buffer */
|
|
644 head.next = node->next;
|
|
645 node->next->prev = node->prev;
|
|
646 vim_free(node->buffer);
|
|
647 vim_free(node);
|
|
648 }
|
|
649 else
|
|
650 {
|
|
651 /* There is a complete command at the start of the buffer.
|
|
652 * Terminate it with a NUL. When no more text is following unlink
|
|
653 * the buffer. Do this before executing, because new buffers can
|
|
654 * be added while busy handling the command. */
|
|
655 *p++ = NUL;
|
|
656 if (*p == NUL)
|
|
657 {
|
|
658 head.next = node->next;
|
|
659 node->next->prev = node->prev;
|
|
660 }
|
|
661
|
|
662 /* now, parse and execute the commands */
|
|
663 nb_parse_cmd(node->buffer);
|
|
664
|
|
665 if (*p == NUL)
|
|
666 {
|
|
667 /* buffer finished, dispose of the node and buffer */
|
|
668 vim_free(node->buffer);
|
|
669 vim_free(node);
|
|
670 }
|
|
671 else
|
|
672 {
|
|
673 /* more follows, move to the start */
|
|
674 mch_memmove(node->buffer, p, STRLEN(p) + 1);
|
|
675 }
|
|
676 }
|
|
677 }
|
|
678 }
|
|
679
|
|
680 /* Buffer size for reading incoming messages. */
|
|
681 #define MAXMSGSIZE 4096
|
|
682
|
|
683 /*
|
|
684 * Read and process a command from netbeans.
|
|
685 */
|
|
686 /*ARGSUSED*/
|
|
687 #if defined(FEAT_GUI_W32) || defined(PROTO)
|
|
688 /* Use this one when generating prototypes, the others are static. */
|
|
689 void
|
|
690 messageFromNetbeansW32()
|
|
691 #else
|
|
692 # ifdef FEAT_GUI_MOTIF
|
|
693 static void
|
|
694 messageFromNetbeans(XtPointer clientData, int *unused1, XtInputId *unused2)
|
|
695 # endif
|
|
696 # ifdef FEAT_GUI_GTK
|
|
697 static void
|
|
698 messageFromNetbeans(gpointer clientData, gint unused1,
|
|
699 GdkInputCondition unused2)
|
|
700 # endif
|
|
701 #endif
|
|
702 {
|
|
703 static char_u *buf = NULL;
|
|
704 int len;
|
|
705 int readlen = 0;
|
|
706 static int level = 0;
|
|
707
|
|
708 if (sd < 0)
|
|
709 {
|
|
710 nbdebug(("messageFromNetbeans() called without a socket\n"));
|
|
711 return;
|
|
712 }
|
|
713
|
|
714 ++level; /* recursion guard; this will be called from the X event loop */
|
|
715
|
|
716 /* Allocate a buffer to read into. */
|
|
717 if (buf == NULL)
|
|
718 {
|
|
719 buf = alloc(MAXMSGSIZE);
|
|
720 if (buf == NULL)
|
|
721 return; /* out of memory! */
|
|
722 }
|
|
723
|
|
724 /* Keep on reading for as long as there is something to read. */
|
|
725 for (;;)
|
|
726 {
|
|
727 len = sock_read(sd, buf, MAXMSGSIZE);
|
|
728 if (len <= 0)
|
|
729 break; /* error or nothing more to read */
|
|
730
|
|
731 /* Store the read message in the queue. */
|
|
732 save(buf, len);
|
|
733 readlen += len;
|
|
734 if (len < MAXMSGSIZE)
|
|
735 break; /* did read everything that's available */
|
|
736 }
|
|
737
|
|
738 if (readlen <= 0)
|
|
739 {
|
|
740 /* read error or didn't read anything */
|
|
741 netbeans_disconnect();
|
|
742 nbdebug(("messageFromNetbeans: Error in read() from socket\n"));
|
|
743 if (len < 0)
|
|
744 PERROR(_("read from Netbeans socket"));
|
|
745 return; /* don't try to parse it */;
|
|
746 }
|
|
747
|
|
748 /* Parse the messages, but avoid recursion. */
|
|
749 if (level == 1)
|
|
750 nb_parse_messages();
|
|
751
|
|
752 --level;
|
|
753 }
|
|
754
|
|
755 /*
|
|
756 * Handle one NUL terminated command.
|
|
757 *
|
|
758 * format of a command from netbeans:
|
|
759 *
|
|
760 * 6:setTitle!84 "a.c"
|
|
761 *
|
|
762 * bufno
|
|
763 * colon
|
|
764 * cmd
|
|
765 * !
|
|
766 * cmdno
|
|
767 * args
|
|
768 *
|
|
769 * for function calls, the ! is replaced by a /
|
|
770 */
|
|
771 static void
|
|
772 nb_parse_cmd(char_u *cmd)
|
|
773 {
|
27
|
774 char *verb;
|
|
775 char *q;
|
7
|
776 int bufno;
|
|
777 int isfunc = -1;
|
|
778
|
|
779 if (STRCMP(cmd, "DISCONNECT") == 0)
|
|
780 {
|
|
781 /* We assume the server knows that we can safely exit! */
|
|
782 if (sd >= 0)
|
|
783 sock_close(sd);
|
|
784 /* Disconnect before exiting, Motif hangs in a Select error
|
|
785 * message otherwise. */
|
|
786 netbeans_disconnect();
|
|
787 getout(0);
|
|
788 /* NOTREACHED */
|
|
789 }
|
|
790
|
|
791 if (STRCMP(cmd, "DETACH") == 0)
|
|
792 {
|
|
793 /* The IDE is breaking the connection. */
|
|
794 if (sd >= 0)
|
|
795 sock_close(sd);
|
|
796 netbeans_disconnect();
|
|
797 return;
|
|
798 }
|
|
799
|
27
|
800 bufno = strtol((char *)cmd, &verb, 10);
|
7
|
801
|
|
802 if (*verb != ':')
|
|
803 {
|
|
804 EMSG2("E627: missing colon: %s", cmd);
|
|
805 return;
|
|
806 }
|
|
807 ++verb; /* skip colon */
|
|
808
|
|
809 for (q = verb; *q; q++)
|
|
810 {
|
|
811 if (*q == '!')
|
|
812 {
|
|
813 *q++ = NUL;
|
|
814 isfunc = 0;
|
|
815 break;
|
|
816 }
|
|
817 else if (*q == '/')
|
|
818 {
|
|
819 *q++ = NUL;
|
|
820 isfunc = 1;
|
|
821 break;
|
|
822 }
|
|
823 }
|
|
824
|
|
825 if (isfunc < 0)
|
|
826 {
|
|
827 EMSG2("E628: missing ! or / in: %s", cmd);
|
|
828 return;
|
|
829 }
|
|
830
|
27
|
831 cmdno = strtol(q, &q, 10);
|
|
832
|
|
833 q = (char *)skipwhite((char_u *)q);
|
|
834
|
|
835 if (nb_do_cmd(bufno, (char_u *)verb, isfunc, cmdno, (char_u *)q) == FAIL)
|
7
|
836 {
|
33
|
837 #ifdef NBDEBUG
|
|
838 /*
|
|
839 * This happens because the ExtEd can send a cammand or 2 after
|
|
840 * doing a stopDocumentListen command. It doesn't harm anything
|
|
841 * so I'm disabling it except for debugging.
|
|
842 */
|
7
|
843 nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd));
|
|
844 EMSG("E629: bad return from nb_do_cmd");
|
33
|
845 #endif
|
7
|
846 }
|
|
847 }
|
|
848
|
|
849 struct nbbuf_struct
|
|
850 {
|
|
851 buf_T *bufp;
|
|
852 unsigned int fireChanges:1;
|
|
853 unsigned int initDone:1;
|
33
|
854 unsigned int insertDone:1;
|
7
|
855 unsigned int modified:1;
|
33
|
856 int nbbuf_number;
|
7
|
857 char *displayname;
|
|
858 int *signmap;
|
|
859 short_u signmaplen;
|
|
860 short_u signmapused;
|
|
861 };
|
|
862
|
|
863 typedef struct nbbuf_struct nbbuf_T;
|
|
864
|
|
865 static nbbuf_T *buf_list = 0;
|
|
866 int buf_list_size = 0; /* size of buf_list */
|
|
867 int buf_list_used = 0; /* nr of entries in buf_list actually in use */
|
|
868
|
|
869 static char **globalsignmap;
|
|
870 static int globalsignmaplen;
|
|
871 static int globalsignmapused;
|
|
872
|
|
873 static int mapsigntype __ARGS((nbbuf_T *, int localsigntype));
|
|
874 static void addsigntype __ARGS((nbbuf_T *, int localsigntype, char_u *typeName,
|
|
875 char_u *tooltip, char_u *glyphfile,
|
|
876 int usefg, int fg, int usebg, int bg));
|
33
|
877 static void print_read_msg __ARGS((nbbuf_T *buf));
|
|
878 static void print_save_msg __ARGS((nbbuf_T *buf, long nchars));
|
7
|
879
|
|
880 static int curPCtype = -1;
|
|
881
|
|
882 /*
|
|
883 * Get the Netbeans buffer number for the specified buffer.
|
|
884 */
|
|
885 static int
|
|
886 nb_getbufno(buf_T *bufp)
|
|
887 {
|
|
888 int i;
|
|
889
|
|
890 for (i = 0; i < buf_list_used; i++)
|
|
891 if (buf_list[i].bufp == bufp)
|
|
892 return i;
|
|
893 return -1;
|
|
894 }
|
|
895
|
|
896 /*
|
|
897 * Is this a NetBeans-owned buffer?
|
|
898 */
|
|
899 int
|
|
900 isNetbeansBuffer(buf_T *bufp)
|
|
901 {
|
33
|
902 return usingNetbeans && bufp->b_netbeans_file;
|
7
|
903 }
|
|
904
|
|
905 /*
|
|
906 * NetBeans and Vim have different undo models. In Vim, the file isn't
|
|
907 * changed if changes are undone via the undo command. In NetBeans, once
|
|
908 * a change has been made the file is marked as modified until saved. It
|
|
909 * doesn't matter if the change was undone.
|
|
910 *
|
|
911 * So this function is for the corner case where Vim thinks a buffer is
|
|
912 * unmodified but NetBeans thinks it IS modified.
|
|
913 */
|
|
914 int
|
|
915 isNetbeansModified(buf_T *bufp)
|
|
916 {
|
33
|
917 if (usingNetbeans && bufp->b_netbeans_file)
|
|
918 {
|
|
919 int bufno = nb_getbufno(bufp);
|
|
920
|
|
921 if (bufno > 0)
|
|
922 return buf_list[bufno].modified;
|
|
923 else
|
|
924 return FALSE;
|
|
925 }
|
7
|
926 else
|
|
927 return FALSE;
|
|
928 }
|
|
929
|
|
930 /*
|
|
931 * Given a Netbeans buffer number, return the netbeans buffer.
|
|
932 * Returns NULL for 0 or a negative number. A 0 bufno means a
|
|
933 * non-buffer related command has been sent.
|
|
934 */
|
|
935 static nbbuf_T *
|
|
936 nb_get_buf(int bufno)
|
|
937 {
|
|
938 /* find or create a buffer with the given number */
|
|
939 int incr;
|
|
940
|
|
941 if (bufno <= 0)
|
|
942 return NULL;
|
|
943
|
|
944 if (!buf_list)
|
|
945 {
|
|
946 /* initialize */
|
|
947 buf_list = (nbbuf_T *)alloc_clear(100 * sizeof(nbbuf_T));
|
|
948 buf_list_size = 100;
|
|
949 }
|
|
950 if (bufno >= buf_list_used) /* new */
|
|
951 {
|
|
952 if (bufno >= buf_list_size) /* grow list */
|
|
953 {
|
|
954 incr = bufno - buf_list_size + 90;
|
|
955 buf_list_size += incr;
|
|
956 buf_list = (nbbuf_T *)vim_realloc(
|
|
957 buf_list, buf_list_size * sizeof(nbbuf_T));
|
|
958 memset(buf_list + buf_list_size - incr, 0, incr * sizeof(nbbuf_T));
|
|
959 }
|
|
960
|
|
961 while (buf_list_used <= bufno)
|
|
962 {
|
|
963 /* Default is to fire text changes. */
|
|
964 buf_list[buf_list_used].fireChanges = 1;
|
|
965 ++buf_list_used;
|
|
966 }
|
|
967 }
|
|
968
|
|
969 return buf_list + bufno;
|
|
970 }
|
|
971
|
|
972 /*
|
|
973 * Return the number of buffers that are modified.
|
|
974 */
|
|
975 static int
|
|
976 count_changed_buffers(void)
|
|
977 {
|
|
978 buf_T *bufp;
|
|
979 int n;
|
|
980
|
|
981 n = 0;
|
|
982 for (bufp = firstbuf; bufp != NULL; bufp = bufp->b_next)
|
|
983 if (bufp->b_changed)
|
|
984 ++n;
|
|
985 return n;
|
|
986 }
|
|
987
|
|
988 /*
|
|
989 * End the netbeans session.
|
|
990 */
|
|
991 void
|
|
992 netbeans_end(void)
|
|
993 {
|
|
994 int i;
|
|
995 static char buf[128];
|
|
996
|
|
997 if (!haveConnection)
|
|
998 return;
|
|
999
|
|
1000 for (i = 0; i < buf_list_used; i++)
|
|
1001 {
|
|
1002 if (!buf_list[i].bufp)
|
|
1003 continue;
|
|
1004 if (netbeansForcedQuit)
|
|
1005 {
|
|
1006 /* mark as unmodified so NetBeans won't put up dialog on "killed" */
|
|
1007 sprintf(buf, "%d:unmodified=%d\n", i, cmdno);
|
|
1008 nbdebug(("EVT: %s", buf));
|
|
1009 nb_send(buf, "netbeans_end");
|
|
1010 }
|
|
1011 sprintf(buf, "%d:killed=%d\n", i, cmdno);
|
|
1012 nbdebug(("EVT: %s", buf));
|
|
1013 /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */
|
|
1014 if (sd >= 0)
|
|
1015 sock_write(sd, buf, STRLEN(buf)); /* ignore errors */
|
|
1016 }
|
|
1017 }
|
|
1018
|
|
1019 /*
|
|
1020 * Send a message to netbeans.
|
|
1021 */
|
|
1022 static void
|
|
1023 nb_send(char *buf, char *fun)
|
|
1024 {
|
|
1025 /* Avoid giving pages full of error messages when the other side has
|
|
1026 * exited, only mention the first error until the connection works again. */
|
|
1027 static int did_error = FALSE;
|
|
1028
|
|
1029 if (sd < 0)
|
|
1030 {
|
|
1031 if (!did_error)
|
|
1032 EMSG2("E630: %s(): write while not connected", fun);
|
|
1033 did_error = TRUE;
|
|
1034 }
|
|
1035 else if (sock_write(sd, buf, STRLEN(buf)) != (int)STRLEN(buf))
|
|
1036 {
|
|
1037 if (!did_error)
|
|
1038 EMSG2("E631: %s(): write failed", fun);
|
|
1039 did_error = TRUE;
|
|
1040 }
|
|
1041 else
|
|
1042 did_error = FALSE;
|
|
1043 }
|
|
1044
|
|
1045 /*
|
|
1046 * Some input received from netbeans requires a response. This function
|
|
1047 * handles a response with no information (except the command number).
|
|
1048 */
|
|
1049 static void
|
|
1050 nb_reply_nil(int cmdno)
|
|
1051 {
|
|
1052 char reply[32];
|
|
1053
|
|
1054 if (!haveConnection)
|
|
1055 return;
|
|
1056
|
33
|
1057 nbdebug(("REP %d: <none>\n", cmdno));
|
|
1058
|
7
|
1059 sprintf(reply, "%d\n", cmdno);
|
|
1060 nb_send(reply, "nb_reply_nil");
|
|
1061 }
|
|
1062
|
|
1063
|
|
1064 /*
|
|
1065 * Send a response with text.
|
|
1066 * "result" must have been quoted already (using nb_quote()).
|
|
1067 */
|
|
1068 static void
|
|
1069 nb_reply_text(int cmdno, char_u *result)
|
|
1070 {
|
|
1071 char_u *reply;
|
|
1072
|
|
1073 if (!haveConnection)
|
|
1074 return;
|
|
1075
|
33
|
1076 nbdebug(("REP %d: %s\n", cmdno, (char *)result));
|
|
1077
|
7
|
1078 reply = alloc(STRLEN(result) + 32);
|
|
1079 sprintf((char *)reply, "%d %s\n", cmdno, (char *)result);
|
|
1080 nb_send((char *)reply, "nb_reply_text");
|
|
1081
|
|
1082 vim_free(reply);
|
|
1083 }
|
|
1084
|
|
1085
|
|
1086 /*
|
|
1087 * Send a response with a number result code.
|
|
1088 */
|
|
1089 static void
|
|
1090 nb_reply_nr(int cmdno, long result)
|
|
1091 {
|
|
1092 char reply[32];
|
|
1093
|
|
1094 if (!haveConnection)
|
|
1095 return;
|
|
1096
|
33
|
1097 nbdebug(("REP %d: %ld\n", cmdno, result));
|
|
1098
|
7
|
1099 sprintf(reply, "%d %ld\n", cmdno, result);
|
|
1100 nb_send(reply, "nb_reply_nr");
|
|
1101 }
|
|
1102
|
|
1103
|
|
1104 /*
|
|
1105 * Encode newline, ret, backslash, double quote for transmission to NetBeans.
|
|
1106 */
|
|
1107 static char_u *
|
|
1108 nb_quote(char_u *txt)
|
|
1109 {
|
|
1110 char_u *buf = alloc(2 * STRLEN(txt) + 1);
|
|
1111 char_u *p = txt;
|
|
1112 char_u *q = buf;
|
|
1113
|
|
1114 if (buf == NULL)
|
|
1115 return NULL;
|
|
1116 for (; *p; p++)
|
|
1117 {
|
|
1118 switch (*p)
|
|
1119 {
|
|
1120 case '\"':
|
|
1121 case '\\':
|
|
1122 *q++ = '\\'; *q++ = *p; break;
|
|
1123 /* case '\t': */
|
|
1124 /* *q++ = '\\'; *q++ = 't'; break; */
|
|
1125 case '\n':
|
|
1126 *q++ = '\\'; *q++ = 'n'; break;
|
|
1127 case '\r':
|
|
1128 *q++ = '\\'; *q++ = 'r'; break;
|
|
1129 default:
|
|
1130 *q++ = *p;
|
|
1131 break;
|
|
1132 }
|
|
1133 }
|
|
1134 *q++ = '\0';
|
|
1135
|
|
1136 return buf;
|
|
1137 }
|
|
1138
|
|
1139
|
|
1140 /*
|
|
1141 * Remove top level double quotes; convert backslashed chars.
|
|
1142 * Returns an allocated string (NULL for failure).
|
|
1143 * If "endp" is not NULL it is set to the character after the terminating
|
|
1144 * quote.
|
|
1145 */
|
|
1146 static char *
|
|
1147 nb_unquote(char_u *p, char_u **endp)
|
|
1148 {
|
|
1149 char *result = 0;
|
|
1150 char *q;
|
|
1151 int done = 0;
|
|
1152
|
|
1153 /* result is never longer than input */
|
|
1154 result = (char *)alloc_clear(STRLEN(p) + 1);
|
|
1155 if (result == NULL)
|
|
1156 return NULL;
|
|
1157
|
|
1158 if (*p++ != '"')
|
|
1159 {
|
|
1160 nbdebug(("nb_unquote called with string that doesn't start with a quote!: %s\n",
|
|
1161 p));
|
|
1162 result[0] = NUL;
|
|
1163 return result;
|
|
1164 }
|
|
1165
|
|
1166 for (q = result; !done && *p != NUL;)
|
|
1167 {
|
|
1168 switch (*p)
|
|
1169 {
|
|
1170 case '"':
|
|
1171 /*
|
|
1172 * Unbackslashed dquote marks the end, if first char was dquote.
|
|
1173 */
|
|
1174 done = 1;
|
|
1175 break;
|
|
1176
|
|
1177 case '\\':
|
|
1178 ++p;
|
|
1179 switch (*p)
|
|
1180 {
|
|
1181 case '\\': *q++ = '\\'; break;
|
|
1182 case 'n': *q++ = '\n'; break;
|
|
1183 case 't': *q++ = '\t'; break;
|
|
1184 case 'r': *q++ = '\r'; break;
|
|
1185 case '"': *q++ = '"'; break;
|
|
1186 case NUL: --p; break;
|
|
1187 /* default: skip over illegal chars */
|
|
1188 }
|
|
1189 ++p;
|
|
1190 break;
|
|
1191
|
|
1192 default:
|
|
1193 *q++ = *p++;
|
|
1194 }
|
|
1195 }
|
|
1196
|
|
1197 if (endp != NULL)
|
|
1198 *endp = p;
|
|
1199
|
|
1200 return result;
|
|
1201 }
|
|
1202
|
|
1203 #define SKIP_STOP 2
|
|
1204 #define streq(a,b) (strcmp(a,b) == 0)
|
|
1205 static int needupdate = 0;
|
|
1206 static int inAtomic = 0;
|
|
1207
|
|
1208 /*
|
|
1209 * Do the actual processing of a single netbeans command or function.
|
|
1210 * The differance between a command and function is that a function
|
|
1211 * gets a response (its required) but a command does not.
|
|
1212 * For arguments see comment for nb_parse_cmd().
|
|
1213 */
|
|
1214 static int
|
|
1215 nb_do_cmd(
|
|
1216 int bufno,
|
|
1217 char_u *cmd,
|
|
1218 int func,
|
|
1219 int cmdno,
|
|
1220 char_u *args) /* points to space before arguments or NUL */
|
|
1221 {
|
|
1222 int doupdate = 0;
|
|
1223 long off = 0;
|
|
1224 nbbuf_T *buf = nb_get_buf(bufno);
|
|
1225 static int skip = 0;
|
|
1226 int retval = OK;
|
27
|
1227 char *cp; /* for when a char pointer is needed */
|
7
|
1228
|
|
1229 nbdebug(("%s %d: (%d) %s %s\n", (func) ? "FUN" : "CMD", cmdno, bufno, cmd,
|
|
1230 STRCMP(cmd, "insert") == 0 ? "<text>" : (char *)args));
|
|
1231
|
|
1232 if (func)
|
|
1233 {
|
|
1234 /* =====================================================================*/
|
|
1235 if (streq((char *)cmd, "getModified"))
|
|
1236 {
|
|
1237 if (buf == NULL || buf->bufp == NULL)
|
|
1238 /* Return the number of buffers that are modified. */
|
|
1239 nb_reply_nr(cmdno, (long)count_changed_buffers());
|
|
1240 else
|
|
1241 /* Return whether the buffer is modified. */
|
|
1242 nb_reply_nr(cmdno, (long)(buf->bufp->b_changed
|
|
1243 || isNetbeansModified(buf->bufp)));
|
|
1244 /* =====================================================================*/
|
|
1245 }
|
|
1246 else if (streq((char *)cmd, "saveAndExit"))
|
|
1247 {
|
|
1248 /* Note: this will exit Vim if successful. */
|
|
1249 coloncmd(":confirm qall");
|
|
1250
|
|
1251 /* We didn't exit: return the number of changed buffers. */
|
|
1252 nb_reply_nr(cmdno, (long)count_changed_buffers());
|
|
1253 /* =====================================================================*/
|
|
1254 }
|
|
1255 else if (streq((char *)cmd, "getCursor"))
|
|
1256 {
|
|
1257 char_u text[200];
|
|
1258
|
|
1259 /* Note: nb_getbufno() may return -1. This indicates the IDE
|
|
1260 * didn't assign a number to the current buffer in response to a
|
|
1261 * fileOpened event. */
|
|
1262 sprintf((char *)text, "%d %ld %d %ld",
|
|
1263 nb_getbufno(curbuf),
|
|
1264 (long)curwin->w_cursor.lnum,
|
|
1265 (int)curwin->w_cursor.col,
|
|
1266 pos2off(curbuf, &curwin->w_cursor));
|
|
1267 nb_reply_text(cmdno, text);
|
|
1268 /* =====================================================================*/
|
|
1269 }
|
|
1270 else if (streq((char *)cmd, "getLength"))
|
|
1271 {
|
|
1272 long len = 0;
|
|
1273
|
|
1274 if (buf == NULL || buf->bufp == NULL)
|
|
1275 {
|
|
1276 nbdebug((" null bufp in getLength"));
|
|
1277 EMSG("E632: null bufp in getLength");
|
|
1278 retval = FAIL;
|
|
1279 }
|
|
1280 else
|
|
1281 {
|
|
1282 len = get_buf_size(buf->bufp);
|
|
1283 }
|
|
1284 nb_reply_nr(cmdno, len);
|
|
1285 /* =====================================================================*/
|
|
1286 }
|
|
1287 else if (streq((char *)cmd, "getText"))
|
|
1288 {
|
|
1289 long len;
|
|
1290 linenr_T nlines;
|
|
1291 char_u *text = NULL;
|
|
1292 linenr_T lno = 1;
|
|
1293 char_u *p;
|
|
1294 char_u *line;
|
|
1295
|
|
1296 if (buf == NULL || buf->bufp == NULL)
|
|
1297 {
|
|
1298 nbdebug((" null bufp in getText"));
|
|
1299 EMSG("E633: null bufp in getText");
|
|
1300 retval = FAIL;
|
|
1301 }
|
|
1302 else
|
|
1303 {
|
|
1304 len = get_buf_size(buf->bufp);
|
|
1305 nlines = buf->bufp->b_ml.ml_line_count;
|
|
1306 text = alloc((unsigned)((len > 0)
|
|
1307 ? ((len + nlines) * 2) : 4));
|
|
1308 if (text == NULL)
|
|
1309 {
|
|
1310 nbdebug((" nb_do_cmd: getText has null text field\n"));
|
|
1311 retval = FAIL;
|
|
1312 }
|
|
1313 else
|
|
1314 {
|
|
1315 p = text;
|
|
1316 *p++ = '\"';
|
|
1317 for (; lno <= nlines ; lno++)
|
|
1318 {
|
|
1319 line = nb_quote(ml_get_buf(buf->bufp, lno, FALSE));
|
|
1320 if (line != NULL)
|
|
1321 {
|
|
1322 STRCPY(p, line);
|
|
1323 p += STRLEN(line);
|
|
1324 *p++ = '\\';
|
|
1325 *p++ = 'n';
|
33
|
1326 vim_free(line);
|
7
|
1327 }
|
|
1328 }
|
|
1329 *p++ = '\"';
|
|
1330 *p = '\0';
|
|
1331 }
|
|
1332 }
|
|
1333 if (text == NULL)
|
|
1334 nb_reply_text(cmdno, (char_u *)"");
|
|
1335 else
|
|
1336 {
|
|
1337 nb_reply_text(cmdno, text);
|
|
1338 vim_free(text);
|
|
1339 }
|
|
1340 /* =====================================================================*/
|
|
1341 }
|
|
1342 else if (streq((char *)cmd, "remove"))
|
|
1343 {
|
|
1344 long count;
|
|
1345 pos_T first, last;
|
|
1346 pos_T *pos;
|
|
1347 int oldFire = netbeansFireChanges;
|
|
1348 int oldSuppress = netbeansSuppressNoLines;
|
|
1349 int wasChanged;
|
|
1350
|
|
1351 if (skip >= SKIP_STOP)
|
|
1352 {
|
|
1353 nbdebug((" Skipping %s command\n", (char *) cmd));
|
|
1354 nb_reply_nil(cmdno);
|
|
1355 return OK;
|
|
1356 }
|
|
1357
|
|
1358 if (buf == NULL || buf->bufp == NULL)
|
|
1359 {
|
|
1360 nbdebug((" null bufp in remove"));
|
|
1361 EMSG("E634: null bufp in remove");
|
|
1362 retval = FAIL;
|
|
1363 }
|
|
1364 else
|
|
1365 {
|
|
1366 netbeansFireChanges = FALSE;
|
|
1367 netbeansSuppressNoLines = TRUE;
|
|
1368
|
|
1369 if (curbuf != buf->bufp)
|
|
1370 set_curbuf(buf->bufp, DOBUF_GOTO);
|
|
1371 wasChanged = buf->bufp->b_changed;
|
27
|
1372 cp = (char *)args;
|
|
1373 off = strtol(cp, &cp, 10);
|
|
1374 count = strtol(cp, &cp, 10);
|
|
1375 args = (char_u *)cp;
|
7
|
1376 /* delete "count" chars, starting at "off" */
|
|
1377 pos = off2pos(buf->bufp, off);
|
|
1378 if (!pos)
|
|
1379 {
|
|
1380 nb_reply_text(cmdno, (char_u *)"!bad position");
|
|
1381 netbeansFireChanges = oldFire;
|
|
1382 netbeansSuppressNoLines = oldSuppress;
|
|
1383 return FAIL;
|
|
1384 }
|
|
1385 first = *pos;
|
|
1386 nbdebug((" FIRST POS: line %d, col %d\n", first.lnum, first.col));
|
|
1387 pos = off2pos(buf->bufp, off+count-1);
|
|
1388 if (!pos)
|
|
1389 {
|
|
1390 nb_reply_text(cmdno, (char_u *)"!bad count");
|
|
1391 netbeansFireChanges = oldFire;
|
|
1392 netbeansSuppressNoLines = oldSuppress;
|
|
1393 return FAIL;
|
|
1394 }
|
|
1395 last = *pos;
|
|
1396 nbdebug((" LAST POS: line %d, col %d\n", last.lnum, last.col));
|
|
1397 curwin->w_cursor = first;
|
|
1398 doupdate = 1;
|
|
1399
|
|
1400 /* keep part of first line */
|
|
1401 if (first.lnum == last.lnum && first.col != last.col)
|
|
1402 {
|
|
1403 /* deletion is within one line */
|
|
1404 char_u *p = ml_get(first.lnum);
|
|
1405 mch_memmove(p + first.col, p + last.col + 1, STRLEN(p + last.col) + 1);
|
|
1406 nbdebug((" NEW LINE %d: %s\n", first.lnum, p));
|
|
1407 ml_replace(first.lnum, p, TRUE);
|
|
1408 }
|
|
1409
|
|
1410 if (first.lnum < last.lnum)
|
|
1411 {
|
|
1412 int i;
|
|
1413
|
|
1414 /* delete signs from the lines being deleted */
|
|
1415 for (i = first.lnum; i <= last.lnum; i++)
|
|
1416 {
|
|
1417 int id = buf_findsign_id(buf->bufp, (linenr_T)i);
|
|
1418 if (id > 0)
|
|
1419 {
|
|
1420 nbdebug((" Deleting sign %d on line %d\n", id, i));
|
|
1421 buf_delsign(buf->bufp, id);
|
|
1422 }
|
|
1423 else
|
|
1424 nbdebug((" No sign on line %d\n", i));
|
|
1425 }
|
|
1426
|
|
1427 /* delete whole lines */
|
|
1428 nbdebug((" Deleting lines %d through %d\n", first.lnum, last.lnum));
|
|
1429 del_lines(last.lnum - first.lnum + 1, FALSE);
|
|
1430 }
|
|
1431 buf->bufp->b_changed = wasChanged; /* logically unchanged */
|
|
1432 netbeansFireChanges = oldFire;
|
|
1433 netbeansSuppressNoLines = oldSuppress;
|
|
1434
|
|
1435 u_blockfree(buf->bufp);
|
|
1436 u_clearall(buf->bufp);
|
|
1437 }
|
|
1438 nb_reply_nil(cmdno);
|
|
1439 /* =====================================================================*/
|
|
1440 }
|
|
1441 else if (streq((char *)cmd, "insert"))
|
|
1442 {
|
|
1443 pos_T *pos;
|
|
1444 pos_T mypos;
|
|
1445 char_u *to_free;
|
|
1446 char_u *nl;
|
33
|
1447 linenr_T lnum;
|
7
|
1448 pos_T old_w_cursor;
|
|
1449 int old_b_changed;
|
|
1450
|
|
1451 if (skip >= SKIP_STOP)
|
|
1452 {
|
|
1453 nbdebug((" Skipping %s command\n", (char *) cmd));
|
|
1454 nb_reply_nil(cmdno);
|
|
1455 return OK;
|
|
1456 }
|
|
1457
|
|
1458 /* get offset */
|
27
|
1459 cp = (char *)args;
|
|
1460 off = strtol(cp, &cp, 10);
|
|
1461 args = (char_u *)cp;
|
7
|
1462
|
|
1463 /* get text to be inserted */
|
|
1464 args = skipwhite(args);
|
|
1465 args = to_free = (char_u *)nb_unquote(args, NULL);
|
33
|
1466 /*
|
|
1467 nbdebug((" CHUNK[%d]: %d bytes at offset %d\n",
|
|
1468 buf->bufp->b_ml.ml_line_count, STRLEN(args), off));
|
|
1469 */
|
7
|
1470
|
|
1471 if (buf == NULL || buf->bufp == NULL)
|
|
1472 {
|
|
1473 nbdebug((" null bufp in insert"));
|
|
1474 EMSG("E635: null bufp in insert");
|
|
1475 retval = FAIL;
|
|
1476 }
|
|
1477 else if (args != NULL)
|
|
1478 {
|
33
|
1479 /*
|
|
1480 * We need to detect EOL style
|
7
|
1481 * because addAnno passes char-offset
|
|
1482 */
|
|
1483 int ff_detected = EOL_UNKNOWN;
|
|
1484 int buf_was_empty = (buf->bufp->b_ml.ml_flags & ML_EMPTY);
|
33
|
1485 char_u lbuf[4096]; /* size of largest insert sent by exted */
|
|
1486 int lbuf_len = 0;
|
7
|
1487
|
|
1488 oldFire = netbeansFireChanges;
|
|
1489 netbeansFireChanges = 0;
|
33
|
1490 lbuf[0] = '\0';
|
7
|
1491
|
|
1492 if (curbuf != buf->bufp)
|
|
1493 set_curbuf(buf->bufp, DOBUF_GOTO);
|
|
1494 old_b_changed = buf->bufp->b_changed;
|
|
1495
|
|
1496 pos = off2pos(buf->bufp, off);
|
|
1497 if (pos)
|
|
1498 {
|
|
1499 if (pos->lnum == 0)
|
|
1500 pos->lnum = 1;
|
|
1501 }
|
|
1502 else
|
|
1503 {
|
|
1504 /* if the given position is not found, assume we want
|
|
1505 * the end of the file. See setLocAndSize HACK. */
|
|
1506 pos = &mypos;
|
|
1507 pos->col = 0;
|
|
1508 #ifdef FEAT_VIRTUALEDIT
|
|
1509 pos->coladd = 0;
|
|
1510 #endif
|
|
1511 pos->lnum = buf->bufp->b_ml.ml_line_count;
|
|
1512 }
|
|
1513 lnum = pos->lnum;
|
|
1514 old_w_cursor = curwin->w_cursor;
|
|
1515 curwin->w_cursor = *pos;
|
|
1516
|
33
|
1517 if (buf->bufp->b_start_eol == FALSE && lnum > 0)
|
|
1518 {
|
|
1519 /* Append to a partial line */
|
|
1520 char_u *partial = ml_get(lnum);
|
|
1521
|
|
1522 if (partial != IObuff)
|
|
1523 STRCPY(lbuf, partial);
|
|
1524 lbuf_len = STRLEN(partial);
|
|
1525 ml_delete(lnum, FALSE);
|
|
1526 }
|
|
1527
|
7
|
1528 doupdate = 1;
|
|
1529 while (*args)
|
|
1530 {
|
|
1531 nl = (char_u *)strchr((char *)args, '\n');
|
33
|
1532 if (nl)
|
7
|
1533 {
|
33
|
1534 STRNCAT(lbuf, args, nl - args);
|
|
1535 lbuf[lbuf_len + nl - args] = '\0';
|
|
1536 args += nl - args + 1;
|
7
|
1537 }
|
33
|
1538 else
|
|
1539 {
|
|
1540 STRCPY(lbuf, args);
|
|
1541 args += STRLEN(lbuf);
|
|
1542 }
|
|
1543
|
|
1544 /*
|
|
1545 * EOL detecting. Not sure how to deal with '\n' on Mac.
|
7
|
1546 */
|
33
|
1547 if (buf_was_empty && nl && *(nl - 1) != '\r')
|
7
|
1548 ff_detected = EOL_UNIX;
|
|
1549
|
33
|
1550 /* nbdebug((" INSERT[%d]: %s\n", lnum, lbuf)); */
|
|
1551 ml_append((linenr_T)(lnum++ - 1), lbuf,
|
|
1552 STRLEN(lbuf) + 1, FALSE);
|
|
1553 lbuf[0] = '\0'; /* empty buffer */
|
|
1554 lbuf_len = 0;
|
|
1555 }
|
|
1556
|
|
1557 if (*(args - 1) == '\n')
|
|
1558 {
|
|
1559 buf->bufp->b_p_eol = TRUE;
|
|
1560 buf->bufp->b_start_eol = TRUE;
|
|
1561 }
|
|
1562 else
|
|
1563 {
|
|
1564 buf->bufp->b_p_eol = FALSE;
|
|
1565 buf->bufp->b_start_eol = FALSE;
|
7
|
1566 }
|
|
1567
|
|
1568 appended_lines_mark(pos->lnum - 1, lnum - pos->lnum);
|
|
1569
|
|
1570 /* We can change initial ff without consequences
|
|
1571 * Isn't it a kind of hacking?
|
|
1572 */
|
|
1573 if (buf_was_empty)
|
|
1574 {
|
|
1575 if (ff_detected == EOL_UNKNOWN)
|
|
1576 ff_detected = EOL_DOS;
|
|
1577 set_fileformat(ff_detected, OPT_LOCAL);
|
|
1578 buf->bufp->b_start_ffc = *buf->bufp->b_p_ff;
|
33
|
1579 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
|
7
|
1580 }
|
|
1581
|
|
1582 curwin->w_cursor = old_w_cursor;
|
|
1583
|
|
1584 /*
|
|
1585 * XXX - GRP - Is the next line right? If I've inserted
|
|
1586 * text the buffer has been updated but not written. Will
|
|
1587 * netbeans guarantee to write it? Even if I do a :q! ?
|
|
1588 */
|
|
1589 buf->bufp->b_changed = old_b_changed; /* logically unchanged */
|
|
1590 netbeansFireChanges = oldFire;
|
|
1591
|
|
1592 u_blockfree(buf->bufp);
|
|
1593 u_clearall(buf->bufp);
|
|
1594 }
|
|
1595 vim_free(to_free);
|
|
1596 nb_reply_nil(cmdno); /* or !error */
|
|
1597 }
|
|
1598 else
|
|
1599 {
|
|
1600 nbdebug(("UNIMPLEMENTED FUNCTION: %s\n", cmd));
|
|
1601 nb_reply_nil(cmdno);
|
|
1602 retval = FAIL;
|
|
1603 }
|
|
1604 }
|
|
1605 else /* Not a function; no reply required. */
|
|
1606 {
|
|
1607 /* =====================================================================*/
|
|
1608 if (streq((char *)cmd, "create"))
|
|
1609 {
|
|
1610 /* Create a buffer without a name. */
|
|
1611 if (buf == NULL)
|
|
1612 {
|
|
1613 EMSG("E636: null buf in create");
|
|
1614 return FAIL;
|
|
1615 }
|
|
1616 vim_free(buf->displayname);
|
|
1617 buf->displayname = NULL;
|
|
1618
|
|
1619 netbeansReadFile = 0; /* don't try to open disk file */
|
|
1620 do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF);
|
|
1621 netbeansReadFile = 1;
|
|
1622 buf->bufp = curbuf;
|
|
1623 maketitle();
|
33
|
1624 buf->insertDone = FALSE;
|
7
|
1625 gui_update_menus(0);
|
|
1626 /* =====================================================================*/
|
|
1627 }
|
33
|
1628 else if (streq((char *)cmd, "insertDone"))
|
|
1629 {
|
|
1630 buf->bufp->b_start_eol = *args == 'T';
|
|
1631 buf->insertDone = TRUE;
|
|
1632 args += 2;
|
|
1633 buf->bufp->b_p_ro = *args == 'T';
|
|
1634 print_read_msg(buf);
|
|
1635 /* =====================================================================*/
|
|
1636 }
|
|
1637 else if (streq((char *)cmd, "saveDone"))
|
|
1638 {
|
|
1639 long savedChars = atol((char *) args);
|
|
1640 print_save_msg(buf, savedChars);
|
|
1641 /* =====================================================================*/
|
|
1642 }
|
7
|
1643 else if (streq((char *)cmd, "startDocumentListen"))
|
|
1644 {
|
|
1645 if (buf == NULL)
|
|
1646 {
|
|
1647 EMSG("E637: null buf in startDocumentListen");
|
|
1648 return FAIL;
|
|
1649 }
|
|
1650 buf->fireChanges = 1;
|
|
1651 /* =====================================================================*/
|
|
1652 }
|
|
1653 else if (streq((char *)cmd, "stopDocumentListen"))
|
|
1654 {
|
|
1655 if (buf == NULL)
|
|
1656 {
|
|
1657 EMSG("E638: null buf in stopDocumentListen");
|
|
1658 return FAIL;
|
|
1659 }
|
|
1660 buf->fireChanges = 0;
|
152
|
1661 if (buf->bufp != NULL && buf->bufp->b_was_netbeans_file)
|
33
|
1662 {
|
152
|
1663 if (!buf->bufp->b_netbeans_file)
|
33
|
1664 EMSGN(_("E658: NetBeans connection lost for buffer %ld"),
|
7
|
1665 buf->bufp->b_fnum);
|
33
|
1666 else
|
|
1667 {
|
152
|
1668 /* NetBeans uses stopDocumentListen when it stops editing
|
|
1669 * a file. It then expects the buffer in Vim to
|
|
1670 * disappear. */
|
|
1671 do_bufdel(DOBUF_DEL, (char_u *)"", 1,
|
|
1672 buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE);
|
33
|
1673 vim_memset(buf, 0, sizeof(nbbuf_T));
|
|
1674 }
|
|
1675 }
|
7
|
1676 /* =====================================================================*/
|
|
1677 }
|
|
1678 else if (streq((char *)cmd, "setTitle"))
|
|
1679 {
|
|
1680 if (buf == NULL)
|
|
1681 {
|
|
1682 EMSG("E639: null buf in setTitle");
|
|
1683 return FAIL;
|
|
1684 }
|
|
1685 vim_free(buf->displayname);
|
|
1686 buf->displayname = nb_unquote(args, NULL);
|
|
1687 /* =====================================================================*/
|
|
1688 }
|
|
1689 else if (streq((char *)cmd, "initDone"))
|
|
1690 {
|
|
1691 if (buf == NULL || buf->bufp == NULL)
|
|
1692 {
|
|
1693 EMSG("E640: null buf in initDone");
|
|
1694 return FAIL;
|
|
1695 }
|
|
1696 doupdate = 1;
|
33
|
1697 buf->initDone = TRUE;
|
7
|
1698 if (curbuf != buf->bufp)
|
|
1699 set_curbuf(buf->bufp, DOBUF_GOTO);
|
|
1700 #if defined(FEAT_AUTOCMD)
|
|
1701 apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp);
|
|
1702 #endif
|
|
1703
|
|
1704 /* handle any postponed key commands */
|
|
1705 handle_key_queue();
|
|
1706 /* =====================================================================*/
|
|
1707 }
|
|
1708 else if (streq((char *)cmd, "setBufferNumber")
|
|
1709 || streq((char *)cmd, "putBufferNumber"))
|
|
1710 {
|
33
|
1711 char_u *path;
|
7
|
1712 buf_T *bufp;
|
|
1713
|
|
1714 if (buf == NULL)
|
|
1715 {
|
|
1716 EMSG("E641: null buf in setBufferNumber");
|
|
1717 return FAIL;
|
|
1718 }
|
33
|
1719 path = (char_u *)nb_unquote(args, NULL);
|
|
1720 if (path == NULL)
|
7
|
1721 return FAIL;
|
33
|
1722 bufp = buflist_findname(path);
|
|
1723 vim_free(path);
|
7
|
1724 if (bufp == NULL)
|
|
1725 {
|
|
1726 EMSG2("E642: File %s not found in setBufferNumber", args);
|
|
1727 return FAIL;
|
|
1728 }
|
|
1729 buf->bufp = bufp;
|
33
|
1730 buf->nbbuf_number = bufp->b_fnum;
|
7
|
1731
|
|
1732 /* "setBufferNumber" has the side effect of jumping to the buffer
|
|
1733 * (don't know why!). Don't do that for "putBufferNumber". */
|
|
1734 if (*cmd != 'p')
|
|
1735 coloncmd(":buffer %d", bufp->b_fnum);
|
|
1736 else
|
|
1737 {
|
33
|
1738 buf->initDone = TRUE;
|
7
|
1739
|
|
1740 /* handle any postponed key commands */
|
|
1741 handle_key_queue();
|
|
1742 }
|
|
1743
|
|
1744 #if 0 /* never used */
|
|
1745 buf->internalname = (char *)alloc_clear(8);
|
|
1746 sprintf(buf->internalname, "<%d>", bufno);
|
|
1747 buf->netbeansOwns = 0;
|
|
1748 #endif
|
|
1749 /* =====================================================================*/
|
|
1750 }
|
|
1751 else if (streq((char *)cmd, "setFullName"))
|
|
1752 {
|
|
1753 if (buf == NULL)
|
|
1754 {
|
|
1755 EMSG("E643: null buf in setFullName");
|
|
1756 return FAIL;
|
|
1757 }
|
|
1758 vim_free(buf->displayname);
|
|
1759 buf->displayname = nb_unquote(args, NULL);
|
|
1760
|
|
1761 netbeansReadFile = 0; /* don't try to open disk file */
|
|
1762 do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE,
|
|
1763 ECMD_HIDE + ECMD_OLDBUF);
|
|
1764 netbeansReadFile = 1;
|
|
1765 buf->bufp = curbuf;
|
|
1766 maketitle();
|
|
1767 gui_update_menus(0);
|
|
1768 /* =====================================================================*/
|
|
1769 }
|
|
1770 else if (streq((char *)cmd, "editFile"))
|
|
1771 {
|
|
1772 if (buf == NULL)
|
|
1773 {
|
|
1774 EMSG("E644: null buf in editFile");
|
|
1775 return FAIL;
|
|
1776 }
|
|
1777 /* Edit a file: like create + setFullName + read the file. */
|
|
1778 vim_free(buf->displayname);
|
|
1779 buf->displayname = nb_unquote(args, NULL);
|
|
1780 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
|
|
1781 ECMD_HIDE + ECMD_OLDBUF);
|
|
1782 buf->bufp = curbuf;
|
33
|
1783 buf->initDone = TRUE;
|
7
|
1784 doupdate = 1;
|
|
1785 #if defined(FEAT_TITLE)
|
|
1786 maketitle();
|
|
1787 #endif
|
|
1788 gui_update_menus(0);
|
|
1789 /* =====================================================================*/
|
|
1790 }
|
|
1791 else if (streq((char *)cmd, "setVisible"))
|
|
1792 {
|
|
1793 if (buf == NULL || buf->bufp == NULL)
|
|
1794 {
|
|
1795 /* EMSG("E645: null bufp in setVisible"); */
|
|
1796 return FAIL;
|
|
1797 }
|
33
|
1798 if (streq((char *)args, "T") && buf->bufp != curbuf)
|
7
|
1799 {
|
|
1800 exarg_T exarg;
|
|
1801 exarg.cmd = (char_u *)"goto";
|
|
1802 exarg.forceit = FALSE;
|
33
|
1803 dosetvisible = TRUE;
|
7
|
1804 goto_buffer(&exarg, DOBUF_FIRST, FORWARD, buf->bufp->b_fnum);
|
|
1805 doupdate = 1;
|
33
|
1806 dosetvisible = FALSE;
|
7
|
1807
|
|
1808 /* Side effect!!!. */
|
|
1809 if (!gui.starting)
|
|
1810 gui_mch_set_foreground();
|
|
1811 }
|
|
1812 /* =====================================================================*/
|
|
1813 }
|
|
1814 else if (streq((char *)cmd, "raise"))
|
|
1815 {
|
|
1816 /* Bring gvim to the foreground. */
|
|
1817 if (!gui.starting)
|
|
1818 gui_mch_set_foreground();
|
|
1819 /* =====================================================================*/
|
|
1820 }
|
|
1821 else if (streq((char *)cmd, "setModified"))
|
|
1822 {
|
|
1823 if (buf == NULL || buf->bufp == NULL)
|
|
1824 {
|
|
1825 /* EMSG("E646: null bufp in setModified"); */
|
|
1826 return FAIL;
|
|
1827 }
|
|
1828 if (streq((char *)args, "T"))
|
|
1829 buf->bufp->b_changed = 1;
|
|
1830 else
|
|
1831 {
|
|
1832 struct stat st;
|
|
1833
|
|
1834 /* Assume NetBeans stored the file. Reset the timestamp to
|
|
1835 * avoid "file changed" warnings. */
|
|
1836 if (buf->bufp->b_ffname != NULL
|
|
1837 && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0)
|
|
1838 buf_store_time(buf->bufp, &st, buf->bufp->b_ffname);
|
|
1839 buf->bufp->b_changed = 0;
|
|
1840 }
|
|
1841 buf->modified = buf->bufp->b_changed;
|
|
1842 /* =====================================================================*/
|
|
1843 }
|
33
|
1844 else if (streq((char *)cmd, "setModtime"))
|
|
1845 {
|
|
1846 buf->bufp->b_mtime = atoi((char *) args);
|
|
1847 /* =====================================================================*/
|
|
1848 }
|
|
1849 else if (streq((char *)cmd, "setReadOnly"))
|
|
1850 {
|
|
1851 if (streq((char *)args, "T"))
|
|
1852 buf->bufp->b_p_ro = TRUE;
|
|
1853 else
|
|
1854 buf->bufp->b_p_ro = FALSE;
|
|
1855 /* =====================================================================*/
|
|
1856 }
|
7
|
1857 else if (streq((char *)cmd, "setMark"))
|
|
1858 {
|
|
1859 /* not yet */
|
|
1860 /* =====================================================================*/
|
|
1861 }
|
|
1862 else if (streq((char *)cmd, "showBalloon"))
|
|
1863 {
|
|
1864 #if defined(FEAT_BEVAL)
|
|
1865 static char *text = NULL;
|
|
1866
|
|
1867 /*
|
|
1868 * Set up the Balloon Expression Evaluation area.
|
|
1869 * Ignore 'ballooneval' here.
|
|
1870 * The text pointer must remain valid for a while.
|
|
1871 */
|
|
1872 if (balloonEval != NULL)
|
|
1873 {
|
|
1874 vim_free(text);
|
|
1875 text = nb_unquote(args, NULL);
|
|
1876 if (text != NULL)
|
|
1877 gui_mch_post_balloon(balloonEval, (char_u *)text);
|
|
1878 }
|
|
1879 #endif
|
|
1880 /* =====================================================================*/
|
|
1881 }
|
|
1882 else if (streq((char *)cmd, "setDot"))
|
|
1883 {
|
|
1884 pos_T *pos;
|
|
1885 #ifdef NBDEBUG
|
|
1886 char_u *s;
|
|
1887 #endif
|
|
1888
|
|
1889 if (buf == NULL || buf->bufp == NULL)
|
|
1890 {
|
|
1891 EMSG("E647: null bufp in setDot");
|
|
1892 return FAIL;
|
|
1893 }
|
|
1894
|
|
1895 if (curbuf != buf->bufp)
|
|
1896 set_curbuf(buf->bufp, DOBUF_GOTO);
|
|
1897 #ifdef FEAT_VISUAL
|
|
1898 /* Don't want Visual mode now. */
|
|
1899 if (VIsual_active)
|
|
1900 end_visual_mode();
|
|
1901 #endif
|
|
1902 #ifdef NBDEBUG
|
|
1903 s = args;
|
|
1904 #endif
|
|
1905 pos = get_off_or_lnum(buf->bufp, &args);
|
|
1906 if (pos)
|
|
1907 {
|
|
1908 curwin->w_cursor = *pos;
|
|
1909 check_cursor();
|
|
1910 #ifdef FEAT_FOLDING
|
|
1911 foldOpenCursor();
|
|
1912 #endif
|
|
1913 }
|
|
1914 else
|
|
1915 nbdebug((" BAD POSITION in setDot: %s\n", s));
|
|
1916
|
|
1917 /* gui_update_cursor(TRUE, FALSE); */
|
|
1918 /* update_curbuf(NOT_VALID); */
|
|
1919 update_topline(); /* scroll to show the line */
|
|
1920 update_screen(VALID);
|
|
1921 setcursor();
|
|
1922 out_flush();
|
|
1923 gui_update_cursor(TRUE, FALSE);
|
|
1924 gui_mch_flush();
|
|
1925 /* Quit a hit-return or more prompt. */
|
|
1926 if (State == HITRETURN || State == ASKMORE)
|
|
1927 {
|
|
1928 #ifdef FEAT_GUI_GTK
|
|
1929 if (gtk_main_level() > 0)
|
|
1930 gtk_main_quit();
|
|
1931 #endif
|
|
1932 }
|
|
1933 /* =====================================================================*/
|
|
1934 }
|
|
1935 else if (streq((char *)cmd, "close"))
|
|
1936 {
|
|
1937 #ifdef NBDEBUG
|
|
1938 char *name = "<NONE>";
|
|
1939 #endif
|
|
1940
|
|
1941 if (buf == NULL)
|
|
1942 {
|
|
1943 EMSG("E648: null buf in close");
|
|
1944 return FAIL;
|
|
1945 }
|
|
1946
|
|
1947 #ifdef NBDEBUG
|
|
1948 if (buf->displayname != NULL)
|
|
1949 name = buf->displayname;
|
|
1950 #endif
|
|
1951 /* if (buf->bufp == NULL) */
|
|
1952 /* EMSG("E649: null bufp in close"); */
|
|
1953 nbdebug((" CLOSE %d: %s\n", bufno, name));
|
|
1954 need_mouse_correct = TRUE;
|
|
1955 if (buf->bufp != NULL)
|
|
1956 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD,
|
|
1957 buf->bufp->b_fnum, TRUE);
|
|
1958 doupdate = 1;
|
|
1959 /* =====================================================================*/
|
|
1960 }
|
|
1961 else if (streq((char *)cmd, "setStyle")) /* obsolete... */
|
|
1962 {
|
|
1963 nbdebug((" setStyle is obsolete!"));
|
|
1964 /* =====================================================================*/
|
|
1965 }
|
|
1966 else if (streq((char *)cmd, "setExitDelay"))
|
|
1967 {
|
33
|
1968 /* Only used in version 2.1. */
|
7
|
1969 /* =====================================================================*/
|
|
1970 }
|
|
1971 else if (streq((char *)cmd, "defineAnnoType"))
|
|
1972 {
|
|
1973 #ifdef FEAT_SIGNS
|
|
1974 int typeNum;
|
|
1975 char_u *typeName;
|
|
1976 char_u *tooltip;
|
|
1977 char_u *p;
|
|
1978 char_u *glyphFile;
|
|
1979 int use_fg = 0;
|
|
1980 int use_bg = 0;
|
|
1981 int fg = -1;
|
|
1982 int bg = -1;
|
|
1983
|
|
1984 if (buf == NULL)
|
|
1985 {
|
|
1986 EMSG("E650: null buf in defineAnnoType");
|
|
1987 return FAIL;
|
|
1988 }
|
|
1989
|
27
|
1990 cp = (char *)args;
|
|
1991 typeNum = strtol(cp, &cp, 10);
|
|
1992 args = (char_u *)cp;
|
7
|
1993 args = skipwhite(args);
|
|
1994 typeName = (char_u *)nb_unquote(args, &args);
|
|
1995 args = skipwhite(args + 1);
|
|
1996 tooltip = (char_u *)nb_unquote(args, &args);
|
|
1997 args = skipwhite(args + 1);
|
|
1998
|
|
1999 p = (char_u *)nb_unquote(args, &args);
|
|
2000 glyphFile = vim_strsave_escaped(p, escape_chars);
|
|
2001 vim_free(p);
|
|
2002
|
|
2003 args = skipwhite(args + 1);
|
|
2004 if (STRNCMP(args, "none", 4) == 0)
|
|
2005 args += 5;
|
|
2006 else
|
|
2007 {
|
|
2008 use_fg = 1;
|
27
|
2009 cp = (char *)args;
|
|
2010 fg = strtol(cp, &cp, 10);
|
|
2011 args = (char_u *)cp;
|
7
|
2012 }
|
|
2013 if (STRNCMP(args, "none", 4) == 0)
|
|
2014 args += 5;
|
|
2015 else
|
|
2016 {
|
|
2017 use_bg = 1;
|
27
|
2018 cp = (char *)args;
|
|
2019 bg = strtol(cp, &cp, 10);
|
|
2020 args = (char_u *)cp;
|
7
|
2021 }
|
|
2022 if (typeName != NULL && tooltip != NULL && glyphFile != NULL)
|
|
2023 addsigntype(buf, typeNum, typeName, tooltip, glyphFile,
|
|
2024 use_fg, fg, use_bg, bg);
|
|
2025 else
|
|
2026 vim_free(typeName);
|
|
2027
|
|
2028 /* don't free typeName; it's used directly in addsigntype() */
|
|
2029 vim_free(tooltip);
|
|
2030 vim_free(glyphFile);
|
|
2031
|
|
2032 #endif
|
|
2033 /* =====================================================================*/
|
|
2034 }
|
|
2035 else if (streq((char *)cmd, "addAnno"))
|
|
2036 {
|
|
2037 #ifdef FEAT_SIGNS
|
|
2038 int serNum;
|
|
2039 int localTypeNum;
|
|
2040 int typeNum;
|
|
2041 # ifdef NBDEBUG
|
|
2042 int len;
|
|
2043 # endif
|
|
2044 pos_T *pos;
|
|
2045
|
|
2046 if (buf == NULL || buf->bufp == NULL)
|
|
2047 {
|
|
2048 EMSG("E651: null bufp in addAnno");
|
|
2049 return FAIL;
|
|
2050 }
|
|
2051
|
|
2052 doupdate = 1;
|
|
2053
|
27
|
2054 cp = (char *)args;
|
|
2055 serNum = strtol(cp, &cp, 10);
|
7
|
2056
|
|
2057 /* Get the typenr specific for this buffer and convert it to
|
|
2058 * the global typenumber, as used for the sign name. */
|
27
|
2059 localTypeNum = strtol(cp, &cp, 10);
|
|
2060 args = (char_u *)cp;
|
7
|
2061 typeNum = mapsigntype(buf, localTypeNum);
|
|
2062
|
|
2063 pos = get_off_or_lnum(buf->bufp, &args);
|
|
2064
|
27
|
2065 cp = (char *)args;
|
7
|
2066 # ifdef NBDEBUG
|
|
2067 len =
|
|
2068 # endif
|
27
|
2069 strtol(cp, &cp, 10);
|
|
2070 args = (char_u *)cp;
|
7
|
2071 # ifdef NBDEBUG
|
|
2072 if (len != -1)
|
|
2073 {
|
|
2074 nbdebug((" partial line annotation -- Not Yet Implemented!"));
|
|
2075 }
|
|
2076 # endif
|
|
2077 if (serNum >= GUARDEDOFFSET)
|
|
2078 {
|
|
2079 nbdebug((" too many annotations! ignoring..."));
|
|
2080 return FAIL;
|
|
2081 }
|
|
2082 if (pos)
|
|
2083 {
|
|
2084 coloncmd(":sign place %d line=%d name=%d buffer=%d",
|
|
2085 serNum, pos->lnum, typeNum, buf->bufp->b_fnum);
|
|
2086 if (typeNum == curPCtype)
|
|
2087 coloncmd(":sign jump %d buffer=%d", serNum,
|
|
2088 buf->bufp->b_fnum);
|
|
2089 }
|
|
2090 /* XXX only redraw what changed. */
|
|
2091 redraw_later(CLEAR);
|
|
2092 #endif
|
|
2093 /* =====================================================================*/
|
|
2094 }
|
|
2095 else if (streq((char *)cmd, "removeAnno"))
|
|
2096 {
|
|
2097 #ifdef FEAT_SIGNS
|
|
2098 int serNum;
|
|
2099
|
|
2100 if (buf == NULL || buf->bufp == NULL)
|
|
2101 {
|
|
2102 nbdebug((" null bufp in removeAnno"));
|
|
2103 return FAIL;
|
|
2104 }
|
|
2105 doupdate = 1;
|
27
|
2106 cp = (char *)args;
|
|
2107 serNum = strtol(cp, &cp, 10);
|
|
2108 args = (char_u *)cp;
|
7
|
2109 coloncmd(":sign unplace %d buffer=%d",
|
|
2110 serNum, buf->bufp->b_fnum);
|
|
2111 redraw_buf_later(buf->bufp, NOT_VALID);
|
|
2112 #endif
|
|
2113 /* =====================================================================*/
|
|
2114 }
|
|
2115 else if (streq((char *)cmd, "moveAnnoToFront"))
|
|
2116 {
|
|
2117 #ifdef FEAT_SIGNS
|
|
2118 nbdebug((" moveAnnoToFront: Not Yet Implemented!"));
|
|
2119 #endif
|
|
2120 /* =====================================================================*/
|
|
2121 }
|
|
2122 else if (streq((char *)cmd, "guard") || streq((char *)cmd, "unguard"))
|
|
2123 {
|
|
2124 int len;
|
|
2125 pos_T first;
|
|
2126 pos_T last;
|
|
2127 pos_T *pos;
|
|
2128 int un = (cmd[0] == 'u');
|
|
2129 static int guardId = GUARDEDOFFSET;
|
|
2130
|
|
2131 if (skip >= SKIP_STOP)
|
|
2132 {
|
|
2133 nbdebug((" Skipping %s command\n", (char *) cmd));
|
|
2134 return OK;
|
|
2135 }
|
|
2136
|
|
2137 nb_init_graphics();
|
|
2138
|
|
2139 if (buf == NULL || buf->bufp == NULL)
|
|
2140 {
|
|
2141 nbdebug((" null bufp in %s command", cmd));
|
|
2142 return FAIL;
|
|
2143 }
|
|
2144 if (curbuf != buf->bufp)
|
|
2145 set_curbuf(buf->bufp, DOBUF_GOTO);
|
27
|
2146 cp = (char *)args;
|
|
2147 off = strtol(cp, &cp, 10);
|
|
2148 len = strtol(cp, NULL, 10);
|
|
2149 args = (char_u *)cp;
|
7
|
2150 pos = off2pos(buf->bufp, off);
|
|
2151 doupdate = 1;
|
|
2152 if (!pos)
|
|
2153 nbdebug((" no such start pos in %s, %ld\n", cmd, off));
|
|
2154 else
|
|
2155 {
|
|
2156 first = *pos;
|
|
2157 pos = off2pos(buf->bufp, off + len - 1);
|
33
|
2158 if (pos != NULL && pos->col == 0)
|
|
2159 {
|
7
|
2160 /*
|
|
2161 * In Java Swing the offset is a position between 2
|
|
2162 * characters. If col == 0 then we really want the
|
|
2163 * previous line as the end.
|
|
2164 */
|
|
2165 pos = off2pos(buf->bufp, off + len - 2);
|
|
2166 }
|
|
2167 if (!pos)
|
|
2168 nbdebug((" no such end pos in %s, %ld\n",
|
|
2169 cmd, off + len - 1));
|
|
2170 else
|
|
2171 {
|
|
2172 long lnum;
|
|
2173 last = *pos;
|
|
2174 /* set highlight for region */
|
|
2175 nbdebug((" %sGUARD %ld,%d to %ld,%d\n", (un) ? "UN" : "",
|
|
2176 first.lnum, first.col,
|
|
2177 last.lnum, last.col));
|
|
2178 #ifdef FEAT_SIGNS
|
|
2179 for (lnum = first.lnum; lnum <= last.lnum; lnum++)
|
|
2180 {
|
|
2181 if (un)
|
|
2182 {
|
|
2183 /* never used */
|
|
2184 }
|
|
2185 else
|
|
2186 {
|
|
2187 if (buf_findsigntype_id(buf->bufp, lnum,
|
|
2188 GUARDED) == 0)
|
|
2189 {
|
|
2190 coloncmd(
|
|
2191 ":sign place %d line=%d name=%d buffer=%d",
|
|
2192 guardId++, lnum, GUARDED,
|
|
2193 buf->bufp->b_fnum);
|
|
2194 }
|
|
2195 }
|
|
2196 }
|
|
2197 #endif
|
|
2198 redraw_buf_later(buf->bufp, NOT_VALID);
|
|
2199 }
|
|
2200 }
|
|
2201 /* =====================================================================*/
|
|
2202 }
|
|
2203 else if (streq((char *)cmd, "startAtomic"))
|
|
2204 {
|
|
2205 inAtomic = 1;
|
|
2206 /* =====================================================================*/
|
|
2207 }
|
|
2208 else if (streq((char *)cmd, "endAtomic"))
|
|
2209 {
|
|
2210 inAtomic = 0;
|
|
2211 if (needupdate)
|
|
2212 {
|
|
2213 doupdate = 1;
|
|
2214 needupdate = 0;
|
|
2215 }
|
|
2216 /* =====================================================================*/
|
|
2217 }
|
|
2218 else if (streq((char *)cmd, "save"))
|
|
2219 {
|
33
|
2220 /*
|
|
2221 * NOTE - This command is obsolete wrt NetBeans. Its left in
|
|
2222 * only for historical reasons.
|
|
2223 */
|
7
|
2224 if (buf == NULL || buf->bufp == NULL)
|
|
2225 {
|
|
2226 nbdebug((" null bufp in %s command", cmd));
|
|
2227 return FAIL;
|
|
2228 }
|
|
2229
|
|
2230 /* the following is taken from ex_cmds.c (do_wqall function) */
|
|
2231 if (bufIsChanged(buf->bufp))
|
|
2232 {
|
|
2233 /* Only write if the buffer can be written. */
|
|
2234 if (p_write
|
|
2235 && !buf->bufp->b_p_ro
|
|
2236 && buf->bufp->b_ffname != NULL
|
|
2237 #ifdef FEAT_QUICKFIX
|
|
2238 && !bt_dontwrite(buf->bufp)
|
|
2239 #endif
|
|
2240 )
|
|
2241 {
|
|
2242 buf_write_all(buf->bufp, FALSE);
|
|
2243 #ifdef FEAT_AUTOCMD
|
|
2244 /* an autocommand may have deleted the buffer */
|
|
2245 if (!buf_valid(buf->bufp))
|
|
2246 buf->bufp = NULL;
|
|
2247 #endif
|
|
2248 }
|
|
2249 }
|
|
2250 /* =====================================================================*/
|
|
2251 }
|
|
2252 else if (streq((char *)cmd, "netbeansBuffer"))
|
|
2253 {
|
|
2254 if (buf == NULL || buf->bufp == NULL)
|
|
2255 {
|
|
2256 nbdebug((" null bufp in %s command", cmd));
|
|
2257 return FAIL;
|
|
2258 }
|
|
2259 if (*args == 'T')
|
|
2260 {
|
|
2261 buf->bufp->b_netbeans_file = TRUE;
|
|
2262 buf->bufp->b_was_netbeans_file = TRUE;
|
|
2263 }
|
|
2264 else
|
|
2265 buf->bufp->b_netbeans_file = FALSE;
|
|
2266 /* =====================================================================*/
|
|
2267 }
|
33
|
2268 else if (streq((char *)cmd, "specialKeys"))
|
|
2269 {
|
|
2270 special_keys(args);
|
|
2271 /* =====================================================================*/
|
|
2272 }
|
|
2273 else if (streq((char *)cmd, "actionMenuItem"))
|
|
2274 {
|
|
2275 /* not used yet */
|
|
2276 /* =====================================================================*/
|
|
2277 }
|
7
|
2278 else if (streq((char *)cmd, "version"))
|
|
2279 {
|
33
|
2280 /* not used yet */
|
7
|
2281 }
|
|
2282 /*
|
|
2283 * Unrecognized command is ignored.
|
|
2284 */
|
|
2285 }
|
|
2286 if (inAtomic && doupdate)
|
|
2287 {
|
|
2288 needupdate = 1;
|
|
2289 doupdate = 0;
|
|
2290 }
|
|
2291
|
33
|
2292 /*
|
|
2293 * Is this needed? I moved the netbeans_Xt_connect() later during startup
|
|
2294 * and it may no longer be necessary. If its not needed then needupdate
|
|
2295 * and doupdate can also be removed.
|
|
2296 */
|
7
|
2297 if (buf != NULL && buf->initDone && doupdate)
|
|
2298 {
|
|
2299 update_screen(NOT_VALID);
|
|
2300 setcursor();
|
|
2301 out_flush();
|
|
2302 gui_update_cursor(TRUE, FALSE);
|
|
2303 gui_mch_flush();
|
|
2304 /* Quit a hit-return or more prompt. */
|
|
2305 if (State == HITRETURN || State == ASKMORE)
|
|
2306 {
|
|
2307 #ifdef FEAT_GUI_GTK
|
|
2308 if (gtk_main_level() > 0)
|
|
2309 gtk_main_quit();
|
|
2310 #endif
|
|
2311 }
|
|
2312 }
|
|
2313
|
|
2314 return retval;
|
|
2315 }
|
|
2316
|
|
2317
|
|
2318 /*
|
|
2319 * Process a vim colon command.
|
|
2320 */
|
|
2321 static void
|
|
2322 coloncmd(char *cmd, ...)
|
|
2323 {
|
|
2324 char buf[1024];
|
|
2325 va_list ap;
|
|
2326
|
|
2327 va_start(ap, cmd);
|
|
2328 vsprintf(buf, cmd, ap);
|
|
2329 va_end(ap);
|
|
2330
|
|
2331 nbdebug((" COLONCMD %s\n", buf));
|
|
2332
|
|
2333 /* ALT_INPUT_LOCK_ON; */
|
|
2334 do_cmdline((char_u *)buf, NULL, NULL, DOCMD_NOWAIT | DOCMD_KEYTYPED);
|
|
2335 /* ALT_INPUT_LOCK_OFF; */
|
|
2336
|
|
2337 setcursor(); /* restore the cursor position */
|
|
2338 out_flush(); /* make sure output has been written */
|
|
2339
|
|
2340 gui_update_cursor(TRUE, FALSE);
|
|
2341 gui_mch_flush();
|
|
2342 }
|
|
2343
|
|
2344
|
|
2345 /*
|
33
|
2346 * Parse the specialKeys argument and issue the appropriate map commands.
|
|
2347 */
|
|
2348 static void
|
|
2349 special_keys(char_u *args)
|
|
2350 {
|
|
2351 char *save_str = nb_unquote(args, NULL);
|
|
2352 char *tok = strtok(save_str, " ");
|
|
2353 char *sep;
|
|
2354 char keybuf[64];
|
|
2355 char cmdbuf[256];
|
|
2356
|
|
2357 while (tok != NULL)
|
|
2358 {
|
|
2359 int i = 0;
|
|
2360
|
|
2361 if ((sep = strchr(tok, '-')) != NULL)
|
|
2362 {
|
36
|
2363 *sep = NUL;
|
33
|
2364 while (*tok)
|
|
2365 {
|
|
2366 switch (*tok)
|
|
2367 {
|
|
2368 case 'A':
|
|
2369 case 'M':
|
|
2370 case 'C':
|
|
2371 case 'S':
|
|
2372 keybuf[i++] = *tok;
|
|
2373 keybuf[i++] = '-';
|
|
2374 break;
|
|
2375 }
|
|
2376 tok++;
|
|
2377 }
|
|
2378 tok++;
|
|
2379 }
|
|
2380
|
|
2381 strcpy(&keybuf[i], tok);
|
|
2382 sprintf(cmdbuf, "<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
|
|
2383 do_map(0, (char_u *)cmdbuf, NORMAL, FALSE);
|
|
2384 tok = strtok(NULL, " ");
|
|
2385 }
|
|
2386 vim_free(save_str);
|
|
2387 }
|
|
2388
|
|
2389
|
|
2390 void
|
|
2391 ex_nbkey(eap)
|
|
2392 exarg_T *eap;
|
|
2393 {
|
|
2394 netbeans_keystring(0, (char *)eap->arg);
|
|
2395 }
|
|
2396
|
|
2397
|
|
2398 /*
|
7
|
2399 * Initialize highlights and signs for use by netbeans (mostly obsolete)
|
|
2400 */
|
|
2401 static void
|
|
2402 nb_init_graphics(void)
|
|
2403 {
|
|
2404 static int did_init = FALSE;
|
|
2405
|
|
2406 if (!did_init)
|
|
2407 {
|
|
2408 coloncmd(":highlight NBGuarded guibg=Cyan guifg=Black");
|
|
2409 coloncmd(":sign define %d linehl=NBGuarded", GUARDED);
|
|
2410
|
|
2411 did_init = TRUE;
|
|
2412 }
|
|
2413 }
|
|
2414
|
|
2415 /*
|
|
2416 * Convert key to netbeans name.
|
|
2417 */
|
|
2418 static void
|
|
2419 netbeans_keyname(int key, char *buf)
|
|
2420 {
|
|
2421 char *name = 0;
|
|
2422 char namebuf[2];
|
|
2423 int ctrl = 0;
|
|
2424 int shift = 0;
|
|
2425 int alt = 0;
|
|
2426
|
|
2427 if (mod_mask & MOD_MASK_CTRL)
|
|
2428 ctrl = 1;
|
|
2429 if (mod_mask & MOD_MASK_SHIFT)
|
|
2430 shift = 1;
|
|
2431 if (mod_mask & MOD_MASK_ALT)
|
|
2432 alt = 1;
|
|
2433
|
|
2434
|
|
2435 switch (key)
|
|
2436 {
|
|
2437 case K_F1: name = "F1"; break;
|
|
2438 case K_S_F1: name = "F1"; shift = 1; break;
|
|
2439 case K_F2: name = "F2"; break;
|
|
2440 case K_S_F2: name = "F2"; shift = 1; break;
|
|
2441 case K_F3: name = "F3"; break;
|
|
2442 case K_S_F3: name = "F3"; shift = 1; break;
|
|
2443 case K_F4: name = "F4"; break;
|
|
2444 case K_S_F4: name = "F4"; shift = 1; break;
|
|
2445 case K_F5: name = "F5"; break;
|
|
2446 case K_S_F5: name = "F5"; shift = 1; break;
|
|
2447 case K_F6: name = "F6"; break;
|
|
2448 case K_S_F6: name = "F6"; shift = 1; break;
|
|
2449 case K_F7: name = "F7"; break;
|
|
2450 case K_S_F7: name = "F7"; shift = 1; break;
|
|
2451 case K_F8: name = "F8"; break;
|
|
2452 case K_S_F8: name = "F8"; shift = 1; break;
|
|
2453 case K_F9: name = "F9"; break;
|
|
2454 case K_S_F9: name = "F9"; shift = 1; break;
|
|
2455 case K_F10: name = "F10"; break;
|
|
2456 case K_S_F10: name = "F10"; shift = 1; break;
|
|
2457 case K_F11: name = "F11"; break;
|
|
2458 case K_S_F11: name = "F11"; shift = 1; break;
|
|
2459 case K_F12: name = "F12"; break;
|
|
2460 case K_S_F12: name = "F12"; shift = 1; break;
|
|
2461 default:
|
|
2462 if (key >= ' ' && key <= '~')
|
|
2463 {
|
|
2464 /* Allow ASCII characters. */
|
|
2465 name = namebuf;
|
|
2466 namebuf[0] = key;
|
|
2467 namebuf[1] = NUL;
|
|
2468 }
|
|
2469 else
|
|
2470 name = "X";
|
|
2471 break;
|
|
2472 }
|
|
2473
|
|
2474 buf[0] = '\0';
|
|
2475 if (ctrl)
|
|
2476 strcat(buf, "C");
|
|
2477 if (shift)
|
|
2478 strcat(buf, "S");
|
|
2479 if (alt)
|
|
2480 strcat(buf, "M"); /* META */
|
|
2481 if (ctrl || shift || alt)
|
|
2482 strcat(buf, "-");
|
|
2483 strcat(buf, name);
|
|
2484 }
|
|
2485
|
|
2486 #ifdef FEAT_BEVAL
|
|
2487 /*
|
|
2488 * Function to be called for balloon evaluation. Grabs the text under the
|
|
2489 * cursor and sends it to the debugger for evaluation. The debugger should
|
|
2490 * respond with a showBalloon command when there is a useful result.
|
|
2491 */
|
|
2492 /*ARGSUSED*/
|
183
|
2493 void
|
7
|
2494 netbeans_beval_cb(
|
|
2495 BalloonEval *beval,
|
|
2496 int state)
|
|
2497 {
|
183
|
2498 win_T *wp;
|
7
|
2499 char_u *text;
|
183
|
2500 linenr_T lnum;
|
7
|
2501 int col;
|
|
2502 char buf[MAXPATHL * 2 + 25];
|
|
2503 char_u *p;
|
|
2504
|
|
2505 /* Don't do anything when 'ballooneval' is off, messages scrolled the
|
|
2506 * windows up or we have no connection. */
|
|
2507 if (!p_beval || msg_scrolled > 0 || !haveConnection)
|
|
2508 return;
|
|
2509
|
183
|
2510 if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
|
7
|
2511 {
|
|
2512 /* Send debugger request. Only when the text is of reasonable
|
|
2513 * length. */
|
|
2514 if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
|
|
2515 {
|
|
2516 p = nb_quote(text);
|
|
2517 if (p != NULL)
|
33
|
2518 {
|
7
|
2519 sprintf(buf, "0:balloonText=%d \"%s\"\n", cmdno, p);
|
33
|
2520 vim_free(p);
|
|
2521 }
|
7
|
2522 nbdebug(("EVT: %s", buf));
|
|
2523 nb_send(buf, "netbeans_beval_cb");
|
|
2524 }
|
|
2525 vim_free(text);
|
|
2526 }
|
|
2527 }
|
|
2528 #endif
|
|
2529
|
|
2530 /*
|
|
2531 * Tell netbeans that the window was opened, ready for commands.
|
|
2532 */
|
|
2533 void
|
|
2534 netbeans_startup_done(void)
|
|
2535 {
|
|
2536 char *cmd = "0:startupDone=0\n";
|
|
2537
|
33
|
2538 if (usingNetbeans)
|
|
2539 #ifdef FEAT_GUI_MOTIF
|
|
2540 netbeans_Xt_connect(app_context);
|
|
2541 #else
|
|
2542 # ifdef FEAT_GUI_GTK
|
|
2543 netbeans_gtk_connect();
|
167
|
2544 # else
|
|
2545 # ifdef FEAT_GUI_W32
|
|
2546 netbeans_w32_connect();
|
|
2547 # endif
|
33
|
2548 # endif
|
|
2549 #endif
|
|
2550
|
7
|
2551 if (!haveConnection)
|
|
2552 return;
|
|
2553
|
183
|
2554 #ifdef FEAT_BEVAL
|
|
2555 bevalServers |= BEVAL_NETBEANS;
|
|
2556 #endif
|
|
2557
|
7
|
2558 nbdebug(("EVT: %s", cmd));
|
|
2559 nb_send(cmd, "netbeans_startup_done");
|
|
2560 }
|
|
2561
|
33
|
2562 /*
|
|
2563 * Tell netbeans that we're exiting. This should be called right
|
|
2564 * before calling exit.
|
|
2565 */
|
|
2566 void
|
|
2567 netbeans_send_disconnect()
|
|
2568 {
|
|
2569 char buf[128];
|
|
2570
|
|
2571 if (haveConnection)
|
|
2572 {
|
|
2573 sprintf(buf, "0:disconnect=%d\n", cmdno);
|
|
2574 nbdebug(("EVT: %s", buf));
|
|
2575 nb_send(buf, "netbeans_disconnect");
|
|
2576 }
|
|
2577 }
|
|
2578
|
7
|
2579 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_W32) || defined(PROTO)
|
|
2580 /*
|
|
2581 * Tell netbeans that the window was moved or resized.
|
|
2582 */
|
|
2583 void
|
|
2584 netbeans_frame_moved(int new_x, int new_y)
|
|
2585 {
|
|
2586 char buf[128];
|
|
2587
|
|
2588 if (!haveConnection)
|
|
2589 return;
|
|
2590
|
|
2591 sprintf(buf, "0:geometry=%d %d %d %d %d\n",
|
|
2592 cmdno, (int)Columns, (int)Rows, new_x, new_y);
|
33
|
2593 /*nbdebug(("EVT: %s", buf)); happens too many times during a move */
|
7
|
2594 nb_send(buf, "netbeans_frame_moved");
|
|
2595 }
|
|
2596 #endif
|
|
2597
|
|
2598 /*
|
33
|
2599 * Tell netbeans the user opened or activated a file.
|
|
2600 */
|
|
2601 void
|
|
2602 netbeans_file_activated(buf_T *bufp)
|
|
2603 {
|
|
2604 int bufno = nb_getbufno(bufp);
|
|
2605 nbbuf_T *bp = nb_get_buf(bufno);
|
|
2606 char buffer[2*MAXPATHL];
|
|
2607 char_u *q;
|
|
2608
|
|
2609 if (!haveConnection || dosetvisible)
|
|
2610 return;
|
|
2611
|
|
2612 q = nb_quote(bufp->b_ffname);
|
|
2613 if (q == NULL || bp == NULL || bufp == NULL)
|
|
2614 return;
|
|
2615
|
|
2616 sprintf(buffer, "%d:fileOpened=%d \"%s\" %s %s\n",
|
|
2617 bufno,
|
|
2618 bufno,
|
|
2619 (char *)q,
|
|
2620 "T", /* open in NetBeans */
|
|
2621 "F"); /* modified */
|
|
2622
|
|
2623 vim_free(q);
|
|
2624 nbdebug(("EVT: %s", buffer));
|
|
2625
|
|
2626 nb_send(buffer, "netbeans_file_opened");
|
|
2627 }
|
|
2628
|
|
2629 /*
|
7
|
2630 * Tell netbeans the user opened a file.
|
|
2631 */
|
|
2632 void
|
33
|
2633 netbeans_file_opened(buf_T *bufp)
|
7
|
2634 {
|
33
|
2635 int bufno = nb_getbufno(bufp);
|
7
|
2636 char buffer[2*MAXPATHL];
|
|
2637 char_u *q;
|
33
|
2638 nbbuf_T *bp = nb_get_buf(nb_getbufno(bufp));
|
|
2639 int bnum;
|
7
|
2640
|
|
2641 if (!haveConnection)
|
|
2642 return;
|
|
2643
|
33
|
2644 q = nb_quote(bufp->b_ffname);
|
7
|
2645 if (q == NULL)
|
|
2646 return;
|
33
|
2647 if (bp != NULL)
|
|
2648 bnum = bufno;
|
|
2649 else
|
|
2650 bnum = 0;
|
|
2651
|
|
2652 sprintf(buffer, "%d:fileOpened=%d \"%s\" %s %s\n",
|
|
2653 bnum,
|
7
|
2654 0,
|
|
2655 (char *)q,
|
|
2656 "T", /* open in NetBeans */
|
|
2657 "F"); /* modified */
|
|
2658
|
|
2659 vim_free(q);
|
|
2660 nbdebug(("EVT: %s", buffer));
|
|
2661
|
|
2662 nb_send(buffer, "netbeans_file_opened");
|
33
|
2663 if (p_acd && vim_chdirfile(bufp->b_ffname) == OK)
|
7
|
2664 shorten_fnames(TRUE);
|
|
2665 }
|
|
2666
|
|
2667 /*
|
|
2668 * Tell netbeans a file was closed.
|
|
2669 */
|
|
2670 void
|
|
2671 netbeans_file_closed(buf_T *bufp)
|
|
2672 {
|
|
2673 int bufno = nb_getbufno(bufp);
|
|
2674 nbbuf_T *nbbuf = nb_get_buf(bufno);
|
|
2675 char buffer[2*MAXPATHL];
|
|
2676
|
|
2677 if (!haveConnection || bufno < 0)
|
|
2678 return;
|
|
2679
|
|
2680 if (!netbeansCloseFile)
|
|
2681 {
|
33
|
2682 nbdebug(("Ignoring file_closed for %s. File was closed from IDE\n",
|
|
2683 bufp->b_ffname));
|
7
|
2684 return;
|
|
2685 }
|
|
2686
|
33
|
2687 nbdebug(("netbeans_file_closed:\n"));
|
|
2688 nbdebug((" Closing bufno: %d", bufno));
|
|
2689 if (curbuf != NULL && curbuf != bufp)
|
|
2690 {
|
|
2691 nbdebug((" Curbuf bufno: %d\n", nb_getbufno(curbuf)));
|
|
2692 }
|
|
2693 else if (curbuf == bufp)
|
|
2694 {
|
|
2695 nbdebug((" curbuf == bufp\n"));
|
|
2696 }
|
7
|
2697
|
|
2698 if (bufno <= 0)
|
|
2699 return;
|
|
2700
|
|
2701 sprintf(buffer, "%d:killed=%d\n", bufno, cmdno);
|
|
2702
|
|
2703 nbdebug(("EVT: %s", buffer));
|
|
2704
|
|
2705 nb_send(buffer, "netbeans_file_closed");
|
|
2706
|
|
2707 if (nbbuf != NULL)
|
|
2708 nbbuf->bufp = NULL;
|
|
2709 }
|
|
2710
|
|
2711 /*
|
|
2712 * Get a pointer to the Netbeans buffer for Vim buffer "bufp".
|
|
2713 * Return NULL if there is no such buffer or changes are not to be reported.
|
|
2714 * Otherwise store the buffer number in "*bufnop".
|
|
2715 */
|
|
2716 static nbbuf_T *
|
|
2717 nb_bufp2nbbuf_fire(buf_T *bufp, int *bufnop)
|
|
2718 {
|
|
2719 int bufno;
|
|
2720 nbbuf_T *nbbuf;
|
|
2721
|
|
2722 if (!haveConnection || !netbeansFireChanges)
|
|
2723 return NULL; /* changes are not reported at all */
|
|
2724
|
|
2725 bufno = nb_getbufno(bufp);
|
|
2726 if (bufno <= 0)
|
|
2727 return NULL; /* file is not known to NetBeans */
|
|
2728
|
|
2729 nbbuf = nb_get_buf(bufno);
|
|
2730 if (nbbuf != NULL && !nbbuf->fireChanges)
|
|
2731 return NULL; /* changes in this buffer are not reported */
|
|
2732
|
|
2733 *bufnop = bufno;
|
|
2734 return nbbuf;
|
|
2735 }
|
|
2736
|
|
2737 /*
|
|
2738 * Tell netbeans the user inserted some text.
|
|
2739 */
|
|
2740 void
|
|
2741 netbeans_inserted(
|
|
2742 buf_T *bufp,
|
|
2743 linenr_T linenr,
|
|
2744 colnr_T col,
|
|
2745 char_u *txt,
|
|
2746 int newlen)
|
|
2747 {
|
|
2748 char_u *buf;
|
|
2749 int bufno;
|
|
2750 nbbuf_T *nbbuf;
|
|
2751 pos_T pos;
|
|
2752 long off;
|
|
2753 char_u *p;
|
|
2754 char_u *newtxt;
|
|
2755
|
|
2756 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
|
|
2757 if (nbbuf == NULL)
|
|
2758 return;
|
|
2759
|
33
|
2760 /* Don't mark as modified for initial read */
|
|
2761 if (nbbuf->insertDone)
|
|
2762 nbbuf->modified = 1;
|
7
|
2763
|
|
2764 pos.lnum = linenr;
|
|
2765 pos.col = col;
|
|
2766 off = pos2off(bufp, &pos);
|
|
2767
|
|
2768 /* send the "insert" EVT */
|
|
2769 newtxt = alloc(newlen + 1);
|
|
2770 STRNCPY(newtxt, txt, newlen);
|
|
2771 newtxt[newlen] = '\0';
|
|
2772 p = nb_quote(newtxt);
|
|
2773 if (p != NULL)
|
|
2774 {
|
33
|
2775 buf = alloc(128 + 2*newlen);
|
7
|
2776 sprintf((char *)buf, "%d:insert=%d %ld \"%s\"\n", bufno, cmdno, off, p);
|
|
2777 nbdebug(("EVT: %s", buf));
|
|
2778 nb_send((char *)buf, "netbeans_inserted");
|
33
|
2779 vim_free(p);
|
|
2780 vim_free(buf);
|
7
|
2781 }
|
|
2782 vim_free(newtxt);
|
|
2783 }
|
|
2784
|
|
2785 /*
|
|
2786 * Tell netbeans some bytes have been removed.
|
|
2787 */
|
|
2788 void
|
|
2789 netbeans_removed(
|
|
2790 buf_T *bufp,
|
|
2791 linenr_T linenr,
|
|
2792 colnr_T col,
|
|
2793 long len)
|
|
2794 {
|
|
2795 char_u buf[128];
|
|
2796 int bufno;
|
|
2797 nbbuf_T *nbbuf;
|
|
2798 pos_T pos;
|
|
2799 long off;
|
|
2800
|
|
2801 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
|
|
2802 if (nbbuf == NULL)
|
|
2803 return;
|
|
2804
|
|
2805 if (len < 0)
|
|
2806 {
|
|
2807 nbdebug(("Negative len %ld in netbeans_removed()!", len));
|
|
2808 return;
|
|
2809 }
|
|
2810
|
|
2811 nbbuf->modified = 1;
|
|
2812
|
|
2813 pos.lnum = linenr;
|
|
2814 pos.col = col;
|
|
2815
|
|
2816 off = pos2off(bufp, &pos);
|
|
2817
|
|
2818 sprintf((char *)buf, "%d:remove=%d %ld %ld\n", bufno, cmdno, off, len);
|
|
2819 nbdebug(("EVT: %s", buf));
|
|
2820 nb_send((char *)buf, "netbeans_removed");
|
|
2821 }
|
|
2822
|
|
2823 /*
|
|
2824 * Send netbeans an unmodufied command.
|
|
2825 */
|
|
2826 /*ARGSUSED*/
|
|
2827 void
|
|
2828 netbeans_unmodified(buf_T *bufp)
|
|
2829 {
|
|
2830 #if 0
|
|
2831 char_u buf[128];
|
|
2832 int bufno;
|
|
2833 nbbuf_T *nbbuf;
|
|
2834
|
|
2835 /* This has been disabled, because NetBeans considers a buffer modified
|
|
2836 * even when all changes have been undone. */
|
|
2837 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
|
|
2838 if (nbbuf == NULL)
|
|
2839 return;
|
|
2840
|
|
2841 nbbuf->modified = 0;
|
|
2842
|
|
2843 sprintf((char *)buf, "%d:unmodified=%d\n", bufno, cmdno);
|
|
2844 nbdebug(("EVT: %s", buf));
|
|
2845 nb_send((char *)buf, "netbeans_unmodified");
|
|
2846 #endif
|
|
2847 }
|
|
2848
|
|
2849 /*
|
|
2850 * Send a button release event back to netbeans. Its up to netbeans
|
|
2851 * to decide what to do (if anything) with this event.
|
|
2852 */
|
|
2853 void
|
|
2854 netbeans_button_release(int button)
|
|
2855 {
|
|
2856 char buf[128];
|
|
2857 int bufno;
|
|
2858
|
|
2859 bufno = nb_getbufno(curbuf);
|
|
2860
|
|
2861 if (bufno >= 0 && curwin != NULL && curwin->w_buffer == curbuf)
|
|
2862 {
|
118
|
2863 int col = mouse_col - W_WINCOL(curwin) - (curwin->w_p_nu ? 9 : 1);
|
7
|
2864 long off = pos2off(curbuf, &curwin->w_cursor);
|
|
2865
|
|
2866 /* sync the cursor position */
|
|
2867 sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, cmdno, off, off);
|
|
2868 nbdebug(("EVT: %s", buf));
|
|
2869 nb_send(buf, "netbeans_button_release[newDotAndMark]");
|
|
2870
|
|
2871 sprintf(buf, "%d:buttonRelease=%d %d %ld %d\n", bufno, cmdno,
|
|
2872 button, (long)curwin->w_cursor.lnum, col);
|
|
2873 nbdebug(("EVT: %s", buf));
|
|
2874 nb_send(buf, "netbeans_button_release");
|
|
2875 }
|
|
2876 }
|
|
2877
|
|
2878
|
|
2879 /*
|
|
2880 * Send a keypress event back to netbeans. This usualy simulates some
|
33
|
2881 * kind of function key press. This function operates on a key code.
|
7
|
2882 */
|
|
2883 void
|
|
2884 netbeans_keycommand(int key)
|
|
2885 {
|
33
|
2886 char keyName[60];
|
|
2887
|
|
2888 netbeans_keyname(key, keyName);
|
|
2889 netbeans_keystring(key, keyName);
|
|
2890 }
|
|
2891
|
|
2892
|
|
2893 /*
|
|
2894 * Send a keypress event back to netbeans. This usualy simulates some
|
|
2895 * kind of function key press. This function operates on a key string.
|
|
2896 */
|
|
2897 static void
|
|
2898 netbeans_keystring(int key, char *keyName)
|
|
2899 {
|
7
|
2900 char buf[2*MAXPATHL];
|
33
|
2901 int bufno = nb_getbufno(curbuf);
|
7
|
2902 long off;
|
|
2903 char_u *q;
|
|
2904
|
|
2905 if (!haveConnection)
|
|
2906 return;
|
|
2907
|
|
2908
|
|
2909 if (bufno == -1)
|
|
2910 {
|
|
2911 nbdebug(("got keycommand for non-NetBeans buffer, opening...\n"));
|
|
2912 q = curbuf->b_ffname == NULL ? (char_u *)""
|
|
2913 : nb_quote(curbuf->b_ffname);
|
|
2914 if (q == NULL)
|
|
2915 return;
|
|
2916 sprintf(buf, "0:fileOpened=%d \"%s\" %s %s\n", 0,
|
|
2917 q,
|
|
2918 "T", /* open in NetBeans */
|
|
2919 "F"); /* modified */
|
|
2920 if (curbuf->b_ffname != NULL)
|
|
2921 vim_free(q);
|
|
2922 nbdebug(("EVT: %s", buf));
|
|
2923 nb_send(buf, "netbeans_keycommand");
|
|
2924
|
143
|
2925 if (key > 0)
|
|
2926 postpone_keycommand(key);
|
7
|
2927 return;
|
|
2928 }
|
|
2929
|
|
2930 /* sync the cursor position */
|
|
2931 off = pos2off(curbuf, &curwin->w_cursor);
|
|
2932 sprintf(buf, "%d:newDotAndMark=%d %ld %ld\n", bufno, cmdno, off, off);
|
|
2933 nbdebug(("EVT: %s", buf));
|
|
2934 nb_send(buf, "netbeans_keycommand");
|
|
2935
|
|
2936 /* To work on Win32 you must apply patch to ExtEditor module
|
|
2937 * from ExtEdCaret.java.diff - make EVT_newDotAndMark handler
|
|
2938 * more synchronous
|
|
2939 */
|
|
2940
|
|
2941 /* now send keyCommand event */
|
|
2942 sprintf(buf, "%d:keyCommand=%d \"%s\"\n", bufno, cmdno, keyName);
|
|
2943 nbdebug(("EVT: %s", buf));
|
|
2944 nb_send(buf, "netbeans_keycommand");
|
|
2945
|
|
2946 /* New: do both at once and include the lnum/col. */
|
|
2947 sprintf(buf, "%d:keyAtPos=%d \"%s\" %ld %ld/%ld\n", bufno, cmdno, keyName,
|
|
2948 off, (long)curwin->w_cursor.lnum, (long)curwin->w_cursor.col);
|
|
2949 nbdebug(("EVT: %s", buf));
|
|
2950 nb_send(buf, "netbeans_keycommand");
|
|
2951 }
|
|
2952
|
|
2953
|
|
2954 /*
|
|
2955 * Send a save event to netbeans.
|
|
2956 */
|
|
2957 void
|
|
2958 netbeans_save_buffer(buf_T *bufp)
|
|
2959 {
|
|
2960 char_u buf[64];
|
|
2961 int bufno;
|
|
2962 nbbuf_T *nbbuf;
|
|
2963
|
|
2964 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
|
|
2965 if (nbbuf == NULL)
|
|
2966 return;
|
|
2967
|
|
2968 nbbuf->modified = 0;
|
|
2969
|
|
2970 sprintf((char *)buf, "%d:save=%d\n", bufno, cmdno);
|
|
2971 nbdebug(("EVT: %s", buf));
|
|
2972 nb_send((char *)buf, "netbeans_save_buffer");
|
|
2973 }
|
|
2974
|
|
2975
|
|
2976 /*
|
|
2977 * Send remove command to netbeans (this command has been turned off).
|
|
2978 */
|
|
2979 void
|
|
2980 netbeans_deleted_all_lines(buf_T *bufp)
|
|
2981 {
|
|
2982 char_u buf[64];
|
|
2983 int bufno;
|
|
2984 nbbuf_T *nbbuf;
|
|
2985
|
|
2986 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
|
|
2987 if (nbbuf == NULL)
|
|
2988 return;
|
|
2989
|
33
|
2990 /* Don't mark as modified for initial read */
|
|
2991 if (nbbuf->insertDone)
|
|
2992 nbbuf->modified = 1;
|
7
|
2993
|
|
2994 sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, cmdno);
|
|
2995 nbdebug(("EVT(suppressed): %s", buf));
|
|
2996 /* nb_send(buf, "netbeans_deleted_all_lines"); */
|
|
2997 }
|
|
2998
|
|
2999
|
|
3000 /*
|
|
3001 * See if the lines are guarded. The top and bot parameters are from
|
|
3002 * u_savecommon(), these are the line above the change and the line below the
|
|
3003 * change.
|
|
3004 */
|
|
3005 int
|
|
3006 netbeans_is_guarded(linenr_T top, linenr_T bot)
|
|
3007 {
|
|
3008 signlist_T *p;
|
|
3009 int lnum;
|
|
3010
|
|
3011 for (p = curbuf->b_signlist; p != NULL; p = p->next)
|
|
3012 if (p->id >= GUARDEDOFFSET)
|
|
3013 for (lnum = top + 1; lnum < bot; lnum++)
|
|
3014 if (lnum == p->lnum)
|
|
3015 return TRUE;
|
|
3016
|
|
3017 return FALSE;
|
|
3018 }
|
|
3019
|
|
3020 #if defined(FEAT_GUI_MOTIF) || defined(PROTO)
|
|
3021 /*
|
|
3022 * We have multiple signs to draw at the same location. Draw the
|
|
3023 * multi-sign indicator instead. This is the Motif version.
|
|
3024 */
|
|
3025 void
|
|
3026 netbeans_draw_multisign_indicator(int row)
|
|
3027 {
|
|
3028 int i;
|
|
3029 int y;
|
|
3030 int x;
|
|
3031
|
|
3032 x = 0;
|
|
3033 y = row * gui.char_height + 2;
|
|
3034
|
|
3035 for (i = 0; i < gui.char_height - 3; i++)
|
|
3036 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y++);
|
|
3037
|
|
3038 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+0, y);
|
|
3039 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
|
|
3040 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+4, y++);
|
|
3041 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+1, y);
|
|
3042 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
|
|
3043 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+3, y++);
|
|
3044 XDrawPoint(gui.dpy, gui.wid, gui.text_gc, x+2, y);
|
|
3045 }
|
|
3046 #endif /* FEAT_GUI_MOTIF */
|
|
3047
|
|
3048 #ifdef FEAT_GUI_GTK
|
|
3049 /*
|
|
3050 * We have multiple signs to draw at the same location. Draw the
|
|
3051 * multi-sign indicator instead. This is the GTK/Gnome version.
|
|
3052 */
|
|
3053 void
|
|
3054 netbeans_draw_multisign_indicator(int row)
|
|
3055 {
|
|
3056 int i;
|
|
3057 int y;
|
|
3058 int x;
|
|
3059 GdkDrawable *drawable = gui.drawarea->window;
|
|
3060
|
|
3061 x = 0;
|
|
3062 y = row * gui.char_height + 2;
|
|
3063
|
|
3064 for (i = 0; i < gui.char_height - 3; i++)
|
|
3065 gdk_draw_point(drawable, gui.text_gc, x+2, y++);
|
|
3066
|
|
3067 gdk_draw_point(drawable, gui.text_gc, x+0, y);
|
|
3068 gdk_draw_point(drawable, gui.text_gc, x+2, y);
|
|
3069 gdk_draw_point(drawable, gui.text_gc, x+4, y++);
|
|
3070 gdk_draw_point(drawable, gui.text_gc, x+1, y);
|
|
3071 gdk_draw_point(drawable, gui.text_gc, x+2, y);
|
|
3072 gdk_draw_point(drawable, gui.text_gc, x+3, y++);
|
|
3073 gdk_draw_point(drawable, gui.text_gc, x+2, y);
|
|
3074 }
|
|
3075 #endif /* FEAT_GUI_GTK */
|
|
3076
|
|
3077 /*
|
|
3078 * If the mouse is clicked in the gutter of a line with multiple
|
|
3079 * annotations, cycle through the set of signs.
|
|
3080 */
|
|
3081 void
|
|
3082 netbeans_gutter_click(linenr_T lnum)
|
|
3083 {
|
|
3084 signlist_T *p;
|
|
3085
|
|
3086 for (p = curbuf->b_signlist; p != NULL; p = p->next)
|
|
3087 {
|
|
3088 if (p->lnum == lnum && p->next && p->next->lnum == lnum)
|
|
3089 {
|
|
3090 signlist_T *tail;
|
|
3091
|
|
3092 /* remove "p" from list, reinsert it at the tail of the sublist */
|
|
3093 if (p->prev)
|
|
3094 p->prev->next = p->next;
|
|
3095 else
|
|
3096 curbuf->b_signlist = p->next;
|
|
3097 p->next->prev = p->prev;
|
|
3098 /* now find end of sublist and insert p */
|
|
3099 for (tail = p->next;
|
|
3100 tail->next && tail->next->lnum == lnum
|
|
3101 && tail->next->id < GUARDEDOFFSET;
|
|
3102 tail = tail->next)
|
|
3103 ;
|
|
3104 /* tail now points to last entry with same lnum (except
|
|
3105 * that "guarded" annotations are always last) */
|
|
3106 p->next = tail->next;
|
|
3107 if (tail->next)
|
|
3108 tail->next->prev = p;
|
|
3109 p->prev = tail;
|
|
3110 tail->next = p;
|
|
3111 update_debug_sign(curbuf, lnum);
|
|
3112 break;
|
|
3113 }
|
|
3114 }
|
|
3115 }
|
|
3116
|
|
3117
|
|
3118 /*
|
|
3119 * Add a sign of the reqested type at the requested location.
|
|
3120 *
|
|
3121 * Reverse engineering:
|
|
3122 * Apparently an annotation is defined the first time it is used in a buffer.
|
|
3123 * When the same annotation is used in two buffers, the second time we do not
|
|
3124 * need to define a new sign name but reuse the existing one. But since the
|
|
3125 * ID number used in the second buffer starts counting at one again, a mapping
|
|
3126 * is made from the ID specifically for the buffer to the global sign name
|
|
3127 * (which is a number).
|
|
3128 *
|
|
3129 * globalsignmap[] stores the signs that have been defined globally.
|
|
3130 * buf->signmapused[] maps buffer-local annotation IDs to an index in
|
|
3131 * globalsignmap[].
|
|
3132 */
|
|
3133 /*ARGSUSED*/
|
|
3134 static void
|
|
3135 addsigntype(
|
|
3136 nbbuf_T *buf,
|
|
3137 int typeNum,
|
|
3138 char_u *typeName,
|
|
3139 char_u *tooltip,
|
|
3140 char_u *glyphFile,
|
|
3141 int use_fg,
|
|
3142 int fg,
|
|
3143 int use_bg,
|
|
3144 int bg)
|
|
3145 {
|
|
3146 char fgbuf[32];
|
|
3147 char bgbuf[32];
|
|
3148 int i, j;
|
|
3149
|
|
3150 for (i = 0; i < globalsignmapused; i++)
|
|
3151 if (STRCMP(typeName, globalsignmap[i]) == 0)
|
|
3152 break;
|
|
3153
|
|
3154 if (i == globalsignmapused) /* not found; add it to global map */
|
|
3155 {
|
|
3156 nbdebug(("DEFINEANNOTYPE(%d,%s,%s,%s,%d,%d)\n",
|
|
3157 typeNum, typeName, tooltip, glyphFile, fg, bg));
|
|
3158 if (use_fg || use_bg)
|
|
3159 {
|
|
3160 sprintf(fgbuf, "guifg=#%06x", fg & 0xFFFFFF);
|
|
3161 sprintf(bgbuf, "guibg=#%06x", bg & 0xFFFFFF);
|
|
3162
|
|
3163 coloncmd(":highlight NB_%s %s %s", typeName, (use_fg) ? fgbuf : "",
|
|
3164 (use_bg) ? bgbuf : "");
|
|
3165 if (*glyphFile == NUL)
|
|
3166 /* no glyph, line highlighting only */
|
|
3167 coloncmd(":sign define %d linehl=NB_%s", i + 1, typeName);
|
|
3168 else if (vim_strsize(glyphFile) <= 2)
|
|
3169 /* one- or two-character glyph name, use as text glyph with
|
|
3170 * texthl */
|
|
3171 coloncmd(":sign define %d text=%s texthl=NB_%s", i + 1,
|
|
3172 glyphFile, typeName);
|
|
3173 else
|
|
3174 /* glyph, line highlighting */
|
|
3175 coloncmd(":sign define %d icon=%s linehl=NB_%s", i + 1,
|
|
3176 glyphFile, typeName);
|
|
3177 }
|
|
3178 else
|
|
3179 /* glyph, no line highlighting */
|
|
3180 coloncmd(":sign define %d icon=%s", i + 1, glyphFile);
|
|
3181
|
|
3182 if (STRCMP(typeName,"CurrentPC") == 0)
|
|
3183 curPCtype = typeNum;
|
|
3184
|
|
3185 if (globalsignmapused == globalsignmaplen)
|
|
3186 {
|
|
3187 if (globalsignmaplen == 0) /* first allocation */
|
|
3188 {
|
|
3189 globalsignmaplen = 20;
|
|
3190 globalsignmap = (char **)alloc_clear(globalsignmaplen*sizeof(char *));
|
|
3191 }
|
|
3192 else /* grow it */
|
|
3193 {
|
|
3194 int incr;
|
|
3195 int oldlen = globalsignmaplen;
|
|
3196
|
|
3197 globalsignmaplen *= 2;
|
|
3198 incr = globalsignmaplen - oldlen;
|
|
3199 globalsignmap = (char **)vim_realloc(globalsignmap,
|
|
3200 globalsignmaplen * sizeof(char *));
|
|
3201 memset(globalsignmap + oldlen, 0, incr * sizeof(char *));
|
|
3202 }
|
|
3203 }
|
|
3204
|
|
3205 globalsignmap[i] = (char *)typeName;
|
|
3206 globalsignmapused = i + 1;
|
|
3207 }
|
|
3208
|
|
3209 /* check local map; should *not* be found! */
|
|
3210 for (j = 0; j < buf->signmapused; j++)
|
|
3211 if (buf->signmap[j] == i + 1)
|
|
3212 return;
|
|
3213
|
|
3214 /* add to local map */
|
|
3215 if (buf->signmapused == buf->signmaplen)
|
|
3216 {
|
|
3217 if (buf->signmaplen == 0) /* first allocation */
|
|
3218 {
|
|
3219 buf->signmaplen = 5;
|
|
3220 buf->signmap = (int *)alloc_clear(buf->signmaplen * sizeof(int *));
|
|
3221 }
|
|
3222 else /* grow it */
|
|
3223 {
|
|
3224 int incr;
|
|
3225 int oldlen = buf->signmaplen;
|
|
3226 buf->signmaplen *= 2;
|
|
3227 incr = buf->signmaplen - oldlen;
|
|
3228 buf->signmap = (int *)vim_realloc(buf->signmap,
|
|
3229 buf->signmaplen*sizeof(int *));
|
|
3230 memset(buf->signmap + oldlen, 0, incr * sizeof(int *));
|
|
3231 }
|
|
3232 }
|
|
3233
|
|
3234 buf->signmap[buf->signmapused++] = i + 1;
|
|
3235
|
|
3236 }
|
|
3237
|
|
3238
|
|
3239 /*
|
|
3240 * See if we have the requested sign type in the buffer.
|
|
3241 */
|
|
3242 static int
|
|
3243 mapsigntype(nbbuf_T *buf, int localsigntype)
|
|
3244 {
|
|
3245 if (--localsigntype >= 0 && localsigntype < buf->signmapused)
|
|
3246 return buf->signmap[localsigntype];
|
|
3247
|
|
3248 return 0;
|
|
3249 }
|
|
3250
|
|
3251
|
|
3252 /*
|
|
3253 * Compute length of buffer, don't print anything.
|
|
3254 */
|
|
3255 static long
|
|
3256 get_buf_size(buf_T *bufp)
|
|
3257 {
|
|
3258 linenr_T lnum;
|
|
3259 long char_count = 0;
|
|
3260 int eol_size;
|
|
3261 long last_check = 100000L;
|
|
3262
|
|
3263 if (bufp->b_ml.ml_flags & ML_EMPTY)
|
|
3264 return 0;
|
|
3265 else
|
|
3266 {
|
|
3267 if (get_fileformat(bufp) == EOL_DOS)
|
|
3268 eol_size = 2;
|
|
3269 else
|
|
3270 eol_size = 1;
|
|
3271 for (lnum = 1; lnum <= bufp->b_ml.ml_line_count; ++lnum)
|
|
3272 {
|
|
3273 char_count += STRLEN(ml_get(lnum)) + eol_size;
|
|
3274 /* Check for a CTRL-C every 100000 characters */
|
|
3275 if (char_count > last_check)
|
|
3276 {
|
|
3277 ui_breakcheck();
|
|
3278 if (got_int)
|
|
3279 return char_count;
|
|
3280 last_check = char_count + 100000L;
|
|
3281 }
|
|
3282 }
|
|
3283 /* Correction for when last line doesn't have an EOL. */
|
|
3284 if (!bufp->b_p_eol && bufp->b_p_bin)
|
|
3285 char_count -= eol_size;
|
|
3286 }
|
|
3287
|
|
3288 return char_count;
|
|
3289 }
|
|
3290
|
|
3291 /*
|
|
3292 * Convert character offset to lnum,col
|
|
3293 */
|
|
3294 static pos_T *
|
|
3295 off2pos(buf_T *buf, long offset)
|
|
3296 {
|
|
3297 linenr_T lnum;
|
|
3298 static pos_T pos;
|
|
3299
|
|
3300 pos.lnum = 0;
|
|
3301 pos.col = 0;
|
|
3302 #ifdef FEAT_VIRTUALEDIT
|
|
3303 pos.coladd = 0;
|
|
3304 #endif
|
|
3305
|
|
3306 if (!(buf->b_ml.ml_flags & ML_EMPTY))
|
|
3307 {
|
|
3308 if ((lnum = ml_find_line_or_offset(buf, (linenr_T)0, &offset)) < 0)
|
|
3309 return NULL;
|
|
3310 pos.lnum = lnum;
|
|
3311 pos.col = offset;
|
|
3312 }
|
|
3313
|
|
3314 return &pos;
|
|
3315 }
|
|
3316
|
|
3317 /*
|
|
3318 * Convert an argument in the form "1234" to an offset and compute the
|
|
3319 * lnum/col from it. Convert an argument in the form "123/12" directly to a
|
|
3320 * lnum/col.
|
|
3321 * "argp" is advanced to after the argument.
|
|
3322 * Return a pointer to the position, NULL if something is wrong.
|
|
3323 */
|
|
3324 static pos_T *
|
|
3325 get_off_or_lnum(buf_T *buf, char_u **argp)
|
|
3326 {
|
|
3327 static pos_T mypos;
|
|
3328 long off;
|
|
3329
|
|
3330 off = strtol((char *)*argp, (char **)argp, 10);
|
|
3331 if (**argp == '/')
|
|
3332 {
|
|
3333 mypos.lnum = (linenr_T)off;
|
|
3334 ++*argp;
|
|
3335 mypos.col = strtol((char *)*argp, (char **)argp, 10);
|
|
3336 #ifdef FEAT_VIRTUALEDIT
|
|
3337 mypos.coladd = 0;
|
|
3338 #endif
|
|
3339 return &mypos;
|
|
3340 }
|
|
3341 return off2pos(buf, off);
|
|
3342 }
|
|
3343
|
|
3344
|
|
3345 /*
|
|
3346 * Convert lnum,col to character offset
|
|
3347 */
|
|
3348 static long
|
|
3349 pos2off(buf_T *buf, pos_T *pos)
|
|
3350 {
|
|
3351 long offset = 0;
|
|
3352
|
|
3353 if (!(buf->b_ml.ml_flags & ML_EMPTY))
|
|
3354 {
|
|
3355 if ((offset = ml_find_line_or_offset(buf, pos->lnum, 0)) < 0)
|
|
3356 return 0;
|
|
3357 offset += pos->col;
|
|
3358 }
|
|
3359
|
|
3360 return offset;
|
|
3361 }
|
|
3362
|
|
3363
|
33
|
3364 /*
|
|
3365 * This message is printed after NetBeans opens a new file. Its
|
|
3366 * similar to the message readfile() uses, but since NetBeans
|
|
3367 * doesn't normally call readfile, we do our own.
|
|
3368 */
|
|
3369 static void
|
|
3370 print_read_msg(buf)
|
|
3371 nbbuf_T *buf;
|
|
3372 {
|
|
3373 int lnum = buf->bufp->b_ml.ml_line_count;
|
|
3374 long nchars = buf->bufp->b_orig_size;
|
|
3375 char_u c;
|
|
3376
|
|
3377 msg_add_fname(buf->bufp, buf->bufp->b_ffname);
|
|
3378 c = FALSE;
|
|
3379
|
|
3380 if (buf->bufp->b_p_ro)
|
|
3381 {
|
|
3382 STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
|
|
3383 c = TRUE;
|
|
3384 }
|
|
3385 if (!buf->bufp->b_start_eol)
|
|
3386 {
|
|
3387 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]"));
|
|
3388 c = TRUE;
|
|
3389 }
|
|
3390 msg_add_lines(c, (long)lnum, nchars);
|
|
3391
|
|
3392 /* Now display it */
|
|
3393 vim_free(keep_msg);
|
|
3394 keep_msg = NULL;
|
|
3395 msg_scrolled_ign = TRUE;
|
|
3396 msg_trunc_attr(IObuff, FALSE, 0);
|
|
3397 msg_scrolled_ign = FALSE;
|
|
3398 }
|
|
3399
|
|
3400
|
|
3401 /*
|
|
3402 * Print a message after NetBeans writes the file. This message should be identical
|
|
3403 * to the standard message a non-netbeans user would see when writing a file.
|
|
3404 */
|
|
3405 static void
|
|
3406 print_save_msg(buf, nchars)
|
|
3407 nbbuf_T *buf;
|
|
3408 long nchars;
|
|
3409 {
|
|
3410 char_u c;
|
|
3411 char_u *p;
|
|
3412
|
|
3413 if (nchars >= 0)
|
|
3414 {
|
|
3415 msg_add_fname(buf->bufp, buf->bufp->b_ffname); /* fname in IObuff with quotes */
|
|
3416 c = FALSE;
|
|
3417
|
|
3418 msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
|
|
3419 (long)buf->bufp->b_orig_size);
|
|
3420
|
|
3421 vim_free(keep_msg);
|
|
3422 keep_msg = NULL;
|
|
3423 msg_scrolled_ign = TRUE;
|
|
3424 p = msg_trunc_attr(IObuff, FALSE, 0);
|
|
3425 if ((msg_scrolled && !need_wait_return) || !buf->initDone)
|
|
3426 {
|
|
3427 /* Need to repeat the message after redrawing when:
|
|
3428 * - When reading from stdin (the screen will be cleared next).
|
|
3429 * - When restart_edit is set (otherwise there will be a delay
|
|
3430 * before redrawing).
|
|
3431 * - When the screen was scrolled but there is no wait-return
|
|
3432 * prompt. */
|
|
3433 set_keep_msg(p);
|
|
3434 keep_msg_attr = 0;
|
|
3435 }
|
|
3436 msg_scrolled_ign = FALSE;
|
|
3437 /* add_to_input_buf((char_u *)"\f", 1); */
|
|
3438 }
|
|
3439 else
|
|
3440 {
|
|
3441 char_u ebuf[BUFSIZ];
|
|
3442
|
|
3443 STRCPY(ebuf, (char_u *)_("E505: "));
|
|
3444 STRCAT(ebuf, IObuff);
|
|
3445 STRCAT(ebuf, (char_u *)_("is read-only (add ! to override)"));
|
|
3446 STRCPY(IObuff, ebuf);
|
|
3447 emsg(IObuff);
|
|
3448 }
|
|
3449 }
|
|
3450
|
7
|
3451 #endif /* defined(FEAT_NETBEANS_INTG) */
|