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