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